on xenial help sign in
CardTool carousel
commitc9bc6422436b0be51c1094c7595a7d55c5815d10 authorAndrea Cimitan <andrea.cimitan@gmail.com> dateThu 6 Mar 2014, 12:45 (13 years ago) parent8851f0e
5 files changed+94−24
qml/Dash/CardTool.qml+51−8 qml/Dash/DashRenderer.qml+5 qml/Dash/GenericScopeView.qml+18−1 tests/qmltests/Dash/tst_CardTool.qml+20 tests/qmltests/Dash/tst_GenericScopeView.qml−15
qml/Dash/CardTool.qml+51−8
@@ -28,20 +28,47 @@ import QtQuick 2.0
2828
2929Item {
3030 id: cardTool
31+
32+ /*!
33+ type:int \brief number of cards.
34+ */
35+ property int count
36+
37+ /*!
38+ type:real \brief width of the category view.
39+ */
40+ property real viewWidth
41+
42+ /*!
43+ type:real \brief Scaling factor of selected Carousel item.
44+ */
45+ readonly property real carouselSelectedItemScaleFactor: 1.38 // XXX assuming 1.38 carousel scaling factor for cards
46+
3147 /*!
3248 \brief Template supplied for the category.
3349 */
3450 property var template
3551
52+ /*!
53+ \brief Tool component for Carousel.
54+ */
55+ property var carouselTool
56+
3657 /*!
3758 \brief Component mapping supplied for the category.
3859 */
3960 property var components
4061
4162 /*!
42− \brief Width of the view, based on which carousel width is calculated.
63+ type:string \brief The category layout for this card tool.
4364 */
44− property var viewWidth
65+ property string categoryLayout: {
66+ var layout = template["category-layout"];
67+
68+ // carousel fallback mode to grid
69+ if (layout === "carousel" && count <= Math.ceil(carouselTool.realPathItemCount)) layout = "grid";
70+ return layout;
71+ }
4572
4673 // FIXME: Saviq
4774 // Only way for the card below to actually be laid out completely.
@@ -56,7 +83,7 @@ Item {
5683 If undefined, should use implicit width of the actual card.
5784 */
5885 readonly property var cardWidth: {
59− switch (template !== undefined && template["category-layout"]) {
86+ switch (categoryLayout) {
6087 case "grid":
6188 case "vertical-journal":
6289 if (template["card-layout"] === "horizontal") return units.gu(38);
@@ -66,10 +93,7 @@ Item {
6693 }
6794 return units.gu(18.5);
6895 case "carousel":
69− if (viewWidth === undefined) return undefined
70− if (viewWidth <= units.gu(40)) return units.gu(18)
71− if (viewWidth >= units.gu(128)) return units.gu(26)
72− return units.gu(18 + Math.round((viewWidth - units.gu(40))/ units.gu(11)))
96+ return carouselTool.minimumTileWidth;
7397 case undefined:
7498 case "organic-grid":
7599 case "journal":
@@ -84,7 +108,7 @@ Item {
84108 If undefined, should use implicit height of the actual card.
85109 */
86110 readonly property var cardHeight: {
87− switch (template !== undefined && template["category-layout"]) {
111+ switch (categoryLayout) {
88112 case "journal":
89113 if (template["card-size"] >= 12 && template["card-size"] <= 38) return units.gu(template["card-size"]);
90114 return units.gu(18.5);
@@ -123,6 +147,25 @@ Item {
123147 return (template["card-layout"] === "horizontal") ? Text.AlignLeft : Text.AlignHCenter;
124148 }
125149
150+ QtObject {
151+ id: carouselTool
152+
153+ property real minimumTileWidth: {
154+ if (cardTool.viewWidth === undefined) return undefined;
155+ if (cardTool.viewWidth <= units.gu(40)) return units.gu(18);
156+ if (cardTool.viewWidth >= units.gu(128)) return units.gu(26);
157+ return units.gu(18 + Math.round((cardTool.viewWidth - units.gu(40)) / units.gu(11)));
158+ }
159+
160+ readonly property real pathItemCount: 4.8457 /// (848 / 175) reference values
161+
162+ property real realPathItemCount: {
163+ var scaledMinimumTileWidth = minimumTileWidth / cardTool.carouselSelectedItemScaleFactor;
164+ var tileWidth = Math.max(cardTool.viewWidth / pathItemCount, scaledMinimumTileWidth);
165+ return Math.min(cardTool.viewWidth / tileWidth, pathItemCount);
166+ }
167+ }
168+
126169 Card {
127170 id: card
128171 objectName: "card"
qml/Dash/DashRenderer.qml+5
@@ -50,6 +50,11 @@ Item {
5050 // The model to renderer
5151 property var model
5252
53+ /*
54+ \brief CardTool component.
55+ */
56+ property var cardTool
57+
5358 /// Emitted when the user clicked on an item
5459 /// @param index is the index of the clicked item
5560 /// @param itemY is y of the clicked delegate
qml/Dash/GenericScopeView.qml+18−1
@@ -139,6 +139,15 @@ FocusScope {
139139 readonly property string category: categoryId
140140 readonly property var item: rendererLoader.item
141141
142+ CardTool {
143+ id: cardTool
144+
145+ count: results.count
146+ template: model.renderer
147+ components: model.components
148+ viewWidth: parent.width
149+ }
150+
142151 Loader {
143152 id: rendererLoader
144153 anchors {
@@ -147,7 +156,14 @@ FocusScope {
147156 right: parent.right
148157 }
149158
150− source: getRenderer(model.renderer, model.contentType, model.rendererHint, results)
159+ source: {
160+ switch (cardTool.categoryLayout) {
161+ case "carousel": return "CardCarousel.qml";
162+ case "running-apps": return "Apps/RunningApplicationsGrid.qml";
163+ case "grid":
164+ default: return "CardFilterGrid.qml";
165+ }
166+ }
151167
152168 onLoaded: {
153169 if (item.enableHeightBehavior !== undefined && item.enableHeightBehaviorOnNextCreation !== undefined) {
@@ -170,6 +186,7 @@ FocusScope {
170186 }
171187 }
172188 updateDelegateCreationRange();
189+ item.cardTool = cardTool;
173190 }
174191
175192 Component.onDestruction: {
tests/qmltests/Dash/tst_CardTool.qml+20
@@ -93,6 +93,7 @@ Rectangle {
9393 CardTool {
9494 id: cardTool
9595
96+ count: 8
9697 template: Helpers.update(JSON.parse(Helpers.defaultLayout), Helpers.tryParse(layoutArea.text, layoutError))['template'];
9798 components: Helpers.update(JSON.parse(Helpers.defaultLayout), Helpers.tryParse(layoutArea.text, layoutError))['components'];
9899 viewWidth: units.gu(Math.round(widthSlider.value))
@@ -343,5 +344,24 @@ Rectangle {
343344 tryCompare(cardTool, data.property, data.value);
344345 }
345346 }
347+
348+ function test_categoryLayout_data() {
349+ return [
350+ { tag: "Default Grid", layout_index: 0, count: 2, viewWidth: units.gu(40), layout: "grid" },
351+ { tag: "Long carousel", layout_index: 4, count: 6, viewWidth: units.gu(140), layout: "carousel" },
352+ { tag: "Long carousel fallback", layout_index: 4, count: 5, viewWidth: units.gu(140), layout: "grid" },
353+ { tag: "Short carousel", layout_index: 4, count: 4, viewWidth: units.gu(30), layout: "carousel" },
354+ { tag: "Short carousel fallback", layout_index: 4, count: 3, viewWidth: units.gu(30), layout: "grid" },
355+ { tag: "Journal", layout_index: 2, count: 8, viewWidth: units.gu(30), layout: "journal" }
356+ ]
357+ }
358+
359+ function test_categoryLayout(data) {
360+ selector.selectedIndex = 0;
361+ layoutSelector.selectedIndex = data.layout_index;
362+ cardTool.viewWidth = data.viewWidth;
363+ cardTool.count = data.count;
364+ compare(cardTool.categoryLayout, data.layout);
365+ }
346366 }
347367}
tests/qmltests/Dash/tst_GenericScopeView.qml−15
@@ -300,21 +300,6 @@ Item {
300300 tryCompare(category, "filtered", true);
301301 }
302302
303− function test_getRendererCarouselGridFallback() {
304− var rendererId = "carousel"
305− var contentType = ""
306− var rendererHint = ""
307− var results = new Object()
308−
309− results.count = 7
310− var renderer = genericScopeView.getRenderer(rendererId, contentType, rendererHint, results)
311− compare(renderer, "Generic/GenericCarousel.qml")
312−
313− results.count = 6
314− renderer = genericScopeView.getRenderer(rendererId, contentType, rendererHint, results)
315− compare(renderer, "Generic/GenericFilterGrid.qml")
316− }
317−
318303 function test_showPreviewCarousel() {
319304 tryCompareFunction(function() { return findChild(genericScopeView, "carouselDelegate") != null; }, true);
320305 var tile = findChild(genericScopeView, "carouselDelegate");