on xenial help sign in
Let GenericScope supports loading different renderers.
commitd6b88d241d08e900ae70faed5e270051036102b9 authorYing-Chun Liu <paul.liu@canonical.com> dateTue 16 Jul 2013, 22:11 (13 years ago) parent5a4e317
4 files changed+195−42
Components/Carousel.qml+38−1 Dash/Generic/GenericCarousel.qml+57 Dash/Generic/GenericFilterGrid.qml+59 Dash/GenericScopeView.qml+41−41
Components/Carousel.qml+38−1
@@ -52,6 +52,12 @@ Item {
5252 /// @param itemY is y of the clicked delegate
5353 signal clicked(int index, var delegateItem, real itemY)
5454
55+ /// Emitted when the user pressAndHold on an item
56+ /// @param index is the index of the clicked item
57+ /// @param delegateItem is the clicked component/delegate itself
58+ /// @param itemY is y of the clicked delegate
59+ signal pressAndHold(int index, var delegateItem, real itemY)
60+
5561 implicitHeight: listView.tileHeight * selectedItemScaleFactor
5662
5763 /* Basic idea behind the carousel effect is to move the items of the delegates (compacting /stuffing them).
@@ -159,6 +165,30 @@ Item {
159165 newContentXAnimation.start()
160166 }
161167
168+ function itemPressAndHold(index, delegateItem) {
169+ var x = CarouselJS.getXFromContinuousIndex(index,
170+ realWidth,
171+ realContentWidth,
172+ tileWidth,
173+ gapToMiddlePhase,
174+ gapToEndPhase,
175+ carousel.drawBuffer)
176+
177+ if (Math.abs(x - contentX) < 1) {
178+ /* We're pressAndHold the selected item and
179+ we're in the neighbourhood of radius 1 pixel from it.
180+ Let's emit the pressAndHold signal. */
181+ carousel.pressAndHold(index, delegateItem, delegateItem.y)
182+ return
183+ }
184+
185+ stepAnimation.stop()
186+ newContentXAnimation.stop()
187+
188+ newContentX = x
189+ newContentXAnimation.start()
190+ }
191+
162192 onMovementStarted: {
163193 stepAnimation.stop()
164194 newContentXAnimation.stop()
@@ -279,7 +309,14 @@ Item {
279309
280310 anchors.fill: parent
281311
282− onClicked: listView.itemClicked(index, item)
312+ onClicked: {
313+ listView.itemClicked(index, item)
314+ }
315+
316+ onPressAndHold: {
317+ listView.itemPressAndHold(index, item)
318+ }
319+
283320 }
284321 }
285322 }
Dash/Generic/GenericCarousel.qmlnew file+57
@@ -0,0 +1,57 @@
1+/*
2+ * Copyright (C) 2013 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 0.1
19+import "../../Components"
20+
21+Carousel {
22+ id: videosCarousel
23+
24+ tileAspectRatio: 198 / 288
25+ minimumTileWidth: units.gu(13)
26+ itemComponent: carouselDelegateVideo
27+ selectedItemScaleFactor: 1.14
28+ cacheBuffer: 1404 // 18px * 13gu * 6
29+ height: implicitHeight + units.gu(6)
30+
31+ Component {
32+ id: carouselDelegateVideo
33+
34+ BaseCarouselDelegate {
35+ id: item
36+
37+ UbuntuShape {
38+ anchors.fill: parent
39+ radius: "medium"
40+ borderSource: ""
41+ image: Image {
42+ asynchronous: true
43+ sourceSize { width: item.width; height: item.height }
44+ source: model ? model.icon : ""
45+ }
46+ }
47+
48+ BorderImage {
49+ anchors.centerIn: parent
50+ opacity: 0.6
51+ source: "../../Components/graphics/non-selected.sci"
52+ width: parent.width + units.gu(1.5)
53+ height: parent.height + units.gu(1.5)
54+ }
55+ }
56+ }
57+}
Dash/Generic/GenericFilterGrid.qmlnew file+59
@@ -0,0 +1,59 @@
1+/*
2+ * Copyright (C) 2013 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 "../../Components"
19+import "../../Components/IconUtil.js" as IconUtil
20+
21+FilterGrid {
22+ id: filtergrid
23+
24+ filter: false
25+ minimumHorizontalSpacing: units.gu(0.5)
26+ delegateWidth: units.gu(11)
27+ delegateHeight: units.gu(18)
28+ verticalSpacing: units.gu(2)
29+
30+ readonly property int iconWidth: (width / columns) * 0.8
31+ readonly property int iconHeight: iconWidth * 16 / 11
32+
33+ signal clicked(int index, var delegateItem, real itemY)
34+ signal pressAndHold(int index, var delegateItem, real itemY)
35+
36+ delegate: Tile {
37+ id: tile
38+ objectName: "delegate" + index
39+ width: filtergrid.cellWidth
40+ height: filtergrid.cellHeight
41+ text: model.title
42+ imageWidth: filtergrid.iconWidth
43+ imageHeight: filtergrid.iconHeight
44+
45+ source: IconUtil.from_gicon(model.icon)
46+
47+ fillMode: Image.PreserveAspectCrop
48+
49+ onClicked: {
50+ var data = { model: model }
51+ filtergrid.clicked(index, data, tile.y)
52+ }
53+
54+ onPressAndHold: {
55+ var data = { model: model }
56+ filtergrid.pressAndHold(index, data, tile.y)
57+ }
58+ }
59+}
Dash/GenericScopeView.qml+41−41
@@ -56,53 +56,45 @@ ScopeView {
5656 delegate: ListItems.Base {
5757 highlightWhenPressed: false
5858
59− FilterGrid {
60− id: filtergrid
61− model: results
62−
59+ Loader {
60+ id: rendererLoader
6361 anchors {
6462 top: parent.top
6563 left: parent.left
6664 right: parent.right
6765 }
6866
69− filter: false
70− minimumHorizontalSpacing: units.gu(0.5)
71− delegateWidth: units.gu(11)
72− delegateHeight: units.gu(18)
73− verticalSpacing: units.gu(2)
74−
75− delegate: Tile {
76− width: filtergrid.cellWidth
77− height: filtergrid.cellHeight
78− text: title
79− imageWidth: units.gu(11)
80− imageHeight: units.gu(16)
81−
82− source: IconUtil.from_gicon(icon)
83−
84− MouseArea {
85− anchors {
86− fill: parent
87− }
88− onClicked: {
89− mouse.accepted = true
90− effect.positionPx = mapToItem(categoryView, 0, 0).y
91− scopeView.scope.activate(uri, icon,
92− category, 0,
93− mimetype, title,
94− comment, dndUri,
95− metadata)
96− }
97− onPressAndHold: {
98− mouse.accepted = true
99− effect.positionPx = mapToItem(categoryView, 0, 0).y
100− scopeView.scope.preview(uri, icon,
101− category, 0,
102− mimetype, title,
103− comment, dndUri,
104− metadata)
105− }
67+ source: getRenderer(model.renderer)
68+
69+ onLoaded: {
70+ item.model = results
71+ }
72+
73+ Connections {
74+ target: rendererLoader.item
75+ onClicked: {
76+ effect.positionPx = mapToItem(categoryView, 0, itemY).y
77+ scopeView.scope.activate(delegateItem.model.uri,
78+ delegateItem.model.icon,
79+ delegateItem.model.category,
80+ 0,
81+ delegateItem.model.mimetype,
82+ delegateItem.model.title,
83+ delegateItem.model.comment,
84+ delegateItem.model.dndUri,
85+ delegateItem.model.metadata)
86+ }
87+ onPressAndHold: {
88+ effect.positionPx = mapToItem(categoryView, 0, itemY).y
89+ scopeView.scope.preview( delegateItem.model.uri,
90+ delegateItem.model.icon,
91+ delegateItem.model.category,
92+ 0,
93+ delegateItem.model.mimetype,
94+ delegateItem.model.title,
95+ delegateItem.model.comment,
96+ delegateItem.model.dndUri,
97+ delegateItem.model.metadata)
10698 }
10799 }
108100 }
@@ -122,6 +114,14 @@ ScopeView {
122114 }
123115 }
124116
117+ function getRenderer(rendererId) {
118+ switch (rendererId) {
119+ case "grid": return "Generic/GenericFilterGrid.qml"
120+ case "carousel": return "Generic/GenericCarousel.qml"
121+ default: return "Generic/GenericFilterGrid.qml"
122+ }
123+ }
124+
125125 OpenEffect {
126126 id: effect
127127 anchors {