// JLH 05/28/2010 Added this text. :-)
//
+// This is only used by the GraphicView class...
+
#include "eventhandler.h"
#include "actioninterface.h"
/**
* 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; i<RS_MAXACTIONS; ++i)
+ for(int i=0; i<RS_MAXACTIONS; i++)
currentActions[i] = NULL;
- coordinateInputEnabled = true;
- defaultAction = NULL;
+// coordinateInputEnabled = true;
+// defaultAction = NULL;
}
/**
{
DEBUG->print("EventHandler::~EventHandler");
- if (defaultAction != NULL)
+ if (defaultAction)
{
defaultAction->finish();
delete defaultAction;
defaultAction = NULL;
}
- killAllActions();
+ KillAllActions();
DEBUG->print("EventHandler::~EventHandler: Deleting all actions..");
}
}
- cleanUp();
+ CleanUp();
DEBUG->print("EventHandler::~EventHandler: Deleting all actions..: OK");
DEBUG->print("EventHandler::~EventHandler: OK");
}
/**
* 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)
{
/**
* Called by GraphicView
*/
-void EventHandler::mouseReleaseEvent(QMouseEvent * e)
+void EventHandler::MouseReleaseEvent(QMouseEvent * e)
{
if (actionIndex >= 0 && currentActions[actionIndex] != NULL
&& !currentActions[actionIndex]->isFinished())
currentActions[actionIndex]->mouseReleaseEvent(e);
// Clean up actions - one might be finished now
- cleanUp();
+ CleanUp();
e->accept();
}
else
/**
* Called by GraphicView
*/
-void EventHandler::mouseMoveEvent(QMouseEvent * e)
+void EventHandler::MouseMoveEvent(QMouseEvent * e)
{
if (actionIndex >= 0 && currentActions[actionIndex]
&& !currentActions[actionIndex]->isFinished())
}
}
+#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())
{
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())
{
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())
/**
* Called by GraphicView
*/
-void EventHandler::keyReleaseEvent(QKeyEvent * e)
+void EventHandler::KeyReleaseEvent(QKeyEvent * e)
{
if (actionIndex >= 0 && currentActions[actionIndex]
&& !currentActions[actionIndex]->isFinished())
/**
* Handles command line events.
*/
-void EventHandler::commandEvent(CommandEvent * e)
+void EventHandler::HandleCommandEvent(GraphicView * graphicView, CommandEvent * e)
{
DEBUG->print("EventHandler::commandEvent");
QString cmd = e->getCommand();
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");
}
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");
}
{
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");
}
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);
{
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);
}
}
}
- // send command event directly to current action:
+ // Send command event directly to current action:
if (!e->isAccepted())
{
if (actionIndex >= 0 && currentActions[actionIndex]
/**
* Enables coordinate input in the command line.
*/
-void EventHandler::enableCoordinateInput()
+void EventHandler::EnableCoordinateInput()
{
coordinateInputEnabled = true;
}
/**
* Enables coordinate input in the command line.
*/
-void EventHandler::disableCoordinateInput()
+void EventHandler::DisableCoordinateInput()
{
coordinateInputEnabled = false;
}
/**
* @return Current action.
*/
-ActionInterface * EventHandler::getCurrentAction()
+ActionInterface * EventHandler::GetCurrentAction()
{
if (actionIndex >= 0 && currentActions[actionIndex]
&& !currentActions[actionIndex]->isFinished())
/**
* @return The current default action.
*/
-ActionInterface * EventHandler::getDefaultAction()
+ActionInterface * EventHandler::GetDefaultAction()
{
return defaultAction;
}
/**
* Sets the default action.
*/
-void EventHandler::setDefaultAction(ActionInterface * action)
+void EventHandler::SetDefaultAction(ActionInterface * action)
{
if (defaultAction)
{
/**
* Sets the current action.
*/
-void EventHandler::setCurrentAction(ActionInterface * action)
+void EventHandler::SetCurrentAction(ActionInterface * action)
{
DEBUG->print("EventHandler::setCurrentAction");
// 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();
}
DEBUG->print("EventHandler::setCurrentAction: cleaning up..");
- cleanUp();
+ CleanUp();
DEBUG->print("EventHandler::setCurrentAction: debugging actions");
- debugActions();
+ DebugActions();
DEBUG->print("GraphicView::setCurrentAction: OK");
}
* 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; c<RS_MAXACTIONS; ++c)
{
/**
* Kills all running actions. Called when a window is closed.
+ * Actually: It does NOTHING
*/
-void EventHandler::killAllActions()
+void EventHandler::KillAllActions()
{
/*
for (int c=0; c<RS_MAXACTIONS; ++c) {
/**
* @return true if there is at least one action in the action stack.
*/
-bool EventHandler::hasAction()
+bool EventHandler::HasAction()
{
if (actionIndex != -1 || defaultAction)
return true;
/**
* Garbage collector for actions.
*/
-void EventHandler::cleanUp()
+void 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)
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; c<RS_MAXACTIONS; ++c)
- if (currentActions[c])
- currentActions[c]->setSnapMode(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; c<RS_MAXACTIONS; ++c)
- if (currentActions[c])
- currentActions[c]->setSnapRestriction(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("---");