diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2015-10-07 17:13:00 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-10-07 18:35:37 +0100 |
commit | afed054d82776874592f02fe0c89966a69cbe993 (patch) | |
tree | 5b1a5b4577d206f9d72aad426dfea1d10a5cc436 /qt-ui/modeldelegates.cpp | |
parent | 2f89a2e6e27a9c659e5f7f661b2b09a9178f550a (diff) | |
download | subsurface-afed054d82776874592f02fe0c89966a69cbe993.tar.gz |
modeldelegates.cpp: add custom highlight drawing in location items
There is a problem in LocationFilterDelegate::paint(), which
can manifest as very light background with white text in the
combo box from which the user selects a location - a
Windows 7 test case.
The main offenders are the drawControl() call which draws the
selected item background very bright and the fact that
the highlightText() is returning white.
It seems as if the combination of these is just wrong, theme
wise.
e5fa424a and 44762c42 fix that by branching Windows by version,
but do not cover the case where the user can use a custom theme -
e.g. dark selection highlight on Windows 7.
This patch skips drawControl() and draws the highlighted item
background manually. It makes it look similar to the small
tag highlights in TagWidget.
The patch adjust slightly the X offset of the drawn text.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/modeldelegates.cpp')
-rw-r--r-- | qt-ui/modeldelegates.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp index 5ec851a20..7bdb69933 100644 --- a/qt-ui/modeldelegates.cpp +++ b/qt-ui/modeldelegates.cpp @@ -558,28 +558,34 @@ print_part: fontBigger.setPointSize(fontBigger.pointSize() + 1); fontBigger.setBold(true); - QPen textPen; -#ifdef WIN32 - if(QSysInfo::windowsVersion() > QSysInfo::WV_VISTA) - textPen = QPen(option.palette.text(), 1); - else -#endif - textPen = QPen(option.state & QStyle::State_Selected ? option.palette.brightText() : option.palette.text(), 1); + QPen textPen = QPen(option.state & QStyle::State_Selected ? option.palette.highlightedText().color() : option.palette.text().color(), 1); initStyleOption(&opt, index); opt.text = QString(); opt.icon = QIcon(); painter->setClipRect(option.rect); - qApp->style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, NULL); painter->save(); + if (option.state & QStyle::State_Selected) { + painter->setPen(QPen(opt.palette.highlight().color().darker())); + painter->setBrush(opt.palette.highlight()); + const qreal pad = 1.0; + const qreal pad2 = pad * 2.0; + const qreal rounding = 5.0; + painter->drawRoundedRect(option.rect.x() + pad, + option.rect.y() + pad, + option.rect.width() - pad2, + option.rect.height() - pad2, + rounding, rounding); + } painter->setPen(textPen); painter->setFont(fontBigger); - painter->drawText(option.rect.x(),option.rect.y() + fmBigger.boundingRect("YH").height(), diveSiteName); + const qreal textPad = 5.0; + painter->drawText(option.rect.x() + textPad, option.rect.y() + fmBigger.boundingRect("YH").height(), diveSiteName); double pointSize = fontSmaller.pointSizeF(); fontSmaller.setPointSizeF(0.9 * pointSize); painter->setFont(fontSmaller); - painter->drawText(option.rect.x(),option.rect.y() + fmBigger.boundingRect("YH").height() * 2, bottomText); + painter->drawText(option.rect.x() + textPad, option.rect.y() + fmBigger.boundingRect("YH").height() * 2, bottomText); painter->restore(); if (!icon.isNull()) { |