From fadbe85b09fc71d1bab42625b10e385841fe4848 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 21 Oct 2015 18:51:10 +0300 Subject: [PATCH] Apply the distance by enter immediatelly. --- src/ModuleBase/ModuleBase_DoubleSpinBox.cpp | 14 ++++++++++-- src/ModuleBase/ModuleBase_DoubleSpinBox.h | 12 +++++++++-- src/ModuleBase/ModuleBase_WidgetEditor.cpp | 24 +++++++++++---------- src/ModuleBase/ModuleBase_WidgetEditor.h | 3 +++ 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp b/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp index 46f208ee2..5cd665673 100644 --- a/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp @@ -59,7 +59,8 @@ const double PSEUDO_ZERO = 1.e-20; ModuleBase_DoubleSpinBox::ModuleBase_DoubleSpinBox(QWidget* theParent, int thePrecision) : QDoubleSpinBox(theParent), myCleared(false), - myIsModified(false) + myIsModified(false), + myIsEmitKeyPressEvent(false) { // VSR 01/07/2010: Disable thousands separator for spin box // (to avoid inconsistency of double-2-string and string-2-double conversion) @@ -207,7 +208,8 @@ void ModuleBase_DoubleSpinBox::keyPressEvent(QKeyEvent *theEvent) case Qt::Key_Enter: case Qt::Key_Return: { // do not react to the Enter key, the property panel processes it - return; + if (!myIsEmitKeyPressEvent) + return; } break; default: @@ -357,3 +359,11 @@ void ModuleBase_DoubleSpinBox::clearModified() { myIsModified = false; } + +bool ModuleBase_DoubleSpinBox::enableKeyPressEvent(const bool& theEnable) +{ + bool aPreviousValue = myIsEmitKeyPressEvent; + myIsEmitKeyPressEvent = theEnable; + + return aPreviousValue; +} diff --git a/src/ModuleBase/ModuleBase_DoubleSpinBox.h b/src/ModuleBase/ModuleBase_DoubleSpinBox.h index f725c59bc..d98957b14 100644 --- a/src/ModuleBase/ModuleBase_DoubleSpinBox.h +++ b/src/ModuleBase/ModuleBase_DoubleSpinBox.h @@ -49,12 +49,17 @@ Q_OBJECT /// Validate current value virtual QValidator::State validate(QString&, int&) const; - // Returns true if the current value is modified by has not been applyed yet + /// Returns true if the current value is modified by has not been applyed yet virtual bool isModified() const; - // Clears modified state + /// Clears modified state void clearModified(); + /// Change enable/disable internal state to emit key press event + /// \param theEnable if true, the signal is emitted + /// \return the previous value + bool enableKeyPressEvent(const bool& theEnable); + signals: /// A signal that is emitted by the "Tab" key event. It is emitted before the key is processed. void focusNextPrev(); @@ -77,6 +82,9 @@ signals: virtual bool focusNextPrevChild(bool theIsNext); private: + // boolen flag whether the key event is emitted. The default value is false + bool myIsEmitKeyPressEvent; + /// Is clear flag bool myCleared; diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index 5aa9aa24f..288e3f4eb 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -43,29 +43,31 @@ ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor() { } -void editedValue(double& outValue, QString& outText) +void ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText) { QDialog aDlg(QApplication::desktop(), Qt::Popup/* | Qt::FramelessWindowHint*/); QHBoxLayout* aLay = new QHBoxLayout(&aDlg); aLay->setContentsMargins(2, 2, 2, 2); - ModuleBase_ParamSpinBox* aEditor = new ModuleBase_ParamSpinBox(&aDlg); - aEditor->setMinimum(0); - aEditor->setMaximum(DBL_MAX); + ModuleBase_ParamSpinBox* anEditor = new ModuleBase_ParamSpinBox(&aDlg); + anEditor->enableKeyPressEvent(true); + + anEditor->setMinimum(0); + anEditor->setMaximum(DBL_MAX); if (outText.isEmpty()) - aEditor->setValue(outValue); + anEditor->setValue(outValue); else - aEditor->setText(outText); + anEditor->setText(outText); - aLay->addWidget(aEditor); + aLay->addWidget(anEditor); - aEditor->setFocus(); - aEditor->selectAll(); - QObject::connect(aEditor, SIGNAL(editingFinished()), &aDlg, SLOT(accept())); + anEditor->setFocus(); + anEditor->selectAll(); + QObject::connect(anEditor, SIGNAL(editingFinished()), &aDlg, SLOT(accept())); aDlg.move(QCursor::pos()); aDlg.exec(); - outText = aEditor->text(); + outText = anEditor->text(); bool isDouble; double aValue = outText.toDouble(&isDouble); if (isDouble) { diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.h b/src/ModuleBase/ModuleBase_WidgetEditor.h index 8bdf6f9e1..f63ec0bca 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.h +++ b/src/ModuleBase/ModuleBase_WidgetEditor.h @@ -47,6 +47,9 @@ Q_OBJECT /// Shous popup window under cursor for data editing void showPopupEditor(); +private: + void editedValue(double& outValue, QString& outText); + private: ///< the current widget feature FeaturePtr myFeature; -- 2.39.2