2018-03-19 08:22:11 +00:00
|
|
|
import QtQuick 2.4
|
2017-12-05 20:53:47 +00:00
|
|
|
import "."
|
2017-10-13 17:48:24 +02:00
|
|
|
|
|
|
|
Item {
|
2018-06-28 15:21:01 +01:00
|
|
|
id: root
|
2017-10-13 17:48:24 +02:00
|
|
|
property bool checked: false
|
|
|
|
property alias label: label.text
|
2017-12-15 15:42:36 +00:00
|
|
|
property bool enabled: true
|
2017-10-13 17:48:24 +02:00
|
|
|
|
|
|
|
implicitWidth: track.width + label.width + 16
|
2018-04-09 19:41:44 +01:00
|
|
|
implicitHeight: Math.max(label.height, thumb.height)
|
2017-10-13 17:48:24 +02:00
|
|
|
|
2018-06-22 12:09:35 +01:00
|
|
|
// helepr to set the value without an animation
|
|
|
|
function setValue(newCheck)
|
|
|
|
{
|
|
|
|
sliderBehaviour.enabled = false;
|
|
|
|
checked = newCheck
|
|
|
|
sliderBehaviour.enabled = true;
|
|
|
|
}
|
|
|
|
|
2018-06-28 15:21:01 +01:00
|
|
|
function toggle(newChecked)
|
|
|
|
{
|
|
|
|
checked = newChecked
|
|
|
|
}
|
|
|
|
|
2017-10-13 17:48:24 +02:00
|
|
|
Rectangle {
|
|
|
|
id: track
|
|
|
|
width: height * 2
|
2017-12-05 20:53:47 +00:00
|
|
|
height: radius * 2
|
|
|
|
radius: Style.roundRadius
|
2017-10-13 17:48:24 +02:00
|
|
|
|
2017-12-15 15:42:36 +00:00
|
|
|
color: (checked && enabled) ? Style.frameColor : Style.minorFrameColor
|
2017-10-13 17:48:24 +02:00
|
|
|
anchors.left: parent.left
|
2017-12-05 20:53:47 +00:00
|
|
|
anchors.leftMargin: Style.margin
|
2017-10-13 17:48:24 +02:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: thumb
|
2017-12-05 20:53:47 +00:00
|
|
|
width: radius * 2
|
|
|
|
height: radius * 2
|
|
|
|
radius: Style.roundRadius * 1.5
|
2017-10-13 17:48:24 +02:00
|
|
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2018-07-17 11:55:25 +01:00
|
|
|
color: enabled && (checked | mouseArea.containsMouse) ? Style.themeColor : "white"
|
2017-10-13 17:48:24 +02:00
|
|
|
border.width: 1
|
2017-12-05 20:53:47 +00:00
|
|
|
border.color: Style.inactiveThemeColor
|
2017-10-13 17:48:24 +02:00
|
|
|
|
2017-12-05 20:53:47 +00:00
|
|
|
x: checked ? parent.width - (track.radius + radius) : (track.radius - radius)
|
2017-10-13 17:48:24 +02:00
|
|
|
|
|
|
|
Behavior on x {
|
2018-06-22 12:09:35 +01:00
|
|
|
id: sliderBehaviour
|
2017-10-13 17:48:24 +02:00
|
|
|
NumberAnimation {
|
|
|
|
duration: 250
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-21 22:54:21 +01:00
|
|
|
StyledText {
|
2017-10-13 17:48:24 +02:00
|
|
|
id: label
|
|
|
|
anchors.left: track.right
|
2017-12-05 20:53:47 +00:00
|
|
|
anchors.leftMargin: Style.margin
|
2017-10-13 17:48:24 +02:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2018-06-21 22:54:21 +01:00
|
|
|
enabled: root.enabled
|
|
|
|
hover: mouseArea.containsMouse
|
2017-10-13 17:48:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
id: mouseArea
|
2017-12-15 15:42:36 +00:00
|
|
|
enabled: root.enabled
|
|
|
|
|
2017-10-13 17:48:24 +02:00
|
|
|
hoverEnabled: true
|
2018-06-28 15:21:01 +01:00
|
|
|
onClicked: root.toggle(!checked)
|
2018-07-17 11:55:25 +01:00
|
|
|
cursorShape: enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
|
|
|
|
|
2017-10-13 17:48:24 +02:00
|
|
|
}
|
|
|
|
}
|