on 5bc8421 help sign in
unity8/Notifications/Notification.qml
254 lines 8.0 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 hints
32 property var notification
34 objectName: "background"
35 implicitHeight: contentColumn.height + contentColumn.spacing * 2
36 color: Qt.rgba(0, 0, 0, 0.85)
37 opacity: 0
39 clip: true
41 Behavior on implicitHeight {
42 id: heightBehavior
44 enabled: false
45 UbuntuNumberAnimation {
46 duration: UbuntuAnimation.SnapDuration
47 }
48 }
50 // delay enabling height behavior until the add transition is complete
51 onOpacityChanged: if (opacity == 1) heightBehavior.enabled = true
53 MouseArea {
54 id: interactiveArea
56 anchors.fill: contentColumn
57 objectName: "interactiveArea"
58 enabled: notification.type == Notification.Interactive
59 onClicked: notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
60 }
62 Column {
63 id: contentColumn
65 anchors {
66 left: parent.left
67 right: parent.right
68 top: parent.top
69 margins: spacing
70 }
72 spacing: units.gu(1)
74 Row {
75 id: topRow
77 spacing: contentColumn.spacing
78 anchors {
79 left: parent.left
80 right: parent.right
81 }
83 UbuntuShape {
84 id: icon
86 objectName: "icon"
87 width: units.gu(6)
88 height: units.gu(6)
89 visible: iconSource !== undefined && iconSource != ""
90 image: Image {
91 id: avatarIcon
93 fillMode: Image.PreserveAspectCrop
94 }
95 }
97 Image {
98 id: secondaryIcon
100 objectName: "secondaryIcon"
101 width: units.gu(2)
102 height: units.gu(2)
103 visible: source !== undefined && source != ""
104 fillMode: Image.PreserveAspectCrop
105 }
107 Column {
108 id: labelColumn
109 width: parent.width - x
111 Label {
112 id: summaryLabel
114 objectName: "summaryLabel"
115 anchors {
116 left: parent.left
117 right: parent.right
118 }
119 fontSize: "medium"
120 font.bold: true
121 color: Theme.palette.selected.backgroundText
122 elide: Text.ElideRight
123 }
125 Label {
126 id: bodyLabel
128 objectName: "bodyLabel"
129 anchors {
130 left: parent.left
131 right: parent.right
132 }
133 visible: body != ""
134 fontSize: "small"
135 color: Theme.palette.selected.backgroundText
136 opacity: 0.6
137 wrapMode: Text.WordWrap
138 maximumLineCount: 10
139 elide: Text.ElideRight
140 }
141 }
142 }
144 Item {
145 id: buttonRow
147 objectName: "buttonRow"
148 anchors {
149 left: parent.left
150 right: parent.right
151 }
152 visible: notification.type == Notification.SnapDecision
153 height: units.gu(4)
155 property real buttonWidth: (width - contentColumn.spacing) / 2
156 property bool expanded
158 Button {
159 id: leftButton
161 objectName: "button1"
162 width: parent.expanded ? parent.width : parent.buttonWidth
163 anchors {
164 top: parent.top
165 bottom: parent.bottom
166 }
167 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 2 ? actionRepeater.itemAt(1).actionLabel : ""
168 gradient: UbuntuColors.greyGradient
169 onClicked: {
170 if (actionRepeater.count > 2) {
171 buttonRow.expanded = !buttonRow.expanded
172 } else {
173 notification.notification.invokeAction(actionRepeater.itemAt(1).actionId)
174 }
175 }
177 Behavior on width {
178 UbuntuNumberAnimation {
179 duration: UbuntuAnimation.SnapDuration
180 }
181 }
182 }
184 Button {
185 id: rightButton
187 objectName: "button0"
188 anchors {
189 left: leftButton.right
190 leftMargin: contentColumn.spacing
191 right: parent.right
192 }
193 text: notification.type == Notification.SnapDecision && actionRepeater.count >= 1 ? actionRepeater.itemAt(0).actionLabel : ""
194 anchors {
195 top: parent.top
196 bottom: parent.bottom
197 }
198 gradient: notification.hints == Notification.ButtonTint ? UbuntuColors.orangeGradient : UbuntuColors.greyGradient
199 visible: width > 0
200 onClicked: notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
201 }
202 }
204 Column {
205 objectName: "buttonColumn"
206 spacing: contentColumn.spacing
207 anchors {
208 left: parent.left
209 right: parent.right
210 }
212 // calculate initial position before Column takes over
213 y: buttonRow.y + buttonRow.height + contentColumn.spacing
215 visible: notification.type == Notification.SnapDecision
216 height: buttonRow.expanded ? implicitHeight : 0
218 Repeater {
219 id: actionRepeater
221 model: notification.actions
222 delegate: Loader {
223 id: loader
225 property string actionId: id
226 property string actionLabel: label
228 anchors {
229 left: parent.left
230 right: parent.right
231 }
233 Component {
234 id: actionButton
236 Button {
237 objectName: "button" + index
238 anchors {
239 left: parent.left
240 right: parent.right
241 }
243 text: loader.actionLabel
244 height: units.gu(4)
245 gradient: UbuntuColors.greyGradient
246 onClicked: notification.notification.invokeAction(loader.actionId)
247 }
248 }
249 sourceComponent: (index == 0 || index == 1) ? undefined : actionButton
250 }
251 }
252 }
253 }