Properly handle Escape key in native Window event handling function if event WM_EXITSIZEMOVE occurs

This commit is contained in:
Uwe Kindler 2020-05-27 13:28:29 +02:00
parent 277e06627b
commit dfb8543aee
2 changed files with 11 additions and 41 deletions

View File

@ -57,6 +57,7 @@
namespace ads
{
#ifdef Q_OS_WIN
#if 0 // set to 1 if you need this function for debugging
/**
* Just for debuging to convert windows message identifiers to strings
*/
@ -350,6 +351,7 @@ static const char* windowsMessageString(int MessageId)
return "unknown WM_ message";
}
#endif
#endif
static unsigned int zOrderCounter = 0;
@ -713,7 +715,6 @@ bool CFloatingDockContainer::nativeEvent(const QByteArray &eventType, void *mess
if (d->isState(DraggingMousePressed))
{
ADS_PRINT("CFloatingDockContainer::nativeEvent WM_ENTERSIZEMOVE" << e->type());
qApp->installEventFilter(this);
d->setState(DraggingFloatingWidget);
d->updateDropOverlays(QCursor::pos());
}
@ -722,9 +723,16 @@ bool CFloatingDockContainer::nativeEvent(const QByteArray &eventType, void *mess
case WM_EXITSIZEMOVE:
if (d->isState(DraggingFloatingWidget))
{
ADS_PRINT("CFloatingDockContainer::nativeEvent WM_EXITSIZEMOVE" << e->type());;
ADS_PRINT("CFloatingDockContainer::nativeEvent WM_EXITSIZEMOVE" << e->type());
if (GetAsyncKeyState(VK_ESCAPE) & 0x8000)
{
d->handleEscapeKey();
}
else
{
d->titleMouseReleaseEvent();
}
}
break;
}
return false;
@ -796,43 +804,6 @@ void CFloatingDockContainer::showEvent(QShowEvent *event)
}
//============================================================================
bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *e)
{
Q_UNUSED(watched);
// I have not found a way to detect non client area key press events to
// handle escape key presses. On Windows, if the escape key is pressed while
// dragging around a widget, the widget position is reset to its start position
// which in turn generates a QEvent::NonClientAreaMouseButtonRelease event
// if the mouse is outside of the widget after the move to its initial position
// or a QEvent::MouseButtonRelease event, if the mouse is inside of teh widget
// after the position has been reset.
// So we can install an event filter on the application to get these events
// here to properly cancel dragging and hide the overlays.
// If we are in DraggingFloatingWidget state, it means the widget
// has been dragged already but if the position is the same like
// the start position, then this is an indication that the escape
// key has been pressed.
if (e->type() == QEvent::MouseButtonRelease || e->type() == QEvent::NonClientAreaMouseButtonRelease)
{
ADS_PRINT("CFloatingDockContainer::eventFilter QEvent::MouseButtonRelease or"
"QEvent::NonClientAreaMouseButtonRelease" << "d->DragggingState " << d->DraggingState);
qApp->removeEventFilter(this);
if (d->DragStartPos == pos())
{
d->handleEscapeKey();
return true;
}
return false;
}
#if (ADS_DEBUG_LEVEL > 0)
qDebug() << QTime::currentTime() << "CFloatingDockContainer::eventFilter " << e->type();
#endif
return false;
}
//============================================================================
void CFloatingDockContainer::startFloating(const QPoint &DragStartMousePos,
const QSize &Size, eDragState DragState, QWidget *MouseEventHandler)

View File

@ -180,7 +180,6 @@ protected: // reimplements QWidget
virtual void closeEvent(QCloseEvent *event) override;
virtual void hideEvent(QHideEvent *event) override;
virtual void showEvent(QShowEvent *event) override;
virtual bool eventFilter(QObject *watched, QEvent *event) override;
#ifdef Q_OS_WIN
/**