Salome HOME
Second integration of PV3D viewer:
[modules/gui.git] / src / SUIT / SUIT_PreferenceMgr.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
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 // File:      SUIT_PreferenceMgr.cxx
21 // Author:    Sergey TELKOV
22 //
23 #include "SUIT_PreferenceMgr.h"
24 #include "SUIT_PagePrefShortcutTreeItem.h"
25
26 SUIT_PreferenceMgr::SUIT_PreferenceMgr( QtxResourceMgr* resMgr, QWidget* parent )
27 : QtxPagePrefMgr( resMgr, parent ),
28 myRoot( 0 )
29 {
30 }
31
32 SUIT_PreferenceMgr::~SUIT_PreferenceMgr()
33 {
34 }
35
36 QIcon SUIT_PreferenceMgr::itemIcon( const int id ) const
37 {
38   const QtxPreferenceItem* item = 0;
39   if ( id == -1 )
40     item = this;
41   else
42     item = findItem( id, true );
43   return item ? item->icon() : QIcon();
44 }
45
46 void SUIT_PreferenceMgr::setItemIcon( const int id, const QIcon& ico )
47 {
48   QtxPreferenceItem* item = id == -1 ? this : findItem( id, true );
49   if ( item )
50     item->setIcon( ico );
51 }
52
53 QVariant SUIT_PreferenceMgr::itemProperty( const QString& prop, const int id ) const
54 {
55   const QtxPreferenceItem* item = 0;
56   if ( id == -1 )
57     item = this;
58   else
59     item = findItem( id, true );
60   return item ? item->option( prop ) : QVariant();
61 }
62
63 void SUIT_PreferenceMgr::setItemProperty( const QString& prop, const QVariant& val, const int id )
64 {
65   QtxPreferenceItem* item = id == -1 ? this : findItem( id, true );
66   if ( item )
67     item->setOption( prop, val );
68 }
69
70 int SUIT_PreferenceMgr::addItem( const QString& title, const int pId,
71                                  const SUIT_PreferenceMgr::PrefItemType type,
72                                  const QString& sect, const QString& param )
73 {
74   QtxPreferenceItem* parent = 0;
75   if ( pId == -1 )
76   {
77     if ( !myRoot )
78       myRoot = new QtxPagePrefListItem( QString( "root" ), this );
79     parent = myRoot;
80   }
81   else
82   {
83     parent = findItem( pId, true );
84   }
85
86   if ( !parent )
87     return -1;
88
89   QtxPreferenceItem* item = parent->findItem( title, false );
90
91   if ( item && item->depth() < 5 )
92     return item->id();
93
94   switch( type )
95   {
96   case Auto:
97     switch ( parent->depth() )
98     {
99     case 1:
100       item = new QtxPagePrefTabsItem( title, parent, sect, param );
101       break;
102     case 2:
103       item = new QtxPagePrefFrameItem( title, parent, sect, param, true );
104       break;
105     case 3:
106       item = new QtxPagePrefGroupItem( title, parent, sect, param );
107       break;
108     }
109     break;
110   case Space:
111     item = new QtxPagePrefSpaceItem( parent );
112     break;
113   case Bool:
114     item = new QtxPagePrefCheckItem( title, parent, sect, param );
115     break;
116   case Color:
117     item = new QtxPagePrefColorItem( title, parent, sect, param );
118     break;
119   case String:
120     item = new QtxPagePrefEditItem( QtxPagePrefEditItem::String, title, parent, sect, param );
121     break;
122   case Selector:
123     item = new QtxPagePrefSelectItem( title, parent, sect, param );
124     break;
125   case DblSpin:
126     item = new QtxPagePrefSpinItem( QtxPagePrefSpinItem::Double, title, parent, sect, param );
127     break;
128   case IntSpin:
129     item = new QtxPagePrefSpinItem( QtxPagePrefSpinItem::Integer, title, parent, sect, param );
130     break;
131   case Double:
132     item = new QtxPagePrefEditItem( QtxPagePrefEditItem::Double, title, parent, sect, param );
133     break;
134   case Integer:
135     item = new QtxPagePrefEditItem( QtxPagePrefEditItem::Integer, title, parent, sect, param );
136     break;
137   case Slider:
138     item = new QtxPagePrefSliderItem( title, parent, sect, param );
139     break;
140   case GroupBox:
141     item = new QtxPagePrefGroupItem( title, parent, sect, param );
142     break;
143   case Tab:
144     item = new QtxPagePrefTabsItem( title, parent, sect, param );
145     break;
146   case Frame:
147     item = new QtxPagePrefFrameItem( title, parent, sect, param );
148     break;
149   case Font:
150     item = new QtxPagePrefFontItem( title, parent, sect, param );
151     break;
152   case File:
153     item = new QtxPagePrefPathItem( Qtx::PT_OpenFile, title, parent, sect, param );
154     break;
155   case Directory:
156     item = new QtxPagePrefPathItem( Qtx::PT_Directory, title, parent, sect, param );
157     break;
158   case DirList:
159     item = new QtxPagePrefPathListItem( Qtx::PT_Directory, title, parent, sect, param );
160     break;
161   case ShortcutTree:
162     item = new SUIT_PagePrefShortcutTreeItem( parent );
163     break;
164   case BiColor:
165     item = new QtxPagePrefBiColorItem( title, parent, sect, param );
166     break;
167   case Background:
168     item = new QtxPagePrefBackgroundItem( title, parent, sect, param );
169     break;
170   case UserDefined:
171     item = new QtxUserDefinedItem(parent);
172     break;
173   }
174
175   return item ? item->id() : -1;
176 }
177
178 void SUIT_PreferenceMgr::removeItem( const QString& title )
179 {
180   if ( myRoot )
181   {
182     QtxPreferenceItem* item = myRoot->findItem( title, false );
183     if ( item ) {
184       QtxPagePrefMgr::removeItem( item );
185       delete item;
186     }
187   }
188 }
189
190 QVariant SUIT_PreferenceMgr::optionValue( const QString& name ) const
191 {
192   QVariant val = QtxPagePrefMgr::optionValue( name );
193   if ( !val.isValid() && myRoot )
194     val = myRoot->option( name );
195   return val;
196 }
197
198 void SUIT_PreferenceMgr::setOptionValue( const QString& name, const QVariant& val )
199 {
200   QtxPagePrefMgr::setOptionValue( name, val );
201   if ( myRoot )
202     myRoot->setOption( name, val );
203 }
204
205 QtxPreferenceItem* SUIT_PreferenceMgr::root() const
206 {
207   return myRoot;
208 }