| 1 |
// SPDX-FileCopyrightText: Nheko Contributors |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
|
| 5 |
import QtQuick 2.5 |
| 6 |
import QtQuick 2.12 |
| 7 |
import QtQuick.Controls 2.12 |
| 8 |
|
| 9 |
Switch { |
| 10 |
id: toggleButton |
| 11 |
|
| 12 |
implicitWidth: indicatorItem.width |
| 13 |
state: checked ? "on" : "off" |
| 14 |
|
| 15 |
indicator: Item { |
| 16 |
id: indicatorItem |
| 17 |
|
| 18 |
implicitHeight: 24 |
| 19 |
implicitWidth: 48 |
| 20 |
y: parent.height / 2 - height / 2 |
| 21 |
|
| 22 |
Rectangle { |
| 23 |
id: track |
| 24 |
|
| 25 |
color: Qt.rgba(border.color.r, border.color.g, border.color.b, 0.6) |
| 26 |
height: parent.height * 0.6 |
| 27 |
radius: height / 2 |
| 28 |
width: parent.width - height |
| 29 |
x: radius |
| 30 |
y: parent.height / 2 - height / 2 |
| 31 |
} |
| 32 |
Rectangle { |
| 33 |
id: handle |
| 34 |
|
| 35 |
border.color: "#767676" |
| 36 |
color: palette.button |
| 37 |
height: width |
| 38 |
radius: width / 2 |
| 39 |
width: parent.height * 0.9 |
| 40 |
y: parent.height / 2 - height / 2 |
| 41 |
} |
| 42 |
} |
| 43 |
states: [ |
| 44 |
State { |
| 45 |
name: "off" |
| 46 |
|
| 47 |
PropertyChanges { |
| 48 |
track.border.color: "#767676" |
| 49 |
} |
| 50 |
PropertyChanges { |
| 51 |
handle.x: 0 |
| 52 |
} |
| 53 |
}, |
| 54 |
State { |
| 55 |
name: "on" |
| 56 |
|
| 57 |
PropertyChanges { |
| 58 |
track.border.color: palette.highlight |
| 59 |
} |
| 60 |
PropertyChanges { |
| 61 |
handle.x: indicatorItem.width - handle.width |
| 62 |
} |
| 63 |
} |
| 64 |
] |
| 65 |
transitions: [ |
| 66 |
Transition { |
| 67 |
reversible: true |
| 68 |
to: "off" |
| 69 |
|
| 70 |
ParallelAnimation { |
| 71 |
NumberAnimation { |
| 72 |
duration: 200 |
| 73 |
easing.type: Easing.InOutQuad |
| 74 |
property: "x" |
| 75 |
target: handle |
| 76 |
} |
| 77 |
ColorAnimation { |
| 78 |
duration: 200 |
| 79 |
properties: "color,border.color" |
| 80 |
target: track |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
] |
| 85 |
} |