Salome HOME
updated copyright message
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetEditor.h
1 // Copyright (C) 2014-2023  CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef ModuleBase_WidgetEditor_H
21 #define ModuleBase_WidgetEditor_H
22
23 #include <ModuleBase.h>
24 #include "ModuleBase_WidgetDoubleValue.h"
25
26 #include <QObject>
27 #include <QStringList>
28
29 class ModelAPI_Feature;
30 class QDialog;
31 class QLineEdit;
32
33 /**\class ModuleBase_WidgetEditor
34  * \ingroup GUI
35  * \brief Custom widget. An abstract class to be redefined to fill with some GUI controls
36  */
37 class MODULEBASE_EXPORT ModuleBase_WidgetEditor : public ModuleBase_WidgetDoubleValue
38 {
39 Q_OBJECT
40  public:
41   /// Constructor
42   /// \param theParent the parent object
43   /// \param theData the widget configuation. The attribute of the model widget is obtained from
44   ModuleBase_WidgetEditor(QWidget* theParent, const Config_WidgetAPI* theData);
45   /// Constructor
46   /// \param theParent the parent object
47   /// \param theAttribute The attribute of the model widget
48   ModuleBase_WidgetEditor(QWidget* theParent, const std::string& theAttribute);
49
50   /// Destructor
51   virtual ~ModuleBase_WidgetEditor();
52
53   /// Set focus to the first control of the current widget.
54   /// The focus policy of the control is checked.
55   /// If the widget has the NonFocus focus policy, it is skipped.
56   /// \return the state whether the widget can accept the focus
57   virtual bool focusTo();
58
59   /// Shous popup window under cursor for data editing
60   /// \param theSendSignals a flag whether the signals should be sent or the value
61   /// is to be applyed directly
62   /// \return true if the editor value is accepted
63   bool showPopupEditor(const bool theSendSignals = true);
64
65   /// Set current cursor position
66   /// \param theX the X coordinate
67   /// \param theY the Y coordinate
68   void setCursorPosition(const int theX, const int theY);
69
70 protected:
71   /// Returns true if the event is processed.
72   virtual bool processEnter();
73
74   /// Reject the current editor dialog if it is shown and returns true.
75   virtual bool processEscape();
76
77 private:
78   /// Show editor
79   /// \param theSpinMinValue a minimal value of popup menu spin box
80   /// \param theSpinMaxValue a maximum value of popup menu spin box
81   /// \param theOutValue a result value
82   /// \param theOutText a result text
83   /// \return true if the editor value is accepted
84   bool editedValue(double theSpinMinValue, double theSpinMaxValue,
85                    double& theOutValue, QString& theOutText);
86
87  private:
88    ///< the current widget feature
89    FeaturePtr myFeature;
90
91    ///< the kinds of possible features
92    QStringList myFeatureKinds;
93
94    int myXPosition, myYPosition;
95
96    QDialog* myEditorDialog;
97 };
98
99 #endif