Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / SUIT / SUIT_PreferenceMgr.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File:      SUIT_PreferenceMgr.cxx
23 // Author:    Sergey TELKOV
24 //
25 #include "SUIT_PreferenceMgr.h"
26
27 SUIT_PreferenceMgr::SUIT_PreferenceMgr( QtxResourceMgr* resMgr, QWidget* parent )
28 : QtxPagePrefMgr( resMgr, parent ),
29 myRoot( 0 )
30 {
31 }
32
33 SUIT_PreferenceMgr::~SUIT_PreferenceMgr()
34 {
35 }
36
37 QIcon SUIT_PreferenceMgr::itemIcon( const int id ) const
38 {
39   const QtxPreferenceItem* item = 0;
40   if ( id == -1 )
41     item = this;
42   else
43     item = findItem( id, true );
44   return item ? item->icon() : QIcon();
45 }
46
47 void SUIT_PreferenceMgr::setItemIcon( const int id, const QIcon& ico )
48 {
49   QtxPreferenceItem* item = id == -1 ? this : findItem( id, true );
50   if ( item )
51     item->setIcon( ico );
52 }
53
54 QVariant SUIT_PreferenceMgr::itemProperty( const QString& prop, const int id ) const
55 {
56   const QtxPreferenceItem* item = 0;
57   if ( id == -1 )
58     item = this;
59   else
60     item = findItem( id, true );
61   return item ? item->option( prop ) : QVariant();
62 }
63
64 void SUIT_PreferenceMgr::setItemProperty( const QString& prop, const QVariant& val, const int id )
65 {
66   QtxPreferenceItem* item = id == -1 ? this : findItem( id, true );
67   if ( item )
68     item->setOption( prop, val );
69 }
70
71 int SUIT_PreferenceMgr::addItem( const QString& title, const int pId,
72                                  const SUIT_PreferenceMgr::PrefItemType type,
73                                  const QString& sect, const QString& param )
74 {
75   QtxPreferenceItem* parent = pId == -1 ? this : findItem( pId, true );
76
77   if ( !parent )
78     return -1;
79
80   QtxPreferenceItem* item = parent->findItem( title, true );
81
82   if ( item && item->depth() < 5 )
83     return item->id();
84
85   if ( pId == -1 )
86   {
87     if ( !myRoot )
88       myRoot = new QtxPagePrefListItem( QString( "root" ), this );
89     parent = myRoot;
90   }
91
92   switch( type )
93   {
94   case Auto:
95     switch ( parent->depth() )
96     {
97     case 1:
98       item = new QtxPagePrefTabsItem( title, parent, sect, param );
99       break;
100     case 2:
101       item = new QtxPagePrefFrameItem( title, parent, sect, param );
102       break;
103     case 3:
104       item = new QtxPagePrefGroupItem( title, parent, sect, param );
105       break;
106     }
107     break;
108   case Space:
109     item = new QtxPagePrefSpaceItem( parent );
110     break;
111   case Bool:
112     item = new QtxPagePrefCheckItem( title, parent, sect, param );
113     break;
114   case Color:
115     item = new QtxPagePrefColorItem( title, parent, sect, param );
116     break;
117   case String:
118     item = new QtxPagePrefEditItem( QtxPagePrefEditItem::String, title, parent, sect, param );
119     break;
120   case Selector:
121     item = new QtxPagePrefSelectItem( title, parent, sect, param );
122     break;
123   case DblSpin:
124     item = new QtxPagePrefSpinItem( QtxPagePrefSpinItem::Double, title, parent, sect, param );
125     break;
126   case IntSpin:
127     item = new QtxPagePrefSpinItem( QtxPagePrefSpinItem::Integer, title, parent, sect, param );
128     break;
129   case Double:
130     item = new QtxPagePrefEditItem( QtxPagePrefEditItem::Double, title, parent, sect, param );
131     break;
132   case Integer:
133     item = new QtxPagePrefEditItem( QtxPagePrefEditItem::Integer, title, parent, sect, param );
134     break;
135   case GroupBox:
136     item = new QtxPagePrefGroupItem( title, parent, sect, param );
137     break;
138   case Tab:
139     item = new QtxPagePrefTabsItem( title, parent, sect, param );
140     break;
141   case Frame:
142     item = new QtxPagePrefFrameItem( title, parent, sect, param );
143     break;
144   case Font:
145     item = new QtxPagePrefFontItem( title, parent, sect, param );
146     break;
147   case File:
148     item = new QtxPagePrefPathItem( Qtx::PT_OpenFile, title, parent, sect, param );
149     break;
150   case DirList:
151     item = new QtxPagePrefPathListItem( Qtx::PT_Directory, title, parent, sect, param );
152     break;
153   }
154
155   return item ? item->id() : -1;
156 }
157
158 QVariant SUIT_PreferenceMgr::optionValue( const QString& name ) const
159 {
160   QVariant val = QtxPagePrefMgr::optionValue( name );
161   if ( !val.isValid() && myRoot )
162     val = myRoot->option( name );
163   return val;
164 }
165
166 void SUIT_PreferenceMgr::setOptionValue( const QString& name, const QVariant& val )
167 {
168   QtxPagePrefMgr::setOptionValue( name, val );
169   if ( myRoot )
170     myRoot->setOption( name, val );
171 }