]> Shamusworld >> Repos - architektonas/blobdiff - src/actions/rs_actionselectwindow.cpp
Major refactoring of actions: Moved implementation from header files
[architektonas] / src / actions / rs_actionselectwindow.cpp
index 8351f8567457b983c7a25b4b3362dbe7e1068498..f0da9bfe60dfa1d84daab99fa90033b94f1b9136 100644 (file)
 
 #include "rs_actionselectwindow.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_ActionSelectWindow::RS_ActionSelectWindow(RS_EntityContainer& container,
-        RS_GraphicView& graphicView,
-        bool select)
-        : RS_PreviewActionInterface("Select Window",
-                            container, graphicView) {
-
-    this->select = select;
+RS_ActionSelectWindow::RS_ActionSelectWindow(RS_EntityContainer & container,
+       RS_GraphicView & graphicView, bool select):
+       RS_PreviewActionInterface("Select Window", container, graphicView)
+{
+       this->select = select;
 }
 
-QAction * RS_ActionSelectWindow::createGUIAction(RS2::ActionType type, QObject * /*parent*/)
+RS_ActionSelectWindow::~RS_ActionSelectWindow()
 {
-       QAction * action;
-
-       if (type == RS2::ActionSelectWindow)
-       {
-               action = new QAction(tr("Select &Window"), 0);
-//             action = new QAction(tr("Select Window"), tr("Select &Window"),
-//                                                             QKeySequence(), NULL);
-               action->setStatusTip(tr("Selects all Entities in a given Window"));
-       }
-       else
-       {
-               action = new QAction(tr("Deselect &Window"), 0);
-//             action = new QAction(tr("Deselect Window"), tr("Deselect &Window"),
-//                                                             QKeySequence(), NULL);
-               action->setStatusTip(tr("Deselects all Entities in a given Window"));
-       }
+}
 
-       return action;
+/*virtual*/ RS2::ActionType RS_ActionSelectWindow::rtti()
+{
+       return RS2::ActionSelectWindow;
 }
 
 void RS_ActionSelectWindow::init(int status)
 {
-    RS_PreviewActionInterface::init(status);
-    v1 = v2 = Vector(false);
-    snapMode = RS2::SnapFree;
-    snapRes = RS2::RestrictNothing;
+       RS_PreviewActionInterface::init(status);
+       v1 = v2 = Vector(false);
+       snapMode = RS2::SnapFree;
+       snapRes = RS2::RestrictNothing;
 }
 
+void RS_ActionSelectWindow::trigger()
+{
+       RS_PreviewActionInterface::trigger();
 
+       if (v1.valid && v2.valid)
+       {
+               if (graphicView->toGuiDX(v1.distanceTo(v2)) > 10)
+               {
+                       deleteSnapper();
 
-void RS_ActionSelectWindow::trigger() {
-    RS_PreviewActionInterface::trigger();
-
-    if (v1.valid && v2.valid) {
-        if (graphicView->toGuiDX(v1.distanceTo(v2))>10) {
-            deleteSnapper();
-
-            bool cross = (v2.y>v1.y);
+                       bool cross = (v2.y > v1.y);
 
-            RS_Selection s(*container, graphicView);
-            s.selectWindow(v1, v2, select, cross);
+                       RS_Selection s(*container, graphicView);
+                       s.selectWindow(v1, v2, select, cross);
 
-            RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
+                       RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
 
-            init();
-        }
-    }
+                       init();
+               }
+       }
 }
 
-
-
-void RS_ActionSelectWindow::mouseMoveEvent(QMouseEvent* e) {
-    if (getStatus()==SetCorner2 && v1.valid) {
-        v2 = snapPoint(e);
-        deletePreview();
-        clearPreview();
-        preview->addEntity(new RS_Line(preview,
-                                       RS_LineData(Vector(v1.x, v1.y),
-                                                   Vector(v2.x, v1.y))));
-        preview->addEntity(new RS_Line(preview,
-                                       RS_LineData(Vector(v2.x, v1.y),
-                                                   Vector(v2.x, v2.y))));
-        preview->addEntity(new RS_Line(preview,
-                                       RS_LineData(Vector(v2.x, v2.y),
-                                                   Vector(v1.x, v2.y))));
-        preview->addEntity(new RS_Line(preview,
-                                       RS_LineData(Vector(v1.x, v2.y),
-                                                   Vector(v1.x, v1.y))));
-        drawPreview();
-    }
+void RS_ActionSelectWindow::mouseMoveEvent(QMouseEvent * e)
+{
+       if (getStatus() == SetCorner2 && v1.valid)
+       {
+               v2 = snapPoint(e);
+               deletePreview();
+               clearPreview();
+               preview->addEntity(new RS_Line(preview,
+                               RS_LineData(Vector(v1.x, v1.y),
+                                       Vector(v2.x, v1.y))));
+               preview->addEntity(new RS_Line(preview,
+                               RS_LineData(Vector(v2.x, v1.y),
+                                       Vector(v2.x, v2.y))));
+               preview->addEntity(new RS_Line(preview,
+                               RS_LineData(Vector(v2.x, v2.y),
+                                       Vector(v1.x, v2.y))));
+               preview->addEntity(new RS_Line(preview,
+                               RS_LineData(Vector(v1.x, v2.y),
+                                       Vector(v1.x, v1.y))));
+               drawPreview();
+       }
 }
 
+void RS_ActionSelectWindow::mousePressEvent(QMouseEvent * e)
+{
+       if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
+       {
+               switch (getStatus())
+               {
+               case SetCorner1:
+                       v1 = snapPoint(e);
+                       setStatus(SetCorner2);
+                       break;
+
+               default:
+                       break;
+               }
+       }
 
-
-void RS_ActionSelectWindow::mousePressEvent(QMouseEvent* e) {
-    if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
-        switch (getStatus()) {
-        case SetCorner1:
-            v1 = snapPoint(e);
-            setStatus(SetCorner2);
-            break;
-
-        default:
-            break;
-        }
-    }
-
-    RS_DEBUG->print("RS_ActionSelectWindow::mousePressEvent(): %f %f",
-                    v1.x, v1.y);
+       RS_DEBUG->print("RS_ActionSelectWindow::mousePressEvent(): %f %f",
+               v1.x, v1.y);
 }
 
+void RS_ActionSelectWindow::mouseReleaseEvent(QMouseEvent * e)
+{
+       RS_DEBUG->print("RS_ActionSelectWindow::mouseReleaseEvent()");
 
-
-void RS_ActionSelectWindow::mouseReleaseEvent(QMouseEvent* e) {
-    RS_DEBUG->print("RS_ActionSelectWindow::mouseReleaseEvent()");
-
-    if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
-        if (getStatus()==SetCorner2) {
-            v2 = snapPoint(e);
-            trigger();
-        }
-    } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
-        if (getStatus()==SetCorner2) {
-            deletePreview();
-        }
-        deleteSnapper();
-        init(getStatus()-1);
-    }
+       if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
+       {
+               if (getStatus() == SetCorner2)
+               {
+                       v2 = snapPoint(e);
+                       trigger();
+               }
+       }
+       else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
+       {
+               if (getStatus() == SetCorner2)
+                       deletePreview();
+               deleteSnapper();
+               init(getStatus() - 1);
+       }
 }
 
+void RS_ActionSelectWindow::updateMouseButtonHints()
+{
+       switch (getStatus())
+       {
+       case SetCorner1:
+               RS_DIALOGFACTORY->updateMouseWidget(tr("Choose first edge"), tr("Cancel"));
+               break;
 
+       case SetCorner2:
+               RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second edge"), tr("Back"));
+               break;
 
-void RS_ActionSelectWindow::updateMouseButtonHints() {
-    switch (getStatus()) {
-    case SetCorner1:
-        RS_DIALOGFACTORY->updateMouseWidget(tr("Choose first edge"), tr("Cancel"));
-        break;
-    case SetCorner2:
-        RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second edge"), tr("Back"));
-        break;
-    default:
-        RS_DIALOGFACTORY->updateMouseWidget("", "");
-        break;
-    }
+       default:
+               RS_DIALOGFACTORY->updateMouseWidget("", "");
+               break;
+       }
 }
 
-
-
-void RS_ActionSelectWindow::updateMouseCursor() {
-    graphicView->setMouseCursor(RS2::SelectCursor);
+void RS_ActionSelectWindow::updateMouseCursor()
+{
+       graphicView->setMouseCursor(RS2::SelectCursor);
 }
 
-
-
-void RS_ActionSelectWindow::updateToolBar() {
-    if (!isFinished()) {
-        //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
-        RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
-    } else {
-        RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
-    }
+void RS_ActionSelectWindow::updateToolBar()
+{
+       if (!isFinished())
+               //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
+               RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
+       else
+               RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
 }
 
 // EOF