diff options
-rw-r--r-- | src/controls/qquickstyle.cpp | 49 | ||||
-rw-r--r-- | tests/auto/material/data/tst_material.qml | 38 | ||||
-rw-r--r-- | tests/auto/universal/data/tst_universal.qml | 38 |
3 files changed, 105 insertions, 20 deletions
diff --git a/src/controls/qquickstyle.cpp b/src/controls/qquickstyle.cpp index 58563954..7f788e95 100644 --- a/src/controls/qquickstyle.cpp +++ b/src/controls/qquickstyle.cpp @@ -63,33 +63,40 @@ static QQuickStyle *findParentStyle(const QMetaObject *type, QObject *parent) if (style) return style; + // lookup object parent (window/popup) + QObject *grandParent = parent->parent(); + if (grandParent) { + QQuickStyle *style = findParentStyle(type, grandParent); + if (style) + return style; + } + QQuickItem *item = qobject_cast<QQuickItem *>(parent); if (item) { // lookup parent items QQuickItem *parent = item->parentItem(); - if (parent) - return findParentStyle(type, parent); + if (parent) { + QQuickStyle *style = findParentStyle(type, parent); + if (style) + return style; + } // fallback to item's window - return findParentStyle(type, item->window()); + QQuickStyle *style = findParentStyle(type, item->window()); + if (style) + return style; } - // lookup object parent (window/popup) - if (parent->parent()) - return findParentStyle(type, parent->parent()); - // fallback to engine (global) - if (parent) { - QQmlEngine *engine = qmlEngine(parent); - if (engine) { - QByteArray name = QByteArray("_q_") + type->className(); - QQuickStyle *style = engine->property(name).value<QQuickStyle*>(); - if (!style) { - style = attachedStyle(type, engine, true); - engine->setProperty(name, QVariant::fromValue(style)); - } - return style; + QQmlEngine *engine = qmlEngine(parent); + if (engine) { + QByteArray name = QByteArray("_q_") + type->className(); + QQuickStyle *style = engine->property(name).value<QQuickStyle*>(); + if (!style) { + style = attachedStyle(type, engine, true); + engine->setProperty(name, QVariant::fromValue(style)); } + return style; } return Q_NULLPTR; @@ -200,14 +207,16 @@ void QQuickStyle::setParentStyle(QQuickStyle *style) void QQuickStyle::init() { - if (!parent()) + QObject *parent = QObject::parent(); + if (!parent) return; - QQuickStyle *parentStyle = findParentStyle(metaObject(), parent()->parent()); + QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent); + QQuickStyle *parentStyle = findParentStyle(metaObject(), parentItem ? parentItem->parentItem() : parent->parent()); if (parentStyle) setParentStyle(parentStyle); - QList<QQuickStyle *> children = findChildStyles(metaObject(), parent()); + QList<QQuickStyle *> children = findChildStyles(metaObject(), parent); foreach (QQuickStyle *child, children) child->setParentStyle(this); } diff --git a/tests/auto/material/data/tst_material.qml b/tests/auto/material/data/tst_material.qml index 6bd99547..e29fea3b 100644 --- a/tests/auto/material/data/tst_material.qml +++ b/tests/auto/material/data/tst_material.qml @@ -107,6 +107,22 @@ TestCase { } } + Component { + id: comboBox + ApplicationWindow { + width: 200 + height: 200 + visible: true + Material.accent: Material.Red + property alias combo: box + ComboBox { + id: box + Material.theme: Material.Dark + model: 1 + } + } + } + function test_defaults() { var control = button.createObject(testCase) verify(control) @@ -251,6 +267,28 @@ TestCase { container.destroy() } + function test_comboBox() { + var window = comboBox.createObject(testCase) + verify(window) + verify(window.combo) + waitForRendering(window.combo) + window.combo.forceActiveFocus() + verify(window.combo.activeFocus) + keyClick(Qt.Key_Space) + verify(window.combo.popup.visible) + var listView = window.combo.popup.contentItem.children[0] + verify(listView) + var child = listView.contentItem.children[0] + verify(child) + compare(window.Material.theme, Material.Light) + compare(window.combo.Material.theme, Material.Dark) + compare(child.Material.theme, Material.Dark) + compare(window.Material.accent, Material.color(Material.Red)) + compare(window.combo.Material.accent, Material.color(Material.Red)) + compare(child.Material.accent, Material.color(Material.Red)) + window.destroy() + } + function test_colors() { var control = button.createObject(testCase) verify(control) diff --git a/tests/auto/universal/data/tst_universal.qml b/tests/auto/universal/data/tst_universal.qml index b2f164e1..af70ad0e 100644 --- a/tests/auto/universal/data/tst_universal.qml +++ b/tests/auto/universal/data/tst_universal.qml @@ -107,6 +107,22 @@ TestCase { } } + Component { + id: comboBox + ApplicationWindow { + width: 200 + height: 200 + visible: true + Universal.accent: Universal.Red + property alias combo: box + ComboBox { + id: box + Universal.theme: Universal.Dark + model: 1 + } + } + } + function test_defaults() { var control = button.createObject(testCase) verify(control) @@ -251,6 +267,28 @@ TestCase { container.destroy() } + function test_comboBox() { + var window = comboBox.createObject(testCase) + verify(window) + verify(window.combo) + waitForRendering(window.combo) + window.combo.forceActiveFocus() + verify(window.combo.activeFocus) + keyClick(Qt.Key_Space) + verify(window.combo.popup.visible) + var listView = window.combo.popup.contentItem.children[0] + verify(listView) + var child = listView.contentItem.children[0] + verify(child) + compare(window.Universal.theme, Universal.Light) + compare(window.combo.Universal.theme, Universal.Dark) + compare(child.Universal.theme, Universal.Dark) + compare(window.Universal.accent, "#e51400") // Red + compare(window.combo.Universal.accent, "#e51400") // Red + compare(child.Universal.accent, "#e51400") // Red + window.destroy() + } + function test_colors() { var control = button.createObject(testCase) verify(control) |