on f7134c6 help sign in
unity8/plugins/Dash/CardAttributes.qml
79 lines 3.2 kB history raw
1/*
2 * Copyright 2014 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.4
18import QtQuick.Layouts 1.1
19import Ubuntu.Components 1.3
21GridLayout {
22 id: grid
23 anchors {
24 left: parent.left;
25 right: parent.right;
26 }
27 columns: 2 + repeater.count % 2
28 rowSpacing: units.gu(.5)
29 property alias model: repeater.model
30 property color color: theme.palette.normal.baseText
31 property real fontScale: 1.0
33 Repeater {
34 id: repeater
35 delegate: Row {
36 spacing: units.gu(0.5)
37 readonly property int column: index % grid.columns;
38 Layout.alignment: {
39 if (column == 0) return Qt.AlignLeft;
40 if (column == grid.columns - 1 || index == repeater.count - 1) return Qt.AlignRight;
41 if (column == 1) return Qt.AlignHCenter;
42 }
43 Layout.column: index % grid.columns
44 Layout.row: index / grid.columns
45 Layout.columnSpan: index == repeater.count - 1 && grid.columns == 3 && column == 1 ? 2 : 1
46 Layout.maximumWidth: Math.max(iconLoader.width, labelLoader.x + labelLoader.implicitWidth)
47 Layout.fillWidth: true
48 height: units.gu(2)
49 Loader {
50 id: iconLoader
51 readonly property string source: "icon" in modelData && modelData["icon"] || ""
52 active: source !== ""
53 sourceComponent: Icon {
54 height: units.gu(2)
55 // FIXME Workaround for bug https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1421293
56 width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth
57 source: parent.source
58 color: grid.color
59 }
60 }
61 Loader {
62 id: labelLoader
63 width: parent.width - x
64 readonly property string value: "value" in modelData && modelData["value"] || ""
65 active: value !== ""
66 sourceComponent: Label {
67 anchors.verticalCenter: parent.verticalCenter
68 text: parent.value
69 elide: Text.ElideRight
70 maximumLineCount: 1
71 font.weight: "style" in modelData && modelData["style"] === "highlighted" ? Font.Bold : Font.Light
72 fontSize: "small"
73 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
74 color: grid.color
75 }
76 }
77 }
78 }