Skip to content

Commit c0070db

Browse files
committed
qml: Introduce the BlockClock.qml and BlockClockComponent.qml files
- The BlockClock.qml files provides the control for BlockClock and determines how the elements would be displayed. - The BlockClockComponent.qml file uses the aforementioned control to display the value, and determines what will be displayed.
1 parent c38209e commit c0070db

File tree

5 files changed

+229
-0
lines changed

5 files changed

+229
-0
lines changed

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"files.associations": {
3+
"__split_buffer": "cpp",
4+
"deque": "cpp",
5+
"list": "cpp"
6+
}
7+
}

src/Makefile.qt.include

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,15 @@ QML_QRC = qml/bitcoin_qml.qrc
322322
QML_RES_QML = \
323323
qml/components/AboutOptions.qml \
324324
qml/components/BlockCounter.qml \
325+
qml/components/BlockClockComponent.qml \
325326
qml/components/ConnectionOptions.qml \
326327
qml/components/ConnectionSettings.qml \
327328
qml/components/DeveloperOptions.qml \
328329
qml/components/PeersIndicator.qml \
329330
qml/components/StorageLocations.qml \
330331
qml/components/StorageOptions.qml \
331332
qml/components/StorageSettings.qml \
333+
qml/controls/BlockClock.qml \
332334
qml/controls/ContinueButton.qml \
333335
qml/controls/ExternalLink.qml \
334336
qml/controls/Header.qml \

src/qml/bitcoin_qml.qrc

Lines changed: 2 additions & 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/BlockClockComponent.qml</file>
45
<file>components/BlockCounter.qml</file>
56
<file>components/ConnectionOptions.qml</file>
67
<file>components/ConnectionSettings.qml</file>
@@ -9,6 +10,7 @@
910
<file>components/StorageLocations.qml</file>
1011
<file>components/StorageOptions.qml</file>
1112
<file>components/StorageSettings.qml</file>
13+
<file>controls/BlockClock.qml</file>
1214
<file>controls/ContinueButton.qml</file>
1315
<file>controls/ExternalLink.qml</file>
1416
<file>controls/Header.qml</file>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import QtQuick 2.15
2+
import QtQuick.Controls 2.15
3+
import QtQuick.Layouts 1.15
4+
import "../controls"
5+
6+
BlockClock {
7+
id: blockClock
8+
anchors.centerIn: parent
9+
synced: nodeModel.verificationProgress > 0.999
10+
pause: nodeModel.pause
11+
conns: nodeModel.numOutboundPeers > 0
12+
13+
states: [
14+
State {
15+
name: "intialBlockDownload"; when: !synced && !pause && conns
16+
PropertyChanges {
17+
target: blockClock
18+
19+
ringProgress: nodeModel.verificationProgress
20+
header: Math.round(ringProgress * 100) + "%"
21+
subText: Math.round(nodeModel.remainingSyncTime/60000) > 0 ? Math.round(nodeModel.remainingSyncTime/60000) + "mins" : Math.round(nodeModel.remainingSyncTime/1000) + "secs"
22+
}
23+
},
24+
25+
State {
26+
name: "blockClock"; when: synced && !pause && conns
27+
PropertyChanges {
28+
target: blockClock
29+
30+
ringProgress: blockList[0]
31+
header: nodeModel.blockTipHeight
32+
subText: "Latest Block"
33+
blockList: chainModel.timeRatioList
34+
}
35+
},
36+
37+
State {
38+
name: "Manual Pause"; when: pause
39+
PropertyChanges {
40+
target: blockClock
41+
42+
ringProgress: 0
43+
header: "Paused"
44+
subText: "Tap to start"
45+
blockList: {}
46+
}
47+
},
48+
49+
State {
50+
name: "Connecting"; when: !pause && !conns
51+
PropertyChanges {
52+
target: blockClock
53+
54+
ringProgress: 0
55+
header: "Connecting"
56+
subText: "Please Wait"
57+
blockList: {}
58+
}
59+
}
60+
]
61+
}

src/qml/controls/BlockClock.qml

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import QtQuick 2.15
2+
import QtQuick.Controls 2.15
3+
import QtQuick.Layouts 1.15
4+
5+
import "../components"
6+
7+
Item {
8+
id: root
9+
10+
Layout.alignment: Qt.AlignCenter
11+
width: size
12+
height: size
13+
14+
property real ringProgress: 0
15+
property string header
16+
property string subText
17+
property bool synced
18+
property bool pause
19+
property bool conns
20+
21+
property int size: 200
22+
property real arcBegin: 0
23+
property real arcEnd: ringProgress * 360
24+
property real lineWidth: 4
25+
property string colorCircle: "#f1d54a"
26+
property string colorBackground: Theme.color.neutral2
27+
28+
property variant blockList: []
29+
property variant colorList: ["#EC5445", "#ED6E46", "#EE8847", "#EFA148", "#F0BB49", "#F1D54A"]
30+
31+
property alias beginAnimation: animationArcBegin.enabled
32+
property alias endAnimation: animationArcEnd.enabled
33+
34+
property int animationDuration: 250
35+
36+
onArcBeginChanged: canvas.requestPaint()
37+
onArcEndChanged: canvas.requestPaint()
38+
onSyncedChanged: canvas.requestPaint()
39+
onBlockListChanged: canvas.requestPaint()
40+
41+
Behavior on arcBegin {
42+
id: animationArcBegin
43+
enabled: true
44+
NumberAnimation {
45+
duration: root.animationDuration
46+
easing.type: Easing.InOutCubic
47+
}
48+
}
49+
50+
Behavior on arcEnd {
51+
id: animationArcEnd
52+
enabled: true
53+
NumberAnimation {
54+
easing.type: Easing.Bezier
55+
easing.bezierCurve: [0.5, 0.0, 0.2, 1, 1, 1]
56+
duration: root.animationDuration
57+
}
58+
}
59+
60+
Canvas {
61+
id: canvas
62+
anchors.fill: parent
63+
rotation: -90
64+
65+
onPaint: {
66+
var ctx = getContext("2d")
67+
var x = width / 2
68+
var y = height / 2
69+
70+
ctx.reset()
71+
72+
// Paint background
73+
ctx.beginPath();
74+
ctx.arc(x, y, (width / 2) - parent.lineWidth / 2, 0, Math.PI * 2, false)
75+
ctx.lineWidth = root.lineWidth
76+
ctx.strokeStyle = root.colorBackground
77+
ctx.stroke()
78+
79+
if (!synced) {
80+
var start = Math.PI * (parent.arcBegin / 180)
81+
var end = Math.PI * (parent.arcEnd / 180)
82+
// Paint foreground arc
83+
ctx.beginPath();
84+
ctx.arc(x, y, (width / 2) - parent.lineWidth / 2, start, end, false)
85+
ctx.lineWidth = root.lineWidth
86+
ctx.strokeStyle = root.colorCircle
87+
ctx.stroke()
88+
}
89+
90+
else {
91+
var del = 0.0025
92+
// Paint Block time points
93+
for (var i=1; i<parent.blockList.length - 1; i++) {
94+
var starts = Math.PI * ((parent.blockList[i]) * 360 / 180)
95+
var ends = Math.PI * ((parent.blockList[i + 1]) * 360 / 180)
96+
var conf = blockList.length - i - 1
97+
ctx.beginPath();
98+
ctx.arc(x, y, (width / 2) - parent.lineWidth / 2, starts, ends, false)
99+
ctx.lineWidth = root.lineWidth
100+
ctx.strokeStyle = conf > 5 ? colorList[5] : colorList[conf]
101+
ctx.stroke()
102+
103+
// Paint dark segments
104+
var start = Math.PI * ((parent.blockList[i + 1] - del) * 360 / 180)
105+
ctx.beginPath();
106+
ctx.arc(x, y, (width / 2) - parent.lineWidth/2, start, ends, false)
107+
ctx.lineWidth = 4
108+
ctx.strokeStyle = root.colorBackground
109+
ctx.stroke();
110+
}
111+
112+
// Print last segment
113+
var starts = Math.PI * ((parent.blockList[parent.blockList.length - 1]) * 360 / 180)
114+
var ends = Math.PI * (ringProgress * 360 / 180)
115+
116+
ctx.beginPath();
117+
ctx.arc(x, y, (width / 2) - parent.lineWidth / 2, starts, ends, false)
118+
ctx.lineWidth = root.lineWidth
119+
ctx.strokeStyle = colorList[0];
120+
ctx.stroke()
121+
}
122+
}
123+
}
124+
125+
ColumnLayout {
126+
anchors.centerIn: root
127+
Image {
128+
Layout.alignment: Qt.AlignCenter
129+
source: "image://images/app"
130+
sourceSize.width: 30
131+
sourceSize.height: 30
132+
Layout.bottomMargin: 15
133+
}
134+
Header {
135+
Layout.fillWidth: true
136+
header: root.header
137+
headerSize: 32
138+
bold: true
139+
description: root.subText
140+
descriptionMargin: 0
141+
descriptionColor: Theme.color.neutral4
142+
Layout.bottomMargin: 20
143+
}
144+
PeersIndicator {
145+
Layout.alignment: Qt.AlignCenter
146+
numOutboundPeers: nodeModel.numOutboundPeers
147+
maxNumOutboundPeers: nodeModel.maxNumOutboundPeers
148+
}
149+
}
150+
151+
MouseArea {
152+
anchors.fill: canvas
153+
onClicked: {
154+
pause ? nodeModel.pause = false : nodeModel.pause = true
155+
}
156+
}
157+
}

0 commit comments

Comments
 (0)