|
a/src/qtgui/restable.cpp |
|
b/src/qtgui/restable.cpp |
|
... |
|
... |
328 |
// We use a custom delegate to display the cells because the base
|
328 |
// We use a custom delegate to display the cells because the base
|
329 |
// tableview's can't handle rich text to highlight the match terms
|
329 |
// tableview's can't handle rich text to highlight the match terms
|
330 |
class ResTableDelegate: public QStyledItemDelegate {
|
330 |
class ResTableDelegate: public QStyledItemDelegate {
|
331 |
public:
|
331 |
public:
|
332 |
ResTableDelegate(QObject *parent) : QStyledItemDelegate(parent) {}
|
332 |
ResTableDelegate(QObject *parent) : QStyledItemDelegate(parent) {}
|
|
|
333 |
|
|
|
334 |
// We might want to optimize by passing the data to the base
|
|
|
335 |
// method if the text does not contain any term matches. Would
|
|
|
336 |
// need a modif to plaintorich to return the match count (easy),
|
|
|
337 |
// and a way to pass an indicator from data(), a bit more
|
|
|
338 |
// difficult. Anyway, the display seems fast enough as is.
|
333 |
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
339 |
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
334 |
const QModelIndex &index) const
|
340 |
const QModelIndex &index) const
|
335 |
{
|
341 |
{
|
|
|
342 |
QStyleOptionViewItemV4 opt = option;
|
|
|
343 |
initStyleOption(&opt, index);
|
336 |
QVariant value = index.data(Qt::DisplayRole);
|
344 |
QVariant value = index.data(Qt::DisplayRole);
|
337 |
if (value.isValid() && !value.isNull()) {
|
345 |
if (value.isValid() && !value.isNull()) {
|
338 |
// We might possibly want to optimize by passing the data
|
346 |
QString text = value.toString();
|
339 |
// to the base method if the text does not contain any
|
347 |
if (!text.isEmpty()) {
|
340 |
// term matches. Would need a modif to plaintorich to
|
|
|
341 |
// return the match count (easy), and a way to pass an
|
|
|
342 |
// indicator from data(), a bit more difficult. Anyway,
|
|
|
343 |
// the display seems fast enough as is.
|
|
|
344 |
QTextDocument document;
|
348 |
QTextDocument document;
|
345 |
document.setHtml(value.toString());
|
|
|
346 |
painter->save();
|
349 |
painter->save();
|
|
|
350 |
if (opt.state & QStyle::State_Selected) {
|
|
|
351 |
painter->fillRect(opt.rect, opt.palette.highlight());
|
|
|
352 |
// Set the foreground color. The pen approach does
|
|
|
353 |
// not seem to work, probably it's reset by the
|
|
|
354 |
// textdocument. Couldn't use
|
|
|
355 |
// setdefaultstylesheet() either. the div thing is
|
|
|
356 |
// an ugly hack. Works for now
|
|
|
357 |
#if 0
|
|
|
358 |
QPen pen = painter->pen();
|
|
|
359 |
pen.setBrush(opt.palette.brush(QPalette::HighlightedText));
|
|
|
360 |
painter->setPen(pen);
|
|
|
361 |
#else
|
|
|
362 |
text = QString::fromAscii("<div style='color: white'> ") +
|
|
|
363 |
text + QString::fromAscii("</div>");
|
|
|
364 |
#endif
|
|
|
365 |
}
|
347 |
painter->setClipRect(option.rect);
|
366 |
painter->setClipRect(option.rect);
|
348 |
painter->translate(option.rect.topLeft());
|
367 |
painter->translate(option.rect.topLeft());
|
|
|
368 |
document.setHtml(text);
|
349 |
document.drawContents(painter);
|
369 |
document.drawContents(painter);
|
350 |
painter->restore();
|
370 |
painter->restore();
|
|
|
371 |
return;
|
|
|
372 |
}
|
351 |
}
|
373 |
}
|
|
|
374 |
QStyledItemDelegate::paint(painter, option, index);
|
352 |
}
|
375 |
}
|
353 |
};
|
376 |
};
|
354 |
|
377 |
|
355 |
void ResTable::init()
|
378 |
void ResTable::init()
|
356 |
{
|
379 |
{
|