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
70 objectName: "mascotShapeLoader"
71 active: headerRoot.mascot != ""
74 anchors.verticalCenter: parent.verticalCenter
75 // TODO karni: Icon aspect-ratio is 8:7.5. Revisit these values to avoid fraction of pixels.
77 height: units.gu(5.625)
78 readonly property int maxSize: Math.max(width, height) * 4
81 sourceComponent: UbuntuShape {
82 objectName: "mascotShape"
83 visible: source.status === Image.Ready
84 sourceFillMode: UbuntuShape.PreserveAspectCrop
85 sourceHorizontalAlignment: UbuntuShape.AlignHCenter
86 sourceVerticalAlignment: UbuntuShape.AlignVCenter
87 aspect: UbuntuShape.Flat
89 source: headerRoot.mascot
90 width: source ? mascotShapeLoader.width : 0
91 height: mascotShapeLoader.height
93 sourceSize { width: mascotShapeLoader.maxSize; height: mascotShapeLoader.maxSize }
94 onStatusChanged: if (status === Image.Error) source = headerRoot.fallback;
101 width: parent.width - x
103 anchors.verticalCenter: parent.verticalCenter
106 anchors { left: parent.left; right: parent.right }
107 height: titleLabel.height
111 objectName: "titleLabel"
114 right: iconLoader.right
115 rightMargin: iconLoader.width > 0 ? units.gu(0.5) : 0
117 elide: Text.ElideRight
119 font.weight: Font.Light
121 color: headerRoot.fontColor
122 text: headerRoot.title
127 active: headerRoot.emblem != ""
129 bottom: titleLabel.baseline
132 sourceComponent: Icon {
133 objectName: "emblemIcon"
134 source: headerRoot.emblem
135 color: headerRoot.fontColor
136 height: source != "" ? titleLabel.font.pixelSize : 0
137 // FIXME Workaround for bug https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1421293
138 width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth
144 active: titleLabel.text && headerRoot.subtitle
145 anchors { left: parent.left; right: parent.right }
146 sourceComponent: Label {
148 objectName: "subtitleLabel"
149 elide: Text.ElideRight
151 font.weight: Font.Light
152 color: headerRoot.fontColor
153 text: headerRoot.subtitle
158 active: titleLabel.text && headerRoot.attributes
159 anchors { left: parent.left; right: parent.right }
160 sourceComponent: CardAttributes {
161 id: previewAttributes
162 objectName: "previewAttributes"
163 model: headerRoot.attributes