Properly implemented support for canceling non-opaque undocking on Linux

This commit is contained in:
Uwe Kindler 2019-12-16 11:45:18 +01:00
parent e085a29484
commit 056f04d408
3 changed files with 31 additions and 2 deletions

View File

@ -384,8 +384,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
// uncomment the follwing line if you want to use non opaque undocking and splitter // uncomment the follwing line if you want to use non opaque undocking and splitter
// moevements // moevements
CDockManager::setConfigFlags(CDockManager::DefaultNonOpaqueConfig); // CDockManager::setConfigFlags(CDockManager::DefaultNonOpaqueConfig);
CDockManager::setConfigFlag(CDockManager::DragPreviewHasWindowFrame, true);
// Now create the dock manager and its content // Now create the dock manager and its content
d->DockManager = new CDockManager(this); d->DockManager = new CDockManager(this);

View File

@ -206,6 +206,13 @@ CFloatingDragPreview::CFloatingDragPreview(QWidget* Content, QWidget* parent) :
connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)), connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
SLOT(onApplicationStateChanged(Qt::ApplicationState))); SLOT(onApplicationStateChanged(Qt::ApplicationState)));
#ifdef Q_OS_LINUX
// In Windows this widget directly receives the escape key press events
// in Linux we need to install an event filter for the given Content
// widget to receive the escape key press
Content->installEventFilter(this);
#endif
} }
@ -372,6 +379,23 @@ void CFloatingDragPreview::onApplicationStateChanged(Qt::ApplicationState state)
} }
//============================================================================
bool CFloatingDragPreview::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::KeyPress)
{
QKeyEvent* e = static_cast<QKeyEvent*>(event);
if (e->key() == Qt::Key_Escape)
{
d->Content->removeEventFilter(this);
d->cancelDragging();
}
}
return false;
}
} // namespace ads } // namespace ads

View File

@ -78,6 +78,12 @@ public:
*/ */
~CFloatingDragPreview(); ~CFloatingDragPreview();
/**
* We filter the events of the assigned content widget to receive
* escape key presses for canceling the drag operation
*/
virtual bool eventFilter(QObject *watched, QEvent *event) override;
public: // implements IFloatingWidget ----------------------------------------- public: // implements IFloatingWidget -----------------------------------------
virtual void startFloating(const QPoint& DragStartMousePos, const QSize& Size, virtual void startFloating(const QPoint& DragStartMousePos, const QSize& Size,