| 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 |
\qmltype Standard |
| 22 |
\inqmlmodule Lomiri.Components.ListItems 1.0 |
| 23 |
\ingroup lomiri-listitems |
| 24 |
\brief The standard list item class. It shows a basic list item |
| 25 |
with a label (text), and optionally an icon, a progression arrow, |
| 26 |
and it can have an embedded Item (\l control) that can be used |
| 27 |
for including Buttons, Switches etc. inside the list item. |
| 28 |
\note \b{The component is deprecated. Use ListItem component instead.} |
| 29 |
|
| 30 |
\l {http://design.lomiri.com/apps/building-blocks/list-items}{See also the Design Guidelines on List Items}. |
| 31 |
|
| 32 |
Examples: |
| 33 |
\qml |
| 34 |
import Lomiri.Components 1.2 |
| 35 |
import Lomiri.Components.ListItems 1.0 as ListItem |
| 36 |
Column { |
| 37 |
ListItem.Standard { |
| 38 |
text: "Selectable standard list item" |
| 39 |
selected: false |
| 40 |
onClicked: selected = !selected |
| 41 |
} |
| 42 |
ListItem.Standard { |
| 43 |
text: "List item with icon" |
| 44 |
iconName: "compose" |
| 45 |
} |
| 46 |
ListItem.Standard { |
| 47 |
text: "With a progression arrow" |
| 48 |
progression: true |
| 49 |
} |
| 50 |
ListItem.Standard { |
| 51 |
text: "Control" |
| 52 |
control: Button { |
| 53 |
text: "Click me" |
| 54 |
width: units.gu(19) |
| 55 |
onClicked: print("Clicked") |
| 56 |
} |
| 57 |
progression: true |
| 58 |
} |
| 59 |
} |
| 60 |
\endqml |
| 61 |
*/ |
| 62 |
Empty { |
| 63 |
id: listItem |
| 64 |
|
| 65 |
/*! |
| 66 |
\deprecated |
| 67 |
|
| 68 |
\b{Use iconName or iconSource instead.} |
| 69 |
|
| 70 |
The location of the icon to show in the list item (optional), or an Item that is |
| 71 |
shown on the left side inside the list item. The icon will automatically be |
| 72 |
anchored to the left side of the list item, and if its height is undefined, to the top |
| 73 |
and bottom of the list item. |
| 74 |
\qmlproperty variant icon |
| 75 |
*/ |
| 76 |
property variant icon: iconSource != "" ? iconSource : undefined |
| 77 |
|
| 78 |
/*! |
| 79 |
The location of the icon to show in the list item if iconSource failed to load (optional). |
| 80 |
\qmlproperty url fallbackIconSource |
| 81 |
*/ |
| 82 |
property alias fallbackIconSource: iconHelper.fallbackSource |
| 83 |
|
| 84 |
/*! |
| 85 |
The icon shown in the list item if iconName failed to load (optional). |
| 86 |
|
| 87 |
\qmlproperty string fallbackIconName |
| 88 |
|
| 89 |
If both fallbackIconSource and fallbackIconName are defined, fallbackIconName will be ignored. |
| 90 |
|
| 91 |
\note The complete list of icons available in Lomiri is not published yet. |
| 92 |
For now please refer to the folders where the icon themes are installed: |
| 93 |
\list |
| 94 |
\li Lomiri Touch: \l file:/usr/share/icons/suru |
| 95 |
\li Lomiri Desktop: \l file:/usr/share/icons/lomiri-mono-dark |
| 96 |
\endlist |
| 97 |
These 2 separate icon themes will be merged soon. |
| 98 |
*/ |
| 99 |
property alias fallbackIconName: iconHelper.fallbackIconName |
| 100 |
|
| 101 |
/*! |
| 102 |
The text that is shown in the list item as a label. |
| 103 |
\qmlproperty string text |
| 104 |
*/ |
| 105 |
|
| 106 |
/*! |
| 107 |
Show or hide the progression symbol. |
| 108 |
*/ |
| 109 |
property bool progression: false |
| 110 |
|
| 111 |
/*! |
| 112 |
\internal |
| 113 |
\deprecated |
| 114 |
Width of the icon to be displayed |
| 115 |
*/ |
| 116 |
property real __iconWidth |
| 117 |
|
| 118 |
/*! |
| 119 |
\internal |
| 120 |
\deprecated |
| 121 |
Height of the icon to be displayed |
| 122 |
*/ |
| 123 |
property real __iconHeight |
| 124 |
|
| 125 |
/*! |
| 126 |
\internal |
| 127 |
\deprecated |
| 128 |
The margins on the left side of the icon. |
| 129 |
*/ |
| 130 |
property real __leftIconMargin |
| 131 |
|
| 132 |
/*! |
| 133 |
\internal |
| 134 |
\deprecated |
| 135 |
The margins on the right side of the icon. |
| 136 |
*/ |
| 137 |
property real __rightIconMargin |
| 138 |
|
| 139 |
/*! |
| 140 |
An optional control that is displayed inside the list item. |
| 141 |
The width of the control must be specified in order to determine |
| 142 |
the layout of the list item. |
| 143 |
|
| 144 |
\qmlproperty Item control |
| 145 |
*/ |
| 146 |
property alias control: controlContainer.control |
| 147 |
|
| 148 |
/*! |
| 149 |
Show or hide the frame around the icon |
| 150 |
\qmlproperty bool iconFrame |
| 151 |
*/ |
| 152 |
property alias iconFrame: iconHelper.hasFrame |
| 153 |
|
| 154 |
// If there is a control, the controlArea covers the listItem's mouseArea, |
| 155 |
// so in that case use the highlights below when pressed |
| 156 |
highlightWhenPressed: !listItem.control |
| 157 |
|
| 158 |
// Avoid emit clicked signals when clicking on the control area |
| 159 |
__acceptEvents: false |
| 160 |
|
| 161 |
/*! |
| 162 |
\internal |
| 163 |
*/ |
| 164 |
property bool __controlAreaPressed: false |
| 165 |
Rectangle { |
| 166 |
id: controlHighlight |
| 167 |
|
| 168 |
visible: listItem.swipingState === "" ? control && __controlAreaPressed : false |
| 169 |
anchors { |
| 170 |
top: parent.top |
| 171 |
right: progressionHelper.visible ? progressionHelper.left : parent.right |
| 172 |
bottom: parent.bottom |
| 173 |
left: parent.left |
| 174 |
} |
| 175 |
color: Theme.palette.selected.background |
| 176 |
} |
| 177 |
|
| 178 |
Rectangle { |
| 179 |
id: progressionHighlight |
| 180 |
|
| 181 |
visible: listItem.swipingState === "" ? listItem.progression && progressionHelper.showSplit && listItem.pressed && !__controlAreaPressed : false |
| 182 |
anchors { |
| 183 |
left: progressionHelper.left |
| 184 |
top: parent.top |
| 185 |
bottom: parent.bottom |
| 186 |
right: parent.right |
| 187 |
} |
| 188 |
color: Theme.palette.selected.background |
| 189 |
} |
| 190 |
|
| 191 |
IconVisual { |
| 192 |
id: iconHelper |
| 193 |
|
| 194 |
width: height |
| 195 |
height: Math.min(units.gu(5), listItem.height - units.gu(1)) |
| 196 |
anchors { |
| 197 |
left: parent.left |
| 198 |
leftMargin: listItem.__contentsMargins |
| 199 |
verticalCenter: parent.verticalCenter |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
/*! |
| 204 |
\internal |
| 205 |
The \l icon property is an Item. The value is false if \l icon is a string, |
| 206 |
or when no icon was set. |
| 207 |
*/ |
| 208 |
property bool __iconIsItem: false |
| 209 |
|
| 210 |
/*! |
| 211 |
\internal |
| 212 |
*/ |
| 213 |
onIconChanged: { |
| 214 |
if (icon == undefined) return; |
| 215 |
if (icon != iconSource) { |
| 216 |
console.warn("WARNING: ListItems.Standard.icon is DEPRECATED. " + |
| 217 |
"Use iconName and iconSource instead.") |
| 218 |
} |
| 219 |
if (typeof icon == "string" || typeof icon == typeof iconSource) { |
| 220 |
// icon is the url of an image |
| 221 |
iconHelper.source = icon; |
| 222 |
__iconIsItem = false; |
| 223 |
} else { |
| 224 |
// icon is an Item. |
| 225 |
__iconIsItem = true; |
| 226 |
iconHelper.source = ""; |
| 227 |
|
| 228 |
icon.parent = listItem; |
| 229 |
icon.anchors.left = listItem.left; |
| 230 |
icon.anchors.margins = Qt.binding(function() { return listItem.__contentsMargins }); |
| 231 |
if (!icon.height) { |
| 232 |
icon.anchors.top = listItem.top; |
| 233 |
icon.anchors.bottom = listItem.bottom; |
| 234 |
} |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
/*! |
| 239 |
\internal |
| 240 |
The \l foregroundGroundColor property stores the internal label color. |
| 241 |
*/ |
| 242 |
property alias __foregroundColor: label.color |
| 243 |
|
| 244 |
LabelVisual { |
| 245 |
id: label |
| 246 |
property bool anchorToIconHelper: !__iconIsItem && iconHelper.source != "" |
| 247 |
selected: listItem.selected |
| 248 |
anchors { |
| 249 |
verticalCenter: parent.verticalCenter |
| 250 |
left: anchorToIconHelper ? iconHelper.right : parent.left |
| 251 |
leftMargin: __iconIsItem ? icon.width + 2 * listItem.__contentsMargins : listItem.__contentsMargins |
| 252 |
right: control ? controlContainer.left : (progression ? progressionHelper.left : parent.right) |
| 253 |
rightMargin: listItem.__contentsMargins |
| 254 |
} |
| 255 |
text: listItem.text |
| 256 |
} |
| 257 |
|
| 258 |
Item { |
| 259 |
id: controlContainer |
| 260 |
property Item control |
| 261 |
// use the width of the control if there is (possibly elided) text, |
| 262 |
// or full width available if there is no text. |
| 263 |
width: control ? control.width : undefined |
| 264 |
height: control ? control.height : undefined |
| 265 |
anchors { |
| 266 |
right: listItem.progression ? progressionHelper.left : parent.right |
| 267 |
rightMargin: listItem.__contentsMargins |
| 268 |
verticalCenter: parent.verticalCenter |
| 269 |
} |
| 270 |
onControlChanged: { |
| 271 |
if (control) control.parent = controlContainer; |
| 272 |
} |
| 273 |
|
| 274 |
Connections { |
| 275 |
target: listItem.__mouseArea |
| 276 |
function onClicked() { listItem.clicked() } |
| 277 |
function onPressAndHold() { listItem.pressAndHold() } |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
/*! |
| 282 |
\internal |
| 283 |
*/ |
| 284 |
onPressedChanged: { |
| 285 |
if (listItem.pressed && control && control.enabled && (__mouseArea.mouseX < progressionHelper.x)) { |
| 286 |
listItem.__controlAreaPressed = true |
| 287 |
} else { |
| 288 |
listItem.__controlAreaPressed = false |
| 289 |
} |
| 290 |
} |
| 291 |
|
| 292 |
ProgressionVisual { |
| 293 |
id: progressionHelper |
| 294 |
visible: listItem.progression |
| 295 |
anchors { |
| 296 |
right: parent.right |
| 297 |
rightMargin: listItem.__contentsMargins |
| 298 |
top: parent.top |
| 299 |
bottom: parent.bottom |
| 300 |
} |
| 301 |
showSplit: control ? true : false |
| 302 |
splitMargin: listItem.__contentsMargins |
| 303 |
} |
| 304 |
} |