Skip to content

Commit

Permalink
Don't carry over small screen HUD presses to docks
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
askmeaboutlo0m committed Nov 23, 2024
1 parent 3d6ddd2 commit 710d1b1
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 40 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
72 changes: 50 additions & 22 deletions src/desktop/scene/canvasview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -1925,32 +1945,40 @@ void CanvasView::touchEvent(QTouchEvent *event)

switch(event->type()) {
case QEvent::TouchBegin: {
const QList<compat::TouchPoint> &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<compat::TouchPoint> &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;
Expand Down
3 changes: 3 additions & 0 deletions src/desktop/scene/canvasview.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ private slots:
void setRotationSnap(qreal degrees);
void rotateByDiscreteSteps(int steps);

bool activatePendingToggleAction();

void viewRectChanged();

QString getZoomNotice() const;
Expand Down Expand Up @@ -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;
Expand Down
64 changes: 46 additions & 18 deletions src/desktop/view/canvascontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -758,32 +760,36 @@ void CanvasController::handleTabletRelease(QTabletEvent *event)
void CanvasController::handleTouchBegin(QTouchEvent *event)
{
event->accept();
const QList<compat::TouchPoint> &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<compat::TouchPoint> &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;
}
}
}
}

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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
3 changes: 3 additions & 0 deletions src/desktop/view/canvascontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ class CanvasController : public QObject {
void setRotationSnap(qreal degrees);
void rotateByDiscreteSteps(int steps);

bool activatePendingToggleAction();

void emitTransformChanged();
void emitViewRectChanged();
void emitScrollAreaChanged();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 710d1b1

Please sign in to comment.