| 1 |
/* |
| 2 |
* Copyright 2012 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 |
****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 1.0 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 |
fontSize: "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/chevron.png") |
| 206 |
opacity: enabled ? 1.0 : 0.5 |
| 207 |
rotation: expanded ? 270 : 90 |
| 208 |
width: implicitWidth / 1.5 |
| 209 |
height: implicitHeight / 1.5 |
| 210 |
|
| 211 |
states: [ |
| 212 |
State { |
| 213 |
name: "expanded" |
| 214 |
when: selector.expanded |
| 215 |
PropertyChanges { target: accordionIcon; rotation: 270 } |
| 216 |
}, State { |
| 217 |
name: "closed" |
| 218 |
when: !selector.expanded |
| 219 |
PropertyChanges { target: accordionIcon; rotation: 90 } |
| 220 |
} |
| 221 |
] |
| 222 |
|
| 223 |
transitions: Transition { |
| 224 |
LomiriNumberAnimation { |
| 225 |
target: accordionIcon |
| 226 |
properties: "rotation" |
| 227 |
duration: LomiriAnimation.SnapDuration |
| 228 |
} |
| 229 |
} |
| 230 |
} |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
Repeater { |
| 235 |
id: valueRepeater |
| 236 |
property int valueHeight: selector.expanded ? units.gu(5) : 0 |
| 237 |
|
| 238 |
states: [ State { |
| 239 |
name: "expanded" |
| 240 |
when: selector.expanded |
| 241 |
PropertyChanges { |
| 242 |
target: valueRepeater |
| 243 |
valueHeight: units.gu(5) |
| 244 |
} |
| 245 |
}, State { |
| 246 |
name: "closed" |
| 247 |
when: !selector.expanded |
| 248 |
PropertyChanges { |
| 249 |
target: valueRepeater |
| 250 |
valueHeight: 0 |
| 251 |
} |
| 252 |
} |
| 253 |
] |
| 254 |
|
| 255 |
transitions: Transition { |
| 256 |
LomiriNumberAnimation { |
| 257 |
target: valueRepeater |
| 258 |
properties: "valueHeight" |
| 259 |
duration: LomiriAnimation.SnapDuration |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
model: selector.values |
| 264 |
Rectangle { |
| 265 |
color: Qt.lighter(Theme.palette.normal.base) |
| 266 |
height: valueRepeater.valueHeight |
| 267 |
width: parent.width |
| 268 |
|
| 269 |
Empty { |
| 270 |
id: valueBase |
| 271 |
height: parent.height |
| 272 |
visible: valueBase.height > 0 |
| 273 |
onClicked: { |
| 274 |
selector.selectedIndex = index |
| 275 |
selector.expanded = false |
| 276 |
} |
| 277 |
|
| 278 |
selected: index === selector.selectedIndex |
| 279 |
|
| 280 |
LabelVisual { |
| 281 |
text: modelData |
| 282 |
anchors { |
| 283 |
left: parent.left |
| 284 |
leftMargin: units.gu(3) |
| 285 |
verticalCenter: parent.verticalCenter |
| 286 |
} |
| 287 |
font.bold: valueBase.selected |
| 288 |
property real heightMargin: valueBase.height - implicitHeight |
| 289 |
visible: heightMargin > 0 |
| 290 |
// fade in/out the values when expanding/contracting the selector. |
| 291 |
opacity: heightMargin < 10 ? heightMargin/10 : 1 |
| 292 |
} |
| 293 |
} |
| 294 |
} |
| 295 |
} |
| 296 |
} |
| 297 |
} |