restable highlighting: fix background and foreground colours for selected rows
This commit is contained in:
parent
44528876e7
commit
030415e850
@ -330,25 +330,48 @@ void RecollModel::sort(int column, Qt::SortOrder order)
|
|||||||
class ResTableDelegate: public QStyledItemDelegate {
|
class ResTableDelegate: public QStyledItemDelegate {
|
||||||
public:
|
public:
|
||||||
ResTableDelegate(QObject *parent) : QStyledItemDelegate(parent) {}
|
ResTableDelegate(QObject *parent) : QStyledItemDelegate(parent) {}
|
||||||
|
|
||||||
|
// We might want to optimize by passing the data to the base
|
||||||
|
// method if the text does not contain any term matches. Would
|
||||||
|
// need a modif to plaintorich to return the match count (easy),
|
||||||
|
// and a way to pass an indicator from data(), a bit more
|
||||||
|
// difficult. Anyway, the display seems fast enough as is.
|
||||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||||
const QModelIndex &index) const
|
const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
|
QStyleOptionViewItemV4 opt = option;
|
||||||
|
initStyleOption(&opt, index);
|
||||||
QVariant value = index.data(Qt::DisplayRole);
|
QVariant value = index.data(Qt::DisplayRole);
|
||||||
if (value.isValid() && !value.isNull()) {
|
if (value.isValid() && !value.isNull()) {
|
||||||
// We might possibly want to optimize by passing the data
|
QString text = value.toString();
|
||||||
// to the base method if the text does not contain any
|
if (!text.isEmpty()) {
|
||||||
// term matches. Would need a modif to plaintorich to
|
QTextDocument document;
|
||||||
// return the match count (easy), and a way to pass an
|
painter->save();
|
||||||
// indicator from data(), a bit more difficult. Anyway,
|
if (opt.state & QStyle::State_Selected) {
|
||||||
// the display seems fast enough as is.
|
painter->fillRect(opt.rect, opt.palette.highlight());
|
||||||
QTextDocument document;
|
// Set the foreground color. The pen approach does
|
||||||
document.setHtml(value.toString());
|
// not seem to work, probably it's reset by the
|
||||||
painter->save();
|
// textdocument. Couldn't use
|
||||||
painter->setClipRect(option.rect);
|
// setdefaultstylesheet() either. the div thing is
|
||||||
painter->translate(option.rect.topLeft());
|
// an ugly hack. Works for now
|
||||||
document.drawContents(painter);
|
#if 0
|
||||||
painter->restore();
|
QPen pen = painter->pen();
|
||||||
|
pen.setBrush(opt.palette.brush(QPalette::HighlightedText));
|
||||||
|
painter->setPen(pen);
|
||||||
|
#else
|
||||||
|
text = QString::fromAscii("<div style='color: white'> ") +
|
||||||
|
text + QString::fromAscii("</div>");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
painter->setClipRect(option.rect);
|
||||||
|
painter->translate(option.rect.topLeft());
|
||||||
|
document.setHtml(text);
|
||||||
|
document.drawContents(painter);
|
||||||
|
painter->restore();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
QStyledItemDelegate::paint(painter, option, index);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user