From 31a655402ff194e556853e6877f1a464a8e51243 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 22 Dec 2017 13:32:04 +0100 Subject: Material: cleanup the internal ID from BusyIndicator Same as da27cace for the Default style. An internal ID in the OpacityAnimator element prevented deferred execution for the whole content item. Apply the same visibility trick in C++ to avoid having to use an ID in QML. Change-Id: I4b54bbe3044aff9603b1135ac25d7325e01fdff2 Reviewed-by: Mitch Curtis --- src/imports/controls/material/BusyIndicator.qml | 4 ++-- .../material/qquickmaterialbusyindicator.cpp | 24 ++++++++++++++++++++-- .../material/qquickmaterialbusyindicator_p.h | 4 ++++ tests/auto/customization/tst_customization.cpp | 1 - 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/imports/controls/material/BusyIndicator.qml b/src/imports/controls/material/BusyIndicator.qml index f1cf8eb5..beaaf30e 100644 --- a/src/imports/controls/material/BusyIndicator.qml +++ b/src/imports/controls/material/BusyIndicator.qml @@ -52,8 +52,8 @@ T.BusyIndicator { implicitHeight: 48 color: control.Material.accentColor + running: control.running opacity: control.running ? 1 : 0 - visible: control.running || animator.running - Behavior on opacity { OpacityAnimator { id: animator; duration: 250 } } + Behavior on opacity { OpacityAnimator { duration: 250 } } } } diff --git a/src/imports/controls/material/qquickmaterialbusyindicator.cpp b/src/imports/controls/material/qquickmaterialbusyindicator.cpp index 9df8f5d2..bd15390b 100644 --- a/src/imports/controls/material/qquickmaterialbusyindicator.cpp +++ b/src/imports/controls/material/qquickmaterialbusyindicator.cpp @@ -197,6 +197,17 @@ void QQuickMaterialBusyIndicator::setColor(QColor color) update(); } +bool QQuickMaterialBusyIndicator::isRunning() const +{ + return isVisible(); +} + +void QQuickMaterialBusyIndicator::setRunning(bool running) +{ + if (running) + setVisible(true); +} + int QQuickMaterialBusyIndicator::elapsed() const { return m_elapsed; @@ -205,14 +216,23 @@ int QQuickMaterialBusyIndicator::elapsed() const void QQuickMaterialBusyIndicator::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) { QQuickItem::itemChange(change, data); - if (change == ItemVisibleHasChanged) + switch (change) { + case ItemOpacityHasChanged: + if (qFuzzyIsNull(data.realValue)) + setVisible(false); + break; + case ItemVisibleHasChanged: update(); + break; + default: + break; + } } QSGNode *QQuickMaterialBusyIndicator::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) { QQuickMaterialBusyIndicatorNode *node = static_cast(oldNode); - if (isVisible() && width() > 0 && height() > 0) { + if (isRunning() && width() > 0 && height() > 0) { if (!node) { node = new QQuickMaterialBusyIndicatorNode(this); node->start(); diff --git a/src/imports/controls/material/qquickmaterialbusyindicator_p.h b/src/imports/controls/material/qquickmaterialbusyindicator_p.h index da84c7b1..6c6d2445 100644 --- a/src/imports/controls/material/qquickmaterialbusyindicator_p.h +++ b/src/imports/controls/material/qquickmaterialbusyindicator_p.h @@ -57,6 +57,7 @@ class QQuickMaterialBusyIndicator : public QQuickItem { Q_OBJECT Q_PROPERTY(QColor color READ color WRITE setColor FINAL) + Q_PROPERTY(bool running READ isRunning WRITE setRunning FINAL) public: explicit QQuickMaterialBusyIndicator(QQuickItem *parent = nullptr); @@ -64,6 +65,9 @@ public: QColor color() const; void setColor(QColor color); + bool isRunning() const; + void setRunning(bool running); + int elapsed() const; protected: diff --git a/tests/auto/customization/tst_customization.cpp b/tests/auto/customization/tst_customization.cpp index 5c6310ba..05d95ec8 100644 --- a/tests/auto/customization/tst_customization.cpp +++ b/tests/auto/customization/tst_customization.cpp @@ -393,7 +393,6 @@ void tst_customization::override() // unparented means that a delegate got destroyed, so there must be an internal ID in one // of the delegates in the tested style. if (!identify && nonDeferred.isEmpty()) { - QEXPECT_FAIL("Material:BusyIndicator", "TODO: remove internal ID in the OpacityAnimator", Continue); QEXPECT_FAIL("Universal:ApplicationWindow", "ApplicationWindow.qml contains an intentionally unparented FocusRectangle", Continue); QCOMPARE(qt_unparentedItemCount, 0); } -- cgit v1.2.3