From 043ecf4d074909ba2f7f53237962f9eaa72f19c2 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Wed, 1 Feb 2012 21:13:04 +0000 Subject: [PATCH] Added action for adding circles to the drawing. --- architektonas.pro | 4 +- src/about.cpp | 8 ++-- src/action.cpp | 2 +- src/applicationwindow.cpp | 12 +++++- src/applicationwindow.h | 1 + src/arc.cpp | 2 +- src/circle.cpp | 2 +- src/container.cpp | 2 +- src/dimension.cpp | 2 +- src/drawcircleaction.cpp | 82 +++++++++++++++++++++++++++++++++++++++ src/drawcircleaction.h | 25 ++++++++++++ src/drawingview.cpp | 22 ++++++++++- src/drawingview.h | 2 + src/drawlineaction.cpp | 2 +- src/generaltab.cpp | 2 +- src/line.cpp | 2 +- src/main.cpp | 2 +- src/mathconstants.h | 2 +- src/object.cpp | 2 +- src/painter.cpp | 16 ++++++-- src/settingsdialog.cpp | 2 +- src/vector.cpp | 2 +- 22 files changed, 175 insertions(+), 23 deletions(-) create mode 100644 src/drawcircleaction.cpp create mode 100644 src/drawcircleaction.h diff --git a/architektonas.pro b/architektonas.pro index e16b0db..1878d40 100644 --- a/architektonas.pro +++ b/architektonas.pro @@ -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 \ diff --git a/src/about.cpp b/src/about.cpp index cef694e..acf0616 100644 --- a/src/about.cpp +++ b/src/about.cpp @@ -1,10 +1,10 @@ // // about.cpp - Credits // -// by James L. Hammons +// by James Hammons // (C) 2011 Underground Software // -// JLH = James L. Hammons +// JLH = James Hammons // // Who When What // --- ---------- ------------------------------------------------------------- @@ -68,8 +68,8 @@ AboutWindow::AboutWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog) "Architektonas: Free, Industrial Strength 2D Computer Aided Design" "Version: 1.0.0" "License: GPL v3 or later" - "Chief Architect: James L. Hammons (shamus)" - "Coders: James L. Hammons (shamus)" + "Chief Architect: James Hammons (shamus)" + "Coders: James Hammons (shamus)" // "Testers: shamus" "Homepage: http://shamusworld.gotdns.org/architektonas/" "" diff --git a/src/action.cpp b/src/action.cpp index d286299..817e1a0 100644 --- a/src/action.cpp +++ b/src/action.cpp @@ -4,7 +4,7 @@ // (C) 2011 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James L. Hammons +// JLH = James Hammons // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ diff --git a/src/applicationwindow.cpp b/src/applicationwindow.cpp index 2337417..8e7891c 100644 --- a/src/applicationwindow.cpp +++ b/src/applicationwindow.cpp @@ -5,7 +5,7 @@ // (C) 2011 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James L. Hammons +// JLH = James Hammons // // 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); diff --git a/src/applicationwindow.h b/src/applicationwindow.h index a68cee9..21d4c8d 100644 --- a/src/applicationwindow.h +++ b/src/applicationwindow.h @@ -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); diff --git a/src/arc.cpp b/src/arc.cpp index 925676d..77c1ce9 100644 --- a/src/arc.cpp +++ b/src/arc.cpp @@ -4,7 +4,7 @@ // (C) 2011 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James L. Hammons +// JLH = James Hammons // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ diff --git a/src/circle.cpp b/src/circle.cpp index 35c9d7c..9233f3e 100644 --- a/src/circle.cpp +++ b/src/circle.cpp @@ -4,7 +4,7 @@ // (C) 2011 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James L. Hammons +// JLH = James Hammons // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ diff --git a/src/container.cpp b/src/container.cpp index b69a6e3..e125672 100644 --- a/src/container.cpp +++ b/src/container.cpp @@ -4,7 +4,7 @@ // (C) 2011 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James L. Hammons +// JLH = James Hammons // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ diff --git a/src/dimension.cpp b/src/dimension.cpp index 4ccd48e..9ba0ed5 100644 --- a/src/dimension.cpp +++ b/src/dimension.cpp @@ -4,7 +4,7 @@ // (C) 2011 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James L. Hammons +// JLH = James Hammons // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ diff --git a/src/drawcircleaction.cpp b/src/drawcircleaction.cpp new file mode 100644 index 0000000..fad3158 --- /dev/null +++ b/src/drawcircleaction.cpp @@ -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 +// +// 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 index 0000000..d989e45 --- /dev/null +++ b/src/drawcircleaction.h @@ -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__ diff --git a/src/drawingview.cpp b/src/drawingview.cpp index a214f02..f5ff2e3 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -4,7 +4,7 @@ // (C) 2011 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James L. Hammons +// JLH = James Hammons // // 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) diff --git a/src/drawingview.h b/src/drawingview.h index e8dc3af..f11bf15 100644 --- a/src/drawingview.h +++ b/src/drawingview.h @@ -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; diff --git a/src/drawlineaction.cpp b/src/drawlineaction.cpp index 65b9fc1..ffa2e7e 100644 --- a/src/drawlineaction.cpp +++ b/src/drawlineaction.cpp @@ -4,7 +4,7 @@ // (C) 2011 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James L. Hammons +// JLH = James Hammons // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ diff --git a/src/generaltab.cpp b/src/generaltab.cpp index ebe36cb..7b18549 100644 --- a/src/generaltab.cpp +++ b/src/generaltab.cpp @@ -5,7 +5,7 @@ // (C) 2011 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James L. Hammons +// JLH = James Hammons // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ diff --git a/src/line.cpp b/src/line.cpp index 2e3539f..2ffb03f 100644 --- a/src/line.cpp +++ b/src/line.cpp @@ -4,7 +4,7 @@ // (C) 2011 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James L. Hammons +// JLH = James Hammons // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ diff --git a/src/main.cpp b/src/main.cpp index 3a1e633..00643e1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,7 +5,7 @@ // (C) 2011 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James L. Hammons +// JLH = James Hammons // // Who When What // --- ---------- ------------------------------------------------------------- diff --git a/src/mathconstants.h b/src/mathconstants.h index c97249c..78d7d70 100644 --- a/src/mathconstants.h +++ b/src/mathconstants.h @@ -7,7 +7,7 @@ // NOTE: Since this has no code associated with it, there is no corresponding // .cpp file. // -// JLH = James L. Hammons +// JLH = James Hammons // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ diff --git a/src/object.cpp b/src/object.cpp index e38e661..03d1f70 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -5,7 +5,7 @@ // (C) 2011 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James L. Hammons +// JLH = James Hammons // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ diff --git a/src/painter.cpp b/src/painter.cpp index 8fe59ab..0dfdf3c 100644 --- a/src/painter.cpp +++ b/src/painter.cpp @@ -5,7 +5,7 @@ // (C) 2011 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James L. Hammons +// JLH = James Hammons // // 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(); } diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 94c61ab..871f1f3 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -5,7 +5,7 @@ // (C) 2011 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James L. Hammons +// JLH = James Hammons // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ diff --git a/src/vector.cpp b/src/vector.cpp index 58228ca..53cdbee 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -1,7 +1,7 @@ // // vector.cpp: Various structures used for 3 dimensional imaging // -// by James L. Hammons +// by James Hammons // (C) 2006 Underground Software // // JLH = James L. Hammons -- 2.37.2