diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/controls/BusyIndicator.qml | 26 | ||||
-rw-r--r-- | src/imports/controls/controls.pro | 6 | ||||
-rw-r--r-- | src/imports/controls/images/spinner_large.png | bin | 8401 -> 0 bytes | |||
-rw-r--r-- | src/imports/controls/images/spinner_medium.png | bin | 2772 -> 0 bytes | |||
-rw-r--r-- | src/imports/controls/images/spinner_small.png | bin | 1810 -> 0 bytes | |||
-rw-r--r-- | src/imports/controls/qquickbusyindicatorring.cpp | 209 | ||||
-rw-r--r-- | src/imports/controls/qquickbusyindicatorring_p.h | 83 | ||||
-rw-r--r-- | src/imports/controls/qtlabscontrolsplugin.cpp | 6 | ||||
-rw-r--r-- | src/imports/controls/qtlabscontrolsplugin.qrc | 3 |
9 files changed, 310 insertions, 23 deletions
diff --git a/src/imports/controls/BusyIndicator.qml b/src/imports/controls/BusyIndicator.qml index 2d898566..1c55e75d 100644 --- a/src/imports/controls/BusyIndicator.qml +++ b/src/imports/controls/BusyIndicator.qml @@ -36,6 +36,7 @@ import QtQuick 2.6 import Qt.labs.controls 1.0 +import Qt.labs.controls.impl 1.0 import Qt.labs.templates 1.0 as T T.BusyIndicator { @@ -47,30 +48,17 @@ T.BusyIndicator { padding: 6 //! [contentItem] - contentItem: Item { - id: delegate + contentItem: BusyRing { + id: ring implicitWidth: 48 implicitHeight: 48 - opacity: control.running ? 1 : 0 - Behavior on opacity { OpacityAnimator { duration: 250 } } - Image { - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 - width: Math.min(parent.width, parent.height) - height: width - source: width <= 32 ? "qrc:/qt-project.org/imports/Qt/labs/controls/images/spinner_small.png" : - width >= 48 ? "qrc:/qt-project.org/imports/Qt/labs/controls/images/spinner_large.png" : - "qrc:/qt-project.org/imports/Qt/labs/controls/images/spinner_medium.png" + Behavior on opacity { OpacityAnimator { duration: 250 } } - RotationAnimator on rotation { - duration: 800 - loops: Animation.Infinite - from: 0 - to: 360 - running: control.visible && (control.running || delegate.opacity > 0) - } + BusyRingAnimator { + target: ring + running: control.visible && control.running } } //! [contentItem] diff --git a/src/imports/controls/controls.pro b/src/imports/controls/controls.pro index c3c5702c..dc24d8b1 100644 --- a/src/imports/controls/controls.pro +++ b/src/imports/controls/controls.pro @@ -12,8 +12,12 @@ QMAKE_DOCS = $$PWD/doc/qtlabscontrols.qdocconf OTHER_FILES += \ qmldir +HEADERS += \ + $$PWD/qquickbusyindicatorring_p.h + SOURCES += \ - $$PWD/qtlabscontrolsplugin.cpp + $$PWD/qtlabscontrolsplugin.cpp \ + $$PWD/qquickbusyindicatorring.cpp RESOURCES += \ $$PWD/qtlabscontrolsplugin.qrc diff --git a/src/imports/controls/images/spinner_large.png b/src/imports/controls/images/spinner_large.png Binary files differdeleted file mode 100644 index bcf51339..00000000 --- a/src/imports/controls/images/spinner_large.png +++ /dev/null diff --git a/src/imports/controls/images/spinner_medium.png b/src/imports/controls/images/spinner_medium.png Binary files differdeleted file mode 100644 index da8141bf..00000000 --- a/src/imports/controls/images/spinner_medium.png +++ /dev/null diff --git a/src/imports/controls/images/spinner_small.png b/src/imports/controls/images/spinner_small.png Binary files differdeleted file mode 100644 index 1f158f56..00000000 --- a/src/imports/controls/images/spinner_small.png +++ /dev/null diff --git a/src/imports/controls/qquickbusyindicatorring.cpp b/src/imports/controls/qquickbusyindicatorring.cpp new file mode 100644 index 00000000..4711ae1b --- /dev/null +++ b/src/imports/controls/qquickbusyindicatorring.cpp @@ -0,0 +1,209 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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/qsgsimplerectnode.h> +#include <QtQuick/qquickwindow.h> + +QT_BEGIN_NAMESPACE + +class QQuickBusyIndicatorAnimatorJob : public QQuickAnimatorJob +{ +public: + QQuickBusyIndicatorAnimatorJob(); + ~QQuickBusyIndicatorAnimatorJob(); + + void updateCurrentTime(int time) Q_DECL_OVERRIDE; + void writeBack() Q_DECL_OVERRIDE; + void nodeWasDestroyed() Q_DECL_OVERRIDE; +}; + +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 = new QSGSimpleRectNode(boundingRect(), Qt::transparent); + static_cast<QSGSimpleRectNode *>(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; + + 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); + + QSGRectangleNode *rectNode = d->sceneGraphContext()->createRectangleNode(); + rectNode->setAntialiasing(true); + rectNode->setColor(QColor("#353637")); + rectNode->setPenColor(QColor("#353637")); + opacityNode->appendChildNode(rectNode); + } + + QSGNode *opacityNode = transformNode->firstChild(); + Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); + + QSGRectangleNode *rectNode = static_cast<QSGRectangleNode *>(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() +{ +} + +QQuickBusyIndicatorAnimatorJob::~QQuickBusyIndicatorAnimatorJob() +{ +} + +void QQuickBusyIndicatorAnimatorJob::updateCurrentTime(int time) +{ + if (!m_target) + return; + + QSGNode *childContainerNode = QQuickItemPrivate::get(m_target)->childContainerNode(); + QSGSimpleRectNode *rootRectNode = static_cast<QSGSimpleRectNode*>(childContainerNode->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()); + 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); + + QSGRectangleNode *rectNode = static_cast<QSGRectangleNode*>(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 ? QColor("#353637") : QColor("transparent")); + rectNode->update(); + + transformNode = static_cast<QSGTransformNode*>(transformNode->nextSibling()); + } +} + +void QQuickBusyIndicatorAnimatorJob::writeBack() +{ +} + +void QQuickBusyIndicatorAnimatorJob::nodeWasDestroyed() +{ +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/qquickbusyindicatorring_p.h b/src/imports/controls/qquickbusyindicatorring_p.h new file mode 100644 index 00000000..24342349 --- /dev/null +++ b/src/imports/controls/qquickbusyindicatorring_p.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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$ +** +****************************************************************************/ + +#ifndef QQUICKBUSYINDICATOR_P_H +#define QQUICKBUSYINDICATOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtQuick/qquickitem.h> +#include <QtQuick/private/qquickanimatorjob_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickBusyIndicatorRing : public QQuickItem +{ + Q_OBJECT + +public: + explicit QQuickBusyIndicatorRing(QQuickItem *parent = Q_NULLPTR); + ~QQuickBusyIndicatorRing(); + +protected: + QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) Q_DECL_OVERRIDE; +}; + +class QQuickBusyIndicatorAnimator : public QQuickAnimator +{ +public: + QQuickBusyIndicatorAnimator(QObject *parent = Q_NULLPTR); + +protected: + QString propertyName() const Q_DECL_OVERRIDE; + QQuickAnimatorJob *createJob() const Q_DECL_OVERRIDE; +}; + +Q_DECLARE_TYPEINFO(QQuickBusyIndicatorRing, Q_COMPLEX_TYPE); +Q_DECLARE_TYPEINFO(QQuickBusyIndicatorAnimator, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKBUSYINDICATOR_P_H diff --git a/src/imports/controls/qtlabscontrolsplugin.cpp b/src/imports/controls/qtlabscontrolsplugin.cpp index 05135213..6c0bacfb 100644 --- a/src/imports/controls/qtlabscontrolsplugin.cpp +++ b/src/imports/controls/qtlabscontrolsplugin.cpp @@ -45,6 +45,8 @@ #include <QtLabsTemplates/private/qquickpopup_p.h> #include <QtLabsControls/private/qquickstyleselector_p.h> +#include "qquickbusyindicatorring_p.h" + static inline void initResources() { Q_INIT_RESOURCE(qtlabscontrolsplugin); @@ -113,6 +115,10 @@ void QtLabsControlsPlugin::initializeEngine(QQmlEngine *engine, const char *uri) Q_UNUSED(engine); Q_UNUSED(uri); initResources(); + + const QByteArray import = QByteArray(uri) + ".impl"; + qmlRegisterType<QQuickBusyIndicatorRing>(import, 1, 0, "BusyRing"); + qmlRegisterType<QQuickBusyIndicatorAnimator>(import, 1, 0, "BusyRingAnimator"); } QT_END_NAMESPACE diff --git a/src/imports/controls/qtlabscontrolsplugin.qrc b/src/imports/controls/qtlabscontrolsplugin.qrc index cb7bc994..1147ae3d 100644 --- a/src/imports/controls/qtlabscontrolsplugin.qrc +++ b/src/imports/controls/qtlabscontrolsplugin.qrc @@ -1,8 +1,5 @@ <RCC> <qresource prefix="/qt-project.org/imports/Qt/labs/controls"> - <file>images/spinner_small.png</file> - <file>images/spinner_medium.png</file> - <file>images/spinner_large.png</file> <file>images/check.png</file> <file>images/check@2x.png</file> <file>images/check@3x.png</file> |