on xenial help sign in
Document and simplify the %1 replacements of artShapeHolderCode
commit869d64b42249f6384bc3337ed2f15024422ce299 authorAlbert Astals <albert.astals@canonical.com> dateWed 7 May 2014, 13:49 (12 years ago) parentf66f9d3
4 files changed+19−15
plugins/Dash/CardCreator.js+16−12 tests/plugins/Dash/cardcreator/1.res+1−1 tests/plugins/Dash/cardcreator/3.res+1−1 tests/plugins/Dash/cardcreator/5.res+1−1
plugins/Dash/CardCreator.js+16−12
@@ -50,11 +50,14 @@ var backgroundLoaderCode = 'Loader {\n\
5050 } \n\
5151 }\n';
5252
53+// %1 is used as anchors of artShapeHolder
54+// %2 is used as image width
55+// %3 is used as image height
5356var artShapeHolderCode = 'Item { \n\
5457 id: artShapeHolder; \n\
5558 height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height; \n\
5659 width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width; \n\
57− %1 \n\
60+ anchors { %1 } \n\
5861 Loader { \n\
5962 id: artShapeLoader; \n\
6063 objectName: "artShapeLoader"; \n\
@@ -86,7 +89,8 @@ var artShapeHolderCode = 'Item { \n\
8689 asynchronous: root.asynchronous; \n\
8790 fillMode: components && components["art"]["fill-mode"] === "fit" ? Image.PreserveAspectFit: Image.PreserveAspectCrop; \n\
8891 readonly property real aspect: implicitWidth / implicitHeight; \n\
89− %2 \n\
92+ width: %2; \n\
93+ height: %3; \n\
9094 } \n\
9195 } \n\
9296 } \n\
@@ -262,26 +266,26 @@ function cardString(template, components) {
262266 if (hasArt) {
263267 code += 'readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);\n';
264268
265− var imageWidthHeightCode;
269+ var widthCode, heightCode;
266270 var anchors;
267271 if (isHorizontal) {
268− anchors = 'anchors.left: parent.left;';
272+ anchors = 'left: parent.left';
269273 if (hasMascot || hasTitle) {
270− imageWidthHeightCode = 'width: height * artShape.aspect; \n\
271− height: headerHeight;\n';
274+ widthCode = 'height * artShape.aspect'
275+ heightCode = 'headerHeight';
272276 } else {
273277 // This side of the else is a bit silly, who wants an horizontal layout without mascot and title?
274278 // So we define a "random" height of the image height + 2 gu for the margins
275− imageWidthHeightCode = 'width: height * artShape.aspect; \n\
276− height: units.gu(7.625)';
279+ widthCode = 'height * artShape.aspect'
280+ heightCode = 'units.gu(7.625)';
277281 }
278282 } else {
279− anchors = 'anchors.horizontalCenter: parent.horizontalCenter;';
280− imageWidthHeightCode = 'width: root.width; \n\
281− height: width / artShape.aspect;\n';
283+ anchors = 'horizontalCenter: parent.horizontalCenter;';
284+ widthCode = 'root.width'
285+ heightCode = 'width / artShape.aspect';
282286 }
283287
284− code += artShapeHolderCode.arg(anchors).arg(imageWidthHeightCode);
288+ code += artShapeHolderCode.arg(anchors).arg(widthCode).arg(heightCode);
285289 } else {
286290 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
287291 }
tests/plugins/Dash/cardcreator/1.res+1−1
@@ -16,7 +16,7 @@ Item {
1616 id: artShapeHolder;
1717 height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height;
1818 width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width;
19− anchors.horizontalCenter: parent.horizontalCenter;
19+ anchors { horizontalCenter: parent.horizontalCenter; }
2020
2121 Loader {
2222 id: artShapeLoader;
tests/plugins/Dash/cardcreator/3.res+1−1
@@ -16,7 +16,7 @@ Item {
1616 id: artShapeHolder;
1717 height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height;
1818 width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width;
19− anchors.horizontalCenter: parent.horizontalCenter;
19+ anchors { horizontalCenter: parent.horizontalCenter; }
2020
2121 Loader {
2222 id: artShapeLoader;
tests/plugins/Dash/cardcreator/5.res+1−1
@@ -16,7 +16,7 @@ Item {
1616 id: artShapeHolder;
1717 height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height;
1818 width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width;
19− anchors.horizontalCenter: parent.horizontalCenter;
19+ anchors { horizontalCenter: parent.horizontalCenter; }
2020
2121 Loader {
2222 id: artShapeLoader;