Skip to content

Commit da118f1

Browse files
johnny9jarolrod
authored andcommitted
qml: Add timer to control BlockClockDial connecting animation
1 parent 7ead714 commit da118f1

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/qml/components/blockclockdial.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,19 @@ BlockClockDial::BlockClockDial(QQuickItem *parent)
1717
, m_background_color{QColor("#2D2D2D")}
1818
, m_confirmation_colors{QList<QColor>{}}
1919
, m_time_tick_color{QColor("#000000")}
20+
, m_animation_timer{QTimer(this)}
21+
, m_delay_timer{QTimer(this)}
2022
{
23+
m_animation_timer.setTimerType(Qt::PreciseTimer);
24+
m_animation_timer.setInterval(16);
25+
m_delay_timer.setTimerType(Qt::PreciseTimer);
26+
m_delay_timer.setSingleShot(true);
27+
m_delay_timer.setInterval(5000);
28+
connect(&m_animation_timer, &QTimer::timeout,
29+
this, [=]() { this->update(); });
30+
connect(&m_delay_timer, &QTimer::timeout,
31+
this, [=]() { this->m_animation_timer.start(); });
32+
m_delay_timer.start();
2133
}
2234

2335
void BlockClockDial::setupConnectingGradient(const QPen & pen)
@@ -54,7 +66,15 @@ void BlockClockDial::setVerificationProgress(double progress)
5466

5567
void BlockClockDial::setConnected(bool connected)
5668
{
57-
m_is_connected = connected;
69+
if (m_is_connected != connected) {
70+
m_is_connected = connected;
71+
m_delay_timer.stop();
72+
if (m_is_connected) {
73+
m_animation_timer.stop();
74+
} else {
75+
m_delay_timer.start();
76+
}
77+
}
5878
update();
5979
}
6080

@@ -178,7 +198,6 @@ void BlockClockDial::paintConnectingAnimation(QPainter * painter)
178198
painter->setPen(pen);
179199
painter->drawArc(bounds, m_connecting_start_angle * 16, m_connecting_end_angle * 16);
180200
m_connecting_start_angle = decrementGradientAngle(m_connecting_start_angle);
181-
update();
182201
}
183202

184203
void BlockClockDial::paintBackground(QPainter * painter)
@@ -228,7 +247,7 @@ void BlockClockDial::paint(QPainter * painter)
228247

229248
if (paused()) return;
230249

231-
if (!(connected())) {
250+
if (m_animation_timer.isActive()) {
232251
paintConnectingAnimation(painter);
233252
return;
234253
}

src/qml/components/blockclockdial.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <QQuickPaintedItem>
99
#include <QConicalGradient>
1010
#include <QPainter>
11+
#include <QTimer>
1112

1213
class BlockClockDial : public QQuickPaintedItem
1314
{
@@ -66,6 +67,8 @@ public Q_SLOTS:
6667
const qreal m_connecting_end_angle = -180;
6768
QList<QColor> m_confirmation_colors;
6869
QColor m_time_tick_color;
70+
QTimer m_animation_timer;
71+
QTimer m_delay_timer;
6972
};
7073

7174
#endif // BITCOIN_QML_COMPONENTS_BLOCKCLOCKDIAL_H

0 commit comments

Comments
 (0)