Skip to content

Commit

Permalink
wasm: fix resizing of qwidget windows
Browse files Browse the repository at this point in the history
This also fixes the cursor changing during resize mode

Fixes: QTBUG-85361
Pick-to: 5.15
Change-Id: Ic85a5c31a8a2dc4265a84f16fd5fcdc231062c6d
Reviewed-by: Morten Johan Sørvig <[email protected]>
  • Loading branch information
lpotter committed Nov 22, 2020
1 parent f785849 commit 0de0a6a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/plugins/platforms/wasm/qwasmeventtranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <QtCore/qdeadlinetimer.h>
#include <private/qmakearray_p.h>
#include <QtCore/qnamespace.h>
#include <QCursor>

#include <emscripten/bind.h>

Expand Down Expand Up @@ -580,8 +581,13 @@ void QWasmEventTranslator::processMouse(int eventType, const EmscriptenMouseEven
Qt::MouseButton button = translateMouseButton(mouseEvent->button);
Qt::KeyboardModifiers modifiers = translateMouseEventModifier(mouseEvent);

QWindow *window2 = screen()->compositor()->windowAt(globalPoint, 5);
QWindow *window2 = nullptr;
if (resizeMode == QWasmWindow::ResizeNone)
window2 = screen()->compositor()->windowAt(globalPoint, 5);

if (lastWindow && lastWindow->cursor() != Qt::ArrowCursor) {
lastWindow->setCursor(Qt::ArrowCursor);
}
if (window2 == nullptr) {
window2 = lastWindow;
} else {
Expand Down Expand Up @@ -643,6 +649,10 @@ void QWasmEventTranslator::processMouse(int eventType, const EmscriptenMouseEven
case EMSCRIPTEN_EVENT_MOUSEMOVE: // drag event
{
buttonEventType = QEvent::MouseMove;

if (htmlWindow && htmlWindow->isPointOnResizeRegion(globalPoint))
window2->setCursor(cursorForMode(htmlWindow->resizeModeAtPoint(globalPoint)));

if (!(htmlWindow->m_windowState & Qt::WindowFullScreen) && !(htmlWindow->m_windowState & Qt::WindowMaximized)) {
if (resizeMode == QWasmWindow::ResizeNone && draggedWindow) {
draggedWindow->setX(draggedWindow->x() + mouseEvent->movementX);
Expand Down Expand Up @@ -996,4 +1006,27 @@ bool QWasmEventTranslator::processKeyboard(int eventType, const EmscriptenKeyboa
return accepted;
}

QCursor QWasmEventTranslator::cursorForMode(QWasmWindow::ResizeMode m)
{
switch (m) {
case QWasmWindow::ResizeTopLeft:
case QWasmWindow::ResizeBottomRight:
return Qt::SizeFDiagCursor;
break;
case QWasmWindow::ResizeBottomLeft:
case QWasmWindow::ResizeTopRight:
return Qt::SizeBDiagCursor;
break;
case QWasmWindow::ResizeTop:
case QWasmWindow::ResizeBottom:
return Qt::SizeVerCursor;
break;
case QWasmWindow::ResizeLeft:
case QWasmWindow::ResizeRight:
return Qt::SizeHorCursor;
break;
}
return Qt::ArrowCursor;
}

QT_END_NAMESPACE
2 changes: 2 additions & 0 deletions src/plugins/platforms/wasm/qwasmeventtranslator.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <QtGui/qpointingdevice.h>
#endif
#include <QHash>
#include <QCursor>

QT_BEGIN_NAMESPACE

Expand Down Expand Up @@ -102,6 +103,7 @@ class QWasmEventTranslator : public QObject

Qt::Key m_emDeadKey = Qt::Key_unknown;
bool m_emStickyDeadKey = false;
QCursor cursorForMode(QWasmWindow::ResizeMode mode);
};

QT_END_NAMESPACE
Expand Down

0 comments on commit 0de0a6a

Please sign in to comment.