From bfd926cd5fd98e95b8b172fabd5340c9b1957e01 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Mon, 25 Oct 2010 20:15:55 +0000 Subject: [PATCH] Removed Snapper class; still refactoring Snapper/Preview... --- architektonas.pro | 8 +- src/actions/actionblockscreate.cpp | 35 +- src/actions/actionblocksinsert.cpp | 4 +- src/actions/actiondefault.cpp | 43 +- src/actions/actiondimlinear.cpp | 11 +- src/actions/actiondrawlineangle.cpp | 7 +- src/actions/actiondrawlinebisector.cpp | 2 +- src/actions/actiondrawlineparallel.cpp | 2 +- src/actions/actiondrawlinerectangle.cpp | 2 +- src/actions/actiondrawpolyline.cpp | 4 +- src/actions/actionmodifydeletefree.cpp | 4 +- src/actions/actionzoompan.cpp | 3 +- src/base/actioninterface.cpp | 18 +- src/base/eventhandler.cpp | 134 ++--- src/base/eventhandler.h | 48 +- src/base/snapper.cpp | 648 ------------------------ src/base/snapper.h | 127 ----- src/mainapp/graphicview.cpp | 104 ++-- src/mainapp/graphicview.h | 4 +- 19 files changed, 195 insertions(+), 1013 deletions(-) delete mode 100644 src/base/snapper.cpp delete mode 100644 src/base/snapper.h diff --git a/architektonas.pro b/architektonas.pro index a4c73df..b9b6b50 100644 --- a/architektonas.pro +++ b/architektonas.pro @@ -101,7 +101,6 @@ HEADERS += \ src/base/script.h \ src/base/scriptlist.h \ src/base/selection.h \ - src/base/snapper.h \ src/base/solid.h \ src/base/spline.h \ src/base/staticgraphicview.h \ @@ -117,6 +116,9 @@ HEADERS += \ src/base/vector.h \ src/base/vectorsolutions.h +# src/base/snapper.h \ +# + SOURCES = \ fparser/fparser.cc \ fparser/fpoptimizer.cc @@ -179,7 +181,6 @@ SOURCES += \ src/base/script.cpp \ src/base/scriptlist.cpp \ src/base/selection.cpp \ - src/base/snapper.cpp \ src/base/solid.cpp \ src/base/spline.cpp \ src/base/staticgraphicview.cpp \ @@ -195,6 +196,9 @@ SOURCES += \ src/base/vector.cpp \ src/base/vectorsolutions.cpp +# src/base/snapper.cpp \ +# + HEADERS += \ src/actions/actionblocksadd.h \ src/actions/actionblocksattributes.h \ diff --git a/src/actions/actionblockscreate.cpp b/src/actions/actionblockscreate.cpp index 723b95c..f377ee7 100644 --- a/src/actions/actionblockscreate.cpp +++ b/src/actions/actionblockscreate.cpp @@ -35,20 +35,6 @@ ActionBlocksCreate::~ActionBlocksCreate() { } -#if 0 -QAction * ActionBlocksCreate::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) -{ - QAction * action = new QAction(tr("&Create Block"), 0); -// QAction* action = new QAction(tr("Create Block"), -// tr("&Create Block"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Create Block")); - - return action; -} - -#endif - /*virtual*/ RS2::ActionType ActionBlocksCreate::rtti() { return RS2::ActionBlocksCreate; @@ -61,19 +47,11 @@ void ActionBlocksCreate::init(int status) void ActionBlocksCreate::trigger() { -// deleteSnapper(); - //deletePreview(); - //clearPreview(); - - //Modification m(*container, graphicView); - //m.paste(data.insertionPoint); - //std::cout << *Clipboard::instance(); - - if (graphic != NULL) + if (graphic) { BlockList * blockList = graphic->getBlockList(); - if (blockList != NULL) + if (blockList) { BlockData d = DIALOGFACTORY->requestNewBlockDialog(blockList); @@ -81,7 +59,6 @@ void ActionBlocksCreate::trigger() { Creation creation(container, graphicView); creation.createBlock(d, referencePoint, true); - InsertData id(d.name, referencePoint, Vector(1.0, 1.0), 0.0, 1, 1, Vector(0.0, 0.0)); creation.createInsert(id); } @@ -95,8 +72,8 @@ void ActionBlocksCreate::trigger() void ActionBlocksCreate::mouseMoveEvent(QMouseEvent * e) { -// snapPoint(e); - graphicView->snapper.snapPoint(e); +// graphicView->snapper.snapPoint(e); + graphicView->SnapPoint(e); switch (getStatus()) { @@ -123,8 +100,8 @@ void ActionBlocksCreate::mouseReleaseEvent(QMouseEvent * e) { if (e->button() == Qt::LeftButton) { -// Vector ce(snapPoint(e)); - Vector ce(graphicView->snapper.snapPoint(e)); +// Vector ce(graphicView->snapper.snapPoint(e)); + Vector ce(graphicView->SnapPoint(e)); coordinateEvent(&ce); } else if (e->button() == Qt::RightButton) diff --git a/src/actions/actionblocksinsert.cpp b/src/actions/actionblocksinsert.cpp index 48d6ff9..da6eea9 100644 --- a/src/actions/actionblocksinsert.cpp +++ b/src/actions/actionblocksinsert.cpp @@ -89,7 +89,7 @@ void ActionBlocksInsert::mouseMoveEvent(QMouseEvent * e) { case SetTargetPoint: // data.insertionPoint = snapPoint(e); - data.insertionPoint = graphicView->snapper.snapPoint(e); + data.insertionPoint = graphicView->SnapPoint(e); if (block != NULL) { @@ -116,7 +116,7 @@ void ActionBlocksInsert::mouseReleaseEvent(QMouseEvent * e) if (e->button() == Qt::LeftButton) { // Vector ce(snapPoint(e)); - Vector ce(graphicView->snapper.snapPoint(e)); + Vector ce(graphicView->SnapPoint(e)); coordinateEvent(&ce); } else if (e->button() == Qt::RightButton) diff --git a/src/actions/actiondefault.cpp b/src/actions/actiondefault.cpp index 801a051..74e77dd 100644 --- a/src/actions/actiondefault.cpp +++ b/src/actions/actiondefault.cpp @@ -34,9 +34,6 @@ ActionDefault::ActionDefault(EntityContainer & container, ActionInterface("Default", container, graphicView) { DEBUG->print("ActionDefault::ActionDefault"); - //hm. -// graphicView.snapper.SetVisible(); -// graphicView.preview.SetVisible(); DEBUG->print("ActionDefault::ActionDefault: OK"); } @@ -55,8 +52,10 @@ void ActionDefault::init(int status /*= 0*/) ActionInterface::init(status); v1 = v2 = Vector(false); - graphicView->snapper.setSnapMode(RS2::SnapFree); - graphicView->snapper.setSnapRestriction(RS2::RestrictNothing); +// graphicView->snapper.setSnapMode(RS2::SnapFree); +// graphicView->snapper.setSnapRestriction(RS2::RestrictNothing); + graphicView->setDefaultSnapMode(RS2::SnapFree); + graphicView->setSnapRestriction(RS2::RestrictNothing); restrBak = RS2::RestrictNothing; DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); @@ -72,22 +71,24 @@ void ActionDefault::keyPressEvent(QKeyEvent * e) { if (e->key() == Qt::Key_Shift) { - restrBak = graphicView->snapper.getSnapRestriction(); - graphicView->snapper.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) - graphicView->snapper.setSnapRestriction(restrBak); +// 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(); - DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse); switch (getStatus()) @@ -111,7 +112,8 @@ void ActionDefault::mouseMoveEvent(QMouseEvent * e) else { // test for an entity to drag: - Entity * en = graphicView->snapper.catchEntity(v1); +// Entity * en = graphicView->snapper.catchEntity(v1); + Entity * en = graphicView->CatchEntity(v1); if (en && en->isSelected()) { @@ -138,7 +140,8 @@ void ActionDefault::mouseMoveEvent(QMouseEvent * e) graphicView->preview.clear(); graphicView->preview.addSelectionFrom(*container); graphicView->preview.moveRef(v1, v2 -v1); - graphicView->snapper.SetVisible(); +// graphicView->snapper.SetVisible(); + graphicView->SetSnapperVisible(); graphicView->preview.SetVisible(); graphicView->redraw(); break; @@ -153,7 +156,8 @@ void ActionDefault::mouseMoveEvent(QMouseEvent * e) graphicView->preview.clear(); graphicView->preview.addSelectionFrom(*container); graphicView->preview.move(v2 -v1); - graphicView->snapper.SetVisible(); +// graphicView->snapper.SetVisible(); + graphicView->SetSnapperVisible(); graphicView->preview.SetVisible(); graphicView->redraw(); break; @@ -211,7 +215,7 @@ void ActionDefault::mousePressEvent(QMouseEvent * e) DIALOGFACTORY->updateSelectionWidget(container->countSelected()); DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); } - break; + break; case MovingRef: { @@ -228,7 +232,7 @@ void ActionDefault::mousePressEvent(QMouseEvent * e) DIALOGFACTORY->updateSelectionWidget(container->countSelected()); DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); } - break; + break; default: break; @@ -249,7 +253,8 @@ void ActionDefault::mouseReleaseEvent(QMouseEvent * e) case Dragging: { // select single entity: - Entity * en = graphicView->snapper.catchEntity(e); +// Entity * en = graphicView->snapper.catchEntity(e); + Entity * en = graphicView->CatchEntity(e); if (en) { @@ -259,9 +264,7 @@ void ActionDefault::mouseReleaseEvent(QMouseEvent * e) Selection s(*container, graphicView); s.selectSingle(en); - DIALOGFACTORY->updateSelectionWidget(container->countSelected()); - e->accept(); setStatus(Neutral); } @@ -293,7 +296,8 @@ void ActionDefault::mouseReleaseEvent(QMouseEvent * e) default: // Was either moving entity or point, so clear that shiatsu - graphicView->snapper.SetVisible(false); +// graphicView->snapper.SetVisible(false); + graphicView->SetSnapperVisible(false); graphicView->preview.SetVisible(false); graphicView->redraw(); break; @@ -315,7 +319,8 @@ void ActionDefault::mouseReleaseEvent(QMouseEvent * e) break; default: - graphicView->snapper.SetVisible(false); +// graphicView->snapper.SetVisible(false); + graphicView->SetSnapperVisible(false); graphicView->preview.SetVisible(false); DIALOGFACTORY->requestPreviousMenu(); e->accept(); diff --git a/src/actions/actiondimlinear.cpp b/src/actions/actiondimlinear.cpp index 3191f1c..1560ac7 100644 --- a/src/actions/actiondimlinear.cpp +++ b/src/actions/actiondimlinear.cpp @@ -38,7 +38,8 @@ ActionDimLinear::ActionDimLinear(EntityContainer & container, this->fixedAngle = fixedAngle; lastStatus = SetExtPoint1; //hm. doesn't work. - graphicView.snapper.SetVisible(); +// graphicView.snapper.SetVisible(); + graphicView.SetSnapperVisible(); reset(); } @@ -84,7 +85,7 @@ void ActionDimLinear::trigger() // graphicView->drawEntity(dim); // graphicView->moveRelativeZero(rz); // drawSnapper(); - graphicView->snapper.SetVisible(false); + graphicView->SetSnapperVisible(false); graphicView->redraw(); DEBUG->print("ActionDimLinear::trigger(): dim added: %d", dim->getId()); @@ -165,14 +166,16 @@ void ActionDimLinear::mouseReleaseEvent(QMouseEvent * e) { Vector ce(snapPoint(e)); coordinateEvent(&ce); - graphicView->snapper.SetVisible(); +// graphicView->snapper.SetVisible(); + graphicView->SetSnapperVisible(); } else if (e->button() == Qt::RightButton) { if (getStatus() == 0) { graphicView->preview.SetVisible(false); - graphicView->snapper.SetVisible(false); +// graphicView->snapper.SetVisible(false); + graphicView->SetSnapperVisible(false); } // deletePreview(); diff --git a/src/actions/actiondrawlineangle.cpp b/src/actions/actiondrawlineangle.cpp index aeff68a..22e0671 100644 --- a/src/actions/actiondrawlineangle.cpp +++ b/src/actions/actiondrawlineangle.cpp @@ -29,11 +29,6 @@ ActionDrawLineAngle::ActionDrawLineAngle(EntityContainer & container, pos(Vector(false)), angle(a), length(1.0), fixedAngle(fa), snpPoint(0) { reset(); - //hm. -// graphicView.snapper.SetContainer(&container); -// graphicView.snapper.SetGraphicView(&graphicView); -// graphicView.snapper.SetVisible(); -// graphicView.preview.SetVisible(); } ActionDrawLineAngle::~ActionDrawLineAngle() @@ -109,7 +104,7 @@ void ActionDrawLineAngle::mouseReleaseEvent(QMouseEvent * e) if (getStatus() == SetPos) { // Vector ce(snapPoint(e)); - Vector ce(graphicView->snapper.snapPoint(e)); + Vector ce(graphicView->SnapPoint(e)); coordinateEvent(&ce); } } diff --git a/src/actions/actiondrawlinebisector.cpp b/src/actions/actiondrawlinebisector.cpp index eb71727..7ed8b19 100644 --- a/src/actions/actiondrawlinebisector.cpp +++ b/src/actions/actiondrawlinebisector.cpp @@ -29,7 +29,7 @@ ActionDrawLineBisector::ActionDrawLineBisector(EntityContainer & container, bisector(NULL), line1(NULL), line2(NULL), length(10.0), number(1), coord1(Vector(false)), coord2(Vector(false)), lastStatus(SetLine1) { - graphicView.snapper.SetVisible(false); + graphicView.SetSnapperVisible(false); } ActionDrawLineBisector::~ActionDrawLineBisector() diff --git a/src/actions/actiondrawlineparallel.cpp b/src/actions/actiondrawlineparallel.cpp index f8a473a..24e8360 100644 --- a/src/actions/actiondrawlineparallel.cpp +++ b/src/actions/actiondrawlineparallel.cpp @@ -31,7 +31,7 @@ ActionDrawLineParallel::ActionDrawLineParallel(EntityContainer & container, ActionInterface("Draw Parallels", container, graphicView), parallel(NULL), distance(1.0), number(1), coord(Vector(false)), entity(NULL) { - graphicView.snapper.SetVisible(false); + graphicView.SetSnapperVisible(false); } ActionDrawLineParallel::~ActionDrawLineParallel() diff --git a/src/actions/actiondrawlinerectangle.cpp b/src/actions/actiondrawlinerectangle.cpp index 7b3d6a1..8700700 100644 --- a/src/actions/actiondrawlinerectangle.cpp +++ b/src/actions/actiondrawlinerectangle.cpp @@ -119,7 +119,7 @@ void ActionDrawLineRectangle::mouseReleaseEvent(QMouseEvent * e) if (e->button() == Qt::LeftButton) { // Vector ce(snapPoint(e)); - Vector ce(graphicView->snapper.snapPoint(e)); + Vector ce(graphicView->SnapPoint(e)); coordinateEvent(&ce); } else if (e->button() == Qt::RightButton) diff --git a/src/actions/actiondrawpolyline.cpp b/src/actions/actiondrawpolyline.cpp index 65a7270..1ddd412 100644 --- a/src/actions/actiondrawpolyline.cpp +++ b/src/actions/actiondrawpolyline.cpp @@ -74,7 +74,7 @@ void ActionDrawPolyline::mouseMoveEvent(QMouseEvent * e) DEBUG->print("ActionDrawPolyline::mouseMoveEvent(): line added: %d", ent->getId()); } #else - Vector mouse = graphicView->snapper.snapPoint(e); + Vector mouse = graphicView->SnapPoint(e); if (getStatus() == SetNextPoint && startPoint.valid) { @@ -142,7 +142,7 @@ void ActionDrawPolyline::mouseReleaseEvent(QMouseEvent * e) { if (e->button() == Qt::LeftButton) { - Vector ce(graphicView->snapper.snapPoint(e)); + Vector ce(graphicView->SnapPoint(e)); coordinateEvent(&ce); //let's try this... diff --git a/src/actions/actionmodifydeletefree.cpp b/src/actions/actionmodifydeletefree.cpp index 8a8c196..434d7d5 100644 --- a/src/actions/actionmodifydeletefree.cpp +++ b/src/actions/actionmodifydeletefree.cpp @@ -107,7 +107,7 @@ void ActionModifyDeleteFree::mouseReleaseEvent(QMouseEvent * e) case 0: v1 = snapPoint(e); // e1 = getKeyEntity(); - e1 = graphicView->snapper.getKeyEntity(); + e1 = graphicView->GetSnapperEntity(); if (e1) { @@ -137,7 +137,7 @@ void ActionModifyDeleteFree::mouseReleaseEvent(QMouseEvent * e) case 1: v2 = snapPoint(e); // e2 = getKeyEntity(); - e2 = graphicView->snapper.getKeyEntity(); + e2 = graphicView->GetSnapperEntity(); if (e2) trigger(); diff --git a/src/actions/actionzoompan.cpp b/src/actions/actionzoompan.cpp index 74b3d82..c2f0280 100644 --- a/src/actions/actionzoompan.cpp +++ b/src/actions/actionzoompan.cpp @@ -21,7 +21,8 @@ ActionZoomPan::ActionZoomPan(EntityContainer & container, GraphicView & graphicView): ActionInterface("Zoom Pan", container, graphicView) { - graphicView.snapper.SetVisible(false); +// graphicView.snapper.SetVisible(false); + graphicView.SetSnapperVisible(false); graphicView.preview.SetVisible(false); } diff --git a/src/base/actioninterface.cpp b/src/base/actioninterface.cpp index 17d1da9..1b4d5d8 100644 --- a/src/base/actioninterface.cpp +++ b/src/base/actioninterface.cpp @@ -30,6 +30,8 @@ I think what's needed here is for the constructor to save the state of the snapp and to restore it in the destructor. This, of course, assumes that the actions are created and used in a certain order, perhaps that needs enforcement? Dunno, but worth a try as suspend() and resume() seem to fuck it up badly. +#define _ASSUAN_DEPRECATED __attribute__ ((__deprecated__)) +on MS it's: __declspec(deprecated) */ /** @@ -51,6 +53,11 @@ ActionInterface::ActionInterface(const char * name, EntityContainer & ec, { DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\"", name); +//This doesn't work properly; not sure why that is... +//Actually, it's working perfectly. Now we just need to propagate the fixes everywhere. :-/ + // We'll use snapperVisibility for the save/restore functionality... + snapperVisibility = graphicView->SnapperVisible(); + this->name = name; status = 0; finished = false; @@ -63,6 +70,7 @@ ActionInterface::ActionInterface(const char * name, EntityContainer & ec, document = ec.getDocument(); // \o/ \o/ \o/ BY GRABTHAR'S HAMMER, IT HAS BEEN EXPUNGED!!! \o/ \o/ \o/ + // This is here until I can figure out a better way to contain all of this // circular referential nonsense that exists in this codebase. It will be // expunged, by Grabthar's Hammer! @@ -75,7 +83,7 @@ ActionInterface::ActionInterface(const char * name, EntityContainer & ec, graphicView->preview.SetVisible(); DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\": OK", name); -printf("ActionInterface::ActionInterface() [%08X]\n", this); +//printf("ActionInterface::ActionInterface() [%08X]\n", this); } /** @@ -86,7 +94,10 @@ printf("ActionInterface::ActionInterface() [%08X]\n", this); // would be pure virtual now: // hideOptions(); //JLH: Only it isn't pure virtual... -printf("ActionInterface::~ActionInterface() [%08X]\n", this); +//printf("ActionInterface::~ActionInterface() [%08X]\n", this); + + // We'll use snapperVisibility for the save/restore functionality... + graphicView->SetSnapperVisible(snapperVisibility); } /** @@ -316,6 +327,9 @@ void ActionInterface::finish() // hm. // graphicView->snapper.SetVisible(false); graphicView->SetSnapperVisible(false); +//Short circuit the destructor fuxoring with this: +//snapperVisibility = false; +//Only it causes other stuff to be fuxorred... Grr... Not sure how to fix this... graphicView->preview.SetVisible(false); // graphicView->preview.clear(); graphicView->redraw(); //hm. diff --git a/src/base/eventhandler.cpp b/src/base/eventhandler.cpp index d8d8f2b..7d7cd6b 100644 --- a/src/base/eventhandler.cpp +++ b/src/base/eventhandler.cpp @@ -14,6 +14,8 @@ // JLH 05/28/2010 Added this text. :-) // +// This is only used by the GraphicView class... + #include "eventhandler.h" #include "actioninterface.h" @@ -26,16 +28,17 @@ /** * Constructor. */ -EventHandler::EventHandler(GraphicView * graphicView) +EventHandler::EventHandler()://GraphicView * graphicView) + defaultAction(NULL), actionIndex(-1), coordinateInputEnabled(true) { - this->graphicView = graphicView; - actionIndex = -1; +// this->graphicView = graphicView; +// actionIndex = -1; - for(int i=0; iprint("EventHandler::~EventHandler: Deleting all actions.."); @@ -66,7 +69,7 @@ EventHandler::~EventHandler() } } - cleanUp(); + CleanUp(); DEBUG->print("EventHandler::~EventHandler: Deleting all actions..: OK"); DEBUG->print("EventHandler::~EventHandler: OK"); } @@ -74,27 +77,27 @@ EventHandler::~EventHandler() /** * Go back in current action. */ -void EventHandler::back() +void EventHandler::Back() { QMouseEvent e(QEvent::MouseButtonRelease, QPoint(0, 0), Qt::RightButton, Qt::RightButton, Qt::NoModifier); - mouseReleaseEvent(&e); + MouseReleaseEvent(&e); } /** * Go enter pressed event for current action. */ -void EventHandler::enter() +void EventHandler::Enter() { // QKeyEvent e(QEvent::KeyPress, Qt::Key_Enter, '\n', 0); QKeyEvent e(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier, "\n", false, 0); - keyPressEvent(&e); + KeyPressEvent(&e); } /** * Called by GraphicView */ -void EventHandler::mousePressEvent(QMouseEvent * e) +void EventHandler::MousePressEvent(QMouseEvent * e) { if (actionIndex >= 0 && currentActions[actionIndex] != NULL) { @@ -119,7 +122,7 @@ void EventHandler::mousePressEvent(QMouseEvent * e) /** * Called by GraphicView */ -void EventHandler::mouseReleaseEvent(QMouseEvent * e) +void EventHandler::MouseReleaseEvent(QMouseEvent * e) { if (actionIndex >= 0 && currentActions[actionIndex] != NULL && !currentActions[actionIndex]->isFinished()) @@ -128,7 +131,7 @@ void EventHandler::mouseReleaseEvent(QMouseEvent * e) currentActions[actionIndex]->mouseReleaseEvent(e); // Clean up actions - one might be finished now - cleanUp(); + CleanUp(); e->accept(); } else @@ -143,7 +146,7 @@ void EventHandler::mouseReleaseEvent(QMouseEvent * e) /** * Called by GraphicView */ -void EventHandler::mouseMoveEvent(QMouseEvent * e) +void EventHandler::MouseMoveEvent(QMouseEvent * e) { if (actionIndex >= 0 && currentActions[actionIndex] && !currentActions[actionIndex]->isFinished()) @@ -177,7 +180,7 @@ into GraphicView itself and be done with it? /** * Called by GraphicView */ -void EventHandler::mouseLeaveEvent() +void EventHandler::MouseLeaveEvent() { #if 0 if (actionIndex >= 0 && currentActions[actionIndex] @@ -197,7 +200,7 @@ void EventHandler::mouseLeaveEvent() /** * Called by GraphicView */ -void EventHandler::mouseEnterEvent() +void EventHandler::MouseEnterEvent() { #if 0 if (actionIndex >= 0 && currentActions[actionIndex] @@ -216,7 +219,7 @@ void EventHandler::mouseEnterEvent() /** * Called by GraphicView */ -void EventHandler::keyPressEvent(QKeyEvent * e) +void EventHandler::KeyPressEvent(QKeyEvent * e) { if (actionIndex >= 0 && currentActions[actionIndex] && !currentActions[actionIndex]->isFinished()) @@ -237,7 +240,7 @@ void EventHandler::keyPressEvent(QKeyEvent * e) /** * Called by GraphicView */ -void EventHandler::keyReleaseEvent(QKeyEvent * e) +void EventHandler::KeyReleaseEvent(QKeyEvent * e) { if (actionIndex >= 0 && currentActions[actionIndex] && !currentActions[actionIndex]->isFinished()) @@ -258,7 +261,7 @@ void EventHandler::keyReleaseEvent(QKeyEvent * e) /** * Handles command line events. */ -void EventHandler::commandEvent(CommandEvent * e) +void EventHandler::HandleCommandEvent(GraphicView * graphicView, CommandEvent * e) { DEBUG->print("EventHandler::commandEvent"); QString cmd = e->getCommand(); @@ -284,16 +287,13 @@ void EventHandler::commandEvent(CommandEvent * e) if (ok1 && ok2) { -// DEBUG->print("EventHandler::commandEvent: 005"); -// CoordinateEvent ce(Vector(x, y)); DEBUG->print("EventHandler::commandEvent: 006"); -// currentActions[actionIndex]->coordinateEvent(&ce); Vector ce(x, y); currentActions[actionIndex]->coordinateEvent(&ce); } else { - if (DIALOGFACTORY != NULL) + if (DIALOGFACTORY) DIALOGFACTORY->commandMessage("Expression Syntax Error"); } @@ -317,14 +317,12 @@ void EventHandler::commandEvent(CommandEvent * e) if (ok1 && ok2) { -// CoordinateEvent ce(Vector(x,y) + graphicView->getRelativeZero()); -// currentActions[actionIndex]->coordinateEvent(&ce); Vector ce(Vector(x,y) + graphicView->getRelativeZero()); currentActions[actionIndex]->coordinateEvent(&ce); } else { - if (DIALOGFACTORY != NULL) + if (DIALOGFACTORY) DIALOGFACTORY->commandMessage("Expression Syntax Error"); } @@ -350,13 +348,11 @@ void EventHandler::commandEvent(CommandEvent * e) { Vector pos; pos.setPolar(r,Math::deg2rad(a)); -// CoordinateEvent ce(pos); -// currentActions[actionIndex]->coordinateEvent(&ce); currentActions[actionIndex]->coordinateEvent(&pos); } else { - if (DIALOGFACTORY != NULL) + if (DIALOGFACTORY) DIALOGFACTORY->commandMessage("Expression Syntax Error"); } @@ -373,7 +369,6 @@ void EventHandler::commandEvent(CommandEvent * e) if (actionIndex >= 0 && currentActions[actionIndex] !=NULL && !currentActions[actionIndex]->isFinished()) { -// int commaPos = cmd.find('<'); int commaPos = cmd.indexOf('<'); bool ok1, ok2; double r = Math::eval(cmd.mid(1, commaPos - 1), &ok1); @@ -383,8 +378,6 @@ void EventHandler::commandEvent(CommandEvent * e) { Vector pos; pos.setPolar(r,Math::deg2rad(a)); -// CoordinateEvent ce(pos + graphicView->getRelativeZero()); -// currentActions[actionIndex]->coordinateEvent(&ce); Vector ce(pos + graphicView->getRelativeZero()); currentActions[actionIndex]->coordinateEvent(&ce); } @@ -400,7 +393,7 @@ void EventHandler::commandEvent(CommandEvent * e) } } - // send command event directly to current action: + // Send command event directly to current action: if (!e->isAccepted()) { if (actionIndex >= 0 && currentActions[actionIndex] @@ -422,7 +415,7 @@ void EventHandler::commandEvent(CommandEvent * e) /** * Enables coordinate input in the command line. */ -void EventHandler::enableCoordinateInput() +void EventHandler::EnableCoordinateInput() { coordinateInputEnabled = true; } @@ -430,7 +423,7 @@ void EventHandler::enableCoordinateInput() /** * Enables coordinate input in the command line. */ -void EventHandler::disableCoordinateInput() +void EventHandler::DisableCoordinateInput() { coordinateInputEnabled = false; } @@ -438,7 +431,7 @@ void EventHandler::disableCoordinateInput() /** * @return Current action. */ -ActionInterface * EventHandler::getCurrentAction() +ActionInterface * EventHandler::GetCurrentAction() { if (actionIndex >= 0 && currentActions[actionIndex] && !currentActions[actionIndex]->isFinished()) @@ -450,7 +443,7 @@ ActionInterface * EventHandler::getCurrentAction() /** * @return The current default action. */ -ActionInterface * EventHandler::getDefaultAction() +ActionInterface * EventHandler::GetDefaultAction() { return defaultAction; } @@ -458,7 +451,7 @@ ActionInterface * EventHandler::getDefaultAction() /** * Sets the default action. */ -void EventHandler::setDefaultAction(ActionInterface * action) +void EventHandler::SetDefaultAction(ActionInterface * action) { if (defaultAction) { @@ -473,7 +466,7 @@ void EventHandler::setDefaultAction(ActionInterface * action) /** * Sets the current action. */ -void EventHandler::setCurrentAction(ActionInterface * action) +void EventHandler::SetCurrentAction(ActionInterface * action) { DEBUG->print("EventHandler::setCurrentAction"); @@ -504,7 +497,7 @@ void EventHandler::setCurrentAction(ActionInterface * action) // Forget about the oldest action and make space for the new action: if (actionIndex == RS_MAXACTIONS - 1) { - // delete oldest action if necessary (usually never happens): + // Delete oldest action if necessary (usually never happens): if (currentActions[0]) { currentActions[0]->finish(); @@ -538,10 +531,10 @@ void EventHandler::setCurrentAction(ActionInterface * action) } DEBUG->print("EventHandler::setCurrentAction: cleaning up.."); - cleanUp(); + CleanUp(); DEBUG->print("EventHandler::setCurrentAction: debugging actions"); - debugActions(); + DebugActions(); DEBUG->print("GraphicView::setCurrentAction: OK"); } @@ -549,7 +542,7 @@ void EventHandler::setCurrentAction(ActionInterface * action) * Kills all running selection actions. Called when a selection action * is launched to reduce confusion. */ -void EventHandler::killSelectActions() +void EventHandler::KillSelectActions() { for(int c=0; cprint("EventHandler::cleanUp"); @@ -604,7 +598,7 @@ void EventHandler::cleanUp() bool doResume = false; // do we need to resume an action actionIndex = -1; - debugActions(); + DebugActions(); do { @@ -644,7 +638,7 @@ void EventHandler::cleanUp() } while (oldIndex < RS_MAXACTIONS); - debugActions(); + DebugActions(); // Resume last used action: if (doResume) @@ -667,45 +661,7 @@ void EventHandler::cleanUp() DEBUG->print("EventHandler::cleanUp: OK"); } -/** - * Sets the snap mode for all currently active actions. - */ -void EventHandler::setSnapMode(RS2::SnapMode sm) -{ -#if 0 - for(int c=0; csetSnapMode(sm); - - if (defaultAction) - defaultAction->setSnapMode(sm); -#else -#warning "!!! Not sure if this is going to work correctly..." -//seems to - graphicView->snapper.setSnapMode(sm); -#endif -} - -/** - * Sets the snap restriction for all currently active actions. - */ -void EventHandler::setSnapRestriction(RS2::SnapRestriction sr) -{ -#if 0 - for(int c=0; csetSnapRestriction(sr); - - if (defaultAction) - defaultAction->setSnapRestriction(sr); -#else -#warning "!!! Not sure if this is going to work correctly..." -//seems to - graphicView->snapper.setSnapRestriction(sr); -#endif -} - -void EventHandler::debugActions() +void EventHandler::DebugActions() { DEBUG->print("---"); diff --git a/src/base/eventhandler.h b/src/base/eventhandler.h index 4651a89..203e9b4 100644 --- a/src/base/eventhandler.h +++ b/src/base/eventhandler.h @@ -2,7 +2,6 @@ #define __EVENTHANDLER_H__ #include -#include "enums.h" #define RS_MAXACTIONS 16 @@ -18,35 +17,32 @@ class GraphicView; class EventHandler { public: - EventHandler(GraphicView * graphicView); + EventHandler(); ~EventHandler(); - void back(); - void enter(); - void mousePressEvent(QMouseEvent * e); - void mouseReleaseEvent(QMouseEvent * e); - void mouseMoveEvent(QMouseEvent * e); - void mouseLeaveEvent(); - void mouseEnterEvent(); - void keyPressEvent(QKeyEvent * e); - void keyReleaseEvent(QKeyEvent * e); - void commandEvent(CommandEvent * e); - void enableCoordinateInput(); - void disableCoordinateInput(); - void setDefaultAction(ActionInterface * action); - ActionInterface * getDefaultAction(); - void setCurrentAction(ActionInterface * action); - ActionInterface * getCurrentAction(); - void killSelectActions(); - void killAllActions(); - bool hasAction(); - void cleanUp(); - void debugActions(); - void setSnapMode(RS2::SnapMode sm); - void setSnapRestriction(RS2::SnapRestriction sr); + void Back(); + void Enter(); + void MousePressEvent(QMouseEvent * e); + void MouseReleaseEvent(QMouseEvent * e); + void MouseMoveEvent(QMouseEvent * e); + void MouseLeaveEvent(); + void MouseEnterEvent(); + void KeyPressEvent(QKeyEvent * e); + void KeyReleaseEvent(QKeyEvent * e); + void HandleCommandEvent(GraphicView *, CommandEvent * e); + void EnableCoordinateInput(); + void DisableCoordinateInput(); + void SetDefaultAction(ActionInterface * action); + ActionInterface * GetDefaultAction(); + void SetCurrentAction(ActionInterface * action); + ActionInterface * GetCurrentAction(); + void KillSelectActions(); + void KillAllActions(); + bool HasAction(); + void CleanUp(); + void DebugActions(); protected: - GraphicView * graphicView; ActionInterface * defaultAction; ActionInterface * currentActions[RS_MAXACTIONS]; int actionIndex; diff --git a/src/base/snapper.cpp b/src/base/snapper.cpp deleted file mode 100644 index 28e600a..0000000 --- a/src/base/snapper.cpp +++ /dev/null @@ -1,648 +0,0 @@ -// snapper.cpp -// -// Part of the Architektonas Project -// Originally part of QCad Community Edition by Andrew Mustun -// Extensively rewritten and refactored by James L. Hammons -// 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 -// -// Who When What -// --- ---------- ----------------------------------------------------------- -// JLH 05/21/2010 Added this text. :-) -// JLH 10/18/2010 Commented out all functions in preparation for deprecating -// this class. -// - -#include "snapper.h" - -#include "dialogfactory.h" -#include "drawing.h" -#include "entitycontainer.h" -#include "graphicview.h" -#include "grid.h" -#include "information.h" -#include "paintinterface.h" -#include "settings.h" - -/** - * Constructor. - */ -Snapper::Snapper(EntityContainer & c, GraphicView & gv): - container(&c), graphicView(&gv), finished(false) -{ -#if 0 - init(); -#endif -} - -Snapper::Snapper(void): - container(NULL), graphicView(NULL), finished(false) -{ -#if 0 - init(); -#endif -} - -/** - * Destructor. - */ -Snapper::~Snapper() -{ -} - -/** - * Initialize (called by all constructors) - */ -void Snapper::init() -{ -#if 0 - if (graphicView) - { - snapMode = graphicView->getDefaultSnapMode(); - snapRes = graphicView->getSnapRestriction(); - } - - keyEntity = NULL; - snapSpot = Vector(false); - snapCoord = Vector(false); - visible = false; - distance = 1.0; - - settings.beginGroup("Snap"); - snapRange = settings.value("Range", 20).toInt(); - settings.endGroup(); - settings.beginGroup("Appearance"); - showCrosshairs = settings.value("ShowCrosshairs", true).toBool(); - settings.endGroup(); - - // Sanity check - if (snapRange < 2) - snapRange = 20; -#endif -} - -void Snapper::finish() -{ -#if 0 - finished = true; -#endif -} - -//bleh -void Snapper::SetContainer(EntityContainer * c) -{ -#if 0 - container = c; -#endif -} - -//bleh -void Snapper::SetGraphicView(GraphicView * v) -{ -#if 0 - graphicView = v; -#endif -} - -/** - * @return Pointer to the entity which was the key entity for the last - * successful snapping action. If the snap mode is "end point" the key entity - * is the entity whose end point was caught. If the snap mode didn't require an - * entity (e.g. free, grid) this method will return NULL. - */ -Entity * Snapper::getKeyEntity() -{ -#if 0 - return keyEntity; -#endif - return NULL; -} - -/** Sets a new snap mode. */ -void Snapper::setSnapMode(RS2::SnapMode snapMode) -{ -#if 0 - this->snapMode = snapMode; -#endif -} - -/** Sets a new snap restriction. */ -void Snapper::setSnapRestriction(RS2::SnapRestriction snapRes) -{ -#if 0 - this->snapRes = snapRes; -#endif -} - -RS2::SnapMode Snapper::getSnapMode(void) -{ -#if 0 - return snapMode; -#endif - return RS2::SnapFree; -} - -RS2::SnapRestriction Snapper::getSnapRestriction(void) -{ -#if 0 - return snapRes; -#endif - return RS2::RestrictNothing; -} - -/** - * Sets the snap range in pixels for catchEntity(). - * - * @see catchEntity() - */ -void Snapper::setSnapRange(int r) -{ -#if 0 - snapRange = r; -#endif -} - -#if 0 -This should get moved into GraphicView... -#endif -/** - * Snap to a coordinate in the drawing using the current snap mode. - * - * @param e A mouse event. - * @return The coordinates of the point or an invalid vector. - */ -Vector Snapper::snapPoint(QMouseEvent * e) -{ -#if 0 - DEBUG->print("Snapper::snapPoint"); - snapSpot = Vector(false); - - if (!e) - { - DEBUG->print(Debug::D_WARNING, "Snapper::snapPoint: event is NULL"); - return snapSpot; - } - - Vector mouseCoord = graphicView->toGraph(e->x(), e->y()); - - switch (snapMode) - { - case RS2::SnapFree: - snapSpot = snapFree(mouseCoord); - break; - - case RS2::SnapEndpoint: - snapSpot = snapEndpoint(mouseCoord); - break; - - case RS2::SnapGrid: - snapSpot = snapGrid(mouseCoord); - break; - - case RS2::SnapOnEntity: - snapSpot = snapOnEntity(mouseCoord); - break; - - case RS2::SnapCenter: - snapSpot = snapCenter(mouseCoord); - break; - - case RS2::SnapMiddle: - snapSpot = snapMiddle(mouseCoord); - break; - - case RS2::SnapDist: - snapSpot = snapDist(mouseCoord); - break; - - case RS2::SnapIntersection: - snapSpot = snapIntersection(mouseCoord); - break; - - default: - break; - } - - // Handle snap restrictions that can be activated in addition to the ones above: - switch (snapRes) - { - case RS2::RestrictOrthogonal: - snapCoord = restrictOrthogonal(snapSpot); - break; - case RS2::RestrictHorizontal: - snapCoord = restrictHorizontal(snapSpot); - break; - case RS2::RestrictVertical: - snapCoord = restrictVertical(snapSpot); - break; - default: - case RS2::RestrictNothing: - snapCoord = snapSpot; - break; - } - - if (DIALOGFACTORY) - DIALOGFACTORY->updateCoordinateWidget(snapCoord, snapCoord - graphicView->getRelativeZero()); - - DEBUG->print("Snapper::snapPoint: OK"); - - return snapCoord; -#endif - return Vector(false); -} - -/** - * Snaps to a free coordinate. - * - * @param coord The mouse coordinate. - * @return The coordinates of the point or an invalid vector. - */ -Vector Snapper::snapFree(Vector coord) -{ -#if 0 - keyEntity = NULL; - return coord; -#endif - return Vector(false); -} - -/** - * Snaps to the closest endpoint. - * - * @param coord The mouse coordinate. - * @return The coordinates of the point or an invalid vector. - */ -Vector Snapper::snapEndpoint(Vector coord) -{ -#if 0 - Vector vec(false); - vec = container->getNearestEndpoint(coord, NULL); - - return vec; -#endif - return Vector(false); -} - -/** - * Snaps to a grid point. - * - * @param coord The mouse coordinate. - * @return The coordinates of the point or an invalid vector. - */ -Vector Snapper::snapGrid(Vector coord) -{ -#if 0 - DEBUG->print("Snapper::snapGrid begin"); - - Vector vec(false); - double dist = 0.0; - - Grid * grid = graphicView->getGrid(); - - DEBUG->print("Snapper::snapGrid 001"); - - if (grid) - { - DEBUG->print("Snapper::snapGrid 002"); - Vector * pts = grid->getPoints(); - DEBUG->print("Snapper::snapGrid 003"); - int closest = -1; - dist = 32000.00; - DEBUG->print("Snapper::snapGrid 004"); - - for(int i=0; icount(); ++i) - { - double d = pts[i].distanceTo(coord); - - if (d < dist) - { - closest = i; - dist = d; - } - } - - DEBUG->print("Snapper::snapGrid 005"); - - if (closest >= 0) - vec = pts[closest]; - - DEBUG->print("Snapper::snapGrid 006"); - } - - keyEntity = NULL; - - DEBUG->print("Snapper::snapGrid end"); - - return vec; -#endif - return Vector(false); -} - -/** - * Snaps to a point on an entity. - * - * @param coord The mouse coordinate. - * @return The coordinates of the point or an invalid vector. - */ -Vector Snapper::snapOnEntity(Vector coord) -{ -#if 0 - Vector vec(false); - vec = container->getNearestPointOnEntity(coord, true, NULL, &keyEntity); - - return vec; -#endif - return Vector(false); -} - -/** - * Snaps to the closest center. - * - * @param coord The mouse coordinate. - * @return The coordinates of the point or an invalid vector. - */ -Vector Snapper::snapCenter(Vector coord) -{ -#if 0 - Vector vec(false); - vec = container->getNearestCenter(coord, NULL); - - return vec; -#endif - return Vector(false); -} - -/** - * Snaps to the closest middle. - * - * @param coord The mouse coordinate. - * @return The coordinates of the point or an invalid vector. - */ -Vector Snapper::snapMiddle(Vector coord) -{ -#if 0 - Vector vec(false); - vec = container->getNearestMiddle(coord, NULL); - - return vec; -#endif - return Vector(false); -} - -/** - * Snaps to the closest point with a given distance to the endpoint. - * - * @param coord The mouse coordinate. - * @return The coordinates of the point or an invalid vector. - */ -Vector Snapper::snapDist(Vector coord) -{ -#if 0 - Vector vec(false); - vec = container->getNearestDist(distance, coord, NULL); - - return vec; -#endif - return Vector(false); -} - -/** - * Snaps to the closest intersection point. - * - * @param coord The mouse coordinate. - * @return The coordinates of the point or an invalid vector. - */ -Vector Snapper::snapIntersection(Vector coord) -{ -#if 0 - Vector vec(false); - vec = container->getNearestIntersection(coord, NULL); - - return vec; -#endif - return Vector(false); -} - -/** - * 'Corrects' the given coordinates to 0, 90, 180, 270 degrees relative to - * the current relative zero point. - * - * @param coord The uncorrected coordinates. - * @return The corrected coordinates. - */ -Vector Snapper::restrictOrthogonal(Vector coord) -{ -#if 0 - Vector rz = graphicView->getRelativeZero(); - Vector ret(coord); - - Vector retx = Vector(rz.x, ret.y); - Vector rety = Vector(ret.x, rz.y); - - if (retx.distanceTo(ret) > rety.distanceTo(ret)) - ret = rety; - else - ret = retx; - - return ret; -#endif - return Vector(false); -} - -/** - * 'Corrects' the given coordinates to 0, 180 degrees relative to - * the current relative zero point. - * - * @param coord The uncorrected coordinates. - * @return The corrected coordinates. - */ -Vector Snapper::restrictHorizontal(Vector coord) -{ -#if 0 - Vector rz = graphicView->getRelativeZero(); - - return Vector(coord.x, rz.y); -#endif - return Vector(false); -} - -/** - * 'Corrects' the given coordinates to 90, 270 degrees relative to - * the current relative zero point. - * - * @param coord The uncorrected coordinates. - * @return The corrected coordinates. - */ -Vector Snapper::restrictVertical(Vector coord) -{ -#if 0 - Vector rz = graphicView->getRelativeZero(); - - return Vector(rz.x, coord.y); -#endif - return Vector(false); -} - -/** - * Catches an entity which is close to the given position 'pos'. - * - * @param pos A graphic coordinate. - * @param level The level of resolving for iterating through the entity - * container - * @return Pointer to the entity or NULL. - */ -Entity * Snapper::catchEntity(const Vector & pos, RS2::ResolveLevel level) -{ -#if 0 - DEBUG->print("Snapper::catchEntity"); - - // Set default distance for points inside solids - double dist = graphicView->toGraphDX(snapRange) * 0.9; - Entity * entity = container->getNearestEntity(pos, &dist, level); - int idx = -1; - - if (entity && entity->getParent()) - idx = entity->getParent()->findEntity(entity); - - if (entity && dist <= graphicView->toGraphDX(snapRange)) - { - // Highlight: - DEBUG->print("Snapper::catchEntity: found: %d", idx); - return entity; - } -// else -// { - DEBUG->print("Snapper::catchEntity: not found"); - return NULL; -// } - -// DEBUG->print("Snapper::catchEntity: OK"); -#endif - return NULL; -} - -/** - * Catches an entity which is close to the mouse cursor. - * - * @param e A mouse event. - * @param level The level of resolving for iterating through the entity - * container - * @return Pointer to the entity or NULL. - */ -Entity * Snapper::catchEntity(QMouseEvent * e, RS2::ResolveLevel level) -{ -#if 0 - return catchEntity(Vector(graphicView->toGraphX(e->x()), - graphicView->toGraphY(e->y())), level); -#endif - return NULL; -} - -#if 0 -I think that these suspend() & resume() functions are not used anymore... -#endif -/** - * Suspends this snapper while another action takes place. - */ -/*virtual*/ void Snapper::suspend() -{ -#if 0 -#warning "!!! This may need to have SetVisibility() called !!!" -// deleteSnapper(); - snapSpot = snapCoord = Vector(false); -#endif -} - -/** - * Resumes this snapper after it has been suspended. - */ -/*virtual*/ void Snapper::resume() -{ -#if 0 -#warning "!!! This may need to have SetVisibility() called !!!" -// drawSnapper(); -#endif -} - -/** - * Hides the snapper options. - */ -/*virtual*/ void Snapper::hideOptions() -{ -#if 0 - if (snapMode == RS2::SnapDist && DIALOGFACTORY) - DIALOGFACTORY->requestSnapDistOptions(distance, false); -#endif -} - -/** - * Shows the snapper options. - */ -/*virtual*/ void Snapper::showOptions() -{ -#if 0 - if (snapMode == RS2::SnapDist && DIALOGFACTORY) - DIALOGFACTORY->requestSnapDistOptions(distance, true); -#endif -} - -void Snapper::SetVisible(bool visibility/*= true*/) -{ -#if 0 - visible = visibility; -#endif -} - -bool Snapper::Visible(void) -{ -#if 0 - return visible; -#endif -} - -/* -We need to figure out how to kick the GraphicView out of this class. Perhaps we -need to move the toGuiX/Y() functions into another class as static functions. -Further inspection seems to rule this out as they are pretty well coupled to the -GraphicView class... What to do? -*/ -void Snapper::Draw(GraphicView * view, PaintInterface * painter) -{ -#if 0 - if (finished || !snapSpot.valid || !snapCoord.valid) - return; - -//hm, I don't like graphicView kicking around in here, especially since it now -//lives inside GraphicView... How to !!! FIX !!!? -//We'll pass it in for now... - // Snap point (need to make sure the brush is NULL!) -// painter->setPen(Pen(Color(0, 127, 255), RS2::Width00, RS2::DashLine)); - painter->setPen(Pen(Color(255, 127, 0), RS2::Width00, RS2::DashLine)); - painter->drawCircle(view->toGui(snapCoord), 4); - - // Crosshairs - if (showCrosshairs) - { - painter->setPen(Pen(Color(0, 255, 255), RS2::Width00, RS2::DashLine)); - painter->drawLine(Vector(0, view->toGuiY(snapCoord.y)), - Vector(view->getWidth(), view->toGuiY(snapCoord.y))); - painter->drawLine(Vector(view->toGuiX(snapCoord.x), 0), - Vector(view->toGuiX(snapCoord.x), view->getHeight())); - } - - if (snapCoord != snapSpot) - { - painter->drawLine(view->toGui(snapSpot) + Vector(-5, 0), - view->toGui(snapSpot) + Vector(-1, 4)); - painter->drawLine(view->toGui(snapSpot) + Vector(0, 5), - view->toGui(snapSpot) + Vector(4, 1)); - painter->drawLine(view->toGui(snapSpot) + Vector(5, 0), - view->toGui(snapSpot) + Vector(1, -4)); - painter->drawLine(view->toGui(snapSpot) + Vector(0, -5), - view->toGui(snapSpot) + Vector(-4, -1)); - } -#endif -} diff --git a/src/base/snapper.h b/src/base/snapper.h deleted file mode 100644 index a37cf33..0000000 --- a/src/base/snapper.h +++ /dev/null @@ -1,127 +0,0 @@ -#ifndef __SNAPPER_H__ -#define __SNAPPER_H__ - -#include -#include "enums.h" -#include "vector.h" - -class Entity; -class EntityContainer; -class GraphicView; -class PaintInterface; - -/** - * This class is used for snapping functions in a graphic view. - * Actions are usually derrived from this base class if they need - * to catch entities or snap to coordinates. Use the methods to - * retrieve a graphic coordinate from a mouse coordinate. - * - * Possible snapping functions are described in RS_SnapMode. - * - * @author Andrew Mustun - */ -class Snapper -{ - public: - Snapper(EntityContainer & container, GraphicView & graphicView); - Snapper(); - virtual ~Snapper(); - - void init(); - void finish(); - - void SetContainer(EntityContainer *); - void SetGraphicView(GraphicView *); - Entity * getKeyEntity(); - void setSnapMode(RS2::SnapMode snapMode); - void setSnapRestriction(RS2::SnapRestriction snapRes); - RS2::SnapMode getSnapMode(void); - RS2::SnapRestriction getSnapRestriction(void); - void setSnapRange(int r); - - Vector snapPoint(QMouseEvent * e); - Vector snapFree(Vector coord); - Vector snapEndpoint(Vector coord); - Vector snapGrid(Vector coord); - Vector snapOnEntity(Vector coord); - Vector snapCenter(Vector coord); - Vector snapMiddle(Vector coord); - Vector snapDist(Vector coord); - Vector snapIntersection(Vector coord); - - Vector restrictOrthogonal(Vector coord); - Vector restrictHorizontal(Vector coord); - Vector restrictVertical(Vector coord); - - Entity * catchEntity(const Vector & pos, RS2::ResolveLevel level = RS2::ResolveNone); - Entity * catchEntity(QMouseEvent * e, RS2::ResolveLevel level = RS2::ResolveNone); - - virtual void suspend(); - virtual void resume(); - virtual void hideOptions(); - virtual void showOptions(); - -// void drawSnapper(); -// void deleteSnapper(); - -/* -How should we handle this? All rendering goes through the GraphicView (QG_GraphicView to be -precise, soon to be merged in) as it should. So shouldn't we control the snapper through -that class as well? Unfortunately, all actions derive from this class... - -Should they? - -Not 100% sure. It does seem to make more sense to have them be a part of the GraphicView, -since snapping is a function of the grid and the entities contained in the view. (This would -also hold for the preview as well.) - -On to the interface: - -For allowing the crosshairs to be drawn, we'd have -void ShowSnapper(void) - -and -void HideSnapper(void) - -to hide it. Maybe -void SetSnapperCoords(Vector, Vector) - -for setting the coordinates? -*/ - public://for now - void SetVisible(bool visibility = true); - bool Visible(void); - void Draw(GraphicView *, PaintInterface *); - -// private: -// void xorSnapper(); - - protected: - EntityContainer * container; - GraphicView * graphicView; - Entity * keyEntity; - Vector snapCoord; - Vector snapSpot; - RS2::SnapMode snapMode; - RS2::SnapRestriction snapRes; - /** - * Snap distance for snaping to points with a - * given distance from endpoints. - */ - double distance; - /** - * Keeps track of the drawings in XOR mode. - */ - bool visible; - /** - * Snap range for catching entities. - */ - int snapRange; - /** - * Show large cross hairs. - */ - bool showCrosshairs; - bool finished; -}; - -#endif diff --git a/src/mainapp/graphicview.cpp b/src/mainapp/graphicview.cpp index 5b633b2..d29de4a 100644 --- a/src/mainapp/graphicview.cpp +++ b/src/mainapp/graphicview.cpp @@ -35,13 +35,11 @@ GraphicView::GraphicView(): background(), foreground() printing = false; deleteMode = false; factor = Vector(1.0, 1.0); - offsetX = 0; - offsetY = 0; + offsetX = offsetY = 0; previousFactor = Vector(1.0, 1.0); - previousOffsetX = 0; - previousOffsetY = 0; + previousOffsetX = previousOffsetY = 0; container = NULL; - eventHandler = new EventHandler(this); + eventHandler = new EventHandler(); gridColor = Qt::gray; metaGridColor = Color(64, 64, 64); grid = new Grid(this); @@ -50,10 +48,7 @@ GraphicView::GraphicView(): background(), foreground() draftMode = false; painter = NULL; - borderLeft = 0; - borderTop = 0; - borderRight = 0; - borderBottom = 0; + borderLeft = borderTop = borderRight = borderBottom = 0; relativeZero = Vector(false); relativeZeroLocked = false; @@ -452,10 +447,10 @@ void GraphicView::updateView() */ ActionInterface * GraphicView::getDefaultAction() { - if (eventHandler != NULL) - return eventHandler->getDefaultAction(); - else - return NULL; + if (eventHandler) + return eventHandler->GetDefaultAction(); + + return NULL; } /** @@ -464,7 +459,7 @@ ActionInterface * GraphicView::getDefaultAction() void GraphicView::setDefaultAction(ActionInterface * action) { if (eventHandler) - eventHandler->setDefaultAction(action); + eventHandler->SetDefaultAction(action); } /** @@ -473,7 +468,7 @@ void GraphicView::setDefaultAction(ActionInterface * action) ActionInterface * GraphicView::getCurrentAction() { if (eventHandler) - return eventHandler->getCurrentAction(); + return eventHandler->GetCurrentAction(); else return NULL; } @@ -486,7 +481,7 @@ void GraphicView::setCurrentAction(ActionInterface * action) DEBUG->print("GraphicView::setCurrentAction"); if (eventHandler) - eventHandler->setCurrentAction(action); + eventHandler->SetCurrentAction(action); DEBUG->print("GraphicView::setCurrentAction: OK"); } @@ -498,7 +493,7 @@ void GraphicView::setCurrentAction(ActionInterface * action) void GraphicView::killSelectActions() { if (eventHandler) - eventHandler->killSelectActions(); + eventHandler->KillSelectActions(); } /** @@ -506,8 +501,9 @@ void GraphicView::killSelectActions() */ void GraphicView::killAllActions() { + //KillAll does nothing... if (eventHandler) - eventHandler->killAllActions(); + eventHandler->KillAllActions(); } /** @@ -515,8 +511,8 @@ void GraphicView::killAllActions() */ void GraphicView::back() { - if (eventHandler && eventHandler->hasAction()) - eventHandler->back(); + if (eventHandler && eventHandler->HasAction()) + eventHandler->Back(); else if (DIALOGFACTORY) DIALOGFACTORY->requestPreviousMenu(); } @@ -526,8 +522,8 @@ void GraphicView::back() */ void GraphicView::enter() { - if (eventHandler && eventHandler->hasAction()) - eventHandler->enter(); + if (eventHandler && eventHandler->HasAction()) + eventHandler->Enter(); } /** @@ -537,7 +533,7 @@ void GraphicView::enter() void GraphicView::mousePressEvent(QMouseEvent * e) { if (eventHandler) - eventHandler->mousePressEvent(e); + eventHandler->MousePressEvent(e); } /** @@ -551,9 +547,9 @@ void GraphicView::mouseReleaseEvent(QMouseEvent * e) if (!eventHandler) return; - if (e->button() != Qt::RightButton || eventHandler->hasAction()) + if (e->button() != Qt::RightButton || eventHandler->HasAction()) { - eventHandler->mouseReleaseEvent(e); + eventHandler->MouseReleaseEvent(e); } else { @@ -572,10 +568,10 @@ void GraphicView::mouseMoveEvent(QMouseEvent * e) { DEBUG->print("GraphicView::mouseMoveEvent begin"); - Drawing * graphic = NULL; + Drawing * drawing = NULL; if (container->rtti() == RS2::EntityGraphic) - graphic = (Drawing *)container; + drawing = (Drawing *)container; DEBUG->print("GraphicView::mouseMoveEvent 001"); @@ -588,17 +584,18 @@ void GraphicView::mouseMoveEvent(QMouseEvent * e) DEBUG->print("GraphicView::mouseMoveEvent 002"); if (eventHandler) - eventHandler->mouseMoveEvent(e); + eventHandler->MouseMoveEvent(e); DEBUG->print("GraphicView::mouseMoveEvent 003"); - if (!eventHandler || !eventHandler->hasAction() && graphic) + if (!eventHandler || !eventHandler->HasAction() && drawing) { - Vector mouse = toGraph(Vector(mx, my)); - Vector relMouse = mouse - getRelativeZero(); - if (DIALOGFACTORY) + { + Vector mouse = toGraph(Vector(mx, my)); + Vector relMouse = mouse - getRelativeZero(); DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse); + } } DEBUG->print("GraphicView::mouseMoveEvent end"); @@ -611,7 +608,7 @@ void GraphicView::mouseMoveEvent(QMouseEvent * e) void GraphicView::mouseLeaveEvent() { if (eventHandler) - eventHandler->mouseLeaveEvent(); + eventHandler->MouseLeaveEvent(); } /** @@ -621,7 +618,7 @@ void GraphicView::mouseLeaveEvent() void GraphicView::mouseEnterEvent() { if (eventHandler) - eventHandler->mouseEnterEvent(); + eventHandler->MouseEnterEvent(); } /** @@ -631,7 +628,7 @@ void GraphicView::mouseEnterEvent() void GraphicView::keyPressEvent(QKeyEvent * e) { if (eventHandler) - eventHandler->keyPressEvent(e); + eventHandler->KeyPressEvent(e); } /** @@ -641,7 +638,7 @@ void GraphicView::keyPressEvent(QKeyEvent * e) void GraphicView::keyReleaseEvent(QKeyEvent * e) { if (eventHandler) - eventHandler->keyReleaseEvent(e); + eventHandler->KeyReleaseEvent(e); } /** @@ -650,7 +647,7 @@ void GraphicView::keyReleaseEvent(QKeyEvent * e) void GraphicView::commandEvent(CommandEvent * e) { if (eventHandler) - eventHandler->commandEvent(e); + eventHandler->HandleCommandEvent(this, e); } /** @@ -659,7 +656,7 @@ void GraphicView::commandEvent(CommandEvent * e) void GraphicView::enableCoordinateInput() { if (eventHandler) - eventHandler->enableCoordinateInput(); + eventHandler->EnableCoordinateInput(); } /** @@ -668,7 +665,7 @@ void GraphicView::enableCoordinateInput() void GraphicView::disableCoordinateInput() { if (eventHandler) - eventHandler->disableCoordinateInput(); + eventHandler->DisableCoordinateInput(); } /** @@ -686,6 +683,7 @@ void GraphicView::zoomIn(double f, const Vector & center) return; Vector c = center; + if (c.valid == false) c = toGraph(Vector(getWidth() / 2, getHeight() / 2)); @@ -2096,6 +2094,8 @@ void GraphicView::setDefaultSnapMode(RS2::SnapMode sm) { defaultSnapMode = sm; +// Don't need this shiaut anymore +#if 0 if (eventHandler) eventHandler->setSnapMode(sm); @@ -2104,6 +2104,7 @@ void GraphicView::setDefaultSnapMode(RS2::SnapMode sm) //us up, hm notwithstanding. [and it does. :-)] //hm. snapper.setSnapMode(sm); +#endif } /** @@ -2113,8 +2114,11 @@ void GraphicView::setSnapRestriction(RS2::SnapRestriction sr) { defaultSnapRes = sr; +// Don't need this shiaut anymore +#if 0 if (eventHandler != NULL) eventHandler->setSnapRestriction(sr); +#endif } /** @@ -2397,6 +2401,17 @@ Entity * GraphicView::CatchEntity(QMouseEvent * e, RS2::ResolveLevel level) return CatchEntity(Vector(toGraphX(e->x()), toGraphY(e->y())), level); } +/** + * @return Pointer to the entity which was the key entity for the last + * successful snapping action. If the snap mode is "end point" the key entity + * is the entity whose end point was caught. If the snap mode didn't require an + * entity (e.g. free, grid) this method will return NULL. + */ +Entity * GraphicView::GetSnapperEntity() +{ + return snapEntity; +} + /** * Snap to a coordinate in the drawing using the current snap mode. * @@ -2617,17 +2632,6 @@ void Snapper::finish() finished = true; } -/** - * @return Pointer to the entity which was the key entity for the last - * successful snapping action. If the snap mode is "end point" the key entity - * is the entity whose end point was caught. If the snap mode didn't require an - * entity (e.g. free, grid) this method will return NULL. - */ -Entity * Snapper::getKeyEntity() -{ - return keyEntity; -} - /** Sets a new snap mode. */ void Snapper::setSnapMode(RS2::SnapMode snapMode) { diff --git a/src/mainapp/graphicview.h b/src/mainapp/graphicview.h index e4cd758..cb684c0 100644 --- a/src/mainapp/graphicview.h +++ b/src/mainapp/graphicview.h @@ -209,6 +209,7 @@ Having this class derive from that one *might* make sense... *Maybe*. Not sure. Entity * CatchEntity(const Vector &, RS2::ResolveLevel level = RS2::ResolveNone); Entity * CatchEntity(QMouseEvent *, RS2::ResolveLevel level = RS2::ResolveNone); + Entity * GetSnapperEntity(void); Vector SnapPoint(QMouseEvent *); Vector SnapGrid(Vector); void DrawSnapper(PaintInterface *); @@ -279,7 +280,8 @@ Having this class derive from that one *might* make sense... *Maybe*. Not sure. public://for now // We use this here instead of deriving ActionInterface from it because // this makes more sense. - Snapper snapper; +// Snapper snapper; +//yer next Preview preview; //QG -- 2.37.2