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 the template["card-background"] string
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\
32 switch (root.backgroundShapeStyle) { \n\
33 case "inset": return UbuntuShape.Inset; \n\
34 case "shadow": return UbuntuShape.DropShadow; \n\
36 case "flat": return UbuntuShape.Flat; \n\
39 backgroundColor: getColor(0) || "white"; \n\
40 secondaryBackgroundColor: getColor(1) || backgroundColor; \n\
41 backgroundMode: UbuntuShape.VerticalGradient; \n\
42 anchors.fill: parent; \n\
43 source: backgroundImage.source ? backgroundImage : null; \n\
44 property real luminance: Style.luminance(backgroundColor); \n\
45 property Image backgroundImage: Image { \n\
46 objectName: "backgroundImage"; \n\
48 if (cardData && typeof cardData["background"] === "string") return cardData["background"]; \n\
52 function getColor(index) { \n\
53 if (cardData && typeof cardData["background"] === "object" \n\
54 && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) { \n\
55 return cardData["background"]["elements"][index]; \n\
56 } else return index === 0 ? %1 : %2; \n\
61// %1 is used as anchors of artShapeHolder
62// %2 is used as image width
63// %3 is used as image height
64// %4 is used for artShapeSource.hideSource and inner Loader visible
65// %5 is used as aspect ratio fallback
66// %6 is injected as code to artImage
67// %7 is used as image fallback
68var kArtShapeHolderCode = 'Item { \n\
69 id: artShapeHolder; \n\
70 height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height; \n\
71 width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width; \n\
74 id: artShapeLoader; \n\
75 objectName: "artShapeLoader"; \n\
76 readonly property string cardArt: cardData && cardData["art"] || %7; \n\
77 active: cardArt != ""; \n\
78 asynchronous: root.asynchronous; \n\
79 visible: status == Loader.Ready; \n\
80 sourceComponent: Item { \n\
82 objectName: "artShape"; \n\
83 visible: image.status == Image.Ready; \n\
84 readonly property alias image: artImage; \n\
85 ShaderEffectSource { \n\
86 id: artShapeSource; \n\
87 sourceItem: artImage; \n\
88 anchors.centerIn: parent; \n\
94 anchors.fill: parent; \n\
96 sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent; \n\
98 id: artShapeShapeComponent; \n\
100 source: artShapeSource; \n\
101 sourceFillMode: UbuntuShape.PreserveAspectCrop; \n\
102 radius: "medium"; \n\
104 switch (root.artShapeStyle) { \n\
105 case "inset": return UbuntuShape.Inset; \n\
106 case "shadow": return UbuntuShape.DropShadow; \n\
108 case "flat": return UbuntuShape.Flat; \n\
114 id: artShapeIconComponent; \n\
115 ProportionalShape { source: artShapeSource; aspect: UbuntuShape.DropShadow; } \n\
118 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1; \n\
119 readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : %5; \n\
120 Component.onCompleted: { updateWidthHeightBindings(); } \n\
121 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); } \n\
122 function updateWidthHeightBindings() { \n\
123 if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) { \n\
124 width = root.fixedArtShapeSize.width; \n\
125 height = root.fixedArtShapeSize.height; \n\
127 width = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.width }); \n\
128 height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height }); \n\
131 CroppedImageMinimumSourceSize { \n\
133 objectName: "artImage"; \n\
134 source: artShapeLoader.cardArt; \n\
135 asynchronous: root.asynchronous; \n\
147var kAudioButtonCode = 'AbstractButton { \n\
149 anchors.fill: %1; \n\
152 readonly property url source: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["uri"]) || ""; \n\
154 anchors.fill: parent; \n\
155 visible: parent.pressed; \n\
156 radius: "medium"; \n\
159 color: Qt.rgba(0, 0, 0, 0.5); \n\
160 anchors.centerIn: parent; \n\
161 width: parent.width * 0.5; \n\
163 radius: width / 2; \n\
166 anchors.centerIn: parent; \n\
167 width: parent.width * 0.3; \n\
170 name: DashAudioPlayer.playing && AudioUrlComparer.compare(parent.source, DashAudioPlayer.currentSource) ? "media-playback-pause" : "media-playback-start"; \n\
174 if (AudioUrlComparer.compare(source, DashAudioPlayer.currentSource)) { \n\
175 if (DashAudioPlayer.playing) { \n\
176 DashAudioPlayer.pause(); \n\
178 DashAudioPlayer.play(); \n\
181 var playlist = (cardData["quickPreviewData"] && cardData["quickPreviewData"]["playlist"]) || null; \n\
182 DashAudioPlayer.playSource(source, playlist); \n\
185 onPressAndHold: { \n\
186 root.pressAndHold(); \n\
190var kOverlayLoaderCode = 'Loader { \n\
191 id: overlayLoader; \n\
192 readonly property real overlayHeight: (fixedHeaderHeight > 0 ? fixedHeaderHeight : headerHeight) + units.gu(2); \n\
193 anchors.fill: artShapeHolder; \n\
194 active: artShapeLoader.active && artShapeLoader.item && artShapeLoader.item.image.status === Image.Ready || false; \n\
195 asynchronous: root.asynchronous; \n\
196 visible: showHeader && status == Loader.Ready; \n\
197 sourceComponent: UbuntuShapeOverlay { \n\
199 property real luminance: Style.luminance(overlayColor); \n\
200 aspect: UbuntuShape.Flat; \n\
201 radius: "medium"; \n\
202 overlayColor: cardData && cardData["overlayColor"] || "#99000000"; \n\
203 overlayRect: Qt.rect(0, 1 - overlayLoader.overlayHeight / height, 1, 1); \n\
207// multiple row version of HeaderRowCode
208function kHeaderRowCodeGenerator() {
209 var kHeaderRowCodeTemplate = 'Row { \n\
211 objectName: "outerRow"; \n\
212 property real margins: units.gu(1); \n\
213 spacing: margins; \n\
214 height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight; \n\
216 anchors.right: parent.right; \n\
217 anchors.margins: margins; \n\
218 anchors.rightMargin: 0; \n\
223 var args = Array.prototype.slice.call(arguments);
224 var code = kHeaderRowCodeTemplate.arg(args.shift()).arg(args.join(',\n'));
228// multiple item version of kHeaderContainerCode
229function kHeaderContainerCodeGenerator() {
230 var headerContainerCodeTemplate = 'Item { \n\
231 id: headerTitleContainer; \n\
233 width: parent.width - x; \n\
234 implicitHeight: %2; \n\
239 var args = Array.prototype.slice.call(arguments);
240 var code = headerContainerCodeTemplate.arg(args.shift()).arg(args.shift()).arg(args.join(',\n'));
244// %1 is used as anchors of mascotShapeLoader
245var kMascotShapeLoaderCode = 'Loader { \n\
246 id: mascotShapeLoader; \n\
247 objectName: "mascotShapeLoader"; \n\
248 asynchronous: root.asynchronous; \n\
249 active: mascotImage.status === Image.Ready; \n\
250 visible: showHeader && active && status == Loader.Ready; \n\
251 width: units.gu(6); \n\
252 height: units.gu(5.625); \n\
253 sourceComponent: UbuntuShape { image: mascotImage } \n\
257// %1 is used as anchors of mascotImage
258// %2 is used as visible of mascotImage
259// %3 is injected as code to mascotImage
260// %4 is used as fallback image
261var kMascotImageCode = 'CroppedImageMinimumSourceSize { \n\
263 objectName: "mascotImage"; \n\
265 source: cardData && cardData["mascot"] || %4; \n\
266 width: units.gu(6); \n\
267 height: units.gu(5.625); \n\
268 horizontalAlignment: Image.AlignHCenter; \n\
269 verticalAlignment: Image.AlignVCenter; \n\
274// %1 is used as anchors of titleLabel
275// %2 is used as color of titleLabel
276// %3 is used as extra condition for visible of titleLabel
277// %4 is used as title width
278var kTitleLabelCode = 'Label { \n\
280 objectName: "titleLabel"; \n\
282 elide: Text.ElideRight; \n\
283 fontSize: "small"; \n\
284 wrapMode: Text.Wrap; \n\
285 maximumLineCount: 2; \n\
286 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
288 visible: showHeader %3; \n\
290 text: root.title; \n\
291 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal; \n\
292 horizontalAlignment: root.titleAlignment; \n\
295// %1 is used as extra anchors of emblemIcon
296// %2 is used as color of emblemIcon
297// FIXME The width code is a
298// Workaround for bug https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1421293
299var kEmblemIconCode = 'Icon { \n\
301 objectName: "emblemIcon"; \n\
303 bottom: titleLabel.baseline; \n\
304 right: parent.right; \n\
307 source: cardData && cardData["emblem"] || ""; \n\
309 height: source != "" ? titleLabel.font.pixelSize : 0; \n\
310 width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth; \n\
313// %1 is used as anchors of touchdown effect
314var kTouchdownCode = 'UbuntuShape { \n\
316 objectName: "touchdown"; \n\
318 visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed; \n\
319 radius: "medium"; \n\
320 borderSource: "radius_pressed.sci" \n\
323// %1 is used as anchors of subtitleLabel
324// %2 is used as color of subtitleLabel
325var kSubtitleLabelCode = 'Label { \n\
326 id: subtitleLabel; \n\
327 objectName: "subtitleLabel"; \n\
329 anchors.topMargin: units.dp(2); \n\
330 elide: Text.ElideRight; \n\
331 maximumLineCount: 1; \n\
332 fontSize: "x-small"; \n\
333 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
335 visible: titleLabel.visible && titleLabel.text; \n\
336 text: cardData && cardData["subtitle"] || ""; \n\
337 font.weight: Font.Light; \n\
340// %1 is used as anchors of attributesRow
341// %2 is used as color of attributesRow
342var kAttributesRowCode = 'CardAttributes { \n\
343 id: attributesRow; \n\
344 objectName: "attributesRow"; \n\
347 fontScale: root.fontScale; \n\
348 model: cardData && cardData["attributes"]; \n\
351// %1 is used as top anchor of summary
352// %2 is used as topMargin anchor of summary
353// %3 is used as color of summary
354var kSummaryLabelCode = 'Label { \n\
356 objectName: "summaryLabel"; \n\
359 left: parent.left; \n\
360 right: parent.right; \n\
361 margins: units.gu(1); \n\
364 wrapMode: Text.Wrap; \n\
365 maximumLineCount: 5; \n\
366 elide: Text.ElideRight; \n\
367 text: cardData && cardData["summary"] || ""; \n\
368 height: text ? implicitHeight : 0; \n\
369 fontSize: "small"; \n\
373// %1 is used as bottom anchor of audio progress bar
374// %2 is used as left anchor of audio progress bar
375// %3 is used as text color
376var kAudioProgressBarCode = 'CardAudioProgress { \n\
377 id: audioProgressBar; \n\
378 duration: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["duration"]) || 0; \n\
379 source: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["uri"]) || ""; \n\
383 right: parent.right; \n\
384 margins: units.gu(1); \n\
389function sanitizeColor(colorString) {
390 if (colorString !== undefined) {
391 if (colorString.match(/^[#a-z0-9]*$/i) === null) {
392 // This is not the perfect regexp for color
393 // but what we're trying to do here is just protect
394 // against injection so it's ok
401function cardString(template, components) {
404 var templateInteractive = (template == null ? true : (template["non-interactive"] !== undefined ? !template["non-interactive"] : true)) ? "true" : "false";
406 code = 'AbstractButton { \n\
408 property var cardData; \n\
409 property string artShapeStyle: "inset"; \n\
410 property string backgroundShapeStyle: "inset"; \n\
411 property real fontScale: 1.0; \n\
412 property var scopeStyle: null; \n\
413 property int titleAlignment: Text.AlignLeft; \n\
414 property int fixedHeaderHeight: -1; \n\
415 property size fixedArtShapeSize: Qt.size(-1, -1); \n\
416 readonly property string title: cardData && cardData["title"] || ""; \n\
417 property bool asynchronous: true; \n\
418 property bool showHeader: true; \n\
419 implicitWidth: childrenRect.width; \n\
421 \n'.arg(templateInteractive);
423 var hasArt = components["art"] && components["art"]["field"] || false;
424 var hasSummary = components["summary"] || false;
425 var isConciergeMode = components["art"] && components["art"]["conciergeMode"] || false;
426 var artAndSummary = hasArt && hasSummary && !isConciergeMode;
427 var isHorizontal = template["card-layout"] === "horizontal";
428 var hasBackground = (!isHorizontal && (template["card-background"] || components["background"] || artAndSummary)) ||
429 (hasSummary && (template["card-background"] || components["background"]));
430 var hasTitle = components["title"] || false;
431 var hasMascot = components["mascot"] || false;
432 var hasEmblem = components["emblem"] && !(hasMascot && template["card-size"] === "small") || false;
433 var headerAsOverlay = hasArt && template && template["overlay"] === true && (hasTitle || hasMascot);
434 var hasSubtitle = hasTitle && components["subtitle"] || false;
435 var hasHeaderRow = hasMascot && hasTitle;
436 var hasAttributes = hasTitle && components["attributes"] && components["attributes"]["field"] || false;
437 var isAudio = template["quick-preview-type"] === "audio";
440 // For now we only support audio cards with [optional] art, title, subtitle
441 // in horizontal mode
442 // Anything else makes it behave not like an audio card
443 if (hasSummary) isAudio = false;
444 if (!isHorizontal) isAudio = false;
445 if (hasMascot) isAudio = false;
446 if (hasEmblem) isAudio = false;
447 if (headerAsOverlay) isAudio = false;
448 if (hasAttributes) isAudio = false;
452 var templateCardBackground;
453 if (template && typeof template["card-background"] === "string") {
454 templateCardBackground = 'decodeURI("' + encodeURI(template["card-background"]) + '")';
456 templateCardBackground = '""';
459 var backgroundElements0;
460 var backgroundElements1;
461 if (template && typeof template["card-background"] === "object" && (template["card-background"]["type"] === "color" || template["card-background"]["type"] === "gradient")) {
462 var element0 = sanitizeColor(template["card-background"]["elements"][0]);
463 var element1 = sanitizeColor(template["card-background"]["elements"][1]);
464 if (element0 !== undefined) {
465 backgroundElements0 = '"%1"'.arg(element0);
467 if (element1 !== undefined) {
468 backgroundElements1 = '"%1"'.arg(element1);
471 code += kBackgroundLoaderCode.arg(backgroundElements0).arg(backgroundElements1).arg(templateCardBackground);
475 code += 'readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);\n';
477 var widthCode, heightCode;
480 artAnchors = 'left: parent.left';
481 if (hasMascot || hasTitle) {
482 widthCode = 'height * artShape.aspect'
483 heightCode = 'headerHeight + 2 * units.gu(1)';
485 // This side of the else is a bit silly, who wants an horizontal layout without mascot and title?
486 // So we define a "random" height of the image height + 2 gu for the margins
487 widthCode = 'height * artShape.aspect'
488 heightCode = 'units.gu(7.625)';
491 artAnchors = 'horizontalCenter: parent.horizontalCenter;';
492 widthCode = 'root.width'
493 heightCode = 'width / artShape.aspect';
496 var aspectRatio = components["art"] && components["art"]["aspect-ratio"] || 1;
497 if (isNaN(aspectRatio)) {
500 var fallback = components["art"] && components["art"]["fallback"] || "";
501 fallback = encodeURI(fallback);
502 var fallbackStatusCode = "";
503 var fallbackURICode = '""';
504 if (fallback !== "") {
505 // fallbackStatusCode has %6 in it because we want to substitute it for fallbackURICode
506 // which in kArtShapeHolderCode is %7
507 fallbackStatusCode += 'onStatusChanged: if (status === Image.Error) source = %7;';
508 fallbackURICode = 'decodeURI("%1")'.arg(fallback);
510 code += kArtShapeHolderCode.arg(artAnchors).arg(widthCode).arg(heightCode).arg(isConciergeMode ? "false" : "true").arg(aspectRatio).arg(fallbackStatusCode).arg(fallbackURICode);
512 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
515 if (headerAsOverlay) {
516 code += kOverlayLoaderCode;
519 var headerVerticalAnchors;
520 if (headerAsOverlay) {
521 headerVerticalAnchors = 'bottom: artShapeHolder.bottom; \n\
522 bottomMargin: units.gu(1);\n';
526 headerVerticalAnchors = 'top: artShapeHolder.top; \n\
527 topMargin: units.gu(1);\n';
529 headerVerticalAnchors = 'top: artShapeHolder.bottom; \n\
530 topMargin: units.gu(1);\n';
533 headerVerticalAnchors = 'top: parent.top; \n\
534 topMargin: units.gu(1);\n';
538 var headerLeftAnchor;
539 var headerLeftAnchorHasMargin = false;
540 if (isHorizontal && hasArt) {
541 headerLeftAnchor = 'left: artShapeHolder.right; \n\
542 leftMargin: units.gu(1);\n';
543 headerLeftAnchorHasMargin = true;
544 } else if (isHorizontal && isAudio) {
545 headerLeftAnchor = 'left: audioButton.right; \n\
546 leftMargin: units.gu(1);\n';
547 headerLeftAnchorHasMargin = true;
549 headerLeftAnchor = 'left: parent.left;\n';
552 var touchdownOnArtShape = !hasBackground && hasArt && !hasMascot && !hasSummary && !isAudio;
555 code += 'readonly property int headerHeight: row.height;\n'
556 } else if (hasMascot) {
557 code += 'readonly property int headerHeight: mascotImage.height;\n'
558 } else if (hasAttributes) {
559 if (hasTitle && hasSubtitle) {
560 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + attributesRow.height + attributesRow.anchors.topMargin;\n'
561 } else if (hasTitle) {
562 code += 'readonly property int headerHeight: titleLabel.height + attributesRow.height + attributesRow.anchors.topMargin;\n'
564 code += 'readonly property int headerHeight: attributesRow.height;\n'
566 } else if (isAudio) {
568 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + audioProgressBar.height + audioProgressBar.anchors.topMargin;\n'
569 } else if (hasTitle) {
570 code += 'readonly property int headerHeight: titleLabel.height + audioProgressBar.height + audioProgressBar.anchors.topMargin;\n'
572 code += 'readonly property int headerHeight: audioProgressBar.height;\n'
574 } else if (hasSubtitle) {
575 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin;\n'
576 } else if (hasTitle) {
577 code += 'readonly property int headerHeight: titleLabel.height;\n'
579 code += 'readonly property int headerHeight: 0;\n'
582 var mascotShapeCode = '';
585 var useMascotShape = !hasBackground && !headerAsOverlay;
586 var mascotAnchors = '';
588 mascotAnchors += headerLeftAnchor;
589 mascotAnchors += headerVerticalAnchors;
590 if (!headerLeftAnchorHasMargin) {
591 mascotAnchors += 'leftMargin: units.gu(1);\n'
594 mascotAnchors = 'verticalCenter: parent.verticalCenter;'
597 if (useMascotShape) {
598 mascotShapeCode = kMascotShapeLoaderCode.arg(mascotAnchors);
601 var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
602 var fallback = components["mascot"] && components["mascot"]["fallback"] || "";
603 fallback = encodeURI(fallback);
604 var fallbackStatusCode = "";
605 var fallbackURICode = '""';
606 if (fallback !== "") {
607 // fallbackStatusCode has %4 in it because we want to substitute it for fallbackURICode
608 // which in kMascotImageCode is %4
609 fallbackStatusCode += 'onStatusChanged: if (status === Image.Error) source = %4;';
610 fallbackURICode = 'decodeURI("%1")'.arg(fallback);
612 mascotCode = kMascotImageCode.arg(mascotAnchors).arg(mascotImageVisible).arg(fallbackStatusCode).arg(fallbackURICode);
615 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")';
617 var hasTitleContainer = hasTitle && (hasEmblem || (hasMascot && (hasSubtitle || hasAttributes)));
618 var titleSubtitleCode = '';
621 if (headerAsOverlay) {
622 titleColor = 'root.scopeStyle && overlayLoader.item ? root.scopeStyle.getTextColor(overlayLoader.item.luminance) : (overlayLoader.item && overlayLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white")';
623 } else if (hasSummary) {
624 titleColor = 'summary.color';
625 } else if (hasBackground) {
626 titleColor = summaryColorWithBackground;
628 titleColor = 'root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText';
633 var attributesAnchors;
634 var titleContainerAnchors;
635 var titleRightAnchor;
636 var titleWidth = "undefined";
638 var extraRightAnchor = '';
639 var extraLeftAnchor = '';
640 if (!touchdownOnArtShape) {
641 extraRightAnchor = 'rightMargin: units.gu(1); \n';
642 extraLeftAnchor = 'leftMargin: units.gu(1); \n';
643 } else if (headerAsOverlay && !hasEmblem) {
644 extraRightAnchor = 'rightMargin: units.gu(1); \n';
648 titleContainerAnchors = 'verticalCenter: parent.verticalCenter; ';
650 titleContainerAnchors = 'right: parent.right; ';
651 titleContainerAnchors += headerLeftAnchor;
652 titleContainerAnchors += headerVerticalAnchors;
653 if (!headerLeftAnchorHasMargin) {
654 titleContainerAnchors += extraLeftAnchor;
658 titleRightAnchor = 'right: emblemIcon.left; \n\
659 rightMargin: emblemIcon.width > 0 ? units.gu(0.5) : 0; \n';
661 titleRightAnchor = 'right: parent.right; \n'
662 titleRightAnchor += extraRightAnchor;
665 if (hasTitleContainer) {
666 // Using headerTitleContainer
667 titleAnchors = titleRightAnchor;
668 titleAnchors += 'left: parent.left; \n\
670 subtitleAnchors = 'right: parent.right; \n\
671 left: parent.left; \n';
672 subtitleAnchors += extraRightAnchor;
674 attributesAnchors = subtitleAnchors + 'top: subtitleLabel.bottom;\n';
675 subtitleAnchors += 'top: titleLabel.bottom;\n';
677 attributesAnchors = subtitleAnchors + 'top: titleLabel.bottom;\n';
679 } else if (hasMascot) {
680 // Using row without titleContainer
681 titleAnchors = 'verticalCenter: parent.verticalCenter;\n';
682 titleWidth = "parent.width - x";
684 if (headerAsOverlay) {
685 // Using anchors to the overlay
686 titleAnchors = titleRightAnchor;
687 titleAnchors += 'left: parent.left; \n\
688 leftMargin: units.gu(1); \n\
689 top: overlayLoader.top; \n\
690 topMargin: units.gu(1) + overlayLoader.height - overlayLoader.overlayHeight; \n';
692 // Using anchors to the mascot/parent
693 titleAnchors = titleRightAnchor;
694 titleAnchors += headerLeftAnchor;
695 titleAnchors += headerVerticalAnchors;
696 if (!headerLeftAnchorHasMargin) {
697 titleAnchors += extraLeftAnchor;
700 subtitleAnchors = 'left: titleLabel.left; \n\
701 leftMargin: titleLabel.leftMargin; \n';
702 subtitleAnchors += extraRightAnchor;
705 subtitleAnchors += 'right: parent.right; \n';
707 subtitleAnchors += 'right: titleLabel.right; \n';
711 attributesAnchors = subtitleAnchors + 'top: subtitleLabel.bottom;\n';
712 subtitleAnchors += 'top: titleLabel.bottom;\n';
714 attributesAnchors = subtitleAnchors + 'top: titleLabel.bottom;\n';
718 // code for different elements
719 var titleLabelVisibleExtra = (headerAsOverlay ? '&& overlayLoader.active': '');
720 var titleCode = kTitleLabelCode.arg(titleAnchors).arg(titleColor).arg(titleLabelVisibleExtra).arg(titleWidth);
724 // code for the title container
725 var containerCode = [];
726 var containerHeight = 'titleLabel.height';
727 containerCode.push(titleCode);
729 subtitleCode = kSubtitleLabelCode.arg(subtitleAnchors).arg(titleColor);
730 containerCode.push(subtitleCode);
731 containerHeight += ' + subtitleLabel.height';
734 containerCode.push(kEmblemIconCode.arg(extraRightAnchor).arg(titleColor));
737 attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(titleColor);
738 containerCode.push(attributesCode);
739 containerHeight += ' + attributesRow.height';
742 if (hasTitleContainer) {
744 titleSubtitleCode = kHeaderContainerCodeGenerator(titleContainerAnchors, containerHeight, containerCode);
747 titleSubtitleCode = titleCode;
749 titleSubtitleCode += subtitleCode;
752 titleSubtitleCode += attributesCode;
758 var rowCode = [mascotCode, titleSubtitleCode];
759 if (mascotShapeCode != '') {
760 rowCode.unshift(mascotShapeCode);
762 code += kHeaderRowCodeGenerator(headerVerticalAnchors + headerLeftAnchor, rowCode)
764 code += mascotShapeCode + mascotCode + titleSubtitleCode;
768 var audioProgressBarLeftAnchor = 'audioButton.right';
769 var audioProgressBarBottomAnchor = 'audioButton.bottom';
770 var audioProgressBarTextColor = 'root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText';
772 code += kAudioProgressBarCode.arg(audioProgressBarBottomAnchor)
773 .arg(audioProgressBarLeftAnchor)
774 .arg(audioProgressBarTextColor);
776 var audioButtonAnchorsFill;
777 var audioButtonWidth;
778 var audioButtonHeight;
780 audioButtonAnchorsFill = 'artShapeHolder';
781 audioButtonWidth = 'undefined';
782 audioButtonHeight = 'undefined';
784 audioButtonAnchorsFill = 'undefined';
785 audioButtonWidth = 'height';
786 audioButtonHeight = '(root.fixedHeaderHeight > 0 ? root.fixedHeaderHeight : headerHeight) + 2 * units.gu(1)';
788 code += kAudioButtonCode.arg(audioButtonAnchorsFill).arg(audioButtonWidth).arg(audioButtonHeight);
792 var summaryTopAnchor;
793 if (isHorizontal && hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
794 else if (headerAsOverlay && hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
795 else if (hasHeaderRow) summaryTopAnchor = 'row.bottom';
796 else if (hasTitleContainer) summaryTopAnchor = 'headerTitleContainer.bottom';
797 else if (hasMascot) summaryTopAnchor = 'mascotImage.bottom';
798 else if (hasAttributes) summaryTopAnchor = 'attributesRow.bottom';
799 else if (hasSubtitle) summaryTopAnchor = 'subtitleLabel.bottom';
800 else if (hasTitle) summaryTopAnchor = 'titleLabel.bottom';
801 else if (hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
802 else summaryTopAnchor = 'parent.top';
806 summaryColor = summaryColorWithBackground;
808 summaryColor = 'root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText';
811 var summaryTopMargin = (hasMascot || hasSubtitle || hasAttributes ? 'anchors.margins' : '0');
813 code += kSummaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(summaryColor);
816 var touchdownAnchors;
818 touchdownAnchors = 'fill: backgroundLoader';
819 } else if (touchdownOnArtShape) {
820 touchdownAnchors = 'fill: artShapeHolder';
822 touchdownAnchors = 'fill: root'
824 code += kTouchdownCode.arg(touchdownAnchors);
826 var implicitHeight = 'implicitHeight: ';
828 implicitHeight += 'summary.y + summary.height + units.gu(1);\n';
829 } else if (isAudio) {
830 implicitHeight += 'audioButton.height;\n';
831 } else if (headerAsOverlay) {
832 implicitHeight += 'artShapeHolder.height;\n';
833 } else if (hasHeaderRow) {
834 implicitHeight += 'row.y + row.height + units.gu(1);\n';
835 } else if (hasMascot) {
836 implicitHeight += 'mascotImage.y + mascotImage.height;\n';
837 } else if (hasTitleContainer) {
838 implicitHeight += 'headerTitleContainer.y + headerTitleContainer.height + units.gu(1);\n';
839 } else if (hasAttributes) {
840 implicitHeight += 'attributesRow.y + attributesRow.height + units.gu(1);\n';
841 } else if (hasSubtitle) {
842 implicitHeight += 'subtitleLabel.y + subtitleLabel.height + units.gu(1);\n';
843 } else if (hasTitle) {
844 implicitHeight += 'titleLabel.y + titleLabel.height + units.gu(1);\n';
846 implicitHeight += 'artShapeHolder.height;\n';
851 // Close the AbstractButton
852 code += implicitHeight + '}\n';
857function createCardComponent(parent, template, components, identifier) {
858 var imports = 'import QtQuick 2.4; \n\
859 import Ubuntu.Components 1.3; \n\
860 import Ubuntu.Settings.Components 0.1; \n\
862 import Utils 0.1;\n';
863 var card = cardString(template, components);
864 var code = imports + 'Component {\n' + card + '}\n';
867 return Qt.createQmlObject(code, parent, identifier);
869 console.error("ERROR: Invalid component created.");
870 console.error("Template:");
871 console.error(JSON.stringify(template));
872 console.error("Components:");
873 console.error(JSON.stringify(components));
874 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