Improvin Widget Editor to correctly process Enter event in global events listener.
*/
ModuleBase_DoubleSpinBox::ModuleBase_DoubleSpinBox(QWidget* theParent, int thePrecision)
: QDoubleSpinBox(theParent),
- myCleared(false),
- myIsEmitKeyPressEvent(false)
+ myCleared(false)
{
setLocale(ModuleBase_Tools::doubleLocale());
return res;
}
-void ModuleBase_DoubleSpinBox::keyPressEvent(QKeyEvent* theEvent)
-{
- switch (theEvent->key()) {
- case Qt::Key_Enter:
- case Qt::Key_Return: {
- // do not react to the Enter key, the property panel processes it
- if (!myIsEmitKeyPressEvent)
- return;
- }
- break;
- default:
- break;
- }
- QDoubleSpinBox::keyPressEvent(theEvent);
-}
-
-void ModuleBase_DoubleSpinBox::keyReleaseEvent(QKeyEvent* theEvent)
-{
- switch (theEvent->key()) {
- case Qt::Key_Enter:
- case Qt::Key_Return: {
- // the enter has already been processed when key is pressed,
- // key release should not be processed in operation manager
- if (myIsEmitKeyPressEvent) {
- theEvent->accept();
- emit enterReleased();
- return;
- }
- }
- break;
- default:
- break;
- }
- QDoubleSpinBox::keyReleaseEvent(theEvent);
-}
-
/*!
\brief Perform \a steps increment/decrement steps.
myCleared = false;
}
-bool ModuleBase_DoubleSpinBox::enableKeyPressEvent(const bool& theEnable)
-{
- bool aPreviousValue = myIsEmitKeyPressEvent;
- myIsEmitKeyPressEvent = theEnable;
-
- return aPreviousValue;
-}
-
void ModuleBase_DoubleSpinBox::setValueEnabled(const bool& theEnable)
{
setReadOnly(!theEnable);
/// Validate current value
virtual QValidator::State validate(QString&, int&) const;
- /// 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);
-
/// Imitation of disable control value. If theEnable is false, the control becomes
/// read only and base color is disabled.
void setValueEnabled(const bool& theEnable);
-signals:
- /// The signal about key release on the control, that corresponds to the attribute
- void enterReleased();
-
protected slots:
/// Called on text changed
virtual void onTextChanged(const QString&);
protected:
/// Removes extra trailing zero symbols
QString removeTrailingZeroes(const QString&) const;
- /// Called on key press event
- virtual void keyReleaseEvent(QKeyEvent* theEvent);
-
- /// Called on key press event
- virtual void keyPressEvent(QKeyEvent* theEvent);
private:
// boolen flag whether the key event is emitted. The default value is false
ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
const Config_WidgetAPI* theData)
: ModuleBase_WidgetDoubleValue(theParent, theData),
- myXPosition(-1), myYPosition(-1)
+ myXPosition(-1), myYPosition(-1), myEditorDialog(0)
{
}
{
bool isValueAccepted = false;
- QDialog aDlg(QApplication::desktop(), Qt::FramelessWindowHint);
- QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
- aLay->setContentsMargins(2, 2, 2, 2);
+ myEditorDialog = new QDialog(QApplication::desktop(), Qt::FramelessWindowHint);
- ModuleBase_ParamSpinBox* anEditor = new ModuleBase_ParamSpinBox(&aDlg);
- anEditor->enableKeyPressEvent(true);
+ QHBoxLayout* aLay = new QHBoxLayout(myEditorDialog);
+ aLay->setContentsMargins(2, 2, 2, 2);
+ ModuleBase_ParamSpinBox* anEditor = new ModuleBase_ParamSpinBox(myEditorDialog);
anEditor->setMinimum(0);
anEditor->setMaximum(DBL_MAX);
if (outText.isEmpty())
ModuleBase_Tools::setFocus(anEditor, "ModuleBase_WidgetEditor::editedValue");
anEditor->selectAll();
- QObject::connect(anEditor, SIGNAL(enterReleased()), &aDlg, SLOT(accept()));
QPoint aPoint = QCursor::pos();
if (myXPosition >= 0 && myYPosition >= 0)
aPoint = QPoint(myXPosition, myYPosition);
- aDlg.move(aPoint);
- isValueAccepted = aDlg.exec() == QDialog::Accepted;
+ myEditorDialog->move(aPoint);
+ isValueAccepted = myEditorDialog->exec() == QDialog::Accepted;
if (isValueAccepted) {
outText = anEditor->text();
bool isDouble;
outText = ""; // return empty string, if it's can be converted to a double
}
}
+ delete myEditorDialog;
+ myEditorDialog = 0;
return isValueAccepted;
}
myXPosition = theX;
myYPosition = theY;
}
+
+bool ModuleBase_WidgetEditor::processEnter()
+{
+ if (myEditorDialog) {
+ myEditorDialog->accept();
+ return true;
+ }
+
+ return ModuleBase_WidgetDoubleValue::processEnter();
+}
#include <QStringList>
class ModelAPI_Feature;
+class QDialog;
class QLineEdit;
/**\class ModuleBase_WidgetEditor
/// \param theY the Y coordinate
void setCursorPosition(const int theX, const int theY);
+ /// Returns true if the event is processed.
+ virtual bool processEnter();
+
private:
/// Show editor
/// \param theOutValue a result value
QStringList myFeatureKinds;
int myXPosition, myYPosition;
+
+ QDialog* myEditorDialog;
};
#endif
bool isAccepted = false;
if (myIsActive && theEvent->type() == QEvent::KeyRelease) {
QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
- if(aKeyEvent) {
+ if (aKeyEvent) {
switch (aKeyEvent->key()) {
- case Qt::Key_Delete: {
+ case Qt::Key_Delete:
isAccepted = myOperationMgr->onProcessDelete(theObject);
- }
+ break;
+ default:
+ myOperationMgr->onKeyReleased(theObject, aKeyEvent);
+ isAccepted = true;
+ break;
}
}
}
return myOperations.at(idx - 1);
}
-bool XGUI_OperationMgr::eventFilter(QObject *theObject, QEvent *theEvent)
-{
- bool isAccepted = false;
- if (theEvent->type() == QEvent::KeyRelease) {
- QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
- if(aKeyEvent)
- isAccepted = onKeyReleased(theObject, aKeyEvent);
- }
- if (!isAccepted)
- isAccepted = QObject::eventFilter(theObject, theEvent);
-
- return isAccepted;
-}
-
bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
{
if (hasOperation())
if (aPanel) { // check for case when the operation is started but property panel is not filled
XGUI_PropertyPanel* aPP = dynamic_cast<XGUI_PropertyPanel*>(aPanel);
aPP->focusNextPrevChild_(theEvent->key() == Qt::Key_Tab);
+ isAccepted = true;
}
}
}
if (!aOperation)
return isAccepted;
ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+ // the next code is obsolete as we want to process Enter in property panel always
// only property panel enter is processed in order to do not process enter in application dialogs
- bool isPPChild = isChildObject(theObject, aPanel);
- if (!isPPChild)
- return isAccepted;
+ //bool isPPChild = isChildObject(theObject, aPanel);
+ //if (!isPPChild)
+ // return isAccepted;
ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
bool isAborted = false;
/// else, or if there is no parent - returns NULL
ModuleBase_Operation* previousOperation(ModuleBase_Operation* theOperation) const;
- /// Redefinition of virtual function
- /// \param theObject a sender of the event
- /// \param theEvent the event
- virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
-
/// Start the operation and append it to the stack of operations
/// \param theOperation the started operation
/// \return the state whether the current operation is started