on c43037e help sign in
unity8/Notifications/Notification.qml
325 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
38 fullscreen: false
39 objectName: "background"
40 implicitHeight: type != Notification.PlaceHolder ? (fullscreen ? notificationList.fullHeight : contentColumn.height + contentColumn.spacing * 4) : 0
42 color: Qt.rgba(0.132, 0.117, 0.109, 0.97)
43 opacity: 0
45 clip: fullscreen ? false : true
46 visible: type != Notification.PlaceHolder
48 UbuntuShape {
49 id: shapedBack
51 visible: !fullscreen
52 anchors.fill: parent
53 anchors.margins: notificationList.margin
54 color: parent.color
55 opacity: parent.opacity
56 radius: "medium"
57 }
59 Rectangle {
60 id: nonShapedBack
62 visible: fullscreen
63 anchors.fill: parent
64 color: parent.color
65 opacity: parent.opacity
66 }
68 Item {
69 id: contents
70 anchors.fill: fullscreen ? nonShapedBack : shapedBack
72 UnityMenuModelPaths {
73 id: paths
75 source: hints["x-canonical-private-menu-model"]
77 busNameHint: "busName"
78 actionsHint: "actions"
79 menuObjectPathHint: "menuPath"
80 }
82 UnityMenuModel {
83 id: unityMenuModel
85 busName: paths.busName
86 actions: paths.actions
87 menuObjectPath: paths.menuObjectPath
88 }
90 Behavior on implicitHeight {
91 id: heightBehavior
93 enabled: false
94 UbuntuNumberAnimation {
95 duration: UbuntuAnimation.SnapDuration
96 }
97 }
99 // delay enabling height behavior until the add transition is complete
100 onOpacityChanged: if (opacity == 1) heightBehavior.enabled = true
102 MouseArea {
103 id: interactiveArea
105 anchors.fill: contentColumn
106 objectName: "interactiveArea"
107 enabled: notification.type == Notification.Interactive
108 onClicked: notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
109 }
111 Column {
112 id: contentColumn
114 anchors {
115 left: parent.left
116 right: parent.right
117 top: parent.top
118 margins: fullscreen ? 0 : spacing
119 }
121 spacing: units.gu(1)
123 Row {
124 id: topRow
126 spacing: contentColumn.spacing
127 anchors {
128 left: parent.left
129 right: parent.right
130 }
132 ShapedIcon {
133 id: icon
135 objectName: "icon"
136 width: units.gu(6)
137 height: units.gu(6)
138 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
139 visible: iconSource !== undefined && iconSource != ""
140 }
142 Image {
143 id: secondaryIcon
145 objectName: "secondaryIcon"
146 width: units.gu(2)
147 height: units.gu(2)
148 visible: source !== undefined && source != ""
149 fillMode: Image.PreserveAspectCrop
150 }
152 Column {
153 id: labelColumn
154 width: parent.width - x
156 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
158 Label {
159 id: summaryLabel
161 objectName: "summaryLabel"
162 anchors {
163 left: parent.left
164 right: parent.right
165 }
166 fontSize: "medium"
167 font.bold: true
168 color: Theme.palette.selected.backgroundText
169 elide: Text.ElideRight
170 }
172 Label {
173 id: bodyLabel
175 objectName: "bodyLabel"
176 anchors {
177 left: parent.left
178 right: parent.right
179 }
180 visible: body != ""
181 fontSize: "small"
182 color: Theme.palette.selected.backgroundText
183 opacity: 0.6
184 wrapMode: Text.WordWrap
185 maximumLineCount: 10
186 elide: Text.ElideRight
187 }
188 }
189 }
191 Column {
192 objectName: "dialogListView"
193 spacing: units.gu(2)
195 visible: count > 0
197 anchors.left: parent.left; anchors.right: parent.right
198 anchors.top: fullscreen ? parent.top : undefined
199 anchors.bottom: fullscreen ? parent.bottom : undefined
201 Repeater {
202 model: unityMenuModel
204 NotificationMenuItemFactory {
205 anchors.left: parent.left; anchors.right: parent.right
207 menuModel: unityMenuModel
208 menuData: model
209 menuIndex: index
210 }
211 }
212 }
214 Item {
215 id: buttonRow
217 objectName: "buttonRow"
218 anchors {
219 left: parent.left
220 right: parent.right
221 }
222 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 0
223 height: units.gu(5)
225 property real buttonWidth: (width - contentColumn.spacing) / 2
226 property bool expanded
228 Button {
229 id: leftButton
231 objectName: "button1"
232 width: parent.expanded ? parent.width : parent.buttonWidth
233 anchors {
234 top: parent.top
235 bottom: parent.bottom
236 }
237 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 2 ? actionRepeater.itemAt(1).actionLabel : ""
238 gradient: UbuntuColors.greyGradient
239 onClicked: {
240 if (actionRepeater.count > 2) {
241 buttonRow.expanded = !buttonRow.expanded
242 } else {
243 notification.notification.invokeAction(actionRepeater.itemAt(1).actionId)
244 }
245 }
247 Behavior on width {
248 UbuntuNumberAnimation {
249 duration: UbuntuAnimation.SnapDuration
250 }
251 }
252 }
254 Button {
255 id: rightButton
257 objectName: "button0"
258 anchors {
259 left: leftButton.right
260 leftMargin: contentColumn.spacing
261 right: parent.right
262 }
263 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 1 ? actionRepeater.itemAt(0).actionLabel : ""
264 anchors {
265 top: parent.top
266 bottom: parent.bottom
267 }
268 gradient: notification.hints["x-canonical-private-button-tint"] == "true" ? UbuntuColors.orangeGradient : UbuntuColors.greyGradient
269 visible: width > 0
270 onClicked: notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
271 }
272 }
274 Column {
275 objectName: "buttonColumn"
276 spacing: contentColumn.spacing
277 anchors {
278 left: parent.left
279 right: parent.right
280 }
282 // calculate initial position before Column takes over
283 y: buttonRow.y + buttonRow.height + contentColumn.spacing
285 visible: notification.type == Notification.SnapDecision && buttonRow.expanded
286 height: buttonRow.expanded ? implicitHeight : 0
288 Repeater {
289 id: actionRepeater
291 model: notification.actions
292 delegate: Loader {
293 id: loader
295 property string actionId: id
296 property string actionLabel: label
298 anchors {
299 left: parent.left
300 right: parent.right
301 }
303 Component {
304 id: actionButton
306 Button {
307 objectName: "button" + index
308 anchors {
309 left: parent.left
310 right: parent.right
311 }
313 text: loader.actionLabel
314 height: units.gu(5)
315 gradient: UbuntuColors.greyGradient
316 onClicked: notification.notification.invokeAction(loader.actionId)
317 }
318 }
319 sourceComponent: (index == 0 || index == 1) ? undefined : actionButton
320 }
321 }
322 }
323 }
324 }