]> Shamusworld >> Repos - architektonas/commitdiff
Fix scrollwheel zooming from walking all over the screen.
authorShamus Hammons <jlhamm@acm.org>
Sat, 23 Jan 2021 02:55:26 +0000 (20:55 -0600)
committerShamus Hammons <jlhamm@acm.org>
Sat, 23 Jan 2021 02:55:26 +0000 (20:55 -0600)
Turns out that Global::zoom was being unnecessarily updated by
SetGridSize(), causing zooming to walk all over the screen.  :-P

src/drawingview.cpp
src/drawingview.h

index d35bd14f5a308dbc1f947950043d0c462e01a5a9..dc6853203769404357e2ac7ca05c5e57f9c7329f 100644 (file)
@@ -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));
index 9d543c44d6f930e3de1e16f8705a813c0f84e1f0..d252ffcf3515e5273c74c48e6cdb33554daf2a26 100644 (file)
@@ -109,6 +109,7 @@ class DrawingView: public QWidget
                bool draggingObject;
                bool angleSnap;
                bool dirty;
+               bool scrollWheelSeen;
 };
 
 #endif // __DRAWINGVIEW_H__