on bbbdccd help sign in
unity8/qml/Dash/Previews/PreviewHeader.qml
140 lines 5.4 kB history raw
1/*
2 * Copyright (C) 2014,2015 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
17import QtQuick 2.4
18import Ubuntu.Components 1.3
19import Dash 0.1
20import "../"
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 */
30PreviewWidget {
31 id: root
33 implicitHeight: childrenRect.height
35 Item {
36 id: headerRoot
37 objectName: "innerPreviewHeader"
38 readonly property url mascot: root.widgetData["mascot"] || fallback
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
49 width: parent.width
51 Row {
52 id: row
53 objectName: "outerRow"
55 property real margins: units.gu(1)
57 spacing: mascotShapeLoader.active ? margins : 0
58 anchors {
59 top: parent.top; left: parent.left; right: parent.right
60 margins: margins
61 leftMargin: spacing
62 rightMargin: spacing
63 }
65 Loader {
66 id: mascotShapeLoader
67 objectName: "mascotShapeLoader"
68 active: headerRoot.mascot != ""
69 visible: active
71 anchors.verticalCenter: parent.verticalCenter
72 // TODO karni: Icon aspect-ratio is 8:7.5. Revisit these values to avoid fraction of pixels.
73 width: units.gu(6)
74 height: units.gu(5.625)
75 readonly property int maxSize: Math.max(width, height) * 4
76 asynchronous: true
78 sourceComponent: UbuntuShape {
79 objectName: "mascotShape"
80 visible: source.status === Image.Ready
81 sourceFillMode: UbuntuShape.PreserveAspectCrop
82 sourceHorizontalAlignment: UbuntuShape.AlignHCenter
83 sourceVerticalAlignment: UbuntuShape.AlignVCenter
84 source: Image {
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;
91 }
92 }
93 }
95 Column {
96 objectName: "column"
97 width: parent.width - x
98 spacing: units.dp(2)
99 anchors.verticalCenter: parent.verticalCenter
101 Label {
102 id: titleLabel
103 objectName: "titleLabel"
104 anchors { left: parent.left; right: parent.right }
105 elide: Text.ElideRight
106 font.weight: Font.Normal
107 fontSize: "large"
108 wrapMode: Text.Wrap
109 color: headerRoot.fontColor
110 text: headerRoot.title
111 }
113 Loader {
114 active: titleLabel.text && headerRoot.subtitle
115 anchors { left: parent.left; right: parent.right }
116 sourceComponent: Label {
117 id: subtitleLabel
118 objectName: "subtitleLabel"
119 elide: Text.ElideRight
120 fontSize: "small"
121 font.weight: Font.Light
122 color: headerRoot.fontColor
123 text: headerRoot.subtitle
124 }
125 }
127 Loader {
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
134 }
135 }
136 }
137 }
138 }