]> Shamusworld >> Repos - architektonas/blobdiff - src/drawingview.cpp
Fix scrollwheel zooming from walking all over the screen.
[architektonas] / src / drawingview.cpp
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));