Salome HOME
3.6 Separation of Boolean operations
[modules/shaper.git] / src / ModuleBase / ModuleBase_ParamSpinBox.h
index 8c94be9a509e975857413dcd4d13db92897663ae..09a10ca3cfa888e3afbea8df5c6df3a4e4ba46ee 100644 (file)
@@ -14,7 +14,8 @@
 // License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 //
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
 //
 
 #ifndef ModuleBase_ParamSpinBox_H
@@ -22,9 +23,9 @@
 
 #include "ModuleBase.h"
 
-#include <ModuleBase_DoubleSpinBox.h>
-
+#include <QAbstractSpinBox>
 #include <QValidator>
+#include <QLineEdit>
 
 class QStringListModel;
 class QCompleter;
@@ -33,7 +34,7 @@ class QCompleter;
 * \ingroup GUI
 * An extension of a double spin box which let to use parameters and expressions for value definition
 */
-class MODULEBASE_EXPORT ModuleBase_ParamSpinBox : public ModuleBase_DoubleSpinBox
+class MODULEBASE_EXPORT ModuleBase_ParamSpinBox : public QAbstractSpinBox
 {
   Q_OBJECT
 
@@ -50,7 +51,7 @@ public:
    \param theParent a parent object
    \param thePrecision a precision of values display
    */
-  explicit ModuleBase_ParamSpinBox( QWidget* theParent = 0, int thePrecision = -12 );
+  ModuleBase_ParamSpinBox( QWidget* theParent = 0, int thePrecision = 12 );
 
   /// Set list of completion strings
   void setCompletionList(QStringList&);
@@ -59,15 +60,19 @@ public:
 
   virtual void stepBy(int);
 
-  virtual double valueFromText(const QString&) const;
-  virtual QString textFromValue (double value) const;
+//  virtual double valueFromText(const QString&) const;
+//  virtual QString textFromValue (double value) const;
 
   virtual QValidator::State validate(QString&, int&) const;
 
   virtual void setValue(double);
 
+  double value() const;
+
   virtual void setText(const QString&);
 
+  QString text() const { return lineEdit()->text(); }
+
   /// Set a flag about accepted variable
   void setAcceptVariables(const bool);
 
@@ -77,42 +82,82 @@ public:
   /// Returns True if the input value contains variable
   bool hasVariable() const;
 
+  double minimum() const { return myMinimum; }
+  double maximum() const { return myMaximum; }
+
+  void setMinimum(double theMin) { myMinimum = theMin; myValidator->setBottom(theMin); }
+  void setMaximum(double theMax) { myMaximum = theMax; myValidator->setTop(theMax); }
+
+  int decimals() const { return myValidator->decimals(); }
+  void setDecimals(int thePrecision) { myValidator->setDecimals(thePrecision); }
+
+  double singleStep() const { return mySingleStep; }
+  void setSingleStep(double theStep) { mySingleStep = theStep; }
+
+  void setValueEnabled(bool theEnable);
+
 protected:
+  /*!
+  \brief This function is called when the spinbox receives key release event.
+  */
+  virtual void keyReleaseEvent(QKeyEvent *event);
+
+  virtual StepEnabled stepEnabled() const { return StepUpEnabled | StepDownEnabled; }
+
    /// Returns True if the given text contains variable
    /// \param theText a text string
   bool hasVariable(const QString& theText) const;
 
-  /// Returns state of the control
-  State isValid(const QString&, double&) const;
-
-  /// Returns True if the given value is within min and max of the control
-  bool checkRange(const double) const;
-
-  /// Finds a variable by its name. Returns true in success
-  /// \param theName a name of variable
-  /// \param outValue an output value of the variable
-  bool findVariable(const QString& theName, double& outValue) const;
+//  /// Returns state of the control
+//  State isValid(const QString&, double&) const;
+//
+//  /// Returns True if the given value is within min and max of the control
+//  bool checkRange(const double) const;
+//
+//  /// Finds a variable by its name. Returns true in success
+//  /// \param theName a name of variable
+//  /// \param outValue an output value of the variable
+//  bool findVariable(const QString& theName, double& outValue) const;
 
 signals:
-  void textChanged(const QString& theText);
+  void textChanged(const QString&);
 
- protected:
-  virtual void showEvent(QShowEvent*);
+// protected:
+//  virtual void showEvent(QShowEvent*);
+//
+// protected slots:
+//   /// A slot called on text change
+//  void onTextChanged(const QString&);
+//
+// private:
+//  void connectSignalsAndSlots();
 
- protected slots:
-   /// A slot called on text change
-  void onTextChanged(const QString&);
+private slots:
+  void insertCompletion(const QString&);
 
- private:
-  void connectSignalsAndSlots();
+  void onTextChanged(const QString&);
 
- private:
-  QString myTextValue;
+private:
+  QString getPrefix(int& theStart, int& theEnd) const;
 
+  bool myIsEquation;
   bool myAcceptVariables;
 
   QStringListModel* myCompleterModel;
   QCompleter* myCompleter;
+  int myPrecision;
+
+  double myMinimum;
+  double myMaximum;
+
+  int myCompletePos;
+
+  double mySingleStep;
+
+  /// Cashed color of active base palette
+  QColor myEnabledBaseColor;
+
+  QDoubleValidator* myValidator;
 };
 
 #endif