]> Shamusworld >> Repos - architektonas/blobdiff - src/drawingview.cpp
Fix object selection to work while in snap mode.
[architektonas] / src / drawingview.cpp
index 5bbcddf62ffeb0396b5f5edc5924e46ceaea9a5e..bdc3540b0442fc51b243e6096da6a94b362d2632 100644 (file)
@@ -47,7 +47,7 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
        gridBackground(BACKGROUND_MAX_SIZE, BACKGROUND_MAX_SIZE),
        scale(1.0), offsetX(-10), offsetY(-10),
        document(Vector(0, 0)),
        gridBackground(BACKGROUND_MAX_SIZE, BACKGROUND_MAX_SIZE),
        scale(1.0), offsetX(-10), offsetY(-10),
        document(Vector(0, 0)),
-       gridSpacing(12.0), gridPixels(0), collided(false), rotateTool(false),
+       /*gridSpacing(12.0),*/ gridPixels(0), collided(false), rotateTool(false),
        rx(150.0), ry(150.0),
        scrollDrag(false), addLineTool(false), addCircleTool(false),
        addDimensionTool(false),
        rx(150.0), ry(150.0),
        scrollDrag(false), addLineTool(false), addCircleTool(false),
        addDimensionTool(false),
@@ -57,6 +57,7 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
        setBackgroundRole(QPalette::Base);
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 
        setBackgroundRole(QPalette::Base);
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 
+       Object::gridSpacing = 12.0;
 //     toolPalette = new ToolWindow();
 //     CreateCursors();
 //     setCursor(cur[TOOLSelect]);
 //     toolPalette = new ToolWindow();
 //     CreateCursors();
 //     setCursor(cur[TOOLSelect]);
@@ -168,7 +169,8 @@ void DrawingView::SetGridSize(uint32_t size)
        pmp.end();
 
        // Set up new BG brush & zoom level (pixels per base unit)
        pmp.end();
 
        // Set up new BG brush & zoom level (pixels per base unit)
-       Painter::zoom = gridPixels / gridSpacing;
+//     Painter::zoom = gridPixels / gridSpacing;
+       Painter::zoom = gridPixels / Object::gridSpacing;
        UpdateGridBackground();
 }
 
        UpdateGridBackground();
 }
 
@@ -282,6 +284,7 @@ QPoint DrawingView::GetAdjustedClientPosition(int x, int y)
 }
 
 
 }
 
 
+#if 0
 //
 // This looks strange, but it's really quite simple: We want a point that's
 // more than half-way to the next grid point to snap there while conversely we
 //
 // This looks strange, but it's really quite simple: We want a point that's
 // more than half-way to the next grid point to snap there while conversely we
@@ -300,6 +303,7 @@ Vector DrawingView::SnapPointToGrid(Vector point)
        point *= gridSpacing;
        return point;
 }
        point *= gridSpacing;
        return point;
 }
+#endif
 
 
 void DrawingView::paintEvent(QPaintEvent * /*event*/)
 
 
 void DrawingView::paintEvent(QPaintEvent * /*event*/)
@@ -375,9 +379,13 @@ So, how to fix this? Have the Object check itself?
 Maybe we can fix this by having the initial point not be snapped, but when there's
 a drag, we substitute the snapped point 'oldPoint' which the Object keeps track of
 internally to know how far it was dragged...
 Maybe we can fix this by having the initial point not be snapped, but when there's
 a drag, we substitute the snapped point 'oldPoint' which the Object keeps track of
 internally to know how far it was dragged...
+
+Now we do... :-/
 */
 */
+#if 0
                if (Object::snapToGrid)
                if (Object::snapToGrid)
-                       point = SnapPointToGrid(point);
+                       point = Object::SnapPointToGrid(point);
+#endif
 
                collided = document.Collided(point);
 
 
                collided = document.Collided(point);
 
@@ -427,25 +435,11 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
        }
 
        // Grid processing...
        }
 
        // Grid processing...
-#if 1
        if ((event->buttons() & Qt::LeftButton) && Object::snapToGrid)
        {
        if ((event->buttons() & Qt::LeftButton) && Object::snapToGrid)
        {
-#if 0
-               point += gridSpacing / 2.0;                                     // *This* adds to Z!!!
-               point /= gridSpacing;
-//200% is ok, gridSpacing = 6 in this case...
-//won't run into problems until gridSpacing = 1.5 (zoom = 800%)
-//run into problems with this approach: when zoom level is 200% this truncates to
-//integers, which is *not* what's wanted here...
-               point.x = floor(point.x);//need to fix this for negative numbers...
-               point.y = floor(point.y);
-               point.z = 0;                                                            // Make *sure* Z doesn't go anywhere!!!
-               point *= gridSpacing;
-#else
-               point = SnapPointToGrid(point);
-#endif
+               point = Object::SnapPointToGrid(point);
        }
        }
-#endif
+
        oldPoint = point;
 //we should keep track of the last point here and only pass this down *if* the point
 //changed...
        oldPoint = point;
 //we should keep track of the last point here and only pass this down *if* the point
 //changed...
@@ -458,7 +452,7 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
        {
                if (Object::snapToGrid)
                {
        {
                if (Object::snapToGrid)
                {
-                       point = SnapPointToGrid(point);
+                       point = Object::SnapPointToGrid(point);
                        oldPoint = point;
                }
 
                        oldPoint = point;
                }