2 * Copyright (C) 2014,2015 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.3
19 import Ubuntu.Components.ListItems 1.3 as ListItems
21 import "../Components"
26 property alias model: list.model
27 property alias title: header.text
28 property var scopeStyle
29 property bool editMode: false
30 property bool isFavoritesFeed: false
31 property bool isAlsoInstalled: false
33 visible: !editMode || isFavoritesFeed
35 signal itemDragging(bool dragging, var dragItem)
36 signal requestFavorite(string scopeId, bool favorite)
37 signal requestEditMode()
38 signal requestScopeMoveTo(string scopeId, int index)
39 signal requestActivate(var result)
40 signal requestRestore(string scopeId)
42 implicitHeight: visible ? childrenRect.height : 0
48 color: scopeStyle ? scopeStyle.foreground : theme.palette.normal.baseText
51 readonly property double listItemHeight: units.gu(6)
55 objectName: "scopesListCategoryInnerList"
57 readonly property double targetHeight: model.count * listItemHeight
58 clip: height != targetHeight
60 Behavior on height { enabled: visible; UbuntuNumberAnimation { } }
64 anchors.top: header.bottom
67 readonly property bool addDropHint: {
68 if (dragMarker.visible) {
69 if (dragItem.originalIndex > index) {
70 return dragMarker.index == index;
72 return dragMarker.index == index - 1;
80 height: listItemHeight + (addDropHint ? units.gu(2) : 0)
81 clip: height < listItemHeight
82 Behavior on height { enabled: visible; UbuntuNumberAnimation { } }
83 sourceComponent: ScopesListCategoryItem {
84 objectName: "delegate" + model.scopeId
87 topMargin: height > listItemHeight ? height - listItemHeight : 0
89 icon: model.art || model.mascot || ""
90 text: model.title || ""
91 subtext: model.subtitle || ""
92 showStar: root.isFavoritesFeed || root.isAlsoInstalled
93 isFavorite: root.isFavoritesFeed
95 hideChildren: dragItem.loaderToShrink == loader
99 if (root.isFavoritesFeed)
100 root.requestRestore(model.scopeId);
102 root.requestActivate(result);
107 root.requestEditMode();
110 onRequestFavorite: root.requestFavorite(model.scopeId, favorite);
113 root.itemDragging(true, dragItem);
114 handle.drag.target = dragItem;
115 handle.drag.maximumX = units.gu(1);
116 handle.drag.minimumX = units.gu(1);
117 handle.drag.minimumY = list.y - dragItem.height / 2;
118 handle.drag.maximumY = list.y + list.height - dragItem.height / 2
119 dragItem.icon = icon;
120 dragItem.text = text;
121 dragItem.subtext = subtext;
122 dragItem.originalY = mapToItem(root, 0, 0).y;
123 dragItem.originalIndex = index;
124 dragItem.y = dragItem.originalY;
125 dragItem.x = units.gu(1);
126 dragItem.visible = true;
127 dragItem.loaderToShrink = loader;
131 root.itemDragging(false, dragItem);
132 if (dragItem.visible) {
133 handle.drag.target = undefined;
134 dragItem.visible = false;
135 if (dragMarker.visible && dragMarker.index != index) {
136 root.requestScopeMoveTo(model.scopeId, dragMarker.index);
138 dragMarker.visible = false;
139 dragItem.loaderToShrink.height = listItemHeight;
140 dragItem.loaderToShrink = null;
147 ListItems.ThinDivider {
151 leftMargin: units.gu(1)
152 rightMargin: units.gu(1)
154 property int index: {
155 var i = Math.round((dragItem.y - list.y + dragItem.height/2) / listItemHeight);
157 if (i >= model.count - 1) i = model.count - 1;
160 y: list.y + index * listItemHeight + units.gu(1)
163 ScopesListCategoryItem {
166 property real originalY
167 property int originalIndex
168 property var loaderToShrink: null
170 objectName: "dragItem"
174 height: listItemHeight
178 if (!dragMarker.visible && Math.abs(y - originalY) > height / 2) {
179 dragMarker.visible = true;
180 loaderToShrink.height = 0;