Unity 8
 All Classes Functions Properties
CardHeader.qml
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  */
16 
17 import QtQuick 2.0
18 import Ubuntu.Components 0.1
19 
20 Item {
21  id: root
22  property url mascot: ""
23  property alias title: titleLabel.text
24  property var subtitle
25 
26  property alias titleWeight: titleLabel.font.weight
27  property alias titleSize: titleLabel.fontSize
28 
29  // FIXME: Saviq, used to scale fonts down in Carousel
30  property real fontScale: 1.0
31 
32  property alias headerAlignment: titleLabel.horizontalAlignment
33 
34  property bool inOverlay: false
35  property bool useMascotShape: true
36  property color fontColor: Theme.palette.selected.backgroundText
37 
38  visible: mascot != "" || title
39  implicitHeight: row.height > 0 ? row.height + row.margins * 2 : 0
40 
41  Row {
42  id: row
43  objectName: "outerRow"
44 
45  property real margins: units.gu(1)
46 
47  spacing: mascotShapeLoader.active || mascotImageLoader.active || inOverlay ? margins : 0
48  anchors {
49  top: parent.top; left: parent.left; right: parent.right
50  margins: margins
51  leftMargin: spacing
52  rightMargin: spacing
53  }
54 
55  Loader {
56  id: mascotShapeLoader
57  objectName: "mascotShapeLoader"
58 
59  active: useMascotShape && mascotImageLoader.item && mascotImageLoader.item.status === Image.Ready
60  visible: active
61  anchors.verticalCenter: parent.verticalCenter
62  // TODO karni: Icon aspect-ratio is 8:7.5. Revisit these values to avoid fraction of pixels.
63  width: units.gu(6)
64  height: units.gu(5.625)
65  readonly property int maxSize: Math.max(width, height) * 4
66 
67  sourceComponent: UbuntuShape {
68  image: mascotImageLoader.item
69  }
70  }
71 
72  Loader {
73  id: mascotImageLoader
74  active: root.mascot != ""
75  visible: active && !useMascotShape && item.status === Image.Ready
76  anchors.verticalCenter: parent.verticalCenter
77  sourceComponent: Image {
78  objectName: "mascotImage"
79 
80  source: root.mascot
81  width: source ? mascotShapeLoader.width : 0
82  height: mascotShapeLoader.height
83 
84  sourceSize { width: mascotShapeLoader.maxSize; height: mascotShapeLoader.maxSize }
85  fillMode: Image.PreserveAspectCrop
86  horizontalAlignment: Image.AlignHCenter
87  verticalAlignment: Image.AlignVCenter
88  }
89  }
90 
91  Column {
92  objectName: "column"
93  width: parent.width - x
94  spacing: units.dp(2)
95  anchors.verticalCenter: parent.verticalCenter
96 
97  Label {
98  id: titleLabel
99  objectName: "titleLabel"
100  anchors { left: parent.left; right: parent.right }
101  elide: Text.ElideRight
102  font.weight: Font.Normal
103  fontSize: "small"
104  wrapMode: Text.Wrap
105  maximumLineCount: 2
106  font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
107  color: fontColor
108  }
109 
110  Loader {
111  active: titleLabel.text && root.subtitle
112  anchors { left: parent.left; right: parent.right }
113  sourceComponent: Label {
114  id: subtitleLabel
115  objectName: "subtitleLabel"
116  elide: Text.ElideRight
117  fontSize: "small"
118  font.weight: Font.Light
119  font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
120  color: fontColor
121  text: root.subtitle
122  }
123  }
124  }
125  }
126 }