From: Shamus Hammons Date: Tue, 27 Aug 2013 20:51:48 +0000 (-0500) Subject: Beginnings of mirror tool. X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=architektonas;a=commitdiff_plain;h=428876081ee41d40e32f5b4f2bfcfdb7a835e6e1 Beginnings of mirror tool. --- diff --git a/architektonas.pro b/architektonas.pro index f0ed682..a2b2d49 100644 --- a/architektonas.pro +++ b/architektonas.pro @@ -65,6 +65,7 @@ HEADERS = \ src/layeritemwidget.h \ src/line.h \ src/main.h \ + src/mirroraction.h \ src/mathconstants.h \ src/object.h \ src/painter.h \ @@ -97,6 +98,7 @@ SOURCES = \ src/layeritemwidget.cpp \ src/line.cpp \ src/main.cpp \ + src/mirroraction.cpp \ src/object.cpp \ src/painter.cpp \ src/settingsdialog.cpp \ diff --git a/res/architektonas.qrc b/res/architektonas.qrc index cbcba71..697cad7 100644 --- a/res/architektonas.qrc +++ b/res/architektonas.qrc @@ -30,5 +30,6 @@ file-save.png file-save-as.png settings.png + mirror-tool.png diff --git a/res/mirror-tool.png b/res/mirror-tool.png new file mode 100644 index 0000000..70ddb3f Binary files /dev/null and b/res/mirror-tool.png differ diff --git a/src/applicationwindow.cpp b/src/applicationwindow.cpp index 72948f8..8220a0e 100644 --- a/src/applicationwindow.cpp +++ b/src/applicationwindow.cpp @@ -38,6 +38,7 @@ #include "fileio.h" #include "generaltab.h" #include "layerwidget.h" +#include "mirroraction.h" #include "painter.h" #include "settingsdialog.h" @@ -243,6 +244,13 @@ void ApplicationWindow::RotateTool(void) } +void ApplicationWindow::MirrorTool(void) +{ + ClearUIToolStatesExcept(mirrorAct); + SetInternalToolStates(); +} + + void ApplicationWindow::AddLineTool(void) { ClearUIToolStatesExcept(addLineAct); @@ -377,6 +385,9 @@ void ApplicationWindow::ClearUIToolStatesExcept(QAction * exception) if (exception != rotateAct) rotateAct->setChecked(false); + + if (exception != mirrorAct) + mirrorAct->setChecked(false); } @@ -405,6 +416,7 @@ void ApplicationWindow::SetInternalToolStates(void) drawing->SetToolActive(addCircleAct->isChecked() ? new DrawCircleAction() : NULL); drawing->SetToolActive(addArcAct->isChecked() ? new DrawArcAction() : NULL); drawing->SetToolActive(addDimensionAct->isChecked() ? new DrawDimensionAction() : NULL); + drawing->SetToolActive(mirrorAct->isChecked() ? new MirrorAction() : NULL); #endif update(); @@ -605,6 +617,10 @@ void ApplicationWindow::CreateActions(void) disconnectAct = CreateAction(tr("&Disconnect"), tr("Disconnect"), tr("Disconnect objects joined at point."), QIcon(":/res/disconnect-tool.png"), QKeySequence("d,d")); + mirrorAct = CreateAction(tr("&Mirror"), tr("Mirror"), tr("Mirror selected objects around a line."), QIcon(":/res/mirror-tool.png"), QKeySequence("m,i"), true); + connect(mirrorAct, SIGNAL(triggered()), this, SLOT(MirrorTool())); + + //Hm. I think we'll have to have separate logic to do the "Radio Group Toolbar" thing... // Yup, in order to turn them off, we'd have to have an "OFF" toolbar button. Ick. /* QActionGroup * group = new QActionGroup(this); @@ -673,6 +689,7 @@ void ApplicationWindow::CreateMenus(void) menu->addAction(fixAngleAct); menu->addAction(fixLengthAct); menu->addAction(rotateAct); + menu->addAction(mirrorAct); menu->addAction(connectAct); menu->addAction(disconnectAct); menu->addSeparator(); @@ -720,6 +737,7 @@ void ApplicationWindow::CreateToolbars(void) toolbar->addAction(fixAngleAct); toolbar->addAction(fixLengthAct); toolbar->addAction(rotateAct); + toolbar->addAction(mirrorAct); toolbar->addAction(deleteAct); toolbar->addAction(connectAct); toolbar->addAction(disconnectAct); diff --git a/src/applicationwindow.h b/src/applicationwindow.h index 8322abc..bc65da2 100644 --- a/src/applicationwindow.h +++ b/src/applicationwindow.h @@ -33,6 +33,7 @@ class ApplicationWindow: public QMainWindow void DeleteTool(void); void DimensionTool(void); void RotateTool(void); + void MirrorTool(void); void AddLineTool(void); void AddCircleTool(void); void AddArcTool(void); @@ -91,6 +92,7 @@ class ApplicationWindow: public QMainWindow QAction * groupAct; QAction * connectAct; QAction * disconnectAct; + QAction * mirrorAct; }; #endif // __APPLICATIONWINDOW_H__ diff --git a/src/mirroraction.cpp b/src/mirroraction.cpp new file mode 100644 index 0000000..500f59d --- /dev/null +++ b/src/mirroraction.cpp @@ -0,0 +1,128 @@ +// mirroraction.cpp: Action class for mirroring selected objects +// +// Part of the Architektonas Project +// (C) 2011 Underground Software +// See the README and GPLv3 files for licensing and warranty information +// +// JLH = James Hammons +// +// WHO WHEN WHAT +// --- ---------- ------------------------------------------------------------ +// JLH 08/27/2011 Created this file +// + +#include "mirroraction.h" +#include "line.h" +#include "painter.h" +//#include "vector.h" + + +//#define FIRST_POINT 0 +//#define NEXT_POINT 1 +enum { FIRST_POINT, NEXT_POINT }; + + +MirrorAction::MirrorAction(): state(FIRST_POINT), line(NULL), + shiftWasPressedOnNextPoint(false) +{ +} + + +MirrorAction::~MirrorAction() +{ +} + + +/*virtual*/ void MirrorAction::Draw(Painter * painter) +{ + painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine)); + + // I think stuff like crosshairs should be done in the DrawingView, tho + // (and it's done there now...) + if (state == FIRST_POINT) + { + painter->DrawHandle(p1); + } + else + { + painter->DrawLine(p1, p2); + painter->DrawHandle(p2); + + QString text = tr("Length: %1 in."); + text = text.arg(Vector::Magnitude(p1, p2)); + painter->DrawInformativeText(text); + } +} + + +/*virtual*/ void MirrorAction::MouseDown(Vector point) +{ + // Clear our override... + shiftWasPressedOnNextPoint = false; + + if (state == FIRST_POINT) + p1 = point; + else + p2 = point; +} + + +/*virtual*/ void MirrorAction::MouseMoved(Vector point) +{ + if (state == FIRST_POINT) + p1 = point; + else + p2 = point; +} + + +/*virtual*/ void MirrorAction::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. +// line = new Line(p1, p2); + // We don't need no stinkin' sentinels, when we have signals & slots! +// emit ObjectReady(line); + + p1 = p2; + state = NEXT_POINT; + } +} + + +/*virtual*/ bool MirrorAction::KeyDown(int key) +{ + if ((key == Qt::Key_Shift) && (state == NEXT_POINT)) + { + shiftWasPressedOnNextPoint = true; + p1Save = p1; + p1 = p2; + state = FIRST_POINT; + return true; + } + + return false; +} + + +/*virtual*/ bool MirrorAction::KeyReleased(int key) +{ + if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint) + { + shiftWasPressedOnNextPoint = false; + p2 = p1; + p1 = p1Save; + state = NEXT_POINT; + return true; + } + + return false; +} + diff --git a/src/mirroraction.h b/src/mirroraction.h new file mode 100644 index 0000000..0ff0a79 --- /dev/null +++ b/src/mirroraction.h @@ -0,0 +1,29 @@ +#ifndef __MIRRORACTION_H__ +#define __MIRRORACTION_H__ + +#include "action.h" + +class Line; + +class MirrorAction: public Action +{ + public: + MirrorAction(); + ~MirrorAction(); + + virtual void Draw(Painter *); + virtual void MouseDown(Vector); + virtual void MouseMoved(Vector); + virtual void MouseReleased(void); + virtual bool KeyDown(int); + virtual bool KeyReleased(int); + + private: + int state; + Line * line; + Vector p1, p2, p1Save; + bool shiftWasPressedOnNextPoint; +}; + +#endif // __MIRRORACTION_H__ +