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 
60  anchors.verticalCenter: parent.verticalCenter
61  // TODO karni: Icon aspect-ratio is 8:7.5. Revisit these values to avoid fraction of pixels.
62  width: units.gu(6)
63  height: units.gu(5.625)
64  readonly property int maxSize: Math.max(width, height) * 4
65  asynchronous: true
66 
67  sourceComponent: UbuntuShape {
68  objectName: "mascotShape"
69  visible: image.status === Image.Ready
70  image: Image {
71  source: headerRoot.mascot
72  width: source ? mascotShapeLoader.width : 0
73  height: mascotShapeLoader.height
74 
75  sourceSize { width: mascotShapeLoader.maxSize; height: mascotShapeLoader.maxSize }
76  fillMode: Image.PreserveAspectCrop
77  horizontalAlignment: Image.AlignHCenter
78  verticalAlignment: Image.AlignVCenter
79  }
80  }
81  }
82 
83  Column {
84  objectName: "column"
85  width: parent.width - x
86  spacing: units.dp(2)
87  anchors.verticalCenter: parent.verticalCenter
88 
89  Label {
90  id: titleLabel
91  objectName: "titleLabel"
92  anchors { left: parent.left; right: parent.right }
93  elide: Text.ElideRight
94  font.weight: Font.Normal
95  fontSize: "large"
96  wrapMode: Text.Wrap
97  maximumLineCount: 2
98  color: headerRoot.fontColor
99  text: headerRoot.title
100  }
101 
102  Loader {
103  active: titleLabel.text && headerRoot.subtitle
104  anchors { left: parent.left; right: parent.right }
105  sourceComponent: Label {
106  id: subtitleLabel
107  objectName: "subtitleLabel"
108  elide: Text.ElideRight
109  fontSize: "small"
110  font.weight: Font.Light
111  color: headerRoot.fontColor
112  text: headerRoot.subtitle
113  }
114  }
115  }
116  }
117  }
118 
119 }