on c5cc48e help sign in
unity8/qml/Dash/CardHeader.qml
116 lines 4.0 kB history raw
1/*
2 * Copyright (C) 2013 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
20Item {
21 id: root
22 property alias mascot: mascotImage.source
23 property alias title: titleLabel.text
24 property alias subtitle: subtitleLabel.text
26 property alias titleWeight: titleLabel.font.weight
27 property alias titleSize: titleLabel.fontSize
29 // FIXME: Saviq, used to scale fonts down in Carousel
30 property real fontScale: 1.0
32 property alias headerAlignment: titleLabel.horizontalAlignment
34 property bool inOverlay: false
35 property bool useMascotShape: true
36 property color fontColor: Theme.palette.selected.backgroundText
38 visible: mascotImage.status === Image.Ready || title
39 height: row.height > 0 ? row.height + row.margins * 2 : 0
41 Row {
42 id: row
43 objectName: "outerRow"
45 property real margins: units.gu(1)
47 spacing: mascotShape.visible || mascotImage.visible || inOverlay ? margins : 0
48 anchors {
49 top: parent.top; left: parent.left; right: parent.right
50 margins: margins
51 leftMargin: spacing
52 rightMargin: spacing
53 }
55 UbuntuShape {
56 id: mascotShape
57 objectName: "mascotShape"
59 // TODO karni: Icon aspect-ratio is 8:7.5. Revisit these values to avoid fraction of pixels.
60 width: units.gu(6)
61 height: units.gu(5.625)
62 anchors.verticalCenter: parent.verticalCenter
63 visible: useMascotShape && image && image.status === Image.Ready
64 readonly property int maxSize: Math.max(width, height) * 4
66 image: useMascotShape ? mascotImage : null
67 }
69 Image {
70 id: mascotImage
71 objectName: "mascotImage"
73 width: source ? mascotShape.width : 0
74 height: mascotShape.height
75 anchors.verticalCenter: parent.verticalCenter
76 visible: !useMascotShape && status === Image.Ready
78 sourceSize { width: mascotShape.maxSize; height: mascotShape.maxSize }
79 fillMode: Image.PreserveAspectCrop
80 horizontalAlignment: Image.AlignHCenter
81 verticalAlignment: Image.AlignVCenter
82 }
84 Column {
85 objectName: "column"
86 width: parent.width - x
87 spacing: units.dp(2)
88 anchors.verticalCenter: parent.verticalCenter
90 Label {
91 id: titleLabel
92 objectName: "titleLabel"
93 anchors { left: parent.left; right: parent.right }
94 elide: Text.ElideRight
95 font.weight: Font.Normal
96 fontSize: "small"
97 wrapMode: Text.Wrap
98 maximumLineCount: 2
99 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
100 color: fontColor
101 }
103 Label {
104 id: subtitleLabel
105 objectName: "subtitleLabel"
106 anchors { left: parent.left; right: parent.right }
107 elide: Text.ElideRight
108 fontSize: "small"
109 font.weight: Font.Light
110 visible: titleLabel.text && text
111 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
112 color: fontColor
113 }
114 }
115 }