| 1 |
/* |
| 2 |
* Copyright 2014-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 1.3 |
| 19 |
import Lomiri.Components.Styles 1.3 |
| 20 |
import QtQuick.Layouts 1.1 |
| 21 |
|
| 22 |
MainView { |
| 23 |
id: main |
| 24 |
width: units.gu(50) |
| 25 |
height: units.gu(105) |
| 26 |
|
| 27 |
property bool override: false |
| 28 |
|
| 29 |
Action { |
| 30 |
objectName: "stock" |
| 31 |
id: stock |
| 32 |
iconName: "starred" |
| 33 |
text: "Staaaar" |
| 34 |
onTriggered: { |
| 35 |
print(iconName, "triggered", value) |
| 36 |
view.ViewItems.selectedIndices = [0, 2, 9]; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
ListItemActions { |
| 41 |
id: leading |
| 42 |
objectName: "StockLeading" |
| 43 |
actions: [ |
| 44 |
Action { |
| 45 |
iconName: "delete" |
| 46 |
onTriggered: print(iconName, "triggered", value) |
| 47 |
}, |
| 48 |
Action { |
| 49 |
iconName: "alarm-clock" |
| 50 |
enabled: false |
| 51 |
onTriggered: print(iconName, "triggered", value) |
| 52 |
}, |
| 53 |
Action { |
| 54 |
iconName: "camcorder" |
| 55 |
onTriggered: print(iconName, "triggered", value) |
| 56 |
}, |
| 57 |
Action { |
| 58 |
iconName: "stock_website" |
| 59 |
onTriggered: print(iconName, "triggered", value) |
| 60 |
}, |
| 61 |
Action { |
| 62 |
iconName: "starred" |
| 63 |
onTriggered: print(iconName, "triggered", value) |
| 64 |
}, |
| 65 |
Action { |
| 66 |
iconName: "go-home" |
| 67 |
onTriggered: print(iconName, "triggered", value) |
| 68 |
} |
| 69 |
] |
| 70 |
} |
| 71 |
|
| 72 |
property bool selectable: false |
| 73 |
property list<Action> leadingArray: [ |
| 74 |
Action { |
| 75 |
iconName: "delete" |
| 76 |
onTriggered: print(iconName, "triggered", value) |
| 77 |
} |
| 78 |
] |
| 79 |
property list<Action> trailingArray: [ |
| 80 |
Action { |
| 81 |
iconName: "toolkit_input-search" |
| 82 |
onTriggered: print(iconName, "triggered", value) |
| 83 |
}, |
| 84 |
Action { |
| 85 |
iconName: "edit" |
| 86 |
onTriggered: print(iconName, "triggered", value) |
| 87 |
}, |
| 88 |
Action { |
| 89 |
iconName: "email" |
| 90 |
onTriggered: print(iconName, "triggered", value) |
| 91 |
} |
| 92 |
] |
| 93 |
|
| 94 |
Column { |
| 95 |
anchors { |
| 96 |
left: parent.left |
| 97 |
right: parent.right |
| 98 |
} |
| 99 |
|
| 100 |
Button { |
| 101 |
text: "Selectable " + (selectable ? "OFF" : "ON") |
| 102 |
onClicked: selectable = !selectable |
| 103 |
} |
| 104 |
|
| 105 |
ListItem { |
| 106 |
id: testItem |
| 107 |
objectName: "single" |
| 108 |
color: "lime" |
| 109 |
height: units.gu(15) |
| 110 |
onClicked: { |
| 111 |
print("click") |
| 112 |
units.gridUnit += 2; |
| 113 |
} |
| 114 |
onPressAndHold: print("pressAndHold", objectName) |
| 115 |
RowLayout { |
| 116 |
anchors { |
| 117 |
fill: parent |
| 118 |
margins: units.gu(0.5) |
| 119 |
leftMargin: anchors.rightMargin |
| 120 |
rightMargin: units.gu(2) |
| 121 |
} |
| 122 |
Label { |
| 123 |
anchors.fill: parent |
| 124 |
text: units.gridUnit + "PX/unit" |
| 125 |
Layout.preferredWidth: paintedWidth |
| 126 |
} |
| 127 |
Button { |
| 128 |
text: "Press me" |
| 129 |
anchors.centerIn: parent |
| 130 |
onClicked: units.gridUnit -= 2 |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
leadingActions: ListItemActions { |
| 135 |
objectName: "InlineLeading" |
| 136 |
actions: [stock] |
| 137 |
delegate: Column { |
| 138 |
width: height + units.gu(2) |
| 139 |
Icon { |
| 140 |
width: units.gu(3) |
| 141 |
height: width |
| 142 |
name: action.iconName |
| 143 |
color: pressed ? "blue" : "pink" |
| 144 |
anchors.horizontalCenter: parent.horizontalCenter |
| 145 |
} |
| 146 |
Label { |
| 147 |
text: action.text + index |
| 148 |
width: parent.width |
| 149 |
horizontalAlignment: Text.AlignHCenter |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
trailingActions: leading |
| 154 |
} |
| 155 |
ListItem { |
| 156 |
Label { |
| 157 |
id: label |
| 158 |
text: "No action" |
| 159 |
} |
| 160 |
onClicked: print(label.text, "clicked") |
| 161 |
} |
| 162 |
|
| 163 |
ListItem { |
| 164 |
Label { |
| 165 |
id: label2 |
| 166 |
anchors.fill: parent |
| 167 |
text: "Another standalone ListItem\nStarted with custom style, reset to theme style on first click" |
| 168 |
} |
| 169 |
leadingActions: testItem.leadingActions |
| 170 |
trailingActions: ListItemActions { |
| 171 |
actions: leading.actions |
| 172 |
} |
| 173 |
style: ListItemStyle {} |
| 174 |
onClicked: { style = undefined; label2.text = "Another standalone ListItem" } |
| 175 |
} |
| 176 |
|
| 177 |
ListView { |
| 178 |
id: view |
| 179 |
clip: true |
| 180 |
width: parent.width |
| 181 |
height: units.gu(28) |
| 182 |
model: 25 |
| 183 |
pressDelay: 0 |
| 184 |
ViewItems.selectMode: main.selectable |
| 185 |
ViewItems.selectedIndices: [9,3,4,1] |
| 186 |
ViewItems.onSelectedIndicesChanged: print("LISTVIEW INDEXES=", ViewItems.selectedIndices) |
| 187 |
delegate: ListItem { |
| 188 |
objectName: "ListItem" + index |
| 189 |
id: listItem |
| 190 |
onClicked: print(" clicked") |
| 191 |
onPressAndHold: print("pressAndHold") |
| 192 |
leadingActions: ListItemActions { |
| 193 |
actions: trailingArray |
| 194 |
} |
| 195 |
|
| 196 |
trailingActions: trailing |
| 197 |
contentItem.anchors.margins: units.gu(1) |
| 198 |
|
| 199 |
RowLayout { |
| 200 |
anchors { |
| 201 |
fill: parent |
| 202 |
margins: units.gu(0.5) |
| 203 |
leftMargin: anchors.rightMargin |
| 204 |
rightMargin: units.gu(2) |
| 205 |
} |
| 206 |
Captions { |
| 207 |
title.text: "This is one Label split in two lines.\n" + |
| 208 |
"The second line - item #" + modelData |
| 209 |
} |
| 210 |
CheckBox {} |
| 211 |
Button { |
| 212 |
text: "Pressme..." |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
states: State { |
| 217 |
name: "override" |
| 218 |
when: main.override |
| 219 |
PropertyChanges { |
| 220 |
target: listItem |
| 221 |
highlightColor: "brown" |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
onContentMovementStarted: print("moving started") |
| 226 |
onContentMovementEnded: print("moving ended") |
| 227 |
} |
| 228 |
} |
| 229 |
Flickable { |
| 230 |
id: flicker |
| 231 |
width: parent.width |
| 232 |
height: units.gu(28) |
| 233 |
clip: true |
| 234 |
contentHeight: column.childrenRect.height |
| 235 |
ListItemActions { |
| 236 |
id: trailing |
| 237 |
actions: leading.actions |
| 238 |
} |
| 239 |
Column { |
| 240 |
id: column |
| 241 |
width: flicker.width |
| 242 |
property alias count: repeater.count |
| 243 |
ViewItems.selectMode: main.selectable |
| 244 |
Repeater { |
| 245 |
id: repeater |
| 246 |
model: 10 |
| 247 |
ListItem { |
| 248 |
objectName: "InFlickable"+index |
| 249 |
color: LomiriColors.silk |
| 250 |
highlightColor: "lime" |
| 251 |
divider.colorFrom: LomiriColors.green |
| 252 |
|
| 253 |
leadingActions: ListItemActions { |
| 254 |
actions: leadingArray |
| 255 |
} |
| 256 |
trailingActions: ListItemActions { |
| 257 |
actions: trailingArray |
| 258 |
} |
| 259 |
contentItem.anchors { |
| 260 |
leftMargin: units.gu(2) |
| 261 |
rightMargin: units.gu(2) |
| 262 |
} |
| 263 |
|
| 264 |
Label { |
| 265 |
text: modelData + " Flickable item" |
| 266 |
} |
| 267 |
Row { |
| 268 |
anchors.centerIn: parent |
| 269 |
spacing: units.dp(4) |
| 270 |
Button { |
| 271 |
text: "Pressme..." |
| 272 |
} |
| 273 |
Switch {} |
| 274 |
} |
| 275 |
|
| 276 |
onClicked: divider.visible = !divider.visible |
| 277 |
} |
| 278 |
} |
| 279 |
} |
| 280 |
} |
| 281 |
ListItem { |
| 282 |
Label { |
| 283 |
text: "Switch makes this item to highlight" |
| 284 |
} |
| 285 |
Switch { |
| 286 |
id: toggle |
| 287 |
anchors.right: parent.right |
| 288 |
} |
| 289 |
Component.onCompleted: clicked.connect(toggle.clicked) |
| 290 |
} |
| 291 |
ListItem { |
| 292 |
Label { |
| 293 |
text: "With action assigned" |
| 294 |
} |
| 295 |
onClicked: print("clicked") |
| 296 |
onPressAndHold: print("longPressed") |
| 297 |
action: stock |
| 298 |
} |
| 299 |
} |
| 300 |
} |