1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
|
/*
* Copyright (C) 2013 Canonical, Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import QtMultimedia 5.0
import Ubuntu.Components 0.1
import Unity.Notifications 1.0
import QMenuModel 0.1
import Utils 0.1
Item {
id: notification
property alias iconSource: icon.fileSource
property alias secondaryIconSource: secondaryIcon.source
property alias summary: summaryLabel.text
property alias body: bodyLabel.text
property var actions
property var notificationId
property var type
property var hints
property var notification
property color color
property bool fullscreen
property int maxHeight
property int margins
fullscreen: false
objectName: "background"
implicitHeight: type !== Notification.PlaceHolder ? (fullscreen ? maxHeight : contentColumn.height + contentColumn.spacing * 2) : 0
color: Qt.rgba(0.132, 0.117, 0.109, 0.97)
opacity: 0
state: {
var result = "";
if (type == Notification.SnapDecision) {
if (ListView.view.currentIndex == index) {
result = "expanded";
} else {
if (ListView.view.count > 2) {
if (ListView.view.currentIndex == -1 && index == 1) {
result = "expanded";
} else {
result = "contracted";
}
} else {
result = "expanded";
}
}
}
return result;
}
Audio {
id: sound
objectName: "sound"
source: hints["suppress-sound"] != "" ? hints["sound-file"] : undefined
}
onOpacityChanged: {
if (opacity == 1.0 && hints["suppress-sound"] != "true" && sound.source) {
sound.play();
}
}
Behavior on height {
id: normalHeightBehavior
//enabled: menuItemFactory.progress == 1
enabled: true
SequentialAnimation {
PauseAnimation {
duration: UbuntuAnimation.SnapDuration
}
UbuntuNumberAnimation {
duration: UbuntuAnimation.SnapDuration
}
}
}
states:[
State {
name: "contracted"
PropertyChanges {target: notification; height: units.gu(8)}
},
State {
name: "expanded"
PropertyChanges {target: notification; height: implicitHeight}
}
]
clip: fullscreen ? false : true
visible: type != Notification.PlaceHolder
UbuntuShape {
id: shapedBack
visible: !fullscreen
anchors {
fill: parent
leftMargin: notification.margins
rightMargin: notification.margins
}
color: parent.color
opacity: parent.opacity
radius: "medium"
}
Rectangle {
id: nonShapedBack
visible: fullscreen
anchors.fill: parent
color: parent.color
opacity: parent.opacity
}
Item {
id: contents
anchors.fill: fullscreen ? nonShapedBack : shapedBack
UnityMenuModelPaths {
id: paths
source: hints["x-canonical-private-menu-model"]
busNameHint: "busName"
actionsHint: "actions"
menuObjectPathHint: "menuPath"
}
UnityMenuModel {
id: unityMenuModel
busName: paths.busName
actions: paths.actions
menuObjectPath: paths.menuObjectPath
}
Behavior on implicitHeight {
id: heightBehavior
enabled: false
UbuntuNumberAnimation {
duration: UbuntuAnimation.SnapDuration
}
}
// delay enabling height behavior until the add transition is complete
onOpacityChanged: if (opacity == 1) heightBehavior.enabled = true
MouseArea {
id: interactiveArea
anchors.fill: parent
objectName: "interactiveArea"
onClicked: {
if (notification.type == Notification.Interactive) {
notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
} else {
notificationList.currentIndex = index;
}
}
}
Column {
id: contentColumn
objectName: "contentColumn"
anchors {
left: parent.left
right: parent.right
top: parent.top
margins: fullscreen ? 0 : spacing
}
spacing: units.gu(1)
Row {
id: topRow
spacing: contentColumn.spacing
anchors {
left: parent.left
right: parent.right
}
ShapedIcon {
id: icon
objectName: "icon"
width: units.gu(6)
height: units.gu(6)
shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
visible: iconSource !== undefined && iconSource != ""
}
Image {
id: secondaryIcon
objectName: "secondaryIcon"
width: units.gu(2)
height: units.gu(2)
visible: source !== undefined && source != ""
fillMode: Image.PreserveAspectCrop
}
Column {
id: labelColumn
width: parent.width - x
anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
Label {
id: summaryLabel
objectName: "summaryLabel"
anchors {
left: parent.left
right: parent.right
}
fontSize: "medium"
font.bold: true
color: Theme.palette.selected.backgroundText
elide: Text.ElideRight
}
Label {
id: bodyLabel
objectName: "bodyLabel"
anchors {
left: parent.left
right: parent.right
}
visible: body != ""
fontSize: "small"
color: Theme.palette.selected.backgroundText
opacity: 0.6
wrapMode: Text.WordWrap
maximumLineCount: 10
elide: Text.ElideRight
}
}
}
Column {
objectName: "dialogListView"
spacing: units.gu(2)
visible: count > 0
anchors.left: parent.left; anchors.right: parent.right
anchors.top: fullscreen ? parent.top : undefined
anchors.bottom: fullscreen ? parent.bottom : undefined
Repeater {
model: unityMenuModel
NotificationMenuItemFactory {
id: menuItemFactory
anchors.left: parent.left; anchors.right: parent.right
menuModel: unityMenuModel
menuData: model
menuIndex: index
maxHeight: notification.maxHeight
onLoaded: {
notification.fullscreen = Qt.binding(function() { return fullscreen; });
}
}
}
}
Item {
id: buttonRow
objectName: "buttonRow"
anchors {
left: parent.left
right: parent.right
}
visible: notification.type == Notification.SnapDecision && actionRepeater.count > 0
height: units.gu(5)
property real buttonWidth: (width - contentColumn.spacing) / 2
property bool expanded
Button {
id: leftButton
objectName: "button1"
width: parent.expanded ? parent.width : parent.buttonWidth
anchors {
top: parent.top
bottom: parent.bottom
}
text: notification.type == Notification.SnapDecision && actionRepeater.count >= 2 ? actionRepeater.itemAt(1).actionLabel : ""
gradient: UbuntuColors.greyGradient
onClicked: {
if (actionRepeater.count > 2) {
buttonRow.expanded = !buttonRow.expanded
} else {
notification.notification.invokeAction(actionRepeater.itemAt(1).actionId)
}
}
Behavior on width {
UbuntuNumberAnimation {
duration: UbuntuAnimation.SnapDuration
}
}
}
Button {
id: rightButton
objectName: "button0"
anchors {
left: leftButton.right
leftMargin: contentColumn.spacing
right: parent.right
}
text: notification.type == Notification.SnapDecision && actionRepeater.count >= 1 ? actionRepeater.itemAt(0).actionLabel : ""
anchors {
top: parent.top
bottom: parent.bottom
}
gradient: notification.hints["x-canonical-private-button-tint"] == "true" ? UbuntuColors.orangeGradient : UbuntuColors.greyGradient
visible: width > 0
onClicked: notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
}
}
Column {
objectName: "buttonColumn"
spacing: contentColumn.spacing
anchors {
left: parent.left
right: parent.right
}
// calculate initial position before Column takes over
y: buttonRow.y + buttonRow.height + contentColumn.spacing
visible: notification.type == Notification.SnapDecision && buttonRow.expanded
height: buttonRow.expanded ? implicitHeight : 0
Repeater {
id: actionRepeater
model: notification.actions
delegate: Loader {
id: loader
property string actionId: id
property string actionLabel: label
anchors {
left: parent.left
right: parent.right
}
Component {
id: actionButton
Button {
objectName: "button" + index
anchors {
left: parent.left
right: parent.right
}
text: loader.actionLabel
height: units.gu(5)
gradient: UbuntuColors.greyGradient
onClicked: notification.notification.invokeAction(loader.actionId)
}
}
sourceComponent: (index == 0 || index == 1) ? undefined : actionButton
}
}
}
}
}
}
|