@@ -0,0 +1,217 @@
1+AbstractButton {
2+ id: root;
3+ property var components;
4+ property var cardData;
5+ property string artShapeStyle: "inset";
6+ property string backgroundShapeStyle: "inset";
7+ property real fontScale: 1.0;
8+ property var scopeStyle: null;
9+ property int titleAlignment: Text.AlignLeft;
10+ property int fixedHeaderHeight: -1;
11+ property size fixedArtShapeSize: Qt.size(-1, -1);
12+ readonly property string title: cardData && cardData["title"] || "";
13+ property bool asynchronous: true;
14+ property bool showHeader: true;
15+ implicitWidth: childrenRect.width;
16+ enabled: true;
17+
18+Loader {
19+ id: backgroundLoader;
20+ objectName: "backgroundLoader";
21+ anchors.fill: parent;
22+ asynchronous: root.asynchronous;
23+ visible: status == Loader.Ready;
24+ sourceComponent: UbuntuShape {
25+ objectName: "background";
26+ radius: "medium";
27+ aspect: {
28+ switch (root.backgroundShapeStyle) {
29+ case "inset": return UbuntuShape.Inset;
30+ case "shadow": return UbuntuShape.DropShadow;
31+ default:
32+ case "flat": return UbuntuShape.Flat;
33+ }
34+ }
35+ backgroundColor: getColor(0) || "white";
36+ secondaryBackgroundColor: getColor(1) || backgroundColor;
37+ backgroundMode: UbuntuShape.VerticalGradient;
38+ anchors.fill: parent;
39+ source: backgroundImage.source ? backgroundImage : null;
40+ property real luminance: Style.luminance(backgroundColor);
41+ property Image backgroundImage: Image {
42+ objectName: "backgroundImage";
43+ source: {
44+ if (cardData && typeof cardData["background"] === "string") return cardData["background"];
45+ else return "";
46+ }
47+ }
48+ function getColor(index) {
49+ if (cardData && typeof cardData["background"] === "object"
50+ && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
51+ return cardData["background"]["elements"][index];
52+ } else return index === 0 ? "#E9E9E9" : undefined;
53+ }
54+ }
55+ }
56+readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
57+Item {
58+ id: artShapeHolder;
59+ height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height;
60+ width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width;
61+ anchors { horizontalCenter: parent.horizontalCenter; }
62+ Loader {
63+ id: artShapeLoader;
64+ objectName: "artShapeLoader";
65+ active: cardData && cardData["art"] || false;
66+ asynchronous: root.asynchronous;
67+ visible: status == Loader.Ready;
68+ sourceComponent: Item {
69+ id: artShape;
70+ objectName: "artShape";
71+ readonly property bool doShapeItem: components["art"]["conciergeMode"] !== true;
72+ visible: image.status == Image.Ready;
73+ readonly property alias image: artImage;
74+ ShaderEffectSource {
75+ id: artShapeSource;
76+ sourceItem: artImage;
77+ anchors.centerIn: parent;
78+ width: 1;
79+ height: 1;
80+ hideSource: doShapeItem;
81+ }
82+ Loader {
83+ anchors.fill: parent;
84+ visible: artShape.doShapeItem;
85+ sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent;
86+ Component {
87+ id: artShapeShapeComponent;
88+ UbuntuShape {
89+ source: artShapeSource;
90+ sourceFillMode: UbuntuShape.PreserveAspectCrop;
91+ radius: "medium";
92+ aspect: {
93+ switch (root.artShapeStyle) {
94+ case "inset": return UbuntuShape.Inset;
95+ case "shadow": return UbuntuShape.DropShadow;
96+ default:
97+ case "flat": return UbuntuShape.Flat;
98+ }
99+ }
100+ }
101+ }
102+ Component {
103+ id: artShapeIconComponent;
104+ ProportionalShape { source: artShapeSource; aspect: UbuntuShape.DropShadow; }
105+ }
106+ }
107+ readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
108+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1;
109+ Component.onCompleted: { updateWidthHeightBindings(); }
110+ Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
111+ function updateWidthHeightBindings() {
112+ if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) {
113+ width = root.fixedArtShapeSize.width;
114+ height = root.fixedArtShapeSize.height;
115+ } else {
116+ width = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.width });
117+ height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height });
118+ }
119+ }
120+ CroppedImageMinimumSourceSize {
121+ id: artImage;
122+ objectName: "artImage";
123+ source: cardData && cardData["art"] || "";
124+ asynchronous: root.asynchronous;
125+ width: root.width;
126+ height: width / artShape.aspect;
127+ onStatusChanged: if (status === Image.Error) source = decodeURI("%5C");
128+ }
129+ }
130+ }
131+ }
132+readonly property int headerHeight: row.height;
133+Row {
134+ id: row;
135+ objectName: "outerRow";
136+ property real margins: units.gu(1);
137+ spacing: margins;
138+ height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight;
139+ anchors { top: artShapeHolder.bottom;
140+ topMargin: units.gu(1);
141+left: parent.left;
142+ }
143+ anchors.right: parent.right;
144+ anchors.margins: margins;
145+ anchors.rightMargin: 0;
146+ data: [
147+ CroppedImageMinimumSourceSize {
148+ id: mascotImage;
149+ objectName: "mascotImage";
150+ anchors { verticalCenter: parent.verticalCenter; }
151+ source: cardData && cardData["mascot"] || "";
152+ width: units.gu(6);
153+ height: units.gu(5.625);
154+ horizontalAlignment: Image.AlignHCenter;
155+ verticalAlignment: Image.AlignVCenter;
156+ visible: showHeader;
157+ onStatusChanged: if (status === Image.Error) source = decodeURI("%22");
158+ }
159+,Item {
160+ id: headerTitleContainer;
161+ anchors { verticalCenter: parent.verticalCenter; }
162+ width: parent.width - x;
163+ implicitHeight: titleLabel.height + subtitleLabel.height;
164+ data: [
165+ Label {
166+ id: titleLabel;
167+ objectName: "titleLabel";
168+ anchors { right: parent.right;
169+rightMargin: units.gu(1);
170+left: parent.left;
171+ top: parent.top; }
172+ elide: Text.ElideRight;
173+ fontSize: "small";
174+ wrapMode: Text.Wrap;
175+ maximumLineCount: 2;
176+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
177+ color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
178+ visible: showHeader ;
179+ width: undefined;
180+ text: root.title;
181+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
182+ horizontalAlignment: root.titleAlignment;
183+ }
184+,Label {
185+ id: subtitleLabel;
186+ objectName: "subtitleLabel";
187+ anchors { right: parent.right;
188+ left: parent.left;
189+rightMargin: units.gu(1);
190+top: titleLabel.bottom;
191+ }
192+ anchors.topMargin: units.dp(2);
193+ elide: Text.ElideRight;
194+ maximumLineCount: 1;
195+ fontSize: "x-small";
196+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
197+ color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
198+ visible: titleLabel.visible && titleLabel.text;
199+ text: cardData && cardData["subtitle"] || "";
200+ font.weight: Font.Light;
201+ }
202+
203+ ]
204+ }
205+
206+ ]
207+ }
208+UbuntuShape {
209+ id: touchdown;
210+ objectName: "touchdown";
211+ anchors { fill: backgroundLoader }
212+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
213+ radius: "medium";
214+ borderSource: "radius_pressed.sci"
215+ }
216+implicitHeight: row.y + row.height + units.gu(1);
217+}