on xenial help sign in
Document and simplify the %1 replacements of artShapeHolderCode
869d64bAlbert Astals
plugins/Dash/CardCreator.js+16−12
@@ -50,11 +50,14 @@ var backgroundLoaderCode = 'Loader {\n\
50 } \n\
50 } \n\
51 }\n';
51 }\n';
52
52
53+// %1 is used as anchors of artShapeHolder
54+// %2 is used as image width
55+// %3 is used as image height
53var artShapeHolderCode = 'Item { \n\
56var artShapeHolderCode = 'Item { \n\
54 id: artShapeHolder; \n\
57 id: artShapeHolder; \n\
55 height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height; \n\
58 height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height; \n\
56 width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width; \n\
59 width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width; \n\
57− %1 \n\
60+ anchors { %1 } \n\
58 Loader { \n\
61 Loader { \n\
59 id: artShapeLoader; \n\
62 id: artShapeLoader; \n\
60 objectName: "artShapeLoader"; \n\
63 objectName: "artShapeLoader"; \n\
@@ -86,7 +89,8 @@ var artShapeHolderCode = 'Item { \n\
86 asynchronous: root.asynchronous; \n\
89 asynchronous: root.asynchronous; \n\
87 fillMode: components && components["art"]["fill-mode"] === "fit" ? Image.PreserveAspectFit: Image.PreserveAspectCrop; \n\
90 fillMode: components && components["art"]["fill-mode"] === "fit" ? Image.PreserveAspectFit: Image.PreserveAspectCrop; \n\
88 readonly property real aspect: implicitWidth / implicitHeight; \n\
91 readonly property real aspect: implicitWidth / implicitHeight; \n\
89− %2 \n\
92+ width: %2; \n\
93+ height: %3; \n\
90 } \n\
94 } \n\
91 } \n\
95 } \n\
92 } \n\
96 } \n\
@@ -262,26 +266,26 @@ function cardString(template, components) {
262 if (hasArt) {
266 if (hasArt) {
263 code += 'readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);\n';
267 code += 'readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);\n';
264
268
265− var imageWidthHeightCode;
269+ var widthCode, heightCode;
266 var anchors;
270 var anchors;
267 if (isHorizontal) {
271 if (isHorizontal) {
268− anchors = 'anchors.left: parent.left;';
272+ anchors = 'left: parent.left';
269 if (hasMascot || hasTitle) {
273 if (hasMascot || hasTitle) {
270− imageWidthHeightCode = 'width: height * artShape.aspect; \n\
274+ widthCode = 'height * artShape.aspect'
271− height: headerHeight;\n';
275+ heightCode = 'headerHeight';
272 } else {
276 } else {
273 // This side of the else is a bit silly, who wants an horizontal layout without mascot and title?
277 // This side of the else is a bit silly, who wants an horizontal layout without mascot and title?
274 // So we define a "random" height of the image height + 2 gu for the margins
278 // So we define a "random" height of the image height + 2 gu for the margins
275− imageWidthHeightCode = 'width: height * artShape.aspect; \n\
279+ widthCode = 'height * artShape.aspect'
276− height: units.gu(7.625)';
280+ heightCode = 'units.gu(7.625)';
277 }
281 }
278 } else {
282 } else {
279− anchors = 'anchors.horizontalCenter: parent.horizontalCenter;';
283+ anchors = 'horizontalCenter: parent.horizontalCenter;';
280− imageWidthHeightCode = 'width: root.width; \n\
284+ widthCode = 'root.width'
281− height: width / artShape.aspect;\n';
285+ heightCode = 'width / artShape.aspect';
282 }
286 }
283
287
284− code += artShapeHolderCode.arg(anchors).arg(imageWidthHeightCode);
288+ code += artShapeHolderCode.arg(anchors).arg(widthCode).arg(heightCode);
285 } else {
289 } else {
286 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
290 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
287 }
291 }
tests/plugins/Dash/cardcreator/1.res+1−1
@@ -16,7 +16,7 @@ Item {
16 id: artShapeHolder;
16 id: artShapeHolder;
17 height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height;
17 height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height;
18 width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width;
18 width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width;
19− anchors.horizontalCenter: parent.horizontalCenter;
19+ anchors { horizontalCenter: parent.horizontalCenter; }
20
20
21 Loader {
21 Loader {
22 id: artShapeLoader;
22 id: artShapeLoader;
tests/plugins/Dash/cardcreator/3.res+1−1
@@ -16,7 +16,7 @@ Item {
16 id: artShapeHolder;
16 id: artShapeHolder;
17 height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height;
17 height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height;
18 width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width;
18 width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width;
19− anchors.horizontalCenter: parent.horizontalCenter;
19+ anchors { horizontalCenter: parent.horizontalCenter; }
20
20
21 Loader {
21 Loader {
22 id: artShapeLoader;
22 id: artShapeLoader;
tests/plugins/Dash/cardcreator/5.res+1−1
@@ -16,7 +16,7 @@ Item {
16 id: artShapeHolder;
16 id: artShapeHolder;
17 height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height;
17 height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height;
18 width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width;
18 width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width;
19− anchors.horizontalCenter: parent.horizontalCenter;
19+ anchors { horizontalCenter: parent.horizontalCenter; }
20
20
21 Loader {
21 Loader {
22 id: artShapeLoader;
22 id: artShapeLoader;