on xenial help sign in
implement the close button
0d3ddc2Lukáš Tinkl
qml/Notifications/Notification.qml+17−3
@@ -43,7 +43,6 @@ StyledItem {
43 readonly property bool draggable: (type === Notification.SnapDecision && state === "contracted") ||
43 readonly property bool draggable: (type === Notification.SnapDecision && state === "contracted") ||
44 type === Notification.Interactive ||
44 type === Notification.Interactive ||
45 type === Notification.Ephemeral
45 type === Notification.Ephemeral
46− readonly property bool canBeClosed: type === Notification.Ephemeral
47 readonly property real defaultOpacity: 0.95
46 readonly property real defaultOpacity: 0.95
48 property bool hasMouse
47 property bool hasMouse
49 property url background: ""
48 property url background: ""
@@ -136,6 +135,8 @@ StyledItem {
136 visible: !fullscreen
135 visible: !fullscreen
137 anchors {
136 anchors {
138 fill: parent
137 fill: parent
138+ leftMargin: notification.margins
139+ rightMargin: notification.margins
139 }
140 }
140 backgroundColor: parent.color
141 backgroundColor: parent.color
141 radius: "small"
142 radius: "small"
@@ -196,12 +197,11 @@ StyledItem {
196 drag.axis: Drag.XAxis
197 drag.axis: Drag.XAxis
197 drag.minimumX: -notification.width
198 drag.minimumX: -notification.width
198 drag.maximumX: notification.width
199 drag.maximumX: notification.width
200+ hoverEnabled: true
199
201
200 onClicked: {
202 onClicked: {
201 if (notification.type === Notification.Interactive) {
203 if (notification.type === Notification.Interactive) {
202 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
204 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
203− } else if (hasMouse && canBeClosed) {
204− notification.notification.close()
205 } else {
205 } else {
206 notificationList.currentIndex = index;
206 notificationList.currentIndex = index;
207 }
207 }
@@ -215,6 +215,20 @@ StyledItem {
215 }
215 }
216 }
216 }
217
217
218+ NotificationButton {
219+ width: units.gu(2)
220+ height: width
221+ radius: width / 2
222+ visible: draggable && (containsMouse || interactiveArea.containsMouse)
223+ iconName: "close"
224+ outline: false
225+ color: theme.palette.normal.negative
226+ anchors.horizontalCenter: parent.left
227+ anchors.verticalCenter: parent.top
228+
229+ onClicked: notification.notification.close()
230+ }
231+
218 Column {
232 Column {
219 id: outterColumn
233 id: outterColumn
220 objectName: "outterColumn"
234 objectName: "outterColumn"
qml/Notifications/NotificationButton.qml+4−1
@@ -25,6 +25,9 @@ Rectangle {
25 border.width: outline ? units.dp(1) : 0
25 border.width: outline ? units.dp(1) : 0
26 border.color: outline ? theme.palette.normal.base : "transparent"
26 border.color: outline ? theme.palette.normal.base : "transparent"
27
27
28+ // to be read from outside
29+ readonly property bool containsMouse: button.__mouseArea.containsMouse
30+
28 // to be set from outside
31 // to be set from outside
29 property bool outline: true
32 property bool outline: true
30 property alias text: label.text
33 property alias text: label.text
@@ -48,7 +51,7 @@ Rectangle {
48
51
49 Icon {
52 Icon {
50 id: icon
53 id: icon
51− height: units.gu(3)
54+ height: root.height * 2 / 3
52 width: height
55 width: height
53 anchors.centerIn: parent
56 anchors.centerIn: parent
54 color: "white"
57 color: "white"
qml/Notifications/Notifications.qml−1
@@ -27,7 +27,6 @@ ListView {
27 interactive: false
27 interactive: false
28
28
29 property real margin
29 property real margin
30− property bool useModal: snapDecisionProxyModel.count > 0
31 property bool hasMouse
30 property bool hasMouse
32 property url background: ""
31 property url background: ""
33
32
tests/qmltests/Notifications/tst_Notifications.qml+5−1
@@ -186,7 +186,6 @@ Item {
186 margin: units.gu(1)
186 margin: units.gu(1)
187
187
188 anchors.fill: parent
188 anchors.fill: parent
189− anchors.margins: units.gu(1)
190 model: mockModel
189 model: mockModel
191 hasMouse: fakeMouseCB.checked
190 hasMouse: fakeMouseCB.checked
192 }
191 }
@@ -268,6 +267,11 @@ Item {
268 anchors.verticalCenter: parent.verticalCenter
267 anchors.verticalCenter: parent.verticalCenter
269 }
268 }
270 }
269 }
270+
271+ MouseTouchEmulationCheckbox {
272+ id: mouseEmulation
273+ checked: false
274+ }
271 }
275 }
272 }
276 }
273
277
tests/qmltests/Notifications/tst_OptionToggle.qml+9−1
@@ -36,6 +36,10 @@ Row {
36 console.log("Action invoked", actionId);
36 console.log("Action invoked", actionId);
37 mockModel.actionInvoked(actionId)
37 mockModel.actionInvoked(actionId)
38 }
38 }
39+
40+ function close() {
41+ console.log("Close notification");
42+ }
39 }
43 }
40 }
44 }
41
45
@@ -110,7 +114,6 @@ Row {
110 margin: units.gu(1)
114 margin: units.gu(1)
111
115
112 anchors.fill: parent
116 anchors.fill: parent
113− anchors.margins: units.gu(1)
114 model: mockModel
117 model: mockModel
115 }
118 }
116 }
119 }
@@ -144,6 +147,11 @@ Row {
144 text: "clear model"
147 text: "clear model"
145 onClicked: clearNotifications()
148 onClicked: clearNotifications()
146 }
149 }
150+
151+ MouseTouchEmulationCheckbox {
152+ id: mouseEmulation
153+ checked: false
154+ }
147 }
155 }
148 }
156 }
149
157
tests/qmltests/Notifications/tst_SwipeToAct.qml+10−2
@@ -35,7 +35,11 @@ Item {
35
35
36 QtObject {
36 QtObject {
37 function invokeAction(actionId) {
37 function invokeAction(actionId) {
38− mockModel.actionInvoked(actionId)
38+ mockModel.actionInvoked(actionId);
39+ }
40+
41+ function close() {
42+ console.log("Close notification");
39 }
43 }
40 }
44 }
41 }
45 }
@@ -110,7 +114,6 @@ Item {
110 margin: units.gu(1)
114 margin: units.gu(1)
111
115
112 anchors.fill: parent
116 anchors.fill: parent
113− anchors.margins: units.gu(1)
114 model: mockModel
117 model: mockModel
115 hasMouse: false
118 hasMouse: false
116 }
119 }
@@ -163,6 +166,11 @@ Item {
163 anchors.verticalCenter: parent.verticalCenter
166 anchors.verticalCenter: parent.verticalCenter
164 }
167 }
165 }
168 }
169+
170+ MouseTouchEmulationCheckbox {
171+ id: mouseEmulation
172+ checked: false
173+ }
166 }
174 }
167 }
175 }
168
176