📄 rs_eventhandler.cpp
字号:
/****************************************************************************** $Id: rs_eventhandler.cpp 2392 2005-05-17 13:52:38Z andrew $**** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.**** This file is part of the qcadlib Library project.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** Licensees holding valid qcadlib Professional Edition licenses may use ** this file in accordance with the qcadlib Commercial License** Agreement provided with the Software.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.ribbonsoft.com for further details.**** Contact info@ribbonsoft.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "rs_eventhandler.h"#include "rs_actioninterface.h"#include "rs_coordinateevent.h"#include "rs_regexp.h"/** * Constructor. */RS_EventHandler::RS_EventHandler(RS_GraphicView* graphicView) { this->graphicView = graphicView; actionIndex=-1; for (int i=0; i<RS_MAXACTIONS; ++i) { currentActions[i] = NULL; } coordinateInputEnabled = true; defaultAction = NULL;}/** * Destructor. */RS_EventHandler::~RS_EventHandler() { RS_DEBUG->print("RS_EventHandler::~RS_EventHandler"); if (defaultAction!=NULL) { defaultAction->finish(); delete defaultAction; defaultAction = NULL; } killAllActions(); RS_DEBUG->print("RS_EventHandler::~RS_EventHandler: Deleting all actions.."); for (int i=0; i<RS_MAXACTIONS; ++i) { if (currentActions[i]!=NULL) { currentActions[i]->setFinished(); //delete currentActions[i]; //currentActions[i] = NULL; } } cleanUp(); RS_DEBUG->print("RS_EventHandler::~RS_EventHandler: Deleting all actions..: OK"); RS_DEBUG->print("RS_EventHandler::~RS_EventHandler: OK");}/** * Go back in current action. */void RS_EventHandler::back() { RS_MouseEvent e(QEvent::MouseButtonRelease, QPoint(0,0), Qt::RightButton, Qt::RightButton); mouseReleaseEvent(&e);}/** * Go enter pressed event for current action. */void RS_EventHandler::enter() { RS_KeyEvent e(QEvent::KeyPress, Qt::Key_Enter, '\n', 0); keyPressEvent(&e);}/** * Called by RS_GraphicView */void RS_EventHandler::mousePressEvent(RS_MouseEvent* e) { if (actionIndex>=0 && currentActions[actionIndex]!=NULL) { currentActions[actionIndex]->mousePressEvent(e);#if QT_VERSION>=0x030000 e->accept();#endif } else { if (defaultAction!=NULL) { defaultAction->mousePressEvent(e);#if QT_VERSION>=0x030000 e->accept();#endif } else { RS_DEBUG->print("currently no action defined");#if QT_VERSION>=0x030000 e->ignore();#endif } }}/** * Called by RS_GraphicView */void RS_EventHandler::mouseReleaseEvent(RS_MouseEvent* e) { if (actionIndex>=0 && currentActions[actionIndex]!=NULL && !currentActions[actionIndex]->isFinished()) { RS_DEBUG->print("call action %s", currentActions[actionIndex]->getName().latin1()); currentActions[actionIndex]->mouseReleaseEvent(e); // Clean up actions - one might be finished now cleanUp();#if QT_VERSION>=0x030000 e->accept();#endif } else { if (defaultAction!=NULL) { defaultAction->mouseReleaseEvent(e); } else {#if QT_VERSION>=0x030000 e->ignore();#endif } }}/** * Called by RS_GraphicView */void RS_EventHandler::mouseMoveEvent(RS_MouseEvent* e) { if (actionIndex>=0 && currentActions[actionIndex]!=NULL && !currentActions[actionIndex]->isFinished()) { currentActions[actionIndex]->mouseMoveEvent(e);#if QT_VERSION>=0x030000 e->accept();#endif } else { if (defaultAction!=NULL) { defaultAction->mouseMoveEvent(e);#if QT_VERSION>=0x030000 e->accept();#endif } else {#if QT_VERSION>=0x030000 e->ignore();#endif } //RS_DEBUG->print("currently no action defined"); }}/** * Called by RS_GraphicView */void RS_EventHandler::mouseLeaveEvent() { if (actionIndex>=0 && currentActions[actionIndex]!=NULL && !currentActions[actionIndex]->isFinished()) { currentActions[actionIndex]->suspend(); } else { if (defaultAction!=NULL) { defaultAction->suspend(); } //RS_DEBUG->print("currently no action defined"); }}/** * Called by RS_GraphicView */void RS_EventHandler::mouseEnterEvent() { if (actionIndex>=0 && currentActions[actionIndex]!=NULL && !currentActions[actionIndex]->isFinished()) { currentActions[actionIndex]->resume(); } else { if (defaultAction!=NULL) { defaultAction->resume(); } }}/** * Called by RS_GraphicView */void RS_EventHandler::keyPressEvent(RS_KeyEvent* e) { if (actionIndex>=0 && currentActions[actionIndex]!=NULL && !currentActions[actionIndex]->isFinished()) { currentActions[actionIndex]->keyPressEvent(e); } else { if (defaultAction!=NULL) { defaultAction->keyPressEvent(e); } else {#if QT_VERSION>=0x030000 e->ignore();#endif } //RS_DEBUG->print("currently no action defined"); }}/** * Called by RS_GraphicView */void RS_EventHandler::keyReleaseEvent(RS_KeyEvent* e) { 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"); }}/** * Handles command line events. */void RS_EventHandler::commandEvent(RS_CommandEvent* e) { RS_DEBUG->print("RS_EventHandler::commandEvent"); //RS_RegExp rex; RS_String cmd = e->getCommand(); if (coordinateInputEnabled) { if (!e->isAccepted()) { // handle absolute cartesian coordinate input: if (cmd.contains(',') && cmd.at(0)!='@') { if (actionIndex>=0 && currentActions[actionIndex]!=NULL && !currentActions[actionIndex]->isFinished()) { int commaPos = cmd.find(','); RS_DEBUG->print("RS_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"); if (ok1 && ok2) { RS_DEBUG->print("RS_EventHandler::commandEvent: 005"); RS_CoordinateEvent ce(RS_Vector(x,y)); RS_DEBUG->print("RS_EventHandler::commandEvent: 006"); currentActions[actionIndex]->coordinateEvent(&ce); } else { if (RS_DIALOGFACTORY!=NULL) { RS_DIALOGFACTORY->commandMessage( "Expression Syntax Error"); } } e->accept(); } } } // handle relative cartesian coordinate input: if (!e->isAccepted()) { if (cmd.contains(',') && cmd.at(0)=='@') { if (actionIndex>=0 && currentActions[actionIndex]!=NULL && !currentActions[actionIndex]->isFinished()) { int commaPos = cmd.find(','); bool ok1, ok2; double x = RS_Math::eval(cmd.mid(1, commaPos-1), &ok1); double y = RS_Math::eval(cmd.mid(commaPos+1), &ok2); if (ok1 && ok2) { RS_CoordinateEvent ce(RS_Vector(x,y) + graphicView->getRelativeZero()); currentActions[actionIndex]->coordinateEvent(&ce); } else { if (RS_DIALOGFACTORY!=NULL) { RS_DIALOGFACTORY->commandMessage( "Expression Syntax Error"); } } e->accept(); } } } // handle absolute polar coordinate input: if (!e->isAccepted()) { if (cmd.contains('<') && cmd.at(0)!='@') { if (actionIndex>=0 && currentActions[actionIndex]!=NULL && !currentActions[actionIndex]->isFinished()) { int commaPos = cmd.find('<'); bool ok1, ok2; double r = RS_Math::eval(cmd.left(commaPos), &ok1); double a = RS_Math::eval(cmd.mid(commaPos+1), &ok2); if (ok1 && ok2) { RS_Vector pos; pos.setPolar(r,RS_Math::deg2rad(a)); RS_CoordinateEvent ce(pos); currentActions[actionIndex]->coordinateEvent(&ce); } else { if (RS_DIALOGFACTORY!=NULL) { RS_DIALOGFACTORY->commandMessage( "Expression Syntax Error"); } } e->accept(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -