From: Shamus Hammons Date: Sat, 23 Jan 2021 02:55:26 +0000 (-0600) Subject: Fix scrollwheel zooming from walking all over the screen. X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=architektonas;a=commitdiff_plain;h=e34f829de8f46c03e74f75e46438433153f6b96d Fix scrollwheel zooming from walking all over the screen. Turns out that Global::zoom was being unnecessarily updated by SetGridSize(), causing zooming to walk all over the screen. :-P --- diff --git a/src/drawingview.cpp b/src/drawingview.cpp index d35bd14..dc68532 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -145,7 +145,8 @@ void DrawingView::SetGridSize(uint32_t size) pmp.end(); // Set up new BG brush & zoom level (pixels per base unit) - Global::zoom = gridPixels / Global::gridSpacing; +// This shouldn't be done here, because it fucks up the scrollwheel zooming... +// Global::zoom = gridPixels / Global::gridSpacing; UpdateGridBackground(); } @@ -1783,6 +1784,13 @@ void DrawingView::mousePressEvent(QMouseEvent * event) void DrawingView::mouseMoveEvent(QMouseEvent * event) { + // It seems that wheelEvent() triggers this for some reason... + if (scrollWheelSeen) + { + scrollWheelSeen = false; + return; + } + Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y())); Global::selection.setBottomRight(QPointF(point.x, point.y)); // Only needs to be done here, as mouse down is always preceded by movement @@ -1989,32 +1997,31 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event) void DrawingView::wheelEvent(QWheelEvent * event) { double zoomFactor = 1.25; - QSize sizeWin = size(); - Vector center(sizeWin.width() / 2.0, sizeWin.height() / 2.0); - center = Painter::QtToCartesianCoords(center); + scrollWheelSeen = true; - // This is not centering for some reason. Need to figure out why. :-/ - if (event->delta() > 0) + if (event->delta() < 0) { if (Global::zoom > 20.0) return; - Vector newOrigin = center - ((center - Global::origin) / zoomFactor); - Global::origin = newOrigin; Global::zoom *= zoomFactor; +// Point np = Painter::QtToCartesianCoords(oldScrollPoint); +// Global::origin += (oldPoint - np); } else { if (Global::zoom < 0.25) return; - Vector newOrigin = center + ((-center + Global::origin) * zoomFactor); - Global::origin = newOrigin; Global::zoom /= zoomFactor; +// Point np = Painter::QtToCartesianCoords(oldScrollPoint); +// Global::origin += (oldPoint - np); } + Point np = Painter::QtToCartesianCoords(oldScrollPoint); + Global::origin += (oldPoint - np); + // Global::gridSpacing = gridPixels / Painter::zoom; -// UpdateGridBackground(); SetGridSize(Global::gridSpacing * Global::zoom); update(); // zoomIndicator->setText(QString("Grid: %1\", BU: Inch").arg(Global::gridSpacing)); diff --git a/src/drawingview.h b/src/drawingview.h index 9d543c4..d252ffc 100644 --- a/src/drawingview.h +++ b/src/drawingview.h @@ -109,6 +109,7 @@ class DrawingView: public QWidget bool draggingObject; bool angleSnap; bool dirty; + bool scrollWheelSeen; }; #endif // __DRAWINGVIEW_H__