]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/CategorizedCombo.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / CategorizedCombo.cpp
index 757196377a67441aad0b68e5f1921d62691d7b26..89b28cd3bd9eb84dfb31593ea45ae3c09494b8b3 100644 (file)
@@ -24,6 +24,7 @@
 #include "support/gettext.h"
 #include "support/lassert.h"
 #include "support/lstrings.h"
+#include "support/qstring_helpers.h"
 
 #include <QAbstractTextDocumentLayout>
 #include <QComboBox>
@@ -267,43 +268,13 @@ QString CCItemDelegate::underlineFilter(QString const & s) const
        QString const & f = cc_->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 charFilterRegExpCC(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 CategorizedCombo::Private::setFilter(QString const & s)
 {
        bool enabled = p->view()->updatesEnabled();
@@ -315,7 +286,7 @@ void CategorizedCombo::Private::setFilter(QString const & s)
                lastSel_ = filterModel_->mapToSource(filterModel_->index(sel, 0)).row();
 
        filter_ = s;
-       filterModel_->setFilterRegExp(charFilterRegExpCC(filter_));
+    filterModel_->setFilterRegExp(charFilterRegExp(filter_));
        countCategories();
 
        // restore old selection