diff options
-rw-r--r-- | src/controls/controls.pro | 2 | ||||
-rw-r--r-- | src/controls/qquickstyle.cpp | 68 | ||||
-rw-r--r-- | src/imports/controls/material/BusyIndicator.qml | 1 | ||||
-rw-r--r-- | src/imports/controls/material/ProgressBar.qml | 4 | ||||
-rw-r--r-- | src/imports/controls/material/material.pro | 2 | ||||
-rw-r--r-- | src/imports/controls/material/qquickmaterialprogressring.cpp | 11 | ||||
-rw-r--r-- | src/imports/controls/material/qtlabsmaterialstyleplugin.cpp | 6 | ||||
-rw-r--r-- | src/imports/controls/plugins.qmltypes | 154 | ||||
-rw-r--r-- | src/imports/controls/universal/universal.pro | 2 | ||||
-rw-r--r-- | src/src.pro | 1 | ||||
-rw-r--r-- | src/templates/qquickapplicationwindow.cpp | 6 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_combobox.qml | 2 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_progressbar.qml | 1 | ||||
-rw-r--r-- | tests/auto/material/data/tst_material.qml | 28 | ||||
-rw-r--r-- | tests/auto/universal/data/tst_universal.qml | 28 |
15 files changed, 119 insertions, 197 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/BusyIndicator.qml b/src/imports/controls/material/BusyIndicator.qml index 6d5e4e8d..9eb48613 100644 --- a/src/imports/controls/material/BusyIndicator.qml +++ b/src/imports/controls/material/BusyIndicator.qml @@ -37,6 +37,7 @@ import QtQuick 2.6 import Qt.labs.templates 1.0 as T import Qt.labs.controls.material 1.0 +import Qt.labs.controls.material.impl 1.0 T.BusyIndicator { id: control diff --git a/src/imports/controls/material/ProgressBar.qml b/src/imports/controls/material/ProgressBar.qml index 34e1aaea..709ac28d 100644 --- a/src/imports/controls/material/ProgressBar.qml +++ b/src/imports/controls/material/ProgressBar.qml @@ -66,7 +66,7 @@ T.ProgressBar { x: (indeterminate ? offset * parent.width : 0) y: (parent.height - height) / 2 width: offset * (parent.width - x) - height: 6 + height: 4 color: control.Material.accentColor @@ -94,7 +94,7 @@ T.ProgressBar { x: control.leftPadding y: control.topPadding + (control.availableHeight - height) / 2 width: control.availableWidth - height: 6 + height: 4 color: Qt.rgba(control.Material.accentColor.r, control.Material.accentColor.g, control.Material.accentColor.b, 0.25) } 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/material/qquickmaterialprogressring.cpp b/src/imports/controls/material/qquickmaterialprogressring.cpp index 54728686..c11a347f 100644 --- a/src/imports/controls/material/qquickmaterialprogressring.cpp +++ b/src/imports/controls/material/qquickmaterialprogressring.cpp @@ -74,6 +74,7 @@ public: void afterNodeSync() Q_DECL_OVERRIDE; private: + qreal m_devicePixelRatio; QSGNode *m_containerNode; QQuickWindow *m_window; }; @@ -165,6 +166,7 @@ QQuickAnimatorJob *QQuickMaterialRingAnimator::createJob() const } QQuickMaterialRingAnimatorJob::QQuickMaterialRingAnimatorJob() : + m_devicePixelRatio(1.0), m_containerNode(Q_NULLPTR), m_window(Q_NULLPTR) { @@ -179,6 +181,7 @@ void QQuickMaterialRingAnimatorJob::initialize(QQuickAnimatorController *control QQuickAnimatorJob::initialize(controller); m_containerNode = QQuickItemPrivate::get(m_target)->childContainerNode(); m_window = m_target->window(); + m_devicePixelRatio = m_window->effectiveDevicePixelRatio(); } void QQuickMaterialRingAnimatorJob::updateCurrentTime(int time) @@ -192,8 +195,8 @@ void QQuickMaterialRingAnimatorJob::updateCurrentTime(int time) Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - const qreal width = rectNode->rect().width(); - const qreal height = rectNode->rect().height(); + const qreal width = rectNode->rect().width() * m_devicePixelRatio; + const qreal height = rectNode->rect().height() * m_devicePixelRatio; QImage image(width, height, QImage::Format_ARGB32_Premultiplied); image.fill(Qt::transparent); @@ -203,7 +206,7 @@ void QQuickMaterialRingAnimatorJob::updateCurrentTime(int time) QPen pen; QQuickMaterialRingTexture *textureNode = static_cast<QQuickMaterialRingTexture*>(rectNode->firstChild()); pen.setColor(textureNode->color()); - pen.setWidth(4); + pen.setWidth(4 * m_devicePixelRatio); painter.setPen(pen); const qreal percentageComplete = time / qreal(rotationAnimationDuration); @@ -237,7 +240,7 @@ void QQuickMaterialRingAnimatorJob::updateCurrentTime(int time) } const int halfPen = pen.width() / 2; - const QRectF arcBounds = QRectF(rectNode->rect().adjusted(halfPen, halfPen, -halfPen, -halfPen)); + const QRectF arcBounds = QRectF(halfPen, halfPen, width - pen.width(), height - pen.width()); // The current angle of the rotation animation. const qreal rotation = oneDegree * percentageComplete * -targetRotation; startAngle -= rotation; diff --git a/src/imports/controls/material/qtlabsmaterialstyleplugin.cpp b/src/imports/controls/material/qtlabsmaterialstyleplugin.cpp index db8b47ee..975e5db6 100644 --- a/src/imports/controls/material/qtlabsmaterialstyleplugin.cpp +++ b/src/imports/controls/material/qtlabsmaterialstyleplugin.cpp @@ -76,8 +76,6 @@ QtLabsMaterialStylePlugin::~QtLabsMaterialStylePlugin() void QtLabsMaterialStylePlugin::registerTypes(const char *uri) { qmlRegisterUncreatableType<QQuickMaterialStyle>(uri, 1, 0, "Material", tr("Material is an attached property")); - qmlRegisterType<QQuickMaterialProgressRing>(uri, 1, 0, "ProgressRing"); - qmlRegisterType<QQuickMaterialRingAnimator>(uri, 1, 0, "RingAnimator"); } void QtLabsMaterialStylePlugin::initializeEngine(QQmlEngine *engine, const char *uri) @@ -97,6 +95,10 @@ void QtLabsMaterialStylePlugin::initializeEngine(QQmlEngine *engine, const char } initResources(); + + QByteArray import = QByteArray(uri) + ".impl"; + qmlRegisterType<QQuickMaterialProgressRing>(import, 1, 0, "ProgressRing"); + qmlRegisterType<QQuickMaterialRingAnimator>(import, 1, 0, "RingAnimator"); } QT_END_NAMESPACE diff --git a/src/imports/controls/plugins.qmltypes b/src/imports/controls/plugins.qmltypes index 518a9b6c..7ffa52be 100644 --- a/src/imports/controls/plugins.qmltypes +++ b/src/imports/controls/plugins.qmltypes @@ -267,160 +267,6 @@ Module { Signal { name: "implicitHeightChanged2"; revision: 1 } } Component { - name: "QQuickItem" - defaultProperty: "data" - prototype: "QObject" - Enum { - name: "TransformOrigin" - values: { - "TopLeft": 0, - "Top": 1, - "TopRight": 2, - "Left": 3, - "Center": 4, - "Right": 5, - "BottomLeft": 6, - "Bottom": 7, - "BottomRight": 8 - } - } - Property { name: "parent"; type: "QQuickItem"; isPointer: true } - Property { name: "data"; type: "QObject"; isList: true; isReadonly: true } - Property { name: "resources"; type: "QObject"; isList: true; isReadonly: true } - Property { name: "children"; type: "QQuickItem"; isList: true; isReadonly: true } - Property { name: "x"; type: "double" } - Property { name: "y"; type: "double" } - Property { name: "z"; type: "double" } - Property { name: "width"; type: "double" } - Property { name: "height"; type: "double" } - Property { name: "opacity"; type: "double" } - Property { name: "enabled"; type: "bool" } - Property { name: "visible"; type: "bool" } - Property { name: "visibleChildren"; type: "QQuickItem"; isList: true; isReadonly: true } - Property { name: "states"; type: "QQuickState"; isList: true; isReadonly: true } - Property { name: "transitions"; type: "QQuickTransition"; isList: true; isReadonly: true } - Property { name: "state"; type: "string" } - Property { name: "childrenRect"; type: "QRectF"; isReadonly: true } - Property { name: "anchors"; type: "QQuickAnchors"; isReadonly: true; isPointer: true } - Property { name: "left"; type: "QQuickAnchorLine"; isReadonly: true } - Property { name: "right"; type: "QQuickAnchorLine"; isReadonly: true } - Property { name: "horizontalCenter"; type: "QQuickAnchorLine"; isReadonly: true } - Property { name: "top"; type: "QQuickAnchorLine"; isReadonly: true } - Property { name: "bottom"; type: "QQuickAnchorLine"; isReadonly: true } - Property { name: "verticalCenter"; type: "QQuickAnchorLine"; isReadonly: true } - Property { name: "baseline"; type: "QQuickAnchorLine"; isReadonly: true } - Property { name: "baselineOffset"; type: "double" } - Property { name: "clip"; type: "bool" } - Property { name: "focus"; type: "bool" } - Property { name: "activeFocus"; type: "bool"; isReadonly: true } - Property { name: "activeFocusOnTab"; revision: 1; type: "bool" } - Property { name: "rotation"; type: "double" } - Property { name: "scale"; type: "double" } - Property { name: "transformOrigin"; type: "TransformOrigin" } - Property { name: "transformOriginPoint"; type: "QPointF"; isReadonly: true } - Property { name: "transform"; type: "QQuickTransform"; isList: true; isReadonly: true } - Property { name: "smooth"; type: "bool" } - Property { name: "antialiasing"; type: "bool" } - Property { name: "implicitWidth"; type: "double" } - Property { name: "implicitHeight"; type: "double" } - Property { name: "layer"; type: "QQuickItemLayer"; isReadonly: true; isPointer: true } - Signal { - name: "childrenRectChanged" - Parameter { type: "QRectF" } - } - Signal { - name: "baselineOffsetChanged" - Parameter { type: "double" } - } - Signal { - name: "stateChanged" - Parameter { type: "string" } - } - Signal { - name: "focusChanged" - Parameter { type: "bool" } - } - Signal { - name: "activeFocusChanged" - Parameter { type: "bool" } - } - Signal { - name: "activeFocusOnTabChanged" - revision: 1 - Parameter { type: "bool" } - } - Signal { - name: "parentChanged" - Parameter { type: "QQuickItem"; isPointer: true } - } - Signal { - name: "transformOriginChanged" - Parameter { type: "TransformOrigin" } - } - Signal { - name: "smoothChanged" - Parameter { type: "bool" } - } - Signal { - name: "antialiasingChanged" - Parameter { type: "bool" } - } - Signal { - name: "clipChanged" - Parameter { type: "bool" } - } - Signal { - name: "windowChanged" - revision: 1 - Parameter { name: "window"; type: "QQuickWindow"; isPointer: true } - } - Method { name: "update" } - Method { - name: "grabToImage" - revision: 2 - type: "bool" - Parameter { name: "callback"; type: "QJSValue" } - Parameter { name: "targetSize"; type: "QSize" } - } - Method { - name: "grabToImage" - revision: 2 - type: "bool" - Parameter { name: "callback"; type: "QJSValue" } - } - Method { - name: "contains" - type: "bool" - Parameter { name: "point"; type: "QPointF" } - } - Method { - name: "mapFromItem" - Parameter { type: "QQmlV4Function"; isPointer: true } - } - Method { - name: "mapToItem" - Parameter { type: "QQmlV4Function"; isPointer: true } - } - Method { name: "forceActiveFocus" } - Method { - name: "forceActiveFocus" - Parameter { name: "reason"; type: "Qt::FocusReason" } - } - Method { - name: "nextItemInFocusChain" - revision: 1 - type: "QQuickItem*" - Parameter { name: "forward"; type: "bool" } - } - Method { name: "nextItemInFocusChain"; revision: 1; type: "QQuickItem*" } - Method { - name: "childAt" - type: "QQuickItem*" - Parameter { name: "x"; type: "double" } - Parameter { name: "y"; type: "double" } - } - } - Component { name: "QQuickItemDelegate" defaultProperty: "data" prototype: "QQuickAbstractButton" 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/src/templates/qquickapplicationwindow.cpp b/src/templates/qquickapplicationwindow.cpp index 46f07d3e..3e6734d7 100644 --- a/src/templates/qquickapplicationwindow.cpp +++ b/src/templates/qquickapplicationwindow.cpp @@ -240,7 +240,8 @@ void QQuickApplicationWindow::setHeader(QQuickItem *header) { Q_D(QQuickApplicationWindow); if (d->header != header) { - delete d->header; + if (d->header) + QQuickItemPrivate::get(d->header)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); d->header = header; if (header) { header->setParentItem(contentItem()); @@ -273,7 +274,8 @@ void QQuickApplicationWindow::setFooter(QQuickItem *footer) { Q_D(QQuickApplicationWindow); if (d->footer != footer) { - delete d->footer; + if (d->footer) + QQuickItemPrivate::get(d->footer)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); d->footer = footer; if (footer) { footer->setParentItem(contentItem()); diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml index 11390bb8..d74c52aa 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -44,6 +44,8 @@ import Qt.labs.controls 1.0 TestCase { id: testCase + width: 200 + height: 200 name: "ComboBox" ApplicationWindow { diff --git a/tests/auto/controls/data/tst_progressbar.qml b/tests/auto/controls/data/tst_progressbar.qml index 086d9ad4..1aea09f5 100644 --- a/tests/auto/controls/data/tst_progressbar.qml +++ b/tests/auto/controls/data/tst_progressbar.qml @@ -183,7 +183,6 @@ TestCase { } function test_indeterminate() { - skip("skipping until https://codereview.qt-project.org/#/c/145140/ is merged") var control = progressBar.createObject(testCase) verify(control) compare(control.indeterminate, false) 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) |