diff options
Diffstat (limited to 'src/imports/controls')
-rw-r--r-- | src/imports/controls/material/ProgressBar.qml | 10 | ||||
-rw-r--r-- | src/imports/controls/material/material.pri | 8 | ||||
-rw-r--r-- | src/imports/controls/material/qquickmaterialprogressbar.cpp (renamed from src/imports/controls/material/qquickmaterialprogressstrip.cpp) | 206 | ||||
-rw-r--r-- | src/imports/controls/material/qquickmaterialprogressbar_p.h (renamed from src/imports/controls/material/qquickmaterialprogressstrip_p.h) | 27 | ||||
-rw-r--r-- | src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp | 5 |
5 files changed, 115 insertions, 141 deletions
diff --git a/src/imports/controls/material/ProgressBar.qml b/src/imports/controls/material/ProgressBar.qml index 2b78be49..54152895 100644 --- a/src/imports/controls/material/ProgressBar.qml +++ b/src/imports/controls/material/ProgressBar.qml @@ -47,19 +47,13 @@ T.ProgressBar { implicitHeight: Math.max(background ? background.implicitHeight : 0, contentItem.implicitHeight + topPadding + bottomPadding) - contentItem: ProgressStrip { - id: strip + contentItem: ProgressBarImpl { implicitHeight: 4 scale: control.mirrored ? -1 : 1 - indeterminate: control.indeterminate color: control.Material.accentColor progress: control.position - - StripAnimator { - target: strip - running: control.visible && control.indeterminate - } + indeterminate: control.visible && control.indeterminate } background: Rectangle { diff --git a/src/imports/controls/material/material.pri b/src/imports/controls/material/material.pri index 908c5529..355d62a5 100644 --- a/src/imports/controls/material/material.pri +++ b/src/imports/controls/material/material.pri @@ -1,16 +1,16 @@ HEADERS += \ $$PWD/qquickmaterialbusyindicator_p.h \ + $$PWD/qquickmaterialprogressbar_p.h \ $$PWD/qquickmaterialripple_p.h \ $$PWD/qquickmaterialstyle_p.h \ - $$PWD/qquickmaterialtheme_p.h \ - $$PWD/qquickmaterialprogressstrip_p.h + $$PWD/qquickmaterialtheme_p.h SOURCES += \ $$PWD/qquickmaterialbusyindicator.cpp \ + $$PWD/qquickmaterialprogressbar.cpp \ $$PWD/qquickmaterialripple.cpp \ $$PWD/qquickmaterialstyle.cpp \ - $$PWD/qquickmaterialtheme.cpp \ - $$PWD/qquickmaterialprogressstrip.cpp + $$PWD/qquickmaterialtheme.cpp QML_FILES += \ $$PWD/ApplicationWindow.qml \ diff --git a/src/imports/controls/material/qquickmaterialprogressstrip.cpp b/src/imports/controls/material/qquickmaterialprogressbar.cpp index 542d312f..36b18781 100644 --- a/src/imports/controls/material/qquickmaterialprogressstrip.cpp +++ b/src/imports/controls/material/qquickmaterialprogressbar.cpp @@ -34,12 +34,12 @@ ** ****************************************************************************/ -#include "qquickmaterialprogressstrip_p.h" +#include "qquickmaterialprogressbar_p.h" #include <QtCore/qmath.h> #include <QtCore/qeasingcurve.h> +#include <QtCore/qelapsedtimer.h> #include <QtQuick/private/qquickitem_p.h> -#include <QtQuick/private/qquickanimatorjob_p.h> #include <QtQuick/private/qsgadaptationlayer_p.h> #include <QtQuick/qsgrectanglenode.h> #include <QtQuick/qsgimagenode.h> @@ -50,43 +50,36 @@ static const int PauseDuration = 520; static const int SlideDuration = 1240; static const int TotalDuration = SlideDuration + PauseDuration; -class QQuickMaterialProgressStripAnimatorJob : public QQuickAnimatorJob +class QQuickMaterialProgressBarNode : public QObject, public QSGNode { public: - QQuickMaterialProgressStripAnimatorJob(); + QQuickMaterialProgressBarNode(QQuickMaterialProgressBar *item); - void initialize(QQuickAnimatorController *controller) override; - void updateCurrentTime(int time) override; - void writeBack() override; - void nodeWasDestroyed() override; - void afterNodeSync() override; + void animate(); + void sync(QQuickMaterialProgressBar *item); +private: void moveNode(QSGTransformNode *node, const QRectF &geometry, qreal progress); -private: - QSGNode *m_node; + bool m_indeterminate; + QElapsedTimer m_timer; + QEasingCurve m_easing; }; -QQuickMaterialProgressStripAnimatorJob::QQuickMaterialProgressStripAnimatorJob() : m_node(nullptr) -{ -} - -void QQuickMaterialProgressStripAnimatorJob::initialize(QQuickAnimatorController *controller) +QQuickMaterialProgressBarNode::QQuickMaterialProgressBarNode(QQuickMaterialProgressBar *) + : m_indeterminate(false), m_easing(QEasingCurve::OutCubic) { - QQuickAnimatorJob::initialize(controller); - m_node = QQuickItemPrivate::get(m_target)->childContainerNode(); + m_timer.start(); } -void QQuickMaterialProgressStripAnimatorJob::updateCurrentTime(int time) +void QQuickMaterialProgressBarNode::animate() { - if (!m_node) - return; - - QSGRectangleNode *geometryNode = static_cast<QSGRectangleNode *>(m_node->firstChild()); - Q_ASSERT(!geometryNode || geometryNode->type() == QSGNode::GeometryNodeType); - if (!geometryNode) - return; + qint64 time = m_timer.elapsed(); + if (time >= TotalDuration) + m_timer.restart(); + QSGRectangleNode *geometryNode = static_cast<QSGRectangleNode *>(firstChild()); + Q_ASSERT(geometryNode->type() == QSGNode::GeometryNodeType); const QRectF geometry = geometryNode->rect(); QSGTransformNode *firstNode = static_cast<QSGTransformNode *>(geometryNode->firstChild()); @@ -106,21 +99,69 @@ void QQuickMaterialProgressStripAnimatorJob::updateCurrentTime(int time) } } -void QQuickMaterialProgressStripAnimatorJob::writeBack() +void QQuickMaterialProgressBarNode::sync(QQuickMaterialProgressBar *item) { -} + if (m_indeterminate != item->isIndeterminate()) { + m_indeterminate = item->isIndeterminate(); + QQuickWindow *window = item->window(); + if (m_indeterminate) { + connect(window, &QQuickWindow::frameSwapped, window, &QQuickWindow::update); + connect(window, &QQuickWindow::beforeRendering, this, &QQuickMaterialProgressBarNode::animate); + } else { + disconnect(window, &QQuickWindow::frameSwapped, window, &QQuickWindow::update); + disconnect(window, &QQuickWindow::beforeRendering, this, &QQuickMaterialProgressBarNode::animate); + } + } -void QQuickMaterialProgressStripAnimatorJob::nodeWasDestroyed() -{ - m_node = nullptr; -} + QQuickItemPrivate *d = QQuickItemPrivate::get(item); -void QQuickMaterialProgressStripAnimatorJob::afterNodeSync() -{ - m_node = QQuickItemPrivate::get(m_target)->childContainerNode(); + QRectF bounds = item->boundingRect(); + bounds.setHeight(item->implicitHeight()); + bounds.moveTop((item->height() - bounds.height()) / 2.0); + + QSGRectangleNode *geometryNode = static_cast<QSGRectangleNode *>(firstChild()); + if (!geometryNode) { + geometryNode = item->window()->createRectangleNode(); + geometryNode->setColor(Qt::transparent); + appendChildNode(geometryNode); + } + geometryNode->setRect(bounds); + + const int count = m_indeterminate ? 2 : 1; + const qreal w = m_indeterminate ? 0 : item->progress() * item->width(); + const QRectF rect(0, bounds.y(), w, bounds.height()); + + QSGNode *transformNode = geometryNode->firstChild(); + for (int i = 0; i < count; ++i) { + if (!transformNode) { + transformNode = new QSGTransformNode; + geometryNode->appendChildNode(transformNode); + + QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); + rectNode->setAntialiasing(true); + transformNode->appendChildNode(rectNode); + } + Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); + static_cast<QSGTransformNode *>(transformNode)->setMatrix(QMatrix4x4()); + + QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(transformNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + + rectNode->setRect(rect); + rectNode->setColor(item->color()); + rectNode->update(); + + transformNode = transformNode->nextSibling(); + } + + while (transformNode) { + QSGNode *nextSibling = transformNode->nextSibling(); + delete transformNode; + transformNode = nextSibling; + } } -void QQuickMaterialProgressStripAnimatorJob::moveNode(QSGTransformNode *transformNode, const QRectF &geometry, qreal progress) +void QQuickMaterialProgressBarNode::moveNode(QSGTransformNode *transformNode, const QRectF &geometry, qreal progress) { const qreal value = m_easing.valueForProgress(progress); const qreal x = value * geometry.width(); @@ -138,36 +179,18 @@ void QQuickMaterialProgressStripAnimatorJob::moveNode(QSGTransformNode *transfor rectNode->update(); } -QQuickMaterialStripAnimator::QQuickMaterialStripAnimator(QObject *parent) - : QQuickAnimator(parent) -{ - setLoops(Infinite); - setDuration(TotalDuration); - setEasing(QEasingCurve::OutCubic); -} - -QString QQuickMaterialStripAnimator::propertyName() const -{ - return QString(); -} - -QQuickAnimatorJob *QQuickMaterialStripAnimator::createJob() const -{ - return new QQuickMaterialProgressStripAnimatorJob; -} - -QQuickMaterialProgressStrip::QQuickMaterialProgressStrip(QQuickItem *parent) +QQuickMaterialProgressBar::QQuickMaterialProgressBar(QQuickItem *parent) : QQuickItem(parent), m_color(Qt::black), m_progress(0.0), m_indeterminate(false) { setFlag(ItemHasContents); } -QColor QQuickMaterialProgressStrip::color() const +QColor QQuickMaterialProgressBar::color() const { return m_color; } -void QQuickMaterialProgressStrip::setColor(const QColor &color) +void QQuickMaterialProgressBar::setColor(const QColor &color) { if (color == m_color) return; @@ -176,12 +199,12 @@ void QQuickMaterialProgressStrip::setColor(const QColor &color) update(); } -qreal QQuickMaterialProgressStrip::progress() const +qreal QQuickMaterialProgressBar::progress() const { return m_progress; } -void QQuickMaterialProgressStrip::setProgress(qreal progress) +void QQuickMaterialProgressBar::setProgress(qreal progress) { if (progress == m_progress) return; @@ -190,12 +213,12 @@ void QQuickMaterialProgressStrip::setProgress(qreal progress) update(); } -bool QQuickMaterialProgressStrip::isIndeterminate() const +bool QQuickMaterialProgressBar::isIndeterminate() const { return m_indeterminate; } -void QQuickMaterialProgressStrip::setIndeterminate(bool indeterminate) +void QQuickMaterialProgressBar::setIndeterminate(bool indeterminate) { if (indeterminate == m_indeterminate) return; @@ -204,54 +227,25 @@ void QQuickMaterialProgressStrip::setIndeterminate(bool indeterminate) update(); } -QSGNode *QQuickMaterialProgressStrip::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) +void QQuickMaterialProgressBar::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) { - QQuickItemPrivate *d = QQuickItemPrivate::get(this); - - QRectF bounds = boundingRect(); - bounds.setHeight(implicitHeight()); - bounds.moveTop((height() - bounds.height()) / 2.0); - - if (!oldNode) { - oldNode = window()->createRectangleNode(); - static_cast<QSGRectangleNode *>(oldNode)->setColor(Qt::transparent); - } - static_cast<QSGRectangleNode *>(oldNode)->setRect(bounds); - - const int count = m_indeterminate ? 2 : 1; - const qreal w = m_indeterminate ? 0 : m_progress * width(); - const QRectF rect(0, bounds.y(), w, bounds.height()); - - QSGNode *transformNode = oldNode->firstChild(); - for (int i = 0; i < count; ++i) { - if (!transformNode) { - transformNode = new QSGTransformNode; - oldNode->appendChildNode(transformNode); - - QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); - rectNode->setAntialiasing(true); - transformNode->appendChildNode(rectNode); - } - Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); - static_cast<QSGTransformNode *>(transformNode)->setMatrix(QMatrix4x4()); - - QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(transformNode->firstChild()); - Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - - rectNode->setRect(rect); - rectNode->setColor(m_color); - rectNode->update(); - - transformNode = transformNode->nextSibling(); - } + QQuickItem::itemChange(change, data); + if (change == ItemVisibleHasChanged) + update(); +} - while (transformNode) { - QSGNode *nextSibling = transformNode->nextSibling(); - delete transformNode; - transformNode = nextSibling; +QSGNode *QQuickMaterialProgressBar::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) +{ + QQuickMaterialProgressBarNode *node = static_cast<QQuickMaterialProgressBarNode *>(oldNode); + if (isVisible() && width() > 0 && height() > 0) { + if (!node) + node = new QQuickMaterialProgressBarNode(this); + node->sync(this); + } else { + delete node; + node = nullptr; } - - return oldNode; + return node; } QT_END_NAMESPACE diff --git a/src/imports/controls/material/qquickmaterialprogressstrip_p.h b/src/imports/controls/material/qquickmaterialprogressbar_p.h index f441c09d..0b0b576f 100644 --- a/src/imports/controls/material/qquickmaterialprogressstrip_p.h +++ b/src/imports/controls/material/qquickmaterialprogressbar_p.h @@ -34,8 +34,8 @@ ** ****************************************************************************/ -#ifndef QQUICKMATERIALPROGRESSSTRIP_P_H -#define QQUICKMATERIALPROGRESSSTRIP_P_H +#ifndef QQUICKMATERIALPROGRESSBAR_P_H +#define QQUICKMATERIALPROGRESSBAR_P_H // // W A R N I N G @@ -49,11 +49,10 @@ // #include <QtQuick/qquickitem.h> -#include <QtQuick/private/qquickanimator_p.h> QT_BEGIN_NAMESPACE -class QQuickMaterialProgressStrip : public QQuickItem +class QQuickMaterialProgressBar : public QQuickItem { Q_OBJECT Q_PROPERTY(QColor color READ color WRITE setColor FINAL) @@ -61,7 +60,7 @@ class QQuickMaterialProgressStrip : public QQuickItem Q_PROPERTY(bool indeterminate READ isIndeterminate WRITE setIndeterminate FINAL) public: - QQuickMaterialProgressStrip(QQuickItem *parent = nullptr); + explicit QQuickMaterialProgressBar(QQuickItem *parent = nullptr); QColor color() const; void setColor(const QColor &color); @@ -73,6 +72,7 @@ public: void setIndeterminate(bool indeterminate); protected: + void itemChange(ItemChange change, const ItemChangeData &data) override; QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; private: @@ -81,21 +81,8 @@ private: bool m_indeterminate; }; -class QQuickMaterialStripAnimator : public QQuickAnimator -{ - Q_OBJECT - -public: - QQuickMaterialStripAnimator(QObject *parent = nullptr); - -protected: - QString propertyName() const override; - QQuickAnimatorJob *createJob() const override; -}; - QT_END_NAMESPACE -QML_DECLARE_TYPE(QQuickMaterialProgressStrip) -QML_DECLARE_TYPE(QQuickMaterialStripAnimator) +QML_DECLARE_TYPE(QQuickMaterialProgressBar) -#endif // QQUICKMATERIALPROGRESSSTRIP_P_H +#endif // QQUICKMATERIALPROGRESSBAR_P_H diff --git a/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp b/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp index 65e9bfe2..bf617488 100644 --- a/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp +++ b/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp @@ -39,7 +39,7 @@ #include "qquickmaterialstyle_p.h" #include "qquickmaterialtheme_p.h" #include "qquickmaterialbusyindicator_p.h" -#include "qquickmaterialprogressstrip_p.h" +#include "qquickmaterialprogressbar_p.h" #include "qquickmaterialripple_p.h" #include <QtQuickControls2/private/qquickstyleselector_p.h> @@ -92,9 +92,8 @@ void QtQuickControls2MaterialStylePlugin::initializeEngine(QQmlEngine *engine, c qmlRegisterType<QQuickPaddedRectangle>(import, 2, 0, "PaddedRectangle"); qmlRegisterRevision<QQuickPaddedRectangle, 1>(import, 2, 1); qmlRegisterType<QQuickMaterialBusyIndicator>(import, 2, 0, "BusyIndicatorImpl"); - qmlRegisterType<QQuickMaterialProgressStrip>(import, 2, 0, "ProgressStrip"); + qmlRegisterType<QQuickMaterialProgressBar>(import, 2, 0, "ProgressBarImpl"); qmlRegisterType<QQuickMaterialRipple>(import, 2, 0, "Ripple"); - qmlRegisterType<QQuickMaterialStripAnimator>(import, 2, 0, "StripAnimator"); qmlRegisterType(typeUrl(QStringLiteral("BoxShadow.qml")), import, 2, 0, "BoxShadow"); qmlRegisterType(typeUrl(QStringLiteral("CheckIndicator.qml")), import, 2, 0, "CheckIndicator"); qmlRegisterType(typeUrl(QStringLiteral("ElevationEffect.qml")), import, 2, 0, "ElevationEffect"); |