Commit 1d1c6f5a authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Introduce setWindow and CloseWhenWindowActivated

This is a replacement for CloseOnWidgetActivated that operates on a QWindow instead of QWidget.
parent 4125c879
Pipeline #83469 passed with stage
in 40 seconds
......@@ -53,6 +53,7 @@ struct Q_DECL_HIDDEN KNotification::Private {
QTimer updateTimer;
bool needUpdate = false;
bool isNew = true;
QWindow *window = nullptr;
#if KNOTIFICATIONS_BUILD_DEPRECATED_SINCE(5, 67)
/**
......@@ -597,3 +598,26 @@ QVariantMap KNotification::hints() const
{
return d->hints;
}
void KNotification::setWindow(QWindow *window)
{
if (window == d->window) {
return;
}
disconnect(d->window, &QWindow::activeChanged, this, &KNotification::slotWindowActiveChanged);
d->window = window;
connect(d->window, &QWindow::activeChanged, this, &KNotification::slotWindowActiveChanged);
}
void KNotification::slotWindowActiveChanged()
{
if (d->window->isActive() && (d->flags & CloseWhenWindowActivated)) {
close();
}
}
QWindow *KNotification::window() const
{
return d->window;
}
......@@ -17,6 +17,7 @@
#include <QPixmap>
#include <QUrl>
#include <QVariant>
#include <QWindow>
#include <memory>
......@@ -103,6 +104,16 @@ public:
*/
SkipGrouping = 0x10,
/**
* The notification will be automatically closed if the window() becomes
* activated.
*
* You need to set a window using setWindow().
*
* @since 5.76
*/
CloseWhenWindowActivated = 0x20,
/**
* @internal
* The event is a standard kde event, and not an event of the application
......@@ -449,6 +460,22 @@ public:
*/
void setUrgency(Urgency urgency);
/**
* Sets the window associated with this notification.
* This is relevant when using the CloseWhenWindowActivated flag.
*
* @since 5.76
*/
void setWindow(QWindow *window);
/**
* The window associated with this notification. nullptr by default.
* @return the window set by setWindow()
*
* @since 5.76
*/
QWindow *window() const;
/**
* @internal
* the id given by the notification manager
......@@ -587,6 +614,8 @@ public Q_SLOTS:
QVariantMap hints() const;
private:
void slotWindowActiveChanged();
struct Private;
Private *const d;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment