on 6358d5e help sign in
unity8/Notifications/Notification.qml
296 lines 9.3 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 || noShapeIcon.visible) && !bodyLabel.visible) ? (icon.visible ? icon.verticalCenter : noShapeIcon.verticalCenter) : undefined
130 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
132 Label {
133 id: summaryLabel
135 objectName: "summaryLabel"
136 anchors {
137 left: parent.left
138 right: parent.right
139 }
140 fontSize: "medium"
141 font.bold: true
142 color: Theme.palette.selected.backgroundText
143 elide: Text.ElideRight
144 }
146 Label {
147 id: bodyLabel
149 objectName: "bodyLabel"
150 anchors {
151 left: parent.left
152 right: parent.right
153 }
154 visible: body != ""
155 fontSize: "small"
156 color: Theme.palette.selected.backgroundText
157 opacity: 0.6
158 wrapMode: Text.WordWrap
159 maximumLineCount: 10
160 elide: Text.ElideRight
161 }
162 }
163 }
165 Column {
166 objectName: "dialogListView"
167 spacing: units.gu(2)
169 visible: count > 0
171 anchors.left: parent.left; anchors.right: parent.right
173 Repeater {
174 model: unityMenuModel
176 NotificationMenuItemFactory {
177 anchors.left: parent.left; anchors.right: parent.right
179 menuModel: unityMenuModel
180 menuData: model
181 menuIndex: index
182 }
183 }
184 }
186 Item {
187 id: buttonRow
189 objectName: "buttonRow"
190 anchors {
191 left: parent.left
192 right: parent.right
193 }
194 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 0
195 height: units.gu(5)
197 property real buttonWidth: (width - contentColumn.spacing) / 2
198 property bool expanded
200 Button {
201 id: leftButton
203 objectName: "button1"
204 width: parent.expanded ? parent.width : parent.buttonWidth
205 anchors {
206 top: parent.top
207 bottom: parent.bottom
208 }
209 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 2 ? actionRepeater.itemAt(1).actionLabel : ""
210 gradient: UbuntuColors.greyGradient
211 onClicked: {
212 if (actionRepeater.count > 2) {
213 buttonRow.expanded = !buttonRow.expanded
214 } else {
215 notification.notification.invokeAction(actionRepeater.itemAt(1).actionId)
216 }
217 }
219 Behavior on width {
220 UbuntuNumberAnimation {
221 duration: UbuntuAnimation.SnapDuration
222 }
223 }
224 }
226 Button {
227 id: rightButton
229 objectName: "button0"
230 anchors {
231 left: leftButton.right
232 leftMargin: contentColumn.spacing
233 right: parent.right
234 }
235 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 1 ? actionRepeater.itemAt(0).actionLabel : ""
236 anchors {
237 top: parent.top
238 bottom: parent.bottom
239 }
240 gradient: notification.hints["x-canonical-private-button-tint"] == "true" ? UbuntuColors.orangeGradient : UbuntuColors.greyGradient
241 visible: width > 0
242 onClicked: notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
243 }
244 }
246 Column {
247 objectName: "buttonColumn"
248 spacing: contentColumn.spacing
249 anchors {
250 left: parent.left
251 right: parent.right
252 }
254 // calculate initial position before Column takes over
255 y: buttonRow.y + buttonRow.height + contentColumn.spacing
257 visible: notification.type == Notification.SnapDecision
258 height: buttonRow.expanded ? implicitHeight : 0
260 Repeater {
261 id: actionRepeater
263 model: notification.actions
264 delegate: Loader {
265 id: loader
267 property string actionId: id
268 property string actionLabel: label
270 anchors {
271 left: parent.left
272 right: parent.right
273 }
275 Component {
276 id: actionButton
278 Button {
279 objectName: "button" + index
280 anchors {
281 left: parent.left
282 right: parent.right
283 }
285 text: loader.actionLabel
286 height: units.gu(5)
287 gradient: UbuntuColors.greyGradient
288 onClicked: notification.notification.invokeAction(loader.actionId)
289 }
290 }
291 sourceComponent: (index == 0 || index == 1) ? undefined : actionButton
292 }
293 }
294 }
295 }