Skip to content

Commit 056f04d

Browse files
Properly implemented support for canceling non-opaque undocking on Linux
1 parent e085a29 commit 056f04d

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

demo/MainWindow.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
384384

385385
// uncomment the follwing line if you want to use non opaque undocking and splitter
386386
// moevements
387-
CDockManager::setConfigFlags(CDockManager::DefaultNonOpaqueConfig);
388-
CDockManager::setConfigFlag(CDockManager::DragPreviewHasWindowFrame, true);
387+
// CDockManager::setConfigFlags(CDockManager::DefaultNonOpaqueConfig);
389388

390389
// Now create the dock manager and its content
391390
d->DockManager = new CDockManager(this);

src/FloatingDragPreview.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,13 @@ CFloatingDragPreview::CFloatingDragPreview(QWidget* Content, QWidget* parent) :
206206

207207
connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
208208
SLOT(onApplicationStateChanged(Qt::ApplicationState)));
209+
210+
#ifdef Q_OS_LINUX
211+
// In Windows this widget directly receives the escape key press events
212+
// in Linux we need to install an event filter for the given Content
213+
// widget to receive the escape key press
214+
Content->installEventFilter(this);
215+
#endif
209216
}
210217

211218

@@ -372,6 +379,23 @@ void CFloatingDragPreview::onApplicationStateChanged(Qt::ApplicationState state)
372379
}
373380

374381

382+
//============================================================================
383+
bool CFloatingDragPreview::eventFilter(QObject *watched, QEvent *event)
384+
{
385+
if (event->type() == QEvent::KeyPress)
386+
{
387+
QKeyEvent* e = static_cast<QKeyEvent*>(event);
388+
if (e->key() == Qt::Key_Escape)
389+
{
390+
d->Content->removeEventFilter(this);
391+
d->cancelDragging();
392+
}
393+
}
394+
395+
return false;
396+
}
397+
398+
375399

376400

377401
} // namespace ads

src/FloatingDragPreview.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ private slots:
7878
*/
7979
~CFloatingDragPreview();
8080

81+
/**
82+
* We filter the events of the assigned content widget to receive
83+
* escape key presses for canceling the drag operation
84+
*/
85+
virtual bool eventFilter(QObject *watched, QEvent *event) override;
86+
8187

8288
public: // implements IFloatingWidget -----------------------------------------
8389
virtual void startFloating(const QPoint& DragStartMousePos, const QSize& Size,

0 commit comments

Comments
 (0)