From e9b6eb7795f5f87b705af0cae855c46c5c135297 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Thu, 15 Nov 2012 16:45:04 +0100 Subject: [PATCH] Improve highligted colorization on mac with Fusion style This mimics the platform behavior of using blue color when the system palette is in use. Change-Id: I9ad6a552614a3466a930ad5b28fc70d9343d2022 Reviewed-by: Gabriel de Dietrich --- src/widgets/styles/qfusionstyle.cpp | 2 +- src/widgets/styles/qfusionstyle_p.h | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 8e52a4b..4121292 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -1417,7 +1417,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio QRect leftRect; QRect rect = bar->rect; QColor textColor = option->palette.text().color(); - QColor alternateTextColor = option->palette.highlightedText().color(); + QColor alternateTextColor = d->highlightedText(option->palette); painter->save(); bool vertical = false, inverted = false; diff --git a/src/widgets/styles/qfusionstyle_p.h b/src/widgets/styles/qfusionstyle_p.h index 1c8089e..affb85b 100644 --- a/src/widgets/styles/qfusionstyle_p.h +++ b/src/widgets/styles/qfusionstyle_p.h @@ -55,6 +55,8 @@ #include "qcommonstyle.h" #include "qcommonstyle_p.h" +#include +#include "private/qguiapplication_p.h" #ifndef QT_NO_STYLE_FUSION @@ -83,10 +85,32 @@ public: return QColor(255, 255, 255, 30); } + // On mac we want a standard blue color used when the system palette is used + bool isMacSystemPalette(const QPalette &pal) const { + Q_UNUSED(pal); +#ifdef Q_OS_MAC + const QPalette *themePalette = QGuiApplicationPrivate::platformTheme()->palette(); + if (themePalette->color(QPalette::Normal, QPalette::Highlight) == + pal.color(QPalette::Normal, QPalette::Highlight) && + themePalette->color(QPalette::Normal, QPalette::HighlightedText) == + pal.color(QPalette::Normal, QPalette::HighlightedText)) + return true; +#endif + return false; + } + QColor highlight(const QPalette &pal) const { + if (isMacSystemPalette(pal)) + return QColor(60, 140, 230); return pal.color(QPalette::Active, QPalette::Highlight); } + QColor highlightedText(const QPalette &pal) const { + if (isMacSystemPalette(pal)) + return Qt::white; + return pal.color(QPalette::Active, QPalette::HighlightedText); + } + QColor outline(const QPalette &pal) const { if (!pal.window().texture().isNull()) return QColor(0, 0, 0, 160); @@ -94,7 +118,7 @@ public: } QColor highlightedOutline(const QPalette &pal) const { - QColor highlightedOutline = pal.highlight().color().darker(125); + QColor highlightedOutline = highlight(pal).darker(125); if (highlightedOutline.value() > 160) highlightedOutline.setHsl(highlightedOutline.hue(), highlightedOutline.saturation(), 160); return highlightedOutline; @@ -109,7 +133,7 @@ public: QColor buttonColor(const QPalette &pal) const { QColor buttonColor = pal.button().color(); int val = qGray(buttonColor.rgb()); - buttonColor = buttonColor.lighter(100 + qMax(0, (180- val)/6)); + buttonColor = buttonColor.lighter(100 + qMax(1, (180 - val)/6)); buttonColor.setHsv(buttonColor.hue(), buttonColor.saturation() * 0.75, buttonColor.value()); return buttonColor; } -- 2.7.4