Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickfusionbusyindicator.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// Qt-Security score:significant reason:default
4
6
7#include <QtGui/qpainter.h>
8
10
11QQuickFusionBusyIndicator::QQuickFusionBusyIndicator(QQuickItem *parent)
13{
14}
15
16QColor QQuickFusionBusyIndicator::color() const
17{
18 return m_color;
19}
20
21void QQuickFusionBusyIndicator::setColor(const QColor &color)
22{
23 if (color == m_color)
24 return;
25
26 m_color = color;
27 update();
28}
29
30bool QQuickFusionBusyIndicator::isRunning() const
31{
32 return isVisible();
33}
34
35void QQuickFusionBusyIndicator::setRunning(bool running)
36{
37 m_running = running;
38
39 if (m_running) {
40 setVisible(true);
41 update();
42 }
43 // Don't set visible to false if not running, because we use an opacity animation (in QML) to hide ourselves.
44}
45
46void QQuickFusionBusyIndicator::paint(QPainter *painter)
47{
48 const qreal w = width();
49 const qreal h = height();
50 if (w <= 0 || h <= 0 || !isRunning())
51 return;
52
53 const qreal sz = qMin(w, h);
54 const qreal dx = (w - sz) / 2;
55 const qreal dy = (h - sz) / 2;
56 const int hpw = qRound(qMax(qreal(1), sz / 14)) & -1;
57 const int pw = 2 * hpw;
58 const QRectF bounds(dx + hpw, dy + hpw, sz - pw - 1, sz - pw - 1);
59
60 QConicalGradient gradient;
61 gradient.setCenter(QPointF(dx + sz / 2, dy + sz / 2));
62 gradient.setColorAt(0, m_color);
63 gradient.setColorAt(0.1, m_color);
64 gradient.setColorAt(1, Qt::transparent);
65
66 painter->translate(0.5, 0.5);
67 painter->setRenderHint(QPainter::Antialiasing, true);
68 painter->setPen(QPen(gradient, pw, Qt::SolidLine));
69 painter->drawArc(bounds, 0, 360 * 16);
70 painter->setPen(QPen(m_color, pw, Qt::SolidLine, Qt::RoundCap));
71 painter->drawArc(bounds, 0, 20 * 16);
72}
73
74void QQuickFusionBusyIndicator::itemChange(ItemChange change, const ItemChangeData &data)
75{
76 QQuickPaintedItem::itemChange(change, data);
77
78 switch (change) {
79 case ItemOpacityHasChanged:
80 // If running is set to false and then true within a short period (QTBUG-85860), our
81 // OpacityAnimator cancels the 1 => 0 animation (which was for running being set to false),
82 // setting opacity to 0 and hence visible to false. This happens _after_ setRunning(true)
83 // was called, because the properties were set synchronously but the animation is
84 // asynchronous. To account for this situation, we only hide ourselves if we're not running.
85 if (qFuzzyIsNull(data.realValue) && !m_running)
86 setVisible(false);
87 break;
88 case ItemVisibleHasChanged:
89 update();
90 break;
91 default:
92 break;
93 }
94}
95
96QT_END_NAMESPACE
97
98#include "moc_qquickfusionbusyindicator_p.cpp"
QObject * parent
Definition qobject.h:73
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64