1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: SUIT_PreferenceMgr.cxx
21 // Author: Sergey TELKOV
23 #include "SUIT_PreferenceMgr.h"
24 #include "SUIT_PagePrefShortcutTreeItem.h"
26 SUIT_PreferenceMgr::SUIT_PreferenceMgr( QtxResourceMgr* resMgr, QWidget* parent )
27 : QtxPagePrefMgr( resMgr, parent ),
32 SUIT_PreferenceMgr::~SUIT_PreferenceMgr()
36 QIcon SUIT_PreferenceMgr::itemIcon( const int id ) const
38 const QtxPreferenceItem* item = 0;
42 item = findItem( id, true );
43 return item ? item->icon() : QIcon();
46 void SUIT_PreferenceMgr::setItemIcon( const int id, const QIcon& ico )
48 QtxPreferenceItem* item = id == -1 ? this : findItem( id, true );
53 QVariant SUIT_PreferenceMgr::itemProperty( const QString& prop, const int id ) const
55 const QtxPreferenceItem* item = 0;
59 item = findItem( id, true );
60 return item ? item->option( prop ) : QVariant();
63 void SUIT_PreferenceMgr::setItemProperty( const QString& prop, const QVariant& val, const int id )
65 QtxPreferenceItem* item = id == -1 ? this : findItem( id, true );
67 item->setOption( prop, val );
70 int SUIT_PreferenceMgr::addItem( const QString& title, const int pId,
71 const SUIT_PreferenceMgr::PrefItemType type,
72 const QString& sect, const QString& param )
74 QtxPreferenceItem* parent = 0;
78 myRoot = new QtxPagePrefListItem( QString( "root" ), this );
83 parent = findItem( pId, true );
89 QtxPreferenceItem* item = parent->findItem( title, false );
91 if ( item && item->depth() < 5 )
97 switch ( parent->depth() )
100 item = new QtxPagePrefTabsItem( title, parent, sect, param );
103 item = new QtxPagePrefFrameItem( title, parent, sect, param, true );
106 item = new QtxPagePrefGroupItem( title, parent, sect, param );
111 item = new QtxPagePrefSpaceItem( parent );
114 item = new QtxPagePrefCheckItem( title, parent, sect, param );
117 item = new QtxPagePrefColorItem( title, parent, sect, param );
120 item = new QtxPagePrefEditItem( QtxPagePrefEditItem::String, title, parent, sect, param );
123 item = new QtxPagePrefSelectItem( title, parent, sect, param );
126 item = new QtxPagePrefSpinItem( QtxPagePrefSpinItem::Double, title, parent, sect, param );
129 item = new QtxPagePrefSpinItem( QtxPagePrefSpinItem::Integer, title, parent, sect, param );
132 item = new QtxPagePrefEditItem( QtxPagePrefEditItem::Double, title, parent, sect, param );
135 item = new QtxPagePrefEditItem( QtxPagePrefEditItem::Integer, title, parent, sect, param );
138 item = new QtxPagePrefSliderItem( title, parent, sect, param );
141 item = new QtxPagePrefGroupItem( title, parent, sect, param );
144 item = new QtxPagePrefTabsItem( title, parent, sect, param );
147 item = new QtxPagePrefFrameItem( title, parent, sect, param );
150 item = new QtxPagePrefFontItem( title, parent, sect, param );
153 item = new QtxPagePrefPathItem( Qtx::PT_OpenFile, title, parent, sect, param );
156 item = new QtxPagePrefPathItem( Qtx::PT_Directory, title, parent, sect, param );
159 item = new QtxPagePrefPathListItem( Qtx::PT_Directory, title, parent, sect, param );
162 item = new SUIT_PagePrefShortcutTreeItem( parent );
165 item = new QtxPagePrefBiColorItem( title, parent, sect, param );
168 item = new QtxPagePrefBackgroundItem( title, parent, sect, param );
171 item = new QtxUserDefinedItem(parent);
175 return item ? item->id() : -1;
178 void SUIT_PreferenceMgr::removeItem( const QString& title )
182 QtxPreferenceItem* item = myRoot->findItem( title, false );
184 QtxPagePrefMgr::removeItem( item );
190 QVariant SUIT_PreferenceMgr::optionValue( const QString& name ) const
192 QVariant val = QtxPagePrefMgr::optionValue( name );
193 if ( !val.isValid() && myRoot )
194 val = myRoot->option( name );
198 void SUIT_PreferenceMgr::setOptionValue( const QString& name, const QVariant& val )
200 QtxPagePrefMgr::setOptionValue( name, val );
202 myRoot->setOption( name, val );
205 QtxPreferenceItem* SUIT_PreferenceMgr::root() const