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"]["elements"][0]
20// %2 is the template["card-background"]["elements"][1]
21// %3 is whether the loader should be asynchronous or not
22// %4 is the template["card-background"] string
23var kBackgroundLoaderCode = 'Loader {\n\
24 id: backgroundLoader; \n\
25 objectName: "backgroundLoader"; \n\
26 anchors.fill: parent; \n\
28 visible: status == Loader.Ready; \n\
29 sourceComponent: UbuntuShape { \n\
30 objectName: "background"; \n\
33 switch (root.backgroundShapeStyle) { \n\
34 case "inset": return UbuntuShape.Inset; \n\
35 case "shadow": return UbuntuShape.DropShadow; \n\
37 case "flat": return UbuntuShape.Flat; \n\
40 backgroundColor: getColor(0) || "white"; \n\
41 secondaryBackgroundColor: getColor(1) || backgroundColor; \n\
42 backgroundMode: UbuntuShape.VerticalGradient; \n\
43 anchors.fill: parent; \n\
44 source: backgroundImage.source ? backgroundImage : null; \n\
45 property real luminance: Style.luminance(backgroundColor); \n\
46 property Image backgroundImage: Image { \n\
47 objectName: "backgroundImage"; \n\
49 if (cardData && typeof cardData["background"] === "string") return cardData["background"]; \n\
53 function getColor(index) { \n\
54 if (cardData && typeof cardData["background"] === "object" \n\
55 && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) { \n\
56 return cardData["background"]["elements"][index]; \n\
57 } else return index === 0 ? %1 : %2; \n\
62// %1 is used as anchors of artShapeHolder
63// %2 is used as image width
64// %3 is used as image height
65// %4 is whether the image or the Loader with the UbuntuShape/ProportionalShape should be visible
66// %5 is used as aspect ratio fallback
67// %6 is whether the loader should be asynchronous or not
68// %7 is injected as code to artImage
69// %8 is used as image fallback
70var kArtShapeHolderCode = 'Item { \n\
71 id: artShapeHolder; \n\
72 height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height; \n\
73 width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width; \n\
76 id: artShapeLoader; \n\
77 objectName: "artShapeLoader"; \n\
78 readonly property string cardArt: cardData && cardData["art"] || %8; \n\
79 active: cardArt != ""; \n\
81 visible: status == Loader.Ready; \n\
82 sourceComponent: Item { \n\
84 objectName: "artShape"; \n\
85 visible: image.status == Image.Ready; \n\
86 readonly property alias image: artImage; \n\
88 anchors.fill: parent; \n\
90 sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent; \n\
92 id: artShapeShapeComponent; \n\
95 sourceFillMode: UbuntuShape.PreserveAspectCrop; \n\
98 switch (root.artShapeStyle) { \n\
99 case "inset": return UbuntuShape.Inset; \n\
100 case "shadow": return UbuntuShape.DropShadow; \n\
102 case "flat": return UbuntuShape.Flat; \n\
108 id: artShapeIconComponent; \n\
109 ProportionalShape { source: artImage; aspect: UbuntuShape.DropShadow; } \n\
112 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1; \n\
113 readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : %5; \n\
114 Component.onCompleted: { updateWidthHeightBindings(); } \n\
115 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); } \n\
116 function updateWidthHeightBindings() { \n\
117 if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) { \n\
118 width = root.fixedArtShapeSize.width; \n\
119 height = root.fixedArtShapeSize.height; \n\
121 width = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.width }); \n\
122 height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height }); \n\
125 CroppedImageMinimumSourceSize { \n\
127 objectName: "artImage"; \n\
128 source: artShapeLoader.cardArt; \n\
129 asynchronous: %6; \n\
142// %4 is whether the icon should be asynchronous or not
143var kAudioButtonCode = 'AbstractButton { \n\
145 anchors.fill: %1; \n\
148 readonly property url source: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["uri"]) || ""; \n\
150 anchors.fill: parent; \n\
151 visible: parent.pressed; \n\
152 radius: "medium"; \n\
155 color: Qt.rgba(0, 0, 0, 0.5); \n\
156 anchors.centerIn: parent; \n\
157 width: parent.width * 0.5; \n\
159 radius: width / 2; \n\
162 anchors.centerIn: parent; \n\
163 width: parent.width * 0.3; \n\
166 name: DashAudioPlayer.playing && AudioUrlComparer.compare(parent.source, DashAudioPlayer.currentSource) ? "media-playback-pause" : "media-playback-start"; \n\
168 asynchronous: %4; \n\
171 if (AudioUrlComparer.compare(source, DashAudioPlayer.currentSource)) { \n\
172 if (DashAudioPlayer.playing) { \n\
173 DashAudioPlayer.pause(); \n\
175 DashAudioPlayer.play(); \n\
178 var playlist = (cardData["quickPreviewData"] && cardData["quickPreviewData"]["playlist"]) || null; \n\
179 DashAudioPlayer.playSource(source, playlist); \n\
182 onPressAndHold: { \n\
183 root.pressAndHold(); \n\
187// %1 is whether the loader should be asynchronous or not
188// %2 is the header height code
189var kOverlayLoaderCode = 'Loader { \n\
190 id: overlayLoader; \n\
191 readonly property real overlayHeight: %2 + units.gu(2); \n\
192 anchors.fill: artShapeHolder; \n\
193 active: artShapeLoader.active && artShapeLoader.item && artShapeLoader.item.image.status === Image.Ready || false; \n\
194 asynchronous: %1; \n\
195 visible: showHeader && status == Loader.Ready; \n\
196 sourceComponent: UbuntuShapeOverlay { \n\
198 property real luminance: Style.luminance(overlayColor); \n\
199 aspect: UbuntuShape.Flat; \n\
200 radius: "medium"; \n\
201 overlayColor: cardData && cardData["overlayColor"] || "#99000000"; \n\
202 overlayRect: Qt.rect(0, 1 - overlayLoader.overlayHeight / height, 1, 1); \n\
206// multiple row version of HeaderRowCode
207function kHeaderRowCodeGenerator() {
208 var kHeaderRowCodeTemplate = 'Row { \n\
210 objectName: "outerRow"; \n\
211 property real margins: units.gu(1); \n\
212 spacing: margins; \n\
215 anchors.right: parent.right; \n\
216 anchors.margins: margins; \n\
217 anchors.rightMargin: 0; \n\
222 var args = Array.prototype.slice.call(arguments);
223 var isCardTool = args.shift();
224 var heightCode = isCardTool ? "" : "height: root.fixedHeaderHeight; \n";
225 var code = kHeaderRowCodeTemplate.arg(args.shift()).arg(heightCode).arg(args.join(',\n'));
229// multiple item version of kHeaderContainerCode
230function kHeaderContainerCodeGenerator() {
231 var headerContainerCodeTemplate = 'Item { \n\
232 id: headerTitleContainer; \n\
234 width: parent.width - x; \n\
235 implicitHeight: %2; \n\
240 var args = Array.prototype.slice.call(arguments);
241 var code = headerContainerCodeTemplate.arg(args.shift()).arg(args.shift()).arg(args.join(',\n'));
245// %1 is used as anchors of mascotShapeLoader
246// %2 is whether the loader should be asynchronous or not
247var kMascotShapeLoaderCode = 'Loader { \n\
248 id: mascotShapeLoader; \n\
249 objectName: "mascotShapeLoader"; \n\
250 asynchronous: %2; \n\
251 active: mascotImage.status === Image.Ready; \n\
252 visible: showHeader && active && status == Loader.Ready; \n\
253 width: units.gu(6); \n\
254 height: units.gu(5.625); \n\
255 sourceComponent: UbuntuShape { image: mascotImage } \n\
259// %1 is used as anchors of mascotImage
260// %2 is used as visible of mascotImage
261// %3 is injected as code to mascotImage
262// %4 is used as fallback image
263var kMascotImageCode = 'CroppedImageMinimumSourceSize { \n\
265 objectName: "mascotImage"; \n\
267 source: cardData && cardData["mascot"] || %4; \n\
268 width: units.gu(6); \n\
269 height: units.gu(5.625); \n\
270 horizontalAlignment: Image.AlignHCenter; \n\
271 verticalAlignment: Image.AlignVCenter; \n\
276// %1 is used as anchors of titleLabel
277// %2 is used as color of titleLabel
278// %3 is used as extra condition for visible of titleLabel
279// %4 is used as title width
280// %5 is used as horizontal alignment
281var kTitleLabelCode = 'Label { \n\
283 objectName: "titleLabel"; \n\
285 elide: Text.ElideRight; \n\
286 fontSize: "small"; \n\
287 wrapMode: Text.Wrap; \n\
288 maximumLineCount: 2; \n\
289 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
291 visible: showHeader %3; \n\
293 text: root.title; \n\
294 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal; \n\
295 horizontalAlignment: %5; \n\
298// %1 is used as extra anchors of emblemIcon
299// %2 is used as color of emblemIcon
300// FIXME The width code is a
301// Workaround for bug https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1421293
302var kEmblemIconCode = 'Icon { \n\
304 objectName: "emblemIcon"; \n\
306 bottom: titleLabel.baseline; \n\
307 right: parent.right; \n\
310 source: cardData && cardData["emblem"] || ""; \n\
312 height: source != "" ? titleLabel.font.pixelSize : 0; \n\
313 width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth; \n\
316// %1 is used as anchors of touchdown effect
317var kTouchdownCode = 'UbuntuShape { \n\
319 objectName: "touchdown"; \n\
321 visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed; \n\
322 radius: "medium"; \n\
323 borderSource: "radius_pressed.sci" \n\
326// %1 is used as anchors of subtitleLabel
327// %2 is used as color of subtitleLabel
328var kSubtitleLabelCode = 'Label { \n\
329 id: subtitleLabel; \n\
330 objectName: "subtitleLabel"; \n\
332 anchors.topMargin: units.dp(2); \n\
333 elide: Text.ElideRight; \n\
334 maximumLineCount: 1; \n\
335 fontSize: "x-small"; \n\
336 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
338 visible: titleLabel.visible && titleLabel.text; \n\
339 text: cardData && cardData["subtitle"] || ""; \n\
340 font.weight: Font.Light; \n\
343// %1 is used as anchors of attributesRow
344// %2 is used as color of attributesRow
345var kAttributesRowCode = 'CardAttributes { \n\
346 id: attributesRow; \n\
347 objectName: "attributesRow"; \n\
350 fontScale: root.fontScale; \n\
351 model: cardData && cardData["attributes"]; \n\
354// %1 is used as top anchor of summary
355// %2 is used as topMargin anchor of summary
356// %3 is used as color of summary
357var kSummaryLabelCode = 'Label { \n\
359 objectName: "summaryLabel"; \n\
362 left: parent.left; \n\
363 right: parent.right; \n\
364 margins: units.gu(1); \n\
367 wrapMode: Text.Wrap; \n\
368 maximumLineCount: 5; \n\
369 elide: Text.ElideRight; \n\
370 text: cardData && cardData["summary"] || ""; \n\
371 height: text ? implicitHeight : 0; \n\
372 fontSize: "small"; \n\
376// %1 is used as bottom anchor of audio progress bar
377// %2 is used as left anchor of audio progress bar
378// %3 is used as text color
379var kAudioProgressBarCode = 'CardAudioProgress { \n\
380 id: audioProgressBar; \n\
381 duration: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["duration"]) || 0; \n\
382 source: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["uri"]) || ""; \n\
386 right: parent.right; \n\
387 margins: units.gu(1); \n\
392function sanitizeColor(colorString) {
393 if (colorString !== undefined) {
394 if (colorString.match(/^[#a-z0-9]*$/i) === null) {
395 // This is not the perfect regexp for color
396 // but what we're trying to do here is just protect
397 // against injection so it's ok
404function cardString(template, components, isCardTool) {
407 var templateInteractive = (template == null ? true : (template["non-interactive"] !== undefined ? !template["non-interactive"] : true)) ? "true" : "false";
409 code = 'AbstractButton { \n\
411 property var cardData; \n\
412 property string artShapeStyle: "inset"; \n\
413 property string backgroundShapeStyle: "inset"; \n\
414 property real fontScale: 1.0; \n\
415 property var scopeStyle: null; \n\
417 property size fixedArtShapeSize: Qt.size(-1, -1); \n\
418 readonly property string title: cardData && cardData["title"] || ""; \n\
419 property bool showHeader: true; \n\
420 implicitWidth: childrenRect.width; \n\
422 \n'.arg(templateInteractive);
424 code = code.arg(isCardTool ? "" : "property int fixedHeaderHeight: -1; \n");
426 var hasArt = components["art"] && components["art"]["field"] || false;
427 var hasSummary = components["summary"] || false;
428 var isConciergeMode = components["art"] && components["art"]["conciergeMode"] || false;
429 var artAndSummary = hasArt && hasSummary && !isConciergeMode;
430 var isHorizontal = template["card-layout"] === "horizontal";
431 var hasBackground = (!isHorizontal && (template["card-background"] || components["background"] || artAndSummary)) ||
432 (hasSummary && (template["card-background"] || components["background"]));
433 var hasTitle = components["title"] || false;
434 var hasMascot = components["mascot"] || false;
435 var hasEmblem = components["emblem"] && !(hasMascot && template["card-size"] === "small") || false;
436 var headerAsOverlay = hasArt && template && template["overlay"] === true && (hasTitle || hasMascot);
437 var hasSubtitle = hasTitle && components["subtitle"] || false;
438 var hasHeaderRow = hasMascot && hasTitle;
439 var hasAttributes = hasTitle && components["attributes"] && components["attributes"]["field"] || false;
440 var isAudio = template["quick-preview-type"] === "audio";
441 var asynchronous = isCardTool ? "false" : "true";
444 // For now we only support audio cards with [optional] art, title, subtitle
445 // in horizontal mode
446 // Anything else makes it behave not like an audio card
447 if (hasSummary) isAudio = false;
448 if (!isHorizontal) isAudio = false;
449 if (hasMascot) isAudio = false;
450 if (hasEmblem) isAudio = false;
451 if (headerAsOverlay) isAudio = false;
452 if (hasAttributes) isAudio = false;
456 var templateCardBackground;
457 if (template && typeof template["card-background"] === "string") {
458 templateCardBackground = 'decodeURI("' + encodeURI(template["card-background"]) + '")';
460 templateCardBackground = '""';
463 var backgroundElements0;
464 var backgroundElements1;
465 if (template && typeof template["card-background"] === "object" && (template["card-background"]["type"] === "color" || template["card-background"]["type"] === "gradient")) {
466 var element0 = sanitizeColor(template["card-background"]["elements"][0]);
467 var element1 = sanitizeColor(template["card-background"]["elements"][1]);
468 if (element0 !== undefined) {
469 backgroundElements0 = '"%1"'.arg(element0);
471 if (element1 !== undefined) {
472 backgroundElements1 = '"%1"'.arg(element1);
475 code += kBackgroundLoaderCode.arg(backgroundElements0).arg(backgroundElements1).arg(asynchronous).arg(templateCardBackground);
479 code += 'readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);\n';
481 var widthCode, heightCode;
484 artAnchors = 'left: parent.left';
485 if (hasMascot || hasTitle) {
486 widthCode = 'height * artShape.aspect'
487 heightCode = 'headerHeight + 2 * units.gu(1)';
489 // This side of the else is a bit silly, who wants an horizontal layout without mascot and title?
490 // So we define a "random" height of the image height + 2 gu for the margins
491 widthCode = 'height * artShape.aspect'
492 heightCode = 'units.gu(7.625)';
495 artAnchors = 'horizontalCenter: parent.horizontalCenter;';
496 widthCode = 'root.width'
497 heightCode = 'width / artShape.aspect';
500 var aspectRatio = components["art"] && components["art"]["aspect-ratio"] || 1;
501 if (isNaN(aspectRatio)) {
504 var fallback = !isCardTool && components["art"] && components["art"]["fallback"] || "";
505 fallback = encodeURI(fallback);
506 var fallbackStatusCode = "";
507 var fallbackURICode = '""';
508 if (fallback !== "") {
509 // fallbackStatusCode has %6 in it because we want to substitute it for fallbackURICode
510 // which in kArtShapeHolderCode is %8
511 fallbackStatusCode += 'onStatusChanged: if (status === Image.Error) source = %8;';
512 fallbackURICode = 'decodeURI("%1")'.arg(fallback);
514 code += kArtShapeHolderCode.arg(artAnchors)
517 .arg(isConciergeMode ? "false" : "true")
520 .arg(fallbackStatusCode)
521 .arg(fallbackURICode);
523 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
526 if (headerAsOverlay) {
527 var headerHeightCode = isCardTool ? "headerHeight" : "root.fixedHeaderHeight";
528 code += kOverlayLoaderCode.arg(asynchronous).arg(headerHeightCode);
531 var headerVerticalAnchors;
532 if (headerAsOverlay) {
533 headerVerticalAnchors = 'bottom: artShapeHolder.bottom; \n\
534 bottomMargin: units.gu(1);\n';
538 headerVerticalAnchors = 'top: artShapeHolder.top; \n\
539 topMargin: units.gu(1);\n';
541 headerVerticalAnchors = 'top: artShapeHolder.bottom; \n\
542 topMargin: units.gu(1);\n';
545 headerVerticalAnchors = 'top: parent.top; \n\
546 topMargin: units.gu(1);\n';
550 var headerLeftAnchor;
551 var headerLeftAnchorHasMargin = false;
552 if (isHorizontal && hasArt) {
553 headerLeftAnchor = 'left: artShapeHolder.right; \n\
554 leftMargin: units.gu(1);\n';
555 headerLeftAnchorHasMargin = true;
556 } else if (isHorizontal && isAudio) {
557 headerLeftAnchor = 'left: audioButton.right; \n\
558 leftMargin: units.gu(1);\n';
559 headerLeftAnchorHasMargin = true;
561 headerLeftAnchor = 'left: parent.left;\n';
564 var touchdownOnArtShape = !hasBackground && hasArt && !hasMascot && !hasSummary && !isAudio;
567 code += 'readonly property int headerHeight: row.height;\n'
568 } else if (hasMascot) {
569 code += 'readonly property int headerHeight: mascotImage.height;\n'
570 } else if (hasAttributes) {
571 if (hasTitle && hasSubtitle) {
572 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + attributesRow.height + attributesRow.anchors.topMargin;\n'
573 } else if (hasTitle) {
574 code += 'readonly property int headerHeight: titleLabel.height + attributesRow.height + attributesRow.anchors.topMargin;\n'
576 code += 'readonly property int headerHeight: attributesRow.height;\n'
578 } else if (isAudio) {
580 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + audioProgressBar.height + audioProgressBar.anchors.topMargin;\n'
581 } else if (hasTitle) {
582 code += 'readonly property int headerHeight: titleLabel.height + audioProgressBar.height + audioProgressBar.anchors.topMargin;\n'
584 code += 'readonly property int headerHeight: audioProgressBar.height;\n'
586 } else if (hasSubtitle) {
587 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin;\n'
588 } else if (hasTitle) {
589 code += 'readonly property int headerHeight: titleLabel.height;\n'
591 code += 'readonly property int headerHeight: 0;\n'
594 var mascotShapeCode = '';
597 var useMascotShape = !hasBackground && !headerAsOverlay;
598 var mascotAnchors = '';
600 mascotAnchors += headerLeftAnchor;
601 mascotAnchors += headerVerticalAnchors;
602 if (!headerLeftAnchorHasMargin) {
603 mascotAnchors += 'leftMargin: units.gu(1);\n'
606 mascotAnchors = 'verticalCenter: parent.verticalCenter;'
609 if (useMascotShape) {
610 mascotShapeCode = kMascotShapeLoaderCode.arg(mascotAnchors).arg(asynchronous);
613 var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
614 var fallback = !isCardTool && components["mascot"] && components["mascot"]["fallback"] || "";
615 fallback = encodeURI(fallback);
616 var fallbackStatusCode = "";
617 var fallbackURICode = '""';
618 if (fallback !== "") {
619 // fallbackStatusCode has %4 in it because we want to substitute it for fallbackURICode
620 // which in kMascotImageCode is %4
621 fallbackStatusCode += 'onStatusChanged: if (status === Image.Error) source = %4;';
622 fallbackURICode = 'decodeURI("%1")'.arg(fallback);
624 mascotCode = kMascotImageCode.arg(mascotAnchors).arg(mascotImageVisible).arg(fallbackStatusCode).arg(fallbackURICode);
627 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")';
629 var hasTitleContainer = hasTitle && (hasEmblem || (hasMascot && (hasSubtitle || hasAttributes)));
630 var titleSubtitleCode = '';
633 if (headerAsOverlay) {
634 titleColor = 'root.scopeStyle && overlayLoader.item ? root.scopeStyle.getTextColor(overlayLoader.item.luminance) : (overlayLoader.item && overlayLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white")';
635 } else if (hasSummary) {
636 titleColor = 'summary.color';
637 } else if (hasBackground) {
638 titleColor = summaryColorWithBackground;
640 titleColor = 'root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText';
645 var attributesAnchors;
646 var titleContainerAnchors;
647 var titleRightAnchor;
648 var titleWidth = "undefined";
650 var extraRightAnchor = '';
651 var extraLeftAnchor = '';
652 if (!touchdownOnArtShape) {
653 extraRightAnchor = 'rightMargin: units.gu(1); \n';
654 extraLeftAnchor = 'leftMargin: units.gu(1); \n';
655 } else if (headerAsOverlay && !hasEmblem) {
656 extraRightAnchor = 'rightMargin: units.gu(1); \n';
660 titleContainerAnchors = 'verticalCenter: parent.verticalCenter; ';
662 titleContainerAnchors = 'right: parent.right; ';
663 titleContainerAnchors += headerLeftAnchor;
664 titleContainerAnchors += headerVerticalAnchors;
665 if (!headerLeftAnchorHasMargin) {
666 titleContainerAnchors += extraLeftAnchor;
670 titleRightAnchor = 'right: emblemIcon.left; \n\
671 rightMargin: emblemIcon.width > 0 ? units.gu(0.5) : 0; \n';
673 titleRightAnchor = 'right: parent.right; \n'
674 titleRightAnchor += extraRightAnchor;
677 if (hasTitleContainer) {
678 // Using headerTitleContainer
679 titleAnchors = titleRightAnchor;
680 titleAnchors += 'left: parent.left; \n\
682 subtitleAnchors = 'right: parent.right; \n\
683 left: parent.left; \n';
684 subtitleAnchors += extraRightAnchor;
686 attributesAnchors = subtitleAnchors + 'top: subtitleLabel.bottom;\n';
687 subtitleAnchors += 'top: titleLabel.bottom;\n';
689 attributesAnchors = subtitleAnchors + 'top: titleLabel.bottom;\n';
691 } else if (hasMascot) {
692 // Using row without titleContainer
693 titleAnchors = 'verticalCenter: parent.verticalCenter;\n';
694 titleWidth = "parent.width - x";
696 if (headerAsOverlay) {
697 // Using anchors to the overlay
698 titleAnchors = titleRightAnchor;
699 titleAnchors += 'left: parent.left; \n\
700 leftMargin: units.gu(1); \n\
701 top: overlayLoader.top; \n\
702 topMargin: units.gu(1) + overlayLoader.height - overlayLoader.overlayHeight; \n';
704 // Using anchors to the mascot/parent
705 titleAnchors = titleRightAnchor;
706 titleAnchors += headerLeftAnchor;
707 titleAnchors += headerVerticalAnchors;
708 if (!headerLeftAnchorHasMargin) {
709 titleAnchors += extraLeftAnchor;
712 subtitleAnchors = 'left: titleLabel.left; \n\
713 leftMargin: titleLabel.leftMargin; \n';
714 subtitleAnchors += extraRightAnchor;
717 subtitleAnchors += 'right: parent.right; \n';
719 subtitleAnchors += 'right: titleLabel.right; \n';
723 attributesAnchors = subtitleAnchors + 'top: subtitleLabel.bottom;\n';
724 subtitleAnchors += 'top: titleLabel.bottom;\n';
726 attributesAnchors = subtitleAnchors + 'top: titleLabel.bottom;\n';
730 var titleAlignment = "Text.AlignHCenter";
731 if (template["card-layout"] === "horizontal"
732 || typeof components["title"] !== "object"
733 || components["title"]["align"] === "left") titleAlignment = "Text.AlignLeft";
734 var keys = ["mascot", "emblem", "subtitle", "attributes", "summary"];
735 for (var key in keys) {
738 if (typeof components[key] === "string"
739 || typeof components[key]["field"] === "string") titleAlignment = "Text.AlignLeft";
745 // code for different elements
746 var titleLabelVisibleExtra = (headerAsOverlay ? '&& overlayLoader.active': '');
747 var titleCode = kTitleLabelCode.arg(titleAnchors).arg(titleColor).arg(titleLabelVisibleExtra).arg(titleWidth).arg(titleAlignment);
751 // code for the title container
752 var containerCode = [];
753 var containerHeight = 'titleLabel.height';
754 containerCode.push(titleCode);
756 subtitleCode = kSubtitleLabelCode.arg(subtitleAnchors).arg(titleColor);
757 containerCode.push(subtitleCode);
758 containerHeight += ' + subtitleLabel.height';
761 containerCode.push(kEmblemIconCode.arg(extraRightAnchor).arg(titleColor));
764 attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(titleColor);
765 containerCode.push(attributesCode);
766 containerHeight += ' + attributesRow.height';
769 if (hasTitleContainer) {
771 titleSubtitleCode = kHeaderContainerCodeGenerator(titleContainerAnchors, containerHeight, containerCode);
774 titleSubtitleCode = titleCode;
776 titleSubtitleCode += subtitleCode;
779 titleSubtitleCode += attributesCode;
785 var rowCode = [mascotCode, titleSubtitleCode];
786 if (mascotShapeCode != '') {
787 rowCode.unshift(mascotShapeCode);
789 code += kHeaderRowCodeGenerator(isCardTool, headerVerticalAnchors + headerLeftAnchor, rowCode)
791 code += mascotShapeCode + mascotCode + titleSubtitleCode;
795 var audioProgressBarLeftAnchor = 'audioButton.right';
796 var audioProgressBarBottomAnchor = 'audioButton.bottom';
797 var audioProgressBarTextColor = 'root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText';
799 code += kAudioProgressBarCode.arg(audioProgressBarBottomAnchor)
800 .arg(audioProgressBarLeftAnchor)
801 .arg(audioProgressBarTextColor);
803 var audioButtonAnchorsFill;
804 var audioButtonWidth;
805 var audioButtonHeight;
807 audioButtonAnchorsFill = 'artShapeHolder';
808 audioButtonWidth = 'undefined';
809 audioButtonHeight = 'undefined';
811 audioButtonAnchorsFill = 'undefined';
812 audioButtonWidth = 'height';
813 audioButtonHeight = isCardTool ? 'headerHeight + 2 * units.gu(1)'
814 : 'root.fixedHeaderHeight + 2 * units.gu(1)';
816 code += kAudioButtonCode.arg(audioButtonAnchorsFill).arg(audioButtonWidth).arg(audioButtonHeight).arg(asynchronous);
820 var summaryTopAnchor;
821 if (isHorizontal && hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
822 else if (headerAsOverlay && hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
823 else if (hasHeaderRow) summaryTopAnchor = 'row.bottom';
824 else if (hasTitleContainer) summaryTopAnchor = 'headerTitleContainer.bottom';
825 else if (hasMascot) summaryTopAnchor = 'mascotImage.bottom';
826 else if (hasAttributes) summaryTopAnchor = 'attributesRow.bottom';
827 else if (hasSubtitle) summaryTopAnchor = 'subtitleLabel.bottom';
828 else if (hasTitle) summaryTopAnchor = 'titleLabel.bottom';
829 else if (hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
830 else summaryTopAnchor = 'parent.top';
834 summaryColor = summaryColorWithBackground;
836 summaryColor = 'root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText';
839 var summaryTopMargin = (hasMascot || hasSubtitle || hasAttributes ? 'anchors.margins' : '0');
841 code += kSummaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(summaryColor);
844 var touchdownAnchors;
846 touchdownAnchors = 'fill: backgroundLoader';
847 } else if (touchdownOnArtShape) {
848 touchdownAnchors = 'fill: artShapeHolder';
850 touchdownAnchors = 'fill: root'
852 code += kTouchdownCode.arg(touchdownAnchors);
854 var implicitHeight = 'implicitHeight: ';
856 implicitHeight += 'summary.y + summary.height + units.gu(1);\n';
857 } else if (isAudio) {
858 implicitHeight += 'audioButton.height;\n';
859 } else if (headerAsOverlay) {
860 implicitHeight += 'artShapeHolder.height;\n';
861 } else if (hasHeaderRow) {
862 implicitHeight += 'row.y + row.height + units.gu(1);\n';
863 } else if (hasMascot) {
864 implicitHeight += 'mascotImage.y + mascotImage.height;\n';
865 } else if (hasTitleContainer) {
866 implicitHeight += 'headerTitleContainer.y + headerTitleContainer.height + units.gu(1);\n';
867 } else if (hasAttributes) {
868 implicitHeight += 'attributesRow.y + attributesRow.height + units.gu(1);\n';
869 } else if (hasSubtitle) {
870 implicitHeight += 'subtitleLabel.y + subtitleLabel.height + units.gu(1);\n';
871 } else if (hasTitle) {
872 implicitHeight += 'titleLabel.y + titleLabel.height + units.gu(1);\n';
874 implicitHeight += 'artShapeHolder.height;\n';
879 // Close the AbstractButton
880 code += implicitHeight + '}\n';
885function createCardComponent(parent, template, components, isCardTool, identifier) {
886 var imports = 'import QtQuick 2.4; \n\
887 import Ubuntu.Components 1.3; \n\
888 import Ubuntu.Settings.Components 0.1; \n\
890 import Utils 0.1;\n';
891 var card = cardString(template, components, isCardTool);
892 var code = imports + 'Component {\n' + card + '}\n';
895 return Qt.createQmlObject(code, parent, identifier);
897 console.error("ERROR: Invalid component created.");
898 console.error("Template:");
899 console.error(JSON.stringify(template));
900 console.error("Components:");
901 console.error(JSON.stringify(components));
902 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