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