2
* Copyright (C) 2014 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU 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 General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
import Ubuntu.Components 1.1
20
import "../Components/ListItems" as ListItems
25
property alias model: list.model
26
property alias title: header.text
27
property var scopeStyle
28
property bool editMode: false
29
property bool isFavoritesFeed: false
30
property bool isAlsoInstalled: false
32
visible: !editMode || isFavoritesFeed
34
signal requestFavorite(string scopeId, bool favorite)
35
signal requestEditMode()
36
signal requestScopeMoveTo(string scopeId, int index)
37
signal requestActivate(var result)
39
implicitHeight: visible ? childrenRect.height : 0
45
color: scopeStyle ? scopeStyle.foreground : Theme.palette.normal.baseText
48
readonly property double listItemHeight: units.gu(6)
52
objectName: "scopesListCategoryInnerList"
54
readonly property double targetHeight: model.count * listItemHeight
55
clip: height != targetHeight
57
Behavior on height { enabled: visible; UbuntuNumberAnimation { } }
61
anchors.top: header.bottom
64
readonly property bool addDropHint: {
65
if (dragMarker.visible) {
66
if (dragItem.originalIndex > index) {
67
return dragMarker.index == index;
69
return dragMarker.index == index - 1;
77
height: listItemHeight + (addDropHint ? units.gu(2) : 0)
78
clip: height < listItemHeight
79
Behavior on height { enabled: visible; UbuntuNumberAnimation { } }
80
sourceComponent: ScopesListCategoryItem {
81
objectName: "delegate" + model.scopeId
84
topMargin: height > listItemHeight ? height - listItemHeight : 0
86
icon: model.art || model.mascot || ""
87
text: model.title || ""
88
subtext: model.subtitle || ""
89
showStar: model.scopeId !== "clickscope" && (root.isFavoritesFeed || root.isAlsoInstalled)
90
isFavorite: root.isFavoritesFeed
92
hideChildren: dragItem.loaderToShrink == loader
96
root.requestActivate(result);
101
root.requestEditMode();
104
onRequestFavorite: root.requestFavorite(model.scopeId, favorite);
107
handle.drag.target = dragItem;
108
handle.drag.maximumX = units.gu(1);
109
handle.drag.minimumX = units.gu(1);
110
handle.drag.minimumY = list.y - dragItem.height / 2;
111
handle.drag.maximumY = list.y + list.height - dragItem.height / 2
112
dragItem.icon = icon;
113
dragItem.text = text;
114
dragItem.subtext = subtext;
115
dragItem.originalY = mapToItem(root, 0, 0).y;
116
dragItem.originalIndex = index;
117
dragItem.y = dragItem.originalY;
118
dragItem.x = units.gu(1);
119
dragItem.visible = true;
120
dragItem.loaderToShrink = loader;
124
if (dragItem.visible) {
125
handle.drag.target = undefined;
126
dragItem.visible = false;
127
if (dragMarker.visible && dragMarker.index != index) {
128
root.requestScopeMoveTo(model.scopeId, dragMarker.index);
130
dragMarker.visible = false;
131
dragItem.loaderToShrink.height = listItemHeight;
132
dragItem.loaderToShrink = null;
139
ListItems.ThinDivider {
143
leftMargin: units.gu(1)
144
rightMargin: units.gu(1)
146
property int index: {
147
var i = Math.round((dragItem.y - list.y + dragItem.height/2) / listItemHeight);
149
if (i >= model.count - 1) i = model.count - 1;
152
y: list.y + index * listItemHeight + units.gu(1)
155
ScopesListCategoryItem {
158
property real originalY
159
property int originalIndex
160
property var loaderToShrink: null
162
objectName: "dragItem"
166
height: listItemHeight
170
if (!dragMarker.visible && Math.abs(y - originalY) > height / 2) {
171
dragMarker.visible = true;
172
loaderToShrink.height = 0;