aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--tests/auto/material/data/tst_material.qml28
-rw-r--r--tests/auto/universal/data/tst_universal.qml28
7 files changed, 99 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
diff --git a/tests/auto/material/data/tst_material.qml b/tests/auto/material/data/tst_material.qml
index 7797b8c3..5fc52f10 100644
--- a/tests/auto/material/data/tst_material.qml
+++ b/tests/auto/material/data/tst_material.qml
@@ -94,6 +94,19 @@ TestCase {
}
}
+ Component {
+ id: menu
+ Item {
+ Material.accent: Material.Red
+ property alias menu: popup
+ Menu {
+ id: popup
+ Material.theme: Material.Dark
+ MenuItem { }
+ }
+ }
+ }
+
function test_defaults() {
var control = button.createObject(testCase)
verify(control)
@@ -222,4 +235,19 @@ TestCase {
compare(child.Material.theme, Material.Dark)
control.destroy()
}
+
+ function test_menu() {
+ var container = menu.createObject(testCase)
+ verify(container)
+ verify(container.menu)
+ var child = container.menu.itemAt(0)
+ verify(child)
+ compare(container.Material.theme, Material.Light)
+ compare(container.menu.Material.theme, Material.Dark)
+ compare(child.Material.theme, Material.Dark)
+ compare(container.Material.accent, Material.Red)
+ compare(container.menu.Material.accent, Material.Red)
+ compare(child.Material.accent, Material.Red)
+ container.destroy()
+ }
}
diff --git a/tests/auto/universal/data/tst_universal.qml b/tests/auto/universal/data/tst_universal.qml
index 5c29f33c..6e70f011 100644
--- a/tests/auto/universal/data/tst_universal.qml
+++ b/tests/auto/universal/data/tst_universal.qml
@@ -94,6 +94,19 @@ TestCase {
}
}
+ Component {
+ id: menu
+ Item {
+ Universal.accent: Universal.Red
+ property alias menu: popup
+ Menu {
+ id: popup
+ Universal.theme: Universal.Dark
+ MenuItem { }
+ }
+ }
+ }
+
function test_defaults() {
var control = button.createObject(testCase)
verify(control)
@@ -223,6 +236,21 @@ TestCase {
control.destroy()
}
+ function test_menu() {
+ var container = menu.createObject(testCase)
+ verify(container)
+ verify(container.menu)
+ var child = container.menu.itemAt(0)
+ verify(child)
+ compare(container.Universal.theme, Universal.Light)
+ compare(container.menu.Universal.theme, Universal.Dark)
+ compare(child.Universal.theme, Universal.Dark)
+ compare(container.Universal.accent, "#e51400") // Red
+ compare(container.menu.Universal.accent, "#e51400") // Red
+ compare(child.Universal.accent, "#e51400") // Red
+ container.destroy()
+ }
+
function test_colors() {
var control = button.createObject(testCase)
verify(control)