X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fbase%2Feventhandler.cpp;h=7d7cd6bba5e60434aac79cbc0a662c3d1e4c9813;hb=5adb444f3e523d3fd028617ced72d1ea6661db21;hp=58334af9958ac11b3b2afef28d4d4aadf9be4be6;hpb=3239ef39dcee08fa6e8cd68cdf2727fc68cc7a8c;p=architektonas diff --git a/src/base/eventhandler.cpp b/src/base/eventhandler.cpp index 58334af..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,35 +28,36 @@ /** * Constructor. */ -RS_EventHandler::RS_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("RS_EventHandler::~RS_EventHandler"); + DEBUG->print("EventHandler::~EventHandler"); - if (defaultAction != NULL) + if (defaultAction) { defaultAction->finish(); delete defaultAction; defaultAction = NULL; } - killAllActions(); + KillAllActions(); - RS_DEBUG->print("RS_EventHandler::~RS_EventHandler: Deleting all actions.."); + DEBUG->print("EventHandler::~EventHandler: Deleting all actions.."); for(int i=0; iprint("RS_EventHandler::~RS_EventHandler: Deleting all actions..: OK"); - RS_DEBUG->print("RS_EventHandler::~RS_EventHandler: OK"); + CleanUp(); + DEBUG->print("EventHandler::~EventHandler: Deleting all actions..: OK"); + DEBUG->print("EventHandler::~EventHandler: OK"); } /** * Go back in current action. */ -void RS_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 RS_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 RS_EventHandler::mousePressEvent(QMouseEvent * e) +void EventHandler::MousePressEvent(QMouseEvent * e) { if (actionIndex >= 0 && currentActions[actionIndex] != NULL) { @@ -110,7 +113,7 @@ void RS_EventHandler::mousePressEvent(QMouseEvent * e) } else { - RS_DEBUG->print("currently no action defined"); + DEBUG->print("currently no action defined"); e->ignore(); } } @@ -119,16 +122,16 @@ void RS_EventHandler::mousePressEvent(QMouseEvent * e) /** * Called by GraphicView */ -void RS_EventHandler::mouseReleaseEvent(QMouseEvent * e) +void EventHandler::MouseReleaseEvent(QMouseEvent * e) { if (actionIndex >= 0 && currentActions[actionIndex] != NULL && !currentActions[actionIndex]->isFinished()) { - RS_DEBUG->print("call action %s", currentActions[actionIndex]->getName().toLatin1().data()); + DEBUG->print("call action %s", currentActions[actionIndex]->getName().toLatin1().data()); currentActions[actionIndex]->mouseReleaseEvent(e); // Clean up actions - one might be finished now - cleanUp(); + CleanUp(); e->accept(); } else @@ -143,7 +146,7 @@ void RS_EventHandler::mouseReleaseEvent(QMouseEvent * e) /** * Called by GraphicView */ -void RS_EventHandler::mouseMoveEvent(QMouseEvent * e) +void EventHandler::MouseMoveEvent(QMouseEvent * e) { if (actionIndex >= 0 && currentActions[actionIndex] && !currentActions[actionIndex]->isFinished()) @@ -160,15 +163,26 @@ void RS_EventHandler::mouseMoveEvent(QMouseEvent * e) } else e->ignore(); - //RS_DEBUG->print("currently no action defined"); + //DEBUG->print("currently no action defined"); } } +#if 0 +Small problem with this approach: Resumes can happen before suspend actions! +This can wreak havoc with things like snapper/preview states and the like... + +Actually, this stuff seems to be pretty useless. Not sure what is accomplished +by this crap. The only thing I can think of is that it would cause a preview +to be removed if the mouse goes out of the drawing window, could be a legit +purpose but this seems too retarded for that. Why wouldn't you just code that +into GraphicView itself and be done with it? +#endif /** * Called by GraphicView */ -void RS_EventHandler::mouseLeaveEvent() +void EventHandler::MouseLeaveEvent() { +#if 0 if (actionIndex >= 0 && currentActions[actionIndex] && !currentActions[actionIndex]->isFinished()) { @@ -178,15 +192,17 @@ void RS_EventHandler::mouseLeaveEvent() { if (defaultAction) defaultAction->suspend(); - //RS_DEBUG->print("currently no action defined"); + //DEBUG->print("currently no action defined"); } +#endif } /** * Called by GraphicView */ -void RS_EventHandler::mouseEnterEvent() +void EventHandler::MouseEnterEvent() { +#if 0 if (actionIndex >= 0 && currentActions[actionIndex] && !currentActions[actionIndex]->isFinished()) { @@ -197,12 +213,13 @@ void RS_EventHandler::mouseEnterEvent() if (defaultAction) defaultAction->resume(); } +#endif } /** * Called by GraphicView */ -void RS_EventHandler::keyPressEvent(QKeyEvent * e) +void EventHandler::KeyPressEvent(QKeyEvent * e) { if (actionIndex >= 0 && currentActions[actionIndex] && !currentActions[actionIndex]->isFinished()) @@ -216,14 +233,14 @@ void RS_EventHandler::keyPressEvent(QKeyEvent * e) else e->ignore(); - //RS_DEBUG->print("currently no action defined"); + //DEBUG->print("currently no action defined"); } } /** * Called by GraphicView */ -void RS_EventHandler::keyReleaseEvent(QKeyEvent * e) +void EventHandler::KeyReleaseEvent(QKeyEvent * e) { if (actionIndex >= 0 && currentActions[actionIndex] && !currentActions[actionIndex]->isFinished()) @@ -237,16 +254,16 @@ void RS_EventHandler::keyReleaseEvent(QKeyEvent * e) else e->ignore(); - //RS_DEBUG->print("currently no action defined"); + //DEBUG->print("currently no action defined"); } } /** * Handles command line events. */ -void RS_EventHandler::commandEvent(RS_CommandEvent * e) +void EventHandler::HandleCommandEvent(GraphicView * graphicView, CommandEvent * e) { - RS_DEBUG->print("RS_EventHandler::commandEvent"); + DEBUG->print("EventHandler::commandEvent"); QString cmd = e->getCommand(); if (coordinateInputEnabled) @@ -260,27 +277,24 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) && !currentActions[actionIndex]->isFinished()) { int commaPos = cmd.indexOf(','); - RS_DEBUG->print("RS_EventHandler::commandEvent: 001"); + DEBUG->print("EventHandler::commandEvent: 001"); bool ok1, ok2; - RS_DEBUG->print("RS_EventHandler::commandEvent: 002"); - double x = RS_Math::eval(cmd.left(commaPos), &ok1); - RS_DEBUG->print("RS_EventHandler::commandEvent: 003a"); - double y = RS_Math::eval(cmd.mid(commaPos + 1), &ok2); - RS_DEBUG->print("RS_EventHandler::commandEvent: 004"); + DEBUG->print("EventHandler::commandEvent: 002"); + double x = Math::eval(cmd.left(commaPos), &ok1); + DEBUG->print("EventHandler::commandEvent: 003a"); + double y = Math::eval(cmd.mid(commaPos + 1), &ok2); + DEBUG->print("EventHandler::commandEvent: 004"); if (ok1 && ok2) { -// RS_DEBUG->print("RS_EventHandler::commandEvent: 005"); -// RS_CoordinateEvent ce(Vector(x, y)); - RS_DEBUG->print("RS_EventHandler::commandEvent: 006"); -// currentActions[actionIndex]->coordinateEvent(&ce); + DEBUG->print("EventHandler::commandEvent: 006"); Vector ce(x, y); currentActions[actionIndex]->coordinateEvent(&ce); } else { - if (RS_DIALOGFACTORY != NULL) - RS_DIALOGFACTORY->commandMessage("Expression Syntax Error"); + if (DIALOGFACTORY) + DIALOGFACTORY->commandMessage("Expression Syntax Error"); } e->accept(); @@ -298,20 +312,18 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) { int commaPos = cmd.indexOf(','); bool ok1, ok2; - double x = RS_Math::eval(cmd.mid(1, commaPos - 1), &ok1); - double y = RS_Math::eval(cmd.mid(commaPos + 1), &ok2); + double x = Math::eval(cmd.mid(1, commaPos - 1), &ok1); + double y = Math::eval(cmd.mid(commaPos + 1), &ok2); if (ok1 && ok2) { -// RS_CoordinateEvent ce(Vector(x,y) + graphicView->getRelativeZero()); -// currentActions[actionIndex]->coordinateEvent(&ce); Vector ce(Vector(x,y) + graphicView->getRelativeZero()); currentActions[actionIndex]->coordinateEvent(&ce); } else { - if (RS_DIALOGFACTORY != NULL) - RS_DIALOGFACTORY->commandMessage("Expression Syntax Error"); + if (DIALOGFACTORY) + DIALOGFACTORY->commandMessage("Expression Syntax Error"); } e->accept(); @@ -329,21 +341,19 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) { int commaPos = cmd.indexOf('<'); bool ok1, ok2; - double r = RS_Math::eval(cmd.left(commaPos), &ok1); - double a = RS_Math::eval(cmd.mid(commaPos + 1), &ok2); + double r = Math::eval(cmd.left(commaPos), &ok1); + double a = Math::eval(cmd.mid(commaPos + 1), &ok2); if (ok1 && ok2) { Vector pos; - pos.setPolar(r,RS_Math::deg2rad(a)); -// RS_CoordinateEvent ce(pos); -// currentActions[actionIndex]->coordinateEvent(&ce); + pos.setPolar(r,Math::deg2rad(a)); currentActions[actionIndex]->coordinateEvent(&pos); } else { - if (RS_DIALOGFACTORY != NULL) - RS_DIALOGFACTORY->commandMessage("Expression Syntax Error"); + if (DIALOGFACTORY) + DIALOGFACTORY->commandMessage("Expression Syntax Error"); } e->accept(); @@ -359,25 +369,22 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) if (actionIndex >= 0 && currentActions[actionIndex] !=NULL && !currentActions[actionIndex]->isFinished()) { -// int commaPos = cmd.find('<'); int commaPos = cmd.indexOf('<'); bool ok1, ok2; - double r = RS_Math::eval(cmd.mid(1, commaPos - 1), &ok1); - double a = RS_Math::eval(cmd.mid(commaPos + 1), &ok2); + double r = Math::eval(cmd.mid(1, commaPos - 1), &ok1); + double a = Math::eval(cmd.mid(commaPos + 1), &ok2); if (ok1 && ok2) { Vector pos; - pos.setPolar(r,RS_Math::deg2rad(a)); -// RS_CoordinateEvent ce(pos + graphicView->getRelativeZero()); -// currentActions[actionIndex]->coordinateEvent(&ce); + pos.setPolar(r,Math::deg2rad(a)); Vector ce(pos + graphicView->getRelativeZero()); currentActions[actionIndex]->coordinateEvent(&ce); } else { - if (RS_DIALOGFACTORY) - RS_DIALOGFACTORY->commandMessage("Expression Syntax Error"); + if (DIALOGFACTORY) + DIALOGFACTORY->commandMessage("Expression Syntax Error"); } e->accept(); @@ -386,7 +393,7 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) } } - // send command event directly to current action: + // Send command event directly to current action: if (!e->isAccepted()) { if (actionIndex >= 0 && currentActions[actionIndex] @@ -402,13 +409,13 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) } } - RS_DEBUG->print("RS_EventHandler::commandEvent: OK"); + DEBUG->print("EventHandler::commandEvent: OK"); } /** * Enables coordinate input in the command line. */ -void RS_EventHandler::enableCoordinateInput() +void EventHandler::EnableCoordinateInput() { coordinateInputEnabled = true; } @@ -416,7 +423,7 @@ void RS_EventHandler::enableCoordinateInput() /** * Enables coordinate input in the command line. */ -void RS_EventHandler::disableCoordinateInput() +void EventHandler::DisableCoordinateInput() { coordinateInputEnabled = false; } @@ -424,7 +431,7 @@ void RS_EventHandler::disableCoordinateInput() /** * @return Current action. */ -ActionInterface * RS_EventHandler::getCurrentAction() +ActionInterface * EventHandler::GetCurrentAction() { if (actionIndex >= 0 && currentActions[actionIndex] && !currentActions[actionIndex]->isFinished()) @@ -436,7 +443,7 @@ ActionInterface * RS_EventHandler::getCurrentAction() /** * @return The current default action. */ -ActionInterface * RS_EventHandler::getDefaultAction() +ActionInterface * EventHandler::GetDefaultAction() { return defaultAction; } @@ -444,7 +451,7 @@ ActionInterface * RS_EventHandler::getDefaultAction() /** * Sets the default action. */ -void RS_EventHandler::setDefaultAction(ActionInterface * action) +void EventHandler::SetDefaultAction(ActionInterface * action) { if (defaultAction) { @@ -459,9 +466,9 @@ void RS_EventHandler::setDefaultAction(ActionInterface * action) /** * Sets the current action. */ -void RS_EventHandler::setCurrentAction(ActionInterface * action) +void EventHandler::SetCurrentAction(ActionInterface * action) { - RS_DEBUG->print("RS_EventHandler::setCurrentAction"); + DEBUG->print("EventHandler::setCurrentAction"); if (!action) return; @@ -490,7 +497,7 @@ void RS_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(); @@ -507,35 +514,35 @@ void RS_EventHandler::setCurrentAction(ActionInterface * action) // Set current action: currentActions[actionIndex] = action; - RS_DEBUG->print("RS_EventHandler::setCurrentAction: current action is: %s", + DEBUG->print("EventHandler::setCurrentAction: current action is: %s", currentActions[actionIndex]->getName().toLatin1().data()); // Initialisation of our new action: - RS_DEBUG->print("RS_EventHandler::setCurrentAction: init current action"); + DEBUG->print("EventHandler::setCurrentAction: init current action"); action->init(); // ## new: if (action->isFinished() == false) { - RS_DEBUG->print("RS_EventHandler::setCurrentAction: show options"); + DEBUG->print("EventHandler::setCurrentAction: show options"); currentActions[actionIndex]->showOptions(); - RS_DEBUG->print("RS_EventHandler::setCurrentAction: set predecessor"); + DEBUG->print("EventHandler::setCurrentAction: set predecessor"); action->setPredecessor(predecessor); } - RS_DEBUG->print("RS_EventHandler::setCurrentAction: cleaning up.."); - cleanUp(); + DEBUG->print("EventHandler::setCurrentAction: cleaning up.."); + CleanUp(); - RS_DEBUG->print("RS_EventHandler::setCurrentAction: debugging actions"); - debugActions(); - RS_DEBUG->print("GraphicView::setCurrentAction: OK"); + DEBUG->print("EventHandler::setCurrentAction: debugging actions"); + DebugActions(); + DEBUG->print("GraphicView::setCurrentAction: OK"); } /** * Kills all running selection actions. Called when a selection action * is launched to reduce confusion. */ -void RS_EventHandler::killSelectActions() +void EventHandler::KillSelectActions() { for(int c=0; cprint("RS_EventHandler::cleanUp"); + DEBUG->print("EventHandler::cleanUp"); - int o = 0; // old index - int n = 0; // new index + int oldIndex = 0; // old index + int newIndex = 0; // new index int resume = 0; // index of action to resume bool doResume = false; // do we need to resume an action actionIndex = -1; - debugActions(); + DebugActions(); do { - // search first used action (o) - while (currentActions[o] == NULL && o < RS_MAXACTIONS) - o++; + // Search first used action (oldIndex) + while (currentActions[oldIndex] == NULL && oldIndex < RS_MAXACTIONS) + oldIndex++; - // delete action if it is finished - if (o < RS_MAXACTIONS && currentActions[o] != NULL - && currentActions[o]->isFinished()) + // Delete action if it is finished + if (oldIndex < RS_MAXACTIONS && currentActions[oldIndex] != NULL + && currentActions[oldIndex]->isFinished()) { - delete currentActions[o]; - currentActions[o] = NULL; + delete currentActions[oldIndex]; + currentActions[oldIndex] = NULL; doResume = true; } - // move a running action up in the stack - if (o < RS_MAXACTIONS && currentActions[o] != NULL) + // Move a running action up in the stack + if (oldIndex < RS_MAXACTIONS && currentActions[oldIndex] != NULL) { - if (n != o) + if (newIndex != oldIndex) { - currentActions[n] = currentActions[o]; - resume = n; - currentActions[o] = NULL; + currentActions[newIndex] = currentActions[oldIndex]; + resume = newIndex; + currentActions[oldIndex] = NULL; } else { - if (o < RS_MAXACTIONS) - o++; + if (oldIndex < RS_MAXACTIONS) + oldIndex++; } - actionIndex = n; + actionIndex = newIndex; - if (n < RS_MAXACTIONS - 1) - n++; + if (newIndex < RS_MAXACTIONS - 1) + newIndex++; } } - while (o < RS_MAXACTIONS); + while (oldIndex < RS_MAXACTIONS); - debugActions(); + DebugActions(); // Resume last used action: if (doResume) @@ -650,61 +658,23 @@ void RS_EventHandler::cleanUp() } } - RS_DEBUG->print("RS_EventHandler::cleanUp: OK"); -} - -/** - * Sets the snap mode for all currently active actions. - */ -void RS_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 RS_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 + DEBUG->print("EventHandler::cleanUp: OK"); } -void RS_EventHandler::debugActions() +void EventHandler::DebugActions() { - RS_DEBUG->print("---"); + DEBUG->print("---"); for(int c=0; cprint("Current"); + DEBUG->print("Current"); if (currentActions[c]) - RS_DEBUG->print("Action %03d: %s [%s]", + DEBUG->print("Action %03d: %s [%s]", c, currentActions[c]->getName().toLatin1().data(), currentActions[c]->isFinished() ? "finished" : "active"); else - RS_DEBUG->print("Action %03d: NULL", c); + DEBUG->print("Action %03d: NULL", c); } }