diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/controls/BusyIndicator.qml | 13 | ||||
-rw-r--r-- | src/imports/controls/controls.pri | 6 | ||||
-rw-r--r-- | src/imports/controls/qquickbusyindicatorring.cpp | 231 | ||||
-rw-r--r-- | src/imports/controls/qquickdefaultbusyindicator.cpp | 188 | ||||
-rw-r--r-- | src/imports/controls/qquickdefaultbusyindicator_p.h (renamed from src/imports/controls/qquickbusyindicatorring_p.h) | 28 | ||||
-rw-r--r-- | src/imports/controls/qtquickcontrols2plugin.cpp | 5 |
6 files changed, 208 insertions, 263 deletions
diff --git a/src/imports/controls/BusyIndicator.qml b/src/imports/controls/BusyIndicator.qml index 936764fa..16fb6091 100644 --- a/src/imports/controls/BusyIndicator.qml +++ b/src/imports/controls/BusyIndicator.qml @@ -48,18 +48,13 @@ T.BusyIndicator { padding: 6 //! [contentItem] - contentItem: BusyRing { - id: ring + contentItem: BusyIndicatorImpl { implicitWidth: 48 implicitHeight: 48 - opacity: control.running ? 1 : 0 - - Behavior on opacity { OpacityAnimator { duration: 250 } } - BusyRingAnimator { - target: ring - running: control.visible && control.running - } + opacity: control.running ? 1 : 0 + visible: control.running || animator.running + Behavior on opacity { OpacityAnimator { id: animator; duration: 250 } } } //! [contentItem] } diff --git a/src/imports/controls/controls.pri b/src/imports/controls/controls.pri index 79e03db5..0c1611e1 100644 --- a/src/imports/controls/controls.pri +++ b/src/imports/controls/controls.pri @@ -1,13 +1,13 @@ HEADERS += \ - $$PWD/qquickbusyindicatorring_p.h \ $$PWD/qquickprogressstrip_p.h \ $$PWD/qquickdialring_p.h \ - $$PWD/qquickdefaultstyle_p.h + $$PWD/qquickdefaultbusyindicator_p.h \ + $$PWD/qquickdefaultstyle_p.h \ SOURCES += \ - $$PWD/qquickbusyindicatorring.cpp \ $$PWD/qquickprogressstrip.cpp \ $$PWD/qquickdialring.cpp \ + $$PWD/qquickdefaultbusyindicator.cpp \ $$PWD/qquickdefaultstyle.cpp QML_CONTROLS = \ diff --git a/src/imports/controls/qquickbusyindicatorring.cpp b/src/imports/controls/qquickbusyindicatorring.cpp deleted file mode 100644 index d8c035d2..00000000 --- a/src/imports/controls/qquickbusyindicatorring.cpp +++ /dev/null @@ -1,231 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickbusyindicatorring_p.h" - -#include <QtCore/qset.h> -#include <QtGui/qpainter.h> -#include <QtQuick/private/qquickitem_p.h> -#include <QtQuick/qsgnode.h> -#include <QtQuick/qquickwindow.h> -#include <QtQuick/qsgrectanglenode.h> - -QT_BEGIN_NAMESPACE - -class QQuickBusyIndicatorAnimatorJob : public QQuickAnimatorJob -{ -public: - QQuickBusyIndicatorAnimatorJob(); - ~QQuickBusyIndicatorAnimatorJob(); - - void initialize(QQuickAnimatorController *controller) override; - void updateCurrentTime(int time) override; - void writeBack() override; - void nodeWasDestroyed() override; - void afterNodeSync() override; - -private: - QSGNode *m_node; -}; - -static const int circles = 10; -static const int animationDuration = 100 * circles * 2; - -QQuickBusyIndicatorRing::QQuickBusyIndicatorRing(QQuickItem *parent) : - QQuickItem(parent) -{ - setFlag(QQuickItem::ItemHasContents); - setImplicitWidth(116); - setImplicitHeight(116); -} - -QQuickBusyIndicatorRing::~QQuickBusyIndicatorRing() -{ -} - -static QPointF moveBy(const QPointF &pos, qreal rotation, qreal distance) -{ - return pos - QTransform().rotate(rotation).map(QPointF(0, distance)); -} - -QSGNode *QQuickBusyIndicatorRing::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) -{ - QQuickItemPrivate *d = QQuickItemPrivate::get(this); - - if (!oldNode) { - oldNode = window()->createRectangleNode(); - static_cast<QSGRectangleNode *>(oldNode)->setColor(Qt::transparent); - } - static_cast<QSGRectangleNode *>(oldNode)->setRect(boundingRect()); - - QSGTransformNode *rootTransformNode = static_cast<QSGTransformNode *>(oldNode->firstChild()); - if (!rootTransformNode) { - rootTransformNode = new QSGTransformNode; - oldNode->appendChildNode(rootTransformNode); - } - Q_ASSERT(rootTransformNode->type() == QSGNode::TransformNodeType); - - const qreal w = width(); - const qreal h = height(); - const qreal sz = qMin(w, h); - const qreal dx = (w - sz) / 2; - const qreal dy = (h - sz) / 2; - const int circleRadius = sz / 12; - const QColor color(0x35, 0x36, 0x37); - - QSGTransformNode *transformNode = static_cast<QSGTransformNode *>(rootTransformNode->firstChild()); - for (int i = 0; i < circles; ++i) { - if (!transformNode) { - transformNode = new QSGTransformNode; - rootTransformNode->appendChildNode(transformNode); - - QSGOpacityNode *opacityNode = new QSGOpacityNode; - transformNode->appendChildNode(opacityNode); - - QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); - rectNode->setAntialiasing(true); - rectNode->setColor(color); - rectNode->setPenColor(color); - opacityNode->appendChildNode(rectNode); - } - - QSGNode *opacityNode = transformNode->firstChild(); - Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); - - QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(opacityNode->firstChild()); - Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - - QPointF pos = QPointF(sz / 2 - circleRadius, sz / 2 - circleRadius); - pos = moveBy(pos, 360 / circles * i, sz / 2 - circleRadius); - - QMatrix4x4 m; - m.translate(dx + pos.x(), dy + pos.y()); - transformNode->setMatrix(m); - - rectNode->setRect(QRectF(QPointF(), QSizeF(circleRadius * 2, circleRadius * 2))); - rectNode->setRadius(circleRadius); - rectNode->update(); - - transformNode = static_cast<QSGTransformNode *>(transformNode->nextSibling()); - } - - return oldNode; -} - -QQuickBusyIndicatorAnimator::QQuickBusyIndicatorAnimator(QObject *parent) : - QQuickAnimator(parent) -{ - setDuration(animationDuration); - setLoops(QQuickAnimator::Infinite); -} - -QString QQuickBusyIndicatorAnimator::propertyName() const -{ - return QString(); -} - -QQuickAnimatorJob *QQuickBusyIndicatorAnimator::createJob() const -{ - return new QQuickBusyIndicatorAnimatorJob; -} - -QQuickBusyIndicatorAnimatorJob::QQuickBusyIndicatorAnimatorJob() : m_node(nullptr) -{ -} - -QQuickBusyIndicatorAnimatorJob::~QQuickBusyIndicatorAnimatorJob() -{ -} - -void QQuickBusyIndicatorAnimatorJob::initialize(QQuickAnimatorController *controller) -{ - QQuickAnimatorJob::initialize(controller); - m_node = QQuickItemPrivate::get(m_target)->childContainerNode(); -} - -void QQuickBusyIndicatorAnimatorJob::updateCurrentTime(int time) -{ - if (!m_node) - return; - - QSGRectangleNode *rootRectNode = static_cast<QSGRectangleNode *>(m_node->firstChild()); - if (!rootRectNode) - return; - - Q_ASSERT(rootRectNode->type() == QSGNode::GeometryNodeType); - - QSGTransformNode *rootTransformNode = static_cast<QSGTransformNode*>(rootRectNode->firstChild()); - Q_ASSERT(rootTransformNode->type() == QSGNode::TransformNodeType); - - const qreal percentageComplete = time / qreal(animationDuration); - const qreal firstPhaseProgress = percentageComplete <= 0.5 ? percentageComplete * 2 : 0; - const qreal secondPhaseProgress = percentageComplete > 0.5 ? (percentageComplete - 0.5) * 2 : 0; - - QSGTransformNode *transformNode = static_cast<QSGTransformNode*>(rootTransformNode->firstChild()); - const QColor color(0x35, 0x36, 0x37); - const QColor transparent(Qt::transparent); - Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); - for (int i = 0; i < circles; ++i) { - QSGOpacityNode *opacityNode = static_cast<QSGOpacityNode*>(transformNode->firstChild()); - Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); - - QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode*>(opacityNode->firstChild()); - Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - - const bool fill = (firstPhaseProgress > qreal(i) / circles) || (secondPhaseProgress > 0 && secondPhaseProgress < qreal(i) / circles); - rectNode->setPenWidth(fill ? 0 : 1); - rectNode->setColor(fill ? color : transparent); - rectNode->update(); - - transformNode = static_cast<QSGTransformNode*>(transformNode->nextSibling()); - } -} - -void QQuickBusyIndicatorAnimatorJob::writeBack() -{ -} - -void QQuickBusyIndicatorAnimatorJob::nodeWasDestroyed() -{ - m_node = nullptr; -} - -void QQuickBusyIndicatorAnimatorJob::afterNodeSync() -{ - m_node = QQuickItemPrivate::get(m_target)->childContainerNode(); -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/qquickdefaultbusyindicator.cpp b/src/imports/controls/qquickdefaultbusyindicator.cpp new file mode 100644 index 00000000..5b952476 --- /dev/null +++ b/src/imports/controls/qquickdefaultbusyindicator.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickdefaultbusyindicator_p.h" + +#include <QtCore/qset.h> +#include <QtCore/qelapsedtimer.h> +#include <QtGui/qpainter.h> +#include <QtQuick/private/qquickitem_p.h> +#include <QtQuick/qquickwindow.h> +#include <QtQuick/qsgnode.h> + +QT_BEGIN_NAMESPACE + +static const int CircleCount = 10; +static const int TotalDuration = 100 * CircleCount * 2; +static const QRgb TransparentColor = 0x00000000; +static const QRgb FillColor = 0xFF353637; + +static QPointF moveCircle(const QPointF &pos, qreal rotation, qreal distance) +{ + return pos - QTransform().rotate(rotation).map(QPointF(0, distance)); +} + +class QQuickDefaultBusyIndicatorNode : public QObject, public QSGNode +{ +public: + QQuickDefaultBusyIndicatorNode(QQuickDefaultBusyIndicator *item); + + int elapsed() const; + + void animate(); + void sync(QQuickDefaultBusyIndicator *item); + +private: + int m_offset; + QElapsedTimer m_timer; +}; + +QQuickDefaultBusyIndicatorNode::QQuickDefaultBusyIndicatorNode(QQuickDefaultBusyIndicator *item) + : m_offset(item->elapsed()) +{ + QQuickWindow *window = item->window(); + connect(window, &QQuickWindow::frameSwapped, window, &QQuickWindow::update); + connect(window, &QQuickWindow::beforeRendering, this, &QQuickDefaultBusyIndicatorNode::animate); + + for (int i = 0; i < CircleCount; ++i) { + QSGTransformNode *transformNode = new QSGTransformNode; + appendChildNode(transformNode); + + QQuickItemPrivate *d = QQuickItemPrivate::get(item); + QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); + rectNode->setAntialiasing(true); + transformNode->appendChildNode(rectNode); + } + + m_timer.restart(); +} + +int QQuickDefaultBusyIndicatorNode::elapsed() const +{ + return m_timer.elapsed() + m_offset; +} + +void QQuickDefaultBusyIndicatorNode::animate() +{ + qint64 time = m_timer.elapsed() + m_offset; + if (time >= TotalDuration) { + m_timer.restart(); + m_offset = 0; + } + + const qreal percentageComplete = time / qreal(TotalDuration); + const qreal firstPhaseProgress = percentageComplete <= 0.5 ? percentageComplete * 2 : 0; + const qreal secondPhaseProgress = percentageComplete > 0.5 ? (percentageComplete - 0.5) * 2 : 0; + + QSGTransformNode *transformNode = static_cast<QSGTransformNode*>(firstChild()); + Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); + for (int i = 0; i < CircleCount; ++i) { + QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode*>(transformNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + + const bool fill = (firstPhaseProgress > qreal(i) / CircleCount) || (secondPhaseProgress > 0 && secondPhaseProgress < qreal(i) / CircleCount); + rectNode->setColor(QColor::fromRgba(fill ? FillColor : TransparentColor)); + rectNode->setPenWidth(fill ? 0 : 1); + rectNode->update(); + + transformNode = static_cast<QSGTransformNode*>(transformNode->nextSibling()); + } +} + +void QQuickDefaultBusyIndicatorNode::sync(QQuickDefaultBusyIndicator *item) +{ + const qreal w = item->width(); + const qreal h = item->height(); + const qreal sz = qMin(w, h); + const qreal dx = (w - sz) / 2; + const qreal dy = (h - sz) / 2; + const int circleRadius = sz / 12; + + QSGTransformNode *transformNode = static_cast<QSGTransformNode *>(firstChild()); + for (int i = 0; i < CircleCount; ++i) { + Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); + + QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(transformNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + + QPointF pos = QPointF(sz / 2 - circleRadius, sz / 2 - circleRadius); + pos = moveCircle(pos, 360 / CircleCount * i, sz / 2 - circleRadius); + + QMatrix4x4 m; + m.translate(dx + pos.x(), dy + pos.y()); + transformNode->setMatrix(m); + + rectNode->setRect(QRectF(QPointF(), QSizeF(circleRadius * 2, circleRadius * 2))); + rectNode->setRadius(circleRadius); + + transformNode = static_cast<QSGTransformNode *>(transformNode->nextSibling()); + } +} + +QQuickDefaultBusyIndicator::QQuickDefaultBusyIndicator(QQuickItem *parent) : + QQuickItem(parent), m_elapsed(0) +{ + setFlag(ItemHasContents); +} + +int QQuickDefaultBusyIndicator::elapsed() const +{ + return m_elapsed; +} + +void QQuickDefaultBusyIndicator::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) +{ + QQuickItem::itemChange(change, data); + if (change == ItemVisibleHasChanged) + update(); +} + +QSGNode *QQuickDefaultBusyIndicator::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) +{ + QQuickDefaultBusyIndicatorNode *node = static_cast<QQuickDefaultBusyIndicatorNode *>(oldNode); + if (isVisible() && width() > 0 && height() > 0) { + if (!node) + node = new QQuickDefaultBusyIndicatorNode(this); + node->sync(this); + } else { + m_elapsed = node ? node->elapsed() : 0; + delete node; + node = nullptr; + } + return node; +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/qquickbusyindicatorring_p.h b/src/imports/controls/qquickdefaultbusyindicator_p.h index ceac0471..6147b8e3 100644 --- a/src/imports/controls/qquickbusyindicatorring_p.h +++ b/src/imports/controls/qquickdefaultbusyindicator_p.h @@ -34,8 +34,8 @@ ** ****************************************************************************/ -#ifndef QQUICKBUSYINDICATORRING_P_H -#define QQUICKBUSYINDICATORRING_P_H +#ifndef QQUICKDEFAULTBUSYINDICATOR_P_H +#define QQUICKDEFAULTBUSYINDICATOR_P_H // // W A R N I N G @@ -49,34 +49,28 @@ // #include <QtQuick/qquickitem.h> -#include <QtQuick/private/qquickanimatorjob_p.h> QT_BEGIN_NAMESPACE -class QQuickBusyIndicatorRing : public QQuickItem +class QQuickDefaultBusyIndicator : public QQuickItem { Q_OBJECT public: - explicit QQuickBusyIndicatorRing(QQuickItem *parent = nullptr); - ~QQuickBusyIndicatorRing(); + explicit QQuickDefaultBusyIndicator(QQuickItem *parent = nullptr); + + int elapsed() const; protected: + void itemChange(ItemChange change, const ItemChangeData &data) override; QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; -}; - -class QQuickBusyIndicatorAnimator : public QQuickAnimator -{ -public: - QQuickBusyIndicatorAnimator(QObject *parent = nullptr); -protected: - QString propertyName() const override; - QQuickAnimatorJob *createJob() const override; +private: + int m_elapsed; }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QQuickBusyIndicatorRing) +QML_DECLARE_TYPE(QQuickDefaultBusyIndicator) -#endif // QQUICKBUSYINDICATORRING_P_H +#endif // QQUICKDEFAULTBUSYINDICATOR_P_H diff --git a/src/imports/controls/qtquickcontrols2plugin.cpp b/src/imports/controls/qtquickcontrols2plugin.cpp index 1bbeefd6..db853f56 100644 --- a/src/imports/controls/qtquickcontrols2plugin.cpp +++ b/src/imports/controls/qtquickcontrols2plugin.cpp @@ -47,7 +47,7 @@ #include <QtQuickTemplates2/private/qquicktumbler_p.h> #include <QtQuickControls2/private/qquicktumblerview_p.h> -#include "qquickbusyindicatorring_p.h" +#include "qquickdefaultbusyindicator_p.h" #include "qquickdefaultstyle_p.h" #include "qquickdialring_p.h" #include "qquickprogressstrip_p.h" @@ -163,8 +163,7 @@ void QtQuickControls2Plugin::initializeEngine(QQmlEngine *engine, const char *ur engine->addImageProvider(QStringLiteral("default"), new QQuickColorImageProvider(QStringLiteral(":/qt-project.org/imports/QtQuick/Controls.2/images"))); const QByteArray import = QByteArray(uri) + ".impl"; - qmlRegisterType<QQuickBusyIndicatorRing>(import, 2, 0, "BusyRing"); - qmlRegisterType<QQuickBusyIndicatorAnimator>(import, 2, 0, "BusyRingAnimator"); + qmlRegisterType<QQuickDefaultBusyIndicator>(import, 2, 0, "BusyIndicatorImpl"); qmlRegisterType<QQuickProgressStrip>(import, 2, 0, "ProgressStrip"); qmlRegisterType<QQuickProgressAnimator>(import, 2, 0, "ProgressStripAnimator"); qmlRegisterType<QQuickDialRing>(import, 2, 0, "DialRing"); |