X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fbase%2Feventhandler.cpp;h=7d7cd6bba5e60434aac79cbc0a662c3d1e4c9813;hb=5adb444f3e523d3fd028617ced72d1ea6661db21;hp=a8b64179e4207ff8a8a504d10759cdcb1a6de70f;hpb=16354e0421b316a62c6b9f7b0b4f3b8cf6f06284;p=architektonas diff --git a/src/base/eventhandler.cpp b/src/base/eventhandler.cpp index a8b6417..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"); - if (defaultAction != NULL) + if (defaultAction) { defaultAction->finish(); delete defaultAction; defaultAction = NULL; } - killAllActions(); + KillAllActions(); DEBUG->print("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()) @@ -164,11 +167,22 @@ void EventHandler::mouseMoveEvent(QMouseEvent * e) } } +#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 EventHandler::mouseLeaveEvent() +void EventHandler::MouseLeaveEvent() { +#if 0 if (actionIndex >= 0 && currentActions[actionIndex] && !currentActions[actionIndex]->isFinished()) { @@ -180,13 +194,15 @@ void EventHandler::mouseLeaveEvent() defaultAction->suspend(); //DEBUG->print("currently no action defined"); } +#endif } /** * Called by GraphicView */ -void EventHandler::mouseEnterEvent() +void EventHandler::MouseEnterEvent() { +#if 0 if (actionIndex >= 0 && currentActions[actionIndex] && !currentActions[actionIndex]->isFinished()) { @@ -197,12 +213,13 @@ void EventHandler::mouseEnterEvent() if (defaultAction) defaultAction->resume(); } +#endif } /** * Called by GraphicView */ -void EventHandler::keyPressEvent(QKeyEvent * e) +void EventHandler::KeyPressEvent(QKeyEvent * e) { if (actionIndex >= 0 && currentActions[actionIndex] && !currentActions[actionIndex]->isFinished()) @@ -223,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()) @@ -244,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(); @@ -270,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"); } @@ -303,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"); } @@ -336,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"); } @@ -359,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); @@ -369,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); } @@ -386,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] @@ -408,7 +415,7 @@ void EventHandler::commandEvent(CommandEvent * e) /** * Enables coordinate input in the command line. */ -void EventHandler::enableCoordinateInput() +void EventHandler::EnableCoordinateInput() { coordinateInputEnabled = true; } @@ -416,7 +423,7 @@ void EventHandler::enableCoordinateInput() /** * Enables coordinate input in the command line. */ -void EventHandler::disableCoordinateInput() +void EventHandler::DisableCoordinateInput() { coordinateInputEnabled = false; } @@ -424,7 +431,7 @@ void EventHandler::disableCoordinateInput() /** * @return Current action. */ -ActionInterface * EventHandler::getCurrentAction() +ActionInterface * EventHandler::GetCurrentAction() { if (actionIndex >= 0 && currentActions[actionIndex] && !currentActions[actionIndex]->isFinished()) @@ -436,7 +443,7 @@ ActionInterface * EventHandler::getCurrentAction() /** * @return The current default action. */ -ActionInterface * EventHandler::getDefaultAction() +ActionInterface * EventHandler::GetDefaultAction() { return defaultAction; } @@ -444,7 +451,7 @@ ActionInterface * EventHandler::getDefaultAction() /** * Sets the default action. */ -void EventHandler::setDefaultAction(ActionInterface * action) +void EventHandler::SetDefaultAction(ActionInterface * action) { if (defaultAction) { @@ -459,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"); @@ -490,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(); @@ -524,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"); } @@ -535,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"); - 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) @@ -653,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("---");