additional correction for case: Escape click in Abort operation dialog did not close this dialog.
return false;
}
+bool ModuleBase_ModelWidget::processEscape()
+{
+ return false;
+}
+
bool ModuleBase_ModelWidget::processDelete()
{
// we consider that model objects eats delete key in order to
/// Returns true if the event is processed. The default implementation is empty, returns false.
virtual bool processEnter();
+ /// Returns true if the event is processed. The default implementation is empty, returns false.
+ virtual bool processEscape();
+
/// Returns true if the event is processed. The default implementation is empty, returns false.
virtual bool processDelete();
#include <GeomDataAPI_Point2D.h>
#include <QApplication>
+#include <QKeyEvent>
#include <QLineEdit>
#include <QMenu>
#include <QWidget>
#include <QDialog>
#include <QLayout>
+// Dialog is redefined to avoid Escape key processing
+class ModuleBase_EditorDialog : public QDialog
+{
+public:
+ ModuleBase_EditorDialog(QWidget* theParent, Qt::WindowFlags theFlags)
+ : QDialog(theParent, theFlags) {}
+ ~ModuleBase_EditorDialog() {}
+
+protected:
+ // Do nothing if key pressed because it is processing on operation manager level
+ virtual void keyPressEvent(QKeyEvent* theEvent) {
+ if (theEvent->key() == Qt::Key_Escape)
+ return;
+ QDialog::keyPressEvent(theEvent);
+ }
+};
+
ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
const Config_WidgetAPI* theData)
: ModuleBase_WidgetDoubleValue(theParent, theData),
{
bool isValueAccepted = false;
- myEditorDialog = new QDialog(QApplication::desktop(), Qt::FramelessWindowHint);
+ myEditorDialog = new ModuleBase_EditorDialog(QApplication::desktop(), Qt::FramelessWindowHint);
QHBoxLayout* aLay = new QHBoxLayout(myEditorDialog);
aLay->setContentsMargins(2, 2, 2, 2);
}
ModuleBase_Tools::setFocus(mySpinBox, "ModuleBase_WidgetEditor::editedValue");
mySpinBox->selectAll();
-
- if (theSendSignals && !myIsEditing)
- emit enterClicked(this);
+ // enter is processed, so we need not anymore emit clicked signal
+ //if (theSendSignals && !myIsEditing && isValueAccepted)
+ // emit enterClicked(this);
return isValueAccepted;
}
return ModuleBase_WidgetDoubleValue::processEnter();
}
+
+bool ModuleBase_WidgetEditor::processEscape()
+{
+ if (myEditorDialog) {
+ myEditorDialog->reject();
+ return true;
+ }
+
+ return ModuleBase_WidgetDoubleValue::processEscape();
+}
/// Returns true if the event is processed.
virtual bool processEnter();
+ /// Reject the current editor dialog if it is shown and returns true.
+ virtual bool processEscape();
+
private:
/// Show editor
/// \param theOutValue a result value
aGroup->featuresInfo();
std::list<std::shared_ptr<Config_FeatureMessage> >::const_iterator aFIt =
aFeaturesInfo.begin(), aFLast = aFeaturesInfo.end();
- int aFSize = aFeaturesInfo.size();
+ size_t aFSize = aFeaturesInfo.size();
for(int i = 0; aFIt != aFLast; aFIt++, i++) {
std::shared_ptr<Config_FeatureMessage> aMessage = *aFIt;
bool aUseSeparator = i == aFSize-1;
else if (theEvent->type() == QEvent::KeyPress) {
QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
+ switch (aKeyEvent->key()) {
+ case Qt::Key_Escape:
+ isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent);
+ break;
+ default:
+ break;
+ }
}
}
if (!isAccepted)
XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent,
ModuleBase_IWorkshop* theWorkshop)
-: QObject(theParent), myWorkshop(theWorkshop), mySHIFTPressed(false)
+: QObject(theParent), myWorkshop(theWorkshop), mySHIFTPressed(false), myActiveMessageBox(0)
{
/// we need to install filter to the application in order to react to 'Delete' key button
/// this key can not be a short cut for a corresponded action because we need to set
aResult = false;
}
else {
- aResult = QMessageBox::question(qApp->activeWindow(),
- tr("Abort operation"),
- tr("All active operations will be aborted."),
- QMessageBox::Ok | QMessageBox::Cancel,
- QMessageBox::Cancel) == QMessageBox::Ok;
+ myActiveMessageBox = createMessageBox(tr("All active operations will be aborted."));
+ aResult = myActiveMessageBox->exec() == QMessageBox::Ok;
+ myActiveMessageBox = 0;
while(aResult && hasOperation()) {
abortOperation(currentOperation());
}
return true;
if (theOperation && theOperation->isModified()) {
QString aMessage = tr("%1 operation will be aborted.").arg(theOperation->id());
- int anAnswer = QMessageBox::question(qApp->activeWindow(),
- tr("Abort operation"),
- aMessage,
- QMessageBox::Ok | QMessageBox::Cancel,
- QMessageBox::Cancel);
- return anAnswer == QMessageBox::Ok;
+
+ myActiveMessageBox = createMessageBox(aMessage);
+ int anAnswer = myActiveMessageBox->exec() == QMessageBox::Ok;
+ myActiveMessageBox = 0;
+ return anAnswer;
}
return true;
}
ModuleBase_Operation* anOperation = currentOperation();
bool isAccepted = false;
switch (theEvent->key()) {
- case Qt::Key_Escape: {
- ModuleBase_Operation* aOperation = currentOperation();
- if (aOperation) {
- onAbortOperation();
- isAccepted = true;
- }
- }
- break;
case Qt::Key_Tab:
case Qt::Key_Backtab:
{
return isAccepted;
}
+bool XGUI_OperationMgr::onKeyPressed(QObject *theObject, QKeyEvent* theEvent)
+{
+ // Let the manager decide what to do with the given key combination.
+ ModuleBase_Operation* anOperation = currentOperation();
+ bool isAccepted = false;
+ switch (theEvent->key()) {
+ case Qt::Key_Escape: {
+ // processing in message box
+ if (myActiveMessageBox)
+ {
+ myActiveMessageBox->reject();
+ isAccepted = true;
+ }
+ // processing in the active widget
+ ModuleBase_Operation* aOperation = currentOperation();
+ if (!isAccepted && aOperation) {
+ ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+ ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
+ if (anActiveWgt)
+ isAccepted = anActiveWgt && anActiveWgt->processEscape();
+ }
+ // default Escape button functionality
+ if (!isAccepted && aOperation) {
+ onAbortOperation();
+ isAccepted = true;
+ }
+ }
+ break;
+ }
+ return isAccepted;
+}
+
bool XGUI_OperationMgr::onProcessEnter(QObject* theObject)
{
bool isAccepted = false;
}
return isPPChild;
}
+
+QMessageBox* XGUI_OperationMgr::createMessageBox(const QString& theMessage)
+{
+ QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
+ QObject::tr("Abort operation"), theMessage, QMessageBox::Ok | QMessageBox::Cancel,
+ qApp->activeWindow());
+ aMessageBox->setDefaultButton(QMessageBox::Cancel);
+ aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key
+
+ return aMessageBox;
+}
\ No newline at end of file
#include <QStringList>
class QKeyEvent;
+class QMessageBox;
class ModuleBase_IWorkshop;
class XGUI_Workshop;
/// \param theEvent the mouse event
bool onKeyReleased(QObject *theObject, QKeyEvent* theEvent);
+ /// SLOT, that is called by the key in the property panel is clicked.
+ /// \param theObject a sender of the event
+ /// \param theEvent the mouse event
+ bool onKeyPressed(QObject *theObject, QKeyEvent* theEvent);
+
/// The functionaly, that should be done by delete click
/// Fistly the active widget processes it, then workshop. If no one does not
/// process it, do nothing
/// \param theParent a candidate to be a parent
static bool isChildObject(const QObject* theObject, const QObject* theParent);
+ /// Creates question message box with OK/Cancel buttons, where Cancel is default button,
+ /// Escape is Null button
+ /// \param theMessage text of the message
+ /// \return message box
+ static QMessageBox* createMessageBox(const QString& theMessage);
+
private:
typedef QList<ModuleBase_Operation*> Operations; ///< definition for a list of operations
Operations myOperations; ///< a stack of started operations. The active operation is on top,
/// Current workshop
ModuleBase_IWorkshop* myWorkshop;
-
+ QMessageBox* myActiveMessageBox;
XGUI_ShortCutListener* myShortCutListener;
bool mySHIFTPressed;
};