on xenial help sign in
document and narrow the rest of substitutions
commit95a3764b39c82ded028558801e0d4478b6e1f287 authorAlbert Astals <albert.astals@canonical.com> dateWed 7 May 2014, 15:31 (12 years ago) parentbb88dd4
6 files changed+122−91
plugins/Dash/CardCreator.js+85−49 tests/plugins/Dash/cardcreator/1.res+4−6 tests/plugins/Dash/cardcreator/2.res+8−8 tests/plugins/Dash/cardcreator/3.res+4−6 tests/plugins/Dash/cardcreator/4.res+13−11 tests/plugins/Dash/cardcreator/5.res+8−11
plugins/Dash/CardCreator.js+85−49
@@ -16,7 +16,7 @@
1616
1717.pragma library
1818
19−var backgroundLoaderCode = 'Loader {\n\
19+var kBackgroundLoaderCode = 'Loader {\n\
2020 id: backgroundLoader; \n\
2121 objectName: "backgroundLoader"; \n\
2222 anchors.fill: parent; \n\
@@ -53,7 +53,7 @@ var backgroundLoaderCode = 'Loader {\n\
5353// %1 is used as anchors of artShapeHolder
5454// %2 is used as image width
5555// %3 is used as image height
56−var artShapeHolderCode = 'Item { \n\
56+var kArtShapeHolderCode = 'Item { \n\
5757 id: artShapeHolder; \n\
5858 height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height; \n\
5959 width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width; \n\
@@ -96,7 +96,7 @@ var artShapeHolderCode = 'Item { \n\
9696 } \n\
9797 }\n';
9898
99−var overlayLoaderCode = 'Loader { \n\
99+var kOverlayLoaderCode = 'Loader { \n\
100100 id: overlayLoader; \n\
101101 anchors { \n\
102102 left: artShapeHolder.left; \n\
@@ -137,21 +137,46 @@ var overlayLoaderCode = 'Loader { \n\
137137 } \n\
138138 }\n';
139139
140−var headerRowCode = 'Row { \n\
140+// %1 is used as anchors of row
141+// %2 is used as first child of the row
142+// %3 is used as second child of the row
143+var kHeaderRow2Code = 'Row { \n\
141144 id: row; \n\
142145 objectName: "outerRow"; \n\
143146 property real margins: units.gu(1); \n\
144147 spacing: margins; \n\
145− %1 \n\
146− %2 \n\
148+ anchors { %1 } \n\
147149 anchors.right: parent.right; \n\
148150 anchors.margins: margins;\n\
149− %3 \n\
151+ data: [ %2\n\
152+ ,\n\
153+ %3 \n\
154+ ] \n\
155+ }\n';
156+
157+// %1 is used as anchors of row
158+// %2 is used as first child of the row
159+// %3 is used as second child of the row
160+// %4 is used as third child of the row
161+var kHeaderRow3Code = 'Row { \n\
162+ id: row; \n\
163+ objectName: "outerRow"; \n\
164+ property real margins: units.gu(1); \n\
165+ spacing: margins; \n\
166+ anchors { %1 } \n\
167+ anchors.right: parent.right; \n\
168+ anchors.margins: margins;\n\
169+ data: [ %2\n\
170+ ,\n\
171+ %3 \n\
172+ ,\n\
173+ %4 \n\
174+ ] \n\
150175 }\n';
151176
152177// %1 is used as first child of the column
153178// %2 is used as second child of the column
154−var headerColumnCode = 'Column { \n\
179+var kHeaderColumnCode = 'Column { \n\
155180 anchors.verticalCenter: parent.verticalCenter; \n\
156181 spacing: units.dp(2); \n\
157182 width: parent.width - x;\n\
@@ -161,7 +186,8 @@ var headerColumnCode = 'Column { \n\
161186 ] \n\
162187 }\n';
163188
164−var mascotShapeLoaderCode = 'Loader { \n\
189+// %1 is used as anchors of mascotShapeLoader
190+var kMascotShapeLoaderCode = 'Loader { \n\
165191 id: mascotShapeLoader; \n\
166192 objectName: "mascotShapeLoader"; \n\
167193 asynchronous: root.asynchronous; \n\
@@ -170,13 +196,15 @@ var mascotShapeLoaderCode = 'Loader { \n\
170196 width: units.gu(6); \n\
171197 height: units.gu(5.625); \n\
172198 sourceComponent: UbuntuShape { image: mascotImage } \n\
173− %1 \n\
199+ anchors { %1 } \n\
174200 }\n';
175201
176−var mascotImageCode = 'Image { \n\
202+// %1 is used as anchors of mascotImage
203+// %2 is used as visible of mascotImage
204+var kMascotImageCode = 'Image { \n\
177205 id: mascotImage; \n\
178206 objectName: "mascotImage"; \n\
179− %1 \n\
207+ anchors { %1 } \n\
180208 readonly property int maxSize: Math.max(width, height) * 4; \n\
181209 source: cardData && cardData["mascot"]; \n\
182210 width: units.gu(6); \n\
@@ -188,10 +216,13 @@ var mascotImageCode = 'Image { \n\
188216 visible: %2; \n\
189217 }\n';
190218
191−var titleLabelCode = 'Label { \n\
219+// %1 is used as anchors of titleLabel
220+// %1 is used as color of titleLabel
221+// %3 is used as extra condition for visible of titleLabel
222+var kTitleLabelCode = 'Label { \n\
192223 id: titleLabel; \n\
193224 objectName: "titleLabel"; \n\
194− %1 \n\
225+ anchors { %1 } \n\
195226 elide: Text.ElideRight; \n\
196227 fontSize: "small"; \n\
197228 wrapMode: Text.Wrap; \n\
@@ -206,7 +237,7 @@ var titleLabelCode = 'Label { \n\
206237
207238// %1 is used as anchors of subtitleLabel
208239// %2 is used as color of subtitleLabel
209−var subtitleLabelCode = 'Label { \n\
240+var kSubtitleLabelCode = 'Label { \n\
210241 id: subtitleLabel; \n\
211242 objectName: "subtitleLabel"; \n\
212243 anchors { %1 } \n\
@@ -223,7 +254,7 @@ var subtitleLabelCode = 'Label { \n\
223254// %1 is used as top anchor of summary
224255// %2 is used as topMargin anchor of summary
225256// %3 is used as color of summary
226−var summaryLabelCode = 'Label { \n\
257+var kSummaryLabelCode = 'Label { \n\
227258 id: summary; \n\
228259 objectName: "summaryLabel"; \n\
229260 anchors { \n\
@@ -270,7 +301,7 @@ function cardString(template, components) {
270301 var hasHeaderRow = hasMascot && hasTitle;
271302
272303 if (hasBackground) {
273− code += backgroundLoaderCode;
304+ code += kBackgroundLoaderCode;
274305 }
275306
276307 if (hasArt) {
@@ -295,41 +326,41 @@ function cardString(template, components) {
295326 heightCode = 'width / artShape.aspect';
296327 }
297328
298− code += artShapeHolderCode.arg(anchors).arg(widthCode).arg(heightCode);
329+ code += kArtShapeHolderCode.arg(anchors).arg(widthCode).arg(heightCode);
299330 } else {
300331 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
301332 }
302333
303334 if (headerAsOverlay) {
304− code += overlayLoaderCode;
335+ code += kOverlayLoaderCode;
305336 }
306337
307338 var headerVerticalAnchors;
308339 if (headerAsOverlay) {
309− headerVerticalAnchors = 'anchors.bottom: artShapeHolder.bottom; \n\
310− anchors.bottomMargin: units.gu(1);\n';
340+ headerVerticalAnchors = 'bottom: artShapeHolder.bottom; \n\
341+ bottomMargin: units.gu(1);\n';
311342 } else {
312343 if (hasArt) {
313344 if (isHorizontal) {
314− headerVerticalAnchors = 'anchors.top: artShapeHolder.top; \n\
315− anchors.topMargin: units.gu(1);\n';
345+ headerVerticalAnchors = 'top: artShapeHolder.top; \n\
346+ topMargin: units.gu(1);\n';
316347 } else {
317− headerVerticalAnchors = 'anchors.top: artShapeHolder.bottom; \n\
318− anchors.topMargin: units.gu(1);\n';
348+ headerVerticalAnchors = 'top: artShapeHolder.bottom; \n\
349+ topMargin: units.gu(1);\n';
319350 }
320351 } else {
321− headerVerticalAnchors = 'anchors.top: parent.top; \n\
322− anchors.topMargin: units.gu(1);\n';
352+ headerVerticalAnchors = 'top: parent.top; \n\
353+ topMargin: units.gu(1);\n';
323354 }
324355 }
325356 var headerLeftAnchor;
326357 var headerLeftAnchorHasMagin = false;
327358 if (isHorizontal && hasArt) {
328− headerLeftAnchor = 'anchors.left: artShapeHolder.right; \n\
329− anchors.leftMargin: units.gu(1);\n';
359+ headerLeftAnchor = 'left: artShapeHolder.right; \n\
360+ leftMargin: units.gu(1);\n';
330361 headerLeftAnchorHasMagin = true;
331362 } else {
332− headerLeftAnchor = 'anchors.left: parent.left;\n';
363+ headerLeftAnchor = 'left: parent.left;\n';
333364 }
334365
335366 if (hasHeaderRow) {
@@ -344,6 +375,7 @@ function cardString(template, components) {
344375 code += 'readonly property int headerHeight: 0;\n'
345376 }
346377
378+ var mascotShapeCode = "";
347379 var mascotCode = "";
348380 if (hasMascot) {
349381 var useMascotShape = !hasBackground && !headerAsOverlay;
@@ -352,18 +384,18 @@ function cardString(template, components) {
352384 anchors += headerLeftAnchor;
353385 anchors += headerVerticalAnchors;
354386 if (!headerLeftAnchorHasMagin) {
355− anchors += 'anchors.leftMargin: units.gu(1);\n'
387+ anchors += 'leftMargin: units.gu(1);\n'
356388 }
357389 } else {
358− anchors = "anchors.verticalCenter: parent.verticalCenter;"
390+ anchors = "verticalCenter: parent.verticalCenter;"
359391 }
360392
361393 if (useMascotShape) {
362− mascotCode += mascotShapeLoaderCode.arg(anchors);
394+ mascotShapeCode = kMascotShapeLoaderCode.arg(anchors);
363395 }
364396
365397 var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
366− mascotCode += mascotImageCode.arg(anchors).arg(mascotImageVisible);
398+ mascotCode = kMascotImageCode.arg(anchors).arg(mascotImageVisible);
367399 }
368400
369401 var summaryColorWithBackground = 'backgroundLoader.active && backgroundLoader.item && backgroundLoader.item.luminance < 0.7 ? "white" : "grey"';
@@ -385,22 +417,22 @@ function cardString(template, components) {
385417 var subtitleAnchors;
386418 if (hasMascot && hasSubtitle) {
387419 // Using row + column
388− titleAnchors = 'anchors { left: parent.left; right: parent.right }\n';
389− subtitleAnchors = 'left: parent.left; right: parent.right';
420+ titleAnchors = 'left: parent.left; right: parent.right';
421+ subtitleAnchors = titleAnchors;
390422 } else if (hasMascot) {
391423 // Using row + label
392− titleAnchors = 'anchors.verticalCenter: parent.verticalCenter;\n'
424+ titleAnchors = 'verticalCenter: parent.verticalCenter;\n'
393425 } else {
394426 if (headerAsOverlay) {
395427 // Using anchors to the overlay
396− titleAnchors = 'anchors.left: parent.left; \n\
397− anchors.leftMargin: units.gu(1); \n\
398− anchors.right: parent.right; \n\
399− anchors.top: overlayLoader.top; \n\
400− anchors.topMargin: units.gu(1);\n';
428+ titleAnchors = 'left: parent.left; \n\
429+ leftMargin: units.gu(1); \n\
430+ right: parent.right; \n\
431+ top: overlayLoader.top; \n\
432+ topMargin: units.gu(1);\n';
401433 } else {
402434 // Using anchors to the mascot/parent
403− titleAnchors = "anchors.right: parent.right;";
435+ titleAnchors = "right: parent.right;";
404436 titleAnchors += headerLeftAnchor;
405437 titleAnchors += headerVerticalAnchors;
406438 }
@@ -412,24 +444,28 @@ function cardString(template, components) {
412444 }
413445
414446 var titleLabelVisibleExtra = (headerAsOverlay ? '&& overlayLoader.active': '');
415− var titleCode = titleLabelCode.arg(titleAnchors).arg(color).arg(titleLabelVisibleExtra);
447+ var titleCode = kTitleLabelCode.arg(titleAnchors).arg(color).arg(titleLabelVisibleExtra);
416448 var subtitleCode = "";
417449 if (hasSubtitle) {
418− subtitleCode += subtitleLabelCode.arg(subtitleAnchors).arg(color);
450+ subtitleCode += kSubtitleLabelCode.arg(subtitleAnchors).arg(color);
419451 }
420452
421453 if (hasMascot && hasSubtitle) {
422454 // If using row + column wrap the code in the column
423− titleSubtitleCode = headerColumnCode.arg(titleCode).arg(subtitleCode);
455+ titleSubtitleCode = kHeaderColumnCode.arg(titleCode).arg(subtitleCode);
424456 } else {
425457 titleSubtitleCode = titleCode + subtitleCode;
426458 }
427459 }
428460
429461 if (hasHeaderRow) {
430− code += headerRowCode.arg(headerVerticalAnchors).arg(headerLeftAnchor).arg(mascotCode + titleSubtitleCode);
462+ if (mascotShapeCode != "") {
463+ code += kHeaderRow3Code.arg(headerVerticalAnchors + headerLeftAnchor).arg(mascotShapeCode).arg(mascotCode).arg(titleSubtitleCode);
464+ } else {
465+ code += kHeaderRow2Code.arg(headerVerticalAnchors + headerLeftAnchor).arg(mascotCode).arg(titleSubtitleCode);
466+ }
431467 } else {
432− code += mascotCode + titleSubtitleCode;
468+ code += mascotShapeCode + mascotCode + titleSubtitleCode;
433469 }
434470
435471 if (hasSummary) {
@@ -452,7 +488,7 @@ function cardString(template, components) {
452488
453489 var summaryTopMargin = (hasMascot || hasSubtitle ? 'anchors.margins' : '0');
454490
455− code += summaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(color);
491+ code += kSummaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(color);
456492 }
457493
458494 if (hasSummary) {
tests/plugins/Dash/cardcreator/1.res+4−6
@@ -17,7 +17,6 @@ Item {
1717 height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height;
1818 width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width;
1919 anchors { horizontalCenter: parent.horizontalCenter; }
20−
2120 Loader {
2221 id: artShapeLoader;
2322 objectName: "artShapeLoader";
@@ -51,7 +50,6 @@ Item {
5150 readonly property real aspect: implicitWidth / implicitHeight;
5251 width: root.width;
5352 height: width / artShape.aspect;
54−
5553 }
5654 }
5755 }
@@ -60,10 +58,10 @@ readonly property int headerHeight: titleLabel.height + titleLabel.anchors.topMa
6058Label {
6159 id: titleLabel;
6260 objectName: "titleLabel";
63− anchors.right: parent.right;anchors.left: parent.left;
64−anchors.top: artShapeHolder.bottom;
65− anchors.topMargin: units.gu(1);
66−
61+ anchors { right: parent.right;left: parent.left;
62+top: artShapeHolder.bottom;
63+ topMargin: units.gu(1);
64+ }
6765 elide: Text.ElideRight;
6866 fontSize: "small";
6967 wrapMode: Text.Wrap;
tests/plugins/Dash/cardcreator/2.res+8−8
@@ -51,17 +51,16 @@ Row {
5151 objectName: "outerRow";
5252 property real margins: units.gu(1);
5353 spacing: margins;
54− anchors.top: parent.top;
55− anchors.topMargin: units.gu(1);
56−
57− anchors.left: parent.left;
58−
54+ anchors { top: parent.top;
55+ topMargin: units.gu(1);
56+ left: parent.left;
57+}
5958 anchors.right: parent.right;
6059 anchors.margins: margins;
61−Image {
60+data: [ Image {
6261 id: mascotImage;
6362 objectName: "mascotImage";
64− anchors.verticalCenter: parent.verticalCenter;
63+ anchors { verticalCenter: parent.verticalCenter; }
6564 readonly property int maxSize: Math.max(width, height) * 4;
6665 source: cardData && cardData["mascot"];
6766 width: units.gu(6);
@@ -72,6 +71,7 @@ Image {
7271 verticalAlignment: Image.AlignVCenter;
7372 visible: showHeader;
7473 }
74+,
7575Column {
7676 anchors.verticalCenter: parent.verticalCenter;
7777 spacing: units.dp(2);
@@ -81,7 +81,6 @@ Label {
8181 id: titleLabel;
8282 objectName: "titleLabel";
8383 anchors { left: parent.left; right: parent.right }
84−
8584 elide: Text.ElideRight;
8685 fontSize: "small";
8786 wrapMode: Text.Wrap;
@@ -110,6 +109,7 @@ Label {
110109 }
111110]
112111}
112+]
113113}
114114implicitHeight: row.y + row.height + units.gu(1);
115115}
tests/plugins/Dash/cardcreator/3.res+4−6
@@ -17,7 +17,6 @@ Item {
1717 height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height;
1818 width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width;
1919 anchors { horizontalCenter: parent.horizontalCenter; }
20−
2120 Loader {
2221 id: artShapeLoader;
2322 objectName: "artShapeLoader";
@@ -51,7 +50,6 @@ Item {
5150 readonly property real aspect: implicitWidth / implicitHeight;
5251 width: root.width;
5352 height: width / artShape.aspect;
54−
5553 }
5654 }
5755 }
@@ -60,10 +58,10 @@ readonly property int headerHeight: subtitleLabel.y + subtitleLabel.height - tit
6058Label {
6159 id: titleLabel;
6260 objectName: "titleLabel";
63− anchors.right: parent.right;anchors.left: parent.left;
64−anchors.top: artShapeHolder.bottom;
65− anchors.topMargin: units.gu(1);
66−
61+ anchors { right: parent.right;left: parent.left;
62+top: artShapeHolder.bottom;
63+ topMargin: units.gu(1);
64+}
6765 elide: Text.ElideRight;
6866 fontSize: "small";
6967 wrapMode: Text.Wrap;
tests/plugins/Dash/cardcreator/4.res+13−11
@@ -18,14 +18,13 @@ Row {
1818 objectName: "outerRow";
1919 property real margins: units.gu(1);
2020 spacing: margins;
21− anchors.top: parent.top;
22− anchors.topMargin: units.gu(1);
23−
24− anchors.left: parent.left;
25−
21+ anchors { top: parent.top;
22+ topMargin: units.gu(1);
23+ left: parent.left;
24+}
2625 anchors.right: parent.right;
2726 anchors.margins: margins;
28−Loader {
27+data: [ Loader {
2928 id: mascotShapeLoader;
3029 objectName: "mascotShapeLoader";
3130 asynchronous: root.asynchronous;
@@ -34,12 +33,14 @@ Loader {
3433 width: units.gu(6);
3534 height: units.gu(5.625);
3635 sourceComponent: UbuntuShape { image: mascotImage }
37− anchors.verticalCenter: parent.verticalCenter;
36+ anchors { verticalCenter: parent.verticalCenter; }
3837 }
38+
39+,
3940Image {
4041 id: mascotImage;
4142 objectName: "mascotImage";
42− anchors.verticalCenter: parent.verticalCenter;
43+ anchors { verticalCenter: parent.verticalCenter; }
4344 readonly property int maxSize: Math.max(width, height) * 4;
4445 source: cardData && cardData["mascot"];
4546 width: units.gu(6);
@@ -50,16 +51,16 @@ Image {
5051 verticalAlignment: Image.AlignVCenter;
5152 visible: false;
5253 }
54+
55+,
5356Column {
5457 anchors.verticalCenter: parent.verticalCenter;
5558 spacing: units.dp(2);
5659 width: parent.width - x;
57−data: [
58−Label {
60+data: [ Label {
5961 id: titleLabel;
6062 objectName: "titleLabel";
6163 anchors { left: parent.left; right: parent.right }
62−
6364 elide: Text.ElideRight;
6465 fontSize: "small";
6566 wrapMode: Text.Wrap;
@@ -88,6 +89,7 @@ Label {
8889 }
8990]
9091}
92+]
9193}
9294implicitHeight: row.y + row.height + units.gu(1);
9395}
tests/plugins/Dash/cardcreator/5.res+8−11
@@ -17,7 +17,6 @@ Item {
1717 height: root.fixedArtShapeSize.height != -1 ? root.fixedArtShapeSize.height : artShapeLoader.height;
1818 width: root.fixedArtShapeSize.width != -1 ? root.fixedArtShapeSize.width : artShapeLoader.width;
1919 anchors { horizontalCenter: parent.horizontalCenter; }
20−
2120 Loader {
2221 id: artShapeLoader;
2322 objectName: "artShapeLoader";
@@ -51,7 +50,6 @@ Item {
5150 readonly property real aspect: implicitWidth / implicitHeight;
5251 width: root.width;
5352 height: width / artShape.aspect;
54−
5553 }
5654 }
5755 }
@@ -69,7 +67,6 @@ Loader {
6967 sourceComponent: ShaderEffect {
7068 id: overlay;
7169 height: fixedHeaderHeight != -1 ? fixedHeaderHeight : headerHeight;
72−
7370 opacity: 0.6;
7471 property var source: ShaderEffectSource {
7572 id: shaderSource;
@@ -101,12 +98,12 @@ readonly property int headerHeight: subtitleLabel.y + subtitleLabel.height - tit
10198Label {
10299 id: titleLabel;
103100 objectName: "titleLabel";
104− anchors.left: parent.left;
105− anchors.leftMargin: units.gu(1);
106− anchors.right: parent.right;
107− anchors.top: overlayLoader.top;
108− anchors.topMargin: units.gu(1);
109−
101+ anchors { left: parent.left;
102+ leftMargin: units.gu(1);
103+ right: parent.right;
104+ top: overlayLoader.top;
105+ topMargin: units.gu(1);
106+}
110107 elide: Text.ElideRight;
111108 fontSize: "small";
112109 wrapMode: Text.Wrap;
@@ -125,8 +122,8 @@ Label {
125122 leftMargin: titleLabel.leftMargin;
126123 right: titleLabel.right;
127124 top: titleLabel.bottom;
128− topMargin: units.dp(2); }
129−
125+ topMargin: units.dp(2);
126+ }
130127 elide: Text.ElideRight;
131128 fontSize: "small";
132129 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);