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\
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 ? %2 : %3; \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 injected as code to artImage
65var kArtShapeHolderCode = 'Item { \n\
66 id: artShapeHolder; \n\
67 height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height; \n\
68 width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width; \n\
71 id: artShapeLoader; \n\
72 objectName: "artShapeLoader"; \n\
73 active: cardData && cardData["art"] || false; \n\
74 asynchronous: root.asynchronous; \n\
75 visible: status == Loader.Ready; \n\
76 sourceComponent: Item { \n\
78 objectName: "artShape"; \n\
79 readonly property bool doShapeItem: components["art"]["conciergeMode"] !== true; \n\
80 visible: image.status == Image.Ready; \n\
81 readonly property alias image: artImage; \n\
82 ShaderEffectSource { \n\
83 id: artShapeSource; \n\
84 sourceItem: artImage; \n\
85 anchors.centerIn: parent; \n\
88 hideSource: doShapeItem; \n\
91 anchors.fill: parent; \n\
92 visible: artShape.doShapeItem; \n\
93 sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent; \n\
95 id: artShapeShapeComponent; \n\
97 source: artShapeSource; \n\
98 sourceFillMode: UbuntuShape.PreserveAspectCrop; \n\
101 switch (root.artShapeStyle) { \n\
102 case "inset": return UbuntuShape.Inset; \n\
103 case "shadow": return UbuntuShape.DropShadow; \n\
105 case "flat": return UbuntuShape.Flat; \n\
111 id: artShapeIconComponent; \n\
112 ProportionalShape { source: artShapeSource; aspect: UbuntuShape.DropShadow; } \n\
115 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1; \n\
116 readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1; \n\
117 Component.onCompleted: { updateWidthHeightBindings(); } \n\
118 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); } \n\
119 function updateWidthHeightBindings() { \n\
120 if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) { \n\
121 width = root.fixedArtShapeSize.width; \n\
122 height = root.fixedArtShapeSize.height; \n\
124 width = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.width }); \n\
125 height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height }); \n\
128 CroppedImageMinimumSourceSize { \n\
130 objectName: "artImage"; \n\
131 source: cardData && cardData["art"] || ""; \n\
132 asynchronous: root.asynchronous; \n\
144var kAudioButtonCode = 'AbstractButton { \n\
146 anchors.fill: %1; \n\
149 readonly property url source: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["uri"]) || ""; \n\
151 anchors.fill: parent; \n\
152 visible: parent.pressed; \n\
153 radius: "medium"; \n\
156 anchors.fill: parent; \n\
157 anchors.margins: parent.height > units.gu(5) ? units.gu(2) : 0; \n\
159 name: DashAudioPlayer.playing && AudioUrlComparer.compare(parent.source, DashAudioPlayer.currentSource) ? "media-playback-pause" : "media-playback-start"; \n\
162 if (AudioUrlComparer.compare(source, DashAudioPlayer.currentSource)) { \n\
163 if (DashAudioPlayer.playing) { \n\
164 DashAudioPlayer.pause(); \n\
166 DashAudioPlayer.play(); \n\
169 var playlist = (cardData["quickPreviewData"] && cardData["quickPreviewData"]["playlist"]) || null; \n\
170 DashAudioPlayer.playSource(source, playlist); \n\
173 onPressAndHold: { \n\
174 root.pressAndHold(); \n\
178var kOverlayLoaderCode = 'Loader { \n\
179 id: overlayLoader; \n\
180 readonly property real overlayHeight: (fixedHeaderHeight > 0 ? fixedHeaderHeight : headerHeight) + units.gu(2); \n\
181 anchors.fill: artShapeHolder; \n\
182 active: artShapeLoader.active && artShapeLoader.item && artShapeLoader.item.image.status === Image.Ready || false; \n\
183 asynchronous: root.asynchronous; \n\
184 visible: showHeader && status == Loader.Ready; \n\
185 sourceComponent: UbuntuShapeOverlay { \n\
187 property real luminance: Style.luminance(overlayColor); \n\
188 aspect: UbuntuShape.Flat; \n\
189 radius: "medium"; \n\
190 overlayColor: cardData && cardData["overlayColor"] || "#99000000"; \n\
191 overlayRect: Qt.rect(0, 1 - overlayLoader.overlayHeight / height, 1, 1); \n\
195// multiple row version of HeaderRowCode
196function kHeaderRowCodeGenerator() {
197 var kHeaderRowCodeTemplate = 'Row { \n\
199 objectName: "outerRow"; \n\
200 property real margins: units.gu(1); \n\
201 spacing: margins; \n\
202 height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight; \n\
204 anchors.right: parent.right; \n\
205 anchors.margins: margins; \n\
206 anchors.rightMargin: 0; \n\
211 var args = Array.prototype.slice.call(arguments);
212 var code = kHeaderRowCodeTemplate.arg(args.shift()).arg(args.join(',\n'));
216// multiple item version of kHeaderContainerCode
217function kHeaderContainerCodeGenerator() {
218 var headerContainerCodeTemplate = 'Item { \n\
219 id: headerTitleContainer; \n\
221 width: parent.width - x; \n\
222 implicitHeight: %2; \n\
227 var args = Array.prototype.slice.call(arguments);
228 var code = headerContainerCodeTemplate.arg(args.shift()).arg(args.shift()).arg(args.join(',\n'));
232// %1 is used as anchors of mascotShapeLoader
233var kMascotShapeLoaderCode = 'Loader { \n\
234 id: mascotShapeLoader; \n\
235 objectName: "mascotShapeLoader"; \n\
236 asynchronous: root.asynchronous; \n\
237 active: mascotImage.status === Image.Ready; \n\
238 visible: showHeader && active && status == Loader.Ready; \n\
239 width: units.gu(6); \n\
240 height: units.gu(5.625); \n\
241 sourceComponent: UbuntuShape { image: mascotImage } \n\
245// %1 is used as anchors of mascotImage
246// %2 is used as visible of mascotImage
247// %3 is injected as code to mascotImage
248var kMascotImageCode = 'CroppedImageMinimumSourceSize { \n\
250 objectName: "mascotImage"; \n\
252 source: cardData && cardData["mascot"] || ""; \n\
253 width: units.gu(6); \n\
254 height: units.gu(5.625); \n\
255 horizontalAlignment: Image.AlignHCenter; \n\
256 verticalAlignment: Image.AlignVCenter; \n\
261// %1 is used as anchors of titleLabel
262// %2 is used as color of titleLabel
263// %3 is used as extra condition for visible of titleLabel
264// %4 is used as title width
265var kTitleLabelCode = 'Label { \n\
267 objectName: "titleLabel"; \n\
269 elide: Text.ElideRight; \n\
270 fontSize: "small"; \n\
271 wrapMode: Text.Wrap; \n\
272 maximumLineCount: 2; \n\
273 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
275 visible: showHeader %3; \n\
277 text: root.title; \n\
278 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal; \n\
279 horizontalAlignment: root.titleAlignment; \n\
282// %1 is used as extra anchors of emblemIcon
283// %2 is used as color of emblemIcon
284// FIXME The width code is a
285// Workaround for bug https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1421293
286var kEmblemIconCode = 'Icon { \n\
288 objectName: "emblemIcon"; \n\
290 bottom: titleLabel.baseline; \n\
291 right: parent.right; \n\
294 source: cardData && cardData["emblem"] || ""; \n\
296 height: source != "" ? titleLabel.font.pixelSize : 0; \n\
297 width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth; \n\
300// %1 is used as anchors of touchdown effect
301var kTouchdownCode = 'UbuntuShape { \n\
303 objectName: "touchdown"; \n\
305 visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed; \n\
306 radius: "medium"; \n\
307 borderSource: "radius_pressed.sci" \n\
310// %1 is used as anchors of subtitleLabel
311// %2 is used as color of subtitleLabel
312var kSubtitleLabelCode = 'Label { \n\
313 id: subtitleLabel; \n\
314 objectName: "subtitleLabel"; \n\
316 anchors.topMargin: units.dp(2); \n\
317 elide: Text.ElideRight; \n\
318 maximumLineCount: 1; \n\
319 fontSize: "x-small"; \n\
320 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
322 visible: titleLabel.visible && titleLabel.text; \n\
323 text: cardData && cardData["subtitle"] || ""; \n\
324 font.weight: Font.Light; \n\
327// %1 is used as anchors of attributesRow
328// %2 is used as color of attributesRow
329var kAttributesRowCode = 'CardAttributes { \n\
330 id: attributesRow; \n\
331 objectName: "attributesRow"; \n\
334 fontScale: root.fontScale; \n\
335 model: cardData && cardData["attributes"]; \n\
338// %1 is used as top anchor of summary
339// %2 is used as topMargin anchor of summary
340// %3 is used as color of summary
341var kSummaryLabelCode = 'Label { \n\
343 objectName: "summaryLabel"; \n\
346 left: parent.left; \n\
347 right: parent.right; \n\
348 margins: units.gu(1); \n\
351 wrapMode: Text.Wrap; \n\
352 maximumLineCount: 5; \n\
353 elide: Text.ElideRight; \n\
354 text: cardData && cardData["summary"] || ""; \n\
355 height: text ? implicitHeight : 0; \n\
356 fontSize: "small"; \n\
360// %1 is used as bottom anchor of audio progress bar
361// %2 is used as left anchor of audio progress bar
362// %3 is used as text color
363var kAudioProgressBarCode = 'CardAudioProgress { \n\
364 id: audioProgressBar; \n\
365 duration: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["duration"]) || 0; \n\
366 source: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["uri"]) || ""; \n\
370 right: parent.right; \n\
371 margins: units.gu(1); \n\
376function sanitizeColor(colorString) {
377 if (colorString !== undefined) {
378 if (colorString.match(/^[#a-z0-9]*$/i) === null) {
379 // This is not the perfect regexp for color
380 // but what we're trying to do here is just protect
381 // against injection so it's ok
388function cardString(template, components) {
391 var templateInteractive = (template == null ? true : (template["non-interactive"] !== undefined ? !template["non-interactive"] : true)) ? "true" : "false";
393 code = 'AbstractButton { \n\
395 property var components; \n\
396 property var cardData; \n\
397 property string artShapeStyle: "inset"; \n\
398 property string backgroundShapeStyle: "inset"; \n\
399 property real fontScale: 1.0; \n\
400 property var scopeStyle: null; \n\
401 property int titleAlignment: Text.AlignLeft; \n\
402 property int fixedHeaderHeight: -1; \n\
403 property size fixedArtShapeSize: Qt.size(-1, -1); \n\
404 readonly property string title: cardData && cardData["title"] || ""; \n\
405 property bool asynchronous: true; \n\
406 property bool showHeader: true; \n\
407 implicitWidth: childrenRect.width; \n\
409 \n'.arg(templateInteractive);
411 var hasArt = components["art"] && components["art"]["field"] || false;
412 var hasSummary = components["summary"] || false;
413 var artAndSummary = hasArt && hasSummary && components["art"]["conciergeMode"] !== true;
414 var isHorizontal = template["card-layout"] === "horizontal";
415 var hasBackground = (!isHorizontal && (template["card-background"] || components["background"] || artAndSummary)) ||
416 (hasSummary && (template["card-background"] || components["background"]));
417 var hasTitle = components["title"] || false;
418 var hasMascot = components["mascot"] || false;
419 var hasEmblem = components["emblem"] && !(hasMascot && template["card-size"] === "small") || false;
420 var headerAsOverlay = hasArt && template && template["overlay"] === true && (hasTitle || hasMascot);
421 var hasSubtitle = hasTitle && components["subtitle"] || false;
422 var hasHeaderRow = hasMascot && hasTitle;
423 var hasAttributes = hasTitle && components["attributes"] && components["attributes"]["field"] || false;
424 var isAudio = template["quick-preview-type"] === "audio";
427 // For now we only support audio cards with [optional] art, title, subtitle
428 // in horizontal mode
429 // Anything else makes it behave not like an audio card
430 if (hasSummary) isAudio = false;
431 if (!isHorizontal) isAudio = false;
432 if (hasMascot) isAudio = false;
433 if (hasEmblem) isAudio = false;
434 if (headerAsOverlay) isAudio = false;
435 if (hasAttributes) isAudio = false;
439 var templateCardBackground;
440 if (template && typeof template["card-background"] === "string") {
441 templateCardBackground = 'decodeURI("' + encodeURI(template["card-background"]) + '")';
443 templateCardBackground = '""';
446 var backgroundElements0;
447 var backgroundElements1;
448 if (template && typeof template["card-background"] === "object" && (template["card-background"]["type"] === "color" || template["card-background"]["type"] === "gradient")) {
449 var element0 = sanitizeColor(template["card-background"]["elements"][0]);
450 var element1 = sanitizeColor(template["card-background"]["elements"][1]);
451 if (element0 !== undefined) {
452 backgroundElements0 = '"%1"'.arg(element0);
454 if (element1 !== undefined) {
455 backgroundElements1 = '"%1"'.arg(element1);
458 code += kBackgroundLoaderCode.arg(templateCardBackground).arg(backgroundElements0).arg(backgroundElements1);
462 code += 'readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);\n';
464 var widthCode, heightCode;
467 artAnchors = 'left: parent.left';
468 if (hasMascot || hasTitle) {
469 widthCode = 'height * artShape.aspect'
470 heightCode = 'headerHeight + 2 * units.gu(1)';
472 // This side of the else is a bit silly, who wants an horizontal layout without mascot and title?
473 // So we define a "random" height of the image height + 2 gu for the margins
474 widthCode = 'height * artShape.aspect'
475 heightCode = 'units.gu(7.625)';
478 artAnchors = 'horizontalCenter: parent.horizontalCenter;';
479 widthCode = 'root.width'
480 heightCode = 'width / artShape.aspect';
483 var fallback = components["art"] && components["art"]["fallback"] || "";
484 fallback = encodeURI(fallback);
485 var fallbackCode = "";
486 if (fallback !== "") {
487 fallbackCode += 'onStatusChanged: if (status === Image.Error) source = decodeURI("%1");'.arg(fallback);
489 code += kArtShapeHolderCode.arg(artAnchors).arg(widthCode).arg(heightCode).arg(fallbackCode);
491 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
494 if (headerAsOverlay) {
495 code += kOverlayLoaderCode;
498 var headerVerticalAnchors;
499 if (headerAsOverlay) {
500 headerVerticalAnchors = 'bottom: artShapeHolder.bottom; \n\
501 bottomMargin: units.gu(1);\n';
505 headerVerticalAnchors = 'top: artShapeHolder.top; \n\
506 topMargin: units.gu(1);\n';
508 headerVerticalAnchors = 'top: artShapeHolder.bottom; \n\
509 topMargin: units.gu(1);\n';
512 headerVerticalAnchors = 'top: parent.top; \n\
513 topMargin: units.gu(1);\n';
517 var headerLeftAnchor;
518 var headerLeftAnchorHasMargin = false;
519 if (isHorizontal && hasArt) {
520 headerLeftAnchor = 'left: artShapeHolder.right; \n\
521 leftMargin: units.gu(1);\n';
522 headerLeftAnchorHasMargin = true;
523 } else if (isHorizontal && isAudio) {
524 headerLeftAnchor = 'left: audioButton.right; \n\
525 leftMargin: units.gu(1);\n';
526 headerLeftAnchorHasMargin = true;
528 headerLeftAnchor = 'left: parent.left;\n';
531 var touchdownOnArtShape = !hasBackground && hasArt && !hasMascot && !hasSummary && !isAudio;
534 code += 'readonly property int headerHeight: row.height;\n'
535 } else if (hasMascot) {
536 code += 'readonly property int headerHeight: mascotImage.height;\n'
537 } else if (hasAttributes) {
538 if (hasTitle && hasSubtitle) {
539 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + attributesRow.height + attributesRow.anchors.topMargin;\n'
540 } else if (hasTitle) {
541 code += 'readonly property int headerHeight: titleLabel.height + attributesRow.height + attributesRow.anchors.topMargin;\n'
543 code += 'readonly property int headerHeight: attributesRow.height;\n'
545 } else if (isAudio) {
547 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + audioProgressBar.height + audioProgressBar.anchors.topMargin;\n'
548 } else if (hasTitle) {
549 code += 'readonly property int headerHeight: titleLabel.height + audioProgressBar.height + audioProgressBar.anchors.topMargin;\n'
551 code += 'readonly property int headerHeight: audioProgressBar.height;\n'
553 } else if (hasSubtitle) {
554 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin;\n'
555 } else if (hasTitle) {
556 code += 'readonly property int headerHeight: titleLabel.height;\n'
558 code += 'readonly property int headerHeight: 0;\n'
561 var mascotShapeCode = '';
564 var useMascotShape = !hasBackground && !headerAsOverlay;
565 var mascotAnchors = '';
567 mascotAnchors += headerLeftAnchor;
568 mascotAnchors += headerVerticalAnchors;
569 if (!headerLeftAnchorHasMargin) {
570 mascotAnchors += 'leftMargin: units.gu(1);\n'
573 mascotAnchors = 'verticalCenter: parent.verticalCenter;'
576 if (useMascotShape) {
577 mascotShapeCode = kMascotShapeLoaderCode.arg(mascotAnchors);
580 var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
581 var fallback = components["mascot"] && components["mascot"]["fallback"] || "";
582 fallback = encodeURI(fallback);
583 var fallbackCode = "";
584 if (fallback !== "") {
585 fallbackCode += 'onStatusChanged: if (status === Image.Error) source = decodeURI("%1");'.arg(fallback);
587 mascotCode = kMascotImageCode.arg(mascotAnchors).arg(mascotImageVisible).arg(fallbackCode);
590 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")';
592 var hasTitleContainer = hasTitle && (hasEmblem || (hasMascot && (hasSubtitle || hasAttributes)));
593 var titleSubtitleCode = '';
596 if (headerAsOverlay) {
597 titleColor = 'root.scopeStyle && overlayLoader.item ? root.scopeStyle.getTextColor(overlayLoader.item.luminance) : (overlayLoader.item && overlayLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white")';
598 } else if (hasSummary) {
599 titleColor = 'summary.color';
600 } else if (hasBackground) {
601 titleColor = summaryColorWithBackground;
603 titleColor = 'root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText';
608 var attributesAnchors;
609 var titleContainerAnchors;
610 var titleRightAnchor;
611 var titleWidth = "undefined";
613 var extraRightAnchor = '';
614 var extraLeftAnchor = '';
615 if (!touchdownOnArtShape) {
616 extraRightAnchor = 'rightMargin: units.gu(1); \n';
617 extraLeftAnchor = 'leftMargin: units.gu(1); \n';
618 } else if (headerAsOverlay && !hasEmblem) {
619 extraRightAnchor = 'rightMargin: units.gu(1); \n';
623 titleContainerAnchors = 'verticalCenter: parent.verticalCenter; ';
625 titleContainerAnchors = 'right: parent.right; ';
626 titleContainerAnchors += headerLeftAnchor;
627 titleContainerAnchors += headerVerticalAnchors;
628 if (!headerLeftAnchorHasMargin) {
629 titleContainerAnchors += extraLeftAnchor;
633 titleRightAnchor = 'right: emblemIcon.left; \n\
634 rightMargin: emblemIcon.width > 0 ? units.gu(0.5) : 0; \n';
636 titleRightAnchor = 'right: parent.right; \n'
637 titleRightAnchor += extraRightAnchor;
640 if (hasTitleContainer) {
641 // Using headerTitleContainer
642 titleAnchors = titleRightAnchor;
643 titleAnchors += 'left: parent.left; \n\
645 subtitleAnchors = 'right: parent.right; \n\
646 left: parent.left; \n';
647 subtitleAnchors += extraRightAnchor;
649 attributesAnchors = subtitleAnchors + 'top: subtitleLabel.bottom;\n';
650 subtitleAnchors += 'top: titleLabel.bottom;\n';
652 attributesAnchors = subtitleAnchors + 'top: titleLabel.bottom;\n';
654 } else if (hasMascot) {
655 // Using row without titleContainer
656 titleAnchors = 'verticalCenter: parent.verticalCenter;\n';
657 titleWidth = "parent.width - x";
659 if (headerAsOverlay) {
660 // Using anchors to the overlay
661 titleAnchors = titleRightAnchor;
662 titleAnchors += 'left: parent.left; \n\
663 leftMargin: units.gu(1); \n\
664 top: overlayLoader.top; \n\
665 topMargin: units.gu(1) + overlayLoader.height - overlayLoader.overlayHeight; \n';
667 // Using anchors to the mascot/parent
668 titleAnchors = titleRightAnchor;
669 titleAnchors += headerLeftAnchor;
670 titleAnchors += headerVerticalAnchors;
671 if (!headerLeftAnchorHasMargin) {
672 titleAnchors += extraLeftAnchor;
675 subtitleAnchors = 'left: titleLabel.left; \n\
676 leftMargin: titleLabel.leftMargin; \n';
677 subtitleAnchors += extraRightAnchor;
680 subtitleAnchors += 'right: parent.right; \n';
682 subtitleAnchors += 'right: titleLabel.right; \n';
686 attributesAnchors = subtitleAnchors + 'top: subtitleLabel.bottom;\n';
687 subtitleAnchors += 'top: titleLabel.bottom;\n';
689 attributesAnchors = subtitleAnchors + 'top: titleLabel.bottom;\n';
693 // code for different elements
694 var titleLabelVisibleExtra = (headerAsOverlay ? '&& overlayLoader.active': '');
695 var titleCode = kTitleLabelCode.arg(titleAnchors).arg(titleColor).arg(titleLabelVisibleExtra).arg(titleWidth);
699 // code for the title container
700 var containerCode = [];
701 var containerHeight = 'titleLabel.height';
702 containerCode.push(titleCode);
704 subtitleCode = kSubtitleLabelCode.arg(subtitleAnchors).arg(titleColor);
705 containerCode.push(subtitleCode);
706 containerHeight += ' + subtitleLabel.height';
709 containerCode.push(kEmblemIconCode.arg(extraRightAnchor).arg(titleColor));
712 attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(titleColor);
713 containerCode.push(attributesCode);
714 containerHeight += ' + attributesRow.height';
717 if (hasTitleContainer) {
719 titleSubtitleCode = kHeaderContainerCodeGenerator(titleContainerAnchors, containerHeight, containerCode);
722 titleSubtitleCode = titleCode;
724 titleSubtitleCode += subtitleCode;
727 titleSubtitleCode += attributesCode;
733 var rowCode = [mascotCode, titleSubtitleCode];
734 if (mascotShapeCode != '') {
735 rowCode.unshift(mascotShapeCode);
737 code += kHeaderRowCodeGenerator(headerVerticalAnchors + headerLeftAnchor, rowCode)
739 code += mascotShapeCode + mascotCode + titleSubtitleCode;
743 var audioProgressBarLeftAnchor = 'audioButton.right';
744 var audioProgressBarBottomAnchor = 'audioButton.bottom';
745 var audioProgressBarTextColor = 'root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText';
747 code += kAudioProgressBarCode.arg(audioProgressBarBottomAnchor)
748 .arg(audioProgressBarLeftAnchor)
749 .arg(audioProgressBarTextColor);
751 var audioButtonAnchorsFill;
752 var audioButtonWidth;
753 var audioButtonHeight;
755 audioButtonAnchorsFill = 'artShapeHolder';
756 audioButtonWidth = 'undefined';
757 audioButtonHeight = 'undefined';
759 audioButtonAnchorsFill = 'undefined';
760 audioButtonWidth = 'height';
761 audioButtonHeight = '(root.fixedHeaderHeight > 0 ? root.fixedHeaderHeight : headerHeight) + 2 * units.gu(1)';
763 code += kAudioButtonCode.arg(audioButtonAnchorsFill).arg(audioButtonWidth).arg(audioButtonHeight);
767 var summaryTopAnchor;
768 if (isHorizontal && hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
769 else if (headerAsOverlay && hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
770 else if (hasHeaderRow) summaryTopAnchor = 'row.bottom';
771 else if (hasTitleContainer) summaryTopAnchor = 'headerTitleContainer.bottom';
772 else if (hasMascot) summaryTopAnchor = 'mascotImage.bottom';
773 else if (hasAttributes) summaryTopAnchor = 'attributesRow.bottom';
774 else if (hasSubtitle) summaryTopAnchor = 'subtitleLabel.bottom';
775 else if (hasTitle) summaryTopAnchor = 'titleLabel.bottom';
776 else if (hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
777 else summaryTopAnchor = 'parent.top';
781 summaryColor = summaryColorWithBackground;
783 summaryColor = 'root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText';
786 var summaryTopMargin = (hasMascot || hasSubtitle || hasAttributes ? 'anchors.margins' : '0');
788 code += kSummaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(summaryColor);
791 var touchdownAnchors;
793 touchdownAnchors = 'fill: backgroundLoader';
794 } else if (touchdownOnArtShape) {
795 touchdownAnchors = 'fill: artShapeHolder';
797 touchdownAnchors = 'fill: root'
799 code += kTouchdownCode.arg(touchdownAnchors);
801 var implicitHeight = 'implicitHeight: ';
803 implicitHeight += 'summary.y + summary.height + units.gu(1);\n';
804 } else if (isAudio) {
805 implicitHeight += 'audioButton.height;\n';
806 } else if (headerAsOverlay) {
807 implicitHeight += 'artShapeHolder.height;\n';
808 } else if (hasHeaderRow) {
809 implicitHeight += 'row.y + row.height + units.gu(1);\n';
810 } else if (hasMascot) {
811 implicitHeight += 'mascotImage.y + mascotImage.height;\n';
812 } else if (hasTitleContainer) {
813 implicitHeight += 'headerTitleContainer.y + headerTitleContainer.height + units.gu(1);\n';
814 } else if (hasAttributes) {
815 implicitHeight += 'attributesRow.y + attributesRow.height + units.gu(1);\n';
816 } else if (hasSubtitle) {
817 implicitHeight += 'subtitleLabel.y + subtitleLabel.height + units.gu(1);\n';
818 } else if (hasTitle) {
819 implicitHeight += 'titleLabel.y + titleLabel.height + units.gu(1);\n';
821 implicitHeight += 'artShapeHolder.height;\n';
826 // Close the AbstractButton
827 code += implicitHeight + '}\n';
832function createCardComponent(parent, template, components) {
833 var imports = 'import QtQuick 2.4; \n\
834 import Ubuntu.Components 1.3; \n\
835 import Ubuntu.Settings.Components 0.1; \n\
837 import Utils 0.1;\n';
838 var card = cardString(template, components);
839 var code = imports + 'Component {\n' + card + '}\n';
842 return Qt.createQmlObject(code, parent, "createCardComponent");
844 console.error("ERROR: Invalid component created.");
845 console.error("Template:");
846 console.error(JSON.stringify(template));
847 console.error("Components:");
848 console.error(JSON.stringify(components));
849 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