HEADERS = \
src/about.h \
+ src/action.h \
src/applicationwindow.h \
src/arc.h \
src/circle.h \
src/container.h \
src/dimension.h \
src/drawingview.h \
+ src/drawlineaction.h \
src/generaltab.h \
src/line.h \
src/main.h \
SOURCES = \
src/about.cpp \
+ src/action.cpp \
src/applicationwindow.cpp \
src/arc.cpp \
src/circle.cpp \
src/container.cpp \
src/dimension.cpp \
src/drawingview.cpp \
+ src/drawlineaction.cpp \
src/generaltab.cpp \
src/line.cpp \
src/main.cpp \
--- /dev/null
+// action.cpp: Action base class
+//
+// Part of the Architektonas Project
+// (C) 2011 Underground Software
+// See the README and GPLv3 files for licensing and warranty information
+//
+// JLH = James L. Hammons <jlhamm@acm.org>
+//
+// WHO WHEN WHAT
+// --- ---------- ------------------------------------------------------------
+// JLH 10/04/2011 Created this file
+//
+
+#include "action.h"
+
+Action::Action(): QObject()
+{
+}
+
+Action::~Action()
+{
+}
--- /dev/null
+#ifndef __ACTION_H__
+#define __ACTION_H__
+
+#include <QtCore>
+#include "vector.h"
+
+class Object;
+class Painter;
+
+class Action: public QObject
+{
+ Q_OBJECT
+
+ public:
+ Action();
+ ~Action();
+
+ // These are all pure virtual functions: Derived classes must define
+ // ALL of them.
+ virtual void Draw(Painter *) = 0;
+ virtual void MouseDown(Vector) = 0;
+ virtual void MouseMoved(Vector) = 0;
+ virtual void MouseReleased(void) = 0;
+
+ signals:
+ void ObjectReady(Object *);
+};
+
+#endif // __ACTION_H__
drawing->SetRotateToolActive(rotateAct->isChecked());
}
+void ApplicationWindow::AddLineTool(void)
+{
+ addCircleAct->setChecked(false);
+ addArcAct->setChecked(false);
+ rotateAct->setChecked(false);
+ RotateTool();
+ drawing->SetAddLineToolActive(addLineAct->isChecked());
+}
+
void ApplicationWindow::ZoomInTool(void)
{
double zoomFactor = 2.0;
addDimensionAct = CreateAction(tr("Add &Dimension"), tr("Add Dimension"), tr("Adds a dimension to the drawing."), QIcon(":/res/dimension-tool.png"), QKeySequence("D,I"), true);
connect(addDimensionAct, SIGNAL(triggered()), this, SLOT(DimensionTool()));
- addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds a line to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
+ addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds lines to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence("A,L"), true);
+ connect(addLineAct, SIGNAL(triggered()), this, SLOT(AddLineTool()));
- addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds a circle to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
+ addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds circles to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence("A,C"), true);
- addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds an arc to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
+ addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds arcs to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence("A,A"), true);
aboutAct = CreateAction(tr("About &Architektonas"), tr("About Architektonas"), tr("Gives information about this program."), QIcon(":/res/generic-tool.png"), QKeySequence());
connect(aboutAct, SIGNAL(triggered()), this, SLOT(HelpAbout()));
rotateAct = CreateAction(tr("&Rotate Objects"), tr("Rotate"), tr("Rotate object(s) around an arbitrary center."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("R,O")), true);
connect(rotateAct, SIGNAL(triggered()), this, SLOT(RotateTool()));
- zoomInAct = CreateAction2(tr("Zoom &In"), tr("Zoom In"), tr("Zoom in on the document."), QIcon(":/res/zoom-in.png"), QKeySequence(tr("+")), QKeySequence(tr("=")));
+ zoomInAct = CreateAction(tr("Zoom &In"), tr("Zoom In"), tr("Zoom in on the document."), QIcon(":/res/zoom-in.png"), QKeySequence(tr("+")), QKeySequence(tr("=")));
connect(zoomInAct, SIGNAL(triggered()), this, SLOT(ZoomInTool()));
zoomOutAct = CreateAction(tr("Zoom &Out"), tr("Zoom Out"), tr("Zoom out of the document."), QIcon(":/res/zoom-out.png"), QKeySequence(tr("-")));
// This is essentially the same as the previous function, but this allows more
// than one key sequence to be added as key shortcuts.
//
-QAction * ApplicationWindow::CreateAction2(QString name, QString tooltip, QString statustip,
+QAction * ApplicationWindow::CreateAction(QString name, QString tooltip, QString statustip,
QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable/*= false*/)
{
QAction * action = new QAction(icon, name, this);
void DeleteTool(void);
void DimensionTool(void);
void RotateTool(void);
+ void AddLineTool(void);
void ZoomInTool(void);
void ZoomOutTool(void);
void HelpAbout(void);
void CreateActions(void);
QAction * CreateAction(QString name, QString tooltip, QString statustip,
QIcon icon, QKeySequence key, bool checkable = false);
- QAction * CreateAction2(QString name, QString tooltip, QString statustip,
+ QAction * CreateAction(QString name, QString tooltip, QString statustip,
QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable = false);
void CreateMenus(void);
void CreateToolbars(void);
#include "arc.h"
#include "circle.h"
#include "dimension.h"
+#include "drawlineaction.h"
#include "line.h"
#include "painter.h"
scale(1.0), offsetX(-10), offsetY(-10),
document(Vector(0, 0)),
gridSpacing(32.0), collided(false), rotateTool(false), rx(150.0), ry(150.0),
- scrollDrag(false)
+ scrollDrag(false), addLineTool(false), toolAction(NULL)
{
setBackgroundRole(QPalette::Base);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// Alternate way to do the above...
line->SetDimensionOnLine();
#endif
+// connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
+// SLOT(AddNewObjectToDocument(Object *)));
}
void DrawingView::SetRotateToolActive(bool state/*= true*/)
update();
}
+void DrawingView::SetAddLineToolActive(bool state/*= true*/)
+{
+ if (state && toolAction == NULL)
+ {
+ toolAction = new DrawLineAction();
+ connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
+ SLOT(AddNewObjectToDocument(Object *)));
+ }
+ else if (!state && toolAction)
+ {
+ delete toolAction;
+ toolAction = NULL;
+ }
+
+ addLineTool = state;
+ update();
+//printf("DrawingView::SetAddLineToolActive(). toolAction=%08X\n", toolAction);
+}
+
+void DrawingView::AddNewObjectToDocument(Object * object)
+{
+ if (object)
+ {
+ object->Reparent(&document);
+ document.Add(object);
+ update();
+ }
+//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.
// The top level document takes care of rendering for us...
document.Draw(&painter);
+
+ if (toolAction)
+ toolAction->Draw(&painter);
}
void DrawingView::mousePressEvent(QMouseEvent * event)
if (collided)
update(); // Do an update if collided with at least *one* object in the document
+
+ if (toolAction)
+ toolAction->MouseDown(point);
}
else if (event->button() == Qt::MiddleButton)
{
{
point = Vector(event->x(), event->y());
// Since we're using Qt coords for scrolling, we have to adjust them here to
- // conform to Cartesian coords, since the origin is using them. :-)
+ // conform to Cartesian coords, since the origin is using Cartesian. :-)
Vector delta(point, oldPoint);
delta /= Painter::zoom;
delta.y = -delta.y;
if (document.NeedsUpdate())
update();
+
+ if (toolAction)
+ {
+ toolAction->MouseMoved(point);
+ update();
+ }
}
void DrawingView::mouseReleaseEvent(QMouseEvent * event)
// if (document.NeedsUpdate())
// if (collided)
update(); // Do an update if collided with at least *one* object in the document
+
+ if (toolAction)
+ toolAction->MouseReleased();
}
else if (event->button() == Qt::MiddleButton)
{
#include <QtGui>
#include <stdint.h>
+#include "action.h"
#include "container.h"
class DrawingView: public QWidget
public:
void SetRotateToolActive(bool state = true);
+ void SetAddLineToolActive(bool state = true);
+
+ public slots:
+ void AddNewObjectToDocument(Object *);
protected:
void paintEvent(QPaintEvent * event);
double rx, ry;
bool scrollDrag;
Vector oldPoint;
+ bool addLineTool;
+ Action * toolAction;
/* QSize minimumSizeHint() const;
QSize sizeHint() const;
--- /dev/null
+// drawlineaction.cpp: Action class for drawing lines
+//
+// Part of the Architektonas Project
+// (C) 2011 Underground Software
+// See the README and GPLv3 files for licensing and warranty information
+//
+// JLH = James L. Hammons <jlhamm@acm.org>
+//
+// WHO WHEN WHAT
+// --- ---------- ------------------------------------------------------------
+// JLH 10/04/2011 Created this file
+// JLH 11/07/2011 Made it so this class actually does something ;-)
+//
+
+#include "drawlineaction.h"
+#include "line.h"
+#include "painter.h"
+//#include "vector.h"
+
+
+#define FIRST_POINT 0
+#define NEXT_POINT 1
+
+
+DrawLineAction::DrawLineAction(): state(0), line(NULL)
+{
+}
+
+DrawLineAction::~DrawLineAction()
+{
+}
+
+
+/*virtual*/ void DrawLineAction::Draw(Painter * painter)
+{
+ // Need to fix pen colors, etc...
+ if (state == FIRST_POINT)
+ {
+ painter->DrawPoint(p1.x, p1.y);
+ }
+ else
+ {
+ painter->DrawLine(p1, p2);
+ }
+}
+
+/*virtual*/ void DrawLineAction::MouseDown(Vector point)
+{
+ if (state == FIRST_POINT)
+ p1 = point;
+ else
+ p2 = point;
+}
+
+/*virtual*/ void DrawLineAction::MouseMoved(Vector point)
+{
+ if (state == FIRST_POINT)
+ p1 = point;
+ else
+ p2 = point;
+}
+
+/*virtual*/ void DrawLineAction::MouseReleased(void)
+{
+ if (state == FIRST_POINT)
+ state = NEXT_POINT;
+ else if (state == NEXT_POINT)
+ {
+ // We create the new object here, and then pass it off to the document.
+ line = new Line(p1, p2);
+ // We don't need no stinkin' sentinels, when we have signals & slots!
+ emit ObjectReady(line);
+
+ p1 = p2;
+ }
+}
--- /dev/null
+#ifndef __DRAWLINEACTION_H__
+#define __DRAWLINEACTION_H__
+
+#include "action.h"
+
+class Line;
+
+class DrawLineAction: public Action
+{
+ public:
+ DrawLineAction();
+ ~DrawLineAction();
+
+ virtual void Draw(Painter *);
+ virtual void MouseDown(Vector);
+ virtual void MouseMoved(Vector);
+ virtual void MouseReleased(void);
+
+ private:
+ int state;
+ Line * line;
+ Vector p1, p2;
+};
+
+#endif // __DRAWLINEACTION_H__
return state;
}
+void Object::Reparent(Object * newParent)
+{
+ parent = newParent;
+}
+
// Class methods...
void Object::SetFixedAngle(bool state/*= true*/)
virtual Object * GetParent(void);
virtual void Add(Object *);
ObjectState GetState(void);
+ void Reparent(Object *);
//Hm. Object * Connect(Object *);
// Class methods
painter->drawText(rect, (Qt::AlignmentFlag)type, text);
}
-