#include <QLineEdit>
#include <QDoubleValidator>
#include <QVariant>
+#include <QKeyEvent>
#include <limits>
*/
ModuleBase_DoubleSpinBox::ModuleBase_DoubleSpinBox(QWidget* theParent, int thePrecision)
: QDoubleSpinBox(theParent),
- myCleared(false)
+ myCleared(false),
+ myIsEmitKeyPressEvent(false)
{
// VSR 01/07/2010: Disable thousands separator for spin box
- // (to avoid incosistency of double-2-string and string-2-double conversion)
+ // (to avoid inconsistency of double-2-string and string-2-double conversion)
QLocale loc;
loc.setNumberOptions(loc.numberOptions() | QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator);
setLocale(loc);
return res;
}
+void ModuleBase_DoubleSpinBox::keyPressEvent(QKeyEvent* theEvent)
+{
+ bool isEmitKeyRelease = false;
+ 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;
+ else
+ isEmitKeyRelease = true;
+ }
+ break;
+ default:
+ break;
+ }
+ QDoubleSpinBox::keyPressEvent(theEvent);
+
+ if (isEmitKeyRelease)
+ emit enterPressed();
+}
+
+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.
}
}
- // Treat values ouside (min; max) range as Invalid
+ // Treat values outside (min; max) range as Invalid
// This check is enabled by assigning "strict_validity_check" dynamic property
// with value "true" to the spin box instance.
if (state == QValidator::Intermediate) {
{
myCleared = false;
}
+
+bool ModuleBase_DoubleSpinBox::enableKeyPressEvent(const bool& theEnable)
+{
+ bool aPreviousValue = myIsEmitKeyPressEvent;
+ myIsEmitKeyPressEvent = theEnable;
+
+ return aPreviousValue;
+}