]> Shamusworld >> Repos - architektonas/commitdiff
Added action for adding circles to the drawing.
authorShamus Hammons <jlhamm@acm.org>
Wed, 1 Feb 2012 21:13:04 +0000 (21:13 +0000)
committerShamus Hammons <jlhamm@acm.org>
Wed, 1 Feb 2012 21:13:04 +0000 (21:13 +0000)
22 files changed:
architektonas.pro
src/about.cpp
src/action.cpp
src/applicationwindow.cpp
src/applicationwindow.h
src/arc.cpp
src/circle.cpp
src/container.cpp
src/dimension.cpp
src/drawcircleaction.cpp [new file with mode: 0644]
src/drawcircleaction.h [new file with mode: 0644]
src/drawingview.cpp
src/drawingview.h
src/drawlineaction.cpp
src/generaltab.cpp
src/line.cpp
src/main.cpp
src/mathconstants.h
src/object.cpp
src/painter.cpp
src/settingsdialog.cpp
src/vector.cpp

index e16b0dbd8b490f024202f88c3c28cd5c958b1a7e..1878d400088b431399cef62a9e276ccc09e2a5b4 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Architektonas Qt project file
 #
-# by James L. Hammons
+# by James Hammons
 # Copyright (C) 2011 Underground Software
 #
 # See the README and GPLv3 files for licensing and warranty information
@@ -49,6 +49,7 @@ HEADERS = \
        src/container.h \
        src/dimension.h \
        src/drawingview.h \
+       src/drawcircleaction.h \
        src/drawlineaction.h \
        src/generaltab.h \
        src/line.h \
@@ -68,6 +69,7 @@ SOURCES = \
        src/container.cpp \
        src/dimension.cpp \
        src/drawingview.cpp \
+       src/drawcircleaction.cpp \
        src/drawlineaction.cpp \
        src/generaltab.cpp \
        src/line.cpp \
index cef694e3fba0571efe39a40f94a54948ed98fbc7..acf06163b87fe87b6dbdb967e716a4dee63a7a65 100644 (file)
@@ -1,10 +1,10 @@
 //
 // about.cpp - Credits
 //
-// by James L. Hammons
+// by James Hammons
 // (C) 2011 Underground Software
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // Who  When        What
 // ---  ----------  -------------------------------------------------------------
@@ -68,8 +68,8 @@ AboutWindow::AboutWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog)
                "<tr><td align='right' width='100'><b>Architektonas: </b></td><td>Free, <i>Industrial Strength</i> 2D Computer Aided Design</td></tr>"
                "<tr><td align='right'><b>Version: </b></td><td>1.0.0</td></tr>"
                "<tr><td align='right'><b>License: </b></td><td>GPL v3 or later</td></tr>"
-               "<tr><td align='right'><b>Chief Architect: </b></td><td>James L. Hammons (shamus)</td></tr>"
-               "<tr><td align='right'><b>Coders: </b></td><td>James L. Hammons (shamus)</td></tr>"
+               "<tr><td align='right'><b>Chief Architect: </b></td><td>James Hammons (shamus)</td></tr>"
+               "<tr><td align='right'><b>Coders: </b></td><td>James Hammons (shamus)</td></tr>"
 //             "<tr><td align='right'><b>Testers: </b></td><td>shamus</td></tr>"
                "<tr><td align='right'><b>Homepage: </b></td><td>http://shamusworld.gotdns.org/architektonas/</td></tr>"
                "</table>"
index d2862994a97e41421221025550959a1a63c4884d..817e1a034be0ae15218b565253bba40ce8a0e07b 100644 (file)
@@ -4,7 +4,7 @@
 // (C) 2011 Underground Software
 // See the README and GPLv3 files for licensing and warranty information
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
index 23374171066c7ac90c2aa9f4d5e87ca641b777cf..8e7891c613ed8e7691fde9e30d905358f5a1040f 100644 (file)
@@ -5,7 +5,7 @@
 // (C) 2011 Underground Software
 // See the README and GPLv3 files for licensing and warranty information
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // Who  When        What
 // ---  ----------  -------------------------------------------------------------
@@ -112,6 +112,15 @@ void ApplicationWindow::AddLineTool(void)
        drawing->SetAddLineToolActive(addLineAct->isChecked());
 }
 
+void ApplicationWindow::AddCircleTool(void)
+{
+       addLineAct->setChecked(false);
+       addArcAct->setChecked(false);
+       rotateAct->setChecked(false);
+       RotateTool();
+       drawing->SetAddCircleToolActive(addCircleAct->isChecked());
+}
+
 void ApplicationWindow::ZoomInTool(void)
 {
        double zoomFactor = 2.0;
@@ -217,6 +226,7 @@ void ApplicationWindow::CreateActions(void)
        connect(addLineAct, SIGNAL(triggered()), this, SLOT(AddLineTool()));
 
        addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds circles to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence("A,C"), true);
+       connect(addCircleAct, SIGNAL(triggered()), this, SLOT(AddCircleTool()));
 
        addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds arcs to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence("A,A"), true);
 
index a68cee9c1880ecf93187187bc7413d8918b05df9..21d4c8dde252016a849301a38ef9e6389f4cf692 100644 (file)
@@ -29,6 +29,7 @@ class ApplicationWindow: public QMainWindow
                void DimensionTool(void);
                void RotateTool(void);
                void AddLineTool(void);
+               void AddCircleTool(void);
                void ZoomInTool(void);
                void ZoomOutTool(void);
                void HelpAbout(void);
index 925676d3f2bb148b22970dc1b9b0fd57795cb6f9..77c1ce942075772ece9e951e7dda9f261f0890dd 100644 (file)
@@ -4,7 +4,7 @@
 // (C) 2011 Underground Software
 // See the README and GPLv3 files for licensing and warranty information
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
index 35c9d7c2e53f224dd97323229027b37c246ce88a..9233f3e1c281dfb46470d12ba31070a808a6db14 100644 (file)
@@ -4,7 +4,7 @@
 // (C) 2011 Underground Software
 // See the README and GPLv3 files for licensing and warranty information
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
index b69a6e3ce679c155c2ddd4ea26d9d40a1764c7ed..e125672eac63c6690d4d1cbc4da044e08a9e6ee7 100644 (file)
@@ -4,7 +4,7 @@
 // (C) 2011 Underground Software
 // See the README and GPLv3 files for licensing and warranty information
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
index 4ccd48e52352e97ad69938f3873b0090221fc11e..9ba0ed5a0b82638e67e4705b75d777add76129da 100644 (file)
@@ -4,7 +4,7 @@
 // (C) 2011 Underground Software
 // See the README and GPLv3 files for licensing and warranty information
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
diff --git a/src/drawcircleaction.cpp b/src/drawcircleaction.cpp
new file mode 100644 (file)
index 0000000..fad3158
--- /dev/null
@@ -0,0 +1,82 @@
+// drawcircleaction.cpp: Action class for drawing circles
+//
+// Part of the Architektonas Project
+// (C) 2012 Underground Software
+// See the README and GPLv3 files for licensing and warranty information
+//
+// JLH = James Hammons <jlhamm@acm.org>
+//
+// WHO  WHEN        WHAT
+// ---  ----------  ------------------------------------------------------------
+// JLH  02/01/2012  Created this file
+//
+
+#include "drawcircleaction.h"
+#include "circle.h"
+#include "painter.h"
+#include "vector.h"
+
+
+#define FIRST_POINT 0
+#define NEXT_POINT 1
+
+
+DrawCircleAction::DrawCircleAction(): state(0), circle(NULL)
+{
+}
+
+DrawCircleAction::~DrawCircleAction()
+{
+}
+
+
+/*virtual*/ void DrawCircleAction::Draw(Painter * painter)
+{
+       // Need to fix pen colors, etc...
+       // I think stuff like crosshairs should be done in the DrawingView, tho
+       if (state == FIRST_POINT)
+       {
+               painter->DrawPoint(p1.x, p1.y);
+       }
+       else
+       {
+               double radius = Vector::Magnitude(p1, p2);
+               painter->DrawEllipse(p1, radius, radius);
+       }
+}
+
+/*virtual*/ void DrawCircleAction::MouseDown(Vector point)
+{
+       if (state == FIRST_POINT)
+               p1 = point;
+       else
+               p2 = point;
+}
+
+/*virtual*/ void DrawCircleAction::MouseMoved(Vector point)
+{
+       if (state == FIRST_POINT)
+               p1 = point;
+       else
+               p2 = point;
+}
+
+/*virtual*/ void DrawCircleAction::MouseReleased(void)
+{
+       if (state == FIRST_POINT)
+       {
+               p2 = p1;
+               state = NEXT_POINT;
+       }
+       else if (state == NEXT_POINT)
+       {
+               // We create the new object here, and then pass it off to the
+               // DrawingView which stuffs it into the document.
+               circle = new Circle(p1, Vector::Magnitude(p1, p2));
+               // We don't need no stinkin' sentinels, when we have signals & slots!
+               emit ObjectReady(circle);
+
+               state = FIRST_POINT;
+               p1 = p2;
+       }
+}
diff --git a/src/drawcircleaction.h b/src/drawcircleaction.h
new file mode 100644 (file)
index 0000000..d989e45
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef __DRAWCIRCLEACTION_H__
+#define __DRAWCIRCLEACTION_H__
+
+#include "action.h"
+
+class Circle;
+
+class DrawCircleAction: public Action
+{
+       public:
+               DrawCircleAction();
+               ~DrawCircleAction();
+
+               virtual void Draw(Painter *);
+               virtual void MouseDown(Vector);
+               virtual void MouseMoved(Vector);
+               virtual void MouseReleased(void);
+
+       private:
+               int state;
+               Circle * circle;
+               Vector p1, p2;
+};
+
+#endif // __DRAWCIRCLEACTION_H__
index a214f02fd901d4b0d339bd3dca571be9dd810044..f5ff2e35a5adaf917a0f3ec83ee15eb1d168a7b9 100644 (file)
@@ -4,7 +4,7 @@
 // (C) 2011 Underground Software
 // See the README and GPLv3 files for licensing and warranty information
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // Who  When        What
 // ---  ----------  -------------------------------------------------------------
@@ -34,6 +34,7 @@
 #include "arc.h"
 #include "circle.h"
 #include "dimension.h"
+#include "drawcircleaction.h"
 #include "drawlineaction.h"
 #include "line.h"
 #include "painter.h"
@@ -100,6 +101,25 @@ void DrawingView::SetAddLineToolActive(bool state/*= true*/)
 //printf("DrawingView::SetAddLineToolActive(). toolAction=%08X\n", toolAction);
 }
 
+void DrawingView::SetAddCircleToolActive(bool state/*= true*/)
+{
+       if (state && toolAction == NULL)
+       {
+               toolAction = new DrawCircleAction();
+               connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
+                       SLOT(AddNewObjectToDocument(Object *)));
+       }
+       else if (!state && toolAction)
+       {
+               delete toolAction;
+               toolAction = NULL;
+       }
+
+       addCircleTool = state;
+       update();
+//printf("DrawingView::SetAddLineToolActive(). toolAction=%08X\n", toolAction);
+}
+
 void DrawingView::AddNewObjectToDocument(Object * object)
 {
        if (object)
index e8dc3af86c1522d61b2244f9f4bf7d6bd55e5bc1..f11bf152260d2d86a842dfaabdb926700fe6686f 100644 (file)
@@ -16,6 +16,7 @@ class DrawingView: public QWidget
        public:
                void SetRotateToolActive(bool state = true);
                void SetAddLineToolActive(bool state = true);
+               void SetAddCircleToolActive(bool state = true);
 
        public slots:
                void AddNewObjectToDocument(Object *);
@@ -45,6 +46,7 @@ class DrawingView: public QWidget
                bool scrollDrag;
                Vector oldPoint;
                bool addLineTool;
+               bool addCircleTool;
                Action * toolAction;
 /*             QSize minimumSizeHint() const;
                QSize sizeHint() const;
index 65b9fc1b85e6ced0bb085e53840cd44fda222e05..ffa2e7eaea35c71cd39ca24be6c9dbe785860eb7 100644 (file)
@@ -4,7 +4,7 @@
 // (C) 2011 Underground Software
 // See the README and GPLv3 files for licensing and warranty information
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
index ebe36cb5d6aaf3909609e9611395557b17aba4b1..7b18549619638885984e9e5fd77100ecce764c69 100644 (file)
@@ -5,7 +5,7 @@
 // (C) 2011 Underground Software
 // See the README and GPLv3 files for licensing and warranty information
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
index 2e3539f7b0cfa510045ce1569c1139578b304d1e..2ffb03ff0addf1cda99dfbd343914c24b8b125ad 100644 (file)
@@ -4,7 +4,7 @@
 // (C) 2011 Underground Software
 // See the README and GPLv3 files for licensing and warranty information
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
index 3a1e633b80f86132afead4991942c7d5f617bd37..00643e10033aed347eb47caeef8233561839eea4 100644 (file)
@@ -5,7 +5,7 @@
 // (C) 2011 Underground Software
 // See the README and GPLv3 files for licensing and warranty information
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // Who  When        What
 // ---  ----------  -------------------------------------------------------------
index c97249cd7491731af251e54028d023c7ce83f4bd..78d7d7021f928257ec472db39b8677634d4bc00f 100644 (file)
@@ -7,7 +7,7 @@
 // NOTE: Since this has no code associated with it, there is no corresponding
 //       .cpp file.
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
index e38e6614ba353d4f7cd8102abdc7a19657c0b70d..03d1f70eb47565271e7ac94070e29ea0834c2eed 100644 (file)
@@ -5,7 +5,7 @@
 // (C) 2011 Underground Software
 // See the README and GPLv3 files for licensing and warranty information
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
index 8fe59ab9ad64720bd06d901b662d602ccf052c2c..0dfdf3c76471920a33ae7e679524f80bc8ebd73a 100644 (file)
@@ -5,7 +5,7 @@
 // (C) 2011 Underground Software
 // See the README and GPLv3 files for licensing and warranty information
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
@@ -100,6 +100,9 @@ void Painter::SetPen(QPen pen)
 
 void Painter::DrawAngledText(Vector center, double angle, QString text)
 {
+       if (!painter)
+               return;
+
        // Strategy: Since Qt doesn't have any rotated text drawing functions,
        // we instead translate the origin to the center of the text to be drawn and
        // then rotate the frame to the desired angle.
@@ -114,20 +117,27 @@ void Painter::DrawAngledText(Vector center, double angle, QString text)
        // Need to figure out if dimensions are always rendered at one size regardless of zoom,
        // or if they have a definite size, and are thus zoomable.
        // If zoomable, this is incorrect:
-       int yOffset = -12;
+       // (Added zoom, so this is correct now :-)
+       int yOffset = -12 * zoom;
 
        // Fix text so it isn't upside down...
        if ((angle > PI * 0.5) && (angle < PI * 1.5))
        {
                angle += PI;
-               yOffset = 12;
+               yOffset = 12 * zoom;
        }
 
+#if 0
+       Vector offset = CartesianToQtCoords(Vector(0, yOffset));
+       textBox.translate(offset.x, offset.y);
+#else
        textBox.translate(0, yOffset);
+#endif
        painter->save();
        painter->translate(center.x, center.y);
        // Angles are backwards in the Qt coord system, so we flip ours...
        painter->rotate(-angle * RADIANS_TO_DEGREES);
+//Need to fix this so the text scales as well...
        painter->drawText(textBox, Qt::AlignCenter, text);
        painter->restore();
 }
index 94c61abd3ae4f99255ffec2da4131466e2fb1003..871f1f30dcc01b0d2ff9670dc51d17f44996a147 100644 (file)
@@ -5,7 +5,7 @@
 // (C) 2011 Underground Software
 // See the README and GPLv3 files for licensing and warranty information
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
index 58228ca39f75a7cfe9bb1b834dd8f19af4d24bf0..53cdbee39ceaba9938ab3b0c82375d640f712833 100644 (file)
@@ -1,7 +1,7 @@
 //\r
 // vector.cpp: Various structures used for 3 dimensional imaging\r
 //\r
-// by James L. Hammons\r
+// by James Hammons\r
 // (C) 2006 Underground Software\r
 //\r
 // JLH = James L. Hammons <jlhamm@acm.org>\r