matrixion/resources/qml/ToggleButton.qml

88 lines
2 KiB
QML
Raw Normal View History

// SPDX-FileCopyrightText: Nheko Contributors
//
2021-03-05 02:35:15 +03:00
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.5
import QtQuick 2.12
import QtQuick.Controls 2.12
import im.nheko 1.0
Switch {
id: toggleButton
implicitWidth: indicatorItem.width
2023-03-10 04:07:19 +03:00
state: checked ? "on" : "off"
2023-06-02 02:45:24 +03: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 04:07:19 +03:00
states: [
State {
name: "off"
PropertyChanges {
2023-10-26 17:43:09 +03:00
track.border.color: "#767676"
2023-03-10 04:07:19 +03:00
}
PropertyChanges {
2023-10-26 17:43:09 +03:00
handle.x: 0
2023-03-10 04:07:19 +03:00
}
},
State {
name: "on"
PropertyChanges {
2023-10-26 17:43:09 +03:00
track.border.color: palette.highlight
2023-03-10 04:07:19 +03:00
}
PropertyChanges {
2023-10-26 17:43:09 +03:00
handle.x: indicatorItem.width - handle.width
2023-03-10 04:07:19 +03:00
}
}
]
transitions: [
Transition {
reversible: true
2023-06-02 02:45:24 +03:00
to: "off"
enabled: !Settings.reducedMotion
2023-03-10 04:07:19 +03:00
ParallelAnimation {
NumberAnimation {
duration: 200
easing.type: Easing.InOutQuad
2023-06-02 02:45:24 +03:00
property: "x"
target: handle
2023-03-10 04:07:19 +03:00
}
ColorAnimation {
duration: 200
2023-06-02 02:45:24 +03:00
properties: "color,border.color"
target: track
2023-03-10 04:07:19 +03:00
}
}
}
]
}