Core: Improved theme-awareness in application menu painting

Using theme colors rather than hard-coded ones and at the same some
simplification.

This is needed for an upcoming "Flat Light" theme.

Change-Id: I8a8715a16d1b246c5228978633143eb64d371701
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Alessandro Portale
2016-06-17 19:00:59 +02:00
committed by Alessandro Portale
parent 6750607244
commit 3b30617758
3 changed files with 20 additions and 13 deletions

View File

@@ -64,6 +64,18 @@ QColor StyleHelper::mergedColors(const QColor &colorA, const QColor &colorB, int
return tmp;
}
QColor StyleHelper::alphaBlendedColors(const QColor &colorA, const QColor &colorB)
{
const QRgb base = colorA.rgba();
const QRgb overlay = colorB.rgba();
const qreal overlayIntensity = qAlpha(overlay) / 255.0;
return qRgba(
qMin(qRed(base) + qRound(qRed(overlay) * overlayIntensity), 0xff),
qMin(qGreen(base) + qRound(qGreen(overlay) * overlayIntensity), 0xff),
qMin(qBlue(base) + qRound(qBlue(overlay) * overlayIntensity), 0xff),
qMin(qAlpha(base) + qAlpha(overlay), 0xff));
}
qreal StyleHelper::sidebarFontSize()
{
return HostOsInfo::isMacHost() ? 10 : 7.5;

View File

@@ -61,6 +61,7 @@ public:
static QColor borderColor(bool lightColored = false);
static QColor buttonTextColor() { return QColor(0x4c4c4c); }
static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50);
static QColor alphaBlendedColors(const QColor &colorA, const QColor &colorB);
static QColor sidebarHighlight() { return QColor(255, 255, 255, 40); }
static QColor sidebarShadow() { return QColor(0, 0, 0, 40); }

View File

@@ -677,24 +677,18 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
if (act) {
// Fill|
if (creatorTheme()->flag(Theme::FlatMenuBar)) {
painter->fillRect(option->rect, creatorTheme()->color(Theme::FancyToolButtonHoverColor));
} else {
QColor baseColor = StyleHelper::baseColor();
QLinearGradient grad(option->rect.topLeft(), option->rect.bottomLeft());
grad.setColorAt(0, baseColor.lighter(120));
grad.setColorAt(1, baseColor.lighter(130));
painter->fillRect(option->rect, grad);
}
const QColor fillColor = StyleHelper::alphaBlendedColors(
StyleHelper::baseColor(), creatorTheme()->color(Theme::FancyToolButtonHoverColor));
painter->fillRect(option->rect, fillColor);
QPalette pal = mbi->palette;
uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
if (!styleHint(SH_UnderlineShortcut, mbi, widget))
alignment |= Qt::TextHideMnemonic;
pal.setBrush(QPalette::Text, dis ? Qt::gray : QColor(0, 0, 0, 60));
drawItemText(painter, item.rect.translated(0, 1), alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text);
pal.setBrush(QPalette::Text, dis ? Qt::gray : Qt::white);
drawItemText(painter, item.rect, alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text);
pal.setBrush(QPalette::Text, creatorTheme()->color(dis
? Theme::IconsDisabledColor
: Theme::PanelTextColorLight));
drawItemText(painter, item.rect, alignment, pal, !dis, mbi->text, QPalette::Text);
}
}
painter->restore();