Move DockWidgetBase::eventFilter() into the private class

Fixes issue #151 where the user is overriding eventFilter too
and getting into some edge cases.

Could be worked around in user code, but it's always good to have
less protected and private API in public classes.
This commit is contained in:
Sergio Martins
2021-01-29 20:20:01 +00:00
parent 799f2a81a7
commit 6ccd98ca01
3 changed files with 16 additions and 15 deletions

View File

@@ -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())

View File

@@ -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;

View File

@@ -18,12 +18,13 @@
#include "Position_p.h"
#include "FloatingWindow_p.h"
#include <QCoreApplication>
#include <QString>
#include <QSize>
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();