on 9db4f20 help sign in
unity8/Notifications/Notification.qml
253 lines 7.7 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
21UbuntuShape {
22 id: notification
24 property alias iconSource: avatarIcon.source
25 property alias secondaryIconSource: secondaryIcon.source
26 property alias summary: summaryLabel.text
27 property alias body: bodyLabel.text
28 property var actions
29 property var notificationId
30 property var type
31 property var notification
33 objectName: "background"
34 implicitHeight: contentColumn.height + contentColumn.spacing * 2
35 color: Qt.rgba(0, 0, 0, 0.85)
36 opacity: 0
38 clip: true
40 Behavior on implicitHeight {
41 id: heightBehavior
43 enabled: false
44 UbuntuNumberAnimation {
45 duration: UbuntuAnimation.SnapDuration
46 }
47 }
49 // delay enabling height behavior until the add transition is complete
50 onOpacityChanged: if (opacity == 1) heightBehavior.enabled = true
52 MouseArea {
53 id: interactiveArea
55 anchors.fill: contentColumn
56 objectName: "interactiveArea"
57 enabled: notification.type == Notification.Interactive
58 onClicked: notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
59 }
61 Column {
62 id: contentColumn
64 anchors {
65 left: parent.left
66 right: parent.right
67 top: parent.top
68 margins: spacing
69 }
71 spacing: units.gu(1)
73 Row {
74 id: topRow
76 spacing: contentColumn.spacing
77 anchors {
78 left: parent.left
79 right: parent.right
80 }
82 UbuntuShape {
83 id: icon
85 objectName: "icon"
86 width: units.gu(6)
87 height: units.gu(6)
88 visible: iconSource !== undefined && iconSource != ""
89 image: Image {
90 id: avatarIcon
92 fillMode: Image.PreserveAspectCrop
93 }
94 }
96 Image {
97 id: secondaryIcon
99 objectName: "secondaryIcon"
100 width: units.gu(2)
101 height: units.gu(2)
102 visible: source !== undefined && source != ""
103 fillMode: Image.PreserveAspectCrop
104 }
106 Column {
107 id: labelColumn
108 width: parent.width - x
110 Label {
111 id: summaryLabel
113 objectName: "summaryLabel"
114 anchors {
115 left: parent.left
116 right: parent.right
117 }
118 fontSize: "medium"
119 font.bold: true
120 color: "#f3f3e7"
121 elide: Text.ElideRight
122 }
124 Label {
125 id: bodyLabel
127 objectName: "bodyLabel"
128 anchors {
129 left: parent.left
130 right: parent.right
131 }
132 visible: body != ""
133 fontSize: "small"
134 color: "#f3f3e7"
135 opacity: 0.6
136 wrapMode: Text.WordWrap
137 maximumLineCount: 10
138 elide: Text.ElideRight
139 }
140 }
141 }
143 Item {
144 id: buttonRow
146 objectName: "buttonRow"
147 anchors {
148 left: parent.left
149 right: parent.right
150 }
151 visible: notification.type == Notification.SnapDecision
152 height: units.gu(4)
154 property real buttonWidth: (width - contentColumn.spacing) / 2
155 property bool expanded
157 Button {
158 id: leftButton
160 objectName: "button1"
161 width: parent.expanded ? parent.width : parent.buttonWidth
162 anchors {
163 top: parent.top
164 bottom: parent.bottom
165 }
166 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 2 ? actionRepeater.itemAt(1).actionLabel : ""
167 color: "#cdcdcb"
168 onClicked: {
169 if (actionRepeater.count > 2) {
170 buttonRow.expanded = !buttonRow.expanded
171 } else {
172 notification.notification.invokeAction(actionRepeater.itemAt(1).actionId)
173 }
174 }
176 Behavior on width {
177 UbuntuNumberAnimation {
178 duration: UbuntuAnimation.SnapDuration
179 }
180 }
181 }
183 Button {
184 id: rightButton
186 objectName: "button0"
187 anchors {
188 left: leftButton.right
189 leftMargin: contentColumn.spacing
190 right: parent.right
191 }
192 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 1 ? actionRepeater.itemAt(0).actionLabel : ""
193 anchors {
194 top: parent.top
195 bottom: parent.bottom
196 }
197 color: "#d85317"
198 visible: width > 0
199 onClicked: notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
200 }
201 }
203 Column {
204 objectName: "buttonColumn"
205 spacing: contentColumn.spacing
206 anchors {
207 left: parent.left
208 right: parent.right
209 }
211 // calculate initial position before Column takes over
212 y: buttonRow.y + buttonRow.height + contentColumn.spacing
214 visible: notification.type == Notification.SnapDecision
215 height: buttonRow.expanded ? implicitHeight : 0
217 Repeater {
218 id: actionRepeater
220 model: notification.actions
221 delegate: Loader {
222 id: loader
224 property string actionId: id
225 property string actionLabel: label
227 anchors {
228 left: parent.left
229 right: parent.right
230 }
232 Component {
233 id: actionButton
235 Button {
236 objectName: "button" + index
237 anchors {
238 left: parent.left
239 right: parent.right
240 }
242 text: loader.actionLabel
243 height: units.gu(4)
244 color: "#cdcdcb"
245 onClicked: notification.notification.invokeAction(loader.actionId)
246 }
247 }
248 sourceComponent: (index == 0 || index == 1) ? undefined : actionButton
249 }
250 }
251 }
252 }