]> Shamusworld >> Repos - architektonas/blobdiff - src/drawingview.cpp
Added ability to drag objects to Line endpoints.
[architektonas] / src / drawingview.cpp
index a88be252f9df4b9e3fb011bb700f4316a544a302..9fb0332a2ff9ccc5b327f460fafbc21435bebc39 100644 (file)
@@ -93,7 +93,6 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
        document.objects.push_back(new Text(Vector(10, 83), "Here is some awesome text!"));
 #endif
 
-printf("Document topLevel = %s\n", (document.topLevel ? "true" : "false"));
 /*
 Here we set the grid size in pixels--12 in this case. Initially, we have our
 zoom set to make this represent 12 inches at a zoom factor of 25%. (This is
@@ -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;