on 7cd287d help sign in
unity8/Notifications/Notification.qml
295 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: 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: 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 ShapedIcon {
106 id: icon
108 objectName: "icon"
109 width: units.gu(6)
110 height: units.gu(6)
111 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
112 visible: iconSource !== undefined && iconSource != ""
113 }
115 Image {
116 id: secondaryIcon
118 objectName: "secondaryIcon"
119 width: units.gu(2)
120 height: units.gu(2)
121 visible: source !== undefined && source != ""
122 fillMode: Image.PreserveAspectCrop
123 }
125 Column {
126 id: labelColumn
127 width: parent.width - x
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 && actionRepeater.count > 0
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 }