on xenial help sign in
all notifications closable, perform secondary action upon closing/swiping away
a9709b7Lukáš Tinkl
qml/Notifications/Notification.qml+13−7
@@ -40,7 +40,6 @@ StyledItem {
40 property bool fullscreen: false
40 property bool fullscreen: false
41 property int maxHeight
41 property int maxHeight
42 property int margins: units.gu(1)
42 property int margins: units.gu(1)
43− readonly property bool draggable: type !== Notification.SnapDecision || state === "contracted"
44
43
45 readonly property real defaultOpacity: 1.0
44 readonly property real defaultOpacity: 1.0
46 property bool hasMouse
45 property bool hasMouse
@@ -99,8 +98,14 @@ StyledItem {
99 }
98 }
100 }
99 }
101
100
101+ function closeNotification() {
102+ if (notification.actions.count > 1) { // perform the "reject" action
103+ notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId));
104+ }
105+ notification.notification.close();
106+ }
107+
102 Behavior on x {
108 Behavior on x {
103− enabled: draggable
104 UbuntuNumberAnimation { easing.type: Easing.OutBounce }
109 UbuntuNumberAnimation { easing.type: Easing.OutBounce }
105 }
110 }
106
111
@@ -153,8 +158,8 @@ StyledItem {
153 }
158 }
154
159
155 onXChanged: {
160 onXChanged: {
156− if (draggable && Math.abs(notification.x) > 0.75 * notification.width) {
161+ if (Math.abs(notification.x) > 0.75 * notification.width) {
157− notification.notification.close()
162+ closeNotification();
158 }
163 }
159 }
164 }
160
165
@@ -194,7 +199,7 @@ StyledItem {
194 anchors.fill: parent
199 anchors.fill: parent
195 objectName: "interactiveArea"
200 objectName: "interactiveArea"
196
201
197− drag.target: draggable ? notification : undefined
202+ drag.target: notification
198 drag.axis: Drag.XAxis
203 drag.axis: Drag.XAxis
199 drag.minimumX: -notification.width
204 drag.minimumX: -notification.width
200 drag.maximumX: notification.width
205 drag.maximumX: notification.width
@@ -221,16 +226,17 @@ StyledItem {
221 width: units.gu(2)
226 width: units.gu(2)
222 height: width
227 height: width
223 radius: width / 2
228 radius: width / 2
224− visible: hasMouse && draggable && (containsMouse || interactiveArea.containsMouse)
229+ visible: hasMouse && (containsMouse || interactiveArea.containsMouse)
225 iconName: "close"
230 iconName: "close"
226 outline: false
231 outline: false
232+ hoverEnabled: true
227 color: theme.palette.normal.negative
233 color: theme.palette.normal.negative
228 anchors.horizontalCenter: parent.left
234 anchors.horizontalCenter: parent.left
229 anchors.horizontalCenterOffset: notification.parent.state === "narrow" ? notification.margins / 2 : 0
235 anchors.horizontalCenterOffset: notification.parent.state === "narrow" ? notification.margins / 2 : 0
230 anchors.verticalCenter: parent.top
236 anchors.verticalCenter: parent.top
231 anchors.verticalCenterOffset: notification.parent.state === "narrow" ? notification.margins / 2 : 0
237 anchors.verticalCenterOffset: notification.parent.state === "narrow" ? notification.margins / 2 : 0
232
238
233− onClicked: notification.notification.close()
239+ onClicked: closeNotification();
234 }
240 }
235
241
236 Column {
242 Column {
qml/Notifications/NotificationButton.qml+2−1
@@ -30,13 +30,14 @@ Rectangle {
30 property bool outline: true
30 property bool outline: true
31 property alias text: label.text
31 property alias text: label.text
32 property alias iconName: icon.name
32 property alias iconName: icon.name
33+ property bool hoverEnabled: false
33
34
34 signal clicked()
35 signal clicked()
35
36
36 AbstractButton {
37 AbstractButton {
37 id: button
38 id: button
38 anchors.fill: root
39 anchors.fill: root
39− __mouseArea.hoverEnabled: false
40+ __mouseArea.hoverEnabled: root.hoverEnabled
40 onClicked: root.clicked()
41 onClicked: root.clicked()
41
42
42 Label {
43 Label {