Skip to content

Commit fe10b57

Browse files
Fixed reception of escape key press events
1 parent f3c5d51 commit fe10b57

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/FloatingDragPreview.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct FloatingDragPreviewPrivate
4040
qreal WindowOpacity;
4141
bool Hidden = false;
4242
QPixmap ContentPreviewPixmap;
43+
bool Canceled = false;
4344

4445

4546
/**
@@ -59,6 +60,7 @@ struct FloatingDragPreviewPrivate
5960
*/
6061
void cancelDragging()
6162
{
63+
Canceled = true;
6264
emit _this->draggingCanceled();
6365
DockManager->containerOverlay()->hideOverlay();
6466
DockManager->dockAreaOverlay()->hideOverlay();
@@ -85,11 +87,6 @@ void FloatingDragPreviewPrivate::updateDropOverlays(const QPoint &GlobalPos)
8587
continue;
8688
}
8789

88-
/*if (DockContainer == ContainerWidget)
89-
{
90-
continue;
91-
}*/
92-
9390
QPoint MappedPos = ContainerWidget->mapFromGlobal(GlobalPos);
9491
if (ContainerWidget->rect().contains(MappedPos))
9592
{
@@ -207,10 +204,9 @@ CFloatingDragPreview::CFloatingDragPreview(QWidget* Content, QWidget* parent) :
207204
connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
208205
SLOT(onApplicationStateChanged(Qt::ApplicationState)));
209206

210-
// The focused object will receive key press events and therefore we
211-
// install the event filter on it to receive escape key press for drag
212-
// canceling
213-
qApp->focusObject()->installEventFilter(this);
207+
// The only safe way to receive escape key presses is to install an event
208+
// filter for the application object
209+
qApp->installEventFilter(this);
214210
}
215211

216212

@@ -377,7 +373,7 @@ void CFloatingDragPreview::onApplicationStateChanged(Qt::ApplicationState state)
377373
bool CFloatingDragPreview::eventFilter(QObject *watched, QEvent *event)
378374
{
379375
Q_UNUSED(watched);
380-
if (event->type() == QEvent::KeyPress)
376+
if (!d->Canceled && event->type() == QEvent::KeyPress)
381377
{
382378
QKeyEvent* e = static_cast<QKeyEvent*>(event);
383379
if (e->key() == Qt::Key_Escape)

0 commit comments

Comments
 (0)