on c155a77 help sign in
unity8/plugins/Dash/CardCreator.js
616 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 color overlayColor: cardData && cardData["overlayColor"] || "#99000000"; \n\
112 property var source: ShaderEffectSource { \n\
113 id: shaderSource; \n\
114 sourceItem: artShapeLoader.item; \n\
115 onVisibleChanged: if (visible) scheduleUpdate(); \n\
116 live: false; \n\
117 sourceRect: Qt.rect(0, artShapeLoader.height - overlay.height, artShapeLoader.width, overlay.height); \n\
118 } \n\
119 vertexShader: " \n\
120 uniform highp mat4 qt_Matrix; \n\
121 attribute highp vec4 qt_Vertex; \n\
122 attribute highp vec2 qt_MultiTexCoord0; \n\
123 varying highp vec2 coord; \n\
124 void main() { \n\
125 coord = qt_MultiTexCoord0; \n\
126 gl_Position = qt_Matrix * qt_Vertex; \n\
127 }"; \n\
128 fragmentShader: " \n\
129 varying highp vec2 coord; \n\
130 uniform sampler2D source; \n\
131 uniform lowp float qt_Opacity; \n\
132 uniform highp vec4 overlayColor; \n\
133 void main() { \n\
134 lowp vec4 tex = texture2D(source, coord); \n\
135 gl_FragColor = vec4(overlayColor.r, overlayColor.g, overlayColor.b, 1) * qt_Opacity * overlayColor.a * tex.a; \n\
136 }"; \n\
137 } \n\
138 }\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
143var kHeaderRow2Code = 'Row { \n\
144 id: row; \n\
145 objectName: "outerRow"; \n\
146 property real margins: units.gu(1); \n\
147 spacing: margins; \n\
148 height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight; \n\
149 anchors { %1 } \n\
150 anchors.right: parent.right; \n\
151 anchors.margins: margins;\n\
152 data: [ %2\n\
153 ,\n\
154 %3 \n\
155 ] \n\
156 }\n';
158// %1 is used as anchors of row
159// %2 is used as first child of the row
160// %3 is used as second child of the row
161// %4 is used as third child of the row
162var kHeaderRow3Code = 'Row { \n\
163 id: row; \n\
164 objectName: "outerRow"; \n\
165 property real margins: units.gu(1); \n\
166 spacing: margins; \n\
167 height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight; \n\
168 anchors { %1 } \n\
169 anchors.right: parent.right; \n\
170 anchors.margins: margins;\n\
171 data: [ %2\n\
172 ,\n\
173 %3 \n\
174 ,\n\
175 %4 \n\
176 ] \n\
177 }\n';
179// %1 is used as first child of the column
180// %2 is used as second child of the column
181var kHeaderColumnCode = 'Column { \n\
182 anchors.verticalCenter: parent.verticalCenter; \n\
183 spacing: units.dp(2); \n\
184 width: parent.width - x;\n\
185 data: [ %1\n\
186 ,\n\
187 %2 \n\
188 ] \n\
189 }\n';
191// multiple column version of kHeaderColumnCode.
192function kHeaderColumnCodeGenerator() {
193 var headerColumnCodeTemplate = 'Column { \n\
194 anchors.verticalCenter: parent.verticalCenter; \n\
195 spacing: units.dp(2); \n\
196 width: parent.width - x;\n\
197 data: [ \n\
198 %1 \n\
199 ]\n\
200 }\n';
201 var args = Array.prototype.slice.call(arguments);
202 var code = headerColumnCodeTemplate.arg(args.join(',\n'));
203 return code;
206// %1 is used as anchors of mascotShapeLoader
207var kMascotShapeLoaderCode = 'Loader { \n\
208 id: mascotShapeLoader; \n\
209 objectName: "mascotShapeLoader"; \n\
210 asynchronous: root.asynchronous; \n\
211 active: mascotImage.status === Image.Ready; \n\
212 visible: showHeader && active && status == Loader.Ready; \n\
213 width: units.gu(6); \n\
214 height: units.gu(5.625); \n\
215 sourceComponent: UbuntuShape { image: mascotImage } \n\
216 anchors { %1 } \n\
217 }\n';
219// %1 is used as anchors of mascotImage
220// %2 is used as visible of mascotImage
221var kMascotImageCode = 'Image { \n\
222 id: mascotImage; \n\
223 objectName: "mascotImage"; \n\
224 anchors { %1 } \n\
225 readonly property int maxSize: Math.max(width, height) * 4; \n\
226 source: cardData && cardData["mascot"]; \n\
227 width: units.gu(6); \n\
228 height: units.gu(5.625); \n\
229 sourceSize { width: maxSize; height: maxSize } \n\
230 fillMode: Image.PreserveAspectCrop; \n\
231 horizontalAlignment: Image.AlignHCenter; \n\
232 verticalAlignment: Image.AlignVCenter; \n\
233 visible: %2; \n\
234 }\n';
236// %1 is used as anchors of titleLabel
237// %2 is used as color of titleLabel
238// %3 is used as extra condition for visible of titleLabel
239var kTitleLabelCode = 'Label { \n\
240 id: titleLabel; \n\
241 objectName: "titleLabel"; \n\
242 anchors { %1 } \n\
243 elide: Text.ElideRight; \n\
244 fontSize: "small"; \n\
245 wrapMode: Text.Wrap; \n\
246 maximumLineCount: 2; \n\
247 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
248 color: %2; \n\
249 visible: showHeader %3; \n\
250 text: root.title; \n\
251 font.weight: components && components["subtitle"] ? Font.DemiBold : Font.Normal; \n\
252 horizontalAlignment: root.headerAlignment; \n\
253 }\n';
255// %1 is used as anchors of touchdown effect
256var kTouchdownCode = 'UbuntuShape { \n\
257 id: touchdown; \n\
258 objectName: "touchdown"; \n\
259 anchors { %1 } \n\
260 visible: root.pressed; \n\
261 radius: "medium"; \n\
262 borderSource: "radius_pressed.sci" \n\
263 }\n';
265// %1 is used as anchors of subtitleLabel
266// %2 is used as color of subtitleLabel
267var kSubtitleLabelCode = 'Label { \n\
268 id: subtitleLabel; \n\
269 objectName: "subtitleLabel"; \n\
270 anchors { %1 } \n\
271 elide: Text.ElideRight; \n\
272 fontSize: "small"; \n\
273 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
274 color: %2; \n\
275 visible: titleLabel.visible && titleLabel.text; \n\
276 text: cardData && cardData["subtitle"] || ""; \n\
277 font.weight: Font.Light; \n\
278 horizontalAlignment: root.headerAlignment; \n\
279 }\n';
281// %1 is used as anchors of attributesRow
282var kAttributesRowCode = 'CardAttributes { \n\
283 id: attributesRow; \n\
284 objectName: "attributesRow"; \n\
285 anchors { %1 } \n\
286 color: %2; \n\
287 model: cardData["attributes"]; \n\
288 }\n';
290// %1 is used as top anchor of summary
291// %2 is used as topMargin anchor of summary
292// %3 is used as color of summary
293var kSummaryLabelCode = 'Label { \n\
294 id: summary; \n\
295 objectName: "summaryLabel"; \n\
296 anchors { \n\
297 top: %1; \n\
298 left: parent.left; \n\
299 right: parent.right; \n\
300 margins: units.gu(1); \n\
301 topMargin: %2; \n\
302 } \n\
303 wrapMode: Text.Wrap; \n\
304 maximumLineCount: 5; \n\
305 elide: Text.ElideRight; \n\
306 text: cardData && cardData["summary"] || ""; \n\
307 height: text ? implicitHeight : 0; \n\
308 fontSize: "small"; \n\
309 color: %3; \n\
310 }\n';
312function cardString(template, components) {
313 var code;
314 code = 'AbstractButton { \n\
315 id: root; \n\
316 property var template; \n\
317 property var components; \n\
318 property var cardData; \n\
319 property var artShapeBorderSource: undefined; \n\
320 property real fontScale: 1.0; \n\
321 property var scopeStyle: null; \n\
322 property int headerAlignment: Text.AlignLeft; \n\
323 property int fixedHeaderHeight: -1; \n\
324 property size fixedArtShapeSize: Qt.size(-1, -1); \n\
325 readonly property string title: cardData && cardData["title"] || ""; \n\
326 property bool asynchronous: true; \n\
327 property bool showHeader: true; \n\
328 implicitWidth: childrenRect.width; \n';
330 var hasArt = components["art"] && components["art"]["field"] || false;
331 var hasSummary = components["summary"] || false;
332 var artAndSummary = hasArt && hasSummary;
333 var isHorizontal = template["card-layout"] === "horizontal";
334 var hasBackground = !isHorizontal && (template["card-background"] || components["background"] || artAndSummary);
335 var hasTitle = components["title"] || false;
336 var hasMascot = components["mascot"] || false;
337 var headerAsOverlay = hasArt && template && template["overlay"] === true && (hasTitle || hasMascot);
338 var hasSubtitle = hasTitle && components["subtitle"] || false;
339 var hasHeaderRow = hasMascot && hasTitle;
340 var hasAttributes = hasTitle && components["attributes"] || false;
342 if (hasBackground) {
343 code += kBackgroundLoaderCode;
344 }
346 if (hasArt) {
347 code += 'onArtShapeBorderSourceChanged: { if (artShapeBorderSource !== undefined && artShapeLoader.item) artShapeLoader.item.borderSource = artShapeBorderSource; } \n';
348 code += 'readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);\n';
350 var widthCode, heightCode;
351 var anchors;
352 if (isHorizontal) {
353 anchors = 'left: parent.left';
354 if (hasMascot || hasTitle) {
355 widthCode = 'height * artShape.aspect'
356 heightCode = 'headerHeight + 2 * units.gu(1)';
357 } else {
358 // This side of the else is a bit silly, who wants an horizontal layout without mascot and title?
359 // So we define a "random" height of the image height + 2 gu for the margins
360 widthCode = 'height * artShape.aspect'
361 heightCode = 'units.gu(7.625)';
362 }
363 } else {
364 anchors = 'horizontalCenter: parent.horizontalCenter;';
365 widthCode = 'root.width'
366 heightCode = 'width / artShape.aspect';
367 }
369 code += kArtShapeHolderCode.arg(anchors).arg(widthCode).arg(heightCode);
370 } else {
371 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
372 }
374 if (headerAsOverlay) {
375 code += kOverlayLoaderCode;
376 }
378 var headerVerticalAnchors;
379 if (headerAsOverlay) {
380 headerVerticalAnchors = 'bottom: artShapeHolder.bottom; \n\
381 bottomMargin: units.gu(1);\n';
382 } else {
383 if (hasArt) {
384 if (isHorizontal) {
385 headerVerticalAnchors = 'top: artShapeHolder.top; \n\
386 topMargin: units.gu(1);\n';
387 } else {
388 headerVerticalAnchors = 'top: artShapeHolder.bottom; \n\
389 topMargin: units.gu(1);\n';
390 }
391 } else {
392 headerVerticalAnchors = 'top: parent.top; \n\
393 topMargin: units.gu(1);\n';
394 }
395 }
396 var headerLeftAnchor;
397 var headerLeftAnchorHasMargin = false;
398 if (isHorizontal && hasArt) {
399 headerLeftAnchor = 'left: artShapeHolder.right; \n\
400 leftMargin: units.gu(1);\n';
401 headerLeftAnchorHasMargin = true;
402 } else {
403 headerLeftAnchor = 'left: parent.left;\n';
404 }
406 if (hasHeaderRow) {
407 code += 'readonly property int headerHeight: row.height;\n'
408 } else if (hasMascot) {
409 code += 'readonly property int headerHeight: mascotImage.height;\n'
410 } else if (hasAttributes) {
411 if (hasTitle && hasSubtitle) {
412 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + attributesRow.height + attributesRow.anchors.topMargin;\n'
413 } else if (hasTitle) {
414 code += 'readonly property int headerHeight: titleLabel.height + attributesRow.height + attributesRow.anchors.topMargin;\n'
415 } else {
416 code += 'readonly property int headerHeight: attributesRow.height;\n'
417 }
418 } else if (hasSubtitle) {
419 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin;\n'
420 } else if (hasTitle) {
421 code += 'readonly property int headerHeight: titleLabel.height;\n'
422 } else {
423 code += 'readonly property int headerHeight: 0;\n'
424 }
426 var mascotShapeCode = "";
427 var mascotCode = "";
428 if (hasMascot) {
429 var useMascotShape = !hasBackground && !headerAsOverlay;
430 var anchors = "";
431 if (!hasHeaderRow) {
432 anchors += headerLeftAnchor;
433 anchors += headerVerticalAnchors;
434 if (!headerLeftAnchorHasMargin) {
435 anchors += 'leftMargin: units.gu(1);\n'
436 }
437 } else {
438 anchors = "verticalCenter: parent.verticalCenter;"
439 }
441 if (useMascotShape) {
442 mascotShapeCode = kMascotShapeLoaderCode.arg(anchors);
443 }
445 var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
446 mascotCode = kMascotImageCode.arg(anchors).arg(mascotImageVisible);
447 }
449 var summaryColorWithBackground = 'backgroundLoader.active && backgroundLoader.item && backgroundLoader.item.luminance < 0.7 ? "white" : (root.scopeStyle ? root.scopeStyle.foreground : "grey")';
451 var titleSubtitleCode = "";
452 if (hasTitle) {
453 var color;
454 if (headerAsOverlay) {
455 color = '"white"';
456 } else if (hasSummary) {
457 color = 'summary.color';
458 } else if (hasBackground) {
459 color = summaryColorWithBackground;
460 } else {
461 color = 'root.scopeStyle ? root.scopeStyle.foreground : "grey"';
462 }
464 var titleAnchors;
465 var subtitleAnchors;
466 var attributesAnchors;
467 if (hasMascot && (hasSubtitle || hasAttributes)) {
468 // Using row + column
469 titleAnchors = 'left: parent.left; right: parent.right';
470 subtitleAnchors = titleAnchors;
471 attributesAnchors = subtitleAnchors;
472 } else if (hasMascot) {
473 // Using row + label
474 titleAnchors = 'verticalCenter: parent.verticalCenter;\n'
475 } else {
476 if (headerAsOverlay) {
477 // Using anchors to the overlay
478 titleAnchors = 'left: parent.left; \n\
479 leftMargin: units.gu(1); \n\
480 right: parent.right; \n\
481 rightMargin: units.gu(1); \n\
482 top: overlayLoader.top; \n\
483 topMargin: units.gu(1);\n';
484 } else {
485 // Using anchors to the mascot/parent
486 titleAnchors = "right: parent.right;\n";
487 titleAnchors += "rightMargin: units.gu(1);\n";
488 titleAnchors += headerLeftAnchor;
489 titleAnchors += headerVerticalAnchors;
490 if (!headerLeftAnchorHasMargin) {
491 titleAnchors += 'leftMargin: units.gu(1);\n'
492 }
493 }
494 subtitleAnchors = 'left: titleLabel.left; \n\
495 leftMargin: titleLabel.leftMargin; \n\
496 right: titleLabel.right; \n\
497 rightMargin: titleLabel.rightMargin; \n\
498 top: titleLabel.bottom; \n\
499 topMargin: units.dp(2);\n';
500 if (hasSubtitle) {
501 attributesAnchors = 'left: subtitleLabel.left; \n\
502 leftMargin: subtitleLabel.leftMargin; \n\
503 right: subtitleLabel.right; \n\
504 rightMargin: subtitleLabel.rightMargin; \n\
505 top: subtitleLabel.bottom; \n\
506 topMargin: units.dp(2);\n';
507 } else {
508 attributesAnchors = subtitleAnchors;
509 }
510 }
512 var titleLabelVisibleExtra = (headerAsOverlay ? '&& overlayLoader.active': '');
513 var titleCode = kTitleLabelCode.arg(titleAnchors).arg(color).arg(titleLabelVisibleExtra);
514 var subtitleCode = "";
515 if (hasSubtitle) {
516 subtitleCode += kSubtitleLabelCode.arg(subtitleAnchors).arg(color);
517 }
519 if (hasMascot && (hasSubtitle || hasAttributes)) {
520 // If using row + column wrap the code in the column
521 titleSubtitleCode = kHeaderColumnCode.arg(titleCode).arg(subtitleCode);
522 if (hasSubtitle && hasAttributes) {
523 var attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(color);
524 titleSubtitleCode = kHeaderColumnCodeGenerator(titleCode, subtitleCode, attributesCode);
525 } else if (hasSubtitle) {
526 titleSubtitleCode = kHeaderColumnCode.arg(titleCode).arg(subtitleCode);
527 } else if (hasAttributes) {
528 var attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(color);
529 titleSubtitleCode = kHeaderColumnCode.arg(titleCode).arg(attributesCode);
530 }
531 } else {
532 titleSubtitleCode = titleCode;
533 if (hasSubtitle) {
534 titleSubtitleCode = titleSubtitleCode + subtitleCode;
535 }
536 if (hasAttributes) {
537 var attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(color);
538 titleSubtitleCode = titleSubtitleCode + attributesCode;
539 }
540 }
541 }
543 if (hasHeaderRow) {
544 if (mascotShapeCode != "") {
545 code += kHeaderRow3Code.arg(headerVerticalAnchors + headerLeftAnchor).arg(mascotShapeCode).arg(mascotCode).arg(titleSubtitleCode);
546 } else {
547 code += kHeaderRow2Code.arg(headerVerticalAnchors + headerLeftAnchor).arg(mascotCode).arg(titleSubtitleCode);
548 }
549 } else {
550 code += mascotShapeCode + mascotCode + titleSubtitleCode;
551 }
553 if (hasSummary) {
554 var summaryTopAnchor;
555 if (isHorizontal && hasArt) summaryTopAnchor = "artShapeHolder.bottom";
556 else if (headerAsOverlay && hasArt) summaryTopAnchor = "artShapeHolder.bottom";
557 else if (hasHeaderRow) summaryTopAnchor = "row.bottom";
558 else if (hasMascot) summaryTopAnchor = "mascotImage.bottom";
559 else if (hasAttributes) summaryTopAnchor = "attributesRow.bottom";
560 else if (hasSubtitle) summaryTopAnchor = "subtitleLabel.bottom";
561 else if (hasTitle) summaryTopAnchor = "titleLabel.bottom";
562 else if (hasArt) summaryTopAnchor = "artShapeHolder.bottom";
563 else summaryTopAnchor = "parent.top";
565 var color;
566 if (hasBackground) {
567 color = summaryColorWithBackground;
568 } else {
569 color = 'root.scopeStyle ? root.scopeStyle.foreground : "grey"';
570 }
572 var summaryTopMargin = (hasMascot || hasSubtitle || hasAttributes ? 'anchors.margins' : '0');
574 code += kSummaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(color);
575 }
577 var touchdownAnchors;
578 if (hasBackground) {
579 touchdownAnchors = 'fill: backgroundLoader';
580 } else if (hasArt && !hasMascot && !hasSummary) {
581 touchdownAnchors = 'fill: artShapeHolder';
582 } else {
583 touchdownAnchors = 'fill: root'
584 }
585 code += kTouchdownCode.arg(touchdownAnchors);
587 if (hasSummary) {
588 code += 'implicitHeight: summary.y + summary.height + (summary.text ? units.gu(1) : 0);\n';
589 } else if (hasHeaderRow) {
590 code += 'implicitHeight: row.y + row.height + units.gu(1);\n';
591 } else if (hasMascot) {
592 code += 'implicitHeight: mascotImage.y + mascotImage.height;\n';
593 } else if (hasAttributes) {
594 code += 'implicitHeight: attributesRow.y + attributesRow.height + units.gu(1);\n';
595 } else if (hasSubtitle) {
596 code += 'implicitHeight: subtitleLabel.y + subtitleLabel.height + units.gu(1);\n';
597 } else if (hasTitle) {
598 code += 'implicitHeight: titleLabel.y + titleLabel.height + units.gu(1);\n';
599 } else if (hasArt) {
600 code += 'implicitHeight: artShapeHolder.height;\n';
601 }
602 // Close the AbstractButton
603 code += '}\n';
605 return code;
608function createCardComponent(parent, template, components) {
609 var imports = 'import QtQuick 2.2; \n\
610 import Ubuntu.Components 0.1; \n\
611 import Dash 0.1;\n';
612 var card = cardString(template, components);
613 var code = imports + 'Component {\n' + card + '}\n';
615 return Qt.createQmlObject(code, parent, "createCardComponent");