@@ -1,243 +0,0 @@
2− * Copyright (C) 2013 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/>.
18−import Ubuntu.Components 0.1
19−// For image://albumart and image://thumbnailer image providers
20−import Ubuntu.Thumbnailer 0.1
24− property var template
25− property var components
26− property var cardData
28− property real fontScale: 1.0
29− property int headerAlignment: Text.AlignLeft
30− readonly property int headerHeight: headerLoader.item ? headerLoader.item.height : 0
31− property int fixedHeaderHeight: -1
32− readonly property string title: cardData && cardData["title"] || ""
34− property bool showHeader: true
36− implicitWidth: childrenRect.width
37− implicitHeight: summary.y + summary.height + (summary.text && backgroundLoader.active ? units.gu(1) : 0)
40− source: "graphics/carousel_dropshadow.sci"
41− anchors.fill: artShape
42− anchors.margins: -units.gu(1)
47− objectName: "backgroundLoader"
49− readonly property bool artAndSummary: components["art"]["field"] && components["summary"] || false
50− active: template["card-layout"] !== "horizontal" && (template["card-background"] || components["background"] || artAndSummary)
53− sourceComponent: UbuntuShape {
54− objectName: "background"
56− color: getColor(0) || "white"
57− gradientColor: getColor(1) || color
59− image: backgroundImage.source ? backgroundImage : null
61− property real luminance: 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b
63− property Image backgroundImage: Image {
64− objectName: "backgroundImage"
66− if (cardData && typeof cardData["background"] === "string") return cardData["background"]
67− else if (template && typeof template["card-background"] === "string") return template["card-background"]
72− function getColor(index) {
73− if (cardData && typeof cardData["background"] === "object"
74− && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
75− return cardData["background"]["elements"][index];
76− } else if (template && typeof template["card-background"] === "object"
77− && (template["card-background"]["type"] === "color" || template["card-background"]["type"] === "gradient")) {
78− return template["card-background"]["elements"][index];
79− } else return undefined;
87− objectName: "artShape"
88− anchors.horizontalCenter: template && template["card-layout"] === "horizontal" ? undefined : parent.horizontalCenter
89− anchors.left: template && template["card-layout"] === "horizontal" ? parent.left : undefined
90− visible: cardData && cardData["art"] || false
93− readonly property real aspect: components !== undefined ? components["art"]["aspect-ratio"] : 1
94− readonly property bool aspectSmallerThanImageAspect: aspect < image.aspect
96− Component.onCompleted: updateWidthHeightBindings();
97− onAspectSmallerThanImageAspectChanged: updateWidthHeightBindings();
99− function updateWidthHeightBindings() {
100− if (aspectSmallerThanImageAspect) {
101− width = Qt.binding(function() { return !visible ? 0 : image.width });
102− height = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.height : width / image.aspect });
104− width = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.width : height * image.aspect });
105− height = Qt.binding(function() { return !visible ? 0 : image.height });
110− objectName: "artImage"
111− source: cardData && cardData["art"] || ""
113− // FIXME uncomment when having investigated / fixed the crash
114− //sourceSize.width: width > height ? width : 0
115− //sourceSize.height: height > width ? height : 0
116− fillMode: components && components["art"]["fill-mode"] === "fit" ? Image.PreserveAspectFit: Image.PreserveAspectCrop
118− readonly property real aspect: implicitWidth / implicitHeight
119− readonly property bool isHorizontal: template && template["card-layout"] === "horizontal"
121− Component.onCompleted: updateWidthHeightBindings();
122− onIsHorizontalChanged: updateWidthHeightBindings();
124− function updateWidthHeightBindings() {
126− width = Qt.binding(function() { return height * artShape.aspect });
127− height = Qt.binding(function() { return root.headerHeight });
129− width = Qt.binding(function() { return root.width });
130− height = Qt.binding(function() { return width / artShape.aspect });
140− right: artShape.right
141− bottom: artShape.bottom
143− active: template && template["overlay"] && artShape.visible && artShape.image.status === Image.Ready || false
145− sourceComponent: ShaderEffect {
148− height: headerLoader.item ? headerLoader.item.height : 0
149− opacity: headerLoader.item ? headerLoader.item.opacity * 0.6 : 0
151− property var source: ShaderEffectSource {
153− sourceItem: artShape
154− onVisibleChanged: if (visible) scheduleUpdate()
156− sourceRect: Qt.rect(0, artShape.height - overlay.height, artShape.width, overlay.height)
160− uniform highp mat4 qt_Matrix;
161− attribute highp vec4 qt_Vertex;
162− attribute highp vec2 qt_MultiTexCoord0;
163− varying highp vec2 coord;
165− coord = qt_MultiTexCoord0;
166− gl_Position = qt_Matrix * qt_Vertex;
170− varying highp vec2 coord;
171− uniform sampler2D source;
172− uniform lowp float qt_Opacity;
174− lowp vec4 tex = texture2D(source, coord);
175− gl_FragColor = vec4(0, 0, 0, tex.a) * qt_Opacity;
182− objectName: "cardHeaderLoader"
187− if (template["overlay"]) return overlayLoader.top;
188− if (template["card-layout"] === "horizontal") return artShape.top;
190− return artShape.bottom;
194− if (!template["overlay"] && template["card-layout"] === "horizontal") return artShape.right;
200− active: cardData && cardData["title"] || cardData && cardData["mascot"] || false
202− sourceComponent: CardHeader {
204− objectName: "cardHeader"
206− mascot: cardData && cardData["mascot"] || ""
208− subtitle: cardData && cardData["subtitle"] || ""
210− titleWeight: components && components["subtitle"] ? Font.DemiBold : Font.Normal
212− opacity: showHeader ? 1 : 0
213− inOverlay: root.template && root.template["overlay"] === true
214− fontColor: inOverlay ? "white" : summary.color
215− useMascotShape: !backgroundLoader.active && !inOverlay
216− headerAlignment: root.headerAlignment
217− height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight
218− fontScale: root.fontScale
220− Behavior on opacity { NumberAnimation { duration: UbuntuAnimation.SnapDuration } }
226− objectName: "summaryLabel"
228− top: headerLoader.active ? headerLoader.bottom : artShape.bottom
231− margins: backgroundLoader.active ? units.gu(1) : 0
236− elide: Text.ElideRight
237− text: cardData && cardData["summary"] || ""
238− height: text ? implicitHeight : 0
240− // TODO karni: Change "grey" to Ubuntu.Components.Palette color once updated.
241− color: backgroundLoader.active && backgroundLoader.item.luminance < 0.7 ? "white" : "grey"