]> Shamusworld >> Repos - architektonas/blobdiff - src/actions/actiondefault.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / actions / actiondefault.cpp
index 4385c7c0dd9f775551ff4613dbbe9e612ece7b03..a1219df0b1793fce779823f552c7aba7c77c6854 100644 (file)
@@ -3,7 +3,9 @@
 // Part of the Architektonas Project
 // Originally part of QCad Community Edition by Andrew Mustun
 // Extensively rewritten and refactored by James L. Hammons
-// (C) 2010 Underground Software
+// Portions copyright (C) 2001-2003 RibbonSoft
+// Copyright (C) 2010 Underground Software
+// See the README and GPLv2 files for licensing and warranty information
 //
 // JLH = James L. Hammons <jlhamm@acm.org>
 //
 
 #include "actiondefault.h"
 
-#include "rs.h"
-#include "rs_commandevent.h"
-#include "rs_dialogfactory.h"
-#include "rs_line.h"
-#include "rs_modification.h"
-#include "rs_preview.h"
-#include "rs_snapper.h"
-#include "rs_selection.h"
+#include "enums.h"
+#include "commandevent.h"
+#include "debug.h"
+#include "dialogfactory.h"
+#include "line.h"
+#include "modification.h"
+#include "preview.h"
+#include "selection.h"
 
 /**
  * Constructor.
  */
-ActionDefault::ActionDefault(RS_EntityContainer & container,
-       GraphicView & graphicView): ActionInterface("Default",
-       container, graphicView)
+ActionDefault::ActionDefault(EntityContainer & container,
+       GraphicView & graphicView):
+       ActionInterface("Default", container, graphicView)
 {
-       RS_DEBUG->print("ActionDefault::ActionDefault");
-       RS_DEBUG->print("ActionDefault::ActionDefault: OK");
+       DEBUG->print("ActionDefault::ActionDefault");
+       DEBUG->print("ActionDefault::ActionDefault: OK");
 }
 
 ActionDefault::~ActionDefault()
@@ -45,16 +47,18 @@ ActionDefault::~ActionDefault()
 
 void ActionDefault::init(int status /*= 0*/)
 {
-       RS_DEBUG->print("ActionDefault::init");
+       DEBUG->print("ActionDefault::init");
 
        ActionInterface::init(status);
        v1 = v2 = Vector(false);
-//     snapMode = RS2::SnapFree;
-//     snapRes = RS2::RestrictNothing;
+//     graphicView->snapper.setSnapMode(RS2::SnapFree);
+//     graphicView->snapper.setSnapRestriction(RS2::RestrictNothing);
+       graphicView->setDefaultSnapMode(RS2::SnapFree);
+       graphicView->setSnapRestriction(RS2::RestrictNothing);
        restrBak = RS2::RestrictNothing;
-       RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
+       DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
 
-       RS_DEBUG->print("ActionDefault::init: OK");
+       DEBUG->print("ActionDefault::init: OK");
 }
 
 void ActionDefault::trigger()
@@ -66,23 +70,25 @@ void ActionDefault::keyPressEvent(QKeyEvent * e)
 {
        if (e->key() == Qt::Key_Shift)
        {
-//             restrBak = snapRes;
-//             setSnapRestriction(RS2::RestrictOrthogonal);
+//             restrBak = graphicView->snapper.getSnapRestriction();
+//             graphicView->snapper.setSnapRestriction(RS2::RestrictOrthogonal);
+               restrBak = graphicView->getSnapRestriction();
+               graphicView->setSnapRestriction(RS2::RestrictOrthogonal);
        }
 }
 
 void ActionDefault::keyReleaseEvent(QKeyEvent * e)
 {
-//     if (e->key() == Qt::Key_Shift)
-//             setSnapRestriction(restrBak);
+       if (e->key() == Qt::Key_Shift)
+//             graphicView->snapper.setSnapRestriction(restrBak);
+               graphicView->setSnapRestriction(restrBak);
 }
 
 void ActionDefault::mouseMoveEvent(QMouseEvent * e)
 {
        Vector mouse = graphicView->toGraph(Vector(e->x(), e->y()));
        Vector relMouse = mouse - graphicView->getRelativeZero();
-
-       RS_DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse);
+       DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse);
 
        switch (getStatus())
        {
@@ -97,8 +103,7 @@ void ActionDefault::mouseMoveEvent(QMouseEvent * e)
 
                        if (ref.valid && graphicView->toGuiDX(dist) < 8)
                        {
-                               RS_DEBUG->print("ActionDefault::mouseMoveEvent: "
-                                       "moving reference point");
+                               DEBUG->print("ActionDefault::mouseMoveEvent: moving reference point");
                                setStatus(MovingRef);
                                v1 = ref;
                                graphicView->moveRelativeZero(v1);
@@ -106,12 +111,12 @@ void ActionDefault::mouseMoveEvent(QMouseEvent * e)
                        else
                        {
                                // test for an entity to drag:
-                               RS_Entity * en = graphicView->snapper.catchEntity(v1);
+//                             Entity * en = graphicView->snapper.catchEntity(v1);
+                               Entity * en = graphicView->CatchEntity(v1);
 
                                if (en && en->isSelected())
                                {
-                                       RS_DEBUG->print("ActionDefault::mouseMoveEvent: "
-                                               "moving entity");
+                                       DEBUG->print("ActionDefault::mouseMoveEvent: moving entity");
                                        setStatus(Moving);
                                        v1 = en->getNearestRef(v1);
                                        graphicView->moveRelativeZero(v1);
@@ -127,21 +132,33 @@ void ActionDefault::mouseMoveEvent(QMouseEvent * e)
        case MovingRef:
                v2 = snapPoint(e);
 
-//             deletePreview();
 //             clearPreview();
 //             preview->addSelectionFrom(*container);
 //             preview->moveRef(v1, v2 - v1);
 //             drawPreview();
+               graphicView->preview.clear();
+               graphicView->preview.addSelectionFrom(*container);
+               graphicView->preview.moveRef(v1, v2 -v1);
+//             graphicView->snapper.SetVisible();
+               graphicView->SetSnapperVisible();
+               graphicView->preview.SetVisible();
+               graphicView->redraw();
                break;
 
        case Moving:
                v2 = snapPoint(e);
 
-//             deletePreview();
 //             clearPreview();
 //             preview->addSelectionFrom(*container);
 //             preview->move(v2 - v1);
 //             drawPreview();
+               graphicView->preview.clear();
+               graphicView->preview.addSelectionFrom(*container);
+               graphicView->preview.move(v2 -v1);
+//             graphicView->snapper.SetVisible();
+               graphicView->SetSnapperVisible();
+               graphicView->preview.SetVisible();
+               graphicView->redraw();
                break;
 
        case SetCorner2:
@@ -149,18 +166,19 @@ void ActionDefault::mouseMoveEvent(QMouseEvent * e)
                {
                        v2 = mouse;
 
-//                     deletePreview();
-//                     clearPreview();
+                       graphicView->preview.clear();
+
+                       graphicView->preview.addEntity(new Line(&(graphicView->preview),
+                               LineData(Vector(v1.x, v1.y), Vector(v2.x, v1.y))));
+                       graphicView->preview.addEntity(new Line(&(graphicView->preview),
+                               LineData(Vector(v2.x, v1.y), Vector(v2.x, v2.y))));
+                       graphicView->preview.addEntity(new Line(&(graphicView->preview),
+                               LineData(Vector(v2.x, v2.y), Vector(v1.x, v2.y))));
+                       graphicView->preview.addEntity(new Line(&(graphicView->preview),
+                               LineData(Vector(v1.x, v2.y), Vector(v1.x, v1.y))));
 
-//                     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();
+                       graphicView->preview.SetVisible();
+                       graphicView->redraw();
                }
 
        default:
@@ -185,18 +203,18 @@ void ActionDefault::mousePressEvent(QMouseEvent * e)
 //                     deleteSnapper();
 //                     deletePreview();
 //                     clearPreview();
-                       RS_Modification m(*container, graphicView);
-                       RS_MoveData data;
+                       Modification m(*container, graphicView);
+                       MoveData data;
                        data.number = 0;
                        data.useCurrentLayer = false;
                        data.useCurrentAttributes = false;
                        data.offset = v2 - v1;
                        m.move(data);
                        setStatus(Neutral);
-                       RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
-                       RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
+                       DIALOGFACTORY->updateSelectionWidget(container->countSelected());
+                       DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
                }
-               break;
+                       break;
 
                case MovingRef:
                {
@@ -204,16 +222,16 @@ void ActionDefault::mousePressEvent(QMouseEvent * e)
 //                     deleteSnapper();
 //                     deletePreview();
 //                     clearPreview();
-                       RS_Modification m(*container, graphicView);
-                       RS_MoveRefData data;
+                       Modification m(*container, graphicView);
+                       MoveRefData data;
                        data.ref = v1;
                        data.offset = v2 - v1;
                        m.moveRef(data);
                        setStatus(Neutral);
-                       RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
-                       RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
+                       DIALOGFACTORY->updateSelectionWidget(container->countSelected());
+                       DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
                }
-               break;
+                       break;
 
                default:
                        break;
@@ -223,7 +241,7 @@ void ActionDefault::mousePressEvent(QMouseEvent * e)
 
 void ActionDefault::mouseReleaseEvent(QMouseEvent * e)
 {
-       RS_DEBUG->print("ActionDefault::mouseReleaseEvent()");
+       DEBUG->print("ActionDefault::mouseReleaseEvent()");
 
        if (e->button() == Qt::LeftButton)
        {
@@ -234,7 +252,8 @@ void ActionDefault::mouseReleaseEvent(QMouseEvent * e)
                case Dragging:
                {
                        // select single entity:
-                       RS_Entity * en = graphicView->snapper.catchEntity(e);
+//                     Entity * en = graphicView->snapper.catchEntity(e);
+                       Entity * en = graphicView->CatchEntity(e);
 
                        if (en)
                        {
@@ -242,18 +261,16 @@ void ActionDefault::mouseReleaseEvent(QMouseEvent * e)
 //                             deletePreview();
 //                             clearPreview();
 
-                               RS_Selection s(*container, graphicView);
+                               Selection s(*container, graphicView);
                                s.selectSingle(en);
-
-                               RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
-
+                               DIALOGFACTORY->updateSelectionWidget(container->countSelected());
                                e->accept();
                                setStatus(Neutral);
                        }
                        else
                                setStatus(SetCorner2);
                }
-               break;
+                       break;
 
                case SetCorner2:
                {
@@ -263,19 +280,25 @@ void ActionDefault::mouseReleaseEvent(QMouseEvent * e)
 //                     deleteSnapper();
 //                     deletePreview();
 //                     clearPreview();
+                       graphicView->preview.SetVisible(false);
 
                        bool cross = (v2.y > v1.y);
-                       RS_Selection s(*container, graphicView);
+                       Selection s(*container, graphicView);
                        s.selectWindow(v1, v2, true, cross);
 
-                       RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
+                       DIALOGFACTORY->updateSelectionWidget(container->countSelected());
 
                        setStatus(Neutral);
                        e->accept();
                }
-               break;
+                       break;
 
                default:
+                       // Was either moving entity or point, so clear that shiatsu
+//                     graphicView->snapper.SetVisible(false);
+                       graphicView->SetSnapperVisible(false);
+                       graphicView->preview.SetVisible(false);
+                       graphicView->redraw();
                        break;
                }
        }
@@ -290,21 +313,22 @@ void ActionDefault::mouseReleaseEvent(QMouseEvent * e)
 //                     clearPreview();
 //                     deleteSnapper();
                        setStatus(Neutral);
-                       RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
+                       DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
                        e->accept();
                        break;
 
                default:
-                       graphicView->snapper.SetVisible(false);
+//                     graphicView->snapper.SetVisible(false);
+                       graphicView->SetSnapperVisible(false);
                        graphicView->preview.SetVisible(false);
-                       RS_DIALOGFACTORY->requestPreviousMenu();
+                       DIALOGFACTORY->requestPreviousMenu();
                        e->accept();
                        break;
                }
        }
 }
 
-void ActionDefault::commandEvent(RS_CommandEvent * e)
+void ActionDefault::commandEvent(CommandEvent * e)
 {
        QString c = e->getCommand().toLower();
 }
@@ -321,15 +345,15 @@ void ActionDefault::updateMouseButtonHints()
        switch (getStatus())
        {
        case Neutral:
-               RS_DIALOGFACTORY->updateMouseWidget("", "");
+               DIALOGFACTORY->updateMouseWidget("", "");
                break;
 
        case SetCorner2:
-               RS_DIALOGFACTORY->updateMouseWidget(tr("Drag to second point"), tr("Back"));
+               DIALOGFACTORY->updateMouseWidget(tr("Drag to second point"), tr("Back"));
                break;
 
        default:
-               RS_DIALOGFACTORY->updateMouseWidget("", "");
+               DIALOGFACTORY->updateMouseWidget("", "");
                break;
        }
 }
@@ -361,7 +385,7 @@ void ActionDefault::updateToolBar()
 
        case Moving:
        case MovingRef:
-               RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
+               DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
                break;
 
        default: