From 710d1b1d36a022e65cc5c73efab0ec83cf7f64a0 Mon Sep 17 00:00:00 2001 From: askmeaboutloom Date: Sat, 23 Nov 2024 01:09:06 +0100 Subject: [PATCH] Don't carry over small screen HUD presses to docks By delaying the activation of the toggle action until the pen or touch release. Otherwise pressing on a toggle action can twiddle brush sliders or similar. --- ChangeLog | 1 + src/desktop/scene/canvasview.cpp | 72 +++++++++++++++++++-------- src/desktop/scene/canvasview.h | 3 ++ src/desktop/view/canvascontroller.cpp | 64 +++++++++++++++++------- src/desktop/view/canvascontroller.h | 3 ++ 5 files changed, 103 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index fa0c7b4d4..844560c51 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,7 @@ Unreleased Version 2.2.2-pre * Server Fix: Don't pointlessly reload server certificates if they didn't change. Thanks Liz for reporting. * Server Fix: Work around too many authenticated users in a session, which could cause a crash. Thanks Liz for reporting. * Fix: Don't crash when filling with feathering and a canvas-filling selection. Thanks Meru for reporting. + * Fix: Don't carry over HUD button presses to dock UI in small screen mode. Thanks Meru for reporting. 2024-11-06 Version 2.2.2-beta.4 * Fix: Solve rendering glitches with selection outlines that happen on some systems. Thanks xxxx for reporting. diff --git a/src/desktop/scene/canvasview.cpp b/src/desktop/scene/canvasview.cpp index 63076f284..3b6d7c449 100644 --- a/src/desktop/scene/canvasview.cpp +++ b/src/desktop/scene/canvasview.cpp @@ -189,6 +189,7 @@ CanvasView::CanvasView(QWidget *parent) , m_alphaLockCursorStyle(int(view::Cursor::SameAsBrush)) , m_brushOutlineWidth(1.0) , m_brushBlendMode(DP_BLEND_MODE_NORMAL) + , m_hudActionToActivate(int(drawingboard::ToggleItem::Action::None)) , m_scrollBarsAdjusting{false} , m_blockNotices{false} , m_showTransformNotices(true) @@ -983,6 +984,21 @@ void CanvasView::setOutlineMode(bool subpixel, bool square, bool force) } } +bool CanvasView::activatePendingToggleAction() +{ + if(int action = m_hudActionToActivate; + action != int(drawingboard::ToggleItem::Action::None)) { + m_hudActionToActivate = int(drawingboard::ToggleItem::Action::None); + m_hoveringOverHud = false; + m_scene->removeHover(); + resetCursor(); + emit toggleActionActivated(action); + return true; + } else { + return false; + } +} + void CanvasView::viewRectChanged() { if(m_scene) { @@ -1200,7 +1216,8 @@ void CanvasView::penPressEvent( qreal xtilt, qreal ytilt, qreal rotation, Qt::MouseButton button, Qt::KeyboardModifiers modifiers, int deviceType, bool eraserOverride) { - if(m_pendown != NOTDOWN) { + if(m_pendown != NOTDOWN || + m_hudActionToActivate != int(drawingboard::ToggleItem::Action::None)) { return; } @@ -1215,10 +1232,7 @@ void CanvasView::penPressEvent( if(event) { event->accept(); } - emit toggleActionActivated(int(action)); - m_hoveringOverHud = false; - m_scene->removeHover(); - resetCursor(); + m_hudActionToActivate = int(action); return; } @@ -1355,6 +1369,10 @@ void CanvasView::penMoveEvent( qreal ytilt, qreal rotation, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers) { + if(m_hudActionToActivate != int(drawingboard::ToggleItem::Action::None)) { + return; + } + canvas::Point point = mapToCanvas(timeMsec, pos, pressure, xtilt, ytilt, rotation); emit coordinatesChanged(point); @@ -1432,6 +1450,8 @@ void CanvasView::penReleaseEvent( long long timeMsec, const QPointF &pos, Qt::MouseButton button, Qt::KeyboardModifiers modifiers) { + activatePendingToggleAction(); + canvas::Point point = mapToCanvas(timeMsec, pos, 0.0, 0.0, 0.0, 0.0); m_prevpoint = point; CanvasShortcuts::Match mouseMatch = m_canvasShortcuts.matchMouseButton( @@ -1925,32 +1945,40 @@ void CanvasView::touchEvent(QTouchEvent *event) switch(event->type()) { case QEvent::TouchBegin: { - const QList &points = compat::touchPoints(*event); - int pointsCount = points.size(); - if(pointsCount > 0) { - QPointF pos = compat::touchPos(points.first()); - drawingboard::ToggleItem::Action action = - m_scene->checkHover(mapToScene(pos.toPoint())); - if(action == drawingboard::ToggleItem::Action::None) { - m_touch->handleTouchBegin(event); - } else { - emit toggleActionActivated(int(action)); - m_hoveringOverHud = false; - m_scene->removeHover(); - resetCursor(); + if(m_hudActionToActivate == + int(drawingboard::ToggleItem::Action::None)) { + const QList &points = + compat::touchPoints(*event); + int pointsCount = points.size(); + if(pointsCount > 0) { + QPointF pos = compat::touchPos(points.first()); + drawingboard::ToggleItem::Action action = + m_scene->checkHover(mapToScene(pos.toPoint())); + if(action == drawingboard::ToggleItem::Action::None) { + m_touch->handleTouchBegin(event); + } else { + m_hudActionToActivate = int(action); + } } } break; } case QEvent::TouchUpdate: - m_touch->handleTouchUpdate( - event, zoom(), rotation(), devicePixelRatioF()); + if(m_hudActionToActivate == + int(drawingboard::ToggleItem::Action::None)) { + m_touch->handleTouchUpdate( + event, zoom(), rotation(), devicePixelRatioF()); + } break; case QEvent::TouchEnd: - m_touch->handleTouchEnd(event, false); + if(!activatePendingToggleAction()) { + m_touch->handleTouchEnd(event, false); + } break; case QEvent::TouchCancel: - m_touch->handleTouchEnd(event, true); + if(!activatePendingToggleAction()) { + m_touch->handleTouchEnd(event, true); + } break; default: break; diff --git a/src/desktop/scene/canvasview.h b/src/desktop/scene/canvasview.h index 04d11fd70..caa6f6567 100644 --- a/src/desktop/scene/canvasview.h +++ b/src/desktop/scene/canvasview.h @@ -348,6 +348,8 @@ private slots: void setRotationSnap(qreal degrees); void rotateByDiscreteSteps(int steps); + bool activatePendingToggleAction(); + void viewRectChanged(); QString getZoomNotice() const; @@ -441,6 +443,7 @@ private slots: int m_alphaLockCursorStyle; qreal m_brushOutlineWidth; int m_brushBlendMode; + int m_hudActionToActivate; bool m_pickingColor = false; bool m_scrollBarsAdjusting; diff --git a/src/desktop/view/canvascontroller.cpp b/src/desktop/view/canvascontroller.cpp index 3c6fa1101..97c425e07 100644 --- a/src/desktop/view/canvascontroller.cpp +++ b/src/desktop/view/canvascontroller.cpp @@ -168,6 +168,7 @@ CanvasController::CanvasController(CanvasScene *scene, QWidget *parent) , m_brushBlendMode(DP_BLEND_MODE_NORMAL) , m_touch(new TouchHandler(this)) , m_toolState(int(tools::ToolState::Normal)) + , m_hudActionToActivate(int(drawingboard::ToggleItem::Action::None)) #ifdef Q_OS_LINUX , m_waylandWorkarounds( QGuiApplication::platformName() == QStringLiteral("wayland")) @@ -566,6 +567,7 @@ void CanvasController::handleLeave() { m_showOutline = false; m_scene->setCursorOnCanvas(false); + m_hudActionToActivate = int(drawingboard::ToggleItem::Action::None); m_hoveringOverHud = false; m_scene->removeHover(); updateOutline(); @@ -758,18 +760,17 @@ void CanvasController::handleTabletRelease(QTabletEvent *event) void CanvasController::handleTouchBegin(QTouchEvent *event) { event->accept(); - const QList &points = compat::touchPoints(*event); - int pointsCount = points.size(); - if(pointsCount > 0) { - int action = - m_scene->checkHover(compat::touchPos(points.first()).toPoint()); - if(action == int(drawingboard::ToggleItem::Action::None)) { - m_touch->handleTouchBegin(event); - } else { - emit toggleActionActivated(action); - m_hoveringOverHud = false; - m_scene->removeHover(); - resetCursor(); + if(m_hudActionToActivate == int(drawingboard::ToggleItem::Action::None)) { + const QList &points = compat::touchPoints(*event); + int pointsCount = points.size(); + if(pointsCount > 0) { + int action = + m_scene->checkHover(compat::touchPos(points.first()).toPoint()); + if(action == int(drawingboard::ToggleItem::Action::None)) { + m_touch->handleTouchBegin(event); + } else { + m_hudActionToActivate = action; + } } } } @@ -777,13 +778,18 @@ void CanvasController::handleTouchBegin(QTouchEvent *event) void CanvasController::handleTouchUpdate(QTouchEvent *event) { event->accept(); - m_touch->handleTouchUpdate(event, zoom(), rotation(), devicePixelRatioF()); + if(m_hudActionToActivate == int(drawingboard::ToggleItem::Action::None)) { + m_touch->handleTouchUpdate( + event, zoom(), rotation(), devicePixelRatioF()); + } } void CanvasController::handleTouchEnd(QTouchEvent *event, bool cancel) { event->accept(); - m_touch->handleTouchEnd(event, cancel); + if(!activatePendingToggleAction()) { + m_touch->handleTouchEnd(event, cancel); + } } void CanvasController::handleGesture(QGestureEvent *event) @@ -1325,6 +1331,10 @@ void CanvasController::penMoveEvent( long long timeMsec, const QPointF &posf, qreal pressure, qreal xtilt, qreal ytilt, qreal rotation, Qt::KeyboardModifiers modifiers) { + if(m_hudActionToActivate != int(drawingboard::ToggleItem::Action::None)) { + return; + } + canvas::Point point = mapPenPointToCanvasF(timeMsec, posf, pressure, xtilt, ytilt, rotation); emit coordinatesChanged(point); @@ -1391,6 +1401,10 @@ void CanvasController::penPressEvent( qreal ytilt, qreal rotation, Qt::MouseButton button, Qt::KeyboardModifiers modifiers, int deviceType, bool eraserOverride) { + if(m_hudActionToActivate != int(drawingboard::ToggleItem::Action::None)) { + return; + } + if(m_penState == PenState::Up) { bool wasHovering; int action = m_scene->checkHover(posf.toPoint(), &wasHovering); @@ -1401,10 +1415,7 @@ void CanvasController::penPressEvent( resetCursor(); } if(m_hoveringOverHud) { - emit toggleActionActivated(action); - m_hoveringOverHud = false; - m_scene->removeHover(); - resetCursor(); + m_hudActionToActivate = action; return; } @@ -1521,6 +1532,8 @@ void CanvasController::penReleaseEvent( long long timeMsec, const QPointF &posf, Qt::MouseButton button, Qt::KeyboardModifiers modifiers) { + activatePendingToggleAction(); + canvas::Point point = mapPenPointToCanvasF(timeMsec, posf, 0.0, 0.0, 0.0, 0.0); m_prevPoint = point; @@ -2292,6 +2305,21 @@ void CanvasController::rotateByDiscreteSteps(int steps) } } +bool CanvasController::activatePendingToggleAction() +{ + if(int action = m_hudActionToActivate; + action != int(drawingboard::ToggleItem::Action::None)) { + m_hudActionToActivate = int(drawingboard::ToggleItem::Action::None); + m_hoveringOverHud = false; + m_scene->removeHover(); + resetCursor(); + emit toggleActionActivated(action); + return true; + } else { + return false; + } +} + void CanvasController::emitTransformChanged() { emit transformChanged(zoom(), rotation()); diff --git a/src/desktop/view/canvascontroller.h b/src/desktop/view/canvascontroller.h index b39433517..b89e20d33 100644 --- a/src/desktop/view/canvascontroller.h +++ b/src/desktop/view/canvascontroller.h @@ -306,6 +306,8 @@ class CanvasController : public QObject { void setRotationSnap(qreal degrees); void rotateByDiscreteSteps(int steps); + bool activatePendingToggleAction(); + void emitTransformChanged(); void emitViewRectChanged(); void emitScrollAreaChanged(); @@ -417,6 +419,7 @@ class CanvasController : public QObject { bool m_blockNotices = false; bool m_showTransformNotices = false; int m_toolState; + int m_hudActionToActivate; bool m_locked = false; QString m_lockDescription; bool m_saveInProgress = false;