Debian Codegraph @

src/imports/Components/Themes/Ambiance/2.0/CheckBoxStyle.qml

raw
1 /*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.4
18 import Lomiri.Components
19
20 Item {
21 id: checkBoxStyle
22
23 /*!
24 The padding between the background shape and the outside border of the checkbox.
25 */
26 property real backgroundPadding: 0
27
28 /*!
29 The background color when the checkbox is not checked.
30 */
31 property color uncheckedBackgroundColor: styledItem.enabled
32 ? theme.palette.normal.foreground
33 : theme.palette.disabled.foreground
34
35 /*!
36 The background color when the checkbox is checked.
37 */
38 property color checkedBackgroundColor: styledItem.enabled
39 ? theme.palette.normal.positive
40 : theme.palette.disabled.raised
41
42 /*!
43 The image to show inside the checkbox when it is checked.
44 */
45 property url iconSource: "image://theme/tick"
46
47 /*!
48 The color of the icon.
49 */
50 property color iconColor: styledItem.enabled
51 ? theme.palette.normal.positiveText
52 : theme.palette.disabled.raisedText
53
54 /*!
55 The padding between the icon and the border of the thumb.
56 */
57 property real iconPadding: units.gu(0.4)
58
59 implicitWidth: units.gu(2)
60 implicitHeight: Math.max(checkBoxLbl.contentHeight, units.gu(2))
61
62 FocusShape {
63 }
64
65 LomiriShape {
66 id: background
67 aspect: LomiriShape.Inset
68 anchors {
69 margins: checkBoxStyle.backgroundPadding
70 }
71 width: units.gu(2)
72 height: units.gu(2)
73
74 property real iconSize: units.gu(2) - 2*checkBoxStyle.iconPadding
75
76 Icon {
77 color: checkBoxStyle.iconColor
78 width: background.iconSize
79 height: background.iconSize
80 id: tick
81 anchors.centerIn: parent
82 smooth: true
83 source: checkBoxStyle.iconSource
84 visible: styledItem.checked || transitionToChecked.running || transitionToUnchecked.running
85 }
86
87 state: styledItem.checked ? "checked" : "unchecked"
88 states: [
89 State {
90 name: "checked"
91 PropertyChanges {
92 target: tick
93 anchors.verticalCenterOffset: 0
94 }
95 PropertyChanges {
96 target: background
97 backgroundColor: checkBoxStyle.checkedBackgroundColor
98 }
99 },
100 State {
101 name: "unchecked"
102 PropertyChanges {
103 target: tick
104 anchors.verticalCenterOffset: checkBoxStyle.height
105 }
106 PropertyChanges {
107 target: background
108 backgroundColor: checkBoxStyle.uncheckedBackgroundColor
109 }
110 }
111 ]
112
113 transitions: [
114 Transition {
115 id: transitionToUnchecked
116 to: "unchecked"
117 ColorAnimation {
118 target: background
119 duration: LomiriAnimation.FastDuration
120 easing: LomiriAnimation.StandardEasingReverse
121 }
122 SequentialAnimation {
123 PropertyAction {
124 target: background
125 property: "clip"
126 value: true
127 }
128 NumberAnimation {
129 target: tick
130 property: "anchors.verticalCenterOffset"
131 duration: LomiriAnimation.FastDuration
132 easing: LomiriAnimation.StandardEasingReverse
133 }
134 PropertyAction {
135 target: background
136 property: "clip"
137 value: false
138 }
139 }
140 },
141 Transition {
142 id: transitionToChecked
143 to: "checked"
144 ColorAnimation {
145 target: background
146 duration: LomiriAnimation.FastDuration
147 easing: LomiriAnimation.StandardEasing
148 }
149 SequentialAnimation {
150 PropertyAction {
151 target: background
152 property: "clip"
153 value: true
154 }
155 NumberAnimation {
156 target: tick
157 property: "anchors.verticalCenterOffset"
158 duration: LomiriAnimation.FastDuration
159 easing: LomiriAnimation.StandardEasing
160 }
161 PropertyAction {
162 target: background
163 property: "clip"
164 value: false
165 }
166 }
167 }
168 ]
169 }
170
171 Label {
172 id: checkBoxLbl
173 text: styledItem.text
174 anchors.left: background.right
175 anchors.leftMargin: units.gu(1)
176 anchors.right: parent.right
177 height: parent.height
178 enabled: styledItem.enabled
179 visible: styledItem.text
180 wrapMode: Text.WordWrap
181 }
182 }