aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2016-01-07 15:52:08 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2016-01-08 16:55:51 +0000
commita3dddf0471452448003cfe6c6802e3ccaf565b5d (patch)
treefb570cfabaa581a6446def56169281cb6beb9a43 /src
parent476f7944d24657055db6384f11eacf7589687f76 (diff)
Fix style inheritance for popups
Change-Id: I7bc36cb68e8d668fff2270e018de7eb1c71ccd20 Task-number: QTBUG-50347 Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/controls/controls.pro2
-rw-r--r--src/controls/qquickstyle.cpp68
-rw-r--r--src/imports/controls/material/material.pro2
-rw-r--r--src/imports/controls/universal/universal.pro2
-rw-r--r--src/src.pro1
5 files changed, 43 insertions, 32 deletions
diff --git a/src/controls/controls.pro b/src/controls/controls.pro
index ecb3a9d6..cb9a8683 100644
--- a/src/controls/controls.pro
+++ b/src/controls/controls.pro
@@ -3,7 +3,7 @@ MODULE = labscontrols
CONFIG += static internal_module
QT += quick
-QT_PRIVATE += core-private gui-private qml-private quick-private
+QT_PRIVATE += core-private gui-private qml-private quick-private labstemplates-private
DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII
diff --git a/src/controls/qquickstyle.cpp b/src/controls/qquickstyle.cpp
index 5e1085c6..58563954 100644
--- a/src/controls/qquickstyle.cpp
+++ b/src/controls/qquickstyle.cpp
@@ -40,6 +40,7 @@
#include <QtCore/qsettings.h>
#include <QtCore/qfileselector.h>
#include <QtQuick/private/qquickitem_p.h>
+#include <QtLabsTemplates/private/qquickpopup_p.h>
QT_BEGIN_NAMESPACE
@@ -53,42 +54,33 @@ static QQuickStyle *attachedStyle(const QMetaObject *type, QObject *object, bool
return qobject_cast<QQuickStyle *>(qmlAttachedPropertiesObject(&idx, object, type, create));
}
-static QQuickStyle *findParentStyle(const QMetaObject *type, QObject *object)
+static QQuickStyle *findParentStyle(const QMetaObject *type, QObject *parent)
{
- QQuickItem *item = qobject_cast<QQuickItem *>(object);
+ if (!parent)
+ return Q_NULLPTR;
+
+ QQuickStyle *style = attachedStyle(type, parent);
+ if (style)
+ return style;
+
+ QQuickItem *item = qobject_cast<QQuickItem *>(parent);
if (item) {
// lookup parent items
QQuickItem *parent = item->parentItem();
- while (parent) {
- QQuickStyle *style = attachedStyle(type, parent);
- if (style)
- return style;
- parent = parent->parentItem();
- }
+ if (parent)
+ return findParentStyle(type, parent);
// fallback to item's window
- QQuickWindow *window = item->window();
- if (window) {
- QQuickStyle *style = attachedStyle(type, window);
- if (style)
- return style;
- }
+ return findParentStyle(type, item->window());
}
- // lookup parent window
- QQuickWindow *window = qobject_cast<QQuickWindow *>(object);
- if (window) {
- QQuickWindow *parentWindow = qobject_cast<QQuickWindow *>(window->parent());
- if (parentWindow) {
- QQuickStyle *style = attachedStyle(type, window);
- if (style)
- return style;
- }
- }
+ // lookup object parent (window/popup)
+ if (parent->parent())
+ return findParentStyle(type, parent->parent());
// fallback to engine (global)
- if (object) {
- QQmlEngine *engine = qmlEngine(object);
+ if (parent) {
+ QQmlEngine *engine = qmlEngine(parent);
if (engine) {
QByteArray name = QByteArray("_q_") + type->className();
QQuickStyle *style = engine->property(name).value<QQuickStyle*>();
@@ -109,8 +101,7 @@ static QList<QQuickStyle *> findChildStyles(const QMetaObject *type, QObject *ob
QQuickItem *item = qobject_cast<QQuickItem *>(object);
if (!item) {
- QQuickWindow *window = qobject_cast<QQuickWindow *>(object);
- if (window) {
+ if (QQuickWindow *window = qobject_cast<QQuickWindow *>(object)) {
item = window->contentItem();
foreach (QObject *child, window->children()) {
@@ -121,6 +112,12 @@ static QList<QQuickStyle *> findChildStyles(const QMetaObject *type, QObject *ob
children += style;
}
}
+ } else if (QQuickPopup *popup = qobject_cast<QQuickPopup *>(object)) {
+ item = popup->contentItem();
+
+ QQuickStyle *style = attachedStyle(type, popup);
+ if (style)
+ children += style;
}
}
@@ -132,6 +129,16 @@ static QList<QQuickStyle *> findChildStyles(const QMetaObject *type, QObject *ob
else
children += findChildStyles(type, child);
}
+
+ foreach (QObject *child, item->children()) {
+ if (!qobject_cast<QQuickItem *>(child)) {
+ QQuickStyle *style = attachedStyle(type, child);
+ if (style)
+ children += style;
+ else
+ children += findChildStyles(type, child);
+ }
+ }
}
return children;
@@ -193,7 +200,10 @@ void QQuickStyle::setParentStyle(QQuickStyle *style)
void QQuickStyle::init()
{
- QQuickStyle *parentStyle = findParentStyle(metaObject(), parent());
+ if (!parent())
+ return;
+
+ QQuickStyle *parentStyle = findParentStyle(metaObject(), parent()->parent());
if (parentStyle)
setParentStyle(parentStyle);
diff --git a/src/imports/controls/material/material.pro b/src/imports/controls/material/material.pro
index 06b9ed7d..63450289 100644
--- a/src/imports/controls/material/material.pro
+++ b/src/imports/controls/material/material.pro
@@ -3,7 +3,7 @@ TARGETPATH = Qt/labs/controls/material
IMPORT_VERSION = 1.0
QT += qml quick
-QT_PRIVATE += core-private gui-private qml-private quick-private labscontrols-private
+QT_PRIVATE += core-private gui-private qml-private quick-private labstemplates-private labscontrols-private
DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII
diff --git a/src/imports/controls/universal/universal.pro b/src/imports/controls/universal/universal.pro
index 41cef97d..88bad8f7 100644
--- a/src/imports/controls/universal/universal.pro
+++ b/src/imports/controls/universal/universal.pro
@@ -3,7 +3,7 @@ TARGETPATH = Qt/labs/controls/universal
IMPORT_VERSION = 1.0
QT += qml quick
-QT_PRIVATE += core-private gui-private qml-private quick-private labscontrols-private
+QT_PRIVATE += core-private gui-private qml-private quick-private labstemplates-private labscontrols-private
DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII
diff --git a/src/src.pro b/src/src.pro
index 1492f15e..38778fe1 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -4,4 +4,5 @@ SUBDIRS += \
controls \
imports
+controls.depends = templates
imports.depends = controls templates