Skip to content

Commit aeefcd9

Browse files
committed
qml: Add connection animation to block clock
1 parent e3e7b4c commit aeefcd9

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

src/qml/components/BlockClock.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Item {
3030
timeRatioList: chainModel.timeRatioList
3131
verificationProgress: nodeModel.verificationProgress
3232
paused: root.paused
33+
connected: root.connected
3334
synced: nodeModel.verificationProgress > 0.999
3435
backgroundColor: Theme.color.neutral2
3536
timeTickColor: Theme.color.neutral5

src/qml/components/blockclockdial.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
#include <qml/components/blockclockdial.h>
66

7+
#include <QBrush>
78
#include <QColor>
89
#include <QPainterPath>
10+
#include <QConicalGradient>
911
#include <QPen>
1012
#include <QtMath>
1113

@@ -18,6 +20,26 @@ BlockClockDial::BlockClockDial(QQuickItem *parent)
1820
{
1921
}
2022

23+
void BlockClockDial::setupConnectingGradient(const QPen & pen)
24+
{
25+
m_connecting_gradient.setCenter(getBoundsForPen(pen).center());
26+
m_connecting_gradient.setAngle(m_connecting_start_angle);
27+
m_connecting_gradient.setColorAt(0, m_confirmation_colors[5]);
28+
m_connecting_gradient.setColorAt(0.5, m_confirmation_colors[5]);
29+
m_connecting_gradient.setColorAt(0.6, m_confirmation_colors[4]);
30+
m_connecting_gradient.setColorAt(0.7, m_confirmation_colors[3]);
31+
m_connecting_gradient.setColorAt(1, m_background_color);
32+
}
33+
34+
qreal BlockClockDial::decrementGradientAngle(qreal angle)
35+
{
36+
if (angle == -360) {
37+
return 0;
38+
} else {
39+
return angle -= 4;
40+
}
41+
}
42+
2143
void BlockClockDial::setTimeRatioList(QVariantList new_list)
2244
{
2345
m_time_ratio_list = new_list;
@@ -30,6 +52,12 @@ void BlockClockDial::setVerificationProgress(double progress)
3052
update();
3153
}
3254

55+
void BlockClockDial::setConnected(bool connected)
56+
{
57+
m_is_connected = connected;
58+
update();
59+
}
60+
3361
void BlockClockDial::setSynced(bool synced)
3462
{
3563
m_is_synced = synced;
@@ -139,6 +167,20 @@ void BlockClockDial::paintProgress(QPainter * painter)
139167
painter->drawArc(bounds, startAngle * 16, spanAngle * 16);
140168
}
141169

170+
void BlockClockDial::paintConnectingAnimation(QPainter * painter)
171+
{
172+
QPen pen;
173+
pen.setWidthF(4);
174+
setupConnectingGradient(pen);
175+
pen.setBrush(QBrush(m_connecting_gradient));
176+
pen.setCapStyle(Qt::RoundCap);
177+
const QRectF bounds = getBoundsForPen(pen);
178+
painter->setPen(pen);
179+
painter->drawArc(bounds, m_connecting_start_angle * 16, m_connecting_end_angle * 16);
180+
m_connecting_start_angle = decrementGradientAngle(m_connecting_start_angle);
181+
update();
182+
}
183+
142184
void BlockClockDial::paintBackground(QPainter * painter)
143185
{
144186
QPen pen(m_background_color);
@@ -186,6 +228,11 @@ void BlockClockDial::paint(QPainter * painter)
186228

187229
if (paused()) return;
188230

231+
if (!(connected())) {
232+
paintConnectingAnimation(painter);
233+
return;
234+
}
235+
189236
if (synced()) {
190237
paintBlocks(painter);
191238
} else {

src/qml/components/blockclockdial.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
#define BITCOIN_QML_COMPONENTS_BLOCKCLOCKDIAL_H
77

88
#include <QQuickPaintedItem>
9+
#include <QConicalGradient>
910
#include <QPainter>
1011

1112
class BlockClockDial : public QQuickPaintedItem
1213
{
1314
Q_OBJECT
1415
Q_PROPERTY(QVariantList timeRatioList READ timeRatioList WRITE setTimeRatioList)
1516
Q_PROPERTY(double verificationProgress READ verificationProgress WRITE setVerificationProgress)
17+
Q_PROPERTY(bool connected READ connected WRITE setConnected)
1618
Q_PROPERTY(bool synced READ synced WRITE setSynced)
1719
Q_PROPERTY(bool paused READ paused WRITE setPaused)
1820
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
@@ -25,6 +27,7 @@ class BlockClockDial : public QQuickPaintedItem
2527

2628
QVariantList timeRatioList() const { return m_time_ratio_list; };
2729
double verificationProgress() const { return m_verification_progress; };
30+
bool connected() const { return m_is_connected; };
2831
bool synced() const { return m_is_synced; };
2932
bool paused() const { return m_is_paused; };
3033
QColor backgroundColor() const { return m_background_color; };
@@ -34,25 +37,33 @@ class BlockClockDial : public QQuickPaintedItem
3437
public Q_SLOTS:
3538
void setTimeRatioList(QVariantList new_time);
3639
void setVerificationProgress(double progress);
40+
void setConnected(bool connected);
3741
void setSynced(bool synced);
3842
void setPaused(bool paused);
3943
void setBackgroundColor(QColor color);
4044
void setConfirmationColors(QList<QColor> colorList);
4145
void setTimeTickColor(QColor color);
4246

4347
private:
48+
void paintConnectingAnimation(QPainter * painter);
4449
void paintProgress(QPainter * painter);
4550
void paintBlocks(QPainter * painter);
4651
void paintBackground(QPainter * painter);
4752
void paintTimeTicks(QPainter * painter);
4853
QRectF getBoundsForPen(const QPen & pen);
4954
double degreesPerPixel();
55+
void setupConnectingGradient(const QPen & pen);
56+
qreal decrementGradientAngle(qreal angle);
5057

5158
QVariantList m_time_ratio_list;
5259
double m_verification_progress;
60+
bool m_is_connected;
5361
bool m_is_synced;
5462
bool m_is_paused;
5563
QColor m_background_color;
64+
QConicalGradient m_connecting_gradient;
65+
qreal m_connecting_start_angle = 90;
66+
const qreal m_connecting_end_angle = -180;
5667
QList<QColor> m_confirmation_colors;
5768
QColor m_time_tick_color;
5869
};

0 commit comments

Comments
 (0)