Changeset View
Changeset View
Standalone View
Standalone View
applets/notifications/package/contents/ui/NotificationItem.qml
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 30 | MouseArea { | |||
---|---|---|---|---|---|
50 | property alias configurable: settingsButton.visible | 50 | property alias configurable: settingsButton.visible | ||
51 | property var created | 51 | property var created | ||
52 | property var urls: [] | 52 | property var urls: [] | ||
53 | 53 | | |||
54 | property int maximumTextHeight: -1 | 54 | property int maximumTextHeight: -1 | ||
55 | 55 | | |||
56 | property ListModel actions: ListModel { } | 56 | property ListModel actions: ListModel { } | ||
57 | 57 | | |||
58 | property bool hasDefaultAction: false; | 58 | property bool hasDefaultAction: false | ||
59 | | ||||
60 | onClicked: { | ||||
61 | // the MEL would close the notification before the action button | ||||
62 | // onClicked handler would fire effectively breaking notification actions | ||||
63 | if (pressedAction()) { | ||||
64 | return | ||||
65 | } | ||||
66 | | ||||
67 | if (hasDefaultAction) { | ||||
68 | // the notifications was clicked, trigger the default action if set | ||||
69 | action("default") | ||||
70 | } | ||||
albertvaka: This is not the behaviour that was agreed here [1], we shouldn't close the notification if… | |||||
71 | } | ||||
59 | 72 | | |||
60 | function pressedAction() { | 73 | function pressedAction() { | ||
61 | for (var i = 0, count = actionRepeater.count; i < count; ++i) { | 74 | for (var i = 0, count = actionRepeater.count; i < count; ++i) { | ||
62 | var item = actionRepeater.itemAt(i) | 75 | var item = actionRepeater.itemAt(i) | ||
63 | if (item.pressed) { | 76 | if (item.pressed) { | ||
64 | return item | 77 | return item | ||
65 | } | 78 | } | ||
66 | } | 79 | } | ||
▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Line(s) | 229 | RowLayout { | |||
219 | spacing: units.smallSpacing | 232 | spacing: units.smallSpacing | ||
220 | 233 | | |||
221 | // Force the whole thing to collapse if the children are invisible | 234 | // Force the whole thing to collapse if the children are invisible | ||
222 | // If there is a big notification followed by a small one, the height | 235 | // If there is a big notification followed by a small one, the height | ||
223 | // of the popup does not always shrink back, so this forces it to | 236 | // of the popup does not always shrink back, so this forces it to | ||
224 | // height=0 when those are invisible. -1 means "default to implicitHeight" | 237 | // height=0 when those are invisible. -1 means "default to implicitHeight" | ||
225 | Layout.maximumHeight: bodyText.visible || actionsColumn.visible ? -1 : 0 | 238 | Layout.maximumHeight: bodyText.visible || actionsColumn.visible ? -1 : 0 | ||
226 | 239 | | |||
227 | MouseArea { | 240 | PlasmaExtras.ScrollArea { | ||
228 | id: contextMouseArea | 241 | id: bodyTextScrollArea | ||
229 | | ||||
230 | Layout.alignment: Qt.AlignTop | 242 | Layout.alignment: Qt.AlignTop | ||
231 | Layout.fillWidth: true | 243 | Layout.fillWidth: true | ||
232 | 244 | | |||
233 | implicitHeight: maximumTextHeight > 0 ? Math.min(maximumTextHeight, bodyText.paintedHeight) : bodyText.paintedHeight | 245 | implicitHeight: maximumTextHeight > 0 ? Math.min(maximumTextHeight, bodyText.paintedHeight) : bodyText.paintedHeight | ||
234 | | ||||
235 | acceptedButtons: Qt.RightButton | | |||
236 | preventStealing: true | | |||
237 | | ||||
238 | onPressed: contextMenu.open(mouse.x, mouse.y) | | |||
239 | | ||||
240 | PlasmaComponents.ContextMenu { | | |||
241 | id: contextMenu | | |||
242 | visualParent: contextMouseArea | | |||
243 | | ||||
244 | PlasmaComponents.MenuItem { | | |||
245 | text: i18n("Copy") | | |||
246 | onClicked: bodyText.copy() | | |||
247 | } | | |||
248 | | ||||
249 | PlasmaComponents.MenuItem { | | |||
250 | text: i18n("Select All") | | |||
251 | onClicked: bodyText.selectAll() | | |||
252 | } | | |||
253 | } | | |||
254 | | ||||
255 | PlasmaExtras.ScrollArea { | | |||
256 | id: bodyTextScrollArea | | |||
257 | anchors.fill: parent | | |||
258 | visible: bodyText.length > 0 | 246 | visible: bodyText.length > 0 | ||
259 | 247 | | |||
260 | flickableItem.boundsBehavior: Flickable.StopAtBounds | 248 | flickableItem.boundsBehavior: Flickable.StopAtBounds | ||
261 | flickableItem.flickableDirection: Flickable.VerticalFlick | 249 | flickableItem.flickableDirection: Flickable.VerticalFlick | ||
262 | horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff | 250 | horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff | ||
263 | 251 | | |||
264 | TextEdit { | 252 | TextEdit { | ||
265 | id: bodyText | 253 | id: bodyText | ||
Show All 24 Lines | |||||
290 | onCursorRectangleChanged: { | 278 | onCursorRectangleChanged: { | ||
291 | var flick = bodyTextScrollArea.flickableItem | 279 | var flick = bodyTextScrollArea.flickableItem | ||
292 | if (flick.contentY >= cursorRectangle.y) { | 280 | if (flick.contentY >= cursorRectangle.y) { | ||
293 | flick.contentY = cursorRectangle.y | 281 | flick.contentY = cursorRectangle.y | ||
294 | } else if (flick.contentY + flick.height <= cursorRectangle.y + cursorRectangle.height) { | 282 | } else if (flick.contentY + flick.height <= cursorRectangle.y + cursorRectangle.height) { | ||
295 | flick.contentY = cursorRectangle.y + cursorRectangle.height - flick.height | 283 | flick.contentY = cursorRectangle.y + cursorRectangle.height - flick.height | ||
296 | } | 284 | } | ||
297 | } | 285 | } | ||
286 | MouseArea { | ||||
287 | anchors.fill: parent | ||||
288 | acceptedButtons: Qt.RightButton | Qt.LeftButton | ||||
289 | | ||||
290 | onClicked: { | ||||
291 | if (mouse.button == Qt.RightButton) | ||||
292 | contextMenu.open(mouse.x, mouse.y) | ||||
293 | else { | ||||
294 | notificationItem.clicked(mouse) | ||||
295 | } | ||||
296 | } | ||||
297 | | ||||
298 | PlasmaComponents.ContextMenu { | ||||
299 | id: contextMenu | ||||
300 | visualParent: parent | ||||
301 | | ||||
302 | PlasmaComponents.MenuItem { | ||||
303 | text: i18n("Copy") | ||||
304 | onClicked: { | ||||
305 | bodyText.selectAll() | ||||
306 | bodyText.copy() | ||||
307 | } | ||||
308 | } | ||||
309 | } | ||||
298 | } | 310 | } | ||
299 | } | 311 | } | ||
300 | } | 312 | } | ||
301 | 313 | | |||
302 | ColumnLayout { | 314 | ColumnLayout { | ||
303 | id: actionsColumn | 315 | id: actionsColumn | ||
304 | Layout.alignment: Qt.AlignTop | 316 | Layout.alignment: Qt.AlignTop | ||
305 | Layout.maximumWidth: theme.mSize(theme.defaultFont).width * (compact ? 10 : 16) | 317 | Layout.maximumWidth: theme.mSize(theme.defaultFont).width * (compact ? 10 : 16) | ||
Show All 31 Lines |
This is not the behaviour that was agreed here [1], we shouldn't close the notification if there is no action to be performed.
[1] https://phabricator.kde.org/D4215