Salome HOME
aa79150bfa3152375b4e6aa08d1b40b871376fab
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetShapeSelector.h
1 // File:        ModuleBase_WidgetShapeSelector.h
2 // Created:     2 June 2014
3 // Author:      Vitaly Smetannikov
4
5 #ifndef ModuleBase_WidgetShapeSelector_H
6 #define ModuleBase_WidgetShapeSelector_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_WidgetShapeSelector : public ModuleBase_ModelWidget
26 {
27 Q_OBJECT
28  public:
29   static TopAbs_ShapeEnum shapeType(const QString& theType);
30
31   ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
32                             const Config_WidgetAPI* theData, const std::string& theParentId);
33
34   virtual ~ModuleBase_WidgetShapeSelector();
35
36   /// Saves the internal parameters to the given feature
37   /// \param theObject a model feature to be changed
38   virtual bool storeValue() const;
39
40   virtual bool restoreValue();
41
42   virtual bool focusTo();
43
44   /// Returns the internal parent wiget control, that can be shown anywhere
45   /// \returns the widget
46   QWidget* getControl() const
47   {
48     return myContainer;
49   }
50
51   /// Returns list of widget controls
52   /// \return a control list
53   virtual QList<QWidget*> getControls() const;
54
55   ObjectPtr selectedFeature() const
56   {
57     return mySelectedObject;
58   }
59
60   /// Set the given wrapped value to the current widget
61   /// This value should be processed in the widget according to the needs
62   /// \param theValue the wrapped widget value
63   virtual bool setValue(ModuleBase_WidgetValue* theValue);
64
65 public slots:
66
67   /// Activate or deactivate selection
68   void activateSelection(bool toActivate);
69
70 private slots:
71   void onSelectionChanged();
72
73 protected:
74   bool eventFilter(QObject* theObj, QEvent* theEvent);
75
76 private:
77   void updateSelectionName();
78   void raisePanel() const;
79   bool isAccepted(const ObjectPtr theObject) const;
80
81   // Set the given object as a value of the widget
82   void setObject(ObjectPtr theObj);
83
84   QWidget* myContainer;
85   QLabel* myLabel;
86   QLineEdit* myTextLine;
87   //QToolButton* myActivateBtn;
88
89   ModuleBase_IWorkshop* myWorkshop;
90
91   ObjectPtr mySelectedObject;
92   QStringList myShapeTypes;
93
94   /// If true then local selector has to be activated in context
95   bool myUseSubShapes;
96
97   QPalette myBasePalet;
98   QPalette myInactivePalet;
99
100   bool myIsActive;
101 };
102
103 #endif