X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fbase%2Frs_eventhandler.cpp;h=260998a133aeefc59de93e64d784a2fb5c472f17;hb=3f46c180da0806c9c263e6d87d0f1404632402da;hp=9f68a951f1d9515b3718bc3a28f0002ce8a887a0;hpb=16ce54abf01ca3032e42a5bb11a4afcf9014dcca;p=architektonas diff --git a/src/base/rs_eventhandler.cpp b/src/base/rs_eventhandler.cpp index 9f68a95..260998a 100644 --- a/src/base/rs_eventhandler.cpp +++ b/src/base/rs_eventhandler.cpp @@ -16,7 +16,11 @@ #include #include "rs_actioninterface.h" -#include "rs_coordinateevent.h" +#include "rs_commandevent.h" +#include "rs_debug.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_math.h" /** * Constructor. @@ -218,20 +222,22 @@ void RS_EventHandler::keyPressEvent(QKeyEvent * e) /** * Called by RS_GraphicView */ -void RS_EventHandler::keyReleaseEvent(QKeyEvent* e) +void RS_EventHandler::keyReleaseEvent(QKeyEvent * e) { - if (actionIndex>=0 && currentActions[actionIndex]!=NULL && - !currentActions[actionIndex]->isFinished()) { - currentActions[actionIndex]->keyReleaseEvent(e); - } else { - if (defaultAction!=NULL) { - defaultAction->keyReleaseEvent(e); - } - else { + if (actionIndex >= 0 && currentActions[actionIndex] != NULL + && !currentActions[actionIndex]->isFinished()) + { + currentActions[actionIndex]->keyReleaseEvent(e); + } + else + { + if (defaultAction != NULL) + defaultAction->keyReleaseEvent(e); + else e->ignore(); - } - //RS_DEBUG->print("currently no action defined"); - } + + //RS_DEBUG->print("currently no action defined"); + } } /** @@ -252,7 +258,6 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) if (actionIndex >= 0 && currentActions[actionIndex] != NULL && !currentActions[actionIndex]->isFinished()) { -// int commaPos = cmd.find(','); int commaPos = cmd.indexOf(','); RS_DEBUG->print("RS_EventHandler::commandEvent: 001"); bool ok1, ok2; @@ -264,9 +269,11 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) if (ok1 && ok2) { - RS_DEBUG->print("RS_EventHandler::commandEvent: 005"); - RS_CoordinateEvent ce(Vector(x, y)); +// RS_DEBUG->print("RS_EventHandler::commandEvent: 005"); +// RS_CoordinateEvent ce(Vector(x, y)); RS_DEBUG->print("RS_EventHandler::commandEvent: 006"); +// currentActions[actionIndex]->coordinateEvent(&ce); + Vector ce(x, y); currentActions[actionIndex]->coordinateEvent(&ce); } else @@ -288,7 +295,6 @@ 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 x = RS_Math::eval(cmd.mid(1, commaPos - 1), &ok1); @@ -296,8 +302,9 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) if (ok1 && ok2) { - RS_CoordinateEvent ce(Vector(x,y) + - graphicView->getRelativeZero()); +// RS_CoordinateEvent ce(Vector(x,y) + graphicView->getRelativeZero()); +// currentActions[actionIndex]->coordinateEvent(&ce); + Vector ce(Vector(x,y) + graphicView->getRelativeZero()); currentActions[actionIndex]->coordinateEvent(&ce); } else @@ -319,7 +326,6 @@ 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.left(commaPos), &ok1); @@ -329,8 +335,9 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) { Vector pos; pos.setPolar(r,RS_Math::deg2rad(a)); - RS_CoordinateEvent ce(pos); - currentActions[actionIndex]->coordinateEvent(&ce); +// RS_CoordinateEvent ce(pos); +// currentActions[actionIndex]->coordinateEvent(&ce); + currentActions[actionIndex]->coordinateEvent(&pos); } else { @@ -361,8 +368,9 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) { Vector pos; pos.setPolar(r,RS_Math::deg2rad(a)); - RS_CoordinateEvent ce(pos + - graphicView->getRelativeZero()); +// RS_CoordinateEvent ce(pos + graphicView->getRelativeZero()); +// currentActions[actionIndex]->coordinateEvent(&ce); + Vector ce(pos + graphicView->getRelativeZero()); currentActions[actionIndex]->coordinateEvent(&ce); } else @@ -389,10 +397,7 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) else { if (defaultAction != NULL) - { defaultAction->commandEvent(e); - //e->accept(); - } } } @@ -461,7 +466,7 @@ void RS_EventHandler::setCurrentAction(RS_ActionInterface * action) return; // Predecessor of the new action or NULL: - RS_ActionInterface* predecessor = NULL; + RS_ActionInterface * predecessor = NULL; // Suspend current action: if (actionIndex >= 0 && currentActions[actionIndex] != NULL @@ -494,14 +499,10 @@ void RS_EventHandler::setCurrentAction(RS_ActionInterface * action) // Move up actionstack (optimize): for(int i=0; iprint("RS_EventHandler::cleanUp"); - - int o=0; // old index - int n=0; // new index - int resume=0; // index of action to resume - bool doResume=false; // do we need to resume an action - actionIndex = -1; - - debugActions(); - do { - // search first used action (o) - while (currentActions[o]==NULL && oprint("RS_EventHandler::cleanUp"); - // delete action if it is finished - if (oisFinished()) { - delete currentActions[o]; - currentActions[o] = NULL; + int o = 0; // old index + int n = 0; // new index + int resume = 0; // index of action to resume + bool doResume = false; // do we need to resume an action + actionIndex = -1; - doResume = true; - } + debugActions(); - // move a running action up in the stack - if (oisFinished()) { - - currentActions[resume]->resume(); - currentActions[resume]->showOptions(); - } else { - if (defaultAction!=NULL) { - defaultAction->resume(); - defaultAction->showOptions(); - } - } - } - RS_DEBUG->print("RS_EventHandler::cleanUp: OK"); + do + { + // search first used action (o) + while (currentActions[o] == NULL && o < RS_MAXACTIONS) + o++; + + // delete action if it is finished + if (o < RS_MAXACTIONS && currentActions[o] != NULL + && currentActions[o]->isFinished()) + { + delete currentActions[o]; + currentActions[o] = NULL; + doResume = true; + } + + // move a running action up in the stack + if (o < RS_MAXACTIONS && currentActions[o] != NULL) + { + if (n != o) + { + currentActions[n] = currentActions[o]; + resume = n; + currentActions[o] = NULL; + } + else + { + if (o < RS_MAXACTIONS) + o++; + } + + actionIndex = n; + + if (n < RS_MAXACTIONS - 1) + n++; + } + } + while (o < RS_MAXACTIONS); + + debugActions(); + + // Resume last used action: + if (doResume) + { + if (currentActions[resume] != NULL && !currentActions[resume]->isFinished()) + { + currentActions[resume]->resume(); + currentActions[resume]->showOptions(); + } + else + { + if (defaultAction != NULL) + { + defaultAction->resume(); + defaultAction->showOptions(); + } + } + } + + RS_DEBUG->print("RS_EventHandler::cleanUp: OK"); } /**