]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/CategorizedCombo.cpp
QDialogButtonBox for the remaining dialogs.
[lyx.git] / src / frontends / qt4 / CategorizedCombo.cpp
index 327059f878588b32cbc46d6c4d6d7f5743abc397..757196377a67441aad0b68e5f1921d62691d7b26 100644 (file)
@@ -55,11 +55,11 @@ public:
        ///
        QSize sizeHint(QStyleOptionViewItem const & opt,
                QModelIndex const & index) const;
-       
+
 private:
        ///
        void drawCategoryHeader(QPainter * painter, QStyleOptionViewItem const & opt,
-               QString const & category) const;        
+               QString const & category) const;
        ///
        QString underlineFilter(QString const & s) const;
        ///
@@ -106,8 +106,8 @@ struct CategorizedCombo::Private
        void countCategories();
        ///
        CategorizedCombo * p;
-       
-       /** the layout model: 
+
+       /** the layout model:
         * 1st column: translated GUI name,
         * 2nd column: raw item name,
         * 3rd column: category,
@@ -162,7 +162,7 @@ void CCItemDelegate::paint(QPainter * painter, QStyleOptionViewItem const & opti
                opt.state = state;
 
                // draw category header
-               drawCategoryHeader(painter, opt, 
+               drawCategoryHeader(painter, opt,
                        categoryCC(*index.model(), index.row()));
 
                // move rect down below header
@@ -245,7 +245,7 @@ void CCItemDelegate::drawCategoryHeader(QPainter * painter, QStyleOptionViewItem
        QFontMetrics fm(font);
        int w = fm.width(category);
        int x = opt.rect.x() + (opt.rect.width() - w) / 2;
-       int y = opt.rect.y() + 1.5 * fm.ascent();
+       int y = opt.rect.y() + 3 * fm.ascent() / 2;
        int left = x;
        int right = x + w;
        painter->drawText(x, y, category);
@@ -271,10 +271,10 @@ QString CCItemDelegate::underlineFilter(QString const & s) const
        // step through data item and put "(x)" for every matching character
        QString r;
        int lastp = -1;
-       cc_->filter();
        for (int i = 0; i < f.length(); ++i) {
                int p = s.indexOf(f[i], lastp + 1, Qt::CaseInsensitive);
-               LASSERT(p != -1, /**/);
+               if (p < 0)
+                       continue;
                if (lastp == p - 1 && lastp != -1) {
                        // remove ")" and append "x)"
                        r = r.left(r.length() - 4) + s[p] + "</u>";
@@ -317,14 +317,14 @@ void CategorizedCombo::Private::setFilter(QString const & s)
        filter_ = s;
        filterModel_->setFilterRegExp(charFilterRegExpCC(filter_));
        countCategories();
-       
+
        // restore old selection
        if (lastSel_ != -1) {
                QModelIndex i = filterModel_->mapFromSource(model_->index(lastSel_, 0));
                if (i.isValid())
                        p->setCurrentIndex(i.row());
        }
-       
+
        // Workaround to resize to content size
        // FIXME: There must be a better way. The QComboBox::AdjustToContents)
        //        does not help.
@@ -339,7 +339,7 @@ void CategorizedCombo::Private::setFilter(QString const & s)
                p->QComboBox::showPopup();
                inShowPopup_ = false;
        }
-       
+
        p->view()->setUpdatesEnabled(enabled);
 }
 
@@ -348,7 +348,6 @@ CategorizedCombo::CategorizedCombo(QWidget * parent)
        : QComboBox(parent), d(new Private(this))
 {
        setSizeAdjustPolicy(QComboBox::AdjustToContents);
-       setFocusPolicy(Qt::ClickFocus);
        setMinimumWidth(sizeHint().width());
        setMaxVisibleItems(100);
 
@@ -357,7 +356,7 @@ CategorizedCombo::CategorizedCombo(QWidget * parent)
        // for the filtering we have to intercept characters
        view()->installEventFilter(this);
        view()->setItemDelegateForColumn(0, d->CCItemDelegate_);
-       
+
        updateCombo();
 }
 
@@ -374,7 +373,7 @@ void CategorizedCombo::Private::countCategories()
        if (n == 0)
                return;
 
-       QString prevCat = model_->index(0, 2).data().toString(); 
+       QString prevCat = model_->index(0, 2).data().toString();
 
        // count categories
        for (int i = 1; i < n; ++i) {
@@ -413,7 +412,7 @@ bool CategorizedCombo::eventFilter(QObject * o, QEvent * e)
        bool modified = (ke->modifiers() == Qt::ControlModifier)
                || (ke->modifiers() == Qt::AltModifier)
                || (ke->modifiers() == Qt::MetaModifier);
-       
+
        switch (ke->key()) {
        case Qt::Key_Escape:
                if (!modified && !d->filter_.isEmpty()) {
@@ -455,7 +454,7 @@ bool CategorizedCombo::eventFilter(QObject * o, QEvent * e)
 
 void CategorizedCombo::setIconSize(QSize size)
 {
-#ifdef Q_WS_MACX
+#ifdef Q_OS_MAC
        bool small = size.height() < 20;
        setAttribute(Qt::WA_MacSmallSize, small);
        setAttribute(Qt::WA_MacNormalSize, !small);
@@ -521,7 +520,7 @@ void CategorizedCombo::addItemSort(QString const & item, QString const & guiname
        if (sortedByCat) {
                // If sortCats == true, sort categories alphabetically, uncategorized at the end.
                while (i < end && d->model_->item(i, 2)->text() != qcat
-                      && (!sortCats 
+                      && (!sortCats
                           || (!uncategorized && d->model_->item(i, 2)->text().localeAwareCompare(qcat) < 0
                               && d->model_->item(i, 2)->text() != qt_("Uncategorized"))
                           || (uncategorized && d->model_->item(i, 2)->text() != qt_("Uncategorized"))))
@@ -557,7 +556,8 @@ void CategorizedCombo::addItemSort(QString const & item, QString const & guiname
 
 QString CategorizedCombo::getData(int row) const
 {
-       return d->model_->data(d->model_->index(row, 1), Qt::DisplayRole).toString();
+       int srow = d->filterModel_->mapToSource(d->filterModel_->index(row, 1)).row();
+       return d->model_->data(d->model_->index(srow, 1), Qt::DisplayRole).toString();
 }
 
 
@@ -571,7 +571,7 @@ void CategorizedCombo::reset()
 void CategorizedCombo::updateCombo()
 {
        d->countCategories();
-       
+
        // needed to recalculate size hint
        hide();
        setMinimumWidth(sizeHint().width());
@@ -584,8 +584,8 @@ QString const & CategorizedCombo::filter() const
        return d->filter_;
 }
 
-}  // namespace frontend
-}  // namespace lyx
+} // namespace frontend
+} // namespace lyx
 
 
 #include "moc_CategorizedCombo.cpp"