on ba54ecc help sign in
unity8/Notifications/Notification.qml
299 lines 9.2 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: type != Notification.PlaceHolder ? contentColumn.height + contentColumn.spacing * 2 : 0
38 color: Qt.rgba(0.132, 0.117, 0.109, 0.97)
39 opacity: 0
40 radius: "medium"
42 clip: true
43 visible: type != Notification.PlaceHolder
45 UnityMenuModelPaths {
46 id: paths
48 source: hints["x-canonical-private-menu-model"]
50 busNameHint: "busName"
51 actionsHint: "actions"
52 menuObjectPathHint: "menuPath"
53 }
55 UnityMenuModel {
56 id: unityMenuModel
58 busName: paths.busName
59 actions: paths.actions
60 menuObjectPath: paths.menuObjectPath
61 }
63 Behavior on implicitHeight {
64 id: heightBehavior
66 enabled: false
67 UbuntuNumberAnimation {
68 duration: UbuntuAnimation.SnapDuration
69 }
70 }
72 // delay enabling height behavior until the add transition is complete
73 onOpacityChanged: if (opacity == 1) heightBehavior.enabled = true
75 MouseArea {
76 id: interactiveArea
78 anchors.fill: contentColumn
79 objectName: "interactiveArea"
80 enabled: notification.type == Notification.Interactive
81 onClicked: notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
82 }
84 Column {
85 id: contentColumn
87 anchors {
88 left: parent.left
89 right: parent.right
90 top: parent.top
91 margins: spacing
92 }
94 spacing: units.gu(1)
96 Row {
97 id: topRow
99 spacing: contentColumn.spacing
100 anchors {
101 left: parent.left
102 right: parent.right
103 }
105 UbuntuShape {
106 id: icon
108 objectName: "icon"
109 width: units.gu(6)
110 height: units.gu(6)
111 visible: iconSource !== undefined && iconSource != ""
112 image: Image {
113 id: avatarIcon
115 fillMode: Image.PreserveAspectCrop
116 }
117 }
119 Image {
120 id: secondaryIcon
122 objectName: "secondaryIcon"
123 width: units.gu(2)
124 height: units.gu(2)
125 visible: source !== undefined && source != ""
126 fillMode: Image.PreserveAspectCrop
127 }
129 Column {
130 id: labelColumn
131 width: parent.width - x
133 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
135 Label {
136 id: summaryLabel
138 objectName: "summaryLabel"
139 anchors {
140 left: parent.left
141 right: parent.right
142 }
143 fontSize: "medium"
144 font.bold: true
145 color: Theme.palette.selected.backgroundText
146 elide: Text.ElideRight
147 }
149 Label {
150 id: bodyLabel
152 objectName: "bodyLabel"
153 anchors {
154 left: parent.left
155 right: parent.right
156 }
157 visible: body != ""
158 fontSize: "small"
159 color: Theme.palette.selected.backgroundText
160 opacity: 0.6
161 wrapMode: Text.WordWrap
162 maximumLineCount: 10
163 elide: Text.ElideRight
164 }
165 }
166 }
168 Column {
169 objectName: "dialogListView"
170 spacing: units.gu(2)
172 visible: count > 0
174 anchors.left: parent.left; anchors.right: parent.right
176 Repeater {
177 model: unityMenuModel
179 NotificationMenuItemFactory {
180 anchors.left: parent.left; anchors.right: parent.right
182 menuModel: unityMenuModel
183 menuData: model
184 menuIndex: index
185 }
186 }
187 }
189 Item {
190 id: buttonRow
192 objectName: "buttonRow"
193 anchors {
194 left: parent.left
195 right: parent.right
196 }
197 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 0
198 height: units.gu(5)
200 property real buttonWidth: (width - contentColumn.spacing) / 2
201 property bool expanded
203 Button {
204 id: leftButton
206 objectName: "button1"
207 width: parent.expanded ? parent.width : parent.buttonWidth
208 anchors {
209 top: parent.top
210 bottom: parent.bottom
211 }
212 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 2 ? actionRepeater.itemAt(1).actionLabel : ""
213 gradient: UbuntuColors.greyGradient
214 onClicked: {
215 if (actionRepeater.count > 2) {
216 buttonRow.expanded = !buttonRow.expanded
217 } else {
218 notification.notification.invokeAction(actionRepeater.itemAt(1).actionId)
219 }
220 }
222 Behavior on width {
223 UbuntuNumberAnimation {
224 duration: UbuntuAnimation.SnapDuration
225 }
226 }
227 }
229 Button {
230 id: rightButton
232 objectName: "button0"
233 anchors {
234 left: leftButton.right
235 leftMargin: contentColumn.spacing
236 right: parent.right
237 }
238 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 1 ? actionRepeater.itemAt(0).actionLabel : ""
239 anchors {
240 top: parent.top
241 bottom: parent.bottom
242 }
243 gradient: notification.hints["x-canonical-private-button-tint"] == "true" ? UbuntuColors.orangeGradient : UbuntuColors.greyGradient
244 visible: width > 0
245 onClicked: notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
246 }
247 }
249 Column {
250 objectName: "buttonColumn"
251 spacing: contentColumn.spacing
252 anchors {
253 left: parent.left
254 right: parent.right
255 }
257 // calculate initial position before Column takes over
258 y: buttonRow.y + buttonRow.height + contentColumn.spacing
260 visible: notification.type == Notification.SnapDecision
261 height: buttonRow.expanded ? implicitHeight : 0
263 Repeater {
264 id: actionRepeater
266 model: notification.actions
267 delegate: Loader {
268 id: loader
270 property string actionId: id
271 property string actionLabel: label
273 anchors {
274 left: parent.left
275 right: parent.right
276 }
278 Component {
279 id: actionButton
281 Button {
282 objectName: "button" + index
283 anchors {
284 left: parent.left
285 right: parent.right
286 }
288 text: loader.actionLabel
289 height: units.gu(5)
290 gradient: UbuntuColors.greyGradient
291 onClicked: notification.notification.invokeAction(loader.actionId)
292 }
293 }
294 sourceComponent: (index == 0 || index == 1) ? undefined : actionButton
295 }
296 }
297 }
298 }