on 2ce45f8 help sign in
unity8/plugins/Dash/CardCreator.js
617 lines 31 kB history raw
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17.pragma library
19var kBackgroundLoaderCode = 'Loader {\n\
20 id: backgroundLoader; \n\
21 objectName: "backgroundLoader"; \n\
22 anchors.fill: parent; \n\
23 asynchronous: root.asynchronous; \n\
24 visible: status == Loader.Ready; \n\
25 sourceComponent: UbuntuShape { \n\
26 objectName: "background"; \n\
27 radius: "medium"; \n\
28 color: getColor(0) || "white"; \n\
29 gradientColor: getColor(1) || color; \n\
30 anchors.fill: parent; \n\
31 image: backgroundImage.source ? backgroundImage : null; \n\
32 property real luminance: 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b; \n\
33 property Image backgroundImage: Image { \n\
34 objectName: "backgroundImage"; \n\
35 source: { \n\
36 if (cardData && typeof cardData["background"] === "string") return cardData["background"]; \n\
37 else if (template && typeof template["card-background"] === "string") return template["card-background"]; \n\
38 else return ""; \n\
39 } \n\
40 } \n\
41 function getColor(index) { \n\
42 if (cardData && typeof cardData["background"] === "object" \n\
43 && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) { \n\
44 return cardData["background"]["elements"][index]; \n\
45 } else if (template && typeof template["card-background"] === "object" \n\
46 && (template["card-background"]["type"] === "color" || template["card-background"]["type"] === "gradient")) { \n\
47 return template["card-background"]["elements"][index]; \n\
48 } else return undefined; \n\
49 } \n\
50 } \n\
51 }\n';
53// %1 is used as anchors of artShapeHolder
54// %2 is used as image width
55// %3 is used as image height
56var kArtShapeHolderCode = 'Item { \n\
57 id: artShapeHolder; \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\
60 anchors { %1 } \n\
61 Loader { \n\
62 id: artShapeLoader; \n\
63 objectName: "artShapeLoader"; \n\
64 active: cardData && cardData["art"] || false; \n\
65 asynchronous: root.asynchronous; \n\
66 visible: status == Loader.Ready; \n\
67 sourceComponent: UbuntuShape { \n\
68 id: artShape; \n\
69 objectName: "artShape"; \n\
70 radius: "medium"; \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\
74 Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; } \n\
75 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); } \n\
76 function updateWidthHeightBindings() { \n\
77 if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) { \n\
78 width = root.fixedArtShapeSize.width; \n\
79 height = root.fixedArtShapeSize.height; \n\
80 } else { \n\
81 width = Qt.binding(function() { return !visible ? 0 : image.width }); \n\
82 height = Qt.binding(function() { return !visible ? 0 : image.height }); \n\
83 } \n\
84 } \n\
85 image: Image { \n\
86 objectName: "artImage"; \n\
87 source: cardData && cardData["art"] || ""; \n\
88 cache: true; \n\
89 asynchronous: root.asynchronous; \n\
90 fillMode: Image.PreserveAspectCrop; \n\
91 width: %2; \n\
92 height: %3; \n\
93 } \n\
94 } \n\
95 } \n\
96 }\n';
98var kOverlayLoaderCode = 'Loader { \n\
99 id: overlayLoader; \n\
100 anchors { \n\
101 left: artShapeHolder.left; \n\
102 right: artShapeHolder.right; \n\
103 bottom: artShapeHolder.bottom; \n\
104 } \n\
105 active: artShapeLoader.active && artShapeLoader.item && artShapeLoader.item.image.status === Image.Ready || false; \n\
106 asynchronous: root.asynchronous; \n\
107 visible: showHeader && status == Loader.Ready; \n\
108 sourceComponent: ShaderEffect { \n\
109 id: overlay; \n\
110 height: (fixedHeaderHeight > 0 ? fixedHeaderHeight : headerHeight) + units.gu(2); \n\
111 property real luminance: 0.2126 * overlayColor.r + 0.7152 * overlayColor.g + 0.0722 * overlayColor.b; \n\
112 property color overlayColor: cardData && cardData["overlayColor"] || "#99000000"; \n\
113 property var source: ShaderEffectSource { \n\
114 id: shaderSource; \n\
115 sourceItem: artShapeLoader.item; \n\
116 onVisibleChanged: if (visible) scheduleUpdate(); \n\
117 live: false; \n\
118 sourceRect: Qt.rect(0, artShapeLoader.height - overlay.height, artShapeLoader.width, overlay.height); \n\
119 } \n\
120 vertexShader: " \n\
121 uniform highp mat4 qt_Matrix; \n\
122 attribute highp vec4 qt_Vertex; \n\
123 attribute highp vec2 qt_MultiTexCoord0; \n\
124 varying highp vec2 coord; \n\
125 void main() { \n\
126 coord = qt_MultiTexCoord0; \n\
127 gl_Position = qt_Matrix * qt_Vertex; \n\
128 }"; \n\
129 fragmentShader: " \n\
130 varying highp vec2 coord; \n\
131 uniform sampler2D source; \n\
132 uniform lowp float qt_Opacity; \n\
133 uniform highp vec4 overlayColor; \n\
134 void main() { \n\
135 lowp vec4 tex = texture2D(source, coord); \n\
136 gl_FragColor = vec4(overlayColor.r, overlayColor.g, overlayColor.b, 1) * qt_Opacity * overlayColor.a * tex.a; \n\
137 }"; \n\
138 } \n\
139 }\n';
141// %1 is used as anchors of row
142// %2 is used as first child of the row
143// %3 is used as second child of the row
144var kHeaderRow2Code = 'Row { \n\
145 id: row; \n\
146 objectName: "outerRow"; \n\
147 property real margins: units.gu(1); \n\
148 spacing: margins; \n\
149 height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight; \n\
150 anchors { %1 } \n\
151 anchors.right: parent.right; \n\
152 anchors.margins: margins;\n\
153 data: [ %2\n\
154 ,\n\
155 %3 \n\
156 ] \n\
157 }\n';
159// %1 is used as anchors of row
160// %2 is used as first child of the row
161// %3 is used as second child of the row
162// %4 is used as third child of the row
163var kHeaderRow3Code = 'Row { \n\
164 id: row; \n\
165 objectName: "outerRow"; \n\
166 property real margins: units.gu(1); \n\
167 spacing: margins; \n\
168 height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight; \n\
169 anchors { %1 } \n\
170 anchors.right: parent.right; \n\
171 anchors.margins: margins;\n\
172 data: [ %2\n\
173 ,\n\
174 %3 \n\
175 ,\n\
176 %4 \n\
177 ] \n\
178 }\n';
180// %1 is used as first child of the column
181// %2 is used as second child of the column
182var kHeaderColumnCode = 'Column { \n\
183 anchors.verticalCenter: parent.verticalCenter; \n\
184 spacing: units.dp(2); \n\
185 width: parent.width - x;\n\
186 data: [ %1\n\
187 ,\n\
188 %2 \n\
189 ] \n\
190 }\n';
192// multiple column version of kHeaderColumnCode.
193function kHeaderColumnCodeGenerator() {
194 var headerColumnCodeTemplate = 'Column { \n\
195 anchors.verticalCenter: parent.verticalCenter; \n\
196 spacing: units.dp(2); \n\
197 width: parent.width - x;\n\
198 data: [ \n\
199 %1 \n\
200 ]\n\
201 }\n';
202 var args = Array.prototype.slice.call(arguments);
203 var code = headerColumnCodeTemplate.arg(args.join(',\n'));
204 return code;
207// %1 is used as anchors of mascotShapeLoader
208var kMascotShapeLoaderCode = 'Loader { \n\
209 id: mascotShapeLoader; \n\
210 objectName: "mascotShapeLoader"; \n\
211 asynchronous: root.asynchronous; \n\
212 active: mascotImage.status === Image.Ready; \n\
213 visible: showHeader && active && status == Loader.Ready; \n\
214 width: units.gu(6); \n\
215 height: units.gu(5.625); \n\
216 sourceComponent: UbuntuShape { image: mascotImage } \n\
217 anchors { %1 } \n\
218 }\n';
220// %1 is used as anchors of mascotImage
221// %2 is used as visible of mascotImage
222var kMascotImageCode = 'Image { \n\
223 id: mascotImage; \n\
224 objectName: "mascotImage"; \n\
225 anchors { %1 } \n\
226 readonly property int maxSize: Math.max(width, height) * 4; \n\
227 source: cardData && cardData["mascot"]; \n\
228 width: units.gu(6); \n\
229 height: units.gu(5.625); \n\
230 sourceSize { width: maxSize; height: maxSize } \n\
231 fillMode: Image.PreserveAspectCrop; \n\
232 horizontalAlignment: Image.AlignHCenter; \n\
233 verticalAlignment: Image.AlignVCenter; \n\
234 visible: %2; \n\
235 }\n';
237// %1 is used as anchors of titleLabel
238// %2 is used as color of titleLabel
239// %3 is used as extra condition for visible of titleLabel
240var kTitleLabelCode = 'Label { \n\
241 id: titleLabel; \n\
242 objectName: "titleLabel"; \n\
243 anchors { %1 } \n\
244 elide: Text.ElideRight; \n\
245 fontSize: "small"; \n\
246 wrapMode: Text.Wrap; \n\
247 maximumLineCount: 2; \n\
248 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
249 color: %2; \n\
250 visible: showHeader %3; \n\
251 text: root.title; \n\
252 font.weight: components && components["subtitle"] ? Font.DemiBold : Font.Normal; \n\
253 horizontalAlignment: root.headerAlignment; \n\
254 }\n';
256// %1 is used as anchors of touchdown effect
257var kTouchdownCode = 'UbuntuShape { \n\
258 id: touchdown; \n\
259 objectName: "touchdown"; \n\
260 anchors { %1 } \n\
261 visible: root.pressed; \n\
262 radius: "medium"; \n\
263 borderSource: "radius_pressed.sci" \n\
264 }\n';
266// %1 is used as anchors of subtitleLabel
267// %2 is used as color of subtitleLabel
268var kSubtitleLabelCode = 'Label { \n\
269 id: subtitleLabel; \n\
270 objectName: "subtitleLabel"; \n\
271 anchors { %1 } \n\
272 elide: Text.ElideRight; \n\
273 fontSize: "small"; \n\
274 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
275 color: %2; \n\
276 visible: titleLabel.visible && titleLabel.text; \n\
277 text: cardData && cardData["subtitle"] || ""; \n\
278 font.weight: Font.Light; \n\
279 horizontalAlignment: root.headerAlignment; \n\
280 }\n';
282// %1 is used as anchors of attributesRow
283var kAttributesRowCode = 'CardAttributes { \n\
284 id: attributesRow; \n\
285 objectName: "attributesRow"; \n\
286 anchors { %1 } \n\
287 color: %2; \n\
288 model: cardData["attributes"]; \n\
289 }\n';
291// %1 is used as top anchor of summary
292// %2 is used as topMargin anchor of summary
293// %3 is used as color of summary
294var kSummaryLabelCode = 'Label { \n\
295 id: summary; \n\
296 objectName: "summaryLabel"; \n\
297 anchors { \n\
298 top: %1; \n\
299 left: parent.left; \n\
300 right: parent.right; \n\
301 margins: units.gu(1); \n\
302 topMargin: %2; \n\
303 } \n\
304 wrapMode: Text.Wrap; \n\
305 maximumLineCount: 5; \n\
306 elide: Text.ElideRight; \n\
307 text: cardData && cardData["summary"] || ""; \n\
308 height: text ? implicitHeight : 0; \n\
309 fontSize: "small"; \n\
310 color: %3; \n\
311 }\n';
313function cardString(template, components) {
314 var code;
315 code = 'AbstractButton { \n\
316 id: root; \n\
317 property var template; \n\
318 property var components; \n\
319 property var cardData; \n\
320 property var artShapeBorderSource: undefined; \n\
321 property real fontScale: 1.0; \n\
322 property var scopeStyle: null; \n\
323 property int headerAlignment: Text.AlignLeft; \n\
324 property int fixedHeaderHeight: -1; \n\
325 property size fixedArtShapeSize: Qt.size(-1, -1); \n\
326 readonly property string title: cardData && cardData["title"] || ""; \n\
327 property bool asynchronous: true; \n\
328 property bool showHeader: true; \n\
329 implicitWidth: childrenRect.width; \n';
331 var hasArt = components["art"] && components["art"]["field"] || false;
332 var hasSummary = components["summary"] || false;
333 var artAndSummary = hasArt && hasSummary;
334 var isHorizontal = template["card-layout"] === "horizontal";
335 var hasBackground = !isHorizontal && (template["card-background"] || components["background"] || artAndSummary);
336 var hasTitle = components["title"] || false;
337 var hasMascot = components["mascot"] || false;
338 var headerAsOverlay = hasArt && template && template["overlay"] === true && (hasTitle || hasMascot);
339 var hasSubtitle = hasTitle && components["subtitle"] || false;
340 var hasHeaderRow = hasMascot && hasTitle;
341 var hasAttributes = hasTitle && components["attributes"] || false;
343 if (hasBackground) {
344 code += kBackgroundLoaderCode;
345 }
347 if (hasArt) {
348 code += 'onArtShapeBorderSourceChanged: { if (artShapeBorderSource !== undefined && artShapeLoader.item) artShapeLoader.item.borderSource = artShapeBorderSource; } \n';
349 code += 'readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);\n';
351 var widthCode, heightCode;
352 var anchors;
353 if (isHorizontal) {
354 anchors = 'left: parent.left';
355 if (hasMascot || hasTitle) {
356 widthCode = 'height * artShape.aspect'
357 heightCode = 'headerHeight + 2 * units.gu(1)';
358 } else {
359 // This side of the else is a bit silly, who wants an horizontal layout without mascot and title?
360 // So we define a "random" height of the image height + 2 gu for the margins
361 widthCode = 'height * artShape.aspect'
362 heightCode = 'units.gu(7.625)';
363 }
364 } else {
365 anchors = 'horizontalCenter: parent.horizontalCenter;';
366 widthCode = 'root.width'
367 heightCode = 'width / artShape.aspect';
368 }
370 code += kArtShapeHolderCode.arg(anchors).arg(widthCode).arg(heightCode);
371 } else {
372 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
373 }
375 if (headerAsOverlay) {
376 code += kOverlayLoaderCode;
377 }
379 var headerVerticalAnchors;
380 if (headerAsOverlay) {
381 headerVerticalAnchors = 'bottom: artShapeHolder.bottom; \n\
382 bottomMargin: units.gu(1);\n';
383 } else {
384 if (hasArt) {
385 if (isHorizontal) {
386 headerVerticalAnchors = 'top: artShapeHolder.top; \n\
387 topMargin: units.gu(1);\n';
388 } else {
389 headerVerticalAnchors = 'top: artShapeHolder.bottom; \n\
390 topMargin: units.gu(1);\n';
391 }
392 } else {
393 headerVerticalAnchors = 'top: parent.top; \n\
394 topMargin: units.gu(1);\n';
395 }
396 }
397 var headerLeftAnchor;
398 var headerLeftAnchorHasMargin = false;
399 if (isHorizontal && hasArt) {
400 headerLeftAnchor = 'left: artShapeHolder.right; \n\
401 leftMargin: units.gu(1);\n';
402 headerLeftAnchorHasMargin = true;
403 } else {
404 headerLeftAnchor = 'left: parent.left;\n';
405 }
407 if (hasHeaderRow) {
408 code += 'readonly property int headerHeight: row.height;\n'
409 } else if (hasMascot) {
410 code += 'readonly property int headerHeight: mascotImage.height;\n'
411 } else if (hasAttributes) {
412 if (hasTitle && hasSubtitle) {
413 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + attributesRow.height + attributesRow.anchors.topMargin;\n'
414 } else if (hasTitle) {
415 code += 'readonly property int headerHeight: titleLabel.height + attributesRow.height + attributesRow.anchors.topMargin;\n'
416 } else {
417 code += 'readonly property int headerHeight: attributesRow.height;\n'
418 }
419 } else if (hasSubtitle) {
420 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin;\n'
421 } else if (hasTitle) {
422 code += 'readonly property int headerHeight: titleLabel.height;\n'
423 } else {
424 code += 'readonly property int headerHeight: 0;\n'
425 }
427 var mascotShapeCode = "";
428 var mascotCode = "";
429 if (hasMascot) {
430 var useMascotShape = !hasBackground && !headerAsOverlay;
431 var anchors = "";
432 if (!hasHeaderRow) {
433 anchors += headerLeftAnchor;
434 anchors += headerVerticalAnchors;
435 if (!headerLeftAnchorHasMargin) {
436 anchors += 'leftMargin: units.gu(1);\n'
437 }
438 } else {
439 anchors = "verticalCenter: parent.verticalCenter;"
440 }
442 if (useMascotShape) {
443 mascotShapeCode = kMascotShapeLoaderCode.arg(anchors);
444 }
446 var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
447 mascotCode = kMascotImageCode.arg(anchors).arg(mascotImageVisible);
448 }
450 var summaryColorWithBackground = 'backgroundLoader.active && backgroundLoader.item && backgroundLoader.item.luminance < (root.scopeStyle ? root.scopeStyle.threshold : 0.7) ? (root.scopeStyle ? root.scopeStyle.light : "white") : (root.scopeStyle ? root.scopeStyle.dark : "grey")';
452 var titleSubtitleCode = "";
453 if (hasTitle) {
454 var color;
455 if (headerAsOverlay) {
456 color = 'overlayLoader.item.luminance < (root.scopeStyle ? root.scopeStyle.threshold : 0.7) ? (root.scopeStyle ? root.scopeStyle.light : "white") : (root.scopeStyle ? root.scopeStyle.dark : "grey")';
457 } else if (hasSummary) {
458 color = 'summary.color';
459 } else if (hasBackground) {
460 color = summaryColorWithBackground;
461 } else {
462 color = 'root.scopeStyle ? root.scopeStyle.foreground : "grey"';
463 }
465 var titleAnchors;
466 var subtitleAnchors;
467 var attributesAnchors;
468 if (hasMascot && (hasSubtitle || hasAttributes)) {
469 // Using row + column
470 titleAnchors = 'left: parent.left; right: parent.right';
471 subtitleAnchors = titleAnchors;
472 attributesAnchors = subtitleAnchors;
473 } else if (hasMascot) {
474 // Using row + label
475 titleAnchors = 'verticalCenter: parent.verticalCenter;\n'
476 } else {
477 if (headerAsOverlay) {
478 // Using anchors to the overlay
479 titleAnchors = 'left: parent.left; \n\
480 leftMargin: units.gu(1); \n\
481 right: parent.right; \n\
482 rightMargin: units.gu(1); \n\
483 top: overlayLoader.top; \n\
484 topMargin: units.gu(1);\n';
485 } else {
486 // Using anchors to the mascot/parent
487 titleAnchors = "right: parent.right;\n";
488 titleAnchors += "rightMargin: units.gu(1);\n";
489 titleAnchors += headerLeftAnchor;
490 titleAnchors += headerVerticalAnchors;
491 if (!headerLeftAnchorHasMargin) {
492 titleAnchors += 'leftMargin: units.gu(1);\n'
493 }
494 }
495 subtitleAnchors = 'left: titleLabel.left; \n\
496 leftMargin: titleLabel.leftMargin; \n\
497 right: titleLabel.right; \n\
498 rightMargin: titleLabel.rightMargin; \n\
499 top: titleLabel.bottom; \n\
500 topMargin: units.dp(2);\n';
501 if (hasSubtitle) {
502 attributesAnchors = 'left: subtitleLabel.left; \n\
503 leftMargin: subtitleLabel.leftMargin; \n\
504 right: subtitleLabel.right; \n\
505 rightMargin: subtitleLabel.rightMargin; \n\
506 top: subtitleLabel.bottom; \n\
507 topMargin: units.dp(2);\n';
508 } else {
509 attributesAnchors = subtitleAnchors;
510 }
511 }
513 var titleLabelVisibleExtra = (headerAsOverlay ? '&& overlayLoader.active': '');
514 var titleCode = kTitleLabelCode.arg(titleAnchors).arg(color).arg(titleLabelVisibleExtra);
515 var subtitleCode = "";
516 if (hasSubtitle) {
517 subtitleCode += kSubtitleLabelCode.arg(subtitleAnchors).arg(color);
518 }
520 if (hasMascot && (hasSubtitle || hasAttributes)) {
521 // If using row + column wrap the code in the column
522 titleSubtitleCode = kHeaderColumnCode.arg(titleCode).arg(subtitleCode);
523 if (hasSubtitle && hasAttributes) {
524 var attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(color);
525 titleSubtitleCode = kHeaderColumnCodeGenerator(titleCode, subtitleCode, attributesCode);
526 } else if (hasSubtitle) {
527 titleSubtitleCode = kHeaderColumnCode.arg(titleCode).arg(subtitleCode);
528 } else if (hasAttributes) {
529 var attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(color);
530 titleSubtitleCode = kHeaderColumnCode.arg(titleCode).arg(attributesCode);
531 }
532 } else {
533 titleSubtitleCode = titleCode;
534 if (hasSubtitle) {
535 titleSubtitleCode = titleSubtitleCode + subtitleCode;
536 }
537 if (hasAttributes) {
538 var attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(color);
539 titleSubtitleCode = titleSubtitleCode + attributesCode;
540 }
541 }
542 }
544 if (hasHeaderRow) {
545 if (mascotShapeCode != "") {
546 code += kHeaderRow3Code.arg(headerVerticalAnchors + headerLeftAnchor).arg(mascotShapeCode).arg(mascotCode).arg(titleSubtitleCode);
547 } else {
548 code += kHeaderRow2Code.arg(headerVerticalAnchors + headerLeftAnchor).arg(mascotCode).arg(titleSubtitleCode);
549 }
550 } else {
551 code += mascotShapeCode + mascotCode + titleSubtitleCode;
552 }
554 if (hasSummary) {
555 var summaryTopAnchor;
556 if (isHorizontal && hasArt) summaryTopAnchor = "artShapeHolder.bottom";
557 else if (headerAsOverlay && hasArt) summaryTopAnchor = "artShapeHolder.bottom";
558 else if (hasHeaderRow) summaryTopAnchor = "row.bottom";
559 else if (hasMascot) summaryTopAnchor = "mascotImage.bottom";
560 else if (hasAttributes) summaryTopAnchor = "attributesRow.bottom";
561 else if (hasSubtitle) summaryTopAnchor = "subtitleLabel.bottom";
562 else if (hasTitle) summaryTopAnchor = "titleLabel.bottom";
563 else if (hasArt) summaryTopAnchor = "artShapeHolder.bottom";
564 else summaryTopAnchor = "parent.top";
566 var color;
567 if (hasBackground) {
568 color = summaryColorWithBackground;
569 } else {
570 color = 'root.scopeStyle ? root.scopeStyle.foreground : "grey"';
571 }
573 var summaryTopMargin = (hasMascot || hasSubtitle || hasAttributes ? 'anchors.margins' : '0');
575 code += kSummaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(color);
576 }
578 var touchdownAnchors;
579 if (hasBackground) {
580 touchdownAnchors = 'fill: backgroundLoader';
581 } else if (hasArt && !hasMascot && !hasSummary) {
582 touchdownAnchors = 'fill: artShapeHolder';
583 } else {
584 touchdownAnchors = 'fill: root'
585 }
586 code += kTouchdownCode.arg(touchdownAnchors);
588 if (hasSummary) {
589 code += 'implicitHeight: summary.y + summary.height + (summary.text ? units.gu(1) : 0);\n';
590 } else if (hasHeaderRow) {
591 code += 'implicitHeight: row.y + row.height + units.gu(1);\n';
592 } else if (hasMascot) {
593 code += 'implicitHeight: mascotImage.y + mascotImage.height;\n';
594 } else if (hasAttributes) {
595 code += 'implicitHeight: attributesRow.y + attributesRow.height + units.gu(1);\n';
596 } else if (hasSubtitle) {
597 code += 'implicitHeight: subtitleLabel.y + subtitleLabel.height + units.gu(1);\n';
598 } else if (hasTitle) {
599 code += 'implicitHeight: titleLabel.y + titleLabel.height + units.gu(1);\n';
600 } else if (hasArt) {
601 code += 'implicitHeight: artShapeHolder.height;\n';
602 }
603 // Close the AbstractButton
604 code += '}\n';
606 return code;
609function createCardComponent(parent, template, components) {
610 var imports = 'import QtQuick 2.2; \n\
611 import Ubuntu.Components 0.1; \n\
612 import Dash 0.1;\n';
613 var card = cardString(template, components);
614 var code = imports + 'Component {\n' + card + '}\n';
616 return Qt.createQmlObject(code, parent, "createCardComponent");