on 436b607 help sign in
unity8/qml/Dash/Previews/PreviewHeader.qml
134 lines 4.9 kB history raw
1/*
2 * Copyright (C) 2014 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.0
18import Ubuntu.Components 0.1
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 subtitle comes in widgetData["subtitle"]
26 * The attributes comes in widgetData["attributes"]
27 */
29PreviewWidget {
30 id: root
32 height: childrenRect.height
34 Item {
35 id: headerRoot
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
44 width: parent.width
46 Row {
47 id: row
48 objectName: "outerRow"
50 property real margins: units.gu(1)
52 spacing: mascotShapeLoader.active ? margins : 0
53 anchors {
54 top: parent.top; left: parent.left; right: parent.right
55 margins: margins
56 leftMargin: spacing
57 rightMargin: spacing
58 }
60 Loader {
61 id: mascotShapeLoader
62 objectName: "mascotShapeLoader"
63 active: headerRoot.mascot != ""
64 visible: active
66 anchors.verticalCenter: parent.verticalCenter
67 // TODO karni: Icon aspect-ratio is 8:7.5. Revisit these values to avoid fraction of pixels.
68 width: units.gu(6)
69 height: units.gu(5.625)
70 readonly property int maxSize: Math.max(width, height) * 4
71 asynchronous: true
73 sourceComponent: UbuntuShape {
74 objectName: "mascotShape"
75 visible: image.status === Image.Ready
76 image: Image {
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
85 }
86 }
87 }
89 Column {
90 objectName: "column"
91 width: parent.width - x
92 spacing: units.dp(2)
93 anchors.verticalCenter: parent.verticalCenter
95 Label {
96 id: titleLabel
97 objectName: "titleLabel"
98 anchors { left: parent.left; right: parent.right }
99 elide: Text.ElideRight
100 font.weight: Font.Normal
101 fontSize: "large"
102 wrapMode: Text.Wrap
103 color: headerRoot.fontColor
104 text: headerRoot.title
105 }
107 Loader {
108 active: titleLabel.text && headerRoot.subtitle
109 anchors { left: parent.left; right: parent.right }
110 sourceComponent: Label {
111 id: subtitleLabel
112 objectName: "subtitleLabel"
113 elide: Text.ElideRight
114 fontSize: "small"
115 font.weight: Font.Light
116 color: headerRoot.fontColor
117 text: headerRoot.subtitle
118 }
119 }
121 Loader {
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
128 }
129 }
130 }
131 }
132 }