From b071aeccc0969d3a59db95fb909caa500b800490 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 21 Feb 2012 12:26:58 +0100 Subject: Streamline QPalette initialization code. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Share the brushes to reduce memory usage by QBrushData. Change-Id: I04044b4c54b1f6a35a73d8bb4d299661ec0136a5 Reviewed-by: Samuel Rødal --- src/gui/kernel/qpalette.cpp | 58 +++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp index d5b17fa665..6d3d1c9580 100644 --- a/src/gui/kernel/qpalette.cpp +++ b/src/gui/kernel/qpalette.cpp @@ -70,13 +70,14 @@ static void qt_palette_from_color(QPalette &pal, const QColor &button) int h, s, v; button.getHsv(&h, &s, &v); // inactive and active are the same.. - const QBrush baseBrush = QBrush(v > 128 ? Qt::white : Qt::black); - const QBrush foregroundBrush = QBrush(v > 128 ? Qt::black : Qt::white); + const QBrush whiteBrush = QBrush(Qt::white); + const QBrush blackBrush = QBrush(Qt::black); + const QBrush baseBrush = v > 128 ? whiteBrush : blackBrush; + const QBrush foregroundBrush = v > 128 ? blackBrush : whiteBrush; const QBrush buttonBrush = QBrush(button); const QBrush buttonBrushDark = QBrush(button.darker()); const QBrush buttonBrushDark150 = QBrush(button.darker(150)); const QBrush buttonBrushLight150 = QBrush(button.lighter(150)); - const QBrush whiteBrush = QBrush(Qt::white); pal.setColorGroup(QPalette::Active, foregroundBrush, buttonBrush, buttonBrushLight150, buttonBrushDark, buttonBrushDark150, foregroundBrush, whiteBrush, baseBrush, buttonBrush); @@ -578,9 +579,11 @@ QPalette::QPalette(const QColor &windowText, const QColor &window, const QColor &text, const QColor &base) { init(); - setColorGroup(All, QBrush(windowText), QBrush(window), QBrush(light), - QBrush(dark), QBrush(mid), QBrush(text), QBrush(light), - QBrush(base), QBrush(window)); + const QBrush windowBrush(window); + const QBrush lightBrush(light); + setColorGroup(All, QBrush(windowText), windowBrush, lightBrush, + QBrush(dark), QBrush(mid), QBrush(text), lightBrush, + QBrush(base), windowBrush); } /*! @@ -591,28 +594,31 @@ QPalette::QPalette(const QColor &windowText, const QColor &window, QPalette::QPalette(const QColor &button, const QColor &window) { init(); - QColor bg = window, btn = button, fg, base, disfg; int h, s, v; - bg.getHsv(&h, &s, &v); - if(v > 128) { - fg = Qt::black; - base = Qt::white; - disfg = Qt::darkGray; - } else { - fg = Qt::white; - base = Qt::black; - disfg = Qt::darkGray; - } + window.getHsv(&h, &s, &v); + + const QBrush windowBrush = QBrush(window); + const QBrush whiteBrush = QBrush(Qt::white); + const QBrush blackBrush = QBrush(Qt::black); + const QBrush baseBrush = v > 128 ? whiteBrush : blackBrush; + const QBrush foregroundBrush = v > 128 ? blackBrush : whiteBrush; + const QBrush disabledForeground = QBrush(Qt::darkGray); + + const QBrush buttonBrush = QBrush(button); + const QBrush buttonBrushDark = QBrush(button.darker()); + const QBrush buttonBrushDark150 = QBrush(button.darker(150)); + const QBrush buttonBrushLight150 = QBrush(button.lighter(150)); + //inactive and active are identical - setColorGroup(Inactive, QBrush(fg), QBrush(btn), QBrush(btn.lighter(150)), QBrush(btn.darker()), - QBrush(btn.darker(150)), QBrush(fg), QBrush(Qt::white), QBrush(base), - QBrush(bg)); - setColorGroup(Active, QBrush(fg), QBrush(btn), QBrush(btn.lighter(150)), QBrush(btn.darker()), - QBrush(btn.darker(150)), QBrush(fg), QBrush(Qt::white), QBrush(base), - QBrush(bg)); - setColorGroup(Disabled, QBrush(disfg), QBrush(btn), QBrush(btn.lighter(150)), - QBrush(btn.darker()), QBrush(btn.darker(150)), QBrush(disfg), - QBrush(Qt::white), QBrush(base), QBrush(bg)); + setColorGroup(Inactive, foregroundBrush, buttonBrush, buttonBrushLight150, buttonBrushDark, + buttonBrushDark150, foregroundBrush, whiteBrush, baseBrush, + windowBrush); + setColorGroup(Active, foregroundBrush, buttonBrush, buttonBrushLight150, buttonBrushDark, + buttonBrushDark150, foregroundBrush, whiteBrush, baseBrush, + windowBrush); + setColorGroup(Disabled, disabledForeground, buttonBrush, buttonBrushLight150, + buttonBrushDark, buttonBrushDark150, disabledForeground, + whiteBrush, baseBrush, windowBrush); } /*! -- cgit v1.2.3