aboutsummaryrefslogtreecommitdiffstats
path: root/src/controls
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2016-03-11 13:40:45 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2016-03-15 20:04:58 +0000
commit54a2a35f17d5e5d1793af63b76993a583e10ab41 (patch)
tree4608034b8431148367d2fef0f26be014427721e6 /src/controls
parent28ce9872fd83e82c8ece0c70624c45ea2be5c58d (diff)
Change style inheritance for popups
The decision to make popups inherit theme & accent from its parent item was driven by ComboBox. However, in many cases it has an undesired side effect, so we've changed Popup to inherit its style attributes from the parent window instead, just like we did for fonts. The only exception to this is ComboBox, where the popup is an integral part of the control. This special case is now handled in the respective style implementation. A concrete example is that we can now specify dark theme by default for Material style ToolBar to get a better matching light text against the colorful background. In Gallery, this won't effect the options menu, which is a child of a ToolButton. The menu retains light theme along the rest of the application. Change-Id: Ibdc8fcf5b5fa258d853410a9b40368472424a8c6 Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src/controls')
-rw-r--r--src/controls/qquickstyle.cpp44
-rw-r--r--src/controls/qquickstyle_p.h2
2 files changed, 31 insertions, 15 deletions
diff --git a/src/controls/qquickstyle.cpp b/src/controls/qquickstyle.cpp
index 76524629..c38950d8 100644
--- a/src/controls/qquickstyle.cpp
+++ b/src/controls/qquickstyle.cpp
@@ -56,22 +56,29 @@ static QQuickStyle *findParentStyle(const QMetaObject *type, QObject *object)
{
QQuickItem *item = qobject_cast<QQuickItem *>(object);
if (item) {
- // lookup parent items
+ // lookup parent items and popups
QQuickItem *parent = item->parentItem();
while (parent) {
QQuickStyle *style = attachedStyle(type, parent);
if (style)
return style;
+
+ QQuickPopup *popup = qobject_cast<QQuickPopup *>(parent->parent());
+ if (popup)
+ return attachedStyle(type, popup);
+
parent = parent->parentItem();
}
// fallback to item's window
- QQuickWindow *window = item->window();
- if (window) {
- QQuickStyle *style = attachedStyle(type, window);
- if (style)
- return style;
- }
+ QQuickStyle *style = attachedStyle(type, item->window());
+ if (style)
+ return style;
+ } else {
+ // lookup popup's window
+ QQuickPopup *popup = qobject_cast<QQuickPopup *>(object);
+ if (popup)
+ return attachedStyle(type, popup->popupItem()->window());
}
// lookup parent window
@@ -138,14 +145,14 @@ static QList<QQuickStyle *> findChildStyles(const QMetaObject *type, QObject *ob
QQuickStyle::QQuickStyle(QObject *parent) : QObject(parent)
{
- QQuickItem *item = qobject_cast<QQuickItem *>(parent);
+ QQuickItem *item = parentItem();
if (item)
QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Parent);
}
QQuickStyle::~QQuickStyle()
{
- QQuickItem *item = qobject_cast<QQuickItem *>(parent());
+ QQuickItem *item = parentItem();
if (item)
QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Parent);
@@ -167,6 +174,17 @@ QSharedPointer<QSettings> QQuickStyle::settings(const QString &group)
return QSharedPointer<QSettings>();
}
+QQuickItem *QQuickStyle::parentItem() const
+{
+ QQuickItem *item = qobject_cast<QQuickItem *>(parent());
+ if (!item) {
+ QQuickPopup *popup = qobject_cast<QQuickPopup *>(parent());
+ if (popup)
+ item = popup->popupItem();
+ }
+ return item;
+}
+
QList<QQuickStyle *> QQuickStyle::childStyles() const
{
return m_childStyles;
@@ -209,12 +227,8 @@ void QQuickStyle::parentStyleChange(QQuickStyle *newParent, QQuickStyle *oldPare
void QQuickStyle::itemParentChanged(QQuickItem *item, QQuickItem *parent)
{
- QQuickStyle *style = attachedStyle(metaObject(), item);
- if (style) {
- QQuickStyle *parentStyle = findParentStyle(metaObject(), parent);
- if (parentStyle)
- style->setParentStyle(parentStyle);
- }
+ Q_UNUSED(parent);
+ setParentStyle(findParentStyle(metaObject(), item));
}
QT_END_NAMESPACE
diff --git a/src/controls/qquickstyle_p.h b/src/controls/qquickstyle_p.h
index 02ee667a..c5bfed0f 100644
--- a/src/controls/qquickstyle_p.h
+++ b/src/controls/qquickstyle_p.h
@@ -72,6 +72,8 @@ public:
protected:
void init();
+ QQuickItem *parentItem() const;
+
QList<QQuickStyle *> childStyles() const;
QQuickStyle *parentStyle() const;