Files
pay/desktop/widgets/CheckBox.qml
T

133 lines
4.2 KiB
QML
Raw Permalink Normal View History

2021-04-22 16:13:40 +02:00
/*
* This file is part of the Flowee project
* Copyright (C) 2021 Tom Zander <tom@flowee.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2021-05-23 00:27:34 +02:00
import QtQuick 2.11
2021-10-15 20:59:18 +02:00
import QtQuick.Controls 2.11
2021-04-22 16:13:40 +02:00
Item {
2021-10-15 20:59:18 +02:00
id: root
2021-04-22 16:13:40 +02:00
property bool checked: false
property bool sliderOnIndicator: true
2021-10-15 20:59:18 +02:00
property alias text: title.text
property string tooltipText: ""
2021-04-22 16:13:40 +02:00
signal clicked;
2021-10-15 20:59:18 +02:00
implicitWidth: slider.width + 6 + title.width + (tooltipText === "" ? 0 : (questionMarkIcon.width + 16))
implicitHeight: Math.max(slider.implicitHeight, title.implicitHeight)
clip: true
activeFocusOnTab: true
focus: true
2021-04-22 16:13:40 +02:00
2021-10-15 20:59:18 +02:00
Item {
id: slider
width: implicitWidth
height: implicitHeight
implicitWidth: 60
implicitHeight: 27
2021-04-22 16:13:40 +02:00
2021-10-15 20:59:18 +02:00
Rectangle {
anchors.fill: parent
radius: parent.height / 3
color: root.sliderOnIndicator && root.enabled && root.checked ? (Pay.useDarkSkin ? "#4f7d63" : "#9ec7af") : mainWindow.palette.window
2021-11-02 19:29:14 +01:00
border.color: root.activeFocus ? (Pay.useDarkSkin ? "white" : "black") : mainWindow.palette.button
2021-10-15 20:59:18 +02:00
border.width: 2
2021-10-25 16:57:32 +02:00
Behavior on color { ColorAnimation {}}
2021-10-15 20:59:18 +02:00
}
Rectangle {
width: parent.height / 5 * 4
height: width
radius: width
x: root.checked ? parent.width - width - 3 : 3
anchors.verticalCenter: parent.verticalCenter
2021-10-29 18:20:42 +02:00
color: {
if (!root.enabled)
return "darkgray"
2021-11-02 19:29:14 +01:00
if (root.checked && Pay.useDarkSkin)
2021-10-29 18:20:42 +02:00
return mainWindow.palette.text;
return mainWindow.palette.highlight
}
2021-10-15 20:59:18 +02:00
Behavior on x { NumberAnimation {}}
2021-10-25 16:57:32 +02:00
Behavior on color { ColorAnimation {}}
2021-10-15 20:59:18 +02:00
}
2021-04-22 16:13:40 +02:00
}
MouseArea {
2021-10-15 20:59:18 +02:00
id: mousy
width: slider.width + 6 + title.width
height: parent.height
2021-10-30 16:29:48 +02:00
cursorShape: Qt.PointingHandCursor
2021-04-23 19:59:49 +02:00
onClicked: {
2021-10-15 20:59:18 +02:00
root.checked = !root.checked
root.clicked()
}
hoverEnabled: true
ToolTip {
parent: root
text: root.tooltipText
delay: 1500
2021-10-21 20:52:20 +02:00
visible: mousy.containsMouse && root.tooltipText !== ""
2021-10-15 20:59:18 +02:00
}
}
Label {
id: title
anchors.left: slider.right
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: 6
2021-10-29 18:20:42 +02:00
color: enabled ? palette.text : "darkgray"
2021-10-15 20:59:18 +02:00
}
Rectangle {
id: questionMarkIcon
2021-10-29 18:20:42 +02:00
visible: root.tooltipText !== "" && root.enabled
2021-10-15 20:59:18 +02:00
width: q.width + 14
height: width
anchors.left: title.right
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: 16
radius: width
color: q.palette.text
Label {
id: q
text: "?"
color: palette.base
anchors.centerIn: parent
MouseArea {
anchors.fill: parent
2021-10-30 16:29:48 +02:00
anchors.margins: -7
cursorShape: Qt.PointingHandCursor
2021-10-15 20:59:18 +02:00
id: clicky
onClicked: ToolTip.show(root.tooltipText, 15000);
}
2021-04-23 19:59:49 +02:00
}
2021-04-22 16:13:40 +02:00
}
Keys.onPressed: {
if (event.key === Qt.Key_Space || event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
root.checked = !root.checked
event.accepted = true
}
else if (root.checked && event.key === Qt.Key_Left) {
root.checked = false;
event.accepted = true
}
else if (!root.checked && event.key === Qt.Key_Right) {
root.checked = true;
event.accepted = true
}
}
2021-04-22 16:13:40 +02:00
}