on xenial help sign in
Hardcode art shape size for click scope local and predefined categories

While at it, drop the fillmode of cards Approved by: Michał Sawicz

commit4aee55348f0d7db933c6d9a12ac92aec206e1155 authorMichał Sawicz <michal.sawicz@canonical.com> dateWed 6 Aug 2014, 19:38 (12 years ago) parent9473462b3cfec7
17 files changed+36−62
plugins/Dash/CardCreator.js+2−8 qml/Dash/CardTool.qml+1−1 qml/Dash/GenericScopeView.qml+4 tests/plugins/Dash/cardcreator/1.res+4−10 tests/plugins/Dash/cardcreator/1.tst+1−1 tests/plugins/Dash/cardcreator/2.tst+1−1 tests/plugins/Dash/cardcreator/3.res+4−10 tests/plugins/Dash/cardcreator/3.tst+1−1 tests/plugins/Dash/cardcreator/4.tst+1−1 tests/plugins/Dash/cardcreator/5.res+6−12 tests/plugins/Dash/cardcreator/5.tst+1−1 tests/plugins/Dash/cardcreator/6.res+2−8 tests/plugins/Dash/cardcreator/6.tst+1−1 tests/plugins/Dash/cardcreator/7.tst+1−1 tests/qmltests/Dash/CardHelpers.js+1−2 tests/qmltests/Dash/tst_Card.qml+3−3 tests/qmltests/Dash/tst_GenericScopeView.qml+2−1
plugins/Dash/CardCreator.js+2−8
@@ -71,19 +71,14 @@ var kArtShapeHolderCode = 'Item { \n\
7171 visible: image.status == Image.Ready; \n\
7272 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1; \n\
7373 readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1; \n\
74− readonly property bool aspectSmallerThanImageAspect: aspect < image.aspect; \n\
7574 Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; } \n\
76− onAspectSmallerThanImageAspectChanged: updateWidthHeightBindings(); \n\
7775 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); } \n\
7876 function updateWidthHeightBindings() { \n\
7977 if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) { \n\
8078 width = root.fixedArtShapeSize.width; \n\
8179 height = root.fixedArtShapeSize.height; \n\
82− } else if (aspectSmallerThanImageAspect) { \n\
83− width = Qt.binding(function() { return !visible ? 0 : image.width }); \n\
84− height = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.height : width / image.aspect }); \n\
8580 } else { \n\
86− width = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.width : height * image.aspect }); \n\
81+ width = Qt.binding(function() { return !visible ? 0 : image.width }); \n\
8782 height = Qt.binding(function() { return !visible ? 0 : image.height }); \n\
8883 } \n\
8984 } \n\
@@ -92,8 +87,7 @@ var kArtShapeHolderCode = 'Item { \n\
9287 source: cardData && cardData["art"] || ""; \n\
9388 cache: true; \n\
9489 asynchronous: root.asynchronous; \n\
95− fillMode: components && components["art"]["fill-mode"] === "fit" ? Image.PreserveAspectFit: Image.PreserveAspectCrop; \n\
96− readonly property real aspect: implicitWidth / implicitHeight; \n\
90+ fillMode: Image.PreserveAspectCrop; \n\
9791 width: %2; \n\
9892 height: %3; \n\
9993 } \n\
qml/Dash/CardTool.qml+1−1
@@ -126,7 +126,7 @@ Item {
126126 type:real \brief Height of the card's header.
127127 */
128128 readonly property int headerHeight: cardLoader.item ? cardLoader.item.headerHeight : 0
129− readonly property size artShapeSize: cardLoader.item ? cardLoader.item.artShapeSize : 0
129+ property size artShapeSize: cardLoader.item ? cardLoader.item.artShapeSize : 0
130130
131131 /*!
132132 \brief Desired alignment of header components.
qml/Dash/GenericScopeView.qml+4
@@ -215,6 +215,10 @@ FocusScope {
215215 baseItem.expand(shouldExpand, false /*animate*/);
216216 }
217217 updateDelegateCreationRange();
218+ if (scope && scope.id === "clickscope" && (categoryId === "predefined" || categoryId === "local")) {
219+ // Yeah, hackish :/
220+ cardTool.artShapeSize = Qt.size(units.gu(8), units.gu(7.5));
221+ }
218222 item.cardTool = cardTool;
219223 }
220224
tests/plugins/Dash/cardcreator/1.res+4−10
@@ -33,20 +33,15 @@ Item {
3333 visible: image.status == Image.Ready;
3434 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
3535 readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1;
36− readonly property bool aspectSmallerThanImageAspect: aspect < image.aspect;
37− Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; }
38− onAspectSmallerThanImageAspectChanged: updateWidthHeightBindings();
36+ Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; }
3937 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
4038 function updateWidthHeightBindings() {
4139 if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) {
4240 width = root.fixedArtShapeSize.width;
4341 height = root.fixedArtShapeSize.height;
44− } else if (aspectSmallerThanImageAspect) {
45− width = Qt.binding(function() { return !visible ? 0 : image.width });
46− height = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.height : width / image.aspect });
4742 } else {
48− width = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.width : height * image.aspect });
49− height = Qt.binding(function() { return !visible ? 0 : image.height });
43+ width = Qt.binding(function() { return !visible ? 0 : image.width });
44+ height = Qt.binding(function() { return !visible ? 0 : image.height });
5045 }
5146 }
5247 image: Image {
@@ -54,8 +49,7 @@ Item {
5449 source: cardData && cardData["art"] || "";
5550 cache: true;
5651 asynchronous: root.asynchronous;
57− fillMode: components && components["art"]["fill-mode"] === "fit" ? Image.PreserveAspectFit: Image.PreserveAspectCrop;
58− readonly property real aspect: implicitWidth / implicitHeight;
52+ fillMode: Image.PreserveAspectCrop;
5953 width: root.width;
6054 height: width / artShape.aspect;
6155 }
tests/plugins/Dash/cardcreator/1.tst+1−1
@@ -1,3 +1,3 @@
11template: {"card-layout":"vertical","card-size":"small","category-layout":"grid","collapsed-rows":2}
2−components: {"art":{"aspect-ratio":1.6,"field":"art","fill-mode":"fit"},"title":{"field":"title"}}
2+components: {"art":{"aspect-ratio":1.6,"field":"art"},"title":{"field":"title"}}
33result: 1.res
tests/plugins/Dash/cardcreator/2.tst+1−1
@@ -1,3 +1,3 @@
11template: {"card-background":{"elements":["#E9E9E9"],"type":"color"},"card-layout":"vertical","card-size":"medium","category-layout":"grid","collapsed-rows":2}
2−components: {"art":{"aspect-ratio":1,"fill-mode":"crop"},"background":{"field":"background"},"mascot":{"field":"icon"},"subtitle":{"field":"author"},"title":{"field":"title"}}
2+components: {"art":{"aspect-ratio":1},"background":{"field":"background"},"mascot":{"field":"icon"},"subtitle":{"field":"author"},"title":{"field":"title"}}
33result: 2.res
tests/plugins/Dash/cardcreator/3.res+4−10
@@ -25,7 +25,7 @@ Item {
2525 objectName: "artShapeLoader";
2626 active: cardData && cardData["art"] || false;
2727 asynchronous: root.asynchronous;
28− visible: status == Loader.Ready;
28+ visible: status == Loader.Ready;
2929 sourceComponent: UbuntuShape {
3030 id: artShape;
3131 objectName: "artShape";
@@ -33,20 +33,15 @@ Item {
3333 visible: image.status == Image.Ready;
3434 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
3535 readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1;
36− readonly property bool aspectSmallerThanImageAspect: aspect < image.aspect;
3736 Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; }
38− onAspectSmallerThanImageAspectChanged: updateWidthHeightBindings();
3937 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
4038 function updateWidthHeightBindings() {
4139 if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) {
4240 width = root.fixedArtShapeSize.width;
4341 height = root.fixedArtShapeSize.height;
44− } else if (aspectSmallerThanImageAspect) {
45− width = Qt.binding(function() { return !visible ? 0 : image.width });
46− height = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.height : width / image.aspect });
4742 } else {
48− width = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.width : height * image.aspect });
49− height = Qt.binding(function() { return !visible ? 0 : image.height });
43+ width = Qt.binding(function() { return !visible ? 0 : image.width });
44+ height = Qt.binding(function() { return !visible ? 0 : image.height });
5045 }
5146 }
5247 image: Image {
@@ -54,8 +49,7 @@ Item {
5449 source: cardData && cardData["art"] || "";
5550 cache: true;
5651 asynchronous: root.asynchronous;
57− fillMode: components && components["art"]["fill-mode"] === "fit" ? Image.PreserveAspectFit: Image.PreserveAspectCrop;
58− readonly property real aspect: implicitWidth / implicitHeight;
52+ fillMode: Image.PreserveAspectCrop;
5953 width: root.width;
6054 height: width / artShape.aspect;
6155 }
tests/plugins/Dash/cardcreator/3.tst+1−1
@@ -1,3 +1,3 @@
11template: {"card-layout":"vertical","card-size":"small","category-layout":"grid","collapsed-rows":2}
2−components: {"art":{"aspect-ratio":0.75,"field":"art","fill-mode":"crop"},"subtitle":{"field":"price"},"title":{"field":"title"}}
2+components: {"art":{"aspect-ratio":0.75,"field":"art"},"subtitle":{"field":"price"},"title":{"field":"title"}}
33result: 3.res
tests/plugins/Dash/cardcreator/4.tst+1−1
@@ -1,3 +1,3 @@
11template: {"card-layout":"horizontal","card-size":"large","category-layout":"grid","collapsed-rows":2}
2−components: {"art":{"aspect-ratio":1,"fill-mode":"crop"},"mascot":{"field":"mascot"},"subtitle":{"field":"domain"},"title":{"field":"title"}}
2+components: {"art":{"aspect-ratio":1},"mascot":{"field":"mascot"},"subtitle":{"field":"domain"},"title":{"field":"title"}}
33result: 4.res
tests/plugins/Dash/cardcreator/5.res+6−12
@@ -25,7 +25,7 @@ Item {
2525 objectName: "artShapeLoader";
2626 active: cardData && cardData["art"] || false;
2727 asynchronous: root.asynchronous;
28− visible: status == Loader.Ready;
28+ visible: status == Loader.Ready;
2929 sourceComponent: UbuntuShape {
3030 id: artShape;
3131 objectName: "artShape";
@@ -33,20 +33,15 @@ Item {
3333 visible: image.status == Image.Ready;
3434 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
3535 readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1;
36− readonly property bool aspectSmallerThanImageAspect: aspect < image.aspect;
3736 Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; }
38− onAspectSmallerThanImageAspectChanged: updateWidthHeightBindings();
3937 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
4038 function updateWidthHeightBindings() {
4139 if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) {
4240 width = root.fixedArtShapeSize.width;
4341 height = root.fixedArtShapeSize.height;
44− } else if (aspectSmallerThanImageAspect) {
45− width = Qt.binding(function() { return !visible ? 0 : image.width });
46− height = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.height : width / image.aspect });
4742 } else {
48− width = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.width : height * image.aspect });
49− height = Qt.binding(function() { return !visible ? 0 : image.height });
43+ width = Qt.binding(function() { return !visible ? 0 : image.width });
44+ height = Qt.binding(function() { return !visible ? 0 : image.height });
5045 }
5146 }
5247 image: Image {
@@ -54,13 +49,12 @@ Item {
5449 source: cardData && cardData["art"] || "";
5550 cache: true;
5651 asynchronous: root.asynchronous;
57− fillMode: components && components["art"]["fill-mode"] === "fit" ? Image.PreserveAspectFit: Image.PreserveAspectCrop;
58− readonly property real aspect: implicitWidth / implicitHeight;
52+ fillMode: Image.PreserveAspectCrop;
5953 width: root.width;
6054 height: width / artShape.aspect;
6155 }
6256 }
63− }
57+ }
6458 }
6559Loader {
6660 id: overlayLoader;
@@ -69,7 +63,7 @@ Loader {
6963 right: artShapeHolder.right;
7064 bottom: artShapeHolder.bottom;
7165 }
72− active: artShapeLoader.active && artShapeLoader.item && artShapeLoader.item.image.status === Image.Ready || false;
66+ active: artShapeLoader.active && artShapeLoader.item && artShapeLoader.item.image.status === Image.Ready || false;
7367 asynchronous: root.asynchronous;
7468 visible: showHeader && status == Loader.Ready;
7569 sourceComponent: ShaderEffect {
tests/plugins/Dash/cardcreator/5.tst+1−1
@@ -1,3 +1,3 @@
11template: {"card-layout":"vertical","card-size":"medium","category-layout":"carousel","collapsed-rows":2,"overlay":true}
2−components: {"art":{"aspect-ratio":1,"field":"art","fill-mode":"crop"},"subtitle":{"field":"artist"},"title":{"field":"title"}}
2+components: {"art":{"aspect-ratio":1,"field":"art"},"subtitle":{"field":"artist"},"title":{"field":"title"}}
33result: 5.res
tests/plugins/Dash/cardcreator/6.res+2−8
@@ -33,19 +33,14 @@ Item {
3333 visible: image.status == Image.Ready;
3434 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
3535 readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1;
36− readonly property bool aspectSmallerThanImageAspect: aspect < image.aspect;
3736 Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; }
38− onAspectSmallerThanImageAspectChanged: updateWidthHeightBindings();
3937 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
4038 function updateWidthHeightBindings() {
4139 if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) {
4240 width = root.fixedArtShapeSize.width;
4341 height = root.fixedArtShapeSize.height;
44− } else if (aspectSmallerThanImageAspect) {
45− width = Qt.binding(function() { return !visible ? 0 : image.width });
46− height = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.height : width / image.aspect });
4742 } else {
48− width = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.width : height * image.aspect });
43+ width = Qt.binding(function() { return !visible ? 0 : image.width });
4944 height = Qt.binding(function() { return !visible ? 0 : image.height });
5045 }
5146 }
@@ -54,8 +49,7 @@ Item {
5449 source: cardData && cardData["art"] || "";
5550 cache: true;
5651 asynchronous: root.asynchronous;
57− fillMode: components && components["art"]["fill-mode"] === "fit" ? Image.PreserveAspectFit: Image.PreserveAspectCrop;
58− readonly property real aspect: implicitWidth / implicitHeight;
52+ fillMode: Image.PreserveAspectCrop;
5953 width: root.width;
6054 height: width / artShape.aspect;
6155 }
tests/plugins/Dash/cardcreator/6.tst+1−1
@@ -1,3 +1,3 @@
11template: {"card-layout":"vertical","card-size":"small","category-layout":"grid","collapsed-rows":2}
2−components: {"art":{"aspect-ratio":1.6,"field":"art","fill-mode":"fit"}}
2+components: {"art":{"aspect-ratio":1.6,"field":"art"}}
33result: 6.res
tests/plugins/Dash/cardcreator/7.tst+1−1
@@ -1,3 +1,3 @@
11template: {"card-background":{"elements":["#E9E9E9"],"type":"color"},"card-layout":"vertical","card-size":"medium","category-layout":"grid","collapsed-rows":2}
2−components: {"art":{"aspect-ratio":1,"fill-mode":"crop"},"background":{"field":"background"},"mascot":{"field":"icon"},"subtitle":{"field":"author"},"title":{"field":"title"},"attributes":{"field":"attributes","max-count":2}}
2+components: {"art":{"aspect-ratio":1},"background":{"field":"background"},"mascot":{"field":"icon"},"subtitle":{"field":"author"},"title":{"field":"title"},"attributes":{"field":"attributes","max-count":2}}
33result: 7.res
tests/qmltests/Dash/CardHelpers.js+1−2
@@ -31,8 +31,7 @@ var defaultLayout = ' \
3131 "components": { \
3232 "title": null, \
3333 "art": { \
34− "aspect-ratio": 1.0, \
35− "fill-mode": "crop" \
34+ "aspect-ratio": 1.0 \
3635 }, \
3736 "subtitle": null, \
3837 "overlayColor": null, \
tests/qmltests/Dash/tst_Card.qml+3−3
@@ -55,8 +55,8 @@ Rectangle {
5555 "layout": { "components": Helpers.update(JSON.parse(Helpers.fullMapping), { "art": { "aspect-ratio": 2 } }) }
5656 },
5757 {
58− "name": "Art, title - fitted",
59− "layout": { "components": Helpers.update(JSON.parse(Helpers.fullMapping), { "art": { "fill-mode": "fit" } }) }
58+ "name": "Art, title - tall",
59+ "layout": { "components": Helpers.update(JSON.parse(Helpers.fullMapping), { "art": { "aspect-ratio": 0.7 } }) }
6060 },
6161 {
6262 "name": "Art, header, summary - horizontal",
@@ -269,7 +269,7 @@ Rectangle {
269269 { tag: "Small", width: units.gu(12), index: 1 },
270270 { tag: "Large", width: units.gu(38), index: 2 },
271271 { tag: "Wide", height: units.gu(19), size: "large", index: 3 },
272− { tag: "Fit", height: units.gu(38), size: "large", width: units.gu(19), index: 4 },
272+ { tag: "Tall", height: units.gu(38) / 0.7, size: "large", width: units.gu(38), index: 4 },
273273 { tag: "VerticalWidth", width: function() { return headerRow.width + units.gu(1) * 2 }, index: 0 },
274274 { tag: "HorizontalHeight", height: function() { return headerRow.height + units.gu(1) * 2 }, index: 5 },
275275 { tag: "HorizontalWidth", width: function() { return headerRow.x - units.gu(1) }, index: 5 },
tests/qmltests/Dash/tst_GenericScopeView.qml+2−1
@@ -129,8 +129,9 @@ Item {
129129 var initialHeight = category.height;
130130 mouseClick(seeAll, seeAll.width / 2, seeAll.height / 2);
131131 verify(category.expanded);
132− tryCompareFunction(function() { return category.height > initialHeight; }, true);
132+ tryCompare(category, "height", category.item.expandedHeight + seeAll.height);
133133
134+ waitForRendering(seeAll);
134135 mouseClick(seeAll, seeAll.width / 2, seeAll.height / 2);
135136 verify(!category.expanded);
136137 }