2 * Copyright (C) 2014 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
22 /*! This preview widget shows a header
23 * The title comes in widgetData["title"]
24 * The mascot comes in widgetData["mascot"]
25 * The subtitle comes in widgetData["subtitle"]
26 * The attributes comes in widgetData["attributes"]
32 height: childrenRect.height
36 objectName: "innerPreviewHeader"
37 readonly property url mascot: root.widgetData["mascot"] || ""
38 readonly property string title: root.widgetData["title"] || ""
39 readonly property string subtitle: root.widgetData["subtitle"] || ""
40 readonly property var attributes: root.widgetData["attributes"] || null
41 readonly property color fontColor: root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText
43 implicitHeight: row.height + row.margins * 2
48 objectName: "outerRow"
50 property real margins: units.gu(1)
52 spacing: mascotShapeLoader.active ? margins : 0
54 top: parent.top; left: parent.left; right: parent.right
62 objectName: "mascotShapeLoader"
63 active: headerRoot.mascot != ""
66 anchors.verticalCenter: parent.verticalCenter
67 // TODO karni: Icon aspect-ratio is 8:7.5. Revisit these values to avoid fraction of pixels.
69 height: units.gu(5.625)
70 readonly property int maxSize: Math.max(width, height) * 4
73 sourceComponent: UbuntuShape {
74 objectName: "mascotShape"
75 visible: image.status === Image.Ready
77 source: headerRoot.mascot
78 width: source ? mascotShapeLoader.width : 0
79 height: mascotShapeLoader.height
81 sourceSize { width: mascotShapeLoader.maxSize; height: mascotShapeLoader.maxSize }
82 fillMode: Image.PreserveAspectCrop
83 horizontalAlignment: Image.AlignHCenter
84 verticalAlignment: Image.AlignVCenter
91 width: parent.width - x
93 anchors.verticalCenter: parent.verticalCenter
97 objectName: "titleLabel"
98 anchors { left: parent.left; right: parent.right }
99 elide: Text.ElideRight
100 font.weight: Font.Normal
103 color: headerRoot.fontColor
104 text: headerRoot.title
108 active: titleLabel.text && headerRoot.subtitle
109 anchors { left: parent.left; right: parent.right }
110 sourceComponent: Label {
112 objectName: "subtitleLabel"
113 elide: Text.ElideRight
115 font.weight: Font.Light
116 color: headerRoot.fontColor
117 text: headerRoot.subtitle
122 active: titleLabel.text && headerRoot.attributes
123 anchors { left: parent.left; right: parent.right }
124 sourceComponent: CardAttributes {
125 id: previewAttributes
126 objectName: "previewAttributes"
127 model: headerRoot.attributes