on c5af873 help sign in
unity8/Notifications/Notification.qml
309 lines 9.6 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
23UbuntuShape {
24 id: notification
26 property alias iconSource: avatarIcon.source
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
36 objectName: "background"
37 implicitHeight: contentColumn.height + contentColumn.spacing * 2
38 color: Qt.rgba(0.132, 0.117, 0.109, 0.97)
39 opacity: 0
40 radius: "medium"
42 clip: true
44 UnityMenuModelPaths {
45 id: paths
47 source: hints["x-canonical-private-menu-model"]
49 busNameHint: "busName"
50 actionsHint: "actions"
51 menuObjectPathHint: "menuPath"
52 }
54 UnityMenuModel {
55 id: unityMenuModel
57 busName: paths.busName
58 actions: paths.actions
59 menuObjectPath: paths.menuObjectPath
60 }
62 Behavior on implicitHeight {
63 id: heightBehavior
65 enabled: false
66 UbuntuNumberAnimation {
67 duration: UbuntuAnimation.SnapDuration
68 }
69 }
71 // delay enabling height behavior until the add transition is complete
72 onOpacityChanged: if (opacity == 1) heightBehavior.enabled = true
74 MouseArea {
75 id: interactiveArea
77 anchors.fill: contentColumn
78 objectName: "interactiveArea"
79 enabled: notification.type == Notification.Interactive
80 onClicked: notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
81 }
83 Column {
84 id: contentColumn
86 anchors {
87 left: parent.left
88 right: parent.right
89 top: parent.top
90 margins: spacing
91 }
93 spacing: units.gu(1)
95 Row {
96 id: topRow
98 spacing: contentColumn.spacing
99 anchors {
100 left: parent.left
101 right: parent.right
102 }
104 Image {
105 id: noShapeIcon
107 fillMode: Image.PreserveAspectCrop
108 objectName: "noShapeIcon"
109 width: units.gu(6)
110 height: units.gu(6)
111 source: iconSource
112 visible: iconSource !== undefined && iconSource !== "" && notification.hints["x-canonical-noshape-icon"] == "true"
113 }
115 UbuntuShape {
116 id: icon
118 objectName: "icon"
119 width: units.gu(6)
120 height: units.gu(6)
121 visible: iconSource !== undefined && iconSource !== "" && notification.hints["x-canonical-noshape-icon"] !== "true"
122 image: Image {
123 id: avatarIcon
125 fillMode: Image.PreserveAspectCrop
126 }
127 }
129 Image {
130 id: secondaryIcon
132 objectName: "secondaryIcon"
133 width: units.gu(2)
134 height: units.gu(2)
135 visible: source !== undefined && source != ""
136 fillMode: Image.PreserveAspectCrop
137 }
139 Column {
140 id: labelColumn
141 width: parent.width - x
143 anchors.verticalCenter: ((icon.visible || noShapeIcon.visible) && !bodyLabel.visible) ? (icon.visible ? icon.verticalCenter : noShapeIcon.verticalCenter) : undefined
145 Label {
146 id: summaryLabel
148 objectName: "summaryLabel"
149 anchors {
150 left: parent.left
151 right: parent.right
152 }
153 fontSize: "medium"
154 font.bold: true
155 color: Theme.palette.selected.backgroundText
156 elide: Text.ElideRight
157 }
159 Label {
160 id: bodyLabel
162 objectName: "bodyLabel"
163 anchors {
164 left: parent.left
165 right: parent.right
166 }
167 visible: body != ""
168 fontSize: "small"
169 color: Theme.palette.selected.backgroundText
170 opacity: 0.6
171 wrapMode: Text.WordWrap
172 maximumLineCount: 10
173 elide: Text.ElideRight
174 }
175 }
176 }
178 Column {
179 objectName: "dialogListView"
180 spacing: units.gu(2)
182 visible: count > 0
184 anchors.left: parent.left; anchors.right: parent.right
186 Repeater {
187 model: unityMenuModel
189 NotificationMenuItemFactory {
190 anchors.left: parent.left; anchors.right: parent.right
192 menuModel: unityMenuModel
193 menuData: model
194 menuIndex: index
195 }
196 }
197 }
199 Item {
200 id: buttonRow
202 objectName: "buttonRow"
203 anchors {
204 left: parent.left
205 right: parent.right
206 }
207 visible: notification.type == Notification.SnapDecision
208 height: units.gu(5)
210 property real buttonWidth: (width - contentColumn.spacing) / 2
211 property bool expanded
213 Button {
214 id: leftButton
216 objectName: "button1"
217 width: parent.expanded ? parent.width : parent.buttonWidth
218 anchors {
219 top: parent.top
220 bottom: parent.bottom
221 }
222 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 2 ? actionRepeater.itemAt(1).actionLabel : ""
223 gradient: UbuntuColors.greyGradient
224 onClicked: {
225 if (actionRepeater.count > 2) {
226 buttonRow.expanded = !buttonRow.expanded
227 } else {
228 notification.notification.invokeAction(actionRepeater.itemAt(1).actionId)
229 }
230 }
232 Behavior on width {
233 UbuntuNumberAnimation {
234 duration: UbuntuAnimation.SnapDuration
235 }
236 }
237 }
239 Button {
240 id: rightButton
242 objectName: "button0"
243 anchors {
244 left: leftButton.right
245 leftMargin: contentColumn.spacing
246 right: parent.right
247 }
248 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 1 ? actionRepeater.itemAt(0).actionLabel : ""
249 anchors {
250 top: parent.top
251 bottom: parent.bottom
252 }
253 gradient: notification.hints["x-canonical-private-button-tint"] == "true" ? UbuntuColors.orangeGradient : UbuntuColors.greyGradient
254 visible: width > 0
255 onClicked: notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
256 }
257 }
259 Column {
260 objectName: "buttonColumn"
261 spacing: contentColumn.spacing
262 anchors {
263 left: parent.left
264 right: parent.right
265 }
267 // calculate initial position before Column takes over
268 y: buttonRow.y + buttonRow.height + contentColumn.spacing
270 visible: notification.type == Notification.SnapDecision
271 height: buttonRow.expanded ? implicitHeight : 0
273 Repeater {
274 id: actionRepeater
276 model: notification.actions
277 delegate: Loader {
278 id: loader
280 property string actionId: id
281 property string actionLabel: label
283 anchors {
284 left: parent.left
285 right: parent.right
286 }
288 Component {
289 id: actionButton
291 Button {
292 objectName: "button" + index
293 anchors {
294 left: parent.left
295 right: parent.right
296 }
298 text: loader.actionLabel
299 height: units.gu(5)
300 gradient: UbuntuColors.greyGradient
301 onClicked: notification.notification.invokeAction(loader.actionId)
302 }
303 }
304 sourceComponent: (index == 0 || index == 1) ? undefined : actionButton
305 }
306 }
307 }
308 }