on fbe3fd3 help sign in
unity8/qml/Dash/CardHeader.qml
155 lines 5.3 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
31 // FIXME: Saviq, used to scale fonts down in Carousel
32 property real fontScale: 1.0
34 property alias headerAlignment: titleLabel.horizontalAlignment
36 property bool inOverlay: false
37 property bool useMascotShape: true
38 property color fontColor: "grey"
40 visible: mascotImage.status === Image.Ready || title || price
41 height: row.height > 0 ? row.height + row.margins * 2 : 0
43 Row {
44 id: row
45 objectName: "outerRow"
47 property real margins: units.gu(1)
49 spacing: mascotShape.visible || mascotImage.visible || inOverlay ? margins : 0
50 anchors {
51 top: parent.top; left: parent.left; right: parent.right
52 margins: margins
53 leftMargin: spacing
54 rightMargin: spacing
55 }
57 UbuntuShape {
58 id: mascotShape
59 objectName: "mascotShape"
61 // TODO karni: Icon aspect-ratio is 8:7.5. Revisit these values to avoid fraction of pixels.
62 width: units.gu(6)
63 height: units.gu(5.625)
64 visible: useMascotShape && image && image.status === Image.Ready
65 readonly property int maxSize: Math.max(width, height) * 4
67 image: useMascotShape ? mascotImage : null
68 }
70 Image {
71 id: mascotImage
73 width: source ? mascotShape.width : 0
74 height: mascotShape.height
75 visible: !useMascotShape && status === Image.Ready
77 sourceSize { width: mascotShape.maxSize; height: mascotShape.maxSize }
78 fillMode: Image.PreserveAspectCrop
79 horizontalAlignment: Image.AlignHCenter
80 verticalAlignment: Image.AlignVCenter
81 }
83 Column {
84 objectName: "column"
85 width: parent.width - x
86 spacing: units.gu(0.5)
88 Label {
89 id: titleLabel
90 objectName: "titleLabel"
91 anchors { left: parent.left; right: parent.right }
92 elide: Text.ElideRight
93 font.weight: Font.DemiBold
94 wrapMode: Text.Wrap
95 maximumLineCount: 2
96 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
97 color: fontColor
98 }
100 Label {
101 id: subtitleLabel
102 objectName: "subtitleLabel"
103 anchors { left: parent.left; right: parent.right }
104 elide: Text.ElideRight
105 font.weight: Font.Light
106 visible: titleLabel.text && text
107 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
108 color: fontColor
109 }
111 Row {
112 id: prices
113 objectName: "prices"
114 anchors { left: parent.left; right: parent.right }
116 property int labels: {
117 var labels = 1; // price always visible
118 if (oldPriceLabel.text !== "") labels += 1;
119 if (altPriceLabel.text !== "") labels += 1;
120 return labels;
121 }
122 property real labelWidth: width / labels
124 Label {
125 id: priceLabel
126 width: parent.labelWidth
127 elide: Text.ElideRight
128 font.weight: Font.DemiBold
129 color: "#ff990000"
130 visible: text
131 }
133 Label {
134 id: oldPriceLabel
135 objectName: "oldPriceLabel"
136 width: parent.labelWidth
137 elide: Text.ElideRight
138 horizontalAlignment: parent.labels === 3 ? Text.AlignHCenter : Text.AlignRight
139 font.strikeout: true
140 color: "black"
141 visible: text
142 }
144 Label {
145 id: altPriceLabel
146 width: parent.labelWidth
147 elide: Text.ElideRight
148 horizontalAlignment: Text.AlignRight
149 color: fontColor
150 visible: text
151 }
152 }
153 }
154 }