on 2139c25 help sign in
unity8/Dash/DashPreview.qml
188 lines 5.2 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
20Rectangle {
21 id: root
23 property var previewData
25 property string title: ""
26 property real previewWidthRatio: 0.5
28 property Component header
29 property Component buttons
30 property Component body
32 readonly property bool narrowMode: width <= height
33 readonly property int contentSpacing: units.gu(3)
35 signal close()
36 signal previewImageClicked()
38 color: Qt.rgba(0, 0, 0, .3)
39 clip: true
41 Connections {
42 target: shell.applicationManager
43 onMainStageFocusedApplicationChanged: {
44 root.close();
45 }
46 onSideStageFocusedApplicationChanged: {
47 root.close();
48 }
49 }
51 MouseArea {
52 anchors.fill: parent
53 }
55 Item {
56 id: headerRow
57 height: units.gu(4)
58 anchors {
59 top: parent.top
60 left: parent.left
61 right: parent.right
62 margins: root.contentSpacing
63 }
65 MouseArea {
66 anchors {
67 fill: parent
68 leftMargin: -root.contentSpacing
69 rightMargin: -root.contentSpacing
70 topMargin: -root.contentSpacing
71 }
73 onClicked: root.close();
74 }
76 Item {
77 id: labelItem
78 anchors {
79 fill: parent
80 rightMargin: closePreviewImage.width + spacing
81 }
83 property int spacing: units.gu(2)
85 Label {
86 id: title
87 objectName: "titleLabel"
88 anchors {
89 left: parent.left
90 right: parent.right
91 }
93 elide: Text.ElideRight
94 fontSize: "x-large"
95 font.weight: Font.Light
96 color: Theme.palette.selected.backgroundText
97 opacity: 0.9
98 text: root.title
99 style: Text.Raised
100 styleColor: "black"
101 }
102 Image {
103 id: closePreviewImage
104 source: "graphics/tablet/icon_close_preview.png"
105 width: units.gu(4)
106 height: units.gu(1.5)
107 anchors {
108 bottom: title.bottom
109 bottomMargin: units.dp(7)
110 left: parent.left
111 leftMargin: title.paintedWidth + labelItem.spacing
112 }
113 }
114 }
115 }
117 Row {
118 id: contentRow
119 anchors {
120 left: parent.left
121 right: parent.right
122 top: headerRow.bottom
123 bottom: parent.bottom
124 margins: root.contentSpacing
125 }
127 spacing: units.gu(2)
129 Flickable {
130 id: leftFlickable
131 anchors.top: parent.top
132 anchors.bottom: parent.bottom
133 width: root.narrowMode ? contentRow.width : contentRow.width * root.previewWidthRatio
134 contentHeight: leftColumn.height
135 clip: true
137 Column {
138 id: leftColumn
139 objectName: "leftColumn"
140 anchors {
141 left: parent.left
142 right: parent.right
143 }
144 height: childrenRect.height
145 spacing: units.gu(1)
147 Loader {
148 id: headerLoader
149 anchors.left: parent.left
150 anchors.right: parent.right
151 sourceComponent: root.header
152 }
153 Loader {
154 id: buttonLoader
155 anchors.left: parent.left
156 anchors.right: parent.right
157 sourceComponent: root.buttons
158 }
159 }
160 }
162 Flickable {
163 id: rightFlickable
164 anchors.top: parent.top
165 anchors.bottom: parent.bottom
166 width: narrowMode ? 0 : (contentRow.width - leftColumn.width - contentRow.spacing)
167 contentHeight: rightColumn.height
168 clip: true
170 Column {
171 id: rightColumn
172 objectName: "rightColumn"
173 height: childrenRect.height
174 anchors {
175 left: parent.left
176 right: parent.right
177 }
178 }
179 }
180 }
182 Loader {
183 parent: root.narrowMode ? leftColumn : rightColumn
184 anchors.left: parent.left
185 anchors.right: parent.right
186 sourceComponent: root.body
187 }