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