on xenial help sign in
Make so that fixedArtShapeSize actually fixes artShapeSize.
commitd232e39cbc8b22ad0d850fe5792473d2c86c6933 authorMichał Sawicz <michal.sawicz@canonical.com> dateMon 23 Jun 2014, 11:16 (12 years ago) parent3acc1949fa62d6
5 files changed+72−43
plugins/Dash/CardCreator.js+11−6 tests/plugins/Dash/cardcreator/1.res+13−8 tests/plugins/Dash/cardcreator/3.res+19−14 tests/plugins/Dash/cardcreator/5.res+20−15 tests/qmltests/Dash/tst_Card.qml+9
plugins/Dash/CardCreator.js+11−6
@@ -55,8 +55,8 @@ var kBackgroundLoaderCode = 'Loader {\n\
5555// %3 is used as image height
5656var kArtShapeHolderCode = 'Item { \n\
5757 id: artShapeHolder; \n\
58− height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height; \n\
59− width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width; \n\
58+ height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height; \n\
59+ width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width; \n\
6060 anchors { %1 } \n\
6161 Loader { \n\
6262 id: artShapeLoader; \n\
@@ -68,13 +68,18 @@ var kArtShapeHolderCode = 'Item { \n\
6868 id: artShape; \n\
6969 objectName: "artShape"; \n\
7070 radius: "medium"; \n\
71− readonly property real aspect: components !== undefined ? components["art"]["aspect-ratio"] : 1; \n\
71+ visible: image.status == Image.Ready; \n\
72+ readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1; \n\
73+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1; \n\
7274 readonly property bool aspectSmallerThanImageAspect: aspect < image.aspect; \n\
7375 Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; } \n\
7476 onAspectSmallerThanImageAspectChanged: updateWidthHeightBindings(); \n\
75− visible: image.status == Image.Ready; \n\
77+ Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); } \n\
7678 function updateWidthHeightBindings() { \n\
77− if (aspectSmallerThanImageAspect) { \n\
79+ if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) { \n\
80+ width = root.fixedArtShapeSize.width; \n\
81+ height = root.fixedArtShapeSize.height; \n\
82+ } else if (aspectSmallerThanImageAspect) { \n\
7883 width = Qt.binding(function() { return !visible ? 0 : image.width }); \n\
7984 height = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.height : width / image.aspect }); \n\
8085 } else { \n\
@@ -108,7 +113,7 @@ var kOverlayLoaderCode = 'Loader { \n\
108113 visible: showHeader && status == Loader.Ready; \n\
109114 sourceComponent: ShaderEffect { \n\
110115 id: overlay; \n\
111− height: fixedHeaderHeight != -1 ? fixedHeaderHeight + units.gu(1) * 2 : headerHeight; \n\
116+ height: fixedHeaderHeight > 0 ? fixedHeaderHeight + units.gu(1) * 2 : headerHeight; \n\
112117 opacity: 0.6; \n\
113118 property var source: ShaderEffectSource { \n\
114119 id: shaderSource; \n\
tests/plugins/Dash/cardcreator/1.res+13−8
@@ -16,8 +16,8 @@ onArtShapeBorderSourceChanged: { if (artShapeBorderSource !== undefined && artSh
1616readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
1717Item {
1818 id: artShapeHolder;
19− height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height;
20− width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width;
19+ height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height;
20+ width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width;
2121 anchors { horizontalCenter: parent.horizontalCenter; }
2222 Loader {
2323 id: artShapeLoader;
@@ -28,14 +28,19 @@ Item {
2828 sourceComponent: UbuntuShape {
2929 id: artShape;
3030 objectName: "artShape";
31− radius: "medium";
32− readonly property real aspect: components !== undefined ? components["art"]["aspect-ratio"] : 1;
33− readonly property bool aspectSmallerThanImageAspect: aspect < image.aspect;
34− Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; }
35− onAspectSmallerThanImageAspectChanged: updateWidthHeightBindings();
31+ radius: "medium";
3632 visible: image.status == Image.Ready;
33+ readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
34+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1;
35+ readonly property bool aspectSmallerThanImageAspect: aspect < image.aspect;
36+ Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; }
37+ onAspectSmallerThanImageAspectChanged: updateWidthHeightBindings();
38+ Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
3739 function updateWidthHeightBindings() {
38− if (aspectSmallerThanImageAspect) {
40+ if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) {
41+ width = root.fixedArtShapeSize.width;
42+ height = root.fixedArtShapeSize.height;
43+ } else if (aspectSmallerThanImageAspect) {
3944 width = Qt.binding(function() { return !visible ? 0 : image.width });
4045 height = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.height : width / image.aspect });
4146 } else {
tests/plugins/Dash/cardcreator/3.res+19−14
@@ -16,8 +16,8 @@ onArtShapeBorderSourceChanged: { if (artShapeBorderSource !== undefined && artSh
1616readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
1717Item {
1818 id: artShapeHolder;
19− height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height;
20− width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width;
19+ height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height;
20+ width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width;
2121 anchors { horizontalCenter: parent.horizontalCenter; }
2222 Loader {
2323 id: artShapeLoader;
@@ -29,19 +29,24 @@ Item {
2929 id: artShape;
3030 objectName: "artShape";
3131 radius: "medium";
32− readonly property real aspect: components !== undefined ? components["art"]["aspect-ratio"] : 1;
33− readonly property bool aspectSmallerThanImageAspect: aspect < image.aspect;
34− Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; }
35− onAspectSmallerThanImageAspectChanged: updateWidthHeightBindings();
3632 visible: image.status == Image.Ready;
37− function updateWidthHeightBindings() {
38− if (aspectSmallerThanImageAspect) {
39− width = Qt.binding(function() { return !visible ? 0 : image.width });
40− height = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.height : width / image.aspect });
41− } else {
42− width = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.width : height * image.aspect });
43− height = Qt.binding(function() { return !visible ? 0 : image.height });
44− }
33+ readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
34+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1;
35+ readonly property bool aspectSmallerThanImageAspect: aspect < image.aspect;
36+ Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; }
37+ onAspectSmallerThanImageAspectChanged: updateWidthHeightBindings();
38+ Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
39+ function updateWidthHeightBindings() {
40+ if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) {
41+ width = root.fixedArtShapeSize.width;
42+ height = root.fixedArtShapeSize.height;
43+ } else if (aspectSmallerThanImageAspect) {
44+ width = Qt.binding(function() { return !visible ? 0 : image.width });
45+ height = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.height : width / image.aspect });
46+ } else {
47+ width = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.width : height * image.aspect });
48+ height = Qt.binding(function() { return !visible ? 0 : image.height });
49+ }
4550 }
4651 image: Image {
4752 objectName: "artImage";
tests/plugins/Dash/cardcreator/5.res+20−15
@@ -16,8 +16,8 @@ onArtShapeBorderSourceChanged: { if (artShapeBorderSource !== undefined && artSh
1616readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
1717Item {
1818 id: artShapeHolder;
19− height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height;
20− width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width;
19+ height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height;
20+ width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width;
2121 anchors { horizontalCenter: parent.horizontalCenter; }
2222 Loader {
2323 id: artShapeLoader;
@@ -29,19 +29,24 @@ Item {
2929 id: artShape;
3030 objectName: "artShape";
3131 radius: "medium";
32− readonly property real aspect: components !== undefined ? components["art"]["aspect-ratio"] : 1;
33− readonly property bool aspectSmallerThanImageAspect: aspect < image.aspect;
34− Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; }
35− onAspectSmallerThanImageAspectChanged: updateWidthHeightBindings();
3632 visible: image.status == Image.Ready;
37− function updateWidthHeightBindings() {
38− if (aspectSmallerThanImageAspect) {
39− width = Qt.binding(function() { return !visible ? 0 : image.width });
40− height = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.height : width / image.aspect });
41− } else {
42− width = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.width : height * image.aspect });
43− height = Qt.binding(function() { return !visible ? 0 : image.height });
44− }
33+ readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
34+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1;
35+ readonly property bool aspectSmallerThanImageAspect: aspect < image.aspect;
36+ Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; }
37+ onAspectSmallerThanImageAspectChanged: updateWidthHeightBindings();
38+ Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
39+ function updateWidthHeightBindings() {
40+ if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) {
41+ width = root.fixedArtShapeSize.width;
42+ height = root.fixedArtShapeSize.height;
43+ } else if (aspectSmallerThanImageAspect) {
44+ width = Qt.binding(function() { return !visible ? 0 : image.width });
45+ height = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.height : width / image.aspect });
46+ } else {
47+ width = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.width : height * image.aspect });
48+ height = Qt.binding(function() { return !visible ? 0 : image.height });
49+ }
4550 }
4651 image: Image {
4752 objectName: "artImage";
@@ -68,7 +73,7 @@ Loader {
6873 visible: showHeader && status == Loader.Ready;
6974 sourceComponent: ShaderEffect {
7075 id: overlay;
71− height: fixedHeaderHeight != -1 ? fixedHeaderHeight + units.gu(1) * 2 : headerHeight;
76+ height: fixedHeaderHeight > 0 ? fixedHeaderHeight + units.gu(1) * 2 : headerHeight;
7277 opacity: 0.6;
7378 property var source: ShaderEffectSource {
7479 id: shaderSource;
tests/qmltests/Dash/tst_Card.qml+9
@@ -305,6 +305,15 @@ Rectangle {
305305 }
306306 }
307307
308+ function test_art_shape_fixed_size() {
309+ selector.selectedIndex = 6;
310+ card.fixedArtShapeSize = Qt.size( units.gu(8), units.gu(4) );
311+ waitForRendering(card);
312+ tryCompare(art, "width", units.gu(8));
313+ tryCompare(art, "height", units.gu(4));
314+ tryCompare(art, "fixedArtShapeSizeAspect", 2);
315+ }
316+
308317 function test_art_layout_data() {
309318 return [
310319 { tag: "Vertical", left: function() { return units.gu(1); }, index: 0},