2018-08-28 23:03:35 +02:00
|
|
|
import QtQuick 2.0
|
|
|
|
import QtQuick.Controls 2.2
|
|
|
|
|
2019-03-27 22:25:23 +01:00
|
|
|
SmoothItemDelegate {
|
2018-08-28 23:03:35 +02:00
|
|
|
id: control
|
2019-03-29 23:42:56 +01:00
|
|
|
|
2018-08-28 23:03:35 +02:00
|
|
|
property var status
|
2019-08-20 22:55:37 +02:00
|
|
|
property string oldState: ""
|
2018-08-28 23:03:35 +02:00
|
|
|
property var connect
|
2019-03-29 23:42:56 +01:00
|
|
|
property var disconnect
|
|
|
|
|
2018-08-28 23:03:35 +02:00
|
|
|
property string type
|
|
|
|
text: qsTr(type)
|
|
|
|
|
2019-03-29 23:42:56 +01:00
|
|
|
enabled: (status.status === "disconnected" && control.connect !== undefined) || ( status.status === "connected" && control.disconnect !== undefined )
|
2018-08-28 23:03:35 +02:00
|
|
|
|
|
|
|
onClicked: {
|
2019-03-29 23:42:56 +01:00
|
|
|
if(status.status === "disconnected"){
|
|
|
|
connect()
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
disconnect()
|
2018-08-28 23:03:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-20 22:55:37 +02:00
|
|
|
onStatusChanged: {
|
|
|
|
if(oldState !== status.status) {
|
|
|
|
if(status.status === "disconnected" && oldState === "connecting") {
|
2019-09-08 15:08:50 +02:00
|
|
|
statusIndicator.color_override = appTheme.style.errorColor
|
2019-08-20 22:55:37 +02:00
|
|
|
shortDelay.start()
|
|
|
|
}
|
|
|
|
oldState = status.status
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-28 23:03:35 +02:00
|
|
|
Timer {
|
|
|
|
id: shortDelay
|
|
|
|
running: false
|
|
|
|
repeat: false
|
|
|
|
interval: 1500
|
|
|
|
onTriggered: {
|
|
|
|
statusIndicator.color_override = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: statusItem
|
|
|
|
anchors {
|
|
|
|
right: parent.right
|
2019-03-27 22:25:23 +01:00
|
|
|
rightMargin: ( height / control.height / 2 ) * height
|
2018-08-28 23:03:35 +02:00
|
|
|
verticalCenter: parent.verticalCenter
|
|
|
|
}
|
2019-03-29 23:42:56 +01:00
|
|
|
height: control.height * 0.4
|
2018-08-28 23:03:35 +02:00
|
|
|
width: height
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: statusIndicator
|
|
|
|
property string color_override: ""
|
|
|
|
anchors.fill: parent
|
2019-09-08 15:08:50 +02:00
|
|
|
color: color_override === "" ? status.status === "connected" ? appTheme.style.successColor:"transparent":color_override
|
2018-08-28 23:03:35 +02:00
|
|
|
opacity: status.status === "connecting" ? 0:1
|
|
|
|
radius: height * 0.5
|
2019-09-08 15:08:50 +02:00
|
|
|
border.color: appTheme.style.lineColor
|
|
|
|
border.width: 1
|
2018-08-28 23:03:35 +02:00
|
|
|
|
|
|
|
Behavior on color {
|
|
|
|
ColorAnimation {
|
|
|
|
duration: 200
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Behavior on opacity {
|
|
|
|
NumberAnimation {
|
|
|
|
duration: 800
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgressCircle {
|
|
|
|
id: prog
|
|
|
|
anchors.fill: parent
|
|
|
|
opacity: status.status === "connecting" ? 1:0
|
2019-09-08 15:08:50 +02:00
|
|
|
lineWidth: 1
|
2018-08-28 23:03:35 +02:00
|
|
|
|
|
|
|
arcBegin: 0
|
2019-08-20 22:55:37 +02:00
|
|
|
arcEnd: 360 * ( status.progress / 100 )
|
2019-09-08 15:08:50 +02:00
|
|
|
colorCircle: appTheme.style.lineColor
|
2018-08-28 23:03:35 +02:00
|
|
|
onColorCircleChanged: prog.repaint()
|
2019-08-20 22:55:37 +02:00
|
|
|
onArcEndChanged: prog.repaint()
|
2018-08-28 23:03:35 +02:00
|
|
|
|
|
|
|
Behavior on opacity {
|
|
|
|
NumberAnimation {
|
|
|
|
duration: 200
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|