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
qquickbasicbusyindicator.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 <QtQuick/private/qquickitem_p.h>
7#include <QtQuick/private/qsgadaptationlayer_p.h>
8#include <QtQuickControls2Impl/private/qquickanimatednode_p.h>
9
11
12static const int CircleCount = 10;
13static const int QbbiTotalDuration = 100 * CircleCount * 2;
14static const QRgb TransparentColor = 0x00000000;
15
16static QPointF moveCircle(const QPointF &pos, qreal rotation, qreal distance)
17{
18 return pos - QTransform().rotate(rotation).map(QPointF(0, distance));
19}
20
22{
23public:
25
26 void updateCurrentTime(int time) override;
27 void sync(QQuickItem *item) override;
28
29private:
30 QColor m_pen;
31 QColor m_fill;
32};
33
36{
39 setCurrentTime(item->elapsed());
40
41 for (int i = 0; i < CircleCount; ++i) {
42 QSGTransformNode *transformNode = new QSGTransformNode;
43 appendChildNode(transformNode);
44
46 QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode();
47 rectNode->setAntialiasing(true);
48 transformNode->appendChildNode(rectNode);
49 }
50}
51
53{
54 const qreal percentageComplete = time / qreal(QbbiTotalDuration);
55 const qreal firstPhaseProgress = percentageComplete <= 0.5 ? percentageComplete * 2 : 0;
56 const qreal secondPhaseProgress = percentageComplete > 0.5 ? (percentageComplete - 0.5) * 2 : 0;
57
58 QSGTransformNode *transformNode = static_cast<QSGTransformNode*>(firstChild());
59 Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType);
60 for (int i = 0; i < CircleCount; ++i) {
61 QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode*>(transformNode->firstChild());
62 Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType);
63
64 const bool fill = (firstPhaseProgress > qreal(i) / CircleCount) || (secondPhaseProgress > 0 && secondPhaseProgress < qreal(i) / CircleCount);
65 rectNode->setColor(fill ? m_fill : QColor::fromRgba(TransparentColor));
66 rectNode->setPenColor(m_pen);
67 rectNode->setPenWidth(1);
68 rectNode->update();
69
70 transformNode = static_cast<QSGTransformNode*>(transformNode->nextSibling());
71 }
72}
73
75{
76 const qreal w = item->width();
77 const qreal h = item->height();
78 const qreal sz = qMin(w, h);
79 const qreal dx = (w - sz) / 2;
80 const qreal dy = (h - sz) / 2;
81 const int circleRadius = sz / 12;
82
83 m_pen = static_cast<QQuickBasicBusyIndicator *>(item)->pen();
84 m_fill = static_cast<QQuickBasicBusyIndicator *>(item)->fill();
85
86 QSGTransformNode *transformNode = static_cast<QSGTransformNode *>(firstChild());
87 for (int i = 0; i < CircleCount; ++i) {
88 Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType);
89
90 QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(transformNode->firstChild());
91 Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType);
92
93 QPointF pos = QPointF(sz / 2 - circleRadius, sz / 2 - circleRadius);
94 pos = moveCircle(pos, 360.0 / CircleCount * i, sz / 2 - circleRadius);
95
97 m.translate(dx + pos.x(), dy + pos.y());
98 transformNode->setMatrix(m);
99
100 rectNode->setRect(QRectF(QPointF(), QSizeF(circleRadius * 2, circleRadius * 2)));
101 rectNode->setRadius(circleRadius);
102
103 transformNode = static_cast<QSGTransformNode *>(transformNode->nextSibling());
104 }
105}
106
112
114{
115 return m_pen;
116}
117
119{
120 if (pen == m_pen)
121 return;
122
123 m_pen = pen;
124 update();
125}
126
128{
129 return m_fill;
130}
131
133{
134 if (fill == m_fill)
135 return;
136
137 m_fill = fill;
138 update();
139}
140
142{
143 return isVisible();
144}
145
147{
148 if (running)
149 setVisible(true);
150}
151
153{
154 return m_elapsed;
155}
156
158{
160 switch (change) {
162 if (qFuzzyIsNull(data.realValue))
163 setVisible(false);
164 break;
166 update();
167 break;
168 default:
169 break;
170 }
171}
172
174{
175 QQuickBasicBusyIndicatorNode *node = static_cast<QQuickBasicBusyIndicatorNode *>(oldNode);
176 if (isRunning() && width() > 0 && height() > 0) {
177 if (!node) {
178 node = new QQuickBasicBusyIndicatorNode(this);
179 node->start();
180 }
181 node->sync(this);
182 } else {
183 m_elapsed = node ? node->currentTime() : 0;
184 delete node;
185 node = nullptr;
186 }
187 return node;
188}
189
191
192#include "moc_qquickbasicbusyindicator_p.cpp"
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
static QColor fromRgba(QRgb rgba) noexcept
Static convenience function that returns a QColor constructed from the given QRgb value rgba.
Definition qcolor.cpp:2385
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
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)
void sync(QQuickItem *item) override
void updateCurrentTime(int time) override
QQuickBasicBusyIndicatorNode(QQuickBasicBusyIndicator *item)
QQuickBasicBusyIndicator(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.
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
void setVisible(bool)
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
@ ItemOpacityHasChanged
Definition qquickitem.h:150
void update()
Schedules a call to updatePaintNode() for this item.
\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
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
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 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
QSGTransformNode()
Create a new QSGTransformNode with its matrix set to the identity matrix.
Definition qsgnode.cpp:1133
\inmodule QtCore
Definition qsize.h:208
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
QTransform & rotate(qreal a, Qt::Axis axis=Qt::ZAxis, qreal distanceToPlane=1024.0f)
QPoint map(const QPoint &p) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Combined button and popup list for selecting options.
static Q_CONSTINIT QBasicAtomicInt running
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:349
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
const GLfloat * m
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei GLsizei GLfloat distance
GLfloat GLfloat GLfloat GLfloat h
static QT_BEGIN_NAMESPACE const int CircleCount
static QPointF moveCircle(const QPointF &pos, qreal rotation, qreal distance)
static const int QbbiTotalDuration
static const QRgb TransparentColor
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
Definition qrgb.h:13
double qreal
Definition qtypes.h:187
ba fill(true)
QGraphicsItem * item
\inmodule QtQuick
Definition qquickitem.h:159