]> Shamusworld >> Repos - architektonas/blobdiff - src/drawingview.cpp
Added ability to drag objects to Line endpoints.
[architektonas] / src / drawingview.cpp
index a86e857880402542b3bdf4d53c16d4bb8133f4e7..9fb0332a2ff9ccc5b327f460fafbc21435bebc39 100644 (file)
@@ -56,7 +56,6 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 
        Global::gridSpacing = 12.0;             // In base units (inch is default)
-
 #if 0
        Line * line = new Line(Vector(5, 5), Vector(50, 40), &document);
        document.Add(line);
@@ -1260,11 +1259,12 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
 
        // Do object hit testing...
        bool needUpdate = HitTestObjects(point);
+       GetHovered(hover);
 
        // Check for multi-hover...
        if (numHovered > 1)
        {
-               GetHovered(hover);
+//need to check for case where hover is over 2 circles and a 3rd's center...
                Object * obj1 = (Object *)hover[0], * obj2 = (Object *)hover[1];
 
                Geometry::Intersects(obj1, obj2);
@@ -1309,6 +1309,8 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
        {
                if (hoveringIntersection)
                        point = intersectionPoint;
+               else if (hoverPointValid)
+                       point = hoverPoint;
                else if (Global::snapToGrid)
                        point = SnapPointToGrid(point);
 
@@ -1323,6 +1325,8 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
        {
                if (hoveringIntersection)
                        point = intersectionPoint;
+               else if (hoverPointValid)
+                       point = hoverPoint;
                else if (Global::snapToGrid)
                        point = SnapPointToGrid(point);
 
@@ -1678,6 +1682,7 @@ bool DrawingView::HitTestObjects(Point point)
        std::vector<void *>::iterator i;
        numHovered = 0;
        bool needUpdate = false;
+       hoverPointValid = false;
 
        for(i=document.objects.begin(); i!=document.objects.end(); i++)
        {
@@ -1728,9 +1733,17 @@ bool DrawingView::HitTest(Object * obj, Point point)
                                / lineSegment.Magnitude());
 
                if ((v1.Magnitude() * Global::zoom) < 8.0)
+               {
                        obj->hitPoint[0] = true;
+                       hoverPoint = obj->p[0];
+                       hoverPointValid = true;
+               }
                else if ((v2.Magnitude() * Global::zoom) < 8.0)
+               {
                        obj->hitPoint[1] = true;
+                       hoverPoint = obj->p[1];
+                       hoverPointValid = true;
+               }
                else if ((distance * Global::zoom) < 5.0)
                        obj->hitObject = true;