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"]
28 * The emblem comes in widgetData["emblem"]
34 implicitHeight: childrenRect.height
38 objectName: "innerPreviewHeader"
39 readonly property url mascot: root.widgetData["mascot"] || fallback
40 readonly property url fallback: root.widgetData["fallback"] || ""
41 readonly property string title: root.widgetData["title"] || ""
42 readonly property string subtitle: root.widgetData["subtitle"] || ""
43 readonly property var attributes: root.widgetData["attributes"] || null
44 readonly property url emblem: root.widgetData["emblem"] || ""
45 readonly property color fontColor: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText
47 // Rewire the source since we may have unwired it on onStatusChanged
48 onMascotChanged: if (mascotShapeLoader.item) mascotShapeLoader.item.source.source = mascot;
50 implicitHeight: row.height + row.margins * 2
55 objectName: "outerRow"
57 property real margins: units.gu(1)
59 spacing: mascotShapeLoader.active ? margins : 0
61 top: parent.top; left: parent.left; right: parent.right
69 objectName: "mascotShapeLoader"
70 active: headerRoot.mascot != ""
73 anchors.verticalCenter: parent.verticalCenter
74 // TODO karni: Icon aspect-ratio is 8:7.5. Revisit these values to avoid fraction of pixels.
76 height: units.gu(5.625)
77 readonly property int maxSize: Math.max(width, height) * 4
80 sourceComponent: UbuntuShape {
81 objectName: "mascotShape"
82 visible: source.status === Image.Ready
83 sourceFillMode: UbuntuShape.PreserveAspectCrop
84 sourceHorizontalAlignment: UbuntuShape.AlignHCenter
85 sourceVerticalAlignment: UbuntuShape.AlignVCenter
87 source: headerRoot.mascot
88 width: source ? mascotShapeLoader.width : 0
89 height: mascotShapeLoader.height
91 sourceSize { width: mascotShapeLoader.maxSize; height: mascotShapeLoader.maxSize }
92 onStatusChanged: if (status === Image.Error) source = headerRoot.fallback;
99 width: parent.width - x
101 anchors.verticalCenter: parent.verticalCenter
104 anchors { left: parent.left; right: parent.right }
105 height: titleLabel.height
109 objectName: "titleLabel"
112 right: iconLoader.right
113 rightMargin: iconLoader.width > 0 ? units.gu(0.5) : 0
115 elide: Text.ElideRight
116 font.weight: Font.Normal
119 color: headerRoot.fontColor
120 text: headerRoot.title
125 active: headerRoot.emblem != ""
127 bottom: titleLabel.baseline
130 sourceComponent: Icon {
131 objectName: "emblemIcon"
132 source: headerRoot.emblem
133 color: headerRoot.fontColor
134 height: source != "" ? titleLabel.font.pixelSize : 0
135 // FIXME Workaround for bug https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1421293
136 width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth
142 active: titleLabel.text && headerRoot.subtitle
143 anchors { left: parent.left; right: parent.right }
144 sourceComponent: Label {
146 objectName: "subtitleLabel"
147 elide: Text.ElideRight
149 font.weight: Font.Light
150 color: headerRoot.fontColor
151 text: headerRoot.subtitle
156 active: titleLabel.text && headerRoot.attributes
157 anchors { left: parent.left; right: parent.right }
158 sourceComponent: CardAttributes {
159 id: previewAttributes
160 objectName: "previewAttributes"
161 model: headerRoot.attributes