on xenial help sign in
Remove "hacks" from GenericScopeView

Now the conditions for appScope are backed into CardTool and CardGrid allowing for the properties to be readonly

commit1f0f2c924e8896faa833176684a05bc0834642bd authorAlbert Astals Cid <albert.astals@canonical.com> dateFri 19 Aug 2016, 17:25 (10 years ago) parent9ffec52
3 files changed+55−59
qml/Dash/CardGrid.qml+3−4 qml/Dash/CardTool.qml+50−13 qml/Dash/GenericScopeView.qml+2−42
qml/Dash/CardGrid.qml+3−4
@@ -20,13 +20,12 @@ import "../Components"
2020DashRenderer {
2121 id: root
2222
23− readonly property real defaultMinimumHorizontalSpacing: units.gu(1)
2423 readonly property int collapsedRows: {
2524 if (!cardTool || !cardTool.template || typeof cardTool.template["collapsed-rows"] != "number") return 2;
2625 return cardTool.template["collapsed-rows"];
2726 }
28− property string backgroundShapeStyle: "inset";
29− property alias minimumHorizontalSpacing: grid.minimumHorizontalSpacing
27+ // ↓ This is the ubuntu store icon
28+ readonly property string backgroundShapeStyle: cardTool.isAppLikeScope && !cardTool.isAppLikeScopeAppCategory ? "shadow" : "inset"
3029
3130 expandedHeight: grid.totalContentHeight
3231 collapsedHeight: Math.min(grid.contentHeightForRows(collapsedRows, grid.cellHeight), expandedHeight)
@@ -46,7 +45,7 @@ DashRenderer {
4645 ResponsiveGridView {
4746 id: grid
4847 anchors.fill: parent
49− minimumHorizontalSpacing: root.defaultMinimumHorizontalSpacing
48+ minimumHorizontalSpacing: (cardTool.isAppLikeScopeAppCategory && cardTool.viewWidth >= units.gu(70)) ? units.gu(5) : units.gu(1)
5049 delegateWidth: cardTool.cardWidth
5150 delegateHeight: cardTool.cardHeight
5251 verticalSpacing: units.gu(1)
qml/Dash/CardTool.qml+50−13
@@ -41,11 +41,6 @@ Item {
4141 */
4242 property real viewWidth
4343
44− /*!
45− \brief Scaling factor of selected Carousel item.
46− */
47− readonly property real carouselSelectedItemScaleFactor: 1.38 // XXX assuming 1.38 carousel scaling factor for cards
48−
4944 /*!
5045 \brief Template supplied for the category.
5146 */
@@ -56,10 +51,25 @@ Item {
5651 */
5752 property var components
5853
54+ /*!
55+ \brief The Scope this cardTool is representing
56+ */
57+ property string scopeId
58+
59+ /*!
60+ \brief The Scope category this cardTool is representing
61+ */
62+ property string categoryId
63+
64+ /*!
65+ \brief Scaling factor of selected Carousel item.
66+ */
67+ readonly property real carouselSelectedItemScaleFactor: 1.38 // XXX assuming 1.38 carousel scaling factor for cards
68+
5969 /*!
6070 \brief The category layout for this card tool.
6171 */
62− property string categoryLayout: {
72+ readonly property string categoryLayout: {
6373 var layout = template["category-layout"];
6474
6575 // carousel fallback mode to grid
@@ -67,11 +77,19 @@ Item {
6777 return layout;
6878 }
6979
80+ readonly property bool isAppLikeScope: scopeId === "clickscope" || scopeId === "libertine-scope.ubuntu_libertine-scope"
81+ readonly property bool isAppLikeScopeAppCategory: ((scopeId === "clickscope" && (categoryId === "predefined" || categoryId === "local"))
82+ || (scopeId === "libertine-scope.ubuntu_libertine-scope" && categoryId !== "hint"))
7083
71− // Not readonly because gets overwritten from GenericScopeView in some cases
72− property string artShapeStyle: categoryLayout === "carousel" ? "shadow" : "inset"
84+ readonly property string artShapeStyle: {
85+ if (isAppLikeScope) {
86+ return isAppLikeScopeAppCategory ? "icon" : "flat";
87+ } else {
88+ return categoryLayout === "carousel" ? "shadow" : "inset"
89+ }
90+ }
7391
74− property var cardComponent: CardCreatorCache.getCardComponent(cardTool.template, cardTool.components, false, cardTool.artShapeStyle, cardTool.categoryLayout);
92+ readonly property var cardComponent: CardCreatorCache.getCardComponent(cardTool.template, cardTool.components, false, cardTool.artShapeStyle, cardTool.categoryLayout);
7593
7694 // FIXME: Saviq
7795 // Only way for the card below to actually be laid out completely.
@@ -85,7 +103,19 @@ Item {
85103
86104 If -1, should use implicit width of the actual card.
87105 */
88− property real cardWidth: {
106+ readonly property real cardWidth: {
107+ if (isAppLikeScopeAppCategory) {
108+ if (viewWidth > units.gu(45)) {
109+ if (viewWidth >= units.gu(70)) {
110+ return units.gu(11);
111+ } else {
112+ return units.gu(10);
113+ }
114+ } else {
115+ return units.gu(12);
116+ }
117+ }
118+
89119 switch (categoryLayout) {
90120 case "grid":
91121 case "vertical-journal":
@@ -142,12 +172,19 @@ Item {
142172 type:real \brief Height of the card's header.
143173 */
144174 readonly property int headerHeight: cardLoader.item ? cardLoader.item.headerHeight : 0
145− property size artShapeSize: cardLoader.item ? cardLoader.item.artShapeSize : Qt.size(0, 0)
175+
176+ readonly property size artShapeSize: {
177+ if (isAppLikeScopeAppCategory) {
178+ return Qt.size(units.gu(8), units.gu(7.5));
179+ } else {
180+ return cardLoader.item ? cardLoader.item.artShapeSize : Qt.size(0, 0)
181+ }
182+ }
146183
147184 QtObject {
148185 id: carouselTool
149186
150− property real minimumTileWidth: {
187+ readonly property real minimumTileWidth: {
151188 if (cardTool.viewWidth === undefined) return undefined;
152189 if (cardTool.viewWidth <= units.gu(40)) return units.gu(18);
153190 if (cardTool.viewWidth >= units.gu(128)) return units.gu(26);
@@ -156,7 +193,7 @@ Item {
156193
157194 readonly property real pathItemCount: 4.8457 /// (848 / 175) reference values
158195
159− property real realPathItemCount: {
196+ readonly property real realPathItemCount: {
160197 var scaledMinimumTileWidth = minimumTileWidth / cardTool.carouselSelectedItemScaleFactor;
161198 var tileWidth = Math.max(cardTool.viewWidth / pathItemCount, scaledMinimumTileWidth);
162199 return Math.min(cardTool.viewWidth / tileWidth, pathItemCount);
qml/Dash/GenericScopeView.qml+2−42
@@ -266,6 +266,8 @@ FocusScope {
266266 template: model.renderer
267267 components: model.components
268268 viewWidth: parent.width
269+ scopeId: scope ? scope.id : ""
270+ categoryId: baseItem.category
269271 }
270272
271273 onExpandableChanged: {
@@ -341,17 +343,6 @@ FocusScope {
341343 baseItem.expand(shouldExpand, false /*animate*/);
342344 }
343345 updateRanges();
344− clickScopeSizingHacks();
345− if (scope && (scope.id === "clickscope" || scope.id === "libertine-scope.ubuntu_libertine-scope")) {
346− if (isLibertineContainerCategory() || categoryId === "predefined" || categoryId === "local") {
347− cardTool.artShapeSize = Qt.binding(function() { return Qt.size(units.gu(8), units.gu(7.5)) });
348− cardTool.artShapeStyle = "icon";
349− } else {
350− // Should be ubuntu store icon
351− cardTool.artShapeStyle = "flat";
352− item.backgroundShapeStyle = "shadow";
353− }
354− }
355346 item.cardTool = cardTool;
356347 }
357348
@@ -360,36 +351,6 @@ FocusScope {
360351 scopeView.enableHeightBehaviorOnNextCreation = item.enableHeightBehaviorOnNextCreation;
361352 }
362353 }
363− // FIXME: directly connecting to onUnitsChanged cause a compile error:
364− // Cannot assign to non-existent property "onUnitsChanged"
365− // Until the units object is reworked to properly do all we need, let's go through a intermediate property
366− property int pxpgu: units.gu(1);
367− onPxpguChanged: clickScopeSizingHacks();
368−
369− // Returns true if the current category pertains to a Libertine container
370− function isLibertineContainerCategory() {
371− return scope && scope.id === "libertine-scope.ubuntu_libertine-scope" && categoryId !== "hint";
372− }
373−
374− function clickScopeSizingHacks() {
375− if (scope &&
376− ((scope.id === "clickscope" && (categoryId === "predefined" || categoryId === "local")) ||
377− isLibertineContainerCategory())) {
378− // Yeah, hackish :/
379− if (scopeView.width > units.gu(45)) {
380− if (scopeView.width >= units.gu(70)) {
381− cardTool.cardWidth = units.gu(11);
382− item.minimumHorizontalSpacing = units.gu(5);
383− return;
384− } else {
385− cardTool.cardWidth = units.gu(10);
386− }
387− } else {
388− cardTool.cardWidth = units.gu(12);
389− }
390− item.minimumHorizontalSpacing = item.defaultMinimumHorizontalSpacing;
391− }
392− }
393354
394355 Connections {
395356 target: rendererLoader.item
@@ -424,7 +385,6 @@ FocusScope {
424385 target: scopeView
425386 onIsCurrentChanged: rendererLoader.updateRanges();
426387 onVisibleToParentChanged: rendererLoader.updateRanges();
427− onWidthChanged: rendererLoader.clickScopeSizingHacks();
428388 }
429389 Connections {
430390 target: holdingList