2
* Copyright 2012 Canonical Ltd.
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.
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.
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/>.
18
import Ubuntu.Components 0.1
23
property color frameColor: UbuntuColors.warmGrey
24
property real frameWidth: 1
25
property color backgroundColor: "#00000000"
26
property bool overlay: true
27
property color overlayColor: UbuntuColors.warmGrey
30
property bool completed: false
36
color: backgroundColor
39
function modelSize() {
40
return loader.item.model.hasOwnProperty("count") ? loader.item.model.count : loader.item.model.length;
43
function moveToIndex(toIndex) {
44
var count = (loader.item && loader.item.model) ? modelSize() : -1;
45
if (completed && count > 0) {
46
if (QuickUtils.className(loader.item) === "QQuickListView") {
47
loader.item.currentIndex = toIndex;
50
loader.item.positionViewAtIndex(count - 1, PathView.Center);
51
loader.item.positionViewAtIndex(toIndex, PathView.Center);
57
id: highlightComponent
59
width: parent ? parent.width : 0
60
height: (parent && parent.currentItem) ? parent.currentItem.height : units.gu(4);
69
property Item tumbler: styledItem
73
model: styledItem.model
74
delegate: styledItem.delegate
75
highlight: highlightComponent
76
// put the currentItem to the center of the view
77
preferredHighlightBegin: 0.5
78
preferredHighlightEnd: 0.5
80
pathItemCount: pView.height / highlightItem.height + 1
81
snapMode: PathView.SnapToItem
82
flickDeceleration: 100
84
property int contentHeight: pathItemCount * highlightItem.height
86
startX: pView.width / 2
87
startY: -(pView.contentHeight - pView.height) / 2
90
y: pView.height + (pView.contentHeight - pView.height) / 2
101
property Item tumbler: styledItem
106
model: styledItem.model
107
delegate: styledItem.delegate
109
highlight: highlightComponent
110
preferredHighlightBegin: highlightItem ? (height - highlightItem.height) / 2 : 0
111
preferredHighlightEnd: highlightItem ? (preferredHighlightBegin + highlightItem.height) : 0
112
highlightRangeMode: ListView.StrictlyEnforceRange
113
highlightMoveDuration: 300
114
flickDeceleration: 100
123
margins: units.gu(0.2)
125
sourceComponent: (styledItem.circular) ? wrapAround : linear
127
// to avoid binding loop
130
onSelectedIndexChanged: loader.item.currentIndex = styledItem.selectedIndex
133
// live selectedIndex updater
136
property: "selectedIndex"
137
value: loader.item.currentIndex
138
when: completed && (styledItem.model !== undefined) && styledItem.live
140
// non-live selectedIndex updater
143
ignoreUnknownSignals: true
145
if (!styledItem.live) styledItem.selectedIndex = loader.item.currentIndex;
147
onCurrentIndexChanged: {
148
if (!styledItem.live && styledItem.__clickedIndex === loader.item.currentIndex) {
149
styledItem.selectedIndex = loader.item.currentIndex;
150
styledItem.__clickedIndex = -1;
154
moveToIndex((completed) ? 0 : styledItem.selectedIndex);
155
if (completed && !styledItem.live) styledItem.selectedIndex = 0;
159
Component.onCompleted: {
162
loader.item.currentIndex = styledItem.selectedIndex;
163
moveToIndex(styledItem.selectedIndex);
169
visible: control.overlay
173
color: control.overlayColor
188
color: control.overlayColor