on 68f5dac help sign in
unity8/Notifications/Notification.qml
295 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: 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
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 ShapedIcon {
105 id: icon
107 objectName: "icon"
108 width: units.gu(6)
109 height: units.gu(6)
110 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
111 visible: iconSource !== undefined && iconSource != ""
112 }
114 Image {
115 id: secondaryIcon
117 objectName: "secondaryIcon"
118 width: units.gu(2)
119 height: units.gu(2)
120 visible: source !== undefined && source != ""
121 fillMode: Image.PreserveAspectCrop
122 }
124 Column {
125 id: labelColumn
126 width: parent.width - x
128 //anchors.verticalCenter: ((icon.visible || noShapeIcon.visible) && !bodyLabel.visible) ? (icon.visible ? icon.verticalCenter : noShapeIcon.verticalCenter) : undefined
129 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
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(5)
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(5)
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 }