-
Notifications
You must be signed in to change notification settings - Fork 23
/
Checkbox.qml
104 lines (93 loc) · 2.98 KB
/
Checkbox.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.Controls.Styles 1.4
import QtQuick.Controls.Universal 2.12
CheckBox {
id: settingsCheckbox
property double labelFontSize
property double circleSize
property var actionId
property bool activeCheckbox: false
property bool hasRemoveButton: false
property bool hasDescriptionButton: false
property bool isToggle: false
property int startX: 0
property var accentColor
width: parent.width
text: qsTr("Chip")
spacing: leftPadding / 2
opacity: 0.0
contentItem: Text {
text: settingsCheckbox.text
elide: Text.ElideRight
width: parent.width - leftPadding * 2 - removeButton.width
leftPadding: settingsCheckbox.indicator.width + settingsCheckbox.spacing
font.pointSize: labelFontSize
font.weight: Font.Normal
color: Universal.foreground
opacity: settingsCheckbox.checked ? 1.0 : 0.7
verticalAlignment: Text.AlignVCenter
}
Button {
id: removeButton
anchors.right: parent.right
rightPadding: settingsCheckbox.leftPadding
leftPadding: settingsCheckbox.leftPadding
flat: true
text: "<font color='#808080'>×</font>"
font.pointSize: labelFontSize
onClicked: {
console.log("Checkbox | Remove item from settings: " + settingsCheckbox.text)
settingsCheckbox.parent.removeSettings(actionId)
}
visible: settingsCheckbox.hasRemoveButton
}
Button {
id: descriptionButton
anchors.right: parent.right
rightPadding: settingsCheckbox.leftPadding
leftPadding: settingsCheckbox.leftPadding
flat: true
text: "<font color='#808080'>ⓘ</font>"
font.pointSize: labelFontSize
onClicked: {
console.log("Checkbox | Show description: " + settingsCheckbox.text)
settingsCheckbox.parent.showDescription(actionId)
}
visible: settingsCheckbox.hasDescriptionButton
}
indicator: Rectangle {
width: circleSize
height: circleSize
x: settingsCheckbox.leftPadding
y: settingsCheckbox.height / 2 - circleSize / 2
radius: width / 2
color: settingsCheckbox.checked ? accentColor : Universal.foreground
opacity: settingsCheckbox.checked ? 1.0 : 0.3
}
onVisibleChanged: {
if (!visible) {
console.log("Checkbox | Force visibility")
visible = true
}
}
onCheckedChanged: {
console.log("Checkbox | Checked changed for " + text + ", " + checked)
if (activeCheckbox) {
if (isToggle && !checked) {
activeCheckbox = false
checked = true
} else {
parent.updateSettings(actionId, checked)
}
}
}
Component.onCompleted: {
opacity = 1.0
}
Behavior on opacity {
NumberAnimation {
duration: 250
}
}
}