Debian Codegraph @

src/imports/Components/ListItems/2.0/ValueSelector.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 /*!
21 ****DEPRECATED! PLEASE USE ITEM SELECTOR OR FOR THE LOMIRI SHAPE VERSION THE OPTION SELECTOR.****
22
23 \qmltype ValueSelector
24 \inqmlmodule Lomiri.Components.ListItems 1.0
25 \ingroup lomiri-listitems
26 \brief List item displaying single selected value when not expanded,
27 where expanding it opens a listing of all the possible values for selection.
28
29 Examples:
30 \qml
31 import Lomiri.Components.ListItems as ListItem
32 Column {
33 width: 250
34 ListItem.ValueSelector {
35 text: "Standard"
36 values: ["Value 1", "Value 2", "Value 3", "Value 4"]
37 }
38 ListItem.ValueSelector {
39 text: "Disabled"
40 values: ["Value 1", "Value 2", "Value 3", "Value 4"]
41 enabled: false
42 }
43 ListItem.ValueSelector {
44 text: "Expanded"
45 values: ["Value 1", "Value 2", "Value 3", "Value 4"]
46 expanded: true
47 }
48 ListItem.ValueSelector {
49 text: "Icon"
50 iconName: "compose"
51 values: ["Value 1", "Value 2", "Value 3", "Value 4"]
52 selectedIndex: 2
53 }
54 }
55 \endqml
56 */
57 Empty {
58 id: selector
59 __height: column.height
60
61 /*!
62 The text that is shown in the list item as a label.
63 \qmlproperty string text
64 */
65
66 /*!
67 \deprecated
68
69 \b{Use iconName or iconSource instead.}
70
71 The location of the icon to show in the list item (optional), or an Item that is
72 shown on the left side inside the list item. The icon will automatically be
73 anchored to the left side of the list item, and if its height is undefined, to the top
74 and bottom of the list item.
75 \qmlproperty variant icon
76 */
77 property alias icon: selectorMain.icon
78
79 /*!
80 The location of the icon to show in the list item if iconSource failed to load (optional).
81 \qmlproperty url fallbackIconSource
82 */
83 property alias fallbackIconSource: selectorMain.fallbackIconSource
84
85 /*!
86 The icon shown in the list item if iconName failed to load (optional).
87
88 \qmlproperty string fallbackIconName
89
90 If both fallbackIconSource and fallbackIconName are defined, fallbackIconName will be ignored.
91
92 \note The complete list of icons available in Lomiri is not published yet.
93 For now please refer to the folders where the icon themes are installed:
94 \list
95 \li Lomiri Touch: \l file:/usr/share/icons/suru
96 \li Lomiri Desktop: \l file:/usr/share/icons/lomiri-mono-dark
97 \endlist
98 These 2 separate icon themes will be merged soon.
99 */
100 property alias fallbackIconName: selectorMain.fallbackIconName
101
102 /*!
103 \internal
104 \deprecated
105 Width of the icon to be displayed
106 */
107 property real __iconWidth
108
109 /*!
110 \internal
111 \deprecated
112 Height of the icon to be displayed
113 */
114 property real __iconHeight
115
116 /*!
117 \internal
118 \deprecated
119 The margins on the left side of the icon.
120 */
121 property real __leftIconMargin
122
123 /*!
124 \internal
125 \deprecated
126 The margins on the right side of the icon.
127 */
128 property real __rightIconMargin
129
130 /*!
131 Show or hide the frame around the icon
132 \qmlproperty bool iconFrame
133 */
134 property alias iconFrame: selectorMain.iconFrame
135
136 /*!
137 The list of values that will be shown under the label text
138 */
139 property variant values
140
141 /*!
142 The index of the currently selected element from the \l values array.
143 */
144 property int selectedIndex: 0
145
146 /*!
147 Specifies whether the selector is 'open' or 'closed'.
148 */
149 property bool expanded: false
150
151 showDivider: false
152
153 Column {
154 id: column
155 anchors {
156 left: parent.left
157 right: parent.right
158 topMargin: units.dp(2)
159 bottomMargin: units.dp(2)
160 }
161
162 Base {
163 id: selectorMain
164 height: units.gu(6)
165 showDivider: true
166 onClicked: selector.expanded = !selector.expanded
167 selected: selector.selected
168 iconSource: selector.iconSource
169
170 LabelVisual {
171 id: label
172 anchors {
173 verticalCenter: parent.verticalCenter
174 left: parent.left
175 }
176 text: selector.text
177 width: Math.min(implicitWidth, parent.width * 0.8)
178 }
179 LabelVisual {
180 id: valueLabel
181 anchors {
182 verticalCenter: parent.verticalCenter
183 right: accordion.left
184 rightMargin: selector.__contentsMargins
185 leftMargin: selector.__contentsMargins
186 left: label.right
187 }
188 textSize: Label.Small
189 text: selector.values[selector.selectedIndex]
190 font.bold: selector.expanded
191 horizontalAlignment: Text.AlignRight
192 }
193 Item {
194 id: accordion
195 width: accordionIcon.width
196 anchors {
197 right: parent.right
198 top: parent.top
199 bottom: parent.bottom
200 }
201 Image {
202 id: accordionIcon
203 anchors.right: parent.right
204 anchors.verticalCenter: parent.verticalCenter
205 source: Qt.resolvedUrl("../../artwork/[email protected]")
206 opacity: enabled ? 1.0 : 0.5
207 rotation: expanded ? 270 : 90
208 width: implicitWidth / 1.5
209 height: implicitHeight / 1.5
210 scale: units.gridUnit / 27
211
212 states: [
213 State {
214 name: "expanded"
215 when: selector.expanded
216 PropertyChanges { target: accordionIcon; rotation: 270 }
217 }, State {
218 name: "closed"
219 when: !selector.expanded
220 PropertyChanges { target: accordionIcon; rotation: 90 }
221 }
222 ]
223
224 transitions: Transition {
225 LomiriNumberAnimation {
226 target: accordionIcon
227 properties: "rotation"
228 duration: LomiriAnimation.SnapDuration
229 }
230 }
231 }
232 }
233 }
234
235 Repeater {
236 id: valueRepeater
237 property int valueHeight: selector.expanded ? units.gu(5) : 0
238
239 states: [ State {
240 name: "expanded"
241 when: selector.expanded
242 PropertyChanges {
243 target: valueRepeater
244 valueHeight: units.gu(5)
245 }
246 }, State {
247 name: "closed"
248 when: !selector.expanded
249 PropertyChanges {
250 target: valueRepeater
251 valueHeight: 0
252 }
253 }
254 ]
255
256 transitions: Transition {
257 LomiriNumberAnimation {
258 target: valueRepeater
259 properties: "valueHeight"
260 duration: LomiriAnimation.SnapDuration
261 }
262 }
263
264 model: selector.values
265 Rectangle {
266 color: Qt.lighter(theme.palette.normal.base)
267 height: valueRepeater.valueHeight
268 width: parent.width
269
270 Empty {
271 id: valueBase
272 height: parent.height
273 visible: valueBase.height > 0
274 onClicked: {
275 selector.selectedIndex = index
276 selector.expanded = false
277 }
278
279 selected: index === selector.selectedIndex
280
281 LabelVisual {
282 text: modelData
283 anchors {
284 left: parent.left
285 leftMargin: units.gu(3)
286 verticalCenter: parent.verticalCenter
287 }
288 font.bold: valueBase.selected
289 property real heightMargin: valueBase.height - implicitHeight
290 visible: heightMargin > 0
291 // fade in/out the values when expanding/contracting the selector.
292 opacity: heightMargin < 10 ? heightMargin/10 : 1
293 }
294 }
295 }
296 }
297 }
298 }