]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/LayoutBox.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / LayoutBox.cpp
index 8626d2f063fd4b51c66413dbc03b108299119282..7d0cfd666f3f1696cf80ae5c8e03ebd8dff6dcc2 100644 (file)
@@ -43,6 +43,7 @@
 #include <QHeaderView>
 #include <QItemDelegate>
 #include <QPainter>
+#include <QRegExp>
 #include <QSortFilterProxyModel>
 #include <QStandardItemModel>
 #include <QTextFrame>
@@ -237,19 +238,22 @@ void LayoutItemDelegate::drawDisplay(QPainter * painter, QStyleOptionViewItem co
 QSize LayoutItemDelegate::sizeHint(QStyleOptionViewItem const & opt,
                                                                   QModelIndex const & index) const
 {
-       QSortFilterProxyModel const * model =
-               static_cast<QSortFilterProxyModel const *>(index.model());
        QSize size = QItemDelegate::sizeHint(opt, index);
+       if (!lyxrc.group_layouts)
+               return size;
 
-       // Add space for the category headers here?
-       // Not for the standard layout though.
-       QString stdCat = category(*model->sourceModel(), 0);
-       QString cat = category(*index.model(), index.row());
-       if (lyxrc.group_layouts && stdCat != cat
-               && (index.row() == 0 || cat != category(*index.model(), index.row() - 1))) {
-               size.setHeight(size.height() + headerHeight(opt));
-       }
+       // Add space for the category headers.
+       QSortFilterProxyModel const * const model =
+               static_cast<QSortFilterProxyModel const *>(index.model());
+       QString const stdCat = category(*model->sourceModel(), 0);
+       QString const cat = category(*index.model(), index.row());
+
+       // There is no header for the stuff at the top.
+       if (stdCat == cat)
+               return size;
 
+       if (index.row() == 0 || cat != category(*index.model(), index.row() - 1))
+               size.setHeight(size.height() + headerHeight(opt));
        return size;
 }
 
@@ -295,43 +299,13 @@ QString LayoutItemDelegate::underlineFilter(QString const & s) const
        QString const & f = layout_->filter();
        if (f.isEmpty())
                return s;
-
-       // step through data item and put "(x)" for every matching character
-       QString r;
-       int lastp = -1;
-       for (int i = 0; i < f.length(); ++i) {
-               int p = s.indexOf(f[i], lastp + 1, Qt::CaseInsensitive);
-               if (p < 0)
-                       continue;
-               if (lastp == p - 1 && lastp != -1) {
-                       // remove ")" and append "x)"
-                       r = r.left(r.length() - 4) + s[p] + "</u>";
-               } else {
-                       // append "(x)"
-                       r += s.mid(lastp + 1, p - lastp - 1);
-                       r += QString("<u>") + s[p] + "</u>";
-               }
-               lastp = p;
-       }
-       r += s.mid(lastp + 1);
+       QString r(s);
+       QRegExp pattern(charFilterRegExpC(f));
+       r.replace(pattern, "<u><b>\\1</b></u>");
        return r;
 }
 
 
-static QString charFilterRegExp(QString const & filter)
-{
-       QString re = ".*";
-       for (int i = 0; i < filter.length(); ++i) {
-               QChar c = filter[i];
-               if (c.isLower())
-                       re +=  "["+ QRegExp::escape(c) + QRegExp::escape(c.toUpper()) + "]";
-               else
-                       re +=  QRegExp::escape(c);
-       }
-       return re;
-}
-
-
 void LayoutBox::Private::setFilter(QString const & s)
 {
        // exit early if nothing has to be done
@@ -423,11 +397,8 @@ void LayoutBox::showPopup()
 
        bool enabled = view()->updatesEnabled();
        view()->setUpdatesEnabled(false);
-
        d->resetFilter();
-
        QComboBox::showPopup();
-
        view()->setUpdatesEnabled(enabled);
 }