]> Shamusworld >> Repos - architektonas/commitdiff
Fix tool handling and circle highlighting.
authorShamus Hammons <jlhamm@acm.org>
Thu, 27 Jun 2013 21:44:27 +0000 (16:44 -0500)
committerShamus Hammons <jlhamm@acm.org>
Thu, 27 Jun 2013 21:44:27 +0000 (16:44 -0500)
src/applicationwindow.cpp
src/circle.cpp
src/dimension.cpp
src/dimension.h
src/drawdimensionaction.cpp
src/drawingview.cpp
src/drawingview.h
src/ellipse.h

index 0911b8e3742881eba036979b353391346339136c..20387318f1f5d24fb022dffad04cf379e891b198 100644 (file)
@@ -346,8 +346,19 @@ void ApplicationWindow::SetInternalToolStates(void)
        Object::SetDeleteActive(deleteAct->isChecked());
        Object::SetDimensionActive(addDimensionAct->isChecked());
        drawing->SetRotateToolActive(rotateAct->isChecked());
+
+       // We can be sure that if we've come here, then either an active tool is
+       // being deactivated, or a new tool is being created. In either case, the
+       // old tool needs to be deleted.
+       if (drawing->toolAction)
+       {
+               delete drawing->toolAction;
+               drawing->toolAction = NULL;
+       }
+
        drawing->SetAddLineToolActive(addLineAct->isChecked());
        drawing->SetAddCircleToolActive(addCircleAct->isChecked());
+       drawing->SetAddDimensionToolActive(addDimensionAct->isChecked());
 }
 
 
index af8f91f3be2c152bf4c906d4ed3dd767f2e0054c..0780f6258bc32f67a94e3d097a5a797f3d6094c1 100644 (file)
@@ -127,10 +127,20 @@ bool Circle::HitTest(Point point)
 Document passes in the correct Cartesian coordinates being pointed to by the mouse.
 So all we have to be concerned with is properly scaling our hot zones/handle sizes,
 since we generally *don't* want those to scale with the zoom level. ;-)
+
+What is going on here?
+If we're zoomed out to, say, 50%, & our radius is 10.0 (absolute), then on screen
+the radius will be 5.0. By multiplying the length by the zoom factor, we align our
+pointed at length with our on screen length.
 */
-       if (length < 8.0)
+       if ((length * Painter::zoom) < 8.0)
                hitCenter = true;
-       else if ((length < (radius + 2.0)) && (length > (radius - 2.0)))
+//wrong:       else if ((length < (radius + 2.0)) && (length > (radius - 2.0)))
+/*NB: The following should be identical to what we have down below, but it doesn't work out that way... :-P */
+//close, but no        else if (((length * Painter::zoom) < ((radius * Painter::zoom) + 2.0)) && ((length * Painter::zoom) > ((radius * Painter::zoom) - 2.0)))
+//really wrong!        else if (((length * Painter::zoom) < (radius + 2.0)) && ((length * Painter::zoom) > (radius - 2.0)))
+// close again, but sill no    else if (((length * Painter::zoom) < ((radius + 2.0) * Painter::zoom)) && ((length * Painter::zoom) > ((radius - 2.0) * Painter::zoom)))
+       else if ((fabs(length - radius) * Painter::zoom) < 2.0)
                hitCircle = true;
 
        return StateChanged();
index eb978fdb0cc50807782662b583ffdce1606d2d2a..2107d67865e34c12fa0fa7feb8bde2f089e24b25 100644 (file)
@@ -344,19 +344,19 @@ about keeping track of old states...
 /*virtual*/ void Dimension::Disconnect(Object * obj, double param)
 {
        if (point1.object == obj && point1.t == param)
-               point1 = NULL;
+               point1.object = NULL;
        else if (point2.object == obj && point2.t == param)
-               point2 = NULL;
+               point2.object = NULL;
 }
 
 
 /*virtual*/ void Dimension::DisconnectAll(Object * obj)
 {
        if (point1.object == obj)
-               point1 = NULL;
+               point1.object = NULL;
 
        if (point2.object == obj)
-               point2 = NULL;
+               point2.object = NULL;
 }
 
 
index 2784e83bb3a9f8271844a03df89e1cf01e08aa15..4fbcaa8054a379069006ddd3cb2e498e302e06a4 100644 (file)
@@ -4,7 +4,7 @@
 #include "connection.h"
 #include "object.h"
 
-enum DimensionType { DTLinear, DTRadial, DTDiametric, DTCircumferential, DTLeader };
+enum DimensionType { DTLinear, DTLinearVert, DTLinearHorz, DTRadial, DTDiametric, DTCircumferential, DTAngular, DTLeader };
 
 class Dimension: public Object
 {
@@ -39,7 +39,7 @@ class Dimension: public Object
                DimensionType type;
 
                // We use these in lieu of the built-in connected[] array; no reason to
-               // do this way especially
+               // do it this way especially
                Connection point1;
                Connection point2;
 };
index 2414afa107285fd8e5b2238a07c80f42dfaed7e3..58fa09595028e0e884c54b52cf62073edff64492 100644 (file)
@@ -78,10 +78,12 @@ DrawDimensionAction::~DrawDimensionAction()
                // We create the new object here, and then pass it off to the
                // DrawingView which stuffs it into the document.
 //             line = new Line(p1, p2);
+               dimension = new Dimension(p1, p2);
                // We don't need no stinkin' sentinels, when we have signals & slots!
                emit ObjectReady(dimension);
 
-               p1 = p2;
+               state = FIRST_POINT;
+//             p1 = p2;
        }
 }
 
index 3f27f96f84c5284b24d7efb5b06f67e7f32c14a8..330f73377540c8e96c9cd2388f0888344534dfde 100644 (file)
@@ -35,6 +35,7 @@
 #include "circle.h"
 #include "dimension.h"
 #include "drawcircleaction.h"
+#include "drawdimensionaction.h"
 #include "drawlineaction.h"
 #include "line.h"
 #include "painter.h"
@@ -48,7 +49,8 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
        document(Vector(0, 0)),
 //     gridSpacing(32.0), collided(false), rotateTool(false), rx(150.0), ry(150.0),
        gridSpacing(12.0), collided(false), rotateTool(false), rx(150.0), ry(150.0),
-       scrollDrag(false), addLineTool(false), toolAction(NULL)
+       scrollDrag(false), addLineTool(false), addCircleTool(false),
+       addDimensionTool(false), toolAction(NULL)
 {
        setBackgroundRole(QPalette::Base);
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@@ -102,58 +104,54 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
        UpdateGridBackground();
 }
 
+
 void DrawingView::SetRotateToolActive(bool state/*= true*/)
 {
        rotateTool = state;
        update();
 }
 
+
 void DrawingView::SetAddLineToolActive(bool state/*= true*/)
 {
-       if (state)// && toolAction == NULL)
+       if (state)
        {
-               if (toolAction)
-                       delete toolAction;
-
-               addCircleTool = false;
                toolAction = new DrawLineAction();
                connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
                        SLOT(AddNewObjectToDocument(Object *)));
        }
-       else if (!state && addLineTool && toolAction)
-       {
-               delete toolAction;
-               toolAction = NULL;
-       }
 
-       addLineTool = state;
        update();
 //printf("DrawingView::SetAddLineToolActive(). toolAction=%08X\n", toolAction);
 }
 
+
 void DrawingView::SetAddCircleToolActive(bool state/*= true*/)
 {
-       if (state)// && toolAction == NULL)
+       if (state)
        {
-               if (toolAction)
-                       delete toolAction;
-
-               addLineTool = false;
                toolAction = new DrawCircleAction();
                connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
                        SLOT(AddNewObjectToDocument(Object *)));
        }
-       else if (!state && addCircleTool && toolAction)
+
+       update();
+}
+
+
+void DrawingView::SetAddDimensionToolActive(bool state/*= true*/)
+{
+       if (state)
        {
-               delete toolAction;
-               toolAction = NULL;
+               toolAction = new DrawDimensionAction();
+               connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
+                       SLOT(AddNewObjectToDocument(Object *)));
        }
 
-       addCircleTool = state;
        update();
-//printf("DrawingView::SetAddCircleToolActive(). toolAction=%08X\n", toolAction);
 }
 
+
 void DrawingView::UpdateGridBackground(void)
 {
 #if 0
@@ -194,6 +192,7 @@ setPalette(pal);
 #endif
 }
 
+
 void DrawingView::AddNewObjectToDocument(Object * object)
 {
        if (object)
@@ -205,6 +204,7 @@ void DrawingView::AddNewObjectToDocument(Object * object)
 //printf("DrawingView::AddNewObjectToDocument(). object=%08X\n", object);
 }
 
+
 QPoint DrawingView::GetAdjustedMousePosition(QMouseEvent * event)
 {
        // This is undoing the transform, e.g. going from client coords to local coords.
@@ -213,6 +213,7 @@ QPoint DrawingView::GetAdjustedMousePosition(QMouseEvent * event)
        return QPoint(offsetX + event->x(), offsetY + (size().height() - event->y()));
 }
 
+
 QPoint DrawingView::GetAdjustedClientPosition(int x, int y)
 {
        // VOODOO ALERT (ON Y COMPONENT!!!!) (eh?)
@@ -221,6 +222,7 @@ QPoint DrawingView::GetAdjustedClientPosition(int x, int y)
        return QPoint(-offsetX + x, (size().height() - (-offsetY + y)) * +1.0);
 }
 
+
 void DrawingView::paintEvent(QPaintEvent * /*event*/)
 {
        QPainter qtPainter(this);
@@ -280,6 +282,7 @@ void DrawingView::paintEvent(QPaintEvent * /*event*/)
                toolAction->Draw(&painter);
 }
 
+
 void DrawingView::mousePressEvent(QMouseEvent * event)
 {
        if (event->button() == Qt::LeftButton)
@@ -302,6 +305,7 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
        }
 }
 
+
 void DrawingView::mouseMoveEvent(QMouseEvent * event)
 {
        Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y()));
@@ -358,6 +362,7 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
        }
 }
 
+
 void DrawingView::mouseReleaseEvent(QMouseEvent * event)
 {
        if (event->button() == Qt::LeftButton)
@@ -380,3 +385,4 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event)
                setCursor(Qt::ArrowCursor);
        }
 }
+
index b8f1760230700ecdb00d06c6b251c713397aa25f..ac7170d026bd63c44a65a23caa4a4c83005a4a94 100644 (file)
@@ -17,6 +17,7 @@ class DrawingView: public QWidget
                void SetRotateToolActive(bool state = true);
                void SetAddLineToolActive(bool state = true);
                void SetAddCircleToolActive(bool state = true);
+               void SetAddDimensionToolActive(bool state = true);
                void UpdateGridBackground(void);
 
        public slots:
@@ -52,25 +53,10 @@ class DrawingView: public QWidget
                Vector oldPoint;
                bool addLineTool;
                bool addCircleTool;
-               Action * toolAction;
-/*             QSize minimumSizeHint() const;
-               QSize sizeHint() const;
-
-       private:
-               void CreateCursors(void);
-               QPoint GetAdjustedMousePosition(QMouseEvent * event);
-               QPoint GetAdjustedClientPosition(int x, int y);
-
-               QImage image;
-               QPoint pt, ptOffset, ptPrevious;
-               ToolType tool;                                                  // Current tool
-               GlyphPoints pts;                                                // Glyph point structure
-               int32 ptHighlight, oldPtHighlight, ptNextHighlight, oldPtNextHighlight;
-               bool polyFirstPoint;
+               bool addDimensionTool;
 
-               ToolWindow * toolPalette;
-               QCursor cur[8];
-*/
+       public:
+               Action * toolAction;
 };
 
 #endif // __DRAWINGVIEW_H__
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..b200f78027c8e2f042cbc3547412fac371035e97 100644 (file)
@@ -0,0 +1,10 @@
+/*
+An ellipse is just a variant of a circle, do we really need a separate class
+for them?
+
+We have a separate class for arcs, and those are circle variants too.
+
+Maybe. The ellipse (and elliptical arc) have two focii and a rotation angle.
+But there's no reason why those extras couldn't go into the Circle class as
+well.
+*/