]> Shamusworld >> Repos - architektonas/commitdiff
Beginnings of mirror tool.
authorShamus Hammons <jlhamm@acm.org>
Tue, 27 Aug 2013 20:51:48 +0000 (15:51 -0500)
committerShamus Hammons <jlhamm@acm.org>
Tue, 27 Aug 2013 20:51:48 +0000 (15:51 -0500)
architektonas.pro
res/architektonas.qrc
res/mirror-tool.png [new file with mode: 0644]
src/applicationwindow.cpp
src/applicationwindow.h
src/mirroraction.cpp [new file with mode: 0644]
src/mirroraction.h [new file with mode: 0644]

index f0ed68254684877f6af7fb5d7686e5bfeedff562..a2b2d49f755924c72d20dd9f37f8c90fdc526b14 100644 (file)
@@ -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 \
index cbcba71062a7df75be671b81861ac6e15f8b30db..697cad71a5b1418b01fb9f91af6f72ffda150bf4 100644 (file)
@@ -30,5 +30,6 @@
                <file>file-save.png</file>
                <file>file-save-as.png</file>
                <file>settings.png</file>
+               <file>mirror-tool.png</file>
        </qresource>
 </RCC>
diff --git a/res/mirror-tool.png b/res/mirror-tool.png
new file mode 100644 (file)
index 0000000..70ddb3f
Binary files /dev/null and b/res/mirror-tool.png differ
index 72948f8a3907e6643201ecee05c6bb089f0c99b4..8220a0eeca1138d6523c884ae70b26c828f92980 100644 (file)
@@ -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);
index 8322abced90307c2f43a834567b2754baae67a76..bc65da264d904332d2915776889f51f36c795d68 100644 (file)
@@ -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 (file)
index 0000000..500f59d
--- /dev/null
@@ -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 <jlhamm@acm.org>
+//
+// 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 (file)
index 0000000..0ff0a79
--- /dev/null
@@ -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__
+