summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@digia.com>2014-03-20 15:40:15 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-20 19:02:53 +0100
commitb69eb02366ad6d8647238f4caf8edfdcaea1b526 (patch)
tree03deef8798cc7def5444cd9d1d17a9ca6833a405
parent75f3d43dbd7ed85a98572d2e3878388fe93ea14c (diff)
downloadqtquickcontrols-b69eb02366ad6d8647238f4caf8edfdcaea1b526.tar.gz
StyleItem: Resolve item palette per item typev5.3.0-beta1
This queries the platform theme for each type, and sets the right palette. This should allow us to remove some workarounds we might have for those cases in desktop style. Change-Id: Ia5f650b46de5418586bc946d63fd394875e90184 Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
-rw-r--r--src/controls/Private/qquickstyleitem.cpp70
-rw-r--r--src/controls/Private/qquickstyleitem_p.h1
2 files changed, 67 insertions, 4 deletions
diff --git a/src/controls/Private/qquickstyleitem.cpp b/src/controls/Private/qquickstyleitem.cpp
index d794d1da..49baa1fd 100644
--- a/src/controls/Private/qquickstyleitem.cpp
+++ b/src/controls/Private/qquickstyleitem.cpp
@@ -264,6 +264,8 @@ void QQuickStyleItem::initStyleOption()
(sizeHint == "small") ? QPlatformTheme::SmallFont :
QPlatformTheme::SystemFont;
+ bool needsResolvePalette = true;
+
switch (m_itemType) {
case Button: {
if (!m_styleoption)
@@ -330,6 +332,8 @@ void QQuickStyleItem::initStyleOption()
opt->features = QStyleOptionViewItem::HasDisplay;
opt->text = text();
opt->textElideMode = Qt::ElideRight;
+ resolvePalette();
+ needsResolvePalette = false;
QPalette pal = m_styleoption->palette;
pal.setBrush(QPalette::Base, Qt::NoBrush);
m_styleoption->palette = pal;
@@ -715,6 +719,9 @@ void QQuickStyleItem::initStyleOption()
if (!m_styleoption)
m_styleoption = new QStyleOption();
+ if (needsResolvePalette)
+ resolvePalette();
+
m_styleoption->styleObject = this;
m_styleoption->direction = qApp->layoutDirection();
@@ -756,6 +763,62 @@ void QQuickStyleItem::initStyleOption()
}
+void QQuickStyleItem::resolvePalette()
+{
+ QPlatformTheme::Palette paletteType = QPlatformTheme::SystemPalette;
+ switch (m_itemType) {
+ case Button:
+ paletteType = QPlatformTheme::ButtonPalette;
+ break;
+ case RadioButton:
+ paletteType = QPlatformTheme::RadioButtonPalette;
+ break;
+ case CheckBox:
+ paletteType = QPlatformTheme::CheckBoxPalette;
+ break;
+ case ComboBox:
+ case ComboBoxItem:
+ paletteType = QPlatformTheme::ComboBoxPalette;
+ break;
+ case ToolBar:
+ case ToolButton:
+ paletteType = QPlatformTheme::ToolButtonPalette;
+ break;
+ case Tab:
+ case TabFrame:
+ paletteType = QPlatformTheme::TabBarPalette;
+ break;
+ case Edit:
+ paletteType = QPlatformTheme::TextEditPalette;
+ break;
+ case GroupBox:
+ paletteType = QPlatformTheme::GroupBoxPalette;
+ break;
+ case Header:
+ paletteType = QPlatformTheme::HeaderPalette;
+ break;
+ case Item:
+ case ItemRow:
+ paletteType = QPlatformTheme::ItemViewPalette;
+ break;
+ case Menu:
+ case MenuItem:
+ paletteType = QPlatformTheme::MenuPalette;
+ break;
+ case MenuBar:
+ case MenuBarItem:
+ paletteType = QPlatformTheme::MenuBarPalette;
+ break;
+ default:
+ break;
+ }
+
+ const QPalette *platformPalette = QGuiApplicationPrivate::platformTheme()->palette(paletteType);
+ if (platformPalette)
+ m_styleoption->palette = *platformPalette;
+ // Defaults to SystemPalette otherwise
+}
+
/*
* Property style
*
@@ -1125,11 +1188,9 @@ QVariant QQuickStyleItem::styleHint(const QString &metric)
if (metric == "comboboxpopup") {
return qApp->style()->styleHint(QStyle::SH_ComboBox_Popup, m_styleoption);
} else if (metric == "highlightedTextColor") {
- QPalette pal = QApplication::palette("QAbstractItemView");
- pal.setCurrentColorGroup(m_styleoption->palette.currentColorGroup());
- return pal.highlightedText().color().name();
+ return m_styleoption->palette.highlightedText().color().name();
} else if (metric == "textColor") {
- QPalette pal = qApp->palette();
+ QPalette pal = m_styleoption->palette;
pal.setCurrentColorGroup(active()? QPalette::Active : QPalette::Inactive);
return pal.text().color().name();
} else if (metric == "focuswidget") {
@@ -1608,6 +1669,7 @@ void QQuickStyleItem::paint(QPainter *painter)
frame.midLineWidth = 0;
frame.rect = m_styleoption->rect;
frame.styleObject = this;
+ frame.palette = m_styleoption->palette;
qApp->style()->drawPrimitive(QStyle::PE_FrameMenu, &frame, painter);
}
}
diff --git a/src/controls/Private/qquickstyleitem_p.h b/src/controls/Private/qquickstyleitem_p.h
index a13cd4cc..8d296f25 100644
--- a/src/controls/Private/qquickstyleitem_p.h
+++ b/src/controls/Private/qquickstyleitem_p.h
@@ -192,6 +192,7 @@ public:
void setContentHeight(int arg);
virtual void initStyleOption ();
+ void resolvePalette();
Q_INVOKABLE qreal textWidth(const QString &);
Q_INVOKABLE qreal textHeight(const QString &);