Skip to content

Commit

Permalink
send Key_Escape to actions, issue#285
Browse files Browse the repository at this point in the history
  • Loading branch information
dxli committed Feb 8, 2012
1 parent 3724dfd commit 7cdc72e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 39 deletions.
49 changes: 24 additions & 25 deletions src/actions/rs_actiondefault.cpp
Expand Up @@ -63,7 +63,10 @@ QAction* RS_ActionDefault::createGUIAction(RS2::ActionType /*type*/,

void RS_ActionDefault::init(int status) {
RS_DEBUG->print("RS_ActionDefault::init");

if(status==Neutral){
deletePreview();
deleteSnapper();
}
RS_PreviewActionInterface::init(status);
v1 = v2 = RS_Vector(false);
// snapMode.clear();
Expand All @@ -82,15 +85,29 @@ void RS_ActionDefault::trigger() {
}

void RS_ActionDefault::keyPressEvent(QKeyEvent* e) {
if (e->key()==Qt::Key_Shift) {
restrBak = snapMode.restriction;
setSnapRestriction(RS2::RestrictOrthogonal);
}
// std::cout<<"RS_ActionDefault::keyPressEvent(): begin"<<std::endl;
switch(e->key()){
case Qt::Key_Shift:
restrBak = snapMode.restriction;
setSnapRestriction(RS2::RestrictOrthogonal);
e->accept();
//cleanup default action, issue#285
case Qt::Key_Escape:
// std::cout<<"RS_ActionDefault::keyPressEvent(): Qt::Key_Escape"<<std::endl;
deletePreview();
deleteSnapper();
setStatus(Neutral);
e->accept();
default:
e->ignore();
}

}

void RS_ActionDefault::keyReleaseEvent(QKeyEvent* e) {
if (e->key()==Qt::Key_Shift) {
setSnapRestriction(restrBak);
e->accept();
}
}

Expand Down Expand Up @@ -247,7 +264,8 @@ void RS_ActionDefault::mousePressEvent(QMouseEvent* e) {
}
} else if (e->button()==Qt::RightButton) {
//cleanup
cleanUpAction(e);
setStatus(Neutral);
e->accept();
}
}

Expand Down Expand Up @@ -309,27 +327,8 @@ void RS_ActionDefault::mouseReleaseEvent(QMouseEvent* e) {
}
} else if (e->button()==Qt::RightButton) {
//cleanup
cleanUpAction(e);
}
}

// cancel the current action and cleanup
void RS_ActionDefault::cleanUpAction(QMouseEvent* e){
switch (getStatus()) {
case SetCorner2:
case Moving:
case MovingRef:
deletePreview();
deleteSnapper();
setStatus(Neutral);
RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
e->accept();
break;

default:
RS_DIALOGFACTORY->requestPreviousMenu();
e->accept();
break;
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/actions/rs_actiondefault.h
Expand Up @@ -85,8 +85,6 @@ class RS_ActionDefault : public RS_PreviewActionInterface {
RS_Vector v1;
RS_Vector v2;
RS2::SnapRestriction restrBak;
private:
void cleanUpAction(QMouseEvent* e); // cancel the current action and cleanup

};

Expand Down
6 changes: 5 additions & 1 deletion src/lib/gui/rs_eventhandler.cpp
Expand Up @@ -529,7 +529,11 @@ void RS_EventHandler::killAllActions() {
if(currentActions.size()==0) return;
delete currentActions.takeFirst();
}
//cleanUp();
// if(defaultAction->rtti() == RS2::ActionDefault){

// }
//cleanup default action, issue#285
defaultAction->init(0);
}


Expand Down
20 changes: 9 additions & 11 deletions src/main/qc_applicationwindow.cpp
Expand Up @@ -4664,25 +4664,23 @@ void QC_ApplicationWindow::keyPressEvent(QKeyEvent* e) {
if (actionProcessed==false) {
// single key codes:
switch (e->key()) {
//need to pass Escape to actions, issue#285
case Qt::Key_Escape:
slotBack();
case Qt::Key_Shift:
case Qt::Key_Control:
case Qt::Key_Meta:
case Qt::Key_Alt:
case Qt::Key_CapsLock: {
QMainWindow::keyPressEvent(e);
QMainWindow::keyPressEvent(e);

// forward to actions:
RS_GraphicView* graphicView = getGraphicView();
if (graphicView!=NULL) {
graphicView->keyPressEvent(e);
}
e->accept();
// forward to actions:
RS_GraphicView* graphicView = getGraphicView();
if (graphicView!=NULL) {
graphicView->keyPressEvent(e);
}
break;

case Qt::Key_Escape:
slotBack();
e->accept();
}
break;

case Qt::Key_Return:
Expand Down

0 comments on commit 7cdc72e

Please sign in to comment.