on 572bc68 help sign in
unity8/Notifications/Notification.qml
295 lines 8.9 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, 0, 0, 0.85)
39 opacity: 0
41 clip: true
43 UnityMenuModelPaths {
44 id: paths
46 source: hints["x-canonical-private-menu-model"]
48 busNameHint: "busName"
49 actionsHint: "actions"
50 menuObjectPathHint: "menuPath"
51 }
53 UnityMenuModel {
54 id: unityMenuModel
56 busName: paths.busName
57 actions: paths.actions
58 menuObjectPath: paths.menuObjectPath
59 }
61 Behavior on implicitHeight {
62 id: heightBehavior
64 enabled: false
65 UbuntuNumberAnimation {
66 duration: UbuntuAnimation.SnapDuration
67 }
68 }
70 // delay enabling height behavior until the add transition is complete
71 onOpacityChanged: if (opacity == 1) heightBehavior.enabled = true
73 MouseArea {
74 id: interactiveArea
76 anchors.fill: contentColumn
77 objectName: "interactiveArea"
78 enabled: notification.type == Notification.Interactive
79 onClicked: notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
80 }
82 Column {
83 id: contentColumn
85 anchors {
86 left: parent.left
87 right: parent.right
88 top: parent.top
89 margins: spacing
90 }
92 spacing: units.gu(1)
94 Row {
95 id: topRow
97 spacing: contentColumn.spacing
98 anchors {
99 left: parent.left
100 right: parent.right
101 }
103 UbuntuShape {
104 id: icon
106 objectName: "icon"
107 width: units.gu(6)
108 height: units.gu(6)
109 visible: iconSource !== undefined && iconSource != ""
110 image: Image {
111 id: avatarIcon
113 fillMode: Image.PreserveAspectCrop
114 }
115 }
117 Image {
118 id: secondaryIcon
120 objectName: "secondaryIcon"
121 width: units.gu(2)
122 height: units.gu(2)
123 visible: source !== undefined && source != ""
124 fillMode: Image.PreserveAspectCrop
125 }
127 Column {
128 id: labelColumn
129 width: parent.width - x
131 Label {
132 id: summaryLabel
134 objectName: "summaryLabel"
135 anchors {
136 left: parent.left
137 right: parent.right
138 }
139 fontSize: "medium"
140 font.bold: true
141 color: Theme.palette.selected.backgroundText
142 elide: Text.ElideRight
143 }
145 Label {
146 id: bodyLabel
148 objectName: "bodyLabel"
149 anchors {
150 left: parent.left
151 right: parent.right
152 }
153 visible: body != ""
154 fontSize: "small"
155 color: Theme.palette.selected.backgroundText
156 opacity: 0.6
157 wrapMode: Text.WordWrap
158 maximumLineCount: 10
159 elide: Text.ElideRight
160 }
161 }
162 }
164 Column {
165 objectName: "dialogListView"
166 spacing: units.gu(2)
168 visible: count > 0
170 anchors.left: parent.left; anchors.right: parent.right
172 Repeater {
173 model: unityMenuModel
175 NotificationMenuItemFactory {
176 anchors.left: parent.left; anchors.right: parent.right
178 menuModel: unityMenuModel
179 menuData: model
180 menuIndex: index
181 }
182 }
183 }
185 Item {
186 id: buttonRow
188 objectName: "buttonRow"
189 anchors {
190 left: parent.left
191 right: parent.right
192 }
193 visible: notification.type == Notification.SnapDecision
194 height: units.gu(4)
196 property real buttonWidth: (width - contentColumn.spacing) / 2
197 property bool expanded
199 Button {
200 id: leftButton
202 objectName: "button1"
203 width: parent.expanded ? parent.width : parent.buttonWidth
204 anchors {
205 top: parent.top
206 bottom: parent.bottom
207 }
208 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 2 ? actionRepeater.itemAt(1).actionLabel : ""
209 gradient: UbuntuColors.greyGradient
210 onClicked: {
211 if (actionRepeater.count > 2) {
212 buttonRow.expanded = !buttonRow.expanded
213 } else {
214 notification.notification.invokeAction(actionRepeater.itemAt(1).actionId)
215 }
216 }
218 Behavior on width {
219 UbuntuNumberAnimation {
220 duration: UbuntuAnimation.SnapDuration
221 }
222 }
223 }
225 Button {
226 id: rightButton
228 objectName: "button0"
229 anchors {
230 left: leftButton.right
231 leftMargin: contentColumn.spacing
232 right: parent.right
233 }
234 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 1 ? actionRepeater.itemAt(0).actionLabel : ""
235 anchors {
236 top: parent.top
237 bottom: parent.bottom
238 }
239 gradient: notification.hints["x-canonical-private-button-tint"] == "true" ? UbuntuColors.orangeGradient : UbuntuColors.greyGradient
240 visible: width > 0
241 onClicked: notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
242 }
243 }
245 Column {
246 objectName: "buttonColumn"
247 spacing: contentColumn.spacing
248 anchors {
249 left: parent.left
250 right: parent.right
251 }
253 // calculate initial position before Column takes over
254 y: buttonRow.y + buttonRow.height + contentColumn.spacing
256 visible: notification.type == Notification.SnapDecision
257 height: buttonRow.expanded ? implicitHeight : 0
259 Repeater {
260 id: actionRepeater
262 model: notification.actions
263 delegate: Loader {
264 id: loader
266 property string actionId: id
267 property string actionLabel: label
269 anchors {
270 left: parent.left
271 right: parent.right
272 }
274 Component {
275 id: actionButton
277 Button {
278 objectName: "button" + index
279 anchors {
280 left: parent.left
281 right: parent.right
282 }
284 text: loader.actionLabel
285 height: units.gu(4)
286 gradient: UbuntuColors.greyGradient
287 onClicked: notification.notification.invokeAction(loader.actionId)
288 }
289 }
290 sourceComponent: (index == 0 || index == 1) ? undefined : actionButton
291 }
292 }
293 }
294 }