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 <gabriel.dedietrich@digia.com>
bb10
Jens Bache-Wiig 2012-11-15 16:45:04 +01:00 committed by The Qt Project
parent f7d99ad50f
commit e9b6eb7795
2 changed files with 27 additions and 3 deletions

View File

@ -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;

View File

@ -55,6 +55,8 @@
#include "qcommonstyle.h"
#include "qcommonstyle_p.h"
#include <qpa/qplatformtheme.h>
#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;
}