on xenial help sign in
Initial implementation of the move support
c732dccAlbert Astals
qml/Dash/Dash.qml+3−1
@@ -158,9 +158,11 @@ Showable {
158 dashContent.currentScope.performQuery("scope://com.canonical.scopes.clickstore");
158 dashContent.currentScope.performQuery("scope://com.canonical.scopes.clickstore");
159 }
159 }
160 onRequestFavorite: {
160 onRequestFavorite: {
161− // TODO This is not yet implemented in the backend
162 scopes.setFavorite(scopeId, favorite);
161 scopes.setFavorite(scopeId, favorite);
163 }
162 }
163+ onRequestFavoriteMoveTo: {
164+ scopes.moveFavoriteTo(scopeId, index);
165+ }
164
166
165 Binding {
167 Binding {
166 target: scopesList.scope
168 target: scopesList.scope
qml/Dash/ScopesList.qml+3−1
@@ -30,6 +30,7 @@ Item {
30 signal backClicked()
30 signal backClicked()
31 signal storeClicked()
31 signal storeClicked()
32 signal requestFavorite(string scopeId, bool favorite)
32 signal requestFavorite(string scopeId, bool favorite)
33+ signal requestFavoriteMoveTo(string scopeId, int index)
33
34
34 state: "browse"
35 state: "browse"
35
36
@@ -111,8 +112,9 @@ Item {
111 }
112 }
112 Connections {
113 Connections {
113 target: item
114 target: item
114− onRequestFavorite: root.requestFavorite(scopeId, favorite)
115+ onRequestFavorite: root.requestFavorite(scopeId, favorite);
115 onRequestEditMode: root.state = "edit";
116 onRequestEditMode: root.state = "edit";
117+ onRequestScopeMoveTo: root.requestFavoriteMoveTo(scopeId, index);
116 }
118 }
117 }
119 }
118 }
120 }
qml/Dash/ScopesListCategory.qml+58−49
@@ -15,7 +15,7 @@
15 */
15 */
16
16
17import QtQuick 2.0
17import QtQuick 2.0
18−import Ubuntu.Components 1.1;
18+import Ubuntu.Components 1.1
19import Dash 0.1
19import Dash 0.1
20import "../Components/ListItems" as ListItems
20import "../Components/ListItems" as ListItems
21
21
@@ -27,8 +27,11 @@ Item {
27 property bool isFavoriteFeeds: false
27 property bool isFavoriteFeeds: false
28 property bool editMode: false
28 property bool editMode: false
29
29
30+ visible: !editMode || isFavoriteFeeds
31+
30 signal requestFavorite(string scopeId, bool favorite)
32 signal requestFavorite(string scopeId, bool favorite)
31 signal requestEditMode()
33 signal requestEditMode()
34+ signal requestScopeMoveTo(string scopeId, int index)
32
35
33 implicitHeight: childrenRect.height
36 implicitHeight: childrenRect.height
34
37
@@ -43,10 +46,12 @@ Item {
43 property var myTemplate: JSON.parse('{"card-layout":"horizontal","card-size":"small","category-layout":"grid","collapsed-rows":2}')
46 property var myTemplate: JSON.parse('{"card-layout":"horizontal","card-size":"small","category-layout":"grid","collapsed-rows":2}')
44 property var myComponents: JSON.parse('{"art":{"aspect-ratio":1,"field":"art"},"title":{"field":"title"},"attributes":{}}')
47 property var myComponents: JSON.parse('{"art":{"aspect-ratio":1,"field":"art"},"title":{"field":"title"},"attributes":{}}')
45
48
49+ readonly property double listItemHeight: units.gu(6)
50+
46 ListView {
51 ListView {
47 id: list
52 id: list
48
53
49− readonly property double targetHeight: model.count * units.gu(6)
54+ readonly property double targetHeight: model.count * listItemHeight
50 clip: height != targetHeight
55 clip: height != targetHeight
51 height: targetHeight
56 height: targetHeight
52 Behavior on height { enabled: visible; UbuntuNumberAnimation { } }
57 Behavior on height { enabled: visible; UbuntuNumberAnimation { } }
@@ -59,59 +64,63 @@ Item {
59 delegate: Loader {
64 delegate: Loader {
60 asynchronous: true
65 asynchronous: true
61 width: root.width
66 width: root.width
62− height: units.gu(6)
67+ height: listItemHeight
63− sourceComponent: MouseArea {
68+ sourceComponent: ScopesListCategoryItem {
64 width: root.width
69 width: root.width
65− UbuntuShape {
70+
66− id: shape
71+ icon: model.art || ""
67− anchors {
72+ text: model.title || ""
68− left: parent.left
73+ showStar: model.scopeId != "clickscope"
69− leftMargin: units.gu(1)
74+
70− verticalCenter: parent.verticalCenter
75+ onRequestFavorite: root.requestFavorite(model.scopeId, favorite);
71− }
76+ onPressAndHold: {
72− width: units.gu(5)
77+ if (!editMode) {
73− height: units.gu(5)
78+ root.requestEditMode();
74− image: Image {
79+ } else {
75− source: model["art"] || ""
80+ dragItem.icon = icon;
76− cache: true
81+ dragItem.text = text;
77− fillMode: Image.PreserveAspectCrop
82+ dragItem.x = units.gu(1)
78− }
83+ dragItem.y = mapToItem(root, 0, 0).y + units.gu(1)
79− }
84+ drag.target = dragItem;
80− Label {
85+ dragItem.visible = true;
81− id: titleLabel
82− anchors {
83− left: shape.right
84− leftMargin: units.gu(1)
85− right: star.right
86− rightMargin: units.gu(1)
87− verticalCenter: parent.verticalCenter
88 }
86 }
89− text: model["title"] || ""
90− elide: Text.ElideRight
91− wrapMode: Text.Wrap
92− maximumLineCount: 1
93− verticalAlignment: Text.AlignHCenter
94 }
87 }
95− Icon {
88+ onReleased: {
96− id: star
89+ if (dragItem.visible) {
97− anchors {
90+ dragItem.visible = false;
98− right: parent.right
91+ if (dragMarker.index != index && dragMarker.index != index + 1) {
99− rightMargin: units.gu(1)
92+ var targetIndex = dragMarker.index > index ? dragMarker.index - 1 : dragMarker.index;
100− verticalCenter: parent.verticalCenter
93+ root.requestScopeMoveTo(model.scopeId, targetIndex);
101− }
94+ }
102− height: units.gu(2)
103− width: units.gu(2)
104− visible: model.scopeId != "clickscope" && (isFavoriteFeeds || !editMode)
105− // TODO is view-grid-symbolic what we really want here? Looks good but seems semantically wrong
106− source: editMode ? "image://theme/view-grid-symbolic" : isFavoriteFeeds ? "image://theme/starred" : "image://theme/non-starred"
107− MouseArea {
108− anchors.fill: parent
109− onClicked: root.requestFavorite(model.scopeId, !isFavoriteFeeds);
110 }
95 }
111 }
96 }
112−
113− onPressAndHold: root.requestEditMode();
114 }
97 }
115 }
98 }
116 }
99 }
100+
101+ Rectangle {
102+ id: dragMarker
103+ color: "black"
104+ opacity: 0.3
105+ height: units.dp(2)
106+ width: root.width
107+ visible: dragItem.visible
108+ property int index: {
109+ var i = Math.round((dragItem.y - list.y) / listItemHeight);
110+ if (i <= 0) i = 1;
111+ if (i >= model.count) i = model.count;
112+ return i;
113+ }
114+ y: list.y + index * listItemHeight
115+ }
116+
117+ ScopesListCategoryItem {
118+ id: dragItem
119+ objectName: "dragItem"
120+ visible: false
121+ showStar: false
122+ width: root.width
123+ height: listItemHeight
124+ opacity: 0.9
125+ }
117}
126}
qml/Dash/ScopesListCategoryItem.qmlnew file+72
@@ -0,0 +1,72 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
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.
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 General Public License for more details.
12+ *
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/>.
15+ */
16+
17+import QtQuick 2.0
18+import Ubuntu.Components 1.1
19+
20+MouseArea {
21+ signal requestFavorite(string scopeId, bool favorite)
22+
23+ property alias icon: shapeImage.source
24+ property alias text: titleLabel.text
25+ property alias showStar: star.visible
26+
27+ UbuntuShape {
28+ id: shape
29+ anchors {
30+ left: parent.left
31+ leftMargin: units.gu(1)
32+ verticalCenter: parent.verticalCenter
33+ }
34+ width: units.gu(5)
35+ height: units.gu(5)
36+ image: Image {
37+ id: shapeImage
38+ cache: true
39+ fillMode: Image.PreserveAspectCrop
40+ }
41+ }
42+ Label {
43+ id: titleLabel
44+ anchors {
45+ left: shape.right
46+ leftMargin: units.gu(1)
47+ right: star.right
48+ rightMargin: units.gu(1)
49+ verticalCenter: parent.verticalCenter
50+ }
51+ elide: Text.ElideRight
52+ wrapMode: Text.Wrap
53+ maximumLineCount: 1
54+ verticalAlignment: Text.AlignHCenter
55+ }
56+ Icon {
57+ id: star
58+ anchors {
59+ right: parent.right
60+ rightMargin: units.gu(1)
61+ verticalCenter: parent.verticalCenter
62+ }
63+ height: units.gu(2)
64+ width: units.gu(2)
65+ // TODO is view-grid-symbolic what we really want here? Looks good but seems semantically wrong
66+ source: editMode ? "image://theme/view-grid-symbolic" : isFavoriteFeeds ? "image://theme/starred" : "image://theme/non-starred"
67+ MouseArea {
68+ anchors.fill: parent
69+ onClicked: root.requestFavorite(model.scopeId, !isFavoriteFeeds);
70+ }
71+ }
72+}