This repository has been archived on 2024-06-03. You can view files and clone it, but cannot push or open issues or pull requests.
app/resources/qml/components/ConnectionDelegate.qml

105 lines
2.5 KiB
QML
Raw Normal View History

import QtQuick 2.0
import QtQuick.Controls 2.2
SmoothItemDelegate {
id: control
property var status
2019-08-20 22:55:37 +02:00
property string oldState: ""
property var connect: null
property var disconnect
2020-10-06 16:29:34 +02:00
property string batteryState: "unknown"
property string type
2020-04-19 13:09:46 +02:00
text: qsTr(type)
enabled: (status.status === "disconnected" && control.connect !== undefined) || ( status.status === "connected" && control.disconnect !== undefined )
onClicked: {
if(connect == null)
return;
if(status.status === "disconnected")
connect()
else
disconnect()
}
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
}
}
Timer {
id: shortDelay
running: false
repeat: false
interval: 1500
onTriggered: {
statusIndicator.color_override = ""
}
}
2020-10-06 16:29:34 +02:00
Row {
anchors {
right: parent.right
rightMargin: ( height / control.height / 2 ) * height
verticalCenter: parent.verticalCenter
}
2020-10-06 16:29:34 +02:00
spacing: height * 0.4
BatteryIndicator {
id: batteryIndicator
height: control.height * 0.4
width: height
opacity: control.batteryState === "unknown" ? 0:1
backgroundColor: "transparent"
chargingColor: fineColor
fineColor: appTheme.theme.colors.success
warningColor: appTheme.theme.colors.warning
criticalColor: appTheme.theme.colors.error
state: control.batteryState
indicatorSize: 0.8
Behavior on opacity {
NumberAnimation {
duration: 200
}
}
}
2020-10-06 14:01:11 +02:00
StateIndicator {
id: statusIndicator
property string color_override: ""
2020-10-06 16:29:34 +02:00
height: control.height * 0.4
width: height
2020-10-06 14:01:11 +02:00
state: color_override === "" ? status.status === "connected" ? "success": status.status === "connecting" ? "working":"unknown":color_override
2020-10-06 14:01:11 +02:00
indicatorSize: 0.8
2020-10-06 14:01:11 +02:00
radius: border.width * 2
2020-10-06 14:01:11 +02:00
backgroundColor: appTheme.theme.colors.background
successColor: appTheme.theme.colors.success
errorColor: appTheme.theme.colors.error
}
}
2020-10-06 16:29:34 +02:00
}