summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2017-02-24 00:56:55 +0100
committerMarc Mutz <marc.mutz@kdab.com>2017-03-08 07:19:53 +0000
commitda730c90a35cce4b24f3cb0cb61246aa87b18e66 (patch)
tree6cec054b4910f661bbadad6621fecdda12dcd50f /src
parenta12a3c6c8c07c0fe52589cea473ac95e556052c7 (diff)
QStyleSheetStyle: introduce class Tampered<QPalette|QFont>
... as a replacement for two QPairs and move some common QFont/QPalette functionality into it. Change-Id: Iaab92130dd54eaa7900ac2048014a80cbd04bfb6 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp35
-rw-r--r--src/widgets/styles/qstylesheetstyle_p.h29
2 files changed, 34 insertions, 30 deletions
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index ba05155b74..0c7a3e692c 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -2594,7 +2594,7 @@ void QStyleSheetStyle::setPalette(QWidget *w)
if (!useStyleSheetPropagationInWidgetStyles || p.resolve() != 0) {
QPalette wp = w->palette();
- styleSheetCaches->customPaletteWidgets.insert(w, qMakePair(wp, p.resolve()));
+ styleSheetCaches->customPaletteWidgets.insert(w, {wp, p.resolve()});
if (useStyleSheetPropagationInWidgetStyles) {
p = p.resolve(wp);
@@ -2614,20 +2614,14 @@ void QStyleSheetStyle::unsetPalette(QWidget *w)
const auto it = styleSheetCaches->customPaletteWidgets.find(w);
if (it != styleSheetCaches->customPaletteWidgets.end()) {
- QPair<QPalette, uint> p = std::move(*it);
+ auto customizedPalette = std::move(*it);
styleSheetCaches->customPaletteWidgets.erase(it);
- QPalette original = p.first;
-
- if (useStyleSheetPropagationInWidgetStyles) {
- original.resolve(original.resolve() & p.second);
-
- QPalette wp = w->palette();
- wp.resolve(wp.resolve() & ~p.second);
- wp.resolve(original);
- wp.resolve(wp.resolve() | original.resolve());
- original = wp;
- }
+ QPalette original;
+ if (useStyleSheetPropagationInWidgetStyles)
+ original = std::move(customizedPalette).reverted(w->palette());
+ else
+ original = customizedPalette.oldWidgetValue;
w->setPalette(original);
QWidget *ew = embeddedWidget(w);
@@ -2657,18 +2651,9 @@ void QStyleSheetStyle::unsetStyleSheetFont(QWidget *w) const
{
const auto it = styleSheetCaches->customFontWidgets.find(w);
if (it != styleSheetCaches->customFontWidgets.end()) {
- QPair<QFont, uint> f = std::move(*it);
+ auto customizedFont = std::move(*it);
styleSheetCaches->customFontWidgets.erase(it);
-
- QFont original = f.first;
- original.resolve(original.resolve() & f.second);
-
- QFont font = w->font();
- font.resolve(font.resolve() & ~f.second);
- font.resolve(original);
- font.resolve(font.resolve() | original.resolve());
-
- w->setFont(font);
+ w->setFont(std::move(customizedFont).reverted(w->font()));
}
}
@@ -5953,7 +5938,7 @@ void QStyleSheetStyle::updateStyleSheetFont(QWidget* w) const
if (rule.font.resolve()) {
QFont wf = w->font();
- styleSheetCaches->customFontWidgets.insert(w, qMakePair(wf, rule.font.resolve()));
+ styleSheetCaches->customFontWidgets.insert(w, {wf, rule.font.resolve()});
QFont font = rule.font.resolve(wf);
font.resolve(wf.resolve() | rule.font.resolve());
diff --git a/src/widgets/styles/qstylesheetstyle_p.h b/src/widgets/styles/qstylesheetstyle_p.h
index 55dd2df329..2d302305bd 100644
--- a/src/widgets/styles/qstylesheetstyle_p.h
+++ b/src/widgets/styles/qstylesheetstyle_p.h
@@ -189,12 +189,31 @@ public:
QHash<const QObject *, QRenderRules> renderRulesCache;
QHash<const void *, QCss::StyleSheet> styleSheetCache; // parsed style sheets
QSet<const QWidget *> autoFillDisabledWidgets;
- // widgets whose palettes and fonts we have tampered. stored value pair is
- // QPair<old widget value, resolve mask of stylesheet value>
- QHash<const QWidget *, QPair<QPalette, uint> > customPaletteWidgets;
- QHash<const QWidget *, QPair<QFont, uint> > customFontWidgets;
+ // widgets with whose palettes and fonts we have tampered:
+ template <typename T>
+ struct Tampered {
+ T oldWidgetValue;
+ uint resolveMask;
+
+ // only call this function on an rvalue *this (it mangles oldWidgetValue)
+ T reverted(T current)
+#ifdef Q_COMPILER_REF_QUALIFIERS
+ &&
+#endif
+ {
+ oldWidgetValue.resolve(oldWidgetValue.resolve() & resolveMask);
+ current.resolve(current.resolve() & ~resolveMask);
+ current.resolve(oldWidgetValue);
+ current.resolve(current.resolve() | oldWidgetValue.resolve());
+ return current;
+ }
+ };
+ QHash<const QWidget *, Tampered<QPalette>> customPaletteWidgets;
+ QHash<const QWidget *, Tampered<QFont>> customFontWidgets;
};
-
+template <typename T>
+class QTypeInfo<QStyleSheetStyleCaches::Tampered<T>>
+ : QTypeInfoMerger<QStyleSheetStyleCaches::Tampered<T>, T> {};
QT_END_NAMESPACE
#endif // QT_NO_STYLE_STYLESHEET