on df73bd5 help sign in
unity8/qml/Notifications/Notification.qml
384 lines 12 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 * 2) : 0
44 color: Qt.rgba(0.132, 0.117, 0.109, 0.97)
45 opacity: 0
47 state: {
48 var result = undefined;
50 if (type == Notification.SnapDecision) {
51 if (notificationList.currentIndex == index) {
52 result = "default";
53 } else {
54 if (notificationList.count > 2) {
55 if (notificationList.currentIndex == -1 && index == 1) {
56 result = "default";
57 } else {
58 result = "contracted";
59 }
60 } else {
61 result = "default";
62 }
63 }
64 }
66 return result;
67 }
69 Behavior on height {
70 id: normalHeightBehavior
72 //enabled: menuItemFactory.progress == 1
73 enabled: true
74 UbuntuNumberAnimation {
75 duration: UbuntuAnimation.FastDuration
76 }
77 }
79 states:[
80 State {
81 name: "contracted"
82 PropertyChanges {target: notification; height: units.gu(8)}
83 },
84 State {
85 name: "default"
86 PropertyChanges {target: notification; height: implicitHeight}
87 }
88 ]
90 clip: fullscreen ? false : true
92 visible: type != Notification.PlaceHolder
94 UbuntuShape {
95 id: shapedBack
97 visible: !fullscreen
98 anchors.fill: parent
99 anchors.leftMargin: notification.margins
100 anchors.rightMargin: notification.margins
101 color: parent.color
102 opacity: parent.opacity
103 radius: "medium"
104 }
106 Rectangle {
107 id: nonShapedBack
109 visible: fullscreen
110 anchors.fill: parent
111 color: parent.color
112 opacity: parent.opacity
113 }
115 Item {
116 id: contents
117 anchors.fill: fullscreen ? nonShapedBack : shapedBack
119 UnityMenuModelPaths {
120 id: paths
122 source: hints["x-canonical-private-menu-model"]
124 busNameHint: "busName"
125 actionsHint: "actions"
126 menuObjectPathHint: "menuPath"
127 }
129 UnityMenuModel {
130 id: unityMenuModel
132 busName: paths.busName
133 actions: paths.actions
134 menuObjectPath: paths.menuObjectPath
135 }
137 Behavior on implicitHeight {
138 id: heightBehavior
140 enabled: false
141 UbuntuNumberAnimation {
142 duration: UbuntuAnimation.SnapDuration
143 }
144 }
146 // delay enabling height behavior until the add transition is complete
147 onOpacityChanged: if (opacity == 1) heightBehavior.enabled = true
149 MouseArea {
150 id: interactiveArea
152 anchors.fill: parent
153 objectName: "interactiveArea"
154 onClicked: {
155 if (notification.type == Notification.Interactive) {
156 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
157 } else {
158 notificationList.currentIndex = index;
159 }
160 }
161 }
163 Column {
164 id: contentColumn
166 anchors {
167 left: parent.left
168 right: parent.right
169 top: parent.top
170 margins: fullscreen ? 0 : spacing
171 }
173 spacing: units.gu(1)
175 Row {
176 id: topRow
178 spacing: contentColumn.spacing
179 anchors {
180 left: parent.left
181 right: parent.right
182 }
184 ShapedIcon {
185 id: icon
187 objectName: "icon"
188 width: units.gu(6)
189 height: units.gu(6)
190 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
191 visible: iconSource !== undefined && iconSource != ""
192 }
194 Image {
195 id: secondaryIcon
197 objectName: "secondaryIcon"
198 width: units.gu(2)
199 height: units.gu(2)
200 visible: source !== undefined && source != ""
201 fillMode: Image.PreserveAspectCrop
202 }
204 Column {
205 id: labelColumn
206 width: parent.width - x
208 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
210 Label {
211 id: summaryLabel
213 objectName: "summaryLabel"
214 anchors {
215 left: parent.left
216 right: parent.right
217 }
218 fontSize: "medium"
219 font.bold: true
220 color: Theme.palette.selected.backgroundText
221 elide: Text.ElideRight
222 }
224 Label {
225 id: bodyLabel
227 objectName: "bodyLabel"
228 anchors {
229 left: parent.left
230 right: parent.right
231 }
232 visible: body != ""
233 fontSize: "small"
234 color: Theme.palette.selected.backgroundText
235 opacity: 0.6
236 wrapMode: Text.WordWrap
237 maximumLineCount: 10
238 elide: Text.ElideRight
239 }
240 }
241 }
243 Column {
244 objectName: "dialogListView"
245 spacing: units.gu(2)
247 visible: count > 0
249 anchors.left: parent.left; anchors.right: parent.right
250 anchors.top: fullscreen ? parent.top : undefined
251 anchors.bottom: fullscreen ? parent.bottom : undefined
253 Repeater {
254 model: unityMenuModel
256 NotificationMenuItemFactory {
257 id: menuItemFactory
259 anchors.left: parent.left; anchors.right: parent.right
261 menuModel: unityMenuModel
262 menuData: model
263 menuIndex: index
264 maxHeight: notification.maxHeight
266 onLoaded: {
267 notification.fullscreen = Qt.binding(function() { return fullscreen; });
268 }
269 }
270 }
271 }
273 Item {
274 id: buttonRow
276 objectName: "buttonRow"
277 anchors {
278 left: parent.left
279 right: parent.right
280 }
281 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 0
282 height: units.gu(5)
284 property real buttonWidth: (width - contentColumn.spacing) / 2
285 property bool expanded
287 Button {
288 id: leftButton
290 objectName: "button1"
291 width: parent.expanded ? parent.width : parent.buttonWidth
292 anchors {
293 top: parent.top
294 bottom: parent.bottom
295 }
296 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 2 ? actionRepeater.itemAt(1).actionLabel : ""
297 gradient: UbuntuColors.greyGradient
298 onClicked: {
299 if (actionRepeater.count > 2) {
300 buttonRow.expanded = !buttonRow.expanded
301 } else {
302 notification.notification.invokeAction(actionRepeater.itemAt(1).actionId)
303 }
304 }
306 Behavior on width {
307 UbuntuNumberAnimation {
308 duration: UbuntuAnimation.SnapDuration
309 }
310 }
311 }
313 Button {
314 id: rightButton
316 objectName: "button0"
317 anchors {
318 left: leftButton.right
319 leftMargin: contentColumn.spacing
320 right: parent.right
321 }
322 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 1 ? actionRepeater.itemAt(0).actionLabel : ""
323 anchors {
324 top: parent.top
325 bottom: parent.bottom
326 }
327 gradient: notification.hints["x-canonical-private-button-tint"] == "true" ? UbuntuColors.orangeGradient : UbuntuColors.greyGradient
328 visible: width > 0
329 onClicked: notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
330 }
331 }
333 Column {
334 objectName: "buttonColumn"
335 spacing: contentColumn.spacing
336 anchors {
337 left: parent.left
338 right: parent.right
339 }
341 // calculate initial position before Column takes over
342 y: buttonRow.y + buttonRow.height + contentColumn.spacing
344 visible: notification.type == Notification.SnapDecision && buttonRow.expanded
345 height: buttonRow.expanded ? implicitHeight : 0
347 Repeater {
348 id: actionRepeater
350 model: notification.actions
351 delegate: Loader {
352 id: loader
354 property string actionId: id
355 property string actionLabel: label
357 anchors {
358 left: parent.left
359 right: parent.right
360 }
362 Component {
363 id: actionButton
365 Button {
366 objectName: "button" + index
367 anchors {
368 left: parent.left
369 right: parent.right
370 }
372 text: loader.actionLabel
373 height: units.gu(5)
374 gradient: UbuntuColors.greyGradient
375 onClicked: notification.notification.invokeAction(loader.actionId)
376 }
377 }
378 sourceComponent: (index == 0 || index == 1) ? undefined : actionButton
379 }
380 }
381 }
382 }
383 }