on xenial help sign in
Merged readonly properties to cardtool
commitc7c9a058912a1ddc4a6dd927e09f4f908edaec21 authorAndrea Cimitan <andrea.cimitan@gmail.com> dateWed 12 Oct 2016, 15:29 (10 years ago) parente1821f0ba8ad93
3 files changed+66−62
qml/Dash/CardGrid.qml+4−4 qml/Dash/CardTool.qml+60−16 qml/Dash/GenericScopeView.qml+2−42
qml/Dash/CardGrid.qml+4−4
@@ -20,13 +20,13 @@ 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: "flat";
29− property alias minimumHorizontalSpacing: grid.minimumHorizontalSpacing
27+
28+ // ↓ This is the ubuntu store icon
29+ readonly property string backgroundShapeStyle: cardTool.isAppLikeScope && !cardTool.isAppLikeScopeAppCategory ? "shadow" : "flat"
3030
3131 expandedHeight: grid.totalContentHeight
3232 collapsedHeight: Math.min(grid.contentHeightForRows(collapsedRows, grid.cellHeight), expandedHeight)
@@ -46,7 +46,7 @@ DashRenderer {
4646 ResponsiveGridView {
4747 id: grid
4848 anchors.fill: parent
49− minimumHorizontalSpacing: root.defaultMinimumHorizontalSpacing
49+ minimumHorizontalSpacing: (cardTool.isAppLikeScopeAppCategory && cardTool.isWideView) ? units.gu(5) : units.gu(1)
5050 delegateWidth: cardTool.cardWidth
5151 delegateHeight: cardTool.cardHeight
5252 verticalSpacing: units.gu(1)
qml/Dash/CardTool.qml+60−16
@@ -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,9 +77,17 @@ 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" : "flat"
84+ readonly property string artShapeStyle: {
85+ if (isAppLikeScope) {
86+ return isAppLikeScopeAppCategory ? "icon" : "flat";
87+ } else {
88+ return categoryLayout === "carousel" ? "shadow" : "flat"
89+ }
90+ }
7391
7492 // FIXME ? This seems like it should not be needed, but on Qt 5.4 + phone
7593 // we are doing unneeded calls to getCardComponent with artShapeStyle and categoryLayout being empty
@@ -90,12 +108,31 @@ Item {
90108 height: 0
91109 clip: true
92110
111+ // We have 3 view "widths"
112+ // narrow <= 45gu
113+ // normal
114+ // wide >= 70gu
115+ readonly property bool isWideView: viewWidth >= units.gu(70)
116+ readonly property bool isNarrowView: viewWidth <= units.gu(45)
117+
93118 /*!
94119 type:real \brief Width to be enforced on the card in this configuration.
95120
96121 If -1, should use implicit width of the actual card.
97122 */
98− property real cardWidth: {
123+ readonly property real cardWidth: {
124+ if (isAppLikeScopeAppCategory) {
125+ if (!isNarrowView) {
126+ if (isWideView) {
127+ return units.gu(11);
128+ } else {
129+ return units.gu(10);
130+ }
131+ } else {
132+ return units.gu(12);
133+ }
134+ }
135+
99136 switch (categoryLayout) {
100137 case "grid":
101138 case "vertical-journal":
@@ -103,16 +140,16 @@ Item {
103140 if (template["card-layout"] === "horizontal") size = "large";
104141 switch (size) {
105142 case "small": {
106− if (viewWidth <= units.gu(45)) return units.gu(12);
143+ if (isNarrowView) return units.gu(12);
107144 else return units.gu(14);
108145 }
109146 case "large": {
110− if (viewWidth >= units.gu(70)) return units.gu(42);
147+ if (isWideView) return units.gu(42);
111148 else return viewWidth - units.gu(2);
112149 }
113150 }
114− if (viewWidth <= units.gu(45)) return units.gu(18);
115− else if (viewWidth >= units.gu(70)) return units.gu(20);
151+ if (isNarrowView) return units.gu(18);
152+ else if (isWideView) return units.gu(20);
116153 else return units.gu(23);
117154 case "carousel":
118155 case "horizontal-list":
@@ -152,12 +189,19 @@ Item {
152189 type:real \brief Height of the card's header.
153190 */
154191 readonly property int headerHeight: cardLoader.item ? cardLoader.item.headerHeight : 0
155− property size artShapeSize: cardLoader.item ? cardLoader.item.artShapeSize : Qt.size(0, 0)
192+
193+ readonly property size artShapeSize: {
194+ if (isAppLikeScopeAppCategory) {
195+ return Qt.size(units.gu(8), units.gu(7.5));
196+ } else {
197+ return cardLoader.item ? cardLoader.item.artShapeSize : Qt.size(0, 0)
198+ }
199+ }
156200
157201 QtObject {
158202 id: carouselTool
159203
160− property real minimumTileWidth: {
204+ readonly property real minimumTileWidth: {
161205 if (cardTool.viewWidth === undefined) return undefined;
162206 if (cardTool.viewWidth <= units.gu(40)) return units.gu(18);
163207 if (cardTool.viewWidth >= units.gu(128)) return units.gu(26);
@@ -166,7 +210,7 @@ Item {
166210
167211 readonly property real pathItemCount: 4.8457 /// (848 / 175) reference values
168212
169− property real realPathItemCount: {
213+ readonly property real realPathItemCount: {
170214 var scaledMinimumTileWidth = minimumTileWidth / cardTool.carouselSelectedItemScaleFactor;
171215 var tileWidth = Math.max(cardTool.viewWidth / pathItemCount, scaledMinimumTileWidth);
172216 return Math.min(cardTool.viewWidth / tileWidth, pathItemCount);
qml/Dash/GenericScopeView.qml+2−42
@@ -267,6 +267,8 @@ FocusScope {
267267 template: model.renderer
268268 components: model.components
269269 viewWidth: parent.width
270+ scopeId: scope ? scope.id : ""
271+ categoryId: baseItem.category
270272 }
271273
272274 onExpandableChanged: {
@@ -342,17 +344,6 @@ FocusScope {
342344 baseItem.expand(shouldExpand, false /*animate*/);
343345 }
344346 updateRanges();
345− clickScopeSizingHacks();
346− if (scope && (scope.id === "clickscope" || scope.id === "libertine-scope.ubuntu_libertine-scope")) {
347− if (isLibertineContainerCategory() || categoryId === "predefined" || categoryId === "local") {
348− cardTool.artShapeSize = Qt.binding(function() { return Qt.size(units.gu(8), units.gu(7.5)) });
349− cardTool.artShapeStyle = "icon";
350− } else {
351− // Should be ubuntu store icon
352− cardTool.artShapeStyle = "flat";
353− item.backgroundShapeStyle = "shadow";
354− }
355− }
356347 item.cardTool = cardTool;
357348 }
358349
@@ -361,36 +352,6 @@ FocusScope {
361352 scopeView.enableHeightBehaviorOnNextCreation = item.enableHeightBehaviorOnNextCreation;
362353 }
363354 }
364− // FIXME: directly connecting to onUnitsChanged cause a compile error:
365− // Cannot assign to non-existent property "onUnitsChanged"
366− // Until the units object is reworked to properly do all we need, let's go through a intermediate property
367− property int pxpgu: units.gu(1);
368− onPxpguChanged: clickScopeSizingHacks();
369−
370− // Returns true if the current category pertains to a Libertine container
371− function isLibertineContainerCategory() {
372− return scope && scope.id === "libertine-scope.ubuntu_libertine-scope" && categoryId !== "hint";
373− }
374−
375− function clickScopeSizingHacks() {
376− if (scope &&
377− ((scope.id === "clickscope" && (categoryId === "predefined" || categoryId === "local")) ||
378− isLibertineContainerCategory())) {
379− // Yeah, hackish :/
380− if (scopeView.width > units.gu(45)) {
381− if (scopeView.width >= units.gu(70)) {
382− cardTool.cardWidth = units.gu(11);
383− item.minimumHorizontalSpacing = units.gu(5);
384− return;
385− } else {
386− cardTool.cardWidth = units.gu(10);
387− }
388− } else {
389− cardTool.cardWidth = units.gu(12);
390− }
391− item.minimumHorizontalSpacing = item.defaultMinimumHorizontalSpacing;
392− }
393− }
394355
395356 Connections {
396357 target: rendererLoader.item
@@ -425,7 +386,6 @@ FocusScope {
425386 target: scopeView
426387 onIsCurrentChanged: rendererLoader.updateRanges();
427388 onVisibleToParentChanged: rendererLoader.updateRanges();
428− onWidthChanged: rendererLoader.clickScopeSizingHacks();
429389 }
430390 Connections {
431391 target: holdingList