on 551c708 help sign in
unity8/qml/Notifications/Notification.qml
335 lines 11 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
19import Unity.Notifications 1.0
20import QMenuModel 0.1
21import Utils 0.1
23Item {
24 id: notification
26 property alias iconSource: icon.fileSource
27 property alias secondaryIconSource: secondaryIcon.source
28 property alias summary: summaryLabel.text
29 property alias body: bodyLabel.text
30 property var actions
31 property var notificationId
32 property var type
33 property var hints
34 property var notification
35 property color color
36 property bool fullscreen
37 property int maxHeight
38 property int margins
40 fullscreen: false
41 objectName: "background"
42 implicitHeight: type !== Notification.PlaceHolder ? (fullscreen ? maxHeight : contentColumn.height + contentColumn.spacing * 4) : 0
44 color: Qt.rgba(0.132, 0.117, 0.109, 0.97)
45 opacity: 0
47 clip: fullscreen ? false : true
48 visible: type != Notification.PlaceHolder
50 UbuntuShape {
51 id: shapedBack
53 visible: !fullscreen
54 anchors.fill: parent
55 anchors.margins: notification.margins
56 color: parent.color
57 opacity: parent.opacity
58 radius: "medium"
59 }
61 Rectangle {
62 id: nonShapedBack
64 visible: fullscreen
65 anchors.fill: parent
66 color: parent.color
67 opacity: parent.opacity
68 }
70 Item {
71 id: contents
72 anchors.fill: fullscreen ? nonShapedBack : shapedBack
74 UnityMenuModelPaths {
75 id: paths
77 source: hints["x-canonical-private-menu-model"]
79 busNameHint: "busName"
80 actionsHint: "actions"
81 menuObjectPathHint: "menuPath"
82 }
84 UnityMenuModel {
85 id: unityMenuModel
87 busName: paths.busName
88 actions: paths.actions
89 menuObjectPath: paths.menuObjectPath
90 }
92 Behavior on implicitHeight {
93 id: heightBehavior
95 enabled: false
96 UbuntuNumberAnimation {
97 duration: UbuntuAnimation.SnapDuration
98 }
99 }
101 // delay enabling height behavior until the add transition is complete
102 onOpacityChanged: if (opacity == 1) heightBehavior.enabled = true
104 MouseArea {
105 id: interactiveArea
107 anchors.fill: contentColumn
108 objectName: "interactiveArea"
109 onClicked: {
110 if (notification.type == Notification.Interactive) {
111 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
112 }
113 }
114 }
116 Column {
117 id: contentColumn
119 anchors {
120 left: parent.left
121 right: parent.right
122 top: parent.top
123 margins: fullscreen ? 0 : spacing
124 }
126 spacing: units.gu(1)
128 Row {
129 id: topRow
131 spacing: contentColumn.spacing
132 anchors {
133 left: parent.left
134 right: parent.right
135 }
137 ShapedIcon {
138 id: icon
140 objectName: "icon"
141 width: units.gu(6)
142 height: units.gu(6)
143 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
144 visible: iconSource !== undefined && iconSource != ""
145 }
147 Image {
148 id: secondaryIcon
150 objectName: "secondaryIcon"
151 width: units.gu(2)
152 height: units.gu(2)
153 visible: source !== undefined && source != ""
154 fillMode: Image.PreserveAspectCrop
155 }
157 Column {
158 id: labelColumn
159 width: parent.width - x
161 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
163 Label {
164 id: summaryLabel
166 objectName: "summaryLabel"
167 anchors {
168 left: parent.left
169 right: parent.right
170 }
171 fontSize: "medium"
172 font.bold: true
173 color: Theme.palette.selected.backgroundText
174 elide: Text.ElideRight
175 }
177 Label {
178 id: bodyLabel
180 objectName: "bodyLabel"
181 anchors {
182 left: parent.left
183 right: parent.right
184 }
185 visible: body != ""
186 fontSize: "small"
187 color: Theme.palette.selected.backgroundText
188 opacity: 0.6
189 wrapMode: Text.WordWrap
190 maximumLineCount: 10
191 elide: Text.ElideRight
192 }
193 }
194 }
196 Column {
197 objectName: "dialogListView"
198 spacing: units.gu(2)
200 visible: count > 0
202 anchors.left: parent.left; anchors.right: parent.right
203 anchors.top: fullscreen ? parent.top : undefined
204 anchors.bottom: fullscreen ? parent.bottom : undefined
206 Repeater {
207 model: unityMenuModel
209 NotificationMenuItemFactory {
210 anchors.left: parent.left; anchors.right: parent.right
212 menuModel: unityMenuModel
213 menuData: model
214 menuIndex: index
215 maxHeight: notification.maxHeight
217 onLoaded: {
218 notification.fullscreen = Qt.binding(function() { return fullscreen; });
219 }
220 }
221 }
222 }
224 Item {
225 id: buttonRow
227 objectName: "buttonRow"
228 anchors {
229 left: parent.left
230 right: parent.right
231 }
232 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 0
233 height: units.gu(5)
235 property real buttonWidth: (width - contentColumn.spacing) / 2
236 property bool expanded
238 Button {
239 id: leftButton
241 objectName: "button1"
242 width: parent.expanded ? parent.width : parent.buttonWidth
243 anchors {
244 top: parent.top
245 bottom: parent.bottom
246 }
247 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 2 ? actionRepeater.itemAt(1).actionLabel : ""
248 gradient: UbuntuColors.greyGradient
249 onClicked: {
250 if (actionRepeater.count > 2) {
251 buttonRow.expanded = !buttonRow.expanded
252 } else {
253 notification.notification.invokeAction(actionRepeater.itemAt(1).actionId)
254 }
255 }
257 Behavior on width {
258 UbuntuNumberAnimation {
259 duration: UbuntuAnimation.SnapDuration
260 }
261 }
262 }
264 Button {
265 id: rightButton
267 objectName: "button0"
268 anchors {
269 left: leftButton.right
270 leftMargin: contentColumn.spacing
271 right: parent.right
272 }
273 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 1 ? actionRepeater.itemAt(0).actionLabel : ""
274 anchors {
275 top: parent.top
276 bottom: parent.bottom
277 }
278 gradient: notification.hints["x-canonical-private-button-tint"] == "true" ? UbuntuColors.orangeGradient : UbuntuColors.greyGradient
279 visible: width > 0
280 onClicked: notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
281 }
282 }
284 Column {
285 objectName: "buttonColumn"
286 spacing: contentColumn.spacing
287 anchors {
288 left: parent.left
289 right: parent.right
290 }
292 // calculate initial position before Column takes over
293 y: buttonRow.y + buttonRow.height + contentColumn.spacing
295 visible: notification.type == Notification.SnapDecision && buttonRow.expanded
296 height: buttonRow.expanded ? implicitHeight : 0
298 Repeater {
299 id: actionRepeater
301 model: notification.actions
302 delegate: Loader {
303 id: loader
305 property string actionId: id
306 property string actionLabel: label
308 anchors {
309 left: parent.left
310 right: parent.right
311 }
313 Component {
314 id: actionButton
316 Button {
317 objectName: "button" + index
318 anchors {
319 left: parent.left
320 right: parent.right
321 }
323 text: loader.actionLabel
324 height: units.gu(5)
325 gradient: UbuntuColors.greyGradient
326 onClicked: notification.notification.invokeAction(loader.actionId)
327 }
328 }
329 sourceComponent: (index == 0 || index == 1) ? undefined : actionButton
330 }
331 }
332 }
333 }
334 }