on xenial help sign in
Initial implementation of the move support
commitc732dccd6b7b1114a60e0b6b1511ac95776f481e authorAlbert Astals <albert.astals@canonical.com> dateFri 26 Sep 2014, 12:35 (12 years ago) parent04b04e7
4 files changed+136−51
qml/Dash/Dash.qml+3−1 qml/Dash/ScopesList.qml+3−1 qml/Dash/ScopesListCategory.qml+58−49 qml/Dash/ScopesListCategoryItem.qml+72
qml/Dash/Dash.qml+3−1
@@ -158,9 +158,11 @@ Showable {
158158 dashContent.currentScope.performQuery("scope://com.canonical.scopes.clickstore");
159159 }
160160 onRequestFavorite: {
161− // TODO This is not yet implemented in the backend
162161 scopes.setFavorite(scopeId, favorite);
163162 }
163+ onRequestFavoriteMoveTo: {
164+ scopes.moveFavoriteTo(scopeId, index);
165+ }
164166
165167 Binding {
166168 target: scopesList.scope
qml/Dash/ScopesList.qml+3−1
@@ -30,6 +30,7 @@ Item {
3030 signal backClicked()
3131 signal storeClicked()
3232 signal requestFavorite(string scopeId, bool favorite)
33+ signal requestFavoriteMoveTo(string scopeId, int index)
3334
3435 state: "browse"
3536
@@ -111,8 +112,9 @@ Item {
111112 }
112113 Connections {
113114 target: item
114− onRequestFavorite: root.requestFavorite(scopeId, favorite)
115+ onRequestFavorite: root.requestFavorite(scopeId, favorite);
115116 onRequestEditMode: root.state = "edit";
117+ onRequestScopeMoveTo: root.requestFavoriteMoveTo(scopeId, index);
116118 }
117119 }
118120 }
qml/Dash/ScopesListCategory.qml+58−49
@@ -15,7 +15,7 @@
1515 */
1616
1717import QtQuick 2.0
18−import Ubuntu.Components 1.1;
18+import Ubuntu.Components 1.1
1919import Dash 0.1
2020import "../Components/ListItems" as ListItems
2121
@@ -27,8 +27,11 @@ Item {
2727 property bool isFavoriteFeeds: false
2828 property bool editMode: false
2929
30+ visible: !editMode || isFavoriteFeeds
31+
3032 signal requestFavorite(string scopeId, bool favorite)
3133 signal requestEditMode()
34+ signal requestScopeMoveTo(string scopeId, int index)
3235
3336 implicitHeight: childrenRect.height
3437
@@ -43,10 +46,12 @@ Item {
4346 property var myTemplate: JSON.parse('{"card-layout":"horizontal","card-size":"small","category-layout":"grid","collapsed-rows":2}')
4447 property var myComponents: JSON.parse('{"art":{"aspect-ratio":1,"field":"art"},"title":{"field":"title"},"attributes":{}}')
4548
49+ readonly property double listItemHeight: units.gu(6)
50+
4651 ListView {
4752 id: list
4853
49− readonly property double targetHeight: model.count * units.gu(6)
54+ readonly property double targetHeight: model.count * listItemHeight
5055 clip: height != targetHeight
5156 height: targetHeight
5257 Behavior on height { enabled: visible; UbuntuNumberAnimation { } }
@@ -59,59 +64,63 @@ Item {
5964 delegate: Loader {
6065 asynchronous: true
6166 width: root.width
62− height: units.gu(6)
63− sourceComponent: MouseArea {
67+ height: listItemHeight
68+ sourceComponent: ScopesListCategoryItem {
6469 width: root.width
65− UbuntuShape {
66− id: shape
67− anchors {
68− left: parent.left
69− leftMargin: units.gu(1)
70− verticalCenter: parent.verticalCenter
71− }
72− width: units.gu(5)
73− height: units.gu(5)
74− image: Image {
75− source: model["art"] || ""
76− cache: true
77− fillMode: Image.PreserveAspectCrop
78− }
79− }
80− Label {
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
70+
71+ icon: model.art || ""
72+ text: model.title || ""
73+ showStar: model.scopeId != "clickscope"
74+
75+ onRequestFavorite: root.requestFavorite(model.scopeId, favorite);
76+ onPressAndHold: {
77+ if (!editMode) {
78+ root.requestEditMode();
79+ } else {
80+ dragItem.icon = icon;
81+ dragItem.text = text;
82+ dragItem.x = units.gu(1)
83+ dragItem.y = mapToItem(root, 0, 0).y + units.gu(1)
84+ drag.target = dragItem;
85+ dragItem.visible = true;
8886 }
89− text: model["title"] || ""
90− elide: Text.ElideRight
91− wrapMode: Text.Wrap
92− maximumLineCount: 1
93− verticalAlignment: Text.AlignHCenter
9487 }
95− Icon {
96− id: star
97− anchors {
98− right: parent.right
99− rightMargin: units.gu(1)
100− verticalCenter: parent.verticalCenter
101− }
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);
88+ onReleased: {
89+ if (dragItem.visible) {
90+ dragItem.visible = false;
91+ if (dragMarker.index != index && dragMarker.index != index + 1) {
92+ var targetIndex = dragMarker.index > index ? dragMarker.index - 1 : dragMarker.index;
93+ root.requestScopeMoveTo(model.scopeId, targetIndex);
94+ }
11095 }
11196 }
112−
113− onPressAndHold: root.requestEditMode();
11497 }
11598 }
11699 }
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+ }
117126}
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+}