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/>.
19var kBackgroundLoaderCode = 'Loader {\n\
20 id: backgroundLoader; \n\
21 objectName: "backgroundLoader"; \n\
22 anchors.fill: parent; \n\
23 asynchronous: root.asynchronous; \n\
24 visible: status == Loader.Ready; \n\
25 sourceComponent: UbuntuShape { \n\
26 objectName: "background"; \n\
28 color: getColor(0) || "white"; \n\
29 gradientColor: getColor(1) || color; \n\
30 anchors.fill: parent; \n\
31 image: backgroundImage.source ? backgroundImage : null; \n\
32 property real luminance: Style.luminance(color); \n\
33 property Image backgroundImage: Image { \n\
34 objectName: "backgroundImage"; \n\
36 if (cardData && typeof cardData["background"] === "string") return cardData["background"]; \n\
37 else if (template && typeof template["card-background"] === "string") return template["card-background"]; \n\
41 function getColor(index) { \n\
42 if (cardData && typeof cardData["background"] === "object" \n\
43 && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) { \n\
44 return cardData["background"]["elements"][index]; \n\
45 } else if (template && typeof template["card-background"] === "object" \n\
46 && (template["card-background"]["type"] === "color" || template["card-background"]["type"] === "gradient")) { \n\
47 return template["card-background"]["elements"][index]; \n\
48 } else return undefined; \n\
53// %1 is used as anchors of artShapeHolder
54// %2 is used as image width
55// %3 is used as image height
56var kArtShapeHolderCode = 'Item { \n\
57 id: artShapeHolder; \n\
58 height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height; \n\
59 width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width; \n\
62 id: artShapeLoader; \n\
63 objectName: "artShapeLoader"; \n\
64 active: cardData && cardData["art"] || false; \n\
65 asynchronous: root.asynchronous; \n\
66 visible: status == Loader.Ready; \n\
67 sourceComponent: Item { \n\
69 objectName: "artShape"; \n\
70 property bool doShapeItem: components["art"]["conciergeMode"] !== true; \n\
71 visible: image.status == Image.Ready; \n\
72 readonly property alias image: artImage.image; \n\
73 ShaderEffectSource { \n\
74 id: artShapeSource; \n\
75 sourceItem: artImage; \n\
76 anchors.centerIn: parent; \n\
79 hideSource: doShapeItem; \n\
82 image: artShapeSource; \n\
83 anchors.fill: parent; \n\
84 visible: doShapeItem; \n\
87 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1; \n\
88 readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1; \n\
89 Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; } \n\
90 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); } \n\
91 function updateWidthHeightBindings() { \n\
92 if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) { \n\
93 width = root.fixedArtShapeSize.width; \n\
94 height = root.fixedArtShapeSize.height; \n\
96 width = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.width }); \n\
97 height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height }); \n\
100 CroppedImageMinimumSourceSize { \n\
102 objectName: "artImage"; \n\
103 source: cardData && cardData["art"] || ""; \n\
104 asynchronous: root.asynchronous; \n\
115var kAudioButtonCode = 'AbstractButton { \n\
117 anchors.fill: %1; \n\
120 readonly property url source: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["uri"]) || ""; \n\
122 anchors.fill: parent; \n\
123 visible: parent.pressed; \n\
124 radius: "medium"; \n\
125 borderSource: "radius_pressed.sci" \n\
128 anchors.fill: parent; \n\
129 anchors.margins: parent.height > units.gu(5) ? units.gu(2) : units.gu(0); \n\
131 name: DashAudioPlayer.isCurrentSource(parent.source) && DashAudioPlayer.playing ? "media-playback-pause" : "media-playback-start"; \n\
134 if (DashAudioPlayer.isCurrentSource(source)) { \n\
135 if (DashAudioPlayer.playing) { \n\
136 DashAudioPlayer.pause(); \n\
138 DashAudioPlayer.play(); \n\
141 DashAudioPlayer.playSource(source); \n\
146var kOverlayLoaderCode = 'Loader { \n\
147 id: overlayLoader; \n\
149 left: artShapeHolder.left; \n\
150 right: artShapeHolder.right; \n\
151 bottom: artShapeHolder.bottom; \n\
153 active: artShapeLoader.active && artShapeLoader.item && artShapeLoader.item.image.status === Image.Ready || false; \n\
154 asynchronous: root.asynchronous; \n\
155 visible: showHeader && status == Loader.Ready; \n\
156 sourceComponent: ShaderEffect { \n\
158 height: (fixedHeaderHeight > 0 ? fixedHeaderHeight : headerHeight) + units.gu(2); \n\
159 property real luminance: Style.luminance(overlayColor); \n\
160 property color overlayColor: cardData && cardData["overlayColor"] || "#99000000"; \n\
161 property var source: ShaderEffectSource { \n\
162 id: shaderSource; \n\
163 sourceItem: artShapeLoader.item; \n\
164 onVisibleChanged: if (visible) scheduleUpdate(); \n\
166 sourceRect: Qt.rect(0, artShapeLoader.height - overlay.height, artShapeLoader.width, overlay.height); \n\
169 uniform highp mat4 qt_Matrix; \n\
170 attribute highp vec4 qt_Vertex; \n\
171 attribute highp vec2 qt_MultiTexCoord0; \n\
172 varying highp vec2 coord; \n\
174 coord = qt_MultiTexCoord0; \n\
175 gl_Position = qt_Matrix * qt_Vertex; \n\
177 fragmentShader: " \n\
178 varying highp vec2 coord; \n\
179 uniform sampler2D source; \n\
180 uniform lowp float qt_Opacity; \n\
181 uniform highp vec4 overlayColor; \n\
183 lowp vec4 tex = texture2D(source, coord); \n\
184 gl_FragColor = vec4(overlayColor.r, overlayColor.g, overlayColor.b, 1) * qt_Opacity * overlayColor.a * tex.a; \n\
189// multiple row version of HeaderRowCode
190function kHeaderRowCodeGenerator() {
191var kHeaderRowCodeTemplate = 'Row { \n\
193 objectName: "outerRow"; \n\
194 property real margins: units.gu(1); \n\
195 spacing: margins; \n\
196 height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight; \n\
198 anchors.right: parent.right; \n\
199 anchors.margins: margins; \n\
200 anchors.rightMargin: 0; \n\
205 var args = Array.prototype.slice.call(arguments);
206 var code = kHeaderRowCodeTemplate.arg(args.shift()).arg(args.join(',\n'));
210// multiple item version of kHeaderContainerCode
211function kHeaderContainerCodeGenerator() {
212 var headerContainerCodeTemplate = 'Item { \n\
213 id: headerTitleContainer; \n\
215 width: parent.width - x; \n\
216 implicitHeight: %2; \n\
221 var args = Array.prototype.slice.call(arguments);
222 var code = headerContainerCodeTemplate.arg(args.shift()).arg(args.shift()).arg(args.join(',\n'));
226// %1 is used as anchors of mascotShapeLoader
227var kMascotShapeLoaderCode = 'Loader { \n\
228 id: mascotShapeLoader; \n\
229 objectName: "mascotShapeLoader"; \n\
230 asynchronous: root.asynchronous; \n\
231 active: mascotImage.image.status === Image.Ready; \n\
232 visible: showHeader && active && status == Loader.Ready; \n\
233 width: units.gu(6); \n\
234 height: units.gu(5.625); \n\
235 sourceComponent: UbuntuShape { image: mascotImage.image } \n\
239// %1 is used as anchors of mascotImage
240// %2 is used as visible of mascotImage
241var kMascotImageCode = 'CroppedImageMinimumSourceSize { \n\
243 objectName: "mascotImage"; \n\
245 source: cardData && cardData["mascot"] || ""; \n\
246 width: units.gu(6); \n\
247 height: units.gu(5.625); \n\
248 horizontalAlignment: Image.AlignHCenter; \n\
249 verticalAlignment: Image.AlignVCenter; \n\
253// %1 is used as anchors of titleLabel
254// %2 is used as color of titleLabel
255// %3 is used as extra condition for visible of titleLabel
256var kTitleLabelCode = 'Label { \n\
258 objectName: "titleLabel"; \n\
260 elide: Text.ElideRight; \n\
261 fontSize: "small"; \n\
262 wrapMode: Text.Wrap; \n\
263 maximumLineCount: 2; \n\
264 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
266 visible: showHeader %3; \n\
267 text: root.title; \n\
268 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal; \n\
269 horizontalAlignment: root.titleAlignment; \n\
272// %1 is used as extra anchors of emblemIcon
273// %2 is used as color of emblemIcon
274// FIXME The width code is a
275// Workaround for bug https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1421293
276var kEmblemIconCode = 'Icon { \n\
278 objectName: "emblemIcon"; \n\
280 bottom: titleLabel.baseline; \n\
281 right: parent.right; \n\
284 source: cardData && cardData["emblem"] || ""; \n\
286 height: source != "" ? titleLabel.font.pixelSize : 0; \n\
287 width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth; \n\
290// %1 is used as anchors of touchdown effect
291var kTouchdownCode = 'UbuntuShape { \n\
293 objectName: "touchdown"; \n\
295 visible: root.pressed; \n\
296 radius: "medium"; \n\
297 borderSource: "radius_pressed.sci" \n\
300// %1 is used as anchors of subtitleLabel
301// %2 is used as color of subtitleLabel
302var kSubtitleLabelCode = 'Label { \n\
303 id: subtitleLabel; \n\
304 objectName: "subtitleLabel"; \n\
306 anchors.topMargin: units.dp(2); \n\
307 elide: Text.ElideRight; \n\
308 maximumLineCount: 1; \n\
309 fontSize: "x-small"; \n\
310 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
312 visible: titleLabel.visible && titleLabel.text; \n\
313 text: cardData && cardData["subtitle"] || ""; \n\
314 font.weight: Font.Light; \n\
317// %1 is used as anchors of attributesRow
318// %2 is used as color of attributesRow
319var kAttributesRowCode = 'CardAttributes { \n\
320 id: attributesRow; \n\
321 objectName: "attributesRow"; \n\
324 fontScale: root.fontScale; \n\
325 model: cardData && cardData["attributes"]; \n\
328// %1 is used as top anchor of summary
329// %2 is used as topMargin anchor of summary
330// %3 is used as color of summary
331var kSummaryLabelCode = 'Label { \n\
333 objectName: "summaryLabel"; \n\
336 left: parent.left; \n\
337 right: parent.right; \n\
338 margins: units.gu(1); \n\
341 wrapMode: Text.Wrap; \n\
342 maximumLineCount: 5; \n\
343 elide: Text.ElideRight; \n\
344 text: cardData && cardData["summary"] || ""; \n\
345 height: text ? implicitHeight : 0; \n\
346 fontSize: "small"; \n\
350// %1 is used as bottom anchor of audio progress bar
351// %2 is used as left anchor of audio progress bar
352// %3 is used as text color
353var kAudioProgressBarCode = 'CardAudioProgress { \n\
354 id: audioProgressBar; \n\
355 duration: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["duration"]) || 0; \n\
356 source: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["uri"]) || ""; \n\
360 right: parent.right; \n\
361 margins: units.gu(1); \n\
366function cardString(template, components) {
368 code = 'AbstractButton { \n\
370 property var template; \n\
371 property var components; \n\
372 property var cardData; \n\
373 property var artShapeBorderSource: undefined; \n\
374 property real fontScale: 1.0; \n\
375 property var scopeStyle: null; \n\
376 property int titleAlignment: Text.AlignLeft; \n\
377 property int fixedHeaderHeight: -1; \n\
378 property size fixedArtShapeSize: Qt.size(-1, -1); \n\
379 readonly property string title: cardData && cardData["title"] || ""; \n\
380 property bool asynchronous: true; \n\
381 property bool showHeader: true; \n\
382 implicitWidth: childrenRect.width; \n\
383 enabled: root.template == null ? true : (root.template["non-interactive"] !== undefined ? !root.template["non-interactive"] : true); \n\
386 var hasArt = components["art"] && components["art"]["field"] || false;
387 var hasSummary = components["summary"] || false;
388 var artAndSummary = hasArt && hasSummary && components["art"]["conciergeMode"] !== true;
389 var isHorizontal = template["card-layout"] === "horizontal";
390 var hasBackground = (!isHorizontal && (template["card-background"] || components["background"] || artAndSummary)) ||
391 (hasSummary && (template["card-background"] || components["background"]));
392 var hasTitle = components["title"] || false;
393 var hasMascot = components["mascot"] || false;
394 var hasEmblem = components["emblem"] && !(hasMascot && template["card-size"] === "small") || false;
395 var headerAsOverlay = hasArt && template && template["overlay"] === true && (hasTitle || hasMascot);
396 var hasSubtitle = hasTitle && components["subtitle"] || false;
397 var hasHeaderRow = hasMascot && hasTitle;
398 var hasAttributes = hasTitle && components["attributes"] && components["attributes"]["field"] || false;
399 var isAudio = template["quick-preview-type"] === "audio";
402 // For now we only support audio cards with [optional] art, title, subtitle
403 // in horizontal mode
404 // Anything else makes it behave not like an audio card
405 if (hasSummary) isAudio = false;
406 if (!isHorizontal) isAudio = false;
407 if (hasMascot) isAudio = false;
408 if (hasEmblem) isAudio = false;
409 if (headerAsOverlay) isAudio = false;
410 if (hasAttributes) isAudio = false;
414 code += kBackgroundLoaderCode;
418 code += 'onArtShapeBorderSourceChanged: { if (artShapeBorderSource !== undefined && artShapeLoader.item) artShapeLoader.item.borderSource = artShapeBorderSource; } \n';
419 code += 'readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);\n';
421 var widthCode, heightCode;
424 artAnchors = 'left: parent.left';
425 if (hasMascot || hasTitle) {
426 widthCode = 'height * artShape.aspect'
427 heightCode = 'headerHeight + 2 * units.gu(1)';
429 // This side of the else is a bit silly, who wants an horizontal layout without mascot and title?
430 // So we define a "random" height of the image height + 2 gu for the margins
431 widthCode = 'height * artShape.aspect'
432 heightCode = 'units.gu(7.625)';
435 artAnchors = 'horizontalCenter: parent.horizontalCenter;';
436 widthCode = 'root.width'
437 heightCode = 'width / artShape.aspect';
440 code += kArtShapeHolderCode.arg(artAnchors).arg(widthCode).arg(heightCode);
442 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
445 if (headerAsOverlay) {
446 code += kOverlayLoaderCode;
449 var headerVerticalAnchors;
450 if (headerAsOverlay) {
451 headerVerticalAnchors = 'bottom: artShapeHolder.bottom; \n\
452 bottomMargin: units.gu(1);\n';
456 headerVerticalAnchors = 'top: artShapeHolder.top; \n\
457 topMargin: units.gu(1);\n';
459 headerVerticalAnchors = 'top: artShapeHolder.bottom; \n\
460 topMargin: units.gu(1);\n';
463 headerVerticalAnchors = 'top: parent.top; \n\
464 topMargin: units.gu(1);\n';
468 var headerLeftAnchor;
469 var headerLeftAnchorHasMargin = false;
470 if (isHorizontal && hasArt) {
471 headerLeftAnchor = 'left: artShapeHolder.right; \n\
472 leftMargin: units.gu(1);\n';
473 headerLeftAnchorHasMargin = true;
474 } else if (isHorizontal && isAudio) {
475 headerLeftAnchor = 'left: audioButton.right; \n\
476 leftMargin: units.gu(1);\n';
477 headerLeftAnchorHasMargin = true;
479 headerLeftAnchor = 'left: parent.left;\n';
482 var touchdownOnArtShape = !hasBackground && hasArt && !hasMascot && !hasSummary && !isAudio;
485 code += 'readonly property int headerHeight: row.height;\n'
486 } else if (hasMascot) {
487 code += 'readonly property int headerHeight: mascotImage.height;\n'
488 } else if (hasAttributes) {
489 if (hasTitle && hasSubtitle) {
490 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + attributesRow.height + attributesRow.anchors.topMargin;\n'
491 } else if (hasTitle) {
492 code += 'readonly property int headerHeight: titleLabel.height + attributesRow.height + attributesRow.anchors.topMargin;\n'
494 code += 'readonly property int headerHeight: attributesRow.height;\n'
496 } else if (isAudio) {
498 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + audioProgressBar.height + audioProgressBar.anchors.topMargin;\n'
499 } else if (hasTitle) {
500 code += 'readonly property int headerHeight: titleLabel.height + audioProgressBar.height + audioProgressBar.anchors.topMargin;\n'
502 code += 'readonly property int headerHeight: audioProgressBar.height;\n'
504 } else if (hasSubtitle) {
505 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin;\n'
506 } else if (hasTitle) {
507 code += 'readonly property int headerHeight: titleLabel.height;\n'
509 code += 'readonly property int headerHeight: 0;\n'
512 var mascotShapeCode = '';
515 var useMascotShape = !hasBackground && !headerAsOverlay;
516 var mascotAnchors = '';
518 mascotAnchors += headerLeftAnchor;
519 mascotAnchors += headerVerticalAnchors;
520 if (!headerLeftAnchorHasMargin) {
521 mascotAnchors += 'leftMargin: units.gu(1);\n'
524 mascotAnchors = 'verticalCenter: parent.verticalCenter;'
527 if (useMascotShape) {
528 mascotShapeCode = kMascotShapeLoaderCode.arg(mascotAnchors);
531 var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
532 mascotCode = kMascotImageCode.arg(mascotAnchors).arg(mascotImageVisible);
535 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")';
537 var hasTitleContainer = hasTitle && (hasEmblem || (hasMascot && (hasSubtitle || hasAttributes)));
538 var titleSubtitleCode = '';
541 if (headerAsOverlay) {
542 titleColor = 'root.scopeStyle && overlayLoader.item ? root.scopeStyle.getTextColor(overlayLoader.item.luminance) : (overlayLoader.item && overlayLoader.item.luminance > 0.7 ? Theme.palette.normal.baseText : "white")';
543 } else if (hasSummary) {
544 titleColor = 'summary.color';
545 } else if (hasBackground) {
546 titleColor = summaryColorWithBackground;
548 titleColor = 'root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText';
553 var attributesAnchors;
554 var titleContainerAnchors;
555 var titleRightAnchor;
557 var extraRightAnchor = '';
558 var extraLeftAnchor = '';
559 if (!touchdownOnArtShape) {
560 extraRightAnchor = 'rightMargin: units.gu(1); \n';
561 extraLeftAnchor = 'leftMargin: units.gu(1); \n';
562 } else if (headerAsOverlay && !hasEmblem) {
563 extraRightAnchor = 'rightMargin: units.gu(1); \n';
567 titleContainerAnchors = 'verticalCenter: parent.verticalCenter; ';
569 titleContainerAnchors = 'right: parent.right; ';
570 titleContainerAnchors += headerLeftAnchor;
571 titleContainerAnchors += headerVerticalAnchors;
572 if (!headerLeftAnchorHasMargin) {
573 titleContainerAnchors += extraLeftAnchor;
577 titleRightAnchor = 'right: emblemIcon.left; \n\
578 rightMargin: emblemIcon.width > 0 ? units.gu(0.5) : 0; \n';
580 titleRightAnchor = 'right: parent.right; \n'
581 titleRightAnchor += extraRightAnchor;
584 if (hasTitleContainer) {
585 // Using headerTitleContainer
586 titleAnchors = titleRightAnchor;
587 titleAnchors += 'left: parent.left; \n\
589 subtitleAnchors = 'right: parent.right; \n\
590 left: parent.left; \n';
591 subtitleAnchors += extraRightAnchor;
593 attributesAnchors = subtitleAnchors + 'top: subtitleLabel.bottom;\n';
594 subtitleAnchors += 'top: titleLabel.bottom;\n';
596 attributesAnchors = subtitleAnchors + 'top: titleLabel.bottom;\n';
598 } else if (hasMascot) {
599 // Using row + titleContainer
600 titleAnchors = 'verticalCenter: parent.verticalCenter;\n';
602 if (headerAsOverlay) {
603 // Using anchors to the overlay
604 titleAnchors = titleRightAnchor;
605 titleAnchors += 'left: parent.left; \n\
606 leftMargin: units.gu(1); \n\
607 top: overlayLoader.top; \n\
608 topMargin: units.gu(1);\n';
610 // Using anchors to the mascot/parent
611 titleAnchors = titleRightAnchor;
612 titleAnchors += headerLeftAnchor;
613 titleAnchors += headerVerticalAnchors;
614 if (!headerLeftAnchorHasMargin) {
615 titleAnchors += extraLeftAnchor;
618 subtitleAnchors = 'left: titleLabel.left; \n\
619 leftMargin: titleLabel.leftMargin; \n';
620 subtitleAnchors += extraRightAnchor;
623 subtitleAnchors += 'right: parent.right; \n';
625 subtitleAnchors += 'right: titleLabel.right; \n';
629 attributesAnchors = subtitleAnchors + 'top: subtitleLabel.bottom;\n';
630 subtitleAnchors += 'top: titleLabel.bottom;\n';
632 attributesAnchors = subtitleAnchors + 'top: titleLabel.bottom;\n';
636 // code for different elements
637 var titleLabelVisibleExtra = (headerAsOverlay ? '&& overlayLoader.active': '');
638 var titleCode = kTitleLabelCode.arg(titleAnchors).arg(titleColor).arg(titleLabelVisibleExtra);
642 // code for the title container
643 var containerCode = [];
644 var containerHeight = 'titleLabel.height';
645 containerCode.push(titleCode);
647 subtitleCode = kSubtitleLabelCode.arg(subtitleAnchors).arg(titleColor);
648 containerCode.push(subtitleCode);
649 containerHeight += ' + subtitleLabel.height';
652 containerCode.push(kEmblemIconCode.arg(extraRightAnchor).arg(titleColor));
655 attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(titleColor);
656 containerCode.push(attributesCode);
657 containerHeight += ' + attributesRow.height';
660 if (hasTitleContainer) {
662 titleSubtitleCode = kHeaderContainerCodeGenerator(titleContainerAnchors, containerHeight, containerCode);
665 titleSubtitleCode = titleCode;
667 titleSubtitleCode += subtitleCode;
670 titleSubtitleCode += attributesCode;
676 var rowCode = [mascotCode, titleSubtitleCode];
677 if (mascotShapeCode != '') {
678 rowCode.unshift(mascotShapeCode);
680 code += kHeaderRowCodeGenerator(headerVerticalAnchors + headerLeftAnchor, rowCode)
682 code += mascotShapeCode + mascotCode + titleSubtitleCode;
686 var audioProgressBarLeftAnchor = 'audioButton.right';
687 var audioProgressBarBottomAnchor = 'audioButton.bottom';
688 var audioProgressBarTextColor = 'root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText';
690 code += kAudioProgressBarCode.arg(audioProgressBarBottomAnchor)
691 .arg(audioProgressBarLeftAnchor)
692 .arg(audioProgressBarTextColor);
694 var audioButtonAnchorsFill;
695 var audioButtonWidth;
696 var audioButtonHeight;
698 audioButtonAnchorsFill = 'artShapeHolder';
699 audioButtonWidth = 'undefined';
700 audioButtonHeight = 'undefined';
702 audioButtonAnchorsFill = 'undefined';
703 audioButtonWidth = 'height';
704 audioButtonHeight = '(root.fixedHeaderHeight > 0 ? root.fixedHeaderHeight : headerHeight) + 2 * units.gu(1)';
706 code += kAudioButtonCode.arg(audioButtonAnchorsFill).arg(audioButtonWidth).arg(audioButtonHeight);
710 var summaryTopAnchor;
711 if (isHorizontal && hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
712 else if (headerAsOverlay && hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
713 else if (hasHeaderRow) summaryTopAnchor = 'row.bottom';
714 else if (hasTitleContainer) summaryTopAnchor = 'headerTitleContainer.bottom';
715 else if (hasMascot) summaryTopAnchor = 'mascotImage.bottom';
716 else if (hasAttributes) summaryTopAnchor = 'attributesRow.bottom';
717 else if (hasSubtitle) summaryTopAnchor = 'subtitleLabel.bottom';
718 else if (hasTitle) summaryTopAnchor = 'titleLabel.bottom';
719 else if (hasArt) summaryTopAnchor = 'artShapeHolder.bottom';
720 else summaryTopAnchor = 'parent.top';
724 summaryColor = summaryColorWithBackground;
726 summaryColor = 'root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText';
729 var summaryTopMargin = (hasMascot || hasSubtitle || hasAttributes ? 'anchors.margins' : '0');
731 code += kSummaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(summaryColor);
734 var touchdownAnchors;
736 touchdownAnchors = 'fill: backgroundLoader';
737 } else if (touchdownOnArtShape) {
738 touchdownAnchors = 'fill: artShapeHolder';
740 touchdownAnchors = 'fill: root'
742 code += kTouchdownCode.arg(touchdownAnchors);
744 var implicitHeight = 'implicitHeight: ';
746 implicitHeight += 'summary.y + summary.height + units.gu(1);\n';
747 } else if (isAudio) {
748 implicitHeight += 'audioButton.height;\n';
749 } else if (headerAsOverlay) {
750 implicitHeight += 'artShapeHolder.height;\n';
751 } else if (hasHeaderRow) {
752 implicitHeight += 'row.y + row.height + units.gu(1);\n';
753 } else if (hasMascot) {
754 implicitHeight += 'mascotImage.y + mascotImage.height;\n';
755 } else if (hasTitleContainer) {
756 implicitHeight += 'headerTitleContainer.y + headerTitleContainer.height + units.gu(1);\n';
757 } else if (hasAttributes) {
758 implicitHeight += 'attributesRow.y + attributesRow.height + units.gu(1);\n';
759 } else if (hasSubtitle) {
760 implicitHeight += 'subtitleLabel.y + subtitleLabel.height + units.gu(1);\n';
761 } else if (hasTitle) {
762 implicitHeight += 'titleLabel.y + titleLabel.height + units.gu(1);\n';
764 implicitHeight += 'artShapeHolder.height;\n';
769 // Close the AbstractButton
770 code += implicitHeight + '}\n';
775function createCardComponent(parent, template, components) {
776 var imports = 'import QtQuick 2.2; \n\
777 import Ubuntu.Components 1.1; \n\
778 import Ubuntu.Settings.Components 0.1; \n\
780 import Utils 0.1;\n';
781 var card = cardString(template, components);
782 var code = imports + 'Component {\n' + card + '}\n';
785 return Qt.createQmlObject(code, parent, "createCardComponent");
787 console.error("ERROR: Invalid component created.");
788 console.error("Template:");
789 console.error(JSON.stringify(template));
790 console.error("Components:");
791 console.error(JSON.stringify(components));
792 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