+ ///
+ QString category(QAbstractItemModel const & model, int row) const
+ {
+ return model.data(model.index(row, 2), Qt::DisplayRole).toString();
+ }
+
+ ///
+ int headerHeight(QStyleOptionViewItem const & opt) const
+ {
+ return opt.fontMetrics.height() * 8 / 10;
+ }
+ ///
+ void drawCategoryHeader(QPainter * painter, QStyleOptionViewItem const & opt,
+ QString const & category) const
+ {
+ // slightly blended color
+ QColor lcol = opt.palette.text().color();
+ lcol.setAlpha(127);
+ painter->setPen(lcol);
+
+ // set 80% scaled, bold font
+ QFont font = opt.font;
+ font.setBold(true);
+ font.setWeight(QFont::Black);
+ font.setPointSize(opt.font.pointSize() * 8 / 10);
+ painter->setFont(font);
+
+ // draw the centered text
+ QFontMetrics fm(font);
+ int w = fm.width(category);
+ int x = opt.rect.x() + (opt.rect.width() - w) / 2;
+ int y = opt.rect.y() + fm.ascent();
+ int left = x;
+ int right = x + w;
+ painter->drawText(x, y, category);
+
+ // the vertical position of the line: middle of lower case chars
+ int ymid = y - 1 - fm.xHeight() / 2; // -1 for the baseline
+
+ // draw the horizontal line
+ if (!category.isEmpty()) {
+ painter->drawLine(opt.rect.x(), ymid, left - 1, ymid);
+ painter->drawLine(right + 1, ymid, opt.rect.right(), ymid);
+ } else
+ painter->drawLine(opt.rect.x(), ymid, opt.rect.right(), ymid);
+ }
+
+
+ ///
+ QString underlineFilter(QString const & s) const
+ {
+ // get filter
+ GuiLayoutBox * p = static_cast<GuiLayoutBox *>(parent());
+ QString const & f = p->filter();
+ if (f.isEmpty())
+ return s;
+
+ // step through data item and put "(x)" for every matching character
+ QString r;
+ int lastp = -1;
+ p->filter();
+ for (int i = 0; i < f.length(); ++i) {
+ int p = s.indexOf(f[i], lastp + 1, Qt::CaseInsensitive);
+ LASSERT(p != -1, /**/);
+ 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);
+ return r;
+ }