summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2016-02-08 12:07:56 +0100
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2016-02-10 12:43:40 +0000
commit6cb462d7aa063e5d7bcf3877fa7e7e1c4cacf3ff (patch)
tree468ed5820c2ab1022fd3520d453636cd4f232a5e
parent8b4ac65e2913bd7fbdd996ca290b129659f89a9e (diff)
QWindowsXPStyle: Introduce utility function for QLineEdit's palette.
Introduce QWindowsXPStylePrivate::isLineEditBaseColorSet() checking whether the base color has been set in the widget's palette taking into account the QSpinBox special case and simplify the code accordingly. Task-number: QTBUG-40634 Change-Id: I0e7527031b333d71727fbd30db6dd80aa715c9ab Reviewed-by: Andy Shaw <andy.shaw@theqtcompany.com>
-rw-r--r--src/widgets/styles/qwindowsvistastyle.cpp21
-rw-r--r--src/widgets/styles/qwindowsxpstyle.cpp38
-rw-r--r--src/widgets/styles/qwindowsxpstyle_p_p.h1
3 files changed, 21 insertions, 39 deletions
diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp
index 3fa0fc899d..52fc2e4af2 100644
--- a/src/widgets/styles/qwindowsvistastyle.cpp
+++ b/src/widgets/styles/qwindowsvistastyle.cpp
@@ -498,26 +498,9 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt
case PE_PanelLineEdit:
if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
- QBrush bg;
- bool usePalette = false;
bool isEnabled = option->state & State_Enabled;
- uint resolve_mask = panel->palette.resolve();
- if (widget) {
- // Since spin box includes a line edit we need to resolve the palette mask also from
- // the parent, as while the color is always correct on the palette supplied by panel,
- // the mask can still be empty. If either mask specifies custom base color, use that.
-#ifndef QT_NO_SPINBOX
- if (QAbstractSpinBox *spinbox = qobject_cast<QAbstractSpinBox*>(widget->parentWidget()))
- resolve_mask |= spinbox->palette().resolve();
-#endif // QT_NO_SPINBOX
- }
- if (resolve_mask & (1 << QPalette::Base)) {
- // Base color is set for this widget, so use it
- bg = panel->palette.brush(QPalette::Base);
- usePalette = true;
- }
- if (usePalette) {
- painter->fillRect(panel->rect, bg);
+ if (QWindowsXPStylePrivate::isLineEditBaseColorSet(option, widget)) {
+ painter->fillRect(panel->rect, panel->palette.brush(QPalette::Base));
} else {
int partId = EP_BACKGROUND;
int stateId = EBS_NORMAL;
diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp
index c350e82c69..5b01312dfb 100644
--- a/src/widgets/styles/qwindowsxpstyle.cpp
+++ b/src/widgets/styles/qwindowsxpstyle.cpp
@@ -371,6 +371,22 @@ bool QWindowsXPStylePrivate::isItemViewDelegateLineEdit(const QWidget *widget)
&& parent2->inherits("QAbstractItemView");
}
+// Returns whether base color is set for this widget
+bool QWindowsXPStylePrivate::isLineEditBaseColorSet(const QStyleOption *option, const QWidget *widget)
+{
+ uint resolveMask = option->palette.resolve();
+ if (widget) {
+ // Since spin box includes a line edit we need to resolve the palette mask also from
+ // the parent, as while the color is always correct on the palette supplied by panel,
+ // the mask can still be empty. If either mask specifies custom base color, use that.
+#ifndef QT_NO_SPINBOX
+ if (const QAbstractSpinBox *spinbox = qobject_cast<QAbstractSpinBox*>(widget->parentWidget()))
+ resolveMask |= spinbox->palette().resolve();
+#endif // QT_NO_SPINBOX
+ }
+ return (resolveMask & (1 << QPalette::Base)) != 0;
+}
+
/*! \internal
This function will always return a valid window handle, and might
create a limbo widget to do so.
@@ -1600,30 +1616,12 @@ case PE_Frame:
themeNumber = QWindowsXPStylePrivate::EditTheme;
partId = EP_EDITTEXT;
noBorder = true;
- QBrush bg;
- bool usePalette = false;
bool isEnabled = flags & State_Enabled;
- uint resolve_mask = panel->palette.resolve();
-
-#ifndef QT_NO_SPINBOX
- // Since spin box includes a line edit we need to resolve the palette mask also from
- // the parent, as while the color is always correct on the palette supplied by panel,
- // the mask can still be empty. If either mask specifies custom base color, use that.
- if (widget) {
- if (QAbstractSpinBox *spinbox = qobject_cast<QAbstractSpinBox*>(widget->parentWidget()))
- resolve_mask |= spinbox->palette().resolve();
- }
-#endif // QT_NO_SPINBOX
- if (resolve_mask & (1 << QPalette::Base)) {
- // Base color is set for this widget, so use it
- bg = panel->palette.brush(QPalette::Base);
- usePalette = true;
- }
stateId = isEnabled ? ETS_NORMAL : ETS_DISABLED;
- if (usePalette) {
- p->fillRect(panel->rect, bg);
+ if (QWindowsXPStylePrivate::isLineEditBaseColorSet(option, widget)) {
+ p->fillRect(panel->rect, panel->palette.brush(QPalette::Base));
} else {
XPThemeData theme(0, p, themeNumber, partId, stateId, rect);
if (!theme.isValid()) {
diff --git a/src/widgets/styles/qwindowsxpstyle_p_p.h b/src/widgets/styles/qwindowsxpstyle_p_p.h
index 5ee418f278..5a0abc1d78 100644
--- a/src/widgets/styles/qwindowsxpstyle_p_p.h
+++ b/src/widgets/styles/qwindowsxpstyle_p_p.h
@@ -415,6 +415,7 @@ public:
static QString themeName(int theme);
static inline bool hasTheme(int theme) { return theme >= 0 && theme < NThemes && m_themes[theme]; }
static bool isItemViewDelegateLineEdit(const QWidget *widget);
+ static bool isLineEditBaseColorSet(const QStyleOption *option, const QWidget *widget);
QIcon dockFloat, dockClose;