]> Shamusworld >> Repos - architektonas/blobdiff - src/actions/rs_actionselectintersected.cpp
Major refactoring of actions: Moved implementation from header files
[architektonas] / src / actions / rs_actionselectintersected.cpp
index 7d6e25c2288f97269aab33b9d9dfdf4a238a8603..dc158d5c4cee3596d11023ac9adee1531d050e86 100644 (file)
@@ -14,9 +14,9 @@
 
 #include "rs_actionselectintersected.h"
 
-#include "rs.h"
-#include "rs_snapper.h"
+#include "rs_dialogfactory.h"
 #include "rs_selection.h"
+#include "rs_preview.h"
 
 /**
  * Constructor.
  * @param select true: select window. false: deselect window
  */
 RS_ActionSelectIntersected::RS_ActionSelectIntersected(
-       RS_EntityContainer& container, RS_GraphicView& graphicView, bool select):
+       RS_EntityContainer & container, RS_GraphicView & graphicView, bool select):
        RS_PreviewActionInterface("Select Intersected", container, graphicView)
 {
        this->select = select;
 }
 
-QAction * RS_ActionSelectIntersected::createGUIAction(RS2::ActionType type, QObject * /*parent*/)
+RS_ActionSelectIntersected::~RS_ActionSelectIntersected()
 {
-       QAction * action;
-
-       if (type == RS2::ActionSelectIntersected)
-       {
-               action = new QAction(tr("In&tersected Entities"), 0);
-//             action = new QAction(tr("Select Intersected Entities"), tr("In&tersected Entities"),
-//                                                             QKeySequence(), NULL);
-               action->setStatusTip(tr("Selects all entities intersected by a line"));
-       }
-       else
-       {
-               action = new QAction(tr("Deselect Inte&rsected Entities"), 0);
-//             action = new QAction(tr("Deselect Intersected Entities"),
-//                                                             tr("Deselect Inte&rsected Entities"),
-//                                                             QKeySequence(), NULL);
-               action->setStatusTip(tr("Deselects all entities intersected by a line"));
-       }
+}
 
-       return action;
+/*virtual*/ RS2::ActionType RS_ActionSelectIntersected::rtti()
+{
+       return RS2::ActionSelectIntersected;
 }
 
 void RS_ActionSelectIntersected::init(int status)
 {
-    RS_PreviewActionInterface::init(status);
+       RS_PreviewActionInterface::init(status);
 
-    v1 = v2 = Vector(false);
-    snapMode = RS2::SnapFree;
-    snapRes = RS2::RestrictNothing;
+       v1 = v2 = Vector(false);
+       snapMode = RS2::SnapFree;
+       snapRes = RS2::RestrictNothing;
 }
 
 void RS_ActionSelectIntersected::trigger()
 {
-    RS_PreviewActionInterface::trigger();
+       RS_PreviewActionInterface::trigger();
 
-    if (v1.valid && v2.valid) {
-        if (graphicView->toGuiDX(v1.distanceTo(v2))>10) {
-            deleteSnapper();
+       if (v1.valid && v2.valid)
+               if (graphicView->toGuiDX(v1.distanceTo(v2)) > 10)
+               {
+                       deleteSnapper();
 
-            RS_Selection s(*container, graphicView);
-            s.selectIntersected(v1, v2, select);
+                       RS_Selection s(*container, graphicView);
+                       s.selectIntersected(v1, v2, select);
 
-            if (RS_DIALOGFACTORY!=NULL) {
-                RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
-            }
+                       if (RS_DIALOGFACTORY != NULL)
+                               RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
 
-            init();
-        }
-    }
+                       init();
+               }
 }
 
-void RS_ActionSelectIntersected::mouseMoveEvent(QMouseEvent* e)
+void RS_ActionSelectIntersected::mouseMoveEvent(QMouseEvent * e)
 {
-    if (getStatus()==SetPoint2 && v1.valid) {
-        v2 = snapPoint(e);
-        deletePreview();
-        clearPreview();
-        preview->addEntity(new RS_Line(preview,
-                                       RS_LineData(Vector(v1.x, v1.y),
-                                                   Vector(v2.x, v2.y))));
-        drawPreview();
-    }
+       if (getStatus() == SetPoint2 && v1.valid)
+       {
+               v2 = snapPoint(e);
+               deletePreview();
+               clearPreview();
+               preview->addEntity(new RS_Line(preview,
+                               RS_LineData(Vector(v1.x, v1.y),
+                                       Vector(v2.x, v2.y))));
+               drawPreview();
+       }
 }
 
+void RS_ActionSelectIntersected::mousePressEvent(QMouseEvent * e)
+{
+       if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
+       {
+               switch (getStatus())
+               {
+               case SetPoint1:
+                       v1 = snapPoint(e);
+                       setStatus(SetPoint2);
+                       break;
+
+               default:
+                       break;
+               }
+       }
 
-
-void RS_ActionSelectIntersected::mousePressEvent(QMouseEvent* e) {
-    if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
-        switch (getStatus()) {
-        case SetPoint1:
-            v1 = snapPoint(e);
-            setStatus(SetPoint2);
-            break;
-
-        default:
-            break;
-        }
-    }
-
-    RS_DEBUG->print("RS_ActionSelectIntersected::mousePressEvent(): %f %f",
-                    v1.x, v1.y);
+       RS_DEBUG->print("RS_ActionSelectIntersected::mousePressEvent(): %f %f",
+               v1.x, v1.y);
 }
 
+void RS_ActionSelectIntersected::mouseReleaseEvent(QMouseEvent * e)
+{
+       RS_DEBUG->print("RS_ActionSelectIntersected::mouseReleaseEvent()");
 
-
-void RS_ActionSelectIntersected::mouseReleaseEvent(QMouseEvent* e) {
-    RS_DEBUG->print("RS_ActionSelectIntersected::mouseReleaseEvent()");
-    if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
-        if (getStatus()==SetPoint2) {
-            deletePreview();
-        }
-        deleteSnapper();
-        init(getStatus()-1);
-    } else if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
-        if (getStatus()==SetPoint2) {
-            v2 = snapPoint(e);
-            trigger();
-        }
-    }
+       if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
+       {
+               if (getStatus() == SetPoint2)
+                       deletePreview();
+               deleteSnapper();
+               init(getStatus() - 1);
+       }
+       else if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
+               if (getStatus() == SetPoint2)
+               {
+                       v2 = snapPoint(e);
+                       trigger();
+               }
 }
 
-
-
-void RS_ActionSelectIntersected::updateMouseButtonHints() {
-    if (RS_DIALOGFACTORY!=NULL) {
-        switch (getStatus()) {
-        case SetPoint1:
-            RS_DIALOGFACTORY->updateMouseWidget(tr("Choose first point of intersection line"), tr("Cancel"));
-            break;
-        case SetPoint2:
-            RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second point of intersection line"), tr("Back"));
-            break;
-        default:
-            RS_DIALOGFACTORY->updateMouseWidget("", "");
-            break;
-        }
-    }
+void RS_ActionSelectIntersected::updateMouseButtonHints()
+{
+       if (RS_DIALOGFACTORY != NULL)
+       {
+               switch (getStatus())
+               {
+               case SetPoint1:
+                       RS_DIALOGFACTORY->updateMouseWidget(tr("Choose first point of intersection line"), tr("Cancel"));
+                       break;
+
+               case SetPoint2:
+                       RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second point of intersection line"), tr("Back"));
+                       break;
+
+               default:
+                       RS_DIALOGFACTORY->updateMouseWidget("", "");
+                       break;
+               }
+       }
 }
 
-
-
-void RS_ActionSelectIntersected::updateMouseCursor() {
-    graphicView->setMouseCursor(RS2::SelectCursor);
+void RS_ActionSelectIntersected::updateMouseCursor()
+{
+       graphicView->setMouseCursor(RS2::SelectCursor);
 }
 
-
-
-void RS_ActionSelectIntersected::updateToolBar() {
-    if (RS_DIALOGFACTORY!=NULL) {
-        if (!isFinished()) {
-            //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
-            RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
-        } else {
-            RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
-        }
-    }
+void RS_ActionSelectIntersected::updateToolBar()
+{
+       if (RS_DIALOGFACTORY != NULL)
+       {
+               if (!isFinished())
+                       //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
+                       RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
+               else
+                       RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
+       }
 }
 
 // EOF