on 551c708 help sign in
unity8/qml/Dash/CardHeader.qml
116 lines 3.8 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.spacing * 2 : 0
32 Row {
33 id: row
34 objectName: "outerRow"
36 anchors { top: parent.top; left: parent.left; right: parent.right; margins: spacing }
37 spacing: units.gu(1)
39 UbuntuShape {
40 id: mascotShape
41 objectName: "mascotShape"
43 width: units.gu(8)
44 height: units.gu(8)
45 visible: image.status === Image.Ready
47 image: Image {
48 id: mascotImage
49 sourceSize { width: mascotShape.width; height: mascotShape.height }
50 }
51 }
53 Column {
54 objectName: "column"
55 width: parent.width - x
57 Label {
58 id: titleLabel
59 objectName: "titleLabel"
60 anchors { left: parent.left; right: parent.right }
61 elide: Text.ElideRight
62 font.weight: Font.DemiBold
63 wrapMode: Text.Wrap
64 maximumLineCount: 2
65 }
67 Label {
68 id: subtitleLabel
69 objectName: "subtitleLabel"
70 anchors { left: parent.left; right: parent.right }
71 elide: Text.ElideRight
72 visible: titleLabel.text && text
73 }
75 Row {
76 id: prices
77 objectName: "prices"
78 anchors { left: parent.left; right: parent.right }
80 property int labels: {
81 var labels = 1; // price always visible
82 if (oldPriceLabel.text !== "") labels += 1;
83 if (altPriceLabel.text !== "") labels += 1;
84 return labels;
85 }
86 property real labelWidth: width / labels
88 Label {
89 id: priceLabel
90 width: parent.labelWidth
91 elide: Text.ElideRight
92 font.weight: Font.DemiBold
93 color: Theme.palette.selected.foreground
94 visible: text
95 }
97 Label {
98 id: oldPriceLabel
99 objectName: "oldPriceLabel"
100 width: parent.labelWidth
101 elide: Text.ElideRight
102 horizontalAlignment: parent.labels === 3 ? Text.AlignHCenter : Text.AlignRight
103 visible: text
104 }
106 Label {
107 id: altPriceLabel
108 width: parent.labelWidth
109 elide: Text.ElideRight
110 horizontalAlignment: Text.AlignRight
111 visible: text
112 }
113 }
114 }
115 }