13
13
* *
14
14
***************************************************************************/
15
15
16
- import QtQuick 2.0
16
+ import QtQuick 2.6
17
17
import QtQuick.Controls 2.2
18
18
import QgsQuick 0.1 as QgsQuick
19
19
@@ -25,60 +25,82 @@ import QgsQuick 0.1 as QgsQuick
25
25
Item {
26
26
signal valueChanged ( var value, bool isNull )
27
27
28
- /**
29
- * Handling missing config value for un/checked state for boolean field
30
- */
31
28
property var checkedState: getConfigValue (config[' CheckedState' ], true )
32
29
property var uncheckedState: getConfigValue (config[' UncheckedState' ], false )
30
+ property string booleanEnum: " 1" // QMetaType::Bool Enum of Qvariant::Type
33
31
34
32
id: fieldItem
35
33
enabled: ! readOnly
36
34
height: childrenRect .height
37
35
anchors {
38
36
right: parent .right
39
37
left: parent .left
38
+ rightMargin: 10 * QgsQuick .Utils .dp
40
39
}
41
40
42
41
function getConfigValue (configValue , defaultValue ) {
43
- if (typeof value === " boolean " && ! configValue ) {
44
- return defaultValue
45
- } else return configValue
42
+ if (! configValue && field . type + " " === fieldItem . booleanEnum ) {
43
+ return defaultValue
44
+ } else return configValue
46
45
}
47
46
48
- CheckBox {
49
- property var currentValue : value
47
+ Rectangle {
48
+ id : fieldContainer
50
49
height: customStyle .fields .height
51
- id : checkBox
52
- leftPadding : 0
53
- checked : value === fieldItem . checkedState
50
+ color : customStyle . fields . backgroundColor
51
+ radius : customStyle . fields . cornerRadius
52
+ anchors { right : parent . right ; left : parent . left }
54
53
55
- indicator: Rectangle {
56
- implicitWidth: customStyle .fields .height
57
- implicitHeight: customStyle .fields .height
58
- radius: customStyle .fields .cornerRadius
59
- border .color : checkBox .activeFocus ? customStyle .fields .fontColor : " grey"
60
- border .width : 1
61
- Rectangle {
62
- visible: checkBox .checked
63
- color: customStyle .fields .fontColor
64
- radius: customStyle .fields .cornerRadius
65
- anchors .margins : 4
66
- anchors .fill : parent
67
- }
54
+ Text {
55
+ text: checkBox .checked ? fieldItem .checkedState : fieldItem .uncheckedState
56
+ font .pixelSize : customStyle .fields .fontPixelSize
57
+ color: customStyle .fields .fontColor
58
+ horizontalAlignment: Text .AlignLeft
59
+ verticalAlignment: Text .AlignVCenter
60
+ anchors .left : parent .left
61
+ anchors .verticalCenter : parent .verticalCenter
62
+ leftPadding: 6 * QgsQuick .Utils .dp
63
+ }
64
+
65
+ CheckBox {
66
+ property var currentValue: value
67
+ height: customStyle .fields .height / 2
68
+ width: height * 2
69
+ anchors .right : parent .right
70
+ anchors .rightMargin : fieldItem .anchors .rightMargin
71
+ anchors .verticalCenter : parent .verticalCenter
72
+ id: checkBox
73
+ leftPadding: 0
74
+ checked: value === fieldItem .checkedState
75
+
76
+ indicator: Rectangle {
77
+ implicitWidth: parent .width
78
+ implicitHeight: parent .height
79
+ x: checkBox .leftPadding
80
+ y: parent .height / 2 - height / 2
81
+ radius: parent .height / 2
82
+ color: checkBox .checked ? customStyle .fields .fontColor : " #ffffff"
83
+ border .color : checkBox .checked ? customStyle .fields .fontColor : customStyle .fields .normalColor
68
84
69
- MouseArea {
70
- anchors .fill : parent
71
- onClicked: checkBox .checked = ! checkBox .checked
72
- }
85
+ Rectangle {
86
+ x: checkBox .checked ? parent .width - width : 0
87
+ width: parent .height
88
+ height: parent .height
89
+ radius: parent .height / 2
90
+ color: " #ffffff"
91
+ border .color : checkBox .checked ? customStyle .fields .fontColor : customStyle .fields .normalColor
73
92
}
74
- onCheckedChanged: {
75
- valueChanged ( checked ? fieldItem .checkedState : fieldItem .uncheckedState , false )
76
- forceActiveFocus ()
77
- }
93
+ }
94
+
95
+ onCheckedChanged: {
96
+ valueChanged ( checked ? fieldItem .checkedState : fieldItem .uncheckedState , false )
97
+ forceActiveFocus ()
98
+ }
78
99
79
- // Workaround to get a signal when the value has changed
80
- onCurrentValueChanged: {
81
- checked = currentValue === fieldItem .checkedState
100
+ // Workaround to get a signal when the value has changed
101
+ onCurrentValueChanged: {
102
+ checked = currentValue === fieldItem .checkedState
103
+ }
82
104
}
83
105
}
84
106
}
0 commit comments