Debian Codegraph @

src/imports/Components/Pickers/1.2/Dialer.qml

raw
1 /*
2 * Copyright 2013 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 1.2
19
20 /*!
21 \qmltype Dialer
22 \inqmlmodule Lomiri.Components.Pickers 1.0
23 \ingroup lomiri-pickers
24 \brief Dialer is a phone dialer style picker component.
25
26 The Dialer component is dedicated for value selection where the value is
27 compound of several sections, i.e. hour, minute and second, or integral and
28 decimal values. Each section is defined by a DialerHand, which shares the
29 same range as the dialer is having. Dialer hand visuals are placed on the
30 same dialer disk, however this can be altered by setting different values
31 to DialerHand propertries.
32
33 The following example shows how to create a dialer component to select a
34 value between 0 and 50.
35
36 \qml
37 import QtQuick 2.4
38 import Lomiri.Components.Pickers 1.0
39
40 Dialer {
41 size: units.gu(20)
42 minimumValue: 0
43 maximumValue: 50
44
45 DialerHand {
46 id: mainHand
47 onValueChanged: console.log(value)
48 }
49 }
50 \endqml
51
52 \sa DialerHand
53 */
54
55 StyledItem {
56
57 /*!
58 \qmlproperty real minimumValue: 0
59 \qmlproperty real maximumValue: 360
60
61 These properties define the value range the dialer hand values can take.
62 The default values are 0 and 360.
63 */
64 property real minimumValue: 0.0
65
66 /*! \internal - documented in previous block*/
67 property real maximumValue: 360.0
68
69 /*!
70 The property holds the size of the dialer. The component should be sized
71 using this property instead of using width and/or height properties. Sizing
72 with this property it is made sure that the component will scale evenly.
73 */
74 property real size: units.gu(32)
75
76 /*!
77 The property holds the height reserved for the dialer hands, being the distance
78 between the outer and the inner dialer disks. This value cannot be higher than
79 the half of the dialer \l size.
80 */
81 property real handSpace: units.gu(6.5)
82
83 /*!
84 \qmlproperty Item centerItem
85 The property holds the component from the center of the Dialer. Items wanted
86 to be placed into the center of the Dialer must be reparented to this component,
87 or listed in the \l centerContent property.
88
89 Beside that, the property helps anchoring the center disk content to the
90 item.
91 \qml
92 Dialer {
93 DialerHand {
94 id: hand
95 Label {
96 parent: hand.centerItem
97 // [...]
98 }
99 }
100 // [...]
101 }
102 \endqml
103 */
104 readonly property alias centerItem: centerHolder
105
106 /*!
107 \qmlproperty list<var> centerContent
108 The property holds the list of items to be placed inside of the center disk.
109 Items placed inside the center disk can either be listed in this property or
110 reparented to \l centerItem property.
111 \qml
112 Dialer {
113 DialerHand {
114 id: hand
115 centerContent: [
116 Label {
117 // [...]
118 }
119 // [...]
120 ]
121 }
122 // [...]
123 }
124 \endqml
125 */
126 property alias centerContent: centerHolder.data
127
128 /*!
129 \qmlproperty list<DialerHands> hands
130 \readonly
131 The property holds the list of DialerHands added to Dialer. This may be the
132 same as the children, however will contain only DialerHand objects.
133 */
134 readonly property alias hands: internal.hands
135
136 /*!
137 \qmlmethod void handUpdated(DialerHand hand)
138 The signal is emitted when the hand value is updated.
139 */
140 signal handUpdated(var hand)
141
142 id: dialer
143 implicitWidth: size
144 implicitHeight: size
145 activeFocusOnPress: true
146
147 style: Theme.createStyleComponent("DialerStyle.qml", dialer)
148
149 Item {
150 id: internal
151 // internal property holding only the list of DialerHand components
152 // workaround for readonly public property
153 property var hands: []
154
155 height: size - handSpace * 2
156 width: size - handSpace * 2
157 anchors.centerIn: parent
158 Item {
159 id: centerHolder
160 anchors.fill: parent
161 z: 1
162 }
163 }
164
165 /*! \internal */
166 onChildrenChanged: {
167 // apply dialer presets if the hand sizes were not set
168 // check dialers only
169 var idx = 0;
170 var stack = [];
171 for (var i in children) {
172 if (children[i].hasOwnProperty("hand")) {
173 children[i].__grabber.index = idx++;
174 stack.push(children[i]);
175 }
176 internal.hands = stack;
177 }
178 }
179 }