Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickuniversalbusyindicator.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtCore/qmath.h>
7#include <QtCore/qeasingcurve.h>
8#include <QtQuick/private/qquickitem_p.h>
9#include <QtQuick/private/qsgadaptationlayer_p.h>
10#include <QtQuickControls2Impl/private/qquickanimatednode_p.h>
11
13
14static const int PhaseCount = 6;
15static const int Interval = 167;
16static const int TotalDuration = 4052;
17
19{
20public:
22
23 void updateCurrentTime(int time) override;
24 void sync(QQuickItem *item) override;
25
26private:
27 struct Phase {
28 Phase() = default;
29 Phase(int d, qreal f, qreal t, QEasingCurve::Type c) : duration(d), from(f), to(t), curve(c) { }
30 int duration = 0;
31 qreal from = 0;
32 qreal to = 0;
34 };
35
36 Phase m_phases[PhaseCount];
37};
38
41{
44 setCurrentTime(item->elapsed());
45
46 m_phases[0] = Phase(433, -110, 10, QEasingCurve::BezierSpline);
47 m_phases[1] = Phase(767, 10, 93, QEasingCurve::Linear );
48 m_phases[2] = Phase(417, 93, 205, QEasingCurve::BezierSpline);
49 m_phases[3] = Phase(400, 205, 357, QEasingCurve::BezierSpline);
50 m_phases[4] = Phase(766, 357, 439, QEasingCurve::Linear );
51 m_phases[5] = Phase(434, 439, 585, QEasingCurve::BezierSpline);
52
53 m_phases[0].curve.addCubicBezierSegment(QPointF(0.02, 0.33), QPointF(0.38, 0.77), QPointF(1.00, 1.00));
54 m_phases[2].curve.addCubicBezierSegment(QPointF(0.57, 0.17), QPointF(0.95, 0.75), QPointF(1.00, 1.00));
55 m_phases[3].curve.addCubicBezierSegment(QPointF(0.00, 0.19), QPointF(0.07, 0.72), QPointF(1.00, 1.00));
56 m_phases[5].curve.addCubicBezierSegment(QPointF(0.00, 0.00), QPointF(0.95, 0.37), QPointF(1.00, 1.00));
57}
58
60{
61 int nodeIndex = 0;
62 int count = childCount();
63 QSGTransformNode *transformNode = static_cast<QSGTransformNode *>(firstChild());
64 while (transformNode) {
65 Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType);
66
67 QSGOpacityNode *opacityNode = static_cast<QSGOpacityNode *>(transformNode->firstChild());
68 Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType);
69
70 int begin = nodeIndex * Interval;
71 int end = TotalDuration - (PhaseCount - nodeIndex - 1) * Interval;
72
73 bool visible = time >= begin && time <= end;
74 opacityNode->setOpacity(visible ? 1.0 : 0.0);
75
76 if (visible) {
77 int phaseIndex, remain = time, elapsed = 0;
78 for (phaseIndex = 0; phaseIndex < PhaseCount - 1; ++phaseIndex) {
79 if (remain <= m_phases[phaseIndex].duration + begin)
80 break;
81 remain -= m_phases[phaseIndex].duration;
82 elapsed += m_phases[phaseIndex].duration;
83 }
84
85 const Phase &phase = m_phases[phaseIndex];
86
87 qreal from = phase.from - nodeIndex * count;
88 qreal to = phase.to - nodeIndex * count;
90
91 qreal value = phase.curve.valueForProgress(pos / phase.duration);
92 qreal rotation = from + (to - from) * value;
93
95 matrix.rotate(rotation, 0, 0, 1);
96 transformNode->setMatrix(matrix);
97 }
98
99 transformNode = static_cast<QSGTransformNode *>(transformNode->nextSibling());
100 ++nodeIndex;
101 }
102}
103
105{
108
110 matrix.translate(item->width() / 2, item->height() / 2);
112
113 qreal size = qMin(item->width(), item->height());
114 qreal diameter = size / 10.0;
115 qreal radius = diameter / 2;
116 qreal offset = (size - diameter * 2) / M_PI;
117 const QRectF rect(offset, offset, diameter, diameter);
118
119 int count = indicator->count();
120 QSGNode *transformNode = firstChild();
121 for (int i = 0; i < count; ++i) {
122 if (!transformNode) {
123 transformNode = new QSGTransformNode;
124 appendChildNode(transformNode);
125
126 QSGOpacityNode *opacityNode = new QSGOpacityNode;
127 transformNode->appendChildNode(opacityNode);
128
129 QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode();
130 rectNode->setAntialiasing(true);
131 opacityNode->appendChildNode(rectNode);
132 }
133
134 QSGNode *opacityNode = transformNode->firstChild();
135 Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType);
136
137 QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(opacityNode->firstChild());
138 Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType);
139
140 rectNode->setRect(rect);
141 rectNode->setColor(indicator->color());
142 rectNode->setRadius(radius);
143 rectNode->update();
144
145 transformNode = transformNode->nextSibling();
146 }
147
148 while (transformNode) {
149 QSGNode *nextSibling = transformNode->nextSibling();
150 delete transformNode;
151 transformNode = nextSibling;
152 }
153}
154
160
162{
163 return m_count;
164}
165
167{
168 if (m_count == count)
169 return;
170
171 m_count = count;
172 update();
173}
174
176{
177 return m_color;
178}
179
181{
182 if (m_color == color)
183 return;
184
185 m_color = color;
186 update();
187}
188
190{
191 return m_elapsed;
192}
193
200
202{
204 if (isVisible() && width() > 0 && height() > 0) {
205 if (!node) {
206 node = new QQuickUniversalBusyIndicatorNode(this);
207 node->start();
208 }
209 node->sync(this);
210 } else {
211 m_elapsed = node ? node->currentTime() : 0;
212 delete node;
213 node = nullptr;
214 }
215 return node;
216}
217
219
220#include "moc_qquickuniversalbusyindicator_p.cpp"
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtCore
void addCubicBezierSegment(const QPointF &c1, const QPointF &c2, const QPointF &endPoint)
Adds a segment of a cubic bezier spline to define a custom easing curve.
Type
The type of easing curve.
qreal valueForProgress(qreal progress) const
Return the effective progress for the easing curve at progress.
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
void rotate(float angle, const QVector3D &vector)
Multiples this matrix by another that rotates coordinates through angle degrees about vector.
void translate(const QVector3D &vector)
Multiplies this matrix by another that translates coordinates by the components of vector.
\inmodule QtCore\reentrant
Definition qpoint.h:217
void setLoopCount(int count)
void setCurrentTime(int time)
void setDuration(int duration)
void start(int duration=0)
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
void setFlag(Flag flag, bool enabled=true)
Enables the specified flag for this item if enabled is true; if enabled is false, the flag is disable...
bool isVisible() const
qreal width
This property holds the width of this item.
Definition qquickitem.h:75
virtual void itemChange(ItemChange, const ItemChangeData &)
Called when change occurs for this item.
qreal height
This property holds the height of this item.
Definition qquickitem.h:76
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
Definition qquickitem.h:144
@ ItemVisibleHasChanged
Definition qquickitem.h:148
void update()
Schedules a call to updatePaintNode() for this item.
QQuickUniversalBusyIndicatorNode(QQuickUniversalBusyIndicator *item)
QQuickUniversalBusyIndicator(QQuickItem *parent=nullptr)
void itemChange(ItemChange change, const ItemChangeData &data) override
Called when change occurs for this item.
QSGNode * updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override
Called on the render thread when it is time to sync the state of the item with the scene graph.
\inmodule QtCore\reentrant
Definition qrect.h:484
virtual void setAntialiasing(bool antialiasing)
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
Definition qsgnode.h:37
QSGNode * nextSibling() const
Returns the node after this in the parent's list of children.
Definition qsgnode.h:107
int childCount() const
Returns the number of child nodes.
Definition qsgnode.cpp:556
void appendChildNode(QSGNode *node)
Appends node to this node's list of children.
Definition qsgnode.cpp:398
@ TransformNodeType
Definition qsgnode.h:42
@ GeometryNodeType
Definition qsgnode.h:41
@ OpacityNodeType
Definition qsgnode.h:44
QSGNode * firstChild() const
Returns the first child of this node.
Definition qsgnode.h:105
NodeType type() const
Returns the type of this node.
Definition qsgnode.h:110
The QSGOpacityNode class is used to change opacity of nodes.
Definition qsgnode.h:276
void setOpacity(qreal opacity)
Sets the opacity of this node to opacity.
Definition qsgnode.cpp:1312
The QSGTransformNode class implements transformations in the scene graph.
Definition qsgnode.h:241
void setMatrix(const QMatrix4x4 &matrix)
Sets this transform node's matrix to matrix.
Definition qsgnode.cpp:1162
const QMatrix4x4 & matrix() const
Returns this transform node's matrix.
Definition qsgnode.h:247
QSGTransformNode()
Create a new QSGTransformNode with its matrix set to the identity matrix.
Definition qsgnode.cpp:1133
rect
[4]
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define M_PI
Definition qmath.h:209
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLuint end
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat f
GLuint color
[2]
GLenum GLuint GLintptr offset
const GLubyte * c
GLuint GLenum matrix
GLdouble GLdouble t
Definition qopenglext.h:243
static const int Interval
static const int TotalDuration
static QT_BEGIN_NAMESPACE const int PhaseCount
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
static double elapsed(qint64 after, qint64 before)
double qreal
Definition qtypes.h:187
QGraphicsItem * item
\inmodule QtQuick
Definition qquickitem.h:159