Files
amnezia-client/client/ui/qml/Components/ConnectButton.qml
T

149 lines
4.1 KiB
QML
Raw Normal View History

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
2023-07-04 09:58:19 +09:00
import QtQuick.Shapes
import Qt5Compat.GraphicalEffects
2023-05-14 21:11:19 +08:00
import ConnectionState 1.0
Button {
id: root
2023-07-04 09:58:19 +09:00
property string defaultButtonColor: "#D7D8DB"
property string progressButtonColor: "#D7D8DB"
property string connectedButtonColor: "#FBB26A"
implicitWidth: 190
implicitHeight: 190
2023-06-05 22:40:35 +08:00
Connections {
target: ConnectionController
function onConnectionErrorOccurred(errorMessage) {
PageController.showErrorMessage(errorMessage)
}
}
text: ConnectionController.connectionStateText
2023-05-14 21:11:19 +08:00
2023-07-04 09:58:19 +09:00
// enabled: !ConnectionController.isConnectionInProgress
2023-06-05 22:40:35 +08:00
background: Item {
2023-07-04 09:58:19 +09:00
implicitWidth: parent.width
implicitHeight: parent.height
transformOrigin: Item.Center
Shape {
id: backgroundCircle
width: parent.implicitWidth
height: parent.implicitHeight
anchors.bottom: parent.bottom
anchors.right: parent.right
layer.enabled: true
layer.samples: 4
layer.smooth: true
2023-07-04 09:58:19 +09:00
layer.effect: DropShadow {
anchors.fill: backgroundCircle
horizontalOffset: 0
verticalOffset: 0
radius: 10
samples: 25
color: "#FBB26A"
source: backgroundCircle
}
2023-07-04 09:58:19 +09:00
ShapePath {
fillColor: "transparent"
strokeColor: {
if (ConnectionController.isConnectionInProgress) {
return "#261E1A"
2023-07-04 09:58:19 +09:00
} else if (ConnectionController.isConnected) {
return connectedButtonColor
} else {
return defaultButtonColor
}
}
strokeWidth: 3
capStyle: ShapePath.RoundCap
PathAngleArc {
centerX: backgroundCircle.width / 2
centerY: backgroundCircle.height / 2
radiusX: 93
radiusY: 93
startAngle: 0
sweepAngle: 360
}
}
2023-07-04 09:58:19 +09:00
MouseArea {
anchors.fill: parent
2023-07-04 09:58:19 +09:00
cursorShape: Qt.PointingHandCursor
enabled: false
}
}
Shape {
id: shape
width: parent.implicitWidth
height: parent.implicitHeight
anchors.bottom: parent.bottom
anchors.right: parent.right
layer.enabled: true
layer.samples: 4
visible: ConnectionController.isConnectionInProgress
ShapePath {
fillColor: "transparent"
strokeColor: "#D7D8DB"
strokeWidth: 3
capStyle: ShapePath.RoundCap
PathAngleArc {
centerX: shape.width / 2
centerY: shape.height / 2
radiusX: 93
radiusY: 93
startAngle: 245
sweepAngle: -180
}
}
2023-06-05 22:40:35 +08:00
RotationAnimator {
2023-07-04 09:58:19 +09:00
target: shape
running: ConnectionController.isConnectionInProgress
2023-06-05 22:40:35 +08:00
from: 0
to: 360
loops: Animation.Infinite
2023-07-04 09:58:19 +09:00
duration: 1000
2023-06-05 22:40:35 +08:00
}
2023-05-14 21:11:19 +08:00
}
}
contentItem: Text {
height: 24
font.family: "PT Root UI VF"
font.weight: 700
font.pixelSize: 20
2023-07-04 09:58:19 +09:00
color: ConnectionController.isConnected ? connectedButtonColor : defaultButtonColor
text: root.text
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
onClicked: {
if (ConnectionController.isConnectionInProgress) {
ConnectionController.closeConnection()
} else if (ConnectionController.isConnected) {
ConnectionController.closeConnection()
} else {
ConnectionController.openConnection()
2023-05-14 21:11:19 +08:00
}
}
}