summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qpalette.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2012-02-10 17:17:36 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-17 11:44:29 +0100
commit4cf0deef73ff2f24a80622ec5f391d10c74ea6c7 (patch)
treec34fb7c1e9b9488ca42ce8d681876515194aba2d /src/gui/kernel/qpalette.cpp
parent71bad3e8180297351b143271856b4b6732169f39 (diff)
Add palette() and further hints to QtGui/QPlatformTheme.
- Move palette() from deprecated QtWidgets/QGuiPlatformPlugin to QtGui/QPlatformTheme, Make it return a const * since QPalette does not have isNull(). - Initialize QGuiApplication::palette() and QApplication::systemPalette() from it. - Do not initialize QPalette from QGuiApplication::palette() unless app_pal is non-null (default to Qt::black if it is 0). This avoids initialization order crashes/recursions in the QPA plugin. Streamline initialization function. - Remove styleName(), systemIconThemeName() and iconSearchPaths() from QGuiPlatformPlugin and re-add them as QPlatformTheme::themeHint(). - Remove styleHint() from QGuiPlatformPlugin, add it to QPlatformTheme::themeHint(). - Add UNIX themes with factory function (Generic, KDE, Gnome), taking it from Qt 4.8 code (stripping the KDE 3 code). - Implement Windows palettes. Task-number: QTBUG-24204 Change-Id: Ie27ec035df4f84c42deaffc4816b2e53ce705462 Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
Diffstat (limited to 'src/gui/kernel/qpalette.cpp')
-rw-r--r--src/gui/kernel/qpalette.cpp62
1 files changed, 33 insertions, 29 deletions
diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp
index 627731ff20..d5b17fa665 100644
--- a/src/gui/kernel/qpalette.cpp
+++ b/src/gui/kernel/qpalette.cpp
@@ -41,6 +41,7 @@
#include "qpalette.h"
#include "qguiapplication.h"
+#include "qguiapplication_p.h"
#include "qdatastream.h"
#include "qvariant.h"
#include "qdebug.h"
@@ -64,6 +65,29 @@ static QColor qt_mix_colors(QColor a, QColor b)
(a.blue() + b.blue()) / 2, (a.alpha() + b.alpha()) / 2);
}
+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 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);
+ pal.setColorGroup(QPalette::Inactive, foregroundBrush, buttonBrush, buttonBrushLight150,
+ buttonBrushDark, buttonBrushDark150, foregroundBrush, whiteBrush,
+ baseBrush, buttonBrush);
+ pal.setColorGroup(QPalette::Disabled, buttonBrushDark, buttonBrush, buttonBrushLight150,
+ buttonBrushDark, buttonBrushDark150, buttonBrushDark,
+ whiteBrush, buttonBrush, buttonBrush);
+}
+
/*!
\fn const QColor &QPalette::color(ColorRole role) const
@@ -488,40 +512,20 @@ static QColor qt_mix_colors(QColor a, QColor b)
\sa QApplication::setPalette(), QApplication::palette()
*/
QPalette::QPalette()
- : d(QGuiApplication::palette().d),
- current_group(Active),
- resolve_mask(0)
-{
- d->ref.ref();
-}
-
-static void qt_palette_from_color(QPalette &pal, const QColor & button)
+ : d(0), current_group(Active), resolve_mask(0)
{
- QColor bg = button,
- btn = button,
- fg, base;
- int h, s, v;
- bg.getHsv(&h, &s, &v);
- if(v > 128) {
- fg = Qt::black;
- base = Qt::white;
+ // Initialize to application palette if present, else default to black.
+ // This makes it possible to instantiate QPalette outside QGuiApplication,
+ // for example in the platform plugins.
+ if (QGuiApplicationPrivate::app_pal) {
+ d = QGuiApplicationPrivate::app_pal->d;
+ d->ref.ref();
} else {
- fg = Qt::white;
- base = Qt::black;
+ init();
+ qt_palette_from_color(*this, Qt::black);
}
- //inactive and active are the same..
- pal.setColorGroup(QPalette::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));
- pal.setColorGroup(QPalette::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));
- pal.setColorGroup(QPalette::Disabled, QBrush(btn.darker()), QBrush(btn), QBrush(btn.lighter(150)),
- QBrush(btn.darker()), QBrush(btn.darker(150)), QBrush(btn.darker()),
- QBrush(Qt::white), QBrush(bg), QBrush(bg));
}
-
/*!
Constructs a palette from the \a button color. The other colors are
automatically calculated, based on this color. \c Window will be