Back to index

salome-gui  6.5.0
SUIT_PreferenceMgr.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // File:      SUIT_PreferenceMgr.cxx
00021 // Author:    Sergey TELKOV
00022 //
00023 #include "SUIT_PreferenceMgr.h"
00024 
00025 SUIT_PreferenceMgr::SUIT_PreferenceMgr( QtxResourceMgr* resMgr, QWidget* parent )
00026 : QtxPagePrefMgr( resMgr, parent ),
00027 myRoot( 0 )
00028 {
00029 }
00030 
00031 SUIT_PreferenceMgr::~SUIT_PreferenceMgr()
00032 {
00033 }
00034 
00035 QIcon SUIT_PreferenceMgr::itemIcon( const int id ) const
00036 {
00037   const QtxPreferenceItem* item = 0;
00038   if ( id == -1 )
00039     item = this;
00040   else
00041     item = findItem( id, true );
00042   return item ? item->icon() : QIcon();
00043 }
00044 
00045 void SUIT_PreferenceMgr::setItemIcon( const int id, const QIcon& ico )
00046 {
00047   QtxPreferenceItem* item = id == -1 ? this : findItem( id, true );
00048   if ( item )
00049     item->setIcon( ico );
00050 }
00051 
00052 QVariant SUIT_PreferenceMgr::itemProperty( const QString& prop, const int id ) const
00053 {
00054   const QtxPreferenceItem* item = 0;
00055   if ( id == -1 )
00056     item = this;
00057   else
00058     item = findItem( id, true );
00059   return item ? item->option( prop ) : QVariant();
00060 }
00061 
00062 void SUIT_PreferenceMgr::setItemProperty( const QString& prop, const QVariant& val, const int id )
00063 {
00064   QtxPreferenceItem* item = id == -1 ? this : findItem( id, true );
00065   if ( item )
00066     item->setOption( prop, val );
00067 }
00068 
00069 int SUIT_PreferenceMgr::addItem( const QString& title, const int pId,
00070                                  const SUIT_PreferenceMgr::PrefItemType type,
00071                                  const QString& sect, const QString& param )
00072 {
00073   QtxPreferenceItem* parent = pId == -1 ? this : findItem( pId, true );
00074 
00075   if ( !parent )
00076     return -1;
00077 
00078   QtxPreferenceItem* item = parent->findItem( title, true );
00079 
00080   if ( item && item->depth() < 5 )
00081     return item->id();
00082 
00083   if ( pId == -1 )
00084   {
00085     if ( !myRoot )
00086       myRoot = new QtxPagePrefListItem( QString( "root" ), this );
00087     parent = myRoot;
00088   }
00089 
00090   switch( type )
00091   {
00092   case Auto:
00093     switch ( parent->depth() )
00094     {
00095     case 1:
00096       item = new QtxPagePrefTabsItem( title, parent, sect, param );
00097       break;
00098     case 2:
00099       item = new QtxPagePrefFrameItem( title, parent, sect, param );
00100       break;
00101     case 3:
00102       item = new QtxPagePrefGroupItem( title, parent, sect, param );
00103       break;
00104     }
00105     break;
00106   case Space:
00107     item = new QtxPagePrefSpaceItem( parent );
00108     break;
00109   case Bool:
00110     item = new QtxPagePrefCheckItem( title, parent, sect, param );
00111     break;
00112   case Color:
00113     item = new QtxPagePrefColorItem( title, parent, sect, param );
00114     break;
00115   case String:
00116     item = new QtxPagePrefEditItem( QtxPagePrefEditItem::String, title, parent, sect, param );
00117     break;
00118   case Selector:
00119     item = new QtxPagePrefSelectItem( title, parent, sect, param );
00120     break;
00121   case DblSpin:
00122     item = new QtxPagePrefSpinItem( QtxPagePrefSpinItem::Double, title, parent, sect, param );
00123     break;
00124   case IntSpin:
00125     item = new QtxPagePrefSpinItem( QtxPagePrefSpinItem::Integer, title, parent, sect, param );
00126     break;
00127   case Double:
00128     item = new QtxPagePrefEditItem( QtxPagePrefEditItem::Double, title, parent, sect, param );
00129     break;
00130   case Integer:
00131     item = new QtxPagePrefEditItem( QtxPagePrefEditItem::Integer, title, parent, sect, param );
00132     break;
00133   case Slider:
00134     item = new QtxPagePrefSliderItem( title, parent, sect, param );
00135     break;
00136   case GroupBox:
00137     item = new QtxPagePrefGroupItem( title, parent, sect, param );
00138     break;
00139   case Tab:
00140     item = new QtxPagePrefTabsItem( title, parent, sect, param );
00141     break;
00142   case Frame:
00143     item = new QtxPagePrefFrameItem( title, parent, sect, param );
00144     break;
00145   case Font:
00146     item = new QtxPagePrefFontItem( title, parent, sect, param );
00147     break;
00148   case File:
00149     item = new QtxPagePrefPathItem( Qtx::PT_OpenFile, title, parent, sect, param );
00150     break;
00151   case DirList:
00152     item = new QtxPagePrefPathListItem( Qtx::PT_Directory, title, parent, sect, param );
00153     break;
00154   case Shortcut:
00155     item = new QtxPagePrefShortcutBtnsItem( title, parent, sect, param );
00156     break;
00157   case ShortcutTree:
00158     item = new QtxPagePrefShortcutTreeItem( title, parent, sect, param );
00159     break;
00160   case BiColor:
00161     item = new QtxPagePrefBiColorItem( title, parent, sect, param );
00162     break;
00163   case Background:
00164     item = new QtxPagePrefBackgroundItem( title, parent, sect, param );
00165     break;
00166   case UserDefined:
00167     item = new QtxUserDefinedItem(parent);
00168     break;
00169   }
00170 
00171   return item ? item->id() : -1;
00172 }
00173 
00174 QVariant SUIT_PreferenceMgr::optionValue( const QString& name ) const
00175 {
00176   QVariant val = QtxPagePrefMgr::optionValue( name );
00177   if ( !val.isValid() && myRoot )
00178     val = myRoot->option( name );
00179   return val;
00180 }
00181 
00182 void SUIT_PreferenceMgr::setOptionValue( const QString& name, const QVariant& val )
00183 {
00184   QtxPagePrefMgr::setOptionValue( name, val );
00185   if ( myRoot )
00186     myRoot->setOption( name, val );
00187 }