Skip to content

Commit a7e4faa

Browse files
committed
qml: Introduce Tooltip for the BlockClock navbar button
The Tooltip will appear when hovering over the BlockClock tab button in the desktop navigation bar. It will show the current state of IBD.
1 parent 085805f commit a7e4faa

File tree

8 files changed

+80
-63
lines changed

8 files changed

+80
-63
lines changed

src/Makefile.qt.include

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ QML_RES_ICONS = \
336336
qml/res/icons/shutdown.png \
337337
qml/res/icons/singlesig-wallet.png \
338338
qml/res/icons/storage-dark.png \
339-
qml/res/icons/storage-light.png
339+
qml/res/icons/storage-light.png \
340+
qml/res/icons/tooltip-arrow.png
340341

341342
QML_QRC_CPP = qml/qrc_bitcoin.cpp
342343
QML_QRC = qml/bitcoin_qml.qrc
@@ -360,6 +361,7 @@ QML_RES_QML = \
360361
qml/components/StorageSettings.qml \
361362
qml/components/ThemeSettings.qml \
362363
qml/components/TotalBytesIndicator.qml \
364+
qml/components/Tooltip.qml \
363365
qml/controls/ContinueButton.qml \
364366
qml/controls/CoreText.qml \
365367
qml/controls/ExternalLink.qml \
@@ -381,6 +383,7 @@ QML_RES_QML = \
381383
qml/controls/TextButton.qml \
382384
qml/controls/Theme.qml \
383385
qml/controls/ToggleButton.qml \
386+
qml/controls/utils.js \
384387
qml/controls/ValueInput.qml \
385388
qml/pages/initerrormessage.qml \
386389
qml/pages/main.qml \

src/qml/bitcoin_qml.qrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<file>components/StorageSettings.qml</file>
2020
<file>components/ThemeSettings.qml</file>
2121
<file>components/TotalBytesIndicator.qml</file>
22+
<file>components/Tooltip.qml</file>
2223
<file>controls/ContinueButton.qml</file>
2324
<file>controls/CoreText.qml</file>
2425
<file>controls/ExternalLink.qml</file>
@@ -41,6 +42,7 @@
4142
<file>controls/TextButton.qml</file>
4243
<file>controls/Theme.qml</file>
4344
<file>controls/ToggleButton.qml</file>
45+
<file>controls/utils.js</file>
4446
<file>controls/ValueInput.qml</file>
4547
<file>pages/initerrormessage.qml</file>
4648
<file>pages/main.qml</file>
@@ -88,6 +90,7 @@
8890
<file alias="singlesig-wallet">res/icons/singlesig-wallet.png</file>
8991
<file alias="storage-dark">res/icons/storage-dark.png</file>
9092
<file alias="storage-light">res/icons/storage-light.png</file>
93+
<file alias="tooltip-arrow">res/icons/tooltip-arrow.png</file>
9194
</qresource>
9295
<qresource prefix="/fonts">
9396
<file alias="inter/regular">res/fonts/Inter-Regular.otf</file>

src/qml/components/BlockClock.qml

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Qt.labs.settings 1.0
1010
import org.bitcoincore.qt 1.0
1111

1212
import "../controls"
13+
import "../controls/utils.js" as Utils
1314

1415
Item {
1516
id: root
@@ -28,7 +29,7 @@ Item {
2829
property bool synced: nodeModel.verificationProgress > 0.999
2930
property string syncProgress: formatProgressPercentage(nodeModel.verificationProgress * 100)
3031
property bool paused: false
31-
property var syncState: formatRemainingSyncTime(nodeModel.remainingSyncTime)
32+
property var syncState: Utils.formatRemainingSyncTime(nodeModel.remainingSyncTime)
3233
property string syncTime: syncState.text
3334
property bool estimating: syncState.estimating
3435

@@ -234,65 +235,4 @@ Item {
234235
return "0%"
235236
}
236237
}
237-
238-
function formatRemainingSyncTime(milliseconds) {
239-
var minutes = Math.floor(milliseconds / 60000);
240-
var seconds = Math.floor((milliseconds % 60000) / 1000);
241-
var weeks = Math.floor(minutes / 10080);
242-
minutes %= 10080;
243-
var days = Math.floor(minutes / 1440);
244-
minutes %= 1440;
245-
var hours = Math.floor(minutes / 60);
246-
minutes %= 60;
247-
var result = "";
248-
var estimatingStatus = false;
249-
250-
if (weeks > 0) {
251-
return {
252-
text: "~" + weeks + (weeks === 1 ? " week" : " weeks") + " left",
253-
estimating: false
254-
};
255-
}
256-
if (days > 0) {
257-
return {
258-
text: "~" + days + (days === 1 ? " day" : " days") + " left",
259-
estimating: false
260-
};
261-
}
262-
if (hours >= 5) {
263-
return {
264-
text: "~" + hours + (hours === 1 ? " hour" : " hours") + " left",
265-
estimating: false
266-
};
267-
}
268-
if (hours > 0) {
269-
return {
270-
text: "~" + hours + "h " + minutes + "m" + " left",
271-
estimating: false
272-
};
273-
}
274-
if (minutes >= 5) {
275-
return {
276-
text: "~" + minutes + (minutes === 1 ? " minute" : " minutes") + " left",
277-
estimating: false
278-
};
279-
}
280-
if (minutes > 0) {
281-
return {
282-
text: "~" + minutes + "m " + seconds + "s" + " left",
283-
estimating: false
284-
};
285-
}
286-
if (seconds > 0) {
287-
return {
288-
text: "~" + seconds + (seconds === 1 ? " second" : " seconds") + " left",
289-
estimating: false
290-
};
291-
} else {
292-
return {
293-
text: "Estimating",
294-
estimating: true
295-
};
296-
}
297-
}
298238
}

src/qml/components/Tooltip.qml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import QtQuick 2.15
2+
import QtQuick.Controls 2.15
3+
4+
import "../controls"
5+
6+
Item {
7+
id: root
8+
9+
property alias text: tooltipText.text
10+
11+
Rectangle {
12+
id: tooltipBg
13+
color: Theme.color.neutral0
14+
border.color: Theme.color.neutral4
15+
radius: 5
16+
border.width: 1
17+
width: tooltipText.width + 30
18+
height: tooltipText.height + 20
19+
anchors.top: arrow.bottom
20+
anchors.right: arrow.right
21+
anchors.rightMargin: -10
22+
anchors.topMargin: -1
23+
}
24+
25+
Image {
26+
id: arrow
27+
source: "qrc:/icons/tooltip-arrow"
28+
width: 22
29+
height: 10
30+
anchors.horizontalCenter: root.horizontalCenter
31+
anchors.top: root.top
32+
}
33+
34+
CoreText {
35+
id: tooltipText
36+
text: ""
37+
wrapMode: Text.NoWrap
38+
anchors.centerIn: tooltipBg
39+
}
40+
}

src/qml/imageprovider.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,10 @@ QPixmap ImageProvider::requestPixmap(const QString& id, QSize* size, const QSize
132132
return QIcon(":/icons/storage-light").pixmap(requested_size);
133133
}
134134

135+
if (id == "tooltip-arrow") {
136+
*size = requested_size;
137+
return QIcon(":/icons/tooltip-arrow").pixmap(requested_size);
138+
}
139+
135140
return {};
136141
}

src/qml/pages/wallet/DesktopWallets.qml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
import QtQuick 2.15
66
import QtQuick.Controls 2.15
77
import QtQuick.Layouts 1.15
8+
89
import org.bitcoincore.qt 1.0
10+
911
import "../../controls"
12+
import "../../controls/utils.js" as Utils
1013
import "../../components"
1114
import "../node"
1215

@@ -67,10 +70,29 @@ Page {
6770
shorten: true
6871
}
6972
NavigationTab {
73+
id: blockClockTabButton
7074
Layout.preferredWidth: 30
7175
Layout.rightMargin: 10
7276
property int index: 3
7377
ButtonGroup.group: navigationTabs
78+
79+
Tooltip {
80+
id: blockClockTooltip
81+
property var syncState: Utils.formatRemainingSyncTime(nodeModel.remainingSyncTime)
82+
property bool synced: nodeModel.verificationProgress > 0.999
83+
84+
anchors.top: blockClockTabButton.bottom
85+
anchors.horizontalCenter: blockClockTabButton.horizontalCenter
86+
87+
visible: blockClockTabButton.hovered
88+
text: {
89+
if (synced) {
90+
qsTr("Blocktime\n" + Number(nodeModel.blockTipHeight).toLocaleString(Qt.locale(), 'f', 0))
91+
} else {
92+
qsTr("Downloading blocks\n" + syncState.text)
93+
}
94+
}
95+
}
7496
}
7597
NavigationTab {
7698
iconSource: "image://images/gear-outline"

src/qml/res/icons/tooltip-arrow.png

2.05 KB
Loading

src/qml/res/src/tooltip-arrow.svg

Lines changed: 4 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)