2 * Copyright (C) 2014 Canonical, Ltd.
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.
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.
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/>.
19// %1 is the template["card-background"] string
20// %2 is the template["card-background"]["elements"][0]
21// %3 is the template["card-background"]["elements"][1]
22var kBackgroundLoaderCode = 'Loader {\n\
23 id: backgroundLoader; \n\
24 objectName: "backgroundLoader"; \n\
25 anchors.fill: parent; \n\
26 asynchronous: root.asynchronous; \n\
27 visible: status == Loader.Ready; \n\
28 sourceComponent: UbuntuShape { \n\
29 objectName: "background"; \n\
31 backgroundColor: getColor(0) || "white"; \n\
32 secondaryBackgroundColor: getColor(1) || backgroundColor; \n\
33 backgroundMode: cardData && typeof cardData["background"] === "object" && cardData["background"]["type"] === "gradient" ? UbuntuShape.VerticalGradient : UbuntuShape.SolidColor; \n\
34 anchors.fill: parent; \n\
35 source: backgroundImage.source ? backgroundImage : null; \n\
36 property real luminance: Style.luminance(backgroundColor); \n\
37 property Image backgroundImage: Image { \n\
38 objectName: "backgroundImage"; \n\
40 if (cardData && typeof cardData["background"] === "string") return cardData["background"]; \n\
44 function getColor(index) { \n\
45 if (cardData && typeof cardData["background"] === "object" \n\
46 && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) { \n\
47 return cardData["background"]["elements"][index]; \n\
48 } else return index === 0 ? %2 : %3; \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\
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: Item { \n\
69 objectName: "artShape"; \n\
70 readonly property bool doShapeItem: components["art"]["conciergeMode"] !== true; \n\
71 visible: image.status == Image.Ready; \n\
72 readonly property alias image: artImage.image; \n\
73 ShaderEffectSource { \n\
74 id: artShapeSource; \n\
75 sourceItem: artImage; \n\
76 anchors.centerIn: parent; \n\
79 hideSource: doShapeItem; \n\
82 anchors.fill: parent; \n\
83 visible: artShape.doShapeItem; \n\
84 sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent; \n\
86 id: artShapeShapeComponent; \n\
88 source: artShapeSource; \n\
89 sourceFillMode: UbuntuShape.PreserveAspectCrop; \n\
92 switch (root.artShapeStyle) { \n\
93 case "inset": return UbuntuShape.Inset; \n\
94 case "shadow": return UbuntuShape.DropShadow; \n\
96 case "flat": return UbuntuShape.Flat; \n\
102 id: artShapeIconComponent; \n\
103 UbuntuShapeIcon { source: artShapeSource; } \n\
106 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1; \n\
107 readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1; \n\
108 Component.onCompleted: { updateWidthHeightBindings(); } \n\
109 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); } \n\
110 function updateWidthHeightBindings() { \n\
111 if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) { \n\
112 width = root.fixedArtShapeSize.width; \n\
113 height = root.fixedArtShapeSize.height; \n\
115 width = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.width }); \n\
116 height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height }); \n\
119 CroppedImageMinimumSourceSize { \n\
121 objectName: "artImage"; \n\
122 source: cardData && cardData["art"] || ""; \n\
123 asynchronous: root.asynchronous; \n\
131var kOverlayLoaderCode = 'Loader { \n\
132 id: overlayLoader; \n\
133 readonly property real overlayHeight: (fixedHeaderHeight > 0 ? fixedHeaderHeight : headerHeight) + units.gu(2); \n\
134 anchors.fill: artShapeHolder; \n\
135 active: artShapeLoader.active && artShapeLoader.item && artShapeLoader.item.image.status === Image.Ready || false; \n\
136 asynchronous: root.asynchronous; \n\
137 visible: showHeader && status == Loader.Ready; \n\
138 sourceComponent: UbuntuShapeOverlay { \n\
140 property real luminance: Style.luminance(overlayColor); \n\
141 aspect: UbuntuShape.Flat; \n\
142 radius: "medium"; \n\
143 overlayColor: cardData && cardData["overlayColor"] || "#99000000"; \n\
144 overlayRect: Qt.rect(0, 1 - overlayLoader.overlayHeight / height, 1, 1); \n\
148// multiple row version of HeaderRowCode
149function kHeaderRowCodeGenerator() {
150 var kHeaderRowCodeTemplate = 'Row { \n\
152 objectName: "outerRow"; \n\
153 property real margins: units.gu(1); \n\
154 spacing: margins; \n\
155 height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight; \n\
157 anchors.right: parent.right; \n\
158 anchors.margins: margins; \n\
159 anchors.rightMargin: 0; \n\
164 var args = Array.prototype.slice.call(arguments);
165 var code = kHeaderRowCodeTemplate.arg(args.shift()).arg(args.join(',\n'));
169// multiple item version of kHeaderContainerCode
170function kHeaderContainerCodeGenerator() {
171 var headerContainerCodeTemplate = 'Item { \n\
172 id: headerTitleContainer; \n\
174 width: parent.width - x; \n\
175 implicitHeight: %2; \n\
180 var args = Array.prototype.slice.call(arguments);
181 var code = headerContainerCodeTemplate.arg(args.shift()).arg(args.shift()).arg(args.join(',\n'));
185// %1 is used as anchors of mascotShapeLoader
186var kMascotShapeLoaderCode = 'Loader { \n\
187 id: mascotShapeLoader; \n\
188 objectName: "mascotShapeLoader"; \n\
189 asynchronous: root.asynchronous; \n\
190 active: mascotImage.image.status === Image.Ready; \n\
191 visible: showHeader && active && status == Loader.Ready; \n\
192 width: units.gu(6); \n\
193 height: units.gu(5.625); \n\
194 sourceComponent: UbuntuShape { image: mascotImage.image } \n\
198// %1 is used as anchors of mascotImage
199// %2 is used as visible of mascotImage
200var kMascotImageCode = 'CroppedImageMinimumSourceSize { \n\
202 objectName: "mascotImage"; \n\
204 source: cardData && cardData["mascot"] || ""; \n\
205 width: units.gu(6); \n\
206 height: units.gu(5.625); \n\
207 horizontalAlignment: Image.AlignHCenter; \n\
208 verticalAlignment: Image.AlignVCenter; \n\
212// %1 is used as anchors of titleLabel
213// %2 is used as color of titleLabel
214// %3 is used as extra condition for visible of titleLabel
215// %4 is used as title width
216var kTitleLabelCode = 'Label { \n\
218 objectName: "titleLabel"; \n\
220 elide: Text.ElideRight; \n\
221 fontSize: "small"; \n\
222 wrapMode: Text.Wrap; \n\
223 maximumLineCount: 2; \n\
224 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
226 visible: showHeader %3; \n\
228 text: root.title; \n\
229 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal; \n\
230 horizontalAlignment: root.titleAlignment; \n\
233// %1 is used as extra anchors of emblemIcon
234// %2 is used as color of emblemIcon
235// FIXME The width code is a
236// Workaround for bug https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1421293
237var kEmblemIconCode = 'Icon { \n\
239 objectName: "emblemIcon"; \n\
241 bottom: titleLabel.baseline; \n\
242 right: parent.right; \n\
245 source: cardData && cardData["emblem"] || ""; \n\
247 height: source != "" ? titleLabel.font.pixelSize : 0; \n\
248 width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth; \n\
251// %1 is used as anchors of touchdown effect
252var kTouchdownCode = 'UbuntuShape { \n\
254 objectName: "touchdown"; \n\
256 visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed; \n\
257 radius: "medium"; \n\
258 borderSource: "radius_pressed.sci" \n\
261// %1 is used as anchors of subtitleLabel
262// %2 is used as color of subtitleLabel
263var kSubtitleLabelCode = 'Label { \n\
264 id: subtitleLabel; \n\
265 objectName: "subtitleLabel"; \n\
267 anchors.topMargin: units.dp(2); \n\
268 elide: Text.ElideRight; \n\
269 maximumLineCount: 1; \n\
270 fontSize: "x-small"; \n\
271 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
273 visible: titleLabel.visible && titleLabel.text; \n\
274 text: cardData && cardData["subtitle"] || ""; \n\
275 font.weight: Font.Light; \n\
278// %1 is used as anchors of attributesRow
279// %2 is used as color of attributesRow
280var kAttributesRowCode = 'CardAttributes { \n\
281 id: attributesRow; \n\
282 objectName: "attributesRow"; \n\
285 fontScale: root.fontScale; \n\
286 model: cardData && cardData["attributes"]; \n\
289// %1 is used as top anchor of summary
290// %2 is used as topMargin anchor of summary
291// %3 is used as color of summary
292var kSummaryLabelCode = 'Label { \n\
294 objectName: "summaryLabel"; \n\
297 left: parent.left; \n\
298 right: parent.right; \n\
299 margins: units.gu(1); \n\
302 wrapMode: Text.Wrap; \n\
303 maximumLineCount: 5; \n\
304 elide: Text.ElideRight; \n\
305 text: cardData && cardData["summary"] || ""; \n\
306 height: text ? implicitHeight : 0; \n\
307 fontSize: "small"; \n\
311function cardString(template, components) {
314 var templateInteractive = (template == null ? true : (template["non-interactive"] !== undefined ? !template["non-interactive"] : true)) ? "true" : "false";
316 code = 'AbstractButton { \n\
318 property var components; \n\
319 property var cardData; \n\
320 property string artShapeStyle: "inset"; \n\
321 property real fontScale: 1.0; \n\
322 property var scopeStyle: null; \n\
323 property int titleAlignment: 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 \n'.arg(templateInteractive);
333 var hasArt = components["art"] && components["art"]["field"] || false;
334 var hasSummary = components["summary"] || false;
335 var artAndSummary = hasArt && hasSummary && components["art"]["conciergeMode"] !== true;
336 var isHorizontal = template["card-layout"] === "horizontal";
337 var hasBackground = (!isHorizontal && (template["card-background"] || components["background"] || artAndSummary)) ||
338 (hasSummary && (template["card-background"] || components["background"]));
339 var hasTitle = components["title"] || false;
340 var hasMascot = components["mascot"] || false;
341 var hasEmblem = components["emblem"] && !(hasMascot && template["card-size"] === "small") || false;
342 var headerAsOverlay = hasArt && template && template["overlay"] === true && (hasTitle || hasMascot);
343 var hasSubtitle = hasTitle && components["subtitle"] || false;
344 var hasHeaderRow = hasMascot && hasTitle;
345 var hasAttributes = hasTitle && components["attributes"]["field"] || false;
348 var templateCardBackground = (template && typeof template["card-background"] === "string") ? template["card-background"] : "";
349 var backgroundElements0;
350 var backgroundElements1;
351 if (template && typeof template["card-background"] === "object" && (template["card-background"]["type"] === "color" || template["card-background"]["type"] === "gradient")) {
352 if (template["card-background"]["elements"][0] !== undefined) {
353 backgroundElements0 = '"%1"'.arg(template["card-background"]["elements"][0]);
355 if (template["card-background"]["elements"][1] !== undefined) {
356 backgroundElements1 = '"%1"'.arg(template["card-background"]["elements"][1]);
359 code += kBackgroundLoaderCode.arg(templateCardBackground).arg(backgroundElements0).arg(backgroundElements1);
363 code += 'readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);\n';
365 var widthCode, heightCode;
368 artAnchors = 'left: parent.left';
369 if (hasMascot || hasTitle) {
370 widthCode = 'height * artShape.aspect'
371 heightCode = 'headerHeight + 2 * units.gu(1)';
373 // This side of the else is a bit silly, who wants an horizontal layout without mascot and title?
374 // So we define a "random" height of the image height + 2 gu for the margins
375 widthCode = 'height * artShape.aspect'
376 heightCode = 'units.gu(7.625)';
379 artAnchors = 'horizontalCenter: parent.horizontalCenter;';
380 widthCode = 'root.width'
381 heightCode = 'width / artShape.aspect';
384 code += kArtShapeHolderCode.arg(artAnchors).arg(widthCode).arg(heightCode);
385 var fallback = components["art"] && components["art"]["fallback"] || "";
386 if (fallback !== "") {
387 code += 'Connections { target: artShapeLoader.item ? artShapeLoader.item.image : null; onStatusChanged: if (artShapeLoader.item.image.status === Image.Error) artShapeLoader.item.image.source = "%1"; } \n'.arg(fallback);
390 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
393 if (headerAsOverlay) {
394 code += kOverlayLoaderCode;
397 var headerVerticalAnchors;
398 if (headerAsOverlay) {
399 headerVerticalAnchors = 'bottom: artShapeHolder.bottom; \n\
400 bottomMargin: units.gu(1);\n';
404 headerVerticalAnchors = 'top: artShapeHolder.top; \n\
405 topMargin: units.gu(1);\n';
407 headerVerticalAnchors = 'top: artShapeHolder.bottom; \n\
408 topMargin: units.gu(1);\n';
411 headerVerticalAnchors = 'top: parent.top; \n\
412 topMargin: units.gu(1);\n';
415 var headerLeftAnchor;
416 var headerLeftAnchorHasMargin = false;
417 if (isHorizontal && hasArt) {
418 headerLeftAnchor = 'left: artShapeHolder.right; \n\
419 leftMargin: units.gu(1);\n';
420 headerLeftAnchorHasMargin = true;
422 headerLeftAnchor = 'left: parent.left;\n';
425 var touchdownOnArtShape = !hasBackground && hasArt && !hasMascot && !hasSummary;
428 code += 'readonly property int headerHeight: row.height;\n'
429 } else if (hasMascot) {
430 code += 'readonly property int headerHeight: mascotImage.height;\n'
431 } else if (hasAttributes) {
432 if (hasTitle && hasSubtitle) {
433 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + attributesRow.height + attributesRow.anchors.topMargin;\n'
434 } else if (hasTitle) {
435 code += 'readonly property int headerHeight: titleLabel.height + attributesRow.height + attributesRow.anchors.topMargin;\n'
437 code += 'readonly property int headerHeight: attributesRow.height;\n'
439 } else if (hasSubtitle) {
440 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin;\n'
441 } else if (hasTitle) {
442 code += 'readonly property int headerHeight: titleLabel.height;\n'
444 code += 'readonly property int headerHeight: 0;\n'
447 var mascotShapeCode = '';
450 var useMascotShape = !hasBackground && !headerAsOverlay;
451 var mascotAnchors = '';
453 mascotAnchors += headerLeftAnchor;
454 mascotAnchors += headerVerticalAnchors;
455 if (!headerLeftAnchorHasMargin) {
456 mascotAnchors += 'leftMargin: units.gu(1);\n'
459 mascotAnchors = 'verticalCenter: parent.verticalCenter;'
462 if (useMascotShape) {
463 mascotShapeCode = kMascotShapeLoaderCode.arg(mascotAnchors);
466 var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
467 mascotCode = kMascotImageCode.arg(mascotAnchors).arg(mascotImageVisible);
468 var fallback = components["mascot"] && components["mascot"]["fallback"] || "";
469 if (fallback !== "") {
470 code += 'Connections { target: mascotImage.image; onStatusChanged: if (mascotImage.image.status === Image.Error) mascotImage.source = "%1"; } \n'.arg(fallback);
474 var summaryColorWithBackground = 'backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white")';
476 var hasTitleContainer = hasTitle && (hasEmblem || (hasMascot && (hasSubtitle || hasAttributes)));
477 var titleSubtitleCode = '';
480 if (headerAsOverlay) {
481 titleColor = 'root.scopeStyle && overlayLoader.item ? root.scopeStyle.getTextColor(overlayLoader.item.luminance) : (overlayLoader.item && overlayLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white")';
482 } else if (hasSummary) {
483 titleColor = 'summary.color';
484 } else if (hasBackground) {
485 titleColor = summaryColorWithBackground;
487 titleColor = 'root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText';
492 var attributesAnchors;
493 var titleContainerAnchors;
494 var titleRightAnchor;
495 var titleWidth = "undefined";
497 var extraRightAnchor = '';
498 var extraLeftAnchor = '';
499 if (!touchdownOnArtShape) {
500 extraRightAnchor = 'rightMargin: units.gu(1); \n';
501 extraLeftAnchor = 'leftMargin: units.gu(1); \n';
502 } else if (headerAsOverlay && !hasEmblem) {
503 extraRightAnchor = 'rightMargin: units.gu(1); \n';
507 titleContainerAnchors = 'verticalCenter: parent.verticalCenter; ';
509 titleContainerAnchors = 'right: parent.right; ';
510 titleContainerAnchors += headerLeftAnchor;
511 titleContainerAnchors += headerVerticalAnchors;
512 if (!headerLeftAnchorHasMargin) {
513 titleContainerAnchors += extraLeftAnchor;
517 titleRightAnchor = 'right: emblemIcon.left; \n\
518 rightMargin: emblemIcon.width > 0 ? units.gu(0.5) : 0; \n';
520 titleRightAnchor = 'right: parent.right; \n'
521 titleRightAnchor += extraRightAnchor;
524 if (hasTitleContainer) {
525 // Using headerTitleContainer
526 titleAnchors = titleRightAnchor;
527 titleAnchors += 'left: parent.left; \n\
529 subtitleAnchors = 'right: parent.right; \n\
530 left: parent.left; \n';
531 subtitleAnchors += extraRightAnchor;
533 attributesAnchors = subtitleAnchors + 'top: subtitleLabel.bottom;\n';
534 subtitleAnchors += 'top: titleLabel.bottom;\n';
536 attributesAnchors = subtitleAnchors + 'top: titleLabel.bottom;\n';
538 } else if (hasMascot) {
539 // Using row without titleContainer
540 titleAnchors = 'verticalCenter: parent.verticalCenter;\n';
541 titleWidth = "parent.width - x";
543 if (headerAsOverlay) {
544 // Using anchors to the overlay
545 titleAnchors = titleRightAnchor;
546 titleAnchors += 'left: parent.left; \n\
547 leftMargin: units.gu(1); \n\
548 top: overlayLoader.top; \n\
549 topMargin: units.gu(1) + overlayLoader.height - overlayLoader.overlayHeight; \n';
551 // Using anchors to the mascot/parent
552 titleAnchors = titleRightAnchor;
553 titleAnchors += headerLeftAnchor;
554 titleAnchors += headerVerticalAnchors;
555 if (!headerLeftAnchorHasMargin) {
556 titleAnchors += extraLeftAnchor;
559 subtitleAnchors = 'left: titleLabel.left; \n\
560 leftMargin: titleLabel.leftMargin; \n';
561 subtitleAnchors += extraRightAnchor;
564 subtitleAnchors += 'right: parent.right; \n';
566 subtitleAnchors += 'right: titleLabel.right; \n';
570 attributesAnchors = subtitleAnchors + 'top: subtitleLabel.bottom;\n';
571 subtitleAnchors += 'top: titleLabel.bottom;\n';
573 attributesAnchors = subtitleAnchors + 'top: titleLabel.bottom;\n';
577 // code for different elements
578 var titleLabelVisibleExtra = (headerAsOverlay ? '&& overlayLoader.active': '');
579 var titleCode = kTitleLabelCode.arg(titleAnchors).arg(titleColor).arg(titleLabelVisibleExtra).arg(titleWidth);
583 // code for the title container
584 var containerCode = [];
585 var containerHeight = 'titleLabel.height';
586 containerCode.push(titleCode);
588 subtitleCode = kSubtitleLabelCode.arg(subtitleAnchors).arg(titleColor);
589 containerCode.push(subtitleCode);
590 containerHeight += ' + subtitleLabel.height';
593 containerCode.push(kEmblemIconCode.arg(extraRightAnchor).arg(titleColor));
596 attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(titleColor);
597 containerCode.push(attributesCode);
598 containerHeight += ' + attributesRow.height';
601 if (hasTitleContainer) {
603 titleSubtitleCode = kHeaderContainerCodeGenerator(titleContainerAnchors, containerHeight, containerCode);
606 titleSubtitleCode = titleCode;
608 titleSubtitleCode += subtitleCode;
611 titleSubtitleCode += attributesCode;
617 var rowCode = [mascotCode, titleSubtitleCode];
618 if (mascotShapeCode != '') {
619 rowCode.unshift(mascotShapeCode);
621 code += kHeaderRowCodeGenerator(headerVerticalAnchors + headerLeftAnchor, rowCode)
623 code += mascotShapeCode + mascotCode + titleSubtitleCode;
627 var summaryTopAnchor;
628 if (isHorizontal && hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
629 else if (headerAsOverlay && hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
630 else if (hasHeaderRow) summaryTopAnchor = 'row.bottom';
631 else if (hasTitleContainer) summaryTopAnchor = 'headerTitleContainer.bottom';
632 else if (hasMascot) summaryTopAnchor = 'mascotImage.bottom';
633 else if (hasAttributes) summaryTopAnchor = 'attributesRow.bottom';
634 else if (hasSubtitle) summaryTopAnchor = 'subtitleLabel.bottom';
635 else if (hasTitle) summaryTopAnchor = 'titleLabel.bottom';
636 else if (hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
637 else summaryTopAnchor = 'parent.top';
641 summaryColor = summaryColorWithBackground;
643 summaryColor = 'root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText';
646 var summaryTopMargin = (hasMascot || hasSubtitle || hasAttributes ? 'anchors.margins' : '0');
648 code += kSummaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(summaryColor);
651 var touchdownAnchors;
653 touchdownAnchors = 'fill: backgroundLoader';
654 } else if (touchdownOnArtShape) {
655 touchdownAnchors = 'fill: artShapeHolder';
657 touchdownAnchors = 'fill: root'
659 code += kTouchdownCode.arg(touchdownAnchors);
661 var implicitHeight = 'implicitHeight: ';
663 implicitHeight += 'summary.y + summary.height + units.gu(1);\n';
664 } else if (headerAsOverlay) {
665 implicitHeight += 'artShapeHolder.height;\n';
666 } else if (hasHeaderRow) {
667 implicitHeight += 'row.y + row.height + units.gu(1);\n';
668 } else if (hasMascot) {
669 implicitHeight += 'mascotImage.y + mascotImage.height;\n';
670 } else if (hasTitleContainer) {
671 implicitHeight += 'headerTitleContainer.y + headerTitleContainer.height + units.gu(1);\n';
672 } else if (hasAttributes) {
673 implicitHeight += 'attributesRow.y + attributesRow.height + units.gu(1);\n';
674 } else if (hasSubtitle) {
675 implicitHeight += 'subtitleLabel.y + subtitleLabel.height + units.gu(1);\n';
676 } else if (hasTitle) {
677 implicitHeight += 'titleLabel.y + titleLabel.height + units.gu(1);\n';
679 implicitHeight += 'artShapeHolder.height;\n';
684 // Close the AbstractButton
685 code += implicitHeight + '}\n';
690function createCardComponent(parent, template, components) {
691 var imports = 'import QtQuick 2.2; \n\
692 import Ubuntu.Components 1.3; \n\
693 import Ubuntu.Settings.Components 0.1; \n\
695 import Utils 0.1;\n';
696 var card = cardString(template, components);
697 var code = imports + 'Component {\n' + card + '}\n';
700 return Qt.createQmlObject(code, parent, "createCardComponent");
702 console.error("ERROR: Invalid component created.");
703 console.error("Template:");
704 console.error(JSON.stringify(template));
705 console.error("Components:");
706 console.error(JSON.stringify(components));
707 console.error("Code:");
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list