]> Shamusworld >> Repos - architektonas/blobdiff - src/base/eventhandler.cpp
In the middle of removing Snapper class/fixing snapper rendering...
[architektonas] / src / base / eventhandler.cpp
index 58334af9958ac11b3b2afef28d4d4aadf9be4be6..d8d8f2b7addb572252841a57393cabb92cff5a10 100644 (file)
@@ -26,7 +26,7 @@
 /**
  * Constructor.
  */
-RS_EventHandler::RS_EventHandler(GraphicView * graphicView)
+EventHandler::EventHandler(GraphicView * graphicView)
 {
        this->graphicView = graphicView;
        actionIndex = -1;
@@ -41,11 +41,11 @@ RS_EventHandler::RS_EventHandler(GraphicView * graphicView)
 /**
  * Destructor.
  */
-RS_EventHandler::~RS_EventHandler()
+EventHandler::~EventHandler()
 {
-       RS_DEBUG->print("RS_EventHandler::~RS_EventHandler");
+       DEBUG->print("EventHandler::~EventHandler");
 
-       if (defaultAction != NULL)
+       if (defaultAction)
        {
                defaultAction->finish();
                delete defaultAction;
@@ -54,7 +54,7 @@ RS_EventHandler::~RS_EventHandler()
 
        killAllActions();
 
-       RS_DEBUG->print("RS_EventHandler::~RS_EventHandler: Deleting all actions..");
+       DEBUG->print("EventHandler::~EventHandler: Deleting all actions..");
 
        for(int i=0; i<RS_MAXACTIONS; ++i)
        {
@@ -67,14 +67,14 @@ RS_EventHandler::~RS_EventHandler()
        }
 
        cleanUp();
-       RS_DEBUG->print("RS_EventHandler::~RS_EventHandler: Deleting all actions..: OK");
-       RS_DEBUG->print("RS_EventHandler::~RS_EventHandler: OK");
+       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);
@@ -84,7 +84,7 @@ void RS_EventHandler::back()
 /**
  * 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);
@@ -94,7 +94,7 @@ void RS_EventHandler::enter()
 /**
  * Called by GraphicView
  */
-void RS_EventHandler::mousePressEvent(QMouseEvent * e)
+void EventHandler::mousePressEvent(QMouseEvent * e)
 {
        if (actionIndex >= 0 && currentActions[actionIndex] != NULL)
        {
@@ -110,7 +110,7 @@ void RS_EventHandler::mousePressEvent(QMouseEvent * e)
                }
                else
                {
-                       RS_DEBUG->print("currently no action defined");
+                       DEBUG->print("currently no action defined");
                        e->ignore();
                }
        }
@@ -119,12 +119,12 @@ 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
@@ -143,7 +143,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 +160,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 +189,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 +210,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 +230,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 +251,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::commandEvent(CommandEvent * e)
 {
-       RS_DEBUG->print("RS_EventHandler::commandEvent");
+       DEBUG->print("EventHandler::commandEvent");
        QString cmd = e->getCommand();
 
        if (coordinateInputEnabled)
@@ -260,27 +274,27 @@ 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");
+//                                             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 (RS_DIALOGFACTORY != NULL)
-                                                       RS_DIALOGFACTORY->commandMessage("Expression Syntax Error");
+                                               if (DIALOGFACTORY != NULL)
+                                                       DIALOGFACTORY->commandMessage("Expression Syntax Error");
                                        }
 
                                        e->accept();
@@ -298,20 +312,20 @@ 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());
+//                                             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 != NULL)
+                                                       DIALOGFACTORY->commandMessage("Expression Syntax Error");
                                        }
 
                                        e->accept();
@@ -329,21 +343,21 @@ 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);
+                                               pos.setPolar(r,Math::deg2rad(a));
+//                                             CoordinateEvent ce(pos);
 //                                             currentActions[actionIndex]->coordinateEvent(&ce);
                                                currentActions[actionIndex]->coordinateEvent(&pos);
                                        }
                                        else
                                        {
-                                               if (RS_DIALOGFACTORY != NULL)
-                                                       RS_DIALOGFACTORY->commandMessage("Expression Syntax Error");
+                                               if (DIALOGFACTORY != NULL)
+                                                       DIALOGFACTORY->commandMessage("Expression Syntax Error");
                                        }
 
                                        e->accept();
@@ -362,22 +376,22 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e)
 //                                     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());
+                                               pos.setPolar(r,Math::deg2rad(a));
+//                                             CoordinateEvent ce(pos + graphicView->getRelativeZero());
 //                                             currentActions[actionIndex]->coordinateEvent(&ce);
                                                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();
@@ -402,13 +416,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 +430,7 @@ void RS_EventHandler::enableCoordinateInput()
 /**
  * Enables coordinate input in the command line.
  */
-void RS_EventHandler::disableCoordinateInput()
+void EventHandler::disableCoordinateInput()
 {
        coordinateInputEnabled = false;
 }
@@ -424,7 +438,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 +450,7 @@ ActionInterface * RS_EventHandler::getCurrentAction()
 /**
  * @return The current default action.
  */
-ActionInterface * RS_EventHandler::getDefaultAction()
+ActionInterface * EventHandler::getDefaultAction()
 {
        return defaultAction;
 }
@@ -444,7 +458,7 @@ ActionInterface * RS_EventHandler::getDefaultAction()
 /**
  * Sets the default action.
  */
-void RS_EventHandler::setDefaultAction(ActionInterface * action)
+void EventHandler::setDefaultAction(ActionInterface * action)
 {
        if (defaultAction)
        {
@@ -459,9 +473,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;
@@ -507,35 +521,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..");
+       DEBUG->print("EventHandler::setCurrentAction: cleaning up..");
        cleanUp();
 
-       RS_DEBUG->print("RS_EventHandler::setCurrentAction: debugging actions");
+       DEBUG->print("EventHandler::setCurrentAction: debugging actions");
        debugActions();
-       RS_DEBUG->print("GraphicView::setCurrentAction: OK");
+       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; c<RS_MAXACTIONS; ++c)
        {
@@ -554,7 +568,7 @@ void RS_EventHandler::killSelectActions()
 /**
  * Kills all running actions. Called when a window is closed.
  */
-void RS_EventHandler::killAllActions()
+void EventHandler::killAllActions()
 {
        /*
     for (int c=0; c<RS_MAXACTIONS; ++c) {
@@ -569,7 +583,7 @@ void RS_EventHandler::killAllActions()
 /**
  * @return true if there is at least one action in the action stack.
  */
-bool RS_EventHandler::hasAction()
+bool EventHandler::hasAction()
 {
        if (actionIndex != -1 || defaultAction)
                return true;
@@ -580,12 +594,12 @@ bool RS_EventHandler::hasAction()
 /**
  * Garbage collector for actions.
  */
-void RS_EventHandler::cleanUp()
+void EventHandler::cleanUp()
 {
-       RS_DEBUG->print("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;
@@ -594,41 +608,41 @@ void RS_EventHandler::cleanUp()
 
        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();
 
@@ -650,13 +664,13 @@ void RS_EventHandler::cleanUp()
                }
        }
 
-       RS_DEBUG->print("RS_EventHandler::cleanUp: OK");
+       DEBUG->print("EventHandler::cleanUp: OK");
 }
 
 /**
  * Sets the snap mode for all currently active actions.
  */
-void RS_EventHandler::setSnapMode(RS2::SnapMode sm)
+void EventHandler::setSnapMode(RS2::SnapMode sm)
 {
 #if 0
        for(int c=0; c<RS_MAXACTIONS; ++c)
@@ -675,7 +689,7 @@ void RS_EventHandler::setSnapMode(RS2::SnapMode sm)
 /**
  * Sets the snap restriction for all currently active actions.
  */
-void RS_EventHandler::setSnapRestriction(RS2::SnapRestriction sr)
+void EventHandler::setSnapRestriction(RS2::SnapRestriction sr)
 {
 #if 0
        for(int c=0; c<RS_MAXACTIONS; ++c)
@@ -691,20 +705,20 @@ void RS_EventHandler::setSnapRestriction(RS2::SnapRestriction sr)
 #endif
 }
 
-void RS_EventHandler::debugActions()
+void EventHandler::debugActions()
 {
-       RS_DEBUG->print("---");
+       DEBUG->print("---");
 
        for(int c=0; c<RS_MAXACTIONS; ++c)
        {
                if (c == actionIndex)
-                       RS_DEBUG->print("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);
        }
 }