Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetSelector.h
1 // File:        ModuleBase_WidgetSelector.h
2 // Created:     2 June 2014
3 // Author:      Vitaly Smetannikov
4
5 #ifndef ModuleBase_WidgetSelector_H
6 #define ModuleBase_WidgetSelector_H
7
8 #include "ModuleBase.h"
9 #include "ModuleBase_ModelWidget.h"
10
11 #include <ModelAPI_Object.h>
12
13 #include <TopAbs_ShapeEnum.hxx>
14
15 #include <QStringList>
16 #include <QPalette>
17
18 class Config_WidgetAPI;
19 class QWidget;
20 class QLabel;
21 class QLineEdit;
22 class QToolButton;
23 class ModuleBase_IWorkshop;
24
25 class MODULEBASE_EXPORT ModuleBase_WidgetSelector : public ModuleBase_ModelWidget
26 {
27 Q_OBJECT
28  public:
29   ModuleBase_WidgetSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
30                             const Config_WidgetAPI* theData, const std::string& theParentId);
31
32   virtual ~ModuleBase_WidgetSelector();
33
34   /// Saves the internal parameters to the given feature
35   /// \param theObject a model feature to be changed
36   virtual bool storeValue() const;
37
38   virtual bool restoreValue();
39
40   virtual bool focusTo();
41
42   /// Returns the internal parent wiget control, that can be shown anywhere
43   /// \returns the widget
44   QWidget* getControl() const
45   {
46     return myContainer;
47   }
48
49   /// Returns list of widget controls
50   /// \return a control list
51   virtual QList<QWidget*> getControls() const;
52
53   void setActivationOnStart(bool toActivate)
54   {
55     myActivateOnStart = toActivate;
56   }
57   bool activateOnStart() const
58   {
59     return myActivateOnStart;
60   }
61
62   ObjectPtr selectedFeature() const
63   {
64     return mySelectedObject;
65   }
66
67  public slots:
68
69   /// Activate or deactivate selection
70   void activateSelection(bool toActivate);
71
72  protected:
73   bool eventFilter(QObject* theObj, QEvent* theEvent);
74
75  private slots:
76   void onSelectionChanged();
77
78  private:
79   void enableOthersControls(bool toEnable) const;
80   void updateSelectionName();
81   void raisePanel() const;
82   bool isAccepted(const ObjectPtr theObject) const;
83
84   static TopAbs_ShapeEnum shapeType(const QString& theType);
85
86   QWidget* myContainer;
87   QLabel* myLabel;
88   QLineEdit* myTextLine;
89   QToolButton* myActivateBtn;
90
91   ModuleBase_IWorkshop* myWorkshop;
92
93   bool myActivateOnStart;
94
95   ObjectPtr mySelectedObject;
96   QStringList myShapeTypes;
97
98   QPalette myBasePalet;
99   QPalette myInactivePalet;
100 };
101
102 #endif