on xenial help sign in
all notifications closable, perform secondary action upon closing/swiping away
commita9709b77f1b8bd369264514692ed0ecee85a1770 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateMon 11 Apr 2016, 18:36 (11 years ago) parent147c2d3
2 files changed+15−8
qml/Notifications/Notification.qml+13−7 qml/Notifications/NotificationButton.qml+2−1
qml/Notifications/Notification.qml+13−7
@@ -40,7 +40,6 @@ StyledItem {
4040 property bool fullscreen: false
4141 property int maxHeight
4242 property int margins: units.gu(1)
43− readonly property bool draggable: type !== Notification.SnapDecision || state === "contracted"
4443
4544 readonly property real defaultOpacity: 1.0
4645 property bool hasMouse
@@ -99,8 +98,14 @@ StyledItem {
9998 }
10099 }
101100
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+
102108 Behavior on x {
103− enabled: draggable
104109 UbuntuNumberAnimation { easing.type: Easing.OutBounce }
105110 }
106111
@@ -153,8 +158,8 @@ StyledItem {
153158 }
154159
155160 onXChanged: {
156− if (draggable && Math.abs(notification.x) > 0.75 * notification.width) {
157− notification.notification.close()
161+ if (Math.abs(notification.x) > 0.75 * notification.width) {
162+ closeNotification();
158163 }
159164 }
160165
@@ -194,7 +199,7 @@ StyledItem {
194199 anchors.fill: parent
195200 objectName: "interactiveArea"
196201
197− drag.target: draggable ? notification : undefined
202+ drag.target: notification
198203 drag.axis: Drag.XAxis
199204 drag.minimumX: -notification.width
200205 drag.maximumX: notification.width
@@ -221,16 +226,17 @@ StyledItem {
221226 width: units.gu(2)
222227 height: width
223228 radius: width / 2
224− visible: hasMouse && draggable && (containsMouse || interactiveArea.containsMouse)
229+ visible: hasMouse && (containsMouse || interactiveArea.containsMouse)
225230 iconName: "close"
226231 outline: false
232+ hoverEnabled: true
227233 color: theme.palette.normal.negative
228234 anchors.horizontalCenter: parent.left
229235 anchors.horizontalCenterOffset: notification.parent.state === "narrow" ? notification.margins / 2 : 0
230236 anchors.verticalCenter: parent.top
231237 anchors.verticalCenterOffset: notification.parent.state === "narrow" ? notification.margins / 2 : 0
232238
233− onClicked: notification.notification.close()
239+ onClicked: closeNotification();
234240 }
235241
236242 Column {
qml/Notifications/NotificationButton.qml+2−1
@@ -30,13 +30,14 @@ Rectangle {
3030 property bool outline: true
3131 property alias text: label.text
3232 property alias iconName: icon.name
33+ property bool hoverEnabled: false
3334
3435 signal clicked()
3536
3637 AbstractButton {
3738 id: button
3839 anchors.fill: root
39− __mouseArea.hoverEnabled: false
40+ __mouseArea.hoverEnabled: root.hoverEnabled
4041 onClicked: root.clicked()
4142
4243 Label {