[PATCH] modeldelegates.cpp: add custom highlight drawing in location items

Lubomir I. Ivanov neolit123 at gmail.com
Wed Oct 7 07:13:00 PDT 2015


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

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 at gmail.com>
---

untested on Linux and OSX!
---
 qt-ui/modeldelegates.cpp | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
index 5ec851a..7bdb699 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()) {
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list