on ac4b821 help sign in
unity8/qml/Dash/CardHeader.qml
133 lines 4.4 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 visible: mascotImage.status === Image.Ready || title || price
30 height: row.height > 0 ? row.height + row.margins * 2 : 0
32 Row {
33 id: row
34 objectName: "outerRow"
36 property real margins: units.gu(1)
38 anchors {
39 top: parent.top; left: parent.left; right: parent.right
40 margins: margins
41 leftMargin: spacing
42 rightMargin: spacing
43 }
44 spacing: mascotShape.visible ? margins : 0
46 UbuntuShape {
47 id: mascotShape
48 objectName: "mascotShape"
50 // TODO karni: Icon aspect-ratio is 8:7.5. Revisit these values to avoid fraction of pixels.
51 width: units.gu(6)
52 height: units.gu(5.625)
53 visible: image.status === Image.Ready
54 readonly property int maxSize: Math.max(width, height)
56 image: Image {
57 id: mascotImage
59 sourceSize { width: mascotShape.maxSize; height: mascotShape.maxSize }
60 fillMode: Image.PreserveAspectCrop
61 horizontalAlignment: Image.AlignHCenter
62 verticalAlignment: Image.AlignVCenter
63 }
64 }
66 Column {
67 objectName: "column"
68 width: parent.width - x
69 spacing: units.gu(0.5)
71 Label {
72 id: titleLabel
73 objectName: "titleLabel"
74 anchors { left: parent.left; right: parent.right }
75 elide: Text.ElideRight
76 font.weight: Font.DemiBold
77 wrapMode: Text.Wrap
78 maximumLineCount: 2
79 fontSize: "small"
80 }
82 Label {
83 id: subtitleLabel
84 objectName: "subtitleLabel"
85 anchors { left: parent.left; right: parent.right }
86 elide: Text.ElideRight
87 font.weight: Font.Light
88 visible: titleLabel.text && text
89 fontSize: "x-small"
90 }
92 Row {
93 id: prices
94 objectName: "prices"
95 anchors { left: parent.left; right: parent.right }
97 property int labels: {
98 var labels = 1; // price always visible
99 if (oldPriceLabel.text !== "") labels += 1;
100 if (altPriceLabel.text !== "") labels += 1;
101 return labels;
102 }
103 property real labelWidth: width / labels
105 Label {
106 id: priceLabel
107 width: parent.labelWidth
108 elide: Text.ElideRight
109 font.weight: Font.DemiBold
110 color: Theme.palette.selected.foreground
111 visible: text
112 }
114 Label {
115 id: oldPriceLabel
116 objectName: "oldPriceLabel"
117 width: parent.labelWidth
118 elide: Text.ElideRight
119 horizontalAlignment: parent.labels === 3 ? Text.AlignHCenter : Text.AlignRight
120 visible: text
121 }
123 Label {
124 id: altPriceLabel
125 width: parent.labelWidth
126 elide: Text.ElideRight
127 horizontalAlignment: Text.AlignRight
128 visible: text
129 }
130 }
131 }
132 }