on 7e36abe help sign in
unity8/qml/Dash/CardHeader.qml
161 lines 5.5 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
25 property alias price: priceLabel.text
26 property alias oldPrice: oldPriceLabel.text
27 property alias altPrice: altPriceLabel.text
29 property alias titleWeight: titleLabel.font.weight
30 property alias titleSize: titleLabel.fontSize
32 // FIXME: Saviq, used to scale fonts down in Carousel
33 property real fontScale: 1.0
35 property alias headerAlignment: titleLabel.horizontalAlignment
37 property bool inOverlay: false
38 property bool useMascotShape: true
39 property color fontColor: "grey"
41 visible: mascotImage.status === Image.Ready || title || price
42 height: row.height > 0 ? row.height + row.margins * 2 : 0
44 Row {
45 id: row
46 objectName: "outerRow"
48 property real margins: units.gu(1)
50 spacing: mascotShape.visible || mascotImage.visible || inOverlay ? margins : 0
51 anchors {
52 top: parent.top; left: parent.left; right: parent.right
53 margins: margins
54 leftMargin: spacing
55 rightMargin: spacing
56 }
58 UbuntuShape {
59 id: mascotShape
60 objectName: "mascotShape"
62 // TODO karni: Icon aspect-ratio is 8:7.5. Revisit these values to avoid fraction of pixels.
63 width: units.gu(6)
64 height: units.gu(5.625)
65 anchors.verticalCenter: parent.verticalCenter
66 visible: useMascotShape && image && image.status === Image.Ready
67 readonly property int maxSize: Math.max(width, height) * 4
69 image: useMascotShape ? mascotImage : null
70 }
72 Image {
73 id: mascotImage
75 width: source ? mascotShape.width : 0
76 height: mascotShape.height
77 anchors.verticalCenter: parent.verticalCenter
78 visible: !useMascotShape && status === Image.Ready
80 sourceSize { width: mascotShape.maxSize; height: mascotShape.maxSize }
81 fillMode: Image.PreserveAspectCrop
82 horizontalAlignment: Image.AlignHCenter
83 verticalAlignment: Image.AlignVCenter
84 }
86 Column {
87 objectName: "column"
88 width: parent.width - x
89 spacing: units.gu(0.25)
90 anchors.verticalCenter: parent.verticalCenter
92 Label {
93 id: titleLabel
94 objectName: "titleLabel"
95 anchors { left: parent.left; right: parent.right }
96 elide: Text.ElideRight
97 font.weight: Font.Normal
98 fontSize: "small"
99 wrapMode: Text.Wrap
100 maximumLineCount: 2
101 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
102 color: fontColor
103 }
105 Label {
106 id: subtitleLabel
107 objectName: "subtitleLabel"
108 anchors { left: parent.left; right: parent.right }
109 elide: Text.ElideRight
110 fontSize: "small"
111 font.weight: Font.Light
112 visible: titleLabel.text && text
113 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
114 color: fontColor
115 }
117 Row {
118 id: prices
119 objectName: "prices"
120 anchors { left: parent.left; right: parent.right }
122 property int labels: {
123 var labels = 1; // price always visible
124 if (oldPriceLabel.text !== "") labels += 1;
125 if (altPriceLabel.text !== "") labels += 1;
126 return labels;
127 }
128 property real labelWidth: width / labels
130 Label {
131 id: priceLabel
132 width: parent.labelWidth
133 elide: Text.ElideRight
134 font.weight: Font.DemiBold
135 color: "#ff990000"
136 visible: text
137 }
139 Label {
140 id: oldPriceLabel
141 objectName: "oldPriceLabel"
142 width: parent.labelWidth
143 elide: Text.ElideRight
144 horizontalAlignment: parent.labels === 3 ? Text.AlignHCenter : Text.AlignRight
145 font.strikeout: true
146 color: "black"
147 visible: text
148 }
150 Label {
151 id: altPriceLabel
152 width: parent.labelWidth
153 elide: Text.ElideRight
154 horizontalAlignment: Text.AlignRight
155 color: fontColor
156 visible: text
157 }
158 }
159 }
160 }