Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / XGUI / XGUI_Preferences.h
1 // File:        XGUI_Preferences.h
2 // Created:     07 Aug 2014
3 // Author:      Vitaly SMETANNIKOV
4
5 #ifndef XGUI_Preferences_H
6 #define XGUI_Preferences_H
7
8 #include "XGUI.h"
9 #include "XGUI_IPrefMgr.h"
10
11 #include <SUIT_PreferenceMgr.h>
12 #include <QDialog>
13
14 class SUIT_ResourceMgr;
15 class QWidget;
16
17 // Pair of values: section name, value name
18 typedef QPair<QString, QString> XGUI_Pref;
19 typedef QList<XGUI_Pref> XGUI_Prefs;
20
21 //***********************************************************************
22 /// Class for manipulation  with preferences in the application
23 class XGUI_EXPORT XGUI_Preferences
24 {
25  public:
26   static const QString VIEWER_SECTION;
27   static const QString MENU_SECTION;
28
29   static bool editPreferences(XGUI_Prefs& theModified);
30
31   /// Returns currently installed resource manager
32   static SUIT_ResourceMgr* resourceMgr();
33
34   /// Sets a resource manager
35   /// It is used in case of necessity to define external resource manager (not NewGeom)
36   static void setResourceMgr(SUIT_ResourceMgr* theMgr) { myResourceMgr = theMgr; }
37
38   /// Updates Config_PropManager properties by module from SUIT_ResourceMgr
39   static void updateConfigByResources();
40
41   /// Updates SUIT_ResourceMgr values by Config_PropManager properties
42   /// \param theUpdateOnlyInvalid flag to update only invalid values, if it is false, all are updated
43   static void updateResourcesByConfig();
44
45   /// Set default values to the Config_PropManager properties
46   static void resetConfig();
47
48   /// Loads properties defined by module to Config_PropManager
49   static void loadCustomProps();
50
51   /// 
52   static void createEditContent(XGUI_IPrefMgr* thePref, int thePage);
53
54 private:
55   /// Creates content of preferences editing widget
56   static void createCustomPage(XGUI_IPrefMgr* thePref, int thePageId);
57
58   static SUIT_ResourceMgr* myResourceMgr;
59 };
60
61 //***********************************************************************
62 /// Manager of preferences
63 class XGUI_EXPORT XGUI_PreferencesMgr : public SUIT_PreferenceMgr
64 {
65 Q_OBJECT
66  public:
67   XGUI_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent)
68       : SUIT_PreferenceMgr(theResource, theParent)
69   {
70   }
71
72   virtual ~XGUI_PreferencesMgr()
73   {
74   }
75
76   XGUI_Prefs modified() const
77   {
78     return myModified;
79   }
80
81  protected:
82   virtual void changedResources(const ResourceMap& theMap);
83
84  private:
85   XGUI_Prefs myModified;
86 };
87
88 //***********************************************************************
89 /// Dialog box for preferences editing
90 class XGUI_EXPORT XGUI_PreferencesDlg : public QDialog
91 {
92 Q_OBJECT
93  public:
94   XGUI_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0);
95   virtual ~XGUI_PreferencesDlg();
96
97   bool isChanged() const
98   {
99     return myIsChanged;
100   }
101
102   void modified(XGUI_Prefs& theModified) const;
103
104  public slots:
105   virtual void accept();
106
107 protected slots:
108   void onDefault();
109
110  private:
111    /// Create editors for aplication properties
112    void createEditors();
113
114    /// Create a viewer page in dialog box
115    void createViewerPage(int thePageId);
116    
117    /// Create menu properties page in the dialog box
118    void createMenuPage(int thePageId);
119
120   XGUI_PreferencesMgr* myPreferences;
121   bool myIsChanged;
122 };
123
124 #endif