]> Shamusworld >> Repos - architektonas/blobdiff - src/actions/rs_actiondrawline.cpp
Major refactoring of actions: Moved implementation from header files
[architektonas] / src / actions / rs_actiondrawline.cpp
index 27c8006b8b95ef60a9223e5c5ff1bf6aeef24572..89a8ea5f4f00993c8ef81d052ade73cc9c1617e7 100644 (file)
 #include "rs_actiondrawline.h"
 
 #include "rs_actioneditundo.h"
-#include "rs_snapper.h"
+#include "commands.h"
+#include "rs_dialogfactory.h"
+#include "rs_graphicview.h"
+#include "rs_preview.h"
 
-RS_ActionDrawLine::RS_ActionDrawLine(RS_EntityContainer & container,
-       RS_GraphicView & graphicView):
+RS_ActionDrawLine::RS_ActionDrawLine(RS_EntityContainer & container, RS_GraphicView & graphicView):
        RS_PreviewActionInterface("Draw lines", container, graphicView)
 {
        RS_DEBUG->print("RS_ActionDrawLine::RS_ActionDrawLine");
@@ -37,16 +39,6 @@ RS_ActionDrawLine::~RS_ActionDrawLine()
        return RS2::ActionDrawLine;
 }
 
-/*static*/ QAction * RS_ActionDrawLine::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
-{
-       QAction * action = new QAction(tr("&2 Points"), 0);
-       action->setEnabled(true);
-//     QAction* action = new QAction(tr("Line: 2 Points"), tr("&2 Points"),
-//                                                                     QKeySequence(), NULL);
-       action->setStatusTip(tr("Draw lines"));
-       return action;
-}
-
 void RS_ActionDrawLine::reset()
 {
        RS_DEBUG->print("RS_ActionDrawLine::reset");
@@ -123,7 +115,7 @@ void RS_ActionDrawLine::mouseReleaseEvent(QMouseEvent * e)
 {
        if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
        {
-               RS_CoordinateEvent ce(snapPoint(e));
+               Vector ce(snapPoint(e));
                coordinateEvent(&ce);
        }
        else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
@@ -135,7 +127,7 @@ void RS_ActionDrawLine::mouseReleaseEvent(QMouseEvent * e)
        }
 }
 
-void RS_ActionDrawLine::coordinateEvent(RS_CoordinateEvent * e)
+void RS_ActionDrawLine::coordinateEvent(Vector * e)
 {
        RS_DEBUG->print("RS_ActionDrawLine::coordinateEvent");
 
@@ -145,7 +137,7 @@ void RS_ActionDrawLine::coordinateEvent(RS_CoordinateEvent * e)
                return;
        }
 
-       Vector mouse = e->getCoordinate();
+       Vector mouse = *e;
 
        switch (getStatus())
        {
@@ -183,6 +175,7 @@ void RS_ActionDrawLine::commandEvent(RS_CommandEvent * e)
        switch (getStatus())
        {
        case SetStartpoint:
+
                if (checkCommand("help", c))
                {
                        RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
@@ -192,6 +185,7 @@ void RS_ActionDrawLine::commandEvent(RS_CommandEvent * e)
                break;
 
        case SetEndpoint:
+
                if (checkCommand("close", c))
                {
                        close();
@@ -222,7 +216,9 @@ QStringList RS_ActionDrawLine::getAvailableCommands()
        {
        case SetStartpoint:
                break;
+
        case SetEndpoint:
+
                if (history.count() >= 2)
                        cmd += command("undo");
 
@@ -230,6 +226,7 @@ QStringList RS_ActionDrawLine::getAvailableCommands()
                        cmd += command("close");
 
                break;
+
        default:
                break;
        }
@@ -244,6 +241,7 @@ void RS_ActionDrawLine::updateMouseButtonHints()
        case SetStartpoint:
                RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first point"), tr("Cancel"));
                break;
+
        case SetEndpoint:
        {
                QString msg = "";
@@ -255,16 +253,15 @@ void RS_ActionDrawLine::updateMouseButtonHints()
                }
 
                if (history.count() >= 2)
-               {
                        msg += RS_COMMANDS->command("undo");
-               }
 
                if (history.count() >= 2)
                        RS_DIALOGFACTORY->updateMouseWidget(tr("Specify next point or [%1]").arg(msg), tr("Back"));
                else
                        RS_DIALOGFACTORY->updateMouseWidget(tr("Specify next point"), tr("Back"));
        }
-               break;
+       break;
+
        default:
                RS_DIALOGFACTORY->updateMouseWidget("", "");
                break;
@@ -310,9 +307,7 @@ void RS_ActionDrawLine::close()
                graphicView->moveRelativeZero(start);
        }
        else
-       {
                RS_DIALOGFACTORY->commandMessage(tr("Cannot close sequence of lines: Not enough entities defined yet."));
-       }
 }
 
 void RS_ActionDrawLine::undo()
@@ -327,9 +322,7 @@ void RS_ActionDrawLine::undo()
                graphicView->moveRelativeZero(data.startpoint);
        }
        else
-       {
                RS_DIALOGFACTORY->commandMessage(tr("Cannot undo: Not enough entities defined yet."));
-       }
 }
 
 void RS_ActionDrawLine::ClearHistory(void)
@@ -337,3 +330,4 @@ void RS_ActionDrawLine::ClearHistory(void)
        while (!history.isEmpty())
                delete history.takeFirst();
 }
+