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 color: getColor(0) || "white"; \n\
32 gradientColor: getColor(1) || color; \n\
33 anchors.fill: parent; \n\
34 image: backgroundImage.source ? backgroundImage : null; \n\
35 property real luminance: Style.luminance(color); \n\
36 property Image backgroundImage: Image { \n\
37 objectName: "backgroundImage"; \n\
39 if (cardData && typeof cardData["background"] === "string") return cardData["background"]; \n\
43 function getColor(index) { \n\
44 if (cardData && typeof cardData["background"] === "object" \n\
45 && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) { \n\
46 return cardData["background"]["elements"][index]; \n\
47 } else return index === 0 ? %2 : %3; \n\
52// %1 is used as anchors of artShapeHolder
53// %2 is used as image width
54// %3 is used as image height
55var kArtShapeHolderCode = 'Item { \n\
56 id: artShapeHolder; \n\
57 height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height; \n\
58 width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width; \n\
61 id: artShapeLoader; \n\
62 objectName: "artShapeLoader"; \n\
63 active: cardData && cardData["art"] || false; \n\
64 asynchronous: root.asynchronous; \n\
65 visible: status == Loader.Ready; \n\
66 sourceComponent: Item { \n\
68 objectName: "artShape"; \n\
69 property bool doShapeItem: components["art"]["conciergeMode"] !== true; \n\
70 visible: image.status == Image.Ready; \n\
71 readonly property alias image: artImage.image; \n\
72 property alias borderSource: artShapeShape.borderSource; \n\
73 ShaderEffectSource { \n\
74 id: artShapeSource; \n\
75 sourceItem: artImage; \n\
76 anchors.centerIn: parent; \n\
79 hideSource: doShapeItem; \n\
82 id: artShapeShape; \n\
83 image: artShapeSource; \n\
84 anchors.fill: parent; \n\
85 visible: doShapeItem; \n\
88 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1; \n\
89 readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1; \n\
90 Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; } \n\
91 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); } \n\
92 function updateWidthHeightBindings() { \n\
93 if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) { \n\
94 width = root.fixedArtShapeSize.width; \n\
95 height = root.fixedArtShapeSize.height; \n\
97 width = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.width }); \n\
98 height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height }); \n\
101 CroppedImageMinimumSourceSize { \n\
103 objectName: "artImage"; \n\
104 source: cardData && cardData["art"] || ""; \n\
105 asynchronous: root.asynchronous; \n\
113var kOverlayLoaderCode = 'Loader { \n\
114 id: overlayLoader; \n\
116 left: artShapeHolder.left; \n\
117 right: artShapeHolder.right; \n\
118 bottom: artShapeHolder.bottom; \n\
120 active: artShapeLoader.active && artShapeLoader.item && artShapeLoader.item.image.status === Image.Ready || false; \n\
121 asynchronous: root.asynchronous; \n\
122 visible: showHeader && status == Loader.Ready; \n\
123 sourceComponent: ShaderEffect { \n\
125 height: (fixedHeaderHeight > 0 ? fixedHeaderHeight : headerHeight) + units.gu(2); \n\
126 property real luminance: Style.luminance(overlayColor); \n\
127 property color overlayColor: cardData && cardData["overlayColor"] || "#99000000"; \n\
128 property var source: ShaderEffectSource { \n\
129 id: shaderSource; \n\
130 sourceItem: artShapeLoader.item; \n\
131 onVisibleChanged: if (visible) scheduleUpdate(); \n\
133 sourceRect: Qt.rect(0, artShapeLoader.height - overlay.height, artShapeLoader.width, overlay.height); \n\
136 uniform highp mat4 qt_Matrix; \n\
137 attribute highp vec4 qt_Vertex; \n\
138 attribute highp vec2 qt_MultiTexCoord0; \n\
139 varying highp vec2 coord; \n\
141 coord = qt_MultiTexCoord0; \n\
142 gl_Position = qt_Matrix * qt_Vertex; \n\
144 fragmentShader: " \n\
145 varying highp vec2 coord; \n\
146 uniform sampler2D source; \n\
147 uniform lowp float qt_Opacity; \n\
148 uniform highp vec4 overlayColor; \n\
150 lowp vec4 tex = texture2D(source, coord); \n\
151 gl_FragColor = vec4(overlayColor.r, overlayColor.g, overlayColor.b, 1) * qt_Opacity * overlayColor.a * tex.a; \n\
156// multiple row version of HeaderRowCode
157function kHeaderRowCodeGenerator() {
158var kHeaderRowCodeTemplate = 'Row { \n\
160 objectName: "outerRow"; \n\
161 property real margins: units.gu(1); \n\
162 spacing: margins; \n\
163 height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight; \n\
165 anchors.right: parent.right; \n\
166 anchors.margins: margins; \n\
167 anchors.rightMargin: 0; \n\
172 var args = Array.prototype.slice.call(arguments);
173 var code = kHeaderRowCodeTemplate.arg(args.shift()).arg(args.join(',\n'));
177// multiple item version of kHeaderContainerCode
178function kHeaderContainerCodeGenerator() {
179 var headerContainerCodeTemplate = 'Item { \n\
180 id: headerTitleContainer; \n\
182 width: parent.width - x; \n\
183 implicitHeight: %2; \n\
188 var args = Array.prototype.slice.call(arguments);
189 var code = headerContainerCodeTemplate.arg(args.shift()).arg(args.shift()).arg(args.join(',\n'));
193// %1 is used as anchors of mascotShapeLoader
194var kMascotShapeLoaderCode = 'Loader { \n\
195 id: mascotShapeLoader; \n\
196 objectName: "mascotShapeLoader"; \n\
197 asynchronous: root.asynchronous; \n\
198 active: mascotImage.image.status === Image.Ready; \n\
199 visible: showHeader && active && status == Loader.Ready; \n\
200 width: units.gu(6); \n\
201 height: units.gu(5.625); \n\
202 sourceComponent: UbuntuShape { image: mascotImage.image } \n\
206// %1 is used as anchors of mascotImage
207// %2 is used as visible of mascotImage
208var kMascotImageCode = 'CroppedImageMinimumSourceSize { \n\
210 objectName: "mascotImage"; \n\
212 source: cardData && cardData["mascot"] || ""; \n\
213 width: units.gu(6); \n\
214 height: units.gu(5.625); \n\
215 horizontalAlignment: Image.AlignHCenter; \n\
216 verticalAlignment: Image.AlignVCenter; \n\
220// %1 is used as anchors of titleLabel
221// %2 is used as color of titleLabel
222// %3 is used as extra condition for visible of titleLabel
223var kTitleLabelCode = 'Label { \n\
225 objectName: "titleLabel"; \n\
227 elide: Text.ElideRight; \n\
228 fontSize: "small"; \n\
229 wrapMode: Text.Wrap; \n\
230 maximumLineCount: 2; \n\
231 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
233 visible: showHeader %3; \n\
234 text: root.title; \n\
235 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal; \n\
236 horizontalAlignment: root.titleAlignment; \n\
239// %1 is used as extra anchors of emblemIcon
240// %2 is used as color of emblemIcon
241// FIXME The width code is a
242// Workaround for bug https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1421293
243var kEmblemIconCode = 'Icon { \n\
245 objectName: "emblemIcon"; \n\
247 bottom: titleLabel.baseline; \n\
248 right: parent.right; \n\
251 source: cardData && cardData["emblem"] || ""; \n\
253 height: source != "" ? titleLabel.font.pixelSize : 0; \n\
254 width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth; \n\
257// %1 is used as anchors of touchdown effect
258var kTouchdownCode = 'UbuntuShape { \n\
260 objectName: "touchdown"; \n\
262 visible: root.pressed; \n\
263 radius: "medium"; \n\
264 borderSource: "radius_pressed.sci" \n\
267// %1 is used as anchors of subtitleLabel
268// %2 is used as color of subtitleLabel
269var kSubtitleLabelCode = 'Label { \n\
270 id: subtitleLabel; \n\
271 objectName: "subtitleLabel"; \n\
273 anchors.topMargin: units.dp(2); \n\
274 elide: Text.ElideRight; \n\
275 maximumLineCount: 1; \n\
276 fontSize: "x-small"; \n\
277 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
279 visible: titleLabel.visible && titleLabel.text; \n\
280 text: cardData && cardData["subtitle"] || ""; \n\
281 font.weight: Font.Light; \n\
284// %1 is used as anchors of attributesRow
285// %2 is used as color of attributesRow
286var kAttributesRowCode = 'CardAttributes { \n\
287 id: attributesRow; \n\
288 objectName: "attributesRow"; \n\
291 fontScale: root.fontScale; \n\
292 model: cardData && cardData["attributes"]; \n\
295// %1 is used as top anchor of summary
296// %2 is used as topMargin anchor of summary
297// %3 is used as color of summary
298var kSummaryLabelCode = 'Label { \n\
300 objectName: "summaryLabel"; \n\
303 left: parent.left; \n\
304 right: parent.right; \n\
305 margins: units.gu(1); \n\
308 wrapMode: Text.Wrap; \n\
309 maximumLineCount: 5; \n\
310 elide: Text.ElideRight; \n\
311 text: cardData && cardData["summary"] || ""; \n\
312 height: text ? implicitHeight : 0; \n\
313 fontSize: "small"; \n\
317function cardString(template, components) {
320 var templateInteractive = (template == null ? true : (template["non-interactive"] !== undefined ? !template["non-interactive"] : true)) ? "true" : "false";
322 code = 'AbstractButton { \n\
324 property var components; \n\
325 property var cardData; \n\
326 property var artShapeBorderSource: undefined; \n\
327 property real fontScale: 1.0; \n\
328 property var scopeStyle: null; \n\
329 property int titleAlignment: Text.AlignLeft; \n\
330 property int fixedHeaderHeight: -1; \n\
331 property size fixedArtShapeSize: Qt.size(-1, -1); \n\
332 readonly property string title: cardData && cardData["title"] || ""; \n\
333 property bool asynchronous: true; \n\
334 property bool showHeader: true; \n\
335 implicitWidth: childrenRect.width; \n\
337 \n'.arg(templateInteractive);
339 var hasArt = components["art"] && components["art"]["field"] || false;
340 var hasSummary = components["summary"] || false;
341 var artAndSummary = hasArt && hasSummary && components["art"]["conciergeMode"] !== true;
342 var isHorizontal = template["card-layout"] === "horizontal";
343 var hasBackground = (!isHorizontal && (template["card-background"] || components["background"] || artAndSummary)) ||
344 (hasSummary && (template["card-background"] || components["background"]));
345 var hasTitle = components["title"] || false;
346 var hasMascot = components["mascot"] || false;
347 var hasEmblem = components["emblem"] && !(hasMascot && template["card-size"] === "small") || false;
348 var headerAsOverlay = hasArt && template && template["overlay"] === true && (hasTitle || hasMascot);
349 var hasSubtitle = hasTitle && components["subtitle"] || false;
350 var hasHeaderRow = hasMascot && hasTitle;
351 var hasAttributes = hasTitle && components["attributes"]["field"] || false;
354 var templateCardBackground = (template && typeof template["card-background"] === "string") ? template["card-background"] : "";
355 var backgroundElements0;
356 var backgroundElements1;
357 if (template && typeof template["card-background"] === "object" && (template["card-background"]["type"] === "color" || template["card-background"]["type"] === "gradient")) {
358 if (template["card-background"]["elements"][0] !== undefined) {
359 backgroundElements0 = '"%1"'.arg(template["card-background"]["elements"][0]);
361 if (template["card-background"]["elements"][1] !== undefined) {
362 backgroundElements1 = '"%1"'.arg(template["card-background"]["elements"][1]);
365 code += kBackgroundLoaderCode.arg(templateCardBackground).arg(backgroundElements0).arg(backgroundElements1);
369 code += 'onArtShapeBorderSourceChanged: { if (artShapeBorderSource !== undefined && artShapeLoader.item) artShapeLoader.item.borderSource = artShapeBorderSource; } \n';
370 code += 'readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);\n';
372 var widthCode, heightCode;
375 artAnchors = 'left: parent.left';
376 if (hasMascot || hasTitle) {
377 widthCode = 'height * artShape.aspect'
378 heightCode = 'headerHeight + 2 * units.gu(1)';
380 // This side of the else is a bit silly, who wants an horizontal layout without mascot and title?
381 // So we define a "random" height of the image height + 2 gu for the margins
382 widthCode = 'height * artShape.aspect'
383 heightCode = 'units.gu(7.625)';
386 artAnchors = 'horizontalCenter: parent.horizontalCenter;';
387 widthCode = 'root.width'
388 heightCode = 'width / artShape.aspect';
391 code += kArtShapeHolderCode.arg(artAnchors).arg(widthCode).arg(heightCode);
392 var fallback = components["art"] && components["art"]["fallback"] || "";
393 if (fallback !== "") {
394 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);
397 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
400 if (headerAsOverlay) {
401 code += kOverlayLoaderCode;
404 var headerVerticalAnchors;
405 if (headerAsOverlay) {
406 headerVerticalAnchors = 'bottom: artShapeHolder.bottom; \n\
407 bottomMargin: units.gu(1);\n';
411 headerVerticalAnchors = 'top: artShapeHolder.top; \n\
412 topMargin: units.gu(1);\n';
414 headerVerticalAnchors = 'top: artShapeHolder.bottom; \n\
415 topMargin: units.gu(1);\n';
418 headerVerticalAnchors = 'top: parent.top; \n\
419 topMargin: units.gu(1);\n';
422 var headerLeftAnchor;
423 var headerLeftAnchorHasMargin = false;
424 if (isHorizontal && hasArt) {
425 headerLeftAnchor = 'left: artShapeHolder.right; \n\
426 leftMargin: units.gu(1);\n';
427 headerLeftAnchorHasMargin = true;
429 headerLeftAnchor = 'left: parent.left;\n';
432 var touchdownOnArtShape = !hasBackground && hasArt && !hasMascot && !hasSummary;
435 code += 'readonly property int headerHeight: row.height;\n'
436 } else if (hasMascot) {
437 code += 'readonly property int headerHeight: mascotImage.height;\n'
438 } else if (hasAttributes) {
439 if (hasTitle && hasSubtitle) {
440 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + attributesRow.height + attributesRow.anchors.topMargin;\n'
441 } else if (hasTitle) {
442 code += 'readonly property int headerHeight: titleLabel.height + attributesRow.height + attributesRow.anchors.topMargin;\n'
444 code += 'readonly property int headerHeight: attributesRow.height;\n'
446 } else if (hasSubtitle) {
447 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin;\n'
448 } else if (hasTitle) {
449 code += 'readonly property int headerHeight: titleLabel.height;\n'
451 code += 'readonly property int headerHeight: 0;\n'
454 var mascotShapeCode = '';
457 var useMascotShape = !hasBackground && !headerAsOverlay;
458 var mascotAnchors = '';
460 mascotAnchors += headerLeftAnchor;
461 mascotAnchors += headerVerticalAnchors;
462 if (!headerLeftAnchorHasMargin) {
463 mascotAnchors += 'leftMargin: units.gu(1);\n'
466 mascotAnchors = 'verticalCenter: parent.verticalCenter;'
469 if (useMascotShape) {
470 mascotShapeCode = kMascotShapeLoaderCode.arg(mascotAnchors);
473 var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
474 mascotCode = kMascotImageCode.arg(mascotAnchors).arg(mascotImageVisible);
475 var fallback = components["mascot"] && components["mascot"]["fallback"] || "";
476 if (fallback !== "") {
477 code += 'Connections { target: mascotImage.image; onStatusChanged: if (mascotImage.image.status === Image.Error) mascotImage.source = "%1"; } \n'.arg(fallback);
481 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")';
483 var hasTitleContainer = hasTitle && (hasEmblem || (hasMascot && (hasSubtitle || hasAttributes)));
484 var titleSubtitleCode = '';
487 if (headerAsOverlay) {
488 titleColor = 'root.scopeStyle && overlayLoader.item ? root.scopeStyle.getTextColor(overlayLoader.item.luminance) : (overlayLoader.item && overlayLoader.item.luminance > 0.7 ? Theme.palette.normal.baseText : "white")';
489 } else if (hasSummary) {
490 titleColor = 'summary.color';
491 } else if (hasBackground) {
492 titleColor = summaryColorWithBackground;
494 titleColor = 'root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText';
499 var attributesAnchors;
500 var titleContainerAnchors;
501 var titleRightAnchor;
503 var extraRightAnchor = '';
504 var extraLeftAnchor = '';
505 if (!touchdownOnArtShape) {
506 extraRightAnchor = 'rightMargin: units.gu(1); \n';
507 extraLeftAnchor = 'leftMargin: units.gu(1); \n';
508 } else if (headerAsOverlay && !hasEmblem) {
509 extraRightAnchor = 'rightMargin: units.gu(1); \n';
513 titleContainerAnchors = 'verticalCenter: parent.verticalCenter; ';
515 titleContainerAnchors = 'right: parent.right; ';
516 titleContainerAnchors += headerLeftAnchor;
517 titleContainerAnchors += headerVerticalAnchors;
518 if (!headerLeftAnchorHasMargin) {
519 titleContainerAnchors += extraLeftAnchor;
523 titleRightAnchor = 'right: emblemIcon.left; \n\
524 rightMargin: emblemIcon.width > 0 ? units.gu(0.5) : 0; \n';
526 titleRightAnchor = 'right: parent.right; \n'
527 titleRightAnchor += extraRightAnchor;
530 if (hasTitleContainer) {
531 // Using headerTitleContainer
532 titleAnchors = titleRightAnchor;
533 titleAnchors += 'left: parent.left; \n\
535 subtitleAnchors = 'right: parent.right; \n\
536 left: parent.left; \n';
537 subtitleAnchors += extraRightAnchor;
539 attributesAnchors = subtitleAnchors + 'top: subtitleLabel.bottom;\n';
540 subtitleAnchors += 'top: titleLabel.bottom;\n';
542 attributesAnchors = subtitleAnchors + 'top: titleLabel.bottom;\n';
544 } else if (hasMascot) {
545 // Using row + titleContainer
546 titleAnchors = 'verticalCenter: parent.verticalCenter;\n';
548 if (headerAsOverlay) {
549 // Using anchors to the overlay
550 titleAnchors = titleRightAnchor;
551 titleAnchors += 'left: parent.left; \n\
552 leftMargin: units.gu(1); \n\
553 top: overlayLoader.top; \n\
554 topMargin: units.gu(1);\n';
556 // Using anchors to the mascot/parent
557 titleAnchors = titleRightAnchor;
558 titleAnchors += headerLeftAnchor;
559 titleAnchors += headerVerticalAnchors;
560 if (!headerLeftAnchorHasMargin) {
561 titleAnchors += extraLeftAnchor;
564 subtitleAnchors = 'left: titleLabel.left; \n\
565 leftMargin: titleLabel.leftMargin; \n';
566 subtitleAnchors += extraRightAnchor;
569 subtitleAnchors += 'right: parent.right; \n';
571 subtitleAnchors += 'right: titleLabel.right; \n';
575 attributesAnchors = subtitleAnchors + 'top: subtitleLabel.bottom;\n';
576 subtitleAnchors += 'top: titleLabel.bottom;\n';
578 attributesAnchors = subtitleAnchors + 'top: titleLabel.bottom;\n';
582 // code for different elements
583 var titleLabelVisibleExtra = (headerAsOverlay ? '&& overlayLoader.active': '');
584 var titleCode = kTitleLabelCode.arg(titleAnchors).arg(titleColor).arg(titleLabelVisibleExtra);
588 // code for the title container
589 var containerCode = [];
590 var containerHeight = 'titleLabel.height';
591 containerCode.push(titleCode);
593 subtitleCode = kSubtitleLabelCode.arg(subtitleAnchors).arg(titleColor);
594 containerCode.push(subtitleCode);
595 containerHeight += ' + subtitleLabel.height';
598 containerCode.push(kEmblemIconCode.arg(extraRightAnchor).arg(titleColor));
601 attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(titleColor);
602 containerCode.push(attributesCode);
603 containerHeight += ' + attributesRow.height';
606 if (hasTitleContainer) {
608 titleSubtitleCode = kHeaderContainerCodeGenerator(titleContainerAnchors, containerHeight, containerCode);
611 titleSubtitleCode = titleCode;
613 titleSubtitleCode += subtitleCode;
616 titleSubtitleCode += attributesCode;
622 var rowCode = [mascotCode, titleSubtitleCode];
623 if (mascotShapeCode != '') {
624 rowCode.unshift(mascotShapeCode);
626 code += kHeaderRowCodeGenerator(headerVerticalAnchors + headerLeftAnchor, rowCode)
628 code += mascotShapeCode + mascotCode + titleSubtitleCode;
632 var summaryTopAnchor;
633 if (isHorizontal && hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
634 else if (headerAsOverlay && hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
635 else if (hasHeaderRow) summaryTopAnchor = 'row.bottom';
636 else if (hasTitleContainer) summaryTopAnchor = 'headerTitleContainer.bottom';
637 else if (hasMascot) summaryTopAnchor = 'mascotImage.bottom';
638 else if (hasAttributes) summaryTopAnchor = 'attributesRow.bottom';
639 else if (hasSubtitle) summaryTopAnchor = 'subtitleLabel.bottom';
640 else if (hasTitle) summaryTopAnchor = 'titleLabel.bottom';
641 else if (hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
642 else summaryTopAnchor = 'parent.top';
646 summaryColor = summaryColorWithBackground;
648 summaryColor = 'root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText';
651 var summaryTopMargin = (hasMascot || hasSubtitle || hasAttributes ? 'anchors.margins' : '0');
653 code += kSummaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(summaryColor);
656 var touchdownAnchors;
658 touchdownAnchors = 'fill: backgroundLoader';
659 } else if (touchdownOnArtShape) {
660 touchdownAnchors = 'fill: artShapeHolder';
662 touchdownAnchors = 'fill: root'
664 code += kTouchdownCode.arg(touchdownAnchors);
666 var implicitHeight = 'implicitHeight: ';
668 implicitHeight += 'summary.y + summary.height + units.gu(1);\n';
669 } else if (headerAsOverlay) {
670 implicitHeight += 'artShapeHolder.height;\n';
671 } else if (hasHeaderRow) {
672 implicitHeight += 'row.y + row.height + units.gu(1);\n';
673 } else if (hasMascot) {
674 implicitHeight += 'mascotImage.y + mascotImage.height;\n';
675 } else if (hasTitleContainer) {
676 implicitHeight += 'headerTitleContainer.y + headerTitleContainer.height + units.gu(1);\n';
677 } else if (hasAttributes) {
678 implicitHeight += 'attributesRow.y + attributesRow.height + units.gu(1);\n';
679 } else if (hasSubtitle) {
680 implicitHeight += 'subtitleLabel.y + subtitleLabel.height + units.gu(1);\n';
681 } else if (hasTitle) {
682 implicitHeight += 'titleLabel.y + titleLabel.height + units.gu(1);\n';
684 implicitHeight += 'artShapeHolder.height;\n';
689 // Close the AbstractButton
690 code += implicitHeight + '}\n';
695function createCardComponent(parent, template, components) {
696 var imports = 'import QtQuick 2.2; \n\
697 import Ubuntu.Components 1.1; \n\
698 import Ubuntu.Settings.Components 0.1; \n\
700 import Utils 0.1;\n';
701 var card = cardString(template, components);
702 var code = imports + 'Component {\n' + card + '}\n';
705 return Qt.createQmlObject(code, parent, "createCardComponent");
707 console.error("ERROR: Invalid component created.");
708 console.error("Template:");
709 console.error(JSON.stringify(template));
710 console.error("Components:");
711 console.error(JSON.stringify(components));
712 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