Skip to content

Commit

Permalink
Editor: Make horizontal scroll work
Browse files Browse the repository at this point in the history
Some mice like Apple's Mighty Mouse do have the ball instead of the wheel, which allows to scroll the stuff in all directions. So, to make that work properly, it's need to handle both X and Y of the angle delta.
  • Loading branch information
Wohlstand committed Jul 24, 2024
1 parent 134f5fc commit 9debff1
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions Editor/common_features/graphicsworkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ void GraphicsWorkspace::wheelEvent(QWheelEvent *event)
}

auto delta = event->angleDelta();
int deltaX = delta.x() != 0 ? delta.x() : delta.y();
int deltaX = delta.x();
int deltaY = delta.y();

if(event->modifiers() & Qt::ControlModifier)
{
Expand All @@ -318,7 +319,7 @@ void GraphicsWorkspace::wheelEvent(QWheelEvent *event)
emit zoomValueChanged(qRound(zoomValue * 100));
emit zoomValueChanged(QString::number(qRound(zoomValue * 100)));
}
else
else if(deltaX < 0)
{
if(zoomValue * scaleFactor <= scaleMin) return;
// Zooming out
Expand All @@ -332,12 +333,20 @@ void GraphicsWorkspace::wheelEvent(QWheelEvent *event)
return;
}

auto *hBar = horizontalScrollBar();
auto *vBar = verticalScrollBar();

if(event->modifiers() & Qt::AltModifier)
{
if(deltaX > 0)
horizontalScrollBar()->setValue(horizontalScrollBar()->value() - modS_h);
else
horizontalScrollBar()->setValue(horizontalScrollBar()->value() + modS_h);
vBar->setValue(vBar->value() - modS_h);
else if(deltaX < 0)
vBar->setValue(vBar->value() + modS_h);

if(deltaY > 0)
hBar->setValue(hBar->value() - modS_h);
else if(deltaY < 0)
hBar->setValue(hBar->value() + modS_h);

//event->accept();
replayLastMouseEvent();
Expand All @@ -350,9 +359,14 @@ void GraphicsWorkspace::wheelEvent(QWheelEvent *event)
else
{
if(deltaX > 0)
verticalScrollBar()->setValue(verticalScrollBar()->value() - modS);
else
verticalScrollBar()->setValue(verticalScrollBar()->value() + modS);
hBar->setValue(hBar->value() - modS);
else if(deltaX < 0)
hBar->setValue(hBar->value() + modS);

if(deltaY > 0)
vBar->setValue(vBar->value() - modS);
else if(deltaY < 0)
vBar->setValue(vBar->value() + modS);

//event->accept();
replayLastMouseEvent();
Expand Down

0 comments on commit 9debff1

Please sign in to comment.