|
| 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