on 5b03213 help sign in
unity8/Notifications/Notification.qml
298 lines 9.1 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 UbuntuShape {
105 id: icon
107 objectName: "icon"
108 width: units.gu(6)
109 height: units.gu(6)
110 visible: iconSource !== undefined && iconSource != ""
111 image: Image {
112 id: avatarIcon
114 fillMode: Image.PreserveAspectCrop
115 }
116 }
118 Image {
119 id: secondaryIcon
121 objectName: "secondaryIcon"
122 width: units.gu(2)
123 height: units.gu(2)
124 visible: source !== undefined && source != ""
125 fillMode: Image.PreserveAspectCrop
126 }
128 Column {
129 id: labelColumn
130 width: parent.width - x
132 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
134 Label {
135 id: summaryLabel
137 objectName: "summaryLabel"
138 anchors {
139 left: parent.left
140 right: parent.right
141 }
142 fontSize: "medium"
143 font.bold: true
144 color: Theme.palette.selected.backgroundText
145 elide: Text.ElideRight
146 }
148 Label {
149 id: bodyLabel
151 objectName: "bodyLabel"
152 anchors {
153 left: parent.left
154 right: parent.right
155 }
156 visible: body != ""
157 fontSize: "small"
158 color: Theme.palette.selected.backgroundText
159 opacity: 0.6
160 wrapMode: Text.WordWrap
161 maximumLineCount: 10
162 elide: Text.ElideRight
163 }
164 }
165 }
167 Column {
168 objectName: "dialogListView"
169 spacing: units.gu(2)
171 visible: count > 0
173 anchors.left: parent.left; anchors.right: parent.right
175 Repeater {
176 model: unityMenuModel
178 NotificationMenuItemFactory {
179 anchors.left: parent.left; anchors.right: parent.right
181 menuModel: unityMenuModel
182 menuData: model
183 menuIndex: index
184 }
185 }
186 }
188 Item {
189 id: buttonRow
191 objectName: "buttonRow"
192 anchors {
193 left: parent.left
194 right: parent.right
195 }
196 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 0
197 height: units.gu(5)
199 property real buttonWidth: (width - contentColumn.spacing) / 2
200 property bool expanded
202 Button {
203 id: leftButton
205 objectName: "button1"
206 width: parent.expanded ? parent.width : parent.buttonWidth
207 anchors {
208 top: parent.top
209 bottom: parent.bottom
210 }
211 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 2 ? actionRepeater.itemAt(1).actionLabel : ""
212 gradient: UbuntuColors.greyGradient
213 onClicked: {
214 if (actionRepeater.count > 2) {
215 buttonRow.expanded = !buttonRow.expanded
216 } else {
217 notification.notification.invokeAction(actionRepeater.itemAt(1).actionId)
218 }
219 }
221 Behavior on width {
222 UbuntuNumberAnimation {
223 duration: UbuntuAnimation.SnapDuration
224 }
225 }
226 }
228 Button {
229 id: rightButton
231 objectName: "button0"
232 anchors {
233 left: leftButton.right
234 leftMargin: contentColumn.spacing
235 right: parent.right
236 }
237 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 1 ? actionRepeater.itemAt(0).actionLabel : ""
238 anchors {
239 top: parent.top
240 bottom: parent.bottom
241 }
242 gradient: notification.hints["x-canonical-private-button-tint"] == "true" ? UbuntuColors.orangeGradient : UbuntuColors.greyGradient
243 visible: width > 0
244 onClicked: notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
245 }
246 }
248 Column {
249 objectName: "buttonColumn"
250 spacing: contentColumn.spacing
251 anchors {
252 left: parent.left
253 right: parent.right
254 }
256 // calculate initial position before Column takes over
257 y: buttonRow.y + buttonRow.height + contentColumn.spacing
259 visible: notification.type == Notification.SnapDecision
260 height: buttonRow.expanded ? implicitHeight : 0
262 Repeater {
263 id: actionRepeater
265 model: notification.actions
266 delegate: Loader {
267 id: loader
269 property string actionId: id
270 property string actionLabel: label
272 anchors {
273 left: parent.left
274 right: parent.right
275 }
277 Component {
278 id: actionButton
280 Button {
281 objectName: "button" + index
282 anchors {
283 left: parent.left
284 right: parent.right
285 }
287 text: loader.actionLabel
288 height: units.gu(5)
289 gradient: UbuntuColors.greyGradient
290 onClicked: notification.notification.invokeAction(loader.actionId)
291 }
292 }
293 sourceComponent: (index == 0 || index == 1) ? undefined : actionButton
294 }
295 }
296 }
297 }