| 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 1.3 |
| 19 |
import Lomiri.Components.Pickers 1.3 |
| 20 |
|
| 21 |
MainView { |
| 22 |
width: units.gu(40) |
| 23 |
height: units.gu(71) |
| 24 |
Column{ |
| 25 |
Row { |
| 26 |
ListModel { |
| 27 |
id: pickerModel |
| 28 |
Component.onCompleted: reset(100); |
| 29 |
|
| 30 |
function reset(num) { |
| 31 |
clear(); |
| 32 |
for (var i = 0; i < num; i++) { |
| 33 |
append({"label": "Item #"+i}); |
| 34 |
} |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
Picker { |
| 40 |
objectName: "Circular" |
| 41 |
id: circularPicker |
| 42 |
height: units.gu(40) |
| 43 |
model: pickerModel |
| 44 |
delegate: PickerDelegate { |
| 45 |
property string text: modelData ? modelData : "" |
| 46 |
Label { |
| 47 |
anchors.fill: parent |
| 48 |
horizontalAlignment: Text.AlignHCenter |
| 49 |
verticalAlignment: Text.AlignVCenter |
| 50 |
text: modelData ? modelData : "" |
| 51 |
} |
| 52 |
} |
| 53 |
onSelectedIndexChanged: print("circular index="+selectedIndex) |
| 54 |
onMovingChanged: print("MOVING?", moving) |
| 55 |
} |
| 56 |
|
| 57 |
Picker { |
| 58 |
objectName: "Linear" |
| 59 |
id: linearPicker |
| 60 |
height: units.gu(40) |
| 61 |
model: pickerModel |
| 62 |
circular: false |
| 63 |
delegate: PickerDelegate { |
| 64 |
property string text: modelData ? modelData : "" |
| 65 |
Label { |
| 66 |
anchors.fill: parent |
| 67 |
horizontalAlignment: Text.AlignHCenter |
| 68 |
verticalAlignment: Text.AlignVCenter |
| 69 |
text: modelData ? modelData : "" |
| 70 |
} |
| 71 |
} |
| 72 |
onSelectedIndexChanged: print("linear index="+selectedIndex) |
| 73 |
onMovingChanged: print("MOVING?", moving) |
| 74 |
} |
| 75 |
|
| 76 |
Picker { |
| 77 |
height: units.gu(40) |
| 78 |
model: pickerModel |
| 79 |
live: true |
| 80 |
delegate: PickerDelegate { |
| 81 |
Label { |
| 82 |
anchors.fill: parent |
| 83 |
horizontalAlignment: Text.AlignHCenter |
| 84 |
verticalAlignment: Text.AlignVCenter |
| 85 |
text: modelData |
| 86 |
} |
| 87 |
} |
| 88 |
onSelectedIndexChanged: print("circular index="+selectedIndex) |
| 89 |
onMovingChanged: print("MOVING?", moving) |
| 90 |
} |
| 91 |
|
| 92 |
Picker { |
| 93 |
height: units.gu(40) |
| 94 |
model: pickerModel |
| 95 |
circular: false |
| 96 |
live: true |
| 97 |
itemHeight: units.gu(10) |
| 98 |
delegate: PickerDelegate { |
| 99 |
Label { |
| 100 |
anchors.fill: parent |
| 101 |
horizontalAlignment: Text.AlignHCenter |
| 102 |
verticalAlignment: Text.AlignVCenter |
| 103 |
text: modelData |
| 104 |
} |
| 105 |
} |
| 106 |
onSelectedIndexChanged: print("linear index="+selectedIndex) |
| 107 |
onMovingChanged: print("MOVING?", moving) |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
Flow { |
| 112 |
spacing: units.gu(1) |
| 113 |
width: parent.width |
| 114 |
|
| 115 |
Button { |
| 116 |
text: "move & crop from 50" |
| 117 |
onClicked: { |
| 118 |
linearPicker.selectedIndex = 50; |
| 119 |
circularPicker.selectedIndex = 50; |
| 120 |
pickerModel.remove(50, 50); |
| 121 |
print("circular: selectedIndex="+circularPicker.selectedIndex) |
| 122 |
print("linear: selectedIndex="+linearPicker.selectedIndex) |
| 123 |
} |
| 124 |
} |
| 125 |
Button { |
| 126 |
text: "crop from 50" |
| 127 |
onClicked: { |
| 128 |
pickerModel.remove(50, 50); |
| 129 |
print("circular: selectedIndex="+circularPicker.selectedIndex) |
| 130 |
print("linear: selectedIndex="+linearPicker.selectedIndex) |
| 131 |
} |
| 132 |
} |
| 133 |
Button { |
| 134 |
text: "reset" |
| 135 |
onClicked: { |
| 136 |
pickerModel.reset(100); |
| 137 |
print("circular: selectedIndex="+circularPicker.selectedIndex) |
| 138 |
print("linear: selectedIndex="+linearPicker.selectedIndex) |
| 139 |
} |
| 140 |
} |
| 141 |
Button { |
| 142 |
text: "move to 20" |
| 143 |
onClicked: { |
| 144 |
circularPicker.selectedIndex = 20; |
| 145 |
linearPicker.selectedIndex = 20; |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
Button { |
| 150 |
text: "clear" |
| 151 |
onClicked: { |
| 152 |
pickerModel.clear(); |
| 153 |
print("circular: selectedIndex="+circularPicker.selectedIndex) |
| 154 |
print("linear: selectedIndex="+linearPicker.selectedIndex) |
| 155 |
} |
| 156 |
} |
| 157 |
Button { |
| 158 |
text: "append" |
| 159 |
onClicked: { |
| 160 |
pickerModel.append({"label": "Item #"+pickerModel.count}); |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
} |