2 * Copyright (C) 2014,2015 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 1.3
22 /*! This preview widget shows a header
23 * The title comes in widgetData["title"]
24 * The mascot comes in widgetData["mascot"]
25 * The mascot fall back image comes in widgetData["fallback"]
26 * The subtitle comes in widgetData["subtitle"]
27 * The attributes comes in widgetData["attributes"]
33 implicitHeight: childrenRect.height
37 objectName: "innerPreviewHeader"
38 readonly property url mascot: root.widgetData["mascot"] || ""
39 readonly property url fallback: root.widgetData["fallback"] || ""
40 readonly property string title: root.widgetData["title"] || ""
41 readonly property string subtitle: root.widgetData["subtitle"] || ""
42 readonly property var attributes: root.widgetData["attributes"] || null
43 readonly property color fontColor: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText
45 // Rewire the source since we may have unwired it on onStatusChanged
46 onMascotChanged: if (mascotShapeLoader.item) mascotShapeLoader.item.source.source = mascot;
48 implicitHeight: row.height + row.margins * 2
53 objectName: "outerRow"
55 property real margins: units.gu(1)
57 spacing: mascotShapeLoader.active ? margins : 0
59 top: parent.top; left: parent.left; right: parent.right
67 objectName: "mascotShapeLoader"
68 active: headerRoot.mascot != ""
71 anchors.verticalCenter: parent.verticalCenter
72 // TODO karni: Icon aspect-ratio is 8:7.5. Revisit these values to avoid fraction of pixels.
74 height: units.gu(5.625)
75 readonly property int maxSize: Math.max(width, height) * 4
78 sourceComponent: UbuntuShape {
79 objectName: "mascotShape"
80 visible: source.status === Image.Ready
81 sourceFillMode: UbuntuShape.PreserveAspectCrop
82 sourceHorizontalAlignment: UbuntuShape.AlignHCenter
83 sourceVerticalAlignment: UbuntuShape.AlignVCenter
85 source: headerRoot.mascot
86 width: source ? mascotShapeLoader.width : 0
87 height: mascotShapeLoader.height
89 sourceSize { width: mascotShapeLoader.maxSize; height: mascotShapeLoader.maxSize }
90 onStatusChanged: if (status === Image.Error) source = headerRoot.fallback;
97 width: parent.width - x
99 anchors.verticalCenter: parent.verticalCenter
103 objectName: "titleLabel"
104 anchors { left: parent.left; right: parent.right }
105 elide: Text.ElideRight
106 font.weight: Font.Normal
109 color: headerRoot.fontColor
110 text: headerRoot.title
114 active: titleLabel.text && headerRoot.subtitle
115 anchors { left: parent.left; right: parent.right }
116 sourceComponent: Label {
118 objectName: "subtitleLabel"
119 elide: Text.ElideRight
121 font.weight: Font.Light
122 color: headerRoot.fontColor
123 text: headerRoot.subtitle
128 active: titleLabel.text && headerRoot.attributes
129 anchors { left: parent.left; right: parent.right }
130 sourceComponent: CardAttributes {
131 id: previewAttributes
132 objectName: "previewAttributes"
133 model: headerRoot.attributes