on xenial help sign in
implement the close button
commit0d3ddc2f710b95023d9280ad9e83b912ba260b40 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateThu 7 Apr 2016, 22:05 (11 years ago) parent5b58aba
6 files changed+45−9
qml/Notifications/Notification.qml+17−3 qml/Notifications/NotificationButton.qml+4−1 qml/Notifications/Notifications.qml−1 tests/qmltests/Notifications/tst_Notifications.qml+5−1 tests/qmltests/Notifications/tst_OptionToggle.qml+9−1 tests/qmltests/Notifications/tst_SwipeToAct.qml+10−2
qml/Notifications/Notification.qml+17−3
@@ -43,7 +43,6 @@ StyledItem {
4343 readonly property bool draggable: (type === Notification.SnapDecision && state === "contracted") ||
4444 type === Notification.Interactive ||
4545 type === Notification.Ephemeral
46− readonly property bool canBeClosed: type === Notification.Ephemeral
4746 readonly property real defaultOpacity: 0.95
4847 property bool hasMouse
4948 property url background: ""
@@ -136,6 +135,8 @@ StyledItem {
136135 visible: !fullscreen
137136 anchors {
138137 fill: parent
138+ leftMargin: notification.margins
139+ rightMargin: notification.margins
139140 }
140141 backgroundColor: parent.color
141142 radius: "small"
@@ -196,12 +197,11 @@ StyledItem {
196197 drag.axis: Drag.XAxis
197198 drag.minimumX: -notification.width
198199 drag.maximumX: notification.width
200+ hoverEnabled: true
199201
200202 onClicked: {
201203 if (notification.type === Notification.Interactive) {
202204 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
203− } else if (hasMouse && canBeClosed) {
204− notification.notification.close()
205205 } else {
206206 notificationList.currentIndex = index;
207207 }
@@ -215,6 +215,20 @@ StyledItem {
215215 }
216216 }
217217
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+
218232 Column {
219233 id: outterColumn
220234 objectName: "outterColumn"
qml/Notifications/NotificationButton.qml+4−1
@@ -25,6 +25,9 @@ Rectangle {
2525 border.width: outline ? units.dp(1) : 0
2626 border.color: outline ? theme.palette.normal.base : "transparent"
2727
28+ // to be read from outside
29+ readonly property bool containsMouse: button.__mouseArea.containsMouse
30+
2831 // to be set from outside
2932 property bool outline: true
3033 property alias text: label.text
@@ -48,7 +51,7 @@ Rectangle {
4851
4952 Icon {
5053 id: icon
51− height: units.gu(3)
54+ height: root.height * 2 / 3
5255 width: height
5356 anchors.centerIn: parent
5457 color: "white"
qml/Notifications/Notifications.qml−1
@@ -27,7 +27,6 @@ ListView {
2727 interactive: false
2828
2929 property real margin
30− property bool useModal: snapDecisionProxyModel.count > 0
3130 property bool hasMouse
3231 property url background: ""
3332
tests/qmltests/Notifications/tst_Notifications.qml+5−1
@@ -186,7 +186,6 @@ Item {
186186 margin: units.gu(1)
187187
188188 anchors.fill: parent
189− anchors.margins: units.gu(1)
190189 model: mockModel
191190 hasMouse: fakeMouseCB.checked
192191 }
@@ -268,6 +267,11 @@ Item {
268267 anchors.verticalCenter: parent.verticalCenter
269268 }
270269 }
270+
271+ MouseTouchEmulationCheckbox {
272+ id: mouseEmulation
273+ checked: false
274+ }
271275 }
272276 }
273277
tests/qmltests/Notifications/tst_OptionToggle.qml+9−1
@@ -36,6 +36,10 @@ Row {
3636 console.log("Action invoked", actionId);
3737 mockModel.actionInvoked(actionId)
3838 }
39+
40+ function close() {
41+ console.log("Close notification");
42+ }
3943 }
4044 }
4145
@@ -110,7 +114,6 @@ Row {
110114 margin: units.gu(1)
111115
112116 anchors.fill: parent
113− anchors.margins: units.gu(1)
114117 model: mockModel
115118 }
116119 }
@@ -144,6 +147,11 @@ Row {
144147 text: "clear model"
145148 onClicked: clearNotifications()
146149 }
150+
151+ MouseTouchEmulationCheckbox {
152+ id: mouseEmulation
153+ checked: false
154+ }
147155 }
148156 }
149157
tests/qmltests/Notifications/tst_SwipeToAct.qml+10−2
@@ -35,7 +35,11 @@ Item {
3535
3636 QtObject {
3737 function invokeAction(actionId) {
38− mockModel.actionInvoked(actionId)
38+ mockModel.actionInvoked(actionId);
39+ }
40+
41+ function close() {
42+ console.log("Close notification");
3943 }
4044 }
4145 }
@@ -110,7 +114,6 @@ Item {
110114 margin: units.gu(1)
111115
112116 anchors.fill: parent
113− anchors.margins: units.gu(1)
114117 model: mockModel
115118 hasMouse: false
116119 }
@@ -163,6 +166,11 @@ Item {
163166 anchors.verticalCenter: parent.verticalCenter
164167 }
165168 }
169+
170+ MouseTouchEmulationCheckbox {
171+ id: mouseEmulation
172+ checked: false
173+ }
166174 }
167175 }
168176