src/layeritemwidget.h \
src/line.h \
src/main.h \
+ src/mirroraction.h \
src/mathconstants.h \
src/object.h \
src/painter.h \
src/layeritemwidget.cpp \
src/line.cpp \
src/main.cpp \
+ src/mirroraction.cpp \
src/object.cpp \
src/painter.cpp \
src/settingsdialog.cpp \
<file>file-save.png</file>
<file>file-save-as.png</file>
<file>settings.png</file>
+ <file>mirror-tool.png</file>
</qresource>
</RCC>
#include "fileio.h"
#include "generaltab.h"
#include "layerwidget.h"
+#include "mirroraction.h"
#include "painter.h"
#include "settingsdialog.h"
}
+void ApplicationWindow::MirrorTool(void)
+{
+ ClearUIToolStatesExcept(mirrorAct);
+ SetInternalToolStates();
+}
+
+
void ApplicationWindow::AddLineTool(void)
{
ClearUIToolStatesExcept(addLineAct);
if (exception != rotateAct)
rotateAct->setChecked(false);
+
+ if (exception != mirrorAct)
+ mirrorAct->setChecked(false);
}
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();
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);
menu->addAction(fixAngleAct);
menu->addAction(fixLengthAct);
menu->addAction(rotateAct);
+ menu->addAction(mirrorAct);
menu->addAction(connectAct);
menu->addAction(disconnectAct);
menu->addSeparator();
toolbar->addAction(fixAngleAct);
toolbar->addAction(fixLengthAct);
toolbar->addAction(rotateAct);
+ toolbar->addAction(mirrorAct);
toolbar->addAction(deleteAct);
toolbar->addAction(connectAct);
toolbar->addAction(disconnectAct);
void DeleteTool(void);
void DimensionTool(void);
void RotateTool(void);
+ void MirrorTool(void);
void AddLineTool(void);
void AddCircleTool(void);
void AddArcTool(void);
QAction * groupAct;
QAction * connectAct;
QAction * disconnectAct;
+ QAction * mirrorAct;
};
#endif // __APPLICATIONWINDOW_H__
--- /dev/null
+// 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;
+}
+
--- /dev/null
+#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__
+