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: ""
|
2020-09-22 15:44:57 +02:00
|
|
|
property var connect: null
|
2019-03-29 23:42:56 +01:00
|
|
|
property var disconnect
|
|
|
|
|
2018-08-28 23:03:35 +02:00
|
|
|
property string type
|
2020-04-19 13:09:46 +02:00
|
|
|
|
2018-08-28 23:03:35 +02:00
|
|
|
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: {
|
2020-09-22 15:44:57 +02:00
|
|
|
if(connect == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(status.status === "disconnected")
|
2019-03-29 23:42:56 +01:00
|
|
|
connect()
|
2020-09-22 15:44:57 +02:00
|
|
|
else
|
2019-03-29 23:42:56 +01:00
|
|
|
disconnect()
|
2020-09-22 15:44:57 +02:00
|
|
|
|
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") {
|
2020-10-06 14:01:11 +02:00
|
|
|
statusIndicator.color_override = "error"
|
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
|
|
|
|
|
2020-10-06 14:01:11 +02:00
|
|
|
StateIndicator {
|
2018-08-28 23:03:35 +02:00
|
|
|
id: statusIndicator
|
|
|
|
property string color_override: ""
|
|
|
|
anchors.fill: parent
|
2020-10-06 14:01:11 +02:00
|
|
|
state: color_override === "" ? status.status === "connected" ? "success": status.status === "connecting" ? "working":"unknown":color_override
|
2018-08-28 23:03:35 +02:00
|
|
|
|
2020-10-06 14:01:11 +02:00
|
|
|
indicatorSize: 0.8
|
2018-08-28 23:03:35 +02:00
|
|
|
|
2020-10-06 14:01:11 +02:00
|
|
|
radius: border.width * 2
|
2018-08-28 23:03:35 +02:00
|
|
|
|
2020-10-06 14:01:11 +02:00
|
|
|
backgroundColor: appTheme.theme.colors.background
|
|
|
|
successColor: appTheme.theme.colors.success
|
|
|
|
errorColor: appTheme.theme.colors.error
|
2018-08-28 23:03:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|