on 4e12dee help sign in
unity8/plugins/Dash/CardCreator.js
658 lines 33 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: Style.luminance(color); \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: Style.luminance(overlayColor); \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// multiple row version of HeaderRowCode
142function kHeaderRowCodeGenerator() {
143var kHeaderRowCodeTemplate = '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 anchors.rightMargin: 0; \n\
153 data: [ \n\
154 %2 \n\
155 ] \n\
156 }\n';
157 var args = Array.prototype.slice.call(arguments);
158 var code = kHeaderRowCodeTemplate.arg(args.shift()).arg(args.join(',\n'));
159 return code;
162// multiple item version of kHeaderContainerCode
163function kHeaderContainerCodeGenerator() {
164 var headerContainerCodeTemplate = 'Item { \n\
165 id: headerTitleContainer; \n\
166 anchors { %1 } \n\
167 width: parent.width - x; \n\
168 implicitHeight: %2; \n\
169 data: [ \n\
170 %3 \n\
171 ]\n\
172 }\n';
173 var args = Array.prototype.slice.call(arguments);
174 var code = headerContainerCodeTemplate.arg(args.shift()).arg(args.shift()).arg(args.join(',\n'));
175 return code;
178// %1 is used as anchors of mascotShapeLoader
179var kMascotShapeLoaderCode = 'Loader { \n\
180 id: mascotShapeLoader; \n\
181 objectName: "mascotShapeLoader"; \n\
182 asynchronous: root.asynchronous; \n\
183 active: mascotImage.status === Image.Ready; \n\
184 visible: showHeader && active && status == Loader.Ready; \n\
185 width: units.gu(6); \n\
186 height: units.gu(5.625); \n\
187 sourceComponent: UbuntuShape { image: mascotImage } \n\
188 anchors { %1 } \n\
189 }\n';
191// %1 is used as anchors of mascotImage
192// %2 is used as visible of mascotImage
193var kMascotImageCode = 'Image { \n\
194 id: mascotImage; \n\
195 objectName: "mascotImage"; \n\
196 anchors { %1 } \n\
197 readonly property int maxSize: Math.max(width, height) * 4; \n\
198 source: cardData && cardData["mascot"] || ""; \n\
199 width: units.gu(6); \n\
200 height: units.gu(5.625); \n\
201 sourceSize { width: maxSize; height: maxSize } \n\
202 fillMode: Image.PreserveAspectCrop; \n\
203 horizontalAlignment: Image.AlignHCenter; \n\
204 verticalAlignment: Image.AlignVCenter; \n\
205 visible: %2; \n\
206 }\n';
208// %1 is used as anchors of titleLabel
209// %2 is used as color of titleLabel
210// %3 is used as extra condition for visible of titleLabel
211var kTitleLabelCode = 'Label { \n\
212 id: titleLabel; \n\
213 objectName: "titleLabel"; \n\
214 anchors { %1 } \n\
215 elide: Text.ElideRight; \n\
216 fontSize: "small"; \n\
217 wrapMode: Text.Wrap; \n\
218 maximumLineCount: 2; \n\
219 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
220 color: %2; \n\
221 visible: showHeader %3; \n\
222 text: root.title; \n\
223 font.weight: components && components["subtitle"] ? Font.DemiBold : Font.Normal; \n\
224 horizontalAlignment: root.headerAlignment; \n\
225 }\n';
227// %1 is used as extra anchors of emblemIcon
228// %2 is used as color of emblemIcon
229var kEmblemIconCode = 'Icon { \n\
230 id: emblemIcon; \n\
231 objectName: "emblemIcon"; \n\
232 anchors { \n\
233 bottom: titleLabel.baseline; \n\
234 right: parent.right; \n\
235 %1
236 } \n\
237 source: cardData && cardData["emblem"] || ""; \n\
238 color: %2; \n\
239 width: height; \n\
240 height: source != "" ? titleLabel.font.pixelSize : 0; \n\
241 }\n';
243// %1 is used as anchors of touchdown effect
244var kTouchdownCode = 'UbuntuShape { \n\
245 id: touchdown; \n\
246 objectName: "touchdown"; \n\
247 anchors { %1 } \n\
248 visible: root.pressed; \n\
249 radius: "medium"; \n\
250 borderSource: "radius_pressed.sci" \n\
251 }\n';
253// %1 is used as anchors of subtitleLabel
254// %2 is used as color of subtitleLabel
255var kSubtitleLabelCode = 'Label { \n\
256 id: subtitleLabel; \n\
257 objectName: "subtitleLabel"; \n\
258 anchors { %1 } \n\
259 anchors.topMargin: units.dp(2); \n\
260 elide: Text.ElideRight; \n\
261 fontSize: "small"; \n\
262 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
263 color: %2; \n\
264 visible: titleLabel.visible && titleLabel.text; \n\
265 text: cardData && cardData["subtitle"] || ""; \n\
266 font.weight: Font.Light; \n\
267 horizontalAlignment: root.headerAlignment; \n\
268 }\n';
270// %1 is used as anchors of attributesRow
271// %2 is used as color of attributesRow
272var kAttributesRowCode = 'CardAttributes { \n\
273 id: attributesRow; \n\
274 objectName: "attributesRow"; \n\
275 anchors { %1 } \n\
276 color: %2; \n\
277 model: cardData && cardData["attributes"]; \n\
278 }\n';
280// %1 is used as top anchor of summary
281// %2 is used as topMargin anchor of summary
282// %3 is used as color of summary
283var kSummaryLabelCode = 'Label { \n\
284 id: summary; \n\
285 objectName: "summaryLabel"; \n\
286 anchors { \n\
287 top: %1; \n\
288 left: parent.left; \n\
289 right: parent.right; \n\
290 margins: units.gu(1); \n\
291 topMargin: %2; \n\
292 } \n\
293 wrapMode: Text.Wrap; \n\
294 maximumLineCount: 5; \n\
295 elide: Text.ElideRight; \n\
296 text: cardData && cardData["summary"] || ""; \n\
297 height: text ? implicitHeight : 0; \n\
298 fontSize: "small"; \n\
299 color: %3; \n\
300 }\n';
302function cardString(template, components) {
303 var code;
304 code = 'AbstractButton { \n\
305 id: root; \n\
306 property var template; \n\
307 property var components; \n\
308 property var cardData; \n\
309 property var artShapeBorderSource: undefined; \n\
310 property real fontScale: 1.0; \n\
311 property var scopeStyle: null; \n\
312 property int headerAlignment: Text.AlignLeft; \n\
313 property int fixedHeaderHeight: -1; \n\
314 property size fixedArtShapeSize: Qt.size(-1, -1); \n\
315 readonly property string title: cardData && cardData["title"] || ""; \n\
316 property bool asynchronous: true; \n\
317 property bool showHeader: true; \n\
318 implicitWidth: childrenRect.width; \n';
320 var hasArt = components["art"] && components["art"]["field"] || false;
321 var hasSummary = components["summary"] || false;
322 var artAndSummary = hasArt && hasSummary;
323 var isHorizontal = template["card-layout"] === "horizontal";
324 var hasBackground = !isHorizontal && (template["card-background"] || components["background"] || artAndSummary);
325 var hasTitle = components["title"] || false;
326 var hasMascot = components["mascot"] || false;
327 var hasEmblem = components["emblem"] && !(hasMascot && template["card-size"] === "small") || false;
328 var headerAsOverlay = hasArt && template && template["overlay"] === true && (hasTitle || hasMascot);
329 var hasSubtitle = hasTitle && components["subtitle"] || false;
330 var hasHeaderRow = hasMascot && hasTitle;
331 var hasAttributes = hasTitle && components["attributes"]["field"] || false;
333 if (hasBackground) {
334 code += kBackgroundLoaderCode;
335 }
337 if (hasArt) {
338 code += 'onArtShapeBorderSourceChanged: { if (artShapeBorderSource !== undefined && artShapeLoader.item) artShapeLoader.item.borderSource = artShapeBorderSource; } \n';
339 code += 'readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);\n';
341 var widthCode, heightCode;
342 var artAnchors;
343 if (isHorizontal) {
344 artAnchors = 'left: parent.left';
345 if (hasMascot || hasTitle) {
346 widthCode = 'height * artShape.aspect'
347 heightCode = 'headerHeight + 2 * units.gu(1)';
348 } else {
349 // This side of the else is a bit silly, who wants an horizontal layout without mascot and title?
350 // So we define a "random" height of the image height + 2 gu for the margins
351 widthCode = 'height * artShape.aspect'
352 heightCode = 'units.gu(7.625)';
353 }
354 } else {
355 artAnchors = 'horizontalCenter: parent.horizontalCenter;';
356 widthCode = 'root.width'
357 heightCode = 'width / artShape.aspect';
358 }
360 code += kArtShapeHolderCode.arg(artAnchors).arg(widthCode).arg(heightCode);
361 } else {
362 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
363 }
365 if (headerAsOverlay) {
366 code += kOverlayLoaderCode;
367 }
369 var headerVerticalAnchors;
370 if (headerAsOverlay) {
371 headerVerticalAnchors = 'bottom: artShapeHolder.bottom; \n\
372 bottomMargin: units.gu(1);\n';
373 } else {
374 if (hasArt) {
375 if (isHorizontal) {
376 headerVerticalAnchors = 'top: artShapeHolder.top; \n\
377 topMargin: units.gu(1);\n';
378 } else {
379 headerVerticalAnchors = 'top: artShapeHolder.bottom; \n\
380 topMargin: units.gu(1);\n';
381 }
382 } else {
383 headerVerticalAnchors = 'top: parent.top; \n\
384 topMargin: units.gu(1);\n';
385 }
386 }
387 var headerLeftAnchor;
388 var headerLeftAnchorHasMargin = false;
389 if (isHorizontal && hasArt) {
390 headerLeftAnchor = 'left: artShapeHolder.right; \n\
391 leftMargin: units.gu(1);\n';
392 headerLeftAnchorHasMargin = true;
393 } else {
394 headerLeftAnchor = 'left: parent.left;\n';
395 }
397 var touchdownOnArtShape = !hasBackground && hasArt && !hasMascot && !hasSummary;
399 if (hasHeaderRow) {
400 code += 'readonly property int headerHeight: row.height;\n'
401 } else if (hasMascot) {
402 code += 'readonly property int headerHeight: mascotImage.height;\n'
403 } else if (hasAttributes) {
404 if (hasTitle && hasSubtitle) {
405 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + attributesRow.height + attributesRow.anchors.topMargin;\n'
406 } else if (hasTitle) {
407 code += 'readonly property int headerHeight: titleLabel.height + attributesRow.height + attributesRow.anchors.topMargin;\n'
408 } else {
409 code += 'readonly property int headerHeight: attributesRow.height;\n'
410 }
411 } else if (hasSubtitle) {
412 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin;\n'
413 } else if (hasTitle) {
414 code += 'readonly property int headerHeight: titleLabel.height;\n'
415 } else {
416 code += 'readonly property int headerHeight: 0;\n'
417 }
419 var mascotShapeCode = '';
420 var mascotCode = '';
421 if (hasMascot) {
422 var useMascotShape = !hasBackground && !headerAsOverlay;
423 var mascotAnchors = '';
424 if (!hasHeaderRow) {
425 mascotAnchors += headerLeftAnchor;
426 mascotAnchors += headerVerticalAnchors;
427 if (!headerLeftAnchorHasMargin) {
428 mascotAnchors += 'leftMargin: units.gu(1);\n'
429 }
430 } else {
431 mascotAnchors = 'verticalCenter: parent.verticalCenter;'
432 }
434 if (useMascotShape) {
435 mascotShapeCode = kMascotShapeLoaderCode.arg(mascotAnchors);
436 }
438 var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
439 mascotCode = kMascotImageCode.arg(mascotAnchors).arg(mascotImageVisible);
440 }
442 var summaryColorWithBackground = 'backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item.luminance > 0.7 ? Theme.palette.normal.baseText : "white")';
444 var hasTitleContainer = hasTitle && (hasEmblem || (hasMascot && (hasSubtitle || hasAttributes)));
445 var titleSubtitleCode = '';
446 if (hasTitle) {
447 var titleColor;
448 if (headerAsOverlay) {
449 titleColor = 'root.scopeStyle ? root.scopeStyle.getTextColor(overlayLoader.item.luminance) : (overlayLoader.item.luminance > 0.7 ? Theme.palette.normal.baseText : "white")';
450 } else if (hasSummary) {
451 titleColor = 'summary.color';
452 } else if (hasBackground) {
453 titleColor = summaryColorWithBackground;
454 } else {
455 titleColor = 'root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText';
456 }
458 var titleAnchors;
459 var subtitleAnchors;
460 var attributesAnchors;
461 var titleContainerAnchors;
462 var titleRightAnchor;
464 var extraRightAnchor = '';
465 var extraLeftAnchor = '';
466 if (!touchdownOnArtShape) {
467 extraRightAnchor = 'rightMargin: units.gu(1); \n';
468 extraLeftAnchor = 'leftMargin: units.gu(1); \n';
469 }
471 if (hasMascot) {
472 titleContainerAnchors = 'verticalCenter: parent.verticalCenter; ';
473 } else {
474 titleContainerAnchors = 'right: parent.right; ';
475 titleContainerAnchors += headerLeftAnchor;
476 titleContainerAnchors += headerVerticalAnchors;
477 if (!headerLeftAnchorHasMargin) {
478 titleContainerAnchors += extraLeftAnchor;
479 }
480 }
481 if (hasEmblem) {
482 titleRightAnchor = 'right: emblemIcon.left; \n\
483 rightMargin: emblemIcon.width > 0 ? units.gu(0.5) : 0; \n';
484 } else {
485 titleRightAnchor = 'right: parent.right; \n'
486 titleRightAnchor += extraRightAnchor;
487 }
489 if (hasTitleContainer) {
490 // Using headerTitleContainer
491 titleAnchors = titleRightAnchor;
492 titleAnchors += 'left: parent.left; \n\
493 top: parent.top;';
494 subtitleAnchors = 'right: parent.right; \n\
495 left: parent.left; \n';
496 subtitleAnchors += extraRightAnchor;
497 if (hasSubtitle) {
498 attributesAnchors = subtitleAnchors + 'top: subtitleLabel.bottom;\n';
499 subtitleAnchors += 'top: titleLabel.bottom;\n';
500 } else {
501 attributesAnchors = subtitleAnchors + 'top: titleLabel.bottom;\n';
502 }
503 } else if (hasMascot) {
504 // Using row + titleContainer
505 titleAnchors = 'verticalCenter: parent.verticalCenter;\n';
506 } else {
507 if (headerAsOverlay) {
508 // Using anchors to the overlay
509 titleAnchors = titleRightAnchor;
510 titleAnchors += 'left: parent.left; \n\
511 leftMargin: units.gu(1); \n\
512 top: overlayLoader.top; \n\
513 topMargin: units.gu(1);\n';
514 } else {
515 // Using anchors to the mascot/parent
516 titleAnchors = titleRightAnchor;
517 titleAnchors += headerLeftAnchor;
518 titleAnchors += headerVerticalAnchors;
519 if (!headerLeftAnchorHasMargin) {
520 titleAnchors += extraLeftAnchor;
521 }
522 }
523 subtitleAnchors = 'left: titleLabel.left; \n\
524 leftMargin: titleLabel.leftMargin; \n';
525 subtitleAnchors += extraRightAnchor;
526 if (hasEmblem) {
527 // using container
528 subtitleAnchors += 'right: parent.right; \n';
529 } else {
530 subtitleAnchors += 'right: titleLabel.right; \n';
531 }
533 if (hasSubtitle) {
534 attributesAnchors = subtitleAnchors + 'top: subtitleLabel.bottom;\n';
535 subtitleAnchors += 'top: titleLabel.bottom;\n';
536 } else {
537 attributesAnchors = subtitleAnchors + 'top: titleLabel.bottom;\n';
538 }
539 }
541 // code for different elements
542 var titleLabelVisibleExtra = (headerAsOverlay ? '&& overlayLoader.active': '');
543 var titleCode = kTitleLabelCode.arg(titleAnchors).arg(titleColor).arg(titleLabelVisibleExtra);
544 var subtitleCode;
545 var attributesCode;
547 // code for the title container
548 var containerCode = [];
549 var containerHeight = 'titleLabel.height';
550 containerCode.push(titleCode);
551 if (hasSubtitle) {
552 subtitleCode = kSubtitleLabelCode.arg(subtitleAnchors).arg(titleColor);
553 containerCode.push(subtitleCode);
554 containerHeight += ' + subtitleLabel.height';
555 }
556 if (hasEmblem) {
557 containerCode.push(kEmblemIconCode.arg(extraRightAnchor).arg(titleColor));
558 }
559 if (hasAttributes) {
560 attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(titleColor);
561 containerCode.push(attributesCode);
562 containerHeight += ' + attributesRow.height';
563 }
565 if (hasTitleContainer) {
566 // use container
567 titleSubtitleCode = kHeaderContainerCodeGenerator(titleContainerAnchors, containerHeight, containerCode);
568 } else {
569 // no container
570 titleSubtitleCode = titleCode;
571 if (hasSubtitle) {
572 titleSubtitleCode += subtitleCode;
573 }
574 if (hasAttributes) {
575 titleSubtitleCode += attributesCode;
576 }
577 }
578 }
580 if (hasHeaderRow) {
581 var rowCode = [mascotCode, titleSubtitleCode];
582 if (mascotShapeCode != '') {
583 rowCode.unshift(mascotShapeCode);
584 }
585 code += kHeaderRowCodeGenerator(headerVerticalAnchors + headerLeftAnchor, rowCode)
586 } else {
587 code += mascotShapeCode + mascotCode + titleSubtitleCode;
588 }
590 if (hasSummary) {
591 var summaryTopAnchor;
592 if (isHorizontal && hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
593 else if (headerAsOverlay && hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
594 else if (hasHeaderRow) summaryTopAnchor = 'row.bottom';
595 else if (hasTitleContainer) summaryTopAnchor = 'headerTitleContainer.bottom';
596 else if (hasMascot) summaryTopAnchor = 'mascotImage.bottom';
597 else if (hasAttributes) summaryTopAnchor = 'attributesRow.bottom';
598 else if (hasSubtitle) summaryTopAnchor = 'subtitleLabel.bottom';
599 else if (hasTitle) summaryTopAnchor = 'titleLabel.bottom';
600 else if (hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
601 else summaryTopAnchor = 'parent.top';
603 var summaryColor;
604 if (hasBackground) {
605 summaryColor = summaryColorWithBackground;
606 } else {
607 summaryColor = 'root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText';
608 }
610 var summaryTopMargin = (hasMascot || hasSubtitle || hasAttributes ? 'anchors.margins' : '0');
612 code += kSummaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(summaryColor);
613 }
615 var touchdownAnchors;
616 if (hasBackground) {
617 touchdownAnchors = 'fill: backgroundLoader';
618 } else if (touchdownOnArtShape) {
619 touchdownAnchors = 'fill: artShapeHolder';
620 } else {
621 touchdownAnchors = 'fill: root'
622 }
623 code += kTouchdownCode.arg(touchdownAnchors);
625 var implicitHeight = 'implicitHeight: ';
626 if (hasSummary) {
627 implicitHeight += 'summary.y + summary.height + (summary.text ? units.gu(1) : 0);\n';
628 } else if (hasHeaderRow) {
629 implicitHeight += 'row.y + row.height + units.gu(1);\n';
630 } else if (hasMascot) {
631 implicitHeight += 'mascotImage.y + mascotImage.height;\n';
632 } else if (hasTitleContainer) {
633 implicitHeight += 'headerTitleContainer.y + headerTitleContainer.height + units.gu(1);\n';
634 } else if (hasAttributes) {
635 implicitHeight += 'attributesRow.y + attributesRow.height + units.gu(1);\n';
636 } else if (hasSubtitle) {
637 implicitHeight += 'subtitleLabel.y + subtitleLabel.height + units.gu(1);\n';
638 } else if (hasTitle) {
639 implicitHeight += 'titleLabel.y + titleLabel.height + units.gu(1);\n';
640 } else if (hasArt) {
641 implicitHeight += 'artShapeHolder.height;\n';
642 }
643 // Close the AbstractButton
644 code += implicitHeight + '}\n';
646 return code;
649function createCardComponent(parent, template, components) {
650 var imports = 'import QtQuick 2.2; \n\
651 import Ubuntu.Components 1.1; \n\
652 import Dash 0.1;\n\
653 import Utils 0.1;\n';
654 var card = cardString(template, components);
655 var code = imports + 'Component {\n' + card + '}\n';
657 return Qt.createQmlObject(code, parent, "createCardComponent");