diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index 5f513a8..5459e15 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -384,8 +384,7 @@ CMainWindow::CMainWindow(QWidget *parent) : // uncomment the follwing line if you want to use non opaque undocking and splitter // moevements - CDockManager::setConfigFlags(CDockManager::DefaultNonOpaqueConfig); - CDockManager::setConfigFlag(CDockManager::DragPreviewHasWindowFrame, true); + // CDockManager::setConfigFlags(CDockManager::DefaultNonOpaqueConfig); // Now create the dock manager and its content d->DockManager = new CDockManager(this); diff --git a/src/FloatingDragPreview.cpp b/src/FloatingDragPreview.cpp index fa062af..c7a95bc 100644 --- a/src/FloatingDragPreview.cpp +++ b/src/FloatingDragPreview.cpp @@ -206,6 +206,13 @@ CFloatingDragPreview::CFloatingDragPreview(QWidget* Content, QWidget* parent) : connect(qApp, SIGNAL(applicationStateChanged(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(event); + if (e->key() == Qt::Key_Escape) + { + d->Content->removeEventFilter(this); + d->cancelDragging(); + } + } + + return false; +} + + } // namespace ads diff --git a/src/FloatingDragPreview.h b/src/FloatingDragPreview.h index 07b68ea..4367710 100644 --- a/src/FloatingDragPreview.h +++ b/src/FloatingDragPreview.h @@ -78,6 +78,12 @@ public: */ ~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 ----------------------------------------- virtual void startFloating(const QPoint& DragStartMousePos, const QSize& Size,