X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_OperationMgr.cpp;h=8a3b36e12ca8755668b625de5c2f3df25eb958ca;hb=0caee92b045249b15dd6df72d52b44335e05cc3f;hp=ad312dad5c99de848390a0f352ace60621f3675f;hpb=cd942c062815dd044cf0625fc987d3244d7954c7;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index ad312dad5..8a3b36e12 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -7,10 +7,14 @@ #include "ModuleBase_Operation.h" #include +#include +#include XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent) : QObject(theParent) { + // listen to Escape signal to stop the current operation + qApp->installEventFilter(this); } XGUI_OperationMgr::~XGUI_OperationMgr() @@ -42,6 +46,8 @@ bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation) connect(theOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped())); connect(theOperation, SIGNAL(started()), this, SIGNAL(operationStarted())); connect(theOperation, SIGNAL(resumed()), this, SIGNAL(operationResumed())); + connect(theOperation, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)), + this, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*))); theOperation->start(); return true; @@ -57,6 +63,29 @@ bool XGUI_OperationMgr::abortOperation() return true; } +QStringList XGUI_OperationMgr::operationList() +{ + QStringList result; + foreach(ModuleBase_Operation* eachOperation, myOperations) { + result << eachOperation->id(); + } + return result; +} + +bool XGUI_OperationMgr::eventFilter(QObject *theObject, QEvent *theEvent) +{ + if (theEvent->type() == QEvent::KeyRelease) { + QKeyEvent* aKeyEvent = (QKeyEvent*)theEvent; + if (aKeyEvent && aKeyEvent->key() == Qt::Key_Escape) { + // TODO: this is Escape button processing when the property panel has empty content, + // but the operation should be stopped by the Enter has been clicked + onKeyReleased("", aKeyEvent); + return true; + } + } + return QObject::eventFilter(theObject, theEvent); +} + void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation) { theOperation->resume(); @@ -79,10 +108,16 @@ bool XGUI_OperationMgr::canStartOperation(ModuleBase_Operation* theOperation) bool XGUI_OperationMgr::canStopOperation() { - int anAnswer = QMessageBox::question(0, tr("Operation launch"), - tr("Previous operation is not finished and will be aborted"), - QMessageBox::Ok, QMessageBox::Cancel); - return anAnswer == QMessageBox::Ok; + ModuleBase_Operation* anOperation = currentOperation(); + if (anOperation) { + if (anOperation->isModified()) { + int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Operation launch"), + tr("Previous operation is not finished and will be aborted"), + QMessageBox::Ok, QMessageBox::Cancel); + return anAnswer == QMessageBox::Ok; + } + } + return true; } void XGUI_OperationMgr::onCommitOperation() @@ -95,10 +130,22 @@ void XGUI_OperationMgr::onCommitOperation() void XGUI_OperationMgr::onAbortOperation() { ModuleBase_Operation* anOperation = currentOperation(); - if (anOperation) + if (anOperation && canAbortOperation()) anOperation->abort(); } +bool XGUI_OperationMgr::canAbortOperation() +{ + ModuleBase_Operation* anOperation = currentOperation(); + if (anOperation && anOperation->isModified()) { + int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Cancel operation"), + tr("Operation %1 will be cancelled. Continue?").arg(anOperation->id()), + QMessageBox::Yes, QMessageBox::No); + return anAnswer == QMessageBox::Yes; + } + return true; +} + void XGUI_OperationMgr::onOperationStopped() { ModuleBase_Operation* aSenderOperation = dynamic_cast(sender()); @@ -106,11 +153,11 @@ void XGUI_OperationMgr::onOperationStopped() if (!aSenderOperation || !anOperation || aSenderOperation != anOperation ) return; - emit operationStopped(anOperation); - myOperations.removeAll(anOperation); anOperation->deleteLater(); + emit operationStopped(anOperation); + // get last operation which can be resumed ModuleBase_Operation* aResultOp = 0; QListIterator anIt(myOperations); @@ -126,3 +173,17 @@ void XGUI_OperationMgr::onOperationStopped() if (aResultOp) resumeOperation(aResultOp); } + +void XGUI_OperationMgr::onKeyReleased(const std::string& theName, QKeyEvent* theEvent) +{ + ModuleBase_Operation* anOperation = currentOperation(); + if (anOperation) + anOperation->keyReleased(theName, theEvent); +} + +void XGUI_OperationMgr::onWidgetActivated(ModuleBase_ModelWidget* theWidget) +{ + ModuleBase_Operation* anOperation = currentOperation(); + if (anOperation) + anOperation->onWidgetActivated(theWidget); +}