on dde6dc2 help sign in
unity8/qml/Dash/CardHeader.qml
142 lines 5.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
25 property alias price: priceLabel.text
26 property alias oldPrice: oldPriceLabel.text
27 property alias altPrice: altPriceLabel.text
29 // FIXME: Saviq, used to scale fonts down in Carousel
30 property real fontScale: 1.0
32 property alias headerAlignment: titleLabel.horizontalAlignment
34 visible: mascotImage.status === Image.Ready || title || price
35 height: row.height > 0 ? row.height + row.margins * 2 : 0
37 Row {
38 id: row
39 objectName: "outerRow"
41 property real margins: units.gu(1)
43 anchors {
44 top: parent.top; left: parent.left; right: parent.right
45 margins: margins
46 leftMargin: spacing
47 rightMargin: spacing
48 }
49 spacing: mascotShape.visible || (template && template["overlay"]) ? margins : 0
51 UbuntuShape {
52 id: mascotShape
53 objectName: "mascotShape"
55 // TODO karni: Icon aspect-ratio is 8:7.5. Revisit these values to avoid fraction of pixels.
56 width: units.gu(6)
57 height: units.gu(5.625)
58 visible: image.status === Image.Ready
59 readonly property int maxSize: Math.max(width, height)
61 image: Image {
62 id: mascotImage
64 sourceSize { width: mascotShape.maxSize; height: mascotShape.maxSize }
65 fillMode: Image.PreserveAspectCrop
66 horizontalAlignment: Image.AlignHCenter
67 verticalAlignment: Image.AlignVCenter
68 }
69 }
71 Column {
72 objectName: "column"
73 width: parent.width - x
74 spacing: units.gu(0.5)
76 Label {
77 id: titleLabel
78 objectName: "titleLabel"
79 anchors { left: parent.left; right: parent.right }
80 elide: Text.ElideRight
81 font.weight: Font.DemiBold
82 wrapMode: Text.Wrap
83 maximumLineCount: 2
84 fontSize: "small"
85 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
86 color: template["overlay"] === true ? "white" : Theme.palette.selected.backgroundText
87 }
89 Label {
90 id: subtitleLabel
91 objectName: "subtitleLabel"
92 anchors { left: parent.left; right: parent.right }
93 elide: Text.ElideRight
94 font.weight: Font.Light
95 visible: titleLabel.text && text
96 fontSize: "x-small"
97 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
98 color: template["overlay"] === true ? "white" : Theme.palette.selected.backgroundText
99 }
101 Row {
102 id: prices
103 objectName: "prices"
104 anchors { left: parent.left; right: parent.right }
106 property int labels: {
107 var labels = 1; // price always visible
108 if (oldPriceLabel.text !== "") labels += 1;
109 if (altPriceLabel.text !== "") labels += 1;
110 return labels;
111 }
112 property real labelWidth: width / labels
114 Label {
115 id: priceLabel
116 width: parent.labelWidth
117 elide: Text.ElideRight
118 font.weight: Font.DemiBold
119 color: Theme.palette.selected.foreground
120 visible: text
121 }
123 Label {
124 id: oldPriceLabel
125 objectName: "oldPriceLabel"
126 width: parent.labelWidth
127 elide: Text.ElideRight
128 horizontalAlignment: parent.labels === 3 ? Text.AlignHCenter : Text.AlignRight
129 visible: text
130 }
132 Label {
133 id: altPriceLabel
134 width: parent.labelWidth
135 elide: Text.ElideRight
136 horizontalAlignment: Text.AlignRight
137 visible: text
138 }
139 }
140 }
141 }