diff --git a/src/DockWidgetBase.cpp b/src/DockWidgetBase.cpp index 9960cef6..1a74825b 100644 --- a/src/DockWidgetBase.cpp +++ b/src/DockWidgetBase.cpp @@ -52,7 +52,6 @@ DockWidgetBase::DockWidgetBase(const QString &name, Options options, qWarning() << Q_FUNC_INFO << "Name can't be null"; setAttribute(Qt::WA_PendingMoveEvent, false); - qApp->installEventFilter(this); } DockWidgetBase::~DockWidgetBase() @@ -541,16 +540,6 @@ void DockWidgetBase::updateFloatAction() d->updateFloatAction(); } -bool DockWidgetBase::eventFilter(QObject *watched, QEvent *event) -{ - const bool isWindowActivate = event->type() == QEvent::WindowActivate; - const bool isWindowDeactivate = event->type() == QEvent::WindowDeactivate; - if ((isWindowActivate || isWindowDeactivate) && watched == window()) - Q_EMIT windowActiveAboutToChange(isWindowActivate); - - return QWidgetAdapter::eventFilter(watched, event); -} - QPoint DockWidgetBase::Private::defaultCenterPosForFloating() { MainWindowBase::List mainWindows = DockRegistry::self()->mainwindows(); @@ -562,6 +551,16 @@ QPoint DockWidgetBase::Private::defaultCenterPosForFloating() return mw->geometry().center(); } +bool DockWidgetBase::Private::eventFilter(QObject *watched, QEvent *event) +{ + const bool isWindowActivate = event->type() == QEvent::WindowActivate; + const bool isWindowDeactivate = event->type() == QEvent::WindowDeactivate; + if ((isWindowActivate || isWindowDeactivate) && watched == q->window()) + Q_EMIT q->windowActiveAboutToChange(isWindowActivate); + + return QObject::eventFilter(watched, event); +} + void DockWidgetBase::Private::updateTitle() { if (q->isFloating()) diff --git a/src/DockWidgetBase.h b/src/DockWidgetBase.h index 7218bfb9..b705fa04 100644 --- a/src/DockWidgetBase.h +++ b/src/DockWidgetBase.h @@ -463,9 +463,6 @@ protected: void onShown(bool spontaneous); void onHidden(bool spontaneous); - ///@reimp - bool eventFilter(QObject *, QEvent *) override; - #ifndef PYTHON_BINDINGS //Pyside bug: https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1327 void onCloseEvent(QCloseEvent *e) override; bool onResize(QSize newSize) override; diff --git a/src/private/DockWidgetBase_p.h b/src/private/DockWidgetBase_p.h index 3a2f9f23..0dab8fcf 100644 --- a/src/private/DockWidgetBase_p.h +++ b/src/private/DockWidgetBase_p.h @@ -18,12 +18,13 @@ #include "Position_p.h" #include "FloatingWindow_p.h" +#include #include #include namespace KDDockWidgets { -class DockWidgetBase::Private +class DockWidgetBase::Private : public QObject { public: Private(const QString &dockName, DockWidgetBase::Options options_, @@ -56,6 +57,8 @@ public: toggleAction->setCheckable(true); floatAction->setCheckable(true); + + qApp->installEventFilter(this); } void init() @@ -96,6 +99,8 @@ public: void forceClose(); QPoint defaultCenterPosForFloating(); + bool eventFilter(QObject *watched, QEvent *event) override; + void updateTitle(); void toggle(bool enabled); void updateToggleAction();