Skip to content

Commit 6701ad2

Browse files
johnny9shaavan
andcommitted
qml: introduce the BlockClock
Implements a few of the BlockClock dial states. Sync progress while downloading, rendering blocks after sync, and pausing/unpausing the node. An additional Model is added, ChainModel, to provide the dial block information. Changes to NodeModel are also made to support the pausing/unpausing Dial feature. Co-authored-by: shaavan <shaavan.github@gmail.com>
1 parent 60bd8cb commit 6701ad2

File tree

9 files changed

+414
-19
lines changed

9 files changed

+414
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ share/qt/Info.plist
4646

4747
src/qt/*.moc
4848
src/qt/moc_*.cpp
49+
src/qml/components/moc_*.cpp
4950
src/qt/forms/ui_*.h
5051

5152
src/qt/test/moc*.cpp

src/Makefile.qt.include

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ QT_FORMS_UI = \
3535
qt/forms/transactiondescdialog.ui
3636

3737
QT_MOC_CPP = \
38+
qml/components/moc_blockclockdial.cpp \
3839
qml/moc_appmode.cpp \
3940
qml/moc_chainmodel.cpp \
4041
qml/moc_nodemodel.cpp \
@@ -113,6 +114,7 @@ BITCOIN_QT_H = \
113114
qml/appmode.h \
114115
qml/bitcoin.h \
115116
qml/chainmodel.h \
117+
qml/components/blockclockdial.h \
116118
qml/imageprovider.h \
117119
qml/nodemodel.h \
118120
qml/options_model.h \
@@ -294,6 +296,7 @@ BITCOIN_QT_WALLET_CPP = \
294296
BITCOIN_QML_BASE_CPP = \
295297
qml/bitcoin.cpp \
296298
qml/chainmodel.cpp \
299+
qml/components/blockclockdial.cpp \
297300
qml/imageprovider.cpp \
298301
qml/nodemodel.cpp \
299302
qml/options_model.cpp \
@@ -325,6 +328,7 @@ QML_QRC_CPP = qml/qrc_bitcoin.cpp
325328
QML_QRC = qml/bitcoin_qml.qrc
326329
QML_RES_QML = \
327330
qml/components/AboutOptions.qml \
331+
qml/components/BlockClock.qml \
328332
qml/components/BlockCounter.qml \
329333
qml/components/ConnectionOptions.qml \
330334
qml/components/ConnectionSettings.qml \

src/qml/bitcoin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <noui.h>
1515
#include <qml/appmode.h>
1616
#include <qml/chainmodel.h>
17+
#include <qml/components/blockclockdial.h>
1718
#include <qml/imageprovider.h>
1819
#include <qml/nodemodel.h>
1920
#include <qml/options_model.h>
@@ -205,6 +206,7 @@ int QmlGuiMain(int argc, char* argv[])
205206
#endif // __ANDROID__
206207

207208
qmlRegisterSingletonInstance<AppMode>("org.bitcoincore.qt", 1, 0, "AppMode", &app_mode);
209+
qmlRegisterType<BlockClockDial>("org.bitcoincore.qt", 1, 0, "BlockClockDial");
208210

209211
engine.load(QUrl(QStringLiteral("qrc:///qml/pages/main.qml")));
210212
if (engine.rootObjects().isEmpty()) {

src/qml/bitcoin_qml.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE RCC><RCC version="1.0">
22
<qresource prefix="/qml">
33
<file>components/AboutOptions.qml</file>
4+
<file>components/BlockClock.qml</file>
45
<file>components/BlockCounter.qml</file>
56
<file>components/ConnectionOptions.qml</file>
67
<file>components/ConnectionSettings.qml</file>

src/qml/components/BlockClock.qml

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// Copyright (c) 2023 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
import QtQuick 2.15
6+
import QtQuick.Controls 2.15
7+
import QtQuick.Layouts 1.15
8+
9+
import org.bitcoincore.qt 1.0
10+
11+
import "../controls"
12+
13+
Item {
14+
id: root
15+
16+
Layout.alignment: Qt.AlignCenter
17+
implicitWidth: 200
18+
implicitHeight: 200
19+
20+
property alias header: mainText.text
21+
property alias headerSize: mainText.font.pixelSize
22+
property alias subText: subText.text
23+
property int headerSize: 32
24+
property bool synced: nodeModel.verificationProgress > 0.999
25+
property bool paused: false
26+
property bool conns: true
27+
28+
BlockClockDial {
29+
id: dial
30+
anchors.fill: parent
31+
timeRatioList: chainModel.timeRatioList
32+
verificationProgress: nodeModel.verificationProgress
33+
paused: root.paused
34+
synced: nodeModel.verificationProgress > 0.999
35+
backgroundColor: Theme.color.neutral2
36+
timeTickColor: Theme.color.neutral5
37+
}
38+
39+
Button {
40+
id: bitcoinIcon
41+
background: null
42+
icon.source: "image://images/bitcoin-circle"
43+
icon.color: Theme.color.neutral9
44+
icon.width: 40
45+
icon.height: 40
46+
anchors.bottom: mainText.top
47+
anchors.horizontalCenter: root.horizontalCenter
48+
}
49+
50+
Label {
51+
id: mainText
52+
anchors.centerIn: parent
53+
font.family: "Inter"
54+
font.styleName: "Semi Bold"
55+
font.pixelSize: 32
56+
color: Theme.color.neutral9
57+
}
58+
59+
Label {
60+
id: subText
61+
anchors.top: mainText.bottom
62+
anchors.horizontalCenter: root.horizontalCenter
63+
font.family: "Inter"
64+
font.styleName: "Semi Bold"
65+
font.pixelSize: 18
66+
color: Theme.color.neutral4
67+
}
68+
69+
RowLayout {
70+
id: peersIndicator
71+
anchors.top: subText.bottom
72+
anchors.topMargin: 20
73+
anchors.horizontalCenter: root.horizontalCenter
74+
spacing: 5
75+
Repeater {
76+
model: 5
77+
Rectangle {
78+
width: 3
79+
height: width
80+
radius: width/2
81+
color: Theme.color.neutral9
82+
}
83+
}
84+
}
85+
86+
MouseArea {
87+
anchors.fill: dial
88+
onClicked: {
89+
root.paused = !root.paused
90+
nodeModel.pause = root.paused
91+
}
92+
}
93+
94+
states: [
95+
State {
96+
name: "intialBlockDownload"; when: !synced && !paused && conns
97+
PropertyChanges {
98+
target: root
99+
header: Math.round(nodeModel.verificationProgress * 100) + "%"
100+
subText: Math.round(nodeModel.remainingSyncTime/60000) > 0 ? Math.round(nodeModel.remainingSyncTime/60000) + "mins" : Math.round(nodeModel.remainingSyncTime/1000) + "secs"
101+
}
102+
},
103+
104+
State {
105+
name: "blockClock"; when: synced && !paused && conns
106+
PropertyChanges {
107+
target: root
108+
header: Number(nodeModel.blockTipHeight).toLocaleString(Qt.locale(), 'f', 0)
109+
subText: "Blocktime"
110+
}
111+
},
112+
113+
State {
114+
name: "Manual Pause"; when: paused
115+
PropertyChanges {
116+
target: root
117+
header: "Paused"
118+
headerSize: 24
119+
subText: "Tap to resume"
120+
}
121+
PropertyChanges {
122+
target: bitcoinIcon
123+
anchors.bottomMargin: 5
124+
}
125+
PropertyChanges {
126+
target: subText
127+
anchors.topMargin: 4
128+
}
129+
},
130+
131+
State {
132+
name: "Connecting"; when: !paused && !conns
133+
PropertyChanges {
134+
target: root
135+
header: "Connecting"
136+
headerSize: 24
137+
subText: "Please Wait"
138+
}
139+
PropertyChanges {
140+
target: bitcoinIcon
141+
anchors.bottomMargin: 5
142+
}
143+
PropertyChanges {
144+
target: subText
145+
anchors.topMargin: 4
146+
}
147+
}
148+
]
149+
}

0 commit comments

Comments
 (0)