nheko/resources/qml/ToggleButton.qml

86 lines
2.0 KiB
QML
Raw Normal View History

// SPDX-FileCopyrightText: Nheko Contributors
//
2021-03-05 00:35:15 +01:00
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.5
import QtQuick 2.12
import QtQuick.Controls 2.12
Switch {
id: toggleButton
implicitWidth: indicatorItem.width
2023-03-10 02:07:19 +01:00
state: checked ? "on" : "off"
2023-06-02 01:45:24 +02:00
indicator: Item {
id: indicatorItem
implicitHeight: 24
implicitWidth: 48
y: parent.height / 2 - height / 2
Rectangle {
id: track
color: Qt.rgba(border.color.r, border.color.g, border.color.b, 0.6)
height: parent.height * 0.6
radius: height / 2
width: parent.width - height
x: radius
y: parent.height / 2 - height / 2
}
Rectangle {
id: handle
border.color: "#767676"
color: palette.button
height: width
radius: width / 2
width: parent.height * 0.9
y: parent.height / 2 - height / 2
}
}
2023-03-10 02:07:19 +01:00
states: [
State {
name: "off"
PropertyChanges {
2023-10-26 16:43:09 +02:00
track.border.color: "#767676"
2023-03-10 02:07:19 +01:00
}
PropertyChanges {
2023-10-26 16:43:09 +02:00
handle.x: 0
2023-03-10 02:07:19 +01:00
}
},
State {
name: "on"
PropertyChanges {
2023-10-26 16:43:09 +02:00
track.border.color: palette.highlight
2023-03-10 02:07:19 +01:00
}
PropertyChanges {
2023-10-26 16:43:09 +02:00
handle.x: indicatorItem.width - handle.width
2023-03-10 02:07:19 +01:00
}
}
]
transitions: [
Transition {
reversible: true
2023-06-02 01:45:24 +02:00
to: "off"
2023-03-10 02:07:19 +01:00
ParallelAnimation {
NumberAnimation {
duration: 200
easing.type: Easing.InOutQuad
2023-06-02 01:45:24 +02:00
property: "x"
target: handle
2023-03-10 02:07:19 +01:00
}
ColorAnimation {
duration: 200
2023-06-02 01:45:24 +02:00
properties: "color,border.color"
target: track
2023-03-10 02:07:19 +01:00
}
}
}
]
}