Back to index

salome-gui  6.5.0
QtxPagePrefMgr.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:      QtxPagePrefMgr.cxx
00021 // Author:    Sergey TELKOV
00022 //
00023 #include "QtxPagePrefMgr.h"
00024 
00025 #include "QtxGridBox.h"
00026 #include "QtxFontEdit.h"
00027 #include "QtxGroupBox.h"
00028 #include "QtxComboBox.h"
00029 #include "QtxIntSpinBox.h"
00030 #include "QtxColorButton.h"
00031 #include "QtxBiColorTool.h"
00032 #include "QtxDoubleSpinBox.h"
00033 #include "QtxShortcutEdit.h"
00034 #include "QtxBackgroundTool.h"
00035 #include "QtxResourceMgr.h"
00036 
00037 #include <QEvent>
00038 #include <QLayout>
00039 #include <QToolBox>
00040 #include <QLineEdit>
00041 #include <QTextEdit>
00042 #include <QCheckBox>
00043 #include <QSplitter>
00044 #include <QTabWidget>
00045 #include <QListWidget>
00046 #include <QApplication>
00047 #include <QDateTimeEdit>
00048 #include <QStackedWidget>
00049 #include <QSlider>
00050 
00051 #include <stdio.h>
00052 
00063 QtxPagePrefMgr::QtxPagePrefMgr( QtxResourceMgr* resMgr, QWidget* parent )
00064 : QFrame( parent ),
00065   QtxPreferenceMgr( resMgr ),
00066   myInit( false )
00067 {
00068   myBox = new QtxGridBox( 1, Qt::Horizontal, this, 0 );
00069   QVBoxLayout* base = new QVBoxLayout( this );
00070   base->setMargin( 5 );
00071   base->setSpacing( 0 );
00072   base->addWidget( myBox );
00073 }
00074 
00078 QtxPagePrefMgr::~QtxPagePrefMgr()
00079 {
00080 }
00081 
00086 QSize QtxPagePrefMgr::sizeHint() const
00087 {
00088   return QFrame::sizeHint();
00089 }
00090 
00095 QSize QtxPagePrefMgr::minimumSizeHint() const
00096 {
00097   return QFrame::minimumSizeHint();
00098 }
00099 
00105 void QtxPagePrefMgr::setVisible( bool on )
00106 {
00107   if ( on )
00108     initialize();
00109 
00110   QApplication::instance()->processEvents();
00111 
00112   QFrame::setVisible( on );
00113 }
00114 
00118 void QtxPagePrefMgr::updateContents()
00119 {
00120   QtxPreferenceMgr::updateContents();
00121 
00122   QList<QtxPreferenceItem*> lst = childItems();
00123   for ( QList<QtxPreferenceItem*>::const_iterator it = lst.begin(); it != lst.end(); ++it )
00124   {
00125     QtxPagePrefItem* item = dynamic_cast<QtxPagePrefItem*>( *it );
00126     if ( item && item->widget() && item->widget()->parent() != myBox )
00127       item->widget()->setParent( myBox );
00128   }
00129 
00130   setWindowIcon( icon() );
00131 }
00132 
00139 void QtxPagePrefMgr::itemAdded( QtxPreferenceItem* /*item*/ )
00140 {
00141   triggerUpdate();
00142 }
00143 
00150 void QtxPagePrefMgr::itemRemoved( QtxPreferenceItem* /*item*/ )
00151 {
00152   triggerUpdate();
00153 }
00154 
00161 void QtxPagePrefMgr::itemChanged( QtxPreferenceItem* /*item*/ )
00162 {
00163   triggerUpdate();
00164 }
00165 
00172 QVariant QtxPagePrefMgr::optionValue( const QString& name ) const
00173 {
00174   if ( name == "orientation" )
00175     return myBox->orientation() == Qt::Horizontal ? Qt::Vertical : Qt::Horizontal;
00176   else
00177     return QtxPreferenceMgr::optionValue( name );
00178 }
00179 
00186 void QtxPagePrefMgr::setOptionValue( const QString& name, const QVariant& val )
00187 {
00188   if ( name == "orientation" )
00189   {
00190     if ( val.canConvert( QVariant::Int ) )
00191       myBox->setOrientation( val.toInt() == Qt::Horizontal ? Qt::Vertical : Qt::Horizontal );
00192   }
00193   else
00194     QtxPreferenceMgr::setOptionValue( name, val );
00195 }
00196 
00200 void QtxPagePrefMgr::initialize() const
00201 {
00202   //  if ( myInit )
00203   //    return;
00204 
00205   QtxPagePrefMgr* that = (QtxPagePrefMgr*)this;
00206   that->initialize( that );
00207 
00208   //  that->myInit = true;
00209 }
00210 
00211 void QtxPagePrefMgr::initialize( QtxPreferenceItem* item )
00212 {
00213   if ( !item )
00214     return;
00215 
00216   QList<QtxPreferenceItem*> lst = item->childItems( false );
00217   for ( QList<QtxPreferenceItem*>::iterator it = lst.begin(); it != lst.end(); ++it )
00218     initialize( *it );
00219 
00220   updateContents();
00221 }
00222 
00229 class QtxPagePrefItem::Listener : public QObject
00230 {
00231 public:
00232   Listener( QtxPagePrefItem* );
00233   virtual ~Listener();
00234 
00235   virtual bool eventFilter( QObject*, QEvent* );
00236 
00237 private:
00238   QtxPagePrefItem* myItem;
00239 };
00240 
00241 QtxPagePrefItem::Listener::Listener( QtxPagePrefItem* item )
00242 : QObject( 0 ),
00243   myItem( item )
00244 {
00245 }
00246 
00247 QtxPagePrefItem::Listener::~Listener()
00248 {
00249 }
00250 
00251 bool QtxPagePrefItem::Listener::eventFilter( QObject* o, QEvent* e )
00252 {
00253   if ( !myItem || myItem->widget() != o )
00254     return false;
00255 
00256   if ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent )
00257     myItem->widgetShown();
00258   if ( e->type() == QEvent::Hide || e->type() == QEvent::HideToParent )
00259     myItem->widgetHided();
00260 
00261   return false;
00262 }
00263 
00271 QtxPagePrefItem::QtxPagePrefItem( const QString& title, QtxPreferenceItem* parent,
00272                                   const QString& sect, const QString& param )
00273 : QtxPreferenceItem( title, sect, param, parent ),
00274   myWidget( 0 ),
00275   myListener( 0 )
00276 {
00277 }
00278 
00282 QtxPagePrefItem::~QtxPagePrefItem()
00283 {
00284   delete myWidget;
00285   delete myListener;
00286 }
00287 
00288 void QtxPagePrefItem::activate()
00289 {
00290   QtxPreferenceItem::activate();
00291 
00292   if ( widget() )
00293     widget()->setFocus();
00294 }
00295 
00301 QWidget* QtxPagePrefItem::widget() const
00302 {
00303   return myWidget;
00304 }
00305 
00311 void QtxPagePrefItem::setWidget( QWidget* wid )
00312 {
00313   if ( myWidget && myListener )
00314     myWidget->removeEventFilter( myListener );
00315 
00316   myWidget = wid;
00317 
00318   if ( myWidget )
00319   {
00320     if ( !myListener )
00321       myListener = new Listener( this );
00322     myWidget->installEventFilter( myListener );
00323   }
00324 
00325   sendItemChanges();
00326 }
00327 
00334 void QtxPagePrefItem::itemAdded( QtxPreferenceItem* /*item*/ )
00335 {
00336   contentChanged();
00337 }
00338 
00345 void QtxPagePrefItem::itemRemoved( QtxPreferenceItem* /*item*/ )
00346 {
00347   contentChanged();
00348 }
00349 
00356 void QtxPagePrefItem::itemChanged( QtxPreferenceItem* /*item*/ )
00357 {
00358   contentChanged();
00359 }
00360 
00369 void QtxPagePrefItem::store()
00370 {
00371 }
00372 
00381 void QtxPagePrefItem::retrieve()
00382 {
00383 }
00384 
00388 void QtxPagePrefItem::widgetShown()
00389 {
00390 }
00391 
00395 void QtxPagePrefItem::widgetHided()
00396 {
00397 }
00398 
00399 void QtxPagePrefItem::ensureVisible( QtxPreferenceItem* i )
00400 {
00401   QtxPreferenceItem::ensureVisible();
00402 
00403   QtxPagePrefItem* item = dynamic_cast<QtxPagePrefItem*>( i );
00404   if ( item && item->widget() )
00405     item->widget()->setVisible( true );
00406 }
00407 
00413 void QtxPagePrefItem::pageChildItems( QList<QtxPagePrefItem*>& list, const bool rec ) const
00414 {
00415   QList<QtxPreferenceItem*> lst = childItems( rec );
00416   for ( QList<QtxPreferenceItem*>::const_iterator it = lst.begin(); it != lst.end(); ++it )
00417   {
00418     QtxPagePrefItem* item = dynamic_cast<QtxPagePrefItem*>( *it );
00419     if ( item )
00420       list.append( item );
00421   }
00422 }
00423 
00429 void QtxPagePrefItem::contentChanged()
00430 {
00431   triggerUpdate();
00432 }
00433 
00447 QtxPageNamedPrefItem::QtxPageNamedPrefItem( const QString& title, QtxPreferenceItem* parent,
00448                                             const QString& sect, const QString& param )
00449 : QtxPagePrefItem( title, parent, sect, param ),
00450   myControl( 0 )
00451 {
00452   QWidget* main = new QWidget();
00453 
00454   //  QtxPagePrefGroupItem* aGroup = 0;//dynamic_cast<QtxPagePrefGroupItem*>(parent);
00455   //  if ( !aGroup )
00456   //  {
00457     QHBoxLayout* base = new QHBoxLayout( main );
00458     base->setMargin( 0 );
00459     base->setSpacing( 5 );
00460 
00461     myLabel = new QLabel( title, main );
00462     base->addWidget( myLabel );
00463     //  }
00464     //  else
00465     //    myLabel = new QLabel( title, aGroup->gridBox() );
00466 
00467   setWidget( main );
00468 
00469   myLabel->setVisible( !title.isEmpty() );
00470 }
00471 
00475 QtxPageNamedPrefItem::~QtxPageNamedPrefItem()
00476 {
00477 }
00478 
00483 void QtxPageNamedPrefItem::setTitle( const QString& txt )
00484 {
00485   QtxPagePrefItem::setTitle( txt );
00486 
00487   label()->setText( title() );
00488   if ( !title().isEmpty() )
00489     label()->setVisible( true );
00490 }
00491 
00496 QLabel* QtxPageNamedPrefItem::label() const
00497 {
00498   return myLabel;
00499 }
00500 
00506 QWidget* QtxPageNamedPrefItem::control() const
00507 {
00508   return myControl;
00509 }
00510 
00516 void QtxPageNamedPrefItem::setControl( QWidget* wid )
00517 {
00518   if ( myControl == wid )
00519     return;
00520 
00521   delete myControl;
00522   myControl = wid;
00523 
00524   if ( myControl )
00525   {
00526     //    QtxPagePrefGroupItem* aGroup = 0;//dynamic_cast<QtxPagePrefGroupItem*>(parentItem());
00527     //    if ( !aGroup )
00528     widget()->layout()->addWidget( myControl );
00529     widget()->setFocusProxy( myControl );
00530       //    else myControl->setParent( aGroup->gridBox() );
00531   }
00532 }
00533 
00534 void QtxPageNamedPrefItem::adjustLabels( QtxPagePrefItem* parent )
00535 {
00536   if ( !parent )
00537     return;
00538 
00539   QList<QtxPreferenceItem*> childList = parent->childItems();
00540 
00541   QList<QtxPageNamedPrefItem*> namedItems;
00542   for ( QList<QtxPreferenceItem*>::iterator it = childList.begin(); it != childList.end(); ++it )
00543   {
00544     QtxPageNamedPrefItem* item = dynamic_cast<QtxPageNamedPrefItem*>( *it );
00545     if ( item )
00546       namedItems.append( item );
00547   }
00548 
00549   int sz = 0;
00550   for ( QList<QtxPageNamedPrefItem*>::iterator it1 = namedItems.begin(); it1 != namedItems.end(); ++it1 )
00551   {
00552     QtxPageNamedPrefItem* item = *it1;
00553     if ( item->label() )
00554       sz = qMax( sz, item->label()->sizeHint().width() );
00555   }
00556 
00557   for ( QList<QtxPageNamedPrefItem*>::iterator it2 = namedItems.begin(); it2 != namedItems.end(); ++it2 )
00558   {
00559     QtxPageNamedPrefItem* item = *it2;
00560     if ( item->label() )
00561       item->label()->setMinimumWidth( sz );
00562   }
00563 }
00564 
00577 QtxPagePrefListItem::QtxPagePrefListItem( const QString& title, QtxPreferenceItem* parent,
00578                                           const QString& sect, const QString& param )
00579 : QtxPagePrefItem( title, parent, sect, param ),
00580   myFix( false )
00581 {
00582   QSplitter* main = new QSplitter( Qt::Horizontal );
00583   main->setChildrenCollapsible( false );
00584 
00585   main->addWidget( myList = new QListWidget( main ) );
00586   main->addWidget( myStack = new QStackedWidget( main ) );
00587 
00588   myList->setSelectionMode( QListWidget::SingleSelection );
00589 
00590   myStack->addWidget( myInfLabel = new QLabel( myStack ) );
00591   myInfLabel->setAlignment( Qt::AlignCenter );
00592 
00593   connect( myList, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) );
00594 
00595   setWidget( main );
00596 }
00597 
00601 QtxPagePrefListItem::~QtxPagePrefListItem()
00602 {
00603 }
00604 
00610 QString QtxPagePrefListItem::emptyInfo() const
00611 {
00612   return myInfText;
00613 }
00614 
00620 void QtxPagePrefListItem::setEmptyInfo( const QString& inf )
00621 {
00622   if ( myInfText == inf )
00623     return;
00624 
00625   myInfText = inf;
00626 
00627   updateVisible();
00628 }
00629 
00635 bool QtxPagePrefListItem::isFixedSize() const
00636 {
00637   return myFix;
00638 }
00639 
00645 void QtxPagePrefListItem::setFixedSize( const bool on )
00646 {
00647   if ( myFix == on )
00648     return;
00649 
00650   myFix = on;
00651 
00652   updateGeom();
00653 }
00654 
00658 void QtxPagePrefListItem::updateContents()
00659 {
00660   QtxPagePrefItem::updateContents();
00661   updateVisible();
00662 }
00663 
00670 QVariant QtxPagePrefListItem::optionValue( const QString& name ) const
00671 {
00672   if ( name == "fixed_size" )
00673     return isFixedSize();
00674   else if ( name == "empty_info" || name == "info" )
00675     return emptyInfo();
00676   else
00677     return QtxPagePrefItem::optionValue( name );
00678 }
00679 
00686 void QtxPagePrefListItem::setOptionValue( const QString& name, const QVariant& val )
00687 {
00688   if ( name == "fixed_size" )
00689   {
00690     if ( val.canConvert( QVariant::Bool ) )
00691       setFixedSize( val.toBool() );
00692   }
00693   else if ( name == "empty_info" || name == "info" )
00694   {
00695     if ( val.canConvert( QVariant::String ) )
00696       setEmptyInfo( val.toString() );
00697   }
00698   else
00699     QtxPagePrefItem::setOptionValue( name, val );
00700 }
00701 
00702 void QtxPagePrefListItem::widgetShown()
00703 {
00704   updateState();
00705 }
00706 
00707 void QtxPagePrefListItem::ensureVisible( QtxPreferenceItem* i )
00708 {
00709   if ( !i )
00710     return;
00711 
00712   QtxPreferenceItem::ensureVisible( i );
00713 
00714   setSelected( i->id() );
00715   updateState();
00716 }
00717 
00721 void QtxPagePrefListItem::onItemSelectionChanged()
00722 {
00723   updateState();
00724 }
00725 
00729 void QtxPagePrefListItem::updateInfo()
00730 {
00731   QString infoText;
00732   QtxPagePrefItem* item = selectedItem();
00733   if ( item )
00734   {
00735     infoText = emptyInfo();
00736     QRegExp rx( "%([%|N])" );
00737 
00738     int idx = 0;
00739     while ( ( idx = rx.indexIn( infoText ) ) != -1 )
00740     {
00741       if ( rx.cap() == QString( "%%" ) )
00742         infoText.replace( idx, rx.matchedLength(), "%" );
00743       else if ( rx.cap() == QString( "%N" ) )
00744         infoText.replace( idx, rx.matchedLength(), item->title() );
00745     }
00746   }
00747   myInfLabel->setText( infoText );
00748 }
00749 
00753 void QtxPagePrefListItem::updateState()
00754 {
00755   QtxPagePrefItem* item = selectedItem();
00756   QWidget* wid = item && !item->isEmpty() ? item->widget() : myInfLabel;
00757   if ( wid )
00758     myStack->setCurrentWidget( wid );
00759 
00760   updateInfo();
00761 }
00762 
00766 void QtxPagePrefListItem::updateVisible()
00767 {
00768   QList<QtxPagePrefItem*> items;
00769   pageChildItems( items );
00770 
00771   QMap<QWidget*, int> map;
00772   for ( int i = 0; i < (int)myStack->count(); i++ )
00773     map.insert( myStack->widget( i ), 0 );
00774 
00775   int selId = selected();
00776   myList->clear();
00777   for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end(); ++it )
00778   {
00779     if ( (*it)->isEmpty() && myInfText.isEmpty() )
00780       continue;
00781 
00782     myList->addItem( (*it)->title() );
00783     myList->item( myList->count() - 1 )->setIcon( (*it)->icon() );
00784     myList->item( myList->count() - 1 )->setData( Qt::UserRole, (*it)->id() );
00785 
00786     QWidget* wid = (*it)->widget();
00787     if ( !map.contains( wid ) )
00788       myStack->addWidget( wid );
00789 
00790     map.remove( wid );
00791   }
00792 
00793   map.remove( myInfLabel );
00794 
00795   for ( QMap<QWidget*, int>::const_iterator it = map.begin(); it != map.end(); ++it )
00796     myStack->removeWidget( it.key() );
00797 
00798   setSelected( selId );
00799   if ( selected() == -1 && myList->count() )
00800     setSelected( myList->item( 0 )->data( Qt::UserRole ).toInt() );
00801 
00802   //myList->setVisible( myList->count() > 1 );
00803 
00804   updateState();
00805   updateGeom();
00806 }
00807 
00811 void QtxPagePrefListItem::updateGeom()
00812 {
00813   if ( myFix )
00814     myList->setFixedWidth( myList->minimumSizeHint().width() + 10 );
00815   else
00816   {
00817     myList->setMinimumWidth( 0 );
00818     myList->setMaximumWidth( 16777215 );
00819 
00820     QSplitter* s = ::qobject_cast<QSplitter*>( widget() );
00821     if ( s )
00822     {
00823       int w = myList->minimumSizeHint().width() + 30;
00824       QList<int> szList;
00825       szList.append( w );
00826       szList.append( s->width() - w );
00827       s->setSizes( szList );
00828     }
00829   }
00830 }
00831 
00837 int QtxPagePrefListItem::selected() const
00838 {
00839   QList<QListWidgetItem*> selList = myList->selectedItems();
00840   if ( selList.isEmpty() )
00841     return -1;
00842 
00843   QVariant v = selList.first()->data( Qt::UserRole );
00844   return v.canConvert( QVariant::Int ) ? v.toInt() : -1;
00845 }
00846 
00852 QtxPagePrefItem* QtxPagePrefListItem::selectedItem() const
00853 {
00854   int selId = selected();
00855 
00856   QList<QtxPagePrefItem*> items;
00857   pageChildItems( items );
00858 
00859   QtxPagePrefItem* item = 0;
00860   for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end() && !item; ++it )
00861   {
00862     if ( (*it)->id() == selId )
00863       item = *it;
00864   }
00865   return item;
00866 }
00867 
00872 void QtxPagePrefListItem::setSelected( const int id )
00873 {
00874   int idx = -1;
00875   for ( int i = 0; i < (int)myList->count() && idx < 0; i++ )
00876   {
00877     QVariant v = myList->item( i )->data( Qt::UserRole );
00878     if ( v.canConvert( QVariant::Int ) && v.toInt() == id )
00879       idx = i;
00880   }
00881 
00882   QItemSelection sel;
00883   QItemSelectionModel* selModel = myList->selectionModel();
00884 
00885   if ( idx >= 0 )
00886     sel.select( myList->model()->index( idx, 0 ), myList->model()->index( idx, 0 ) );
00887 
00888   selModel->select( sel, QItemSelectionModel::ClearAndSelect );
00889 }
00890 
00903 QtxPagePrefToolBoxItem::QtxPagePrefToolBoxItem( const QString& title, QtxPreferenceItem* parent,
00904                                                 const QString& sect, const QString& param )
00905 : QtxPagePrefItem( title, parent, sect, param )
00906 {
00907   setWidget( myToolBox = new QToolBox( 0 ) );
00908 }
00909 
00913 QtxPagePrefToolBoxItem::~QtxPagePrefToolBoxItem()
00914 {
00915 }
00916 
00920 void QtxPagePrefToolBoxItem::updateContents()
00921 {
00922   QtxPagePrefItem::updateContents();
00923   updateToolBox();
00924 }
00925 
00929 void QtxPagePrefToolBoxItem::updateToolBox()
00930 {
00931   QList<QtxPagePrefItem*> items;
00932   pageChildItems( items );
00933 
00934   QWidget* cur = myToolBox->currentWidget();
00935 
00936   int i = 0;
00937   QMap<QWidget*, int> map;
00938   for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end(); ++it )
00939   {
00940     QWidget* wid = (*it)->widget();
00941     if ( !wid )
00942       continue;
00943 
00944     if ( myToolBox->widget( i ) != wid )
00945     {
00946       if ( myToolBox->indexOf( wid ) != -1 )
00947         myToolBox->removeItem( myToolBox->indexOf( wid ) );
00948 
00949       myToolBox->insertItem( i, wid, (*it)->title() );
00950     }
00951     else
00952       myToolBox->setItemText( i, (*it)->title() );
00953 
00954     myToolBox->setItemIcon( i, (*it)->icon() );
00955 
00956     i++;
00957     map.insert( wid, 0 );
00958   }
00959 
00960   QList<QWidget*> del;
00961   for ( int idx = 0; idx < (int)myToolBox->count(); idx++ )
00962   {
00963     QWidget* w = myToolBox->widget( idx );
00964     if ( !map.contains( w ) )
00965       del.append( w );
00966   }
00967 
00968   for ( QList<QWidget*>::const_iterator itr = del.begin(); itr != del.end(); ++itr )
00969     myToolBox->removeItem( myToolBox->indexOf( *itr ) );
00970 
00971   if ( cur )
00972     myToolBox->setCurrentWidget( cur );
00973 }
00974 
00975 void QtxPagePrefToolBoxItem::ensureVisible( QtxPreferenceItem* i )
00976 {
00977   if ( !i )
00978     return;
00979 
00980   QtxPreferenceItem::ensureVisible( i );
00981 
00982   QtxPagePrefItem* item = dynamic_cast<QtxPagePrefItem*>( i );
00983   if ( item && item->widget() )
00984     myToolBox->setCurrentWidget( item->widget() );
00985 }
00986 
00999 QtxPagePrefTabsItem::QtxPagePrefTabsItem( const QString& title, QtxPreferenceItem* parent,
01000                                           const QString& sect, const QString& param )
01001 : QtxPagePrefItem( title, parent, sect, param )
01002 {
01003   setWidget( myTabs = new QTabWidget( 0 ) );
01004 }
01005 
01009 QtxPagePrefTabsItem::~QtxPagePrefTabsItem()
01010 {
01011 }
01012 
01016 void QtxPagePrefTabsItem::updateContents()
01017 {
01018   QtxPagePrefItem::updateContents();
01019   updateTabs();
01020 }
01021 
01027 int QtxPagePrefTabsItem::tabPosition() const
01028 {
01029   return myTabs->tabPosition();
01030 }
01031 
01037 void QtxPagePrefTabsItem::setTabPosition( const int tp )
01038 {
01039   myTabs->setTabPosition( (QTabWidget::TabPosition)tp );
01040 }
01041 
01047 int QtxPagePrefTabsItem::tabShape() const
01048 {
01049   return myTabs->tabShape();
01050 }
01051 
01057 void QtxPagePrefTabsItem::setTabShape( const int ts )
01058 {
01059   myTabs->setTabShape( (QTabWidget::TabShape)ts );
01060 }
01061 
01067 QSize QtxPagePrefTabsItem::tabIconSize() const
01068 {
01069   return myTabs->iconSize();
01070 }
01071 
01077 void QtxPagePrefTabsItem::setTabIconSize( const QSize& sz )
01078 {
01079   myTabs->setIconSize( sz );
01080 }
01081 
01088 QVariant QtxPagePrefTabsItem::optionValue( const QString& name ) const
01089 {
01090   if ( name == "position" )
01091     return tabPosition();
01092   else if ( name == "shape" )
01093     return tabShape();
01094   else if ( name == "icon_size" )
01095     return tabIconSize();
01096   else
01097     return QtxPagePrefItem::optionValue( name );
01098 }
01099 
01106 void QtxPagePrefTabsItem::setOptionValue( const QString& name, const QVariant& val )
01107 {
01108   if ( name == "position" )
01109   {
01110     if ( val.canConvert( QVariant::Int ) )
01111       setTabPosition( val.toInt() );
01112   }
01113   else if ( name == "shape" )
01114   {
01115     if ( val.canConvert( QVariant::Int ) )
01116       setTabShape( val.toInt() );
01117   }
01118   else if ( name == "icon_size" )
01119   {
01120     if ( val.canConvert( QVariant::Size ) )
01121       setTabIconSize( val.toSize() );
01122   }
01123   else
01124     QtxPagePrefItem::setOptionValue( name, val );
01125 }
01126 
01127 void QtxPagePrefTabsItem::ensureVisible( QtxPreferenceItem* i )
01128 {
01129   if ( !i )
01130     return;
01131 
01132   QtxPreferenceItem::ensureVisible( i );
01133 
01134   QtxPagePrefItem* item = dynamic_cast<QtxPagePrefItem*>( i );
01135   if ( item && item->widget() )
01136     myTabs->setCurrentWidget( item->widget() );
01137 }
01138 
01142 void QtxPagePrefTabsItem::updateTabs()
01143 {
01144   QList<QtxPagePrefItem*> items;
01145   pageChildItems( items );
01146 
01147   QWidget* cur = myTabs->currentWidget();
01148 
01149   int i = 0;
01150   QMap<QWidget*, int> map;
01151   for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end(); ++it )
01152   {
01153     QWidget* wid = (*it)->widget();
01154     if ( !wid )
01155       continue;
01156 
01157     if ( myTabs->widget( i ) != wid )
01158     {
01159       if ( myTabs->indexOf( wid ) != -1 )
01160         myTabs->removeTab( myTabs->indexOf( wid ) );
01161 
01162       myTabs->insertTab( i, wid, (*it)->title() );
01163     }
01164     else
01165       myTabs->setTabText( i, (*it)->title() );
01166 
01167     myTabs->setTabIcon( i, (*it)->icon() );
01168 
01169     i++;
01170     map.insert( wid, 0 );
01171   }
01172 
01173   QList<QWidget*> del;
01174   for ( int idx = 0; idx < (int)myTabs->count(); idx++ )
01175   {
01176     QWidget* w = myTabs->widget( idx );
01177     if ( !map.contains( w ) )
01178       del.append( w );
01179   }
01180 
01181   for ( QList<QWidget*>::const_iterator itr = del.begin(); itr != del.end(); ++itr )
01182     myTabs->removeTab( myTabs->indexOf( *itr ) );
01183 
01184   if ( cur )
01185     myTabs->setCurrentWidget( cur );
01186 }
01187 
01200 QtxPagePrefFrameItem::QtxPagePrefFrameItem( const QString& title, QtxPreferenceItem* parent,
01201                                             const QString& sect, const QString& param )
01202 : QtxPagePrefItem( title, parent, sect, param )
01203 {
01204   QWidget* main = new QWidget();
01205   QVBoxLayout* base = new QVBoxLayout( main );
01206   base->setMargin( 0 );
01207   base->setSpacing( 0 );
01208 
01209   base->addWidget( myBox = new QtxGridBox( 1, Qt::Horizontal, main, 5, 5 ) );
01210   base->addItem( new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
01211 
01212   setWidget( main );
01213 }
01214 
01218 QtxPagePrefFrameItem::~QtxPagePrefFrameItem()
01219 {
01220 }
01221 
01225 void QtxPagePrefFrameItem::updateContents()
01226 {
01227   QtxPagePrefItem::updateContents();
01228 
01229   updateFrame();
01230 
01231   QtxPageNamedPrefItem::adjustLabels( this );
01232 }
01233 
01239 int QtxPagePrefFrameItem::margin() const
01240 {
01241   return myBox->insideMargin();
01242 }
01243 
01249 void QtxPagePrefFrameItem::setMargin( const int m )
01250 {
01251   myBox->setInsideMargin( m );
01252 }
01253 
01259 int QtxPagePrefFrameItem::spacing() const
01260 {
01261   return myBox->insideSpacing();
01262 }
01263 
01269 void QtxPagePrefFrameItem::setSpacing( const int s )
01270 {
01271   myBox->setInsideSpacing( s );
01272 }
01273 
01279 int QtxPagePrefFrameItem::columns() const
01280 {
01281   return myBox->columns();
01282 }
01283 
01289 void QtxPagePrefFrameItem::setColumns( const int c )
01290 {
01291   myBox->setColumns( c );
01292 }
01293 
01299 Qt::Orientation QtxPagePrefFrameItem::orientation() const
01300 {
01301   return myBox->orientation();
01302 }
01303 
01309 void QtxPagePrefFrameItem::setOrientation( const Qt::Orientation o )
01310 {
01311   myBox->setOrientation( o );
01312 }
01313 
01319 bool QtxPagePrefFrameItem::stretch() const
01320 {
01321   QSpacerItem* s = 0;
01322   QLayout* l = widget() ? widget()->layout() : 0;
01323   for ( int i = 0; l && i < l->count() && !s; i++ )
01324     s = l->itemAt( i )->spacerItem();
01325 
01326   return s ? (bool)( s->expandingDirections() & Qt::Vertical ) : false;
01327 }
01328 
01334 void QtxPagePrefFrameItem::setStretch( const bool on )
01335 {
01336   QSpacerItem* s = 0;
01337   QLayout* l = widget() ? widget()->layout() : 0;
01338   for ( int i = 0; l && i < l->count() && !s; i++ )
01339     s = l->itemAt( i )->spacerItem();
01340 
01341   if ( s )
01342     s->changeSize( 0, 0, QSizePolicy::Minimum, on ? QSizePolicy::Expanding : QSizePolicy::Minimum );
01343 }
01344 
01351 QVariant QtxPagePrefFrameItem::optionValue( const QString& name ) const
01352 {
01353   if ( name == "margin" )
01354     return margin();
01355   else if ( name == "spacing" )
01356     return spacing();
01357   else if ( name == "columns" )
01358     return columns();
01359   else if ( name == "orientation" )
01360     return orientation();
01361   else if ( name == "stretch" )
01362     return stretch();
01363   else
01364     return QtxPagePrefItem::optionValue( name );
01365 }
01366 
01373 void QtxPagePrefFrameItem::setOptionValue( const QString& name, const QVariant& val )
01374 {
01375   if ( name == "margin" )
01376   {
01377     if ( val.canConvert( QVariant::Int ) )
01378       setMargin( val.toInt() );
01379   }
01380   else if ( name == "spacing" )
01381   {
01382     if ( val.canConvert( QVariant::Int ) )
01383       setSpacing( val.toInt() );
01384   }
01385   else if ( name == "columns" )
01386   {
01387     if ( val.canConvert( QVariant::Int ) )
01388       setColumns( val.toInt() );
01389   }
01390   else if ( name == "orientation" )
01391   {
01392     if ( val.canConvert( QVariant::Int ) )
01393       setOrientation( (Qt::Orientation)val.toInt() );
01394   }
01395   else if ( name == "stretch" )
01396   {
01397     if ( val.canConvert( QVariant::Bool ) )
01398       setStretch( val.toBool() );
01399   }
01400   else
01401     QtxPagePrefItem::setOptionValue( name, val );
01402 }
01403 
01404 void QtxPagePrefFrameItem::widgetShown()
01405 {
01406   QtxPagePrefItem::widgetShown();
01407 
01408   QtxPageNamedPrefItem::adjustLabels( this );
01409 }
01410 
01414 void QtxPagePrefFrameItem::updateFrame()
01415 {
01416   QList<QtxPagePrefItem*> items;
01417   pageChildItems( items );
01418 
01419   for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end(); ++it )
01420   {
01421     QWidget* wid = (*it)->widget();
01422     if ( !wid )
01423       continue;
01424 
01425     if ( wid->parent() != myBox )
01426       wid->setParent( myBox );
01427   }
01428 }
01429 
01442 QtxPagePrefGroupItem::QtxPagePrefGroupItem( const QString& title, QtxPreferenceItem* parent,
01443                                             const QString& sect, const QString& param )
01444 : QtxPagePrefItem( title, parent, sect, param )
01445 {
01446   myGroup = new QtxGroupBox( title, 0 );
01447   myBox = new QtxGridBox( 1, Qt::Horizontal, myGroup, 5, 5 );
01448   myGroup->setWidget( myBox );
01449 
01450   setWidget( myGroup );
01451 
01452   updateState();
01453 }
01454 
01463 QtxPagePrefGroupItem::QtxPagePrefGroupItem( const int cols, const QString& title, QtxPreferenceItem* parent,
01464                                             const QString& sect, const QString& param )
01465 : QtxPagePrefItem( title, parent, sect, param )
01466 {
01467   myGroup = new QtxGroupBox( title, 0 );
01468   myBox = new QtxGridBox( cols, Qt::Horizontal, myGroup, 5, 5 );
01469   myGroup->setWidget( myBox );
01470 
01471   setWidget( myGroup );
01472 
01473   updateState();
01474 }
01475 
01479 QtxPagePrefGroupItem::~QtxPagePrefGroupItem()
01480 {
01481 }
01482 
01489 void QtxPagePrefGroupItem::setResource( const QString& sect, const QString& param )
01490 {
01491   QtxPagePrefItem::setResource( sect, param );
01492   updateState();
01493 }
01494 
01498 void QtxPagePrefGroupItem::updateContents()
01499 {
01500   QtxPagePrefItem::updateContents();
01501 
01502   myGroup->setTitle( title() );
01503 
01504   updateState();
01505   updateGroup();
01506 
01507   QtxPageNamedPrefItem::adjustLabels( this );
01508 }
01509 
01515 int QtxPagePrefGroupItem::margin() const
01516 {
01517   return myBox->insideMargin();
01518 }
01519 
01525 void QtxPagePrefGroupItem::setMargin( const int m )
01526 {
01527   myBox->setInsideMargin( m );
01528 }
01529 
01535 int QtxPagePrefGroupItem::spacing() const
01536 {
01537   return myBox->insideSpacing();
01538 }
01539 
01545 void QtxPagePrefGroupItem::setSpacing( const int s )
01546 {
01547   myBox->setInsideSpacing( s );
01548 }
01549 
01555 int QtxPagePrefGroupItem::columns() const
01556 {
01557   return myBox->columns();
01558 }
01559 
01565 void QtxPagePrefGroupItem::setColumns( const int c )
01566 {
01567   myBox->setColumns( c );
01568 }
01569 
01575 Qt::Orientation QtxPagePrefGroupItem::orientation() const
01576 {
01577   return myBox->orientation();
01578 }
01579 
01585 void QtxPagePrefGroupItem::setOrientation( const Qt::Orientation o )
01586 {
01587   myBox->setOrientation( o );
01588 }
01589 
01594 bool QtxPagePrefGroupItem::isFlat() const
01595 {
01596   return myGroup->isFlat();
01597 }
01598 
01603 void QtxPagePrefGroupItem::setFlat( const bool on )
01604 {
01605   myGroup->setFlat( on );
01606 }
01607 
01612 void QtxPagePrefGroupItem::store()
01613 {
01614   if ( myGroup->isCheckable() )
01615     setBoolean( myGroup->isChecked() );
01616 }
01617 
01621 QtxGridBox* QtxPagePrefGroupItem::gridBox() const
01622 {
01623   return myBox;
01624 }
01625 
01630 void QtxPagePrefGroupItem::retrieve()
01631 {
01632   if ( myGroup->isCheckable() )
01633     myGroup->setChecked( getBoolean() );
01634 }
01635 
01642 QVariant QtxPagePrefGroupItem::optionValue( const QString& name ) const
01643 {
01644   if ( name == "margin" )
01645     return margin();
01646   else if ( name == "spacing" )
01647     return spacing();
01648   else if ( name == "columns" )
01649     return columns();
01650   else if ( name == "orientation" )
01651     return orientation();
01652   else if ( name == "flat" )
01653     return isFlat();
01654   else
01655     return QtxPagePrefItem::optionValue( name );
01656 }
01657 
01664 void QtxPagePrefGroupItem::setOptionValue( const QString& name, const QVariant& val )
01665 {
01666   if ( name == "margin" )
01667   {
01668     if ( val.canConvert( QVariant::Int ) )
01669       setMargin( val.toInt() );
01670   }
01671   else if ( name == "spacing" )
01672   {
01673     if ( val.canConvert( QVariant::Int ) )
01674       setSpacing( val.toInt() );
01675   }
01676   else if ( name == "columns" )
01677   {
01678     if ( val.canConvert( QVariant::Int ) )
01679       setColumns( val.toInt() );
01680   }
01681   else if ( name == "orientation" )
01682   {
01683     if ( val.canConvert( QVariant::Int ) )
01684       setOrientation( (Qt::Orientation)val.toInt() );
01685   }
01686   else if ( name == "flat" )
01687   {
01688     if ( val.canConvert( QVariant::Bool ) )
01689       setFlat( val.toBool() );
01690   }
01691   else
01692     QtxPagePrefItem::setOptionValue( name, val );
01693 }
01694 
01695 void QtxPagePrefGroupItem::widgetShown()
01696 {
01697   QtxPagePrefItem::widgetShown();
01698 
01699   QtxPageNamedPrefItem::adjustLabels( this );
01700 }
01701 
01705 void QtxPagePrefGroupItem::updateState()
01706 {
01707   QString section, param;
01708   resource( section, param );
01709   myGroup->setCheckable( !title().isEmpty() && !section.isEmpty() && !param.isEmpty() );
01710 }
01711 
01715 void QtxPagePrefGroupItem::updateGroup()
01716 {
01717   QList<QtxPagePrefItem*> items;
01718   pageChildItems( items );
01719 
01720   for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end(); ++it )
01721   {
01722     QWidget* wid = (*it)->widget();
01723     if ( !wid )
01724       continue;
01725 
01726     if ( wid->parent() != myBox )
01727       wid->setParent( myBox );
01728   }
01729 }
01730 
01744 QtxPagePrefLabelItem::QtxPagePrefLabelItem( const QString& text, QtxPreferenceItem* parent )
01745 : QtxPagePrefItem( text, parent )
01746 {
01747   setWidget( myLabel = new QLabel( text ) );
01748 }
01749 
01750 QtxPagePrefLabelItem::QtxPagePrefLabelItem( Qt::Alignment align, const QString& text, QtxPreferenceItem* parent )
01751 : QtxPagePrefItem( text, parent )
01752 {
01753   setWidget( myLabel = new QLabel( text ) );
01754   myLabel->setAlignment( align );
01755 }
01756 
01757 QtxPagePrefLabelItem::~QtxPagePrefLabelItem()
01758 {
01759 }
01760 
01761 void QtxPagePrefLabelItem::setTitle( const QString& text )
01762 {
01763   QtxPagePrefItem::setTitle( text );
01764 
01765   if ( myLabel )
01766     myLabel->setText( text );
01767 }
01768 
01769 Qt::Alignment QtxPagePrefLabelItem::alignment() const
01770 {
01771   return myLabel->alignment();
01772 }
01773 
01774 void QtxPagePrefLabelItem::setAlignment( Qt::Alignment align )
01775 {
01776   myLabel->setAlignment( align );
01777 }
01778 
01779 QVariant QtxPagePrefLabelItem::optionValue( const QString& name ) const
01780 {
01781   QVariant val;
01782   if ( name == "alignment" )
01783     val = (int)alignment();
01784   return val;
01785 }
01786 
01787 void QtxPagePrefLabelItem::setOptionValue( const QString& name, const QVariant& val )
01788 {
01789   if ( name == "alignment" )
01790   {
01791     if ( val.canConvert( QVariant::Int ) )
01792       setAlignment( (Qt::Alignment)val.toInt() );
01793   }
01794 }
01795 
01810 QtxPagePrefSpaceItem::QtxPagePrefSpaceItem( QtxPreferenceItem* parent )
01811 : QtxPagePrefItem( QString(), parent )
01812 {
01813   initialize( 0, 0, 1, 1 );
01814 }
01815 
01825 QtxPagePrefSpaceItem::QtxPagePrefSpaceItem( Qt::Orientation o, QtxPreferenceItem* parent )
01826 : QtxPagePrefItem( QString(), parent )
01827 {
01828   if ( o == Qt::Horizontal )
01829     initialize( 0, 0, 1, 0 );
01830   else
01831     initialize( 0, 0, 0, 1 );
01832 }
01833 
01845 QtxPagePrefSpaceItem::QtxPagePrefSpaceItem( const int w, const int h, QtxPreferenceItem* parent )
01846 : QtxPagePrefItem( QString(), parent )
01847 {
01848   initialize( w, h, w > 0 ? 0 : 1, h > 0 ? 0 : 1 );
01849 }
01850 
01854 QtxPagePrefSpaceItem::~QtxPagePrefSpaceItem()
01855 {
01856 }
01857 
01864 int QtxPagePrefSpaceItem::size( Qt::Orientation o ) const
01865 {
01866   return o == Qt::Horizontal ? widget()->minimumWidth() : widget()->minimumHeight();
01867 }
01868 
01875 void QtxPagePrefSpaceItem::setSize( Qt::Orientation o, const int sz )
01876 {
01877   if ( o == Qt::Horizontal )
01878     widget()->setMinimumWidth( sz );
01879   else
01880     widget()->setMinimumHeight( sz );
01881 }
01882 
01889 int QtxPagePrefSpaceItem::stretch( Qt::Orientation o ) const
01890 {
01891   QSizePolicy sp = widget()->sizePolicy();
01892   return o == Qt::Horizontal ? sp.horizontalStretch() : sp.verticalStretch();
01893 }
01894 
01901 void QtxPagePrefSpaceItem::setStretch( Qt::Orientation o, const int sf )
01902 {
01903   QSizePolicy sp = widget()->sizePolicy();
01904   if ( o == Qt::Horizontal )
01905   {
01906     sp.setHorizontalStretch( sf );
01907     sp.setHorizontalPolicy( sf > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed );
01908   }
01909   else
01910   {
01911     sp.setVerticalStretch( sf );
01912     sp.setVerticalPolicy( sf > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed );
01913   }
01914 
01915   widget()->setSizePolicy( sp );
01916 }
01917 
01924 QVariant QtxPagePrefSpaceItem::optionValue( const QString& name ) const
01925 {
01926   if ( name == "horizontal_size" || name == "hsize" )
01927     return size( Qt::Horizontal );
01928   else if ( name == "vertical_size" || name == "vsize" )
01929     return size( Qt::Vertical );
01930   else if ( name == "horizontal_stretch" || name == "hstretch" )
01931     return stretch( Qt::Horizontal );
01932   else if ( name == "vertical_stretch" || name == "vstretch" )
01933     return stretch( Qt::Vertical );
01934   else
01935     return QtxPagePrefItem::optionValue( name );
01936 }
01937 
01944 void QtxPagePrefSpaceItem::setOptionValue( const QString& name, const QVariant& val )
01945 {
01946   if ( name == "horizontal_size" || name == "hsize" )
01947   {
01948     if ( val.canConvert( QVariant::Int ) )
01949       setSize( Qt::Horizontal, val.toInt() );
01950   }
01951   else if ( name == "vertical_size" || name == "vsize" )
01952   {
01953     if ( val.canConvert( QVariant::Int ) )
01954       setSize( Qt::Vertical, val.toInt() );
01955   }
01956   else if ( name == "horizontal_stretch" || name == "hstretch" )
01957   {
01958     if ( val.canConvert( QVariant::Int ) )
01959       setStretch( Qt::Horizontal, val.toInt() );
01960   }
01961   else if ( name == "vertical_stretch" || name == "vstretch" )
01962   {
01963     if ( val.canConvert( QVariant::Int ) )
01964       setStretch( Qt::Vertical, val.toInt() );
01965   }
01966   else
01967     QtxPagePrefItem::setOptionValue( name, val );
01968 }
01969 
01977 void QtxPagePrefSpaceItem::initialize( const int w, const int h, const int hs, const int vs )
01978 {
01979   QSizePolicy sp;
01980   sp.setHorizontalPolicy( hs > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed );
01981   sp.setVerticalPolicy( vs > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed );
01982 
01983   sp.setHorizontalStretch( hs );
01984   sp.setVerticalStretch( vs );
01985 
01986   QWidget* wid = new QWidget();
01987   wid->setSizePolicy( sp );
01988 
01989   wid->setMinimumSize( w, h );
01990 
01991   setWidget( wid );
01992 }
01993 
02006 QtxPagePrefCheckItem::QtxPagePrefCheckItem( const QString& title, QtxPreferenceItem* parent,
02007                                             const QString& sect, const QString& param )
02008 
02009 : QtxPagePrefItem( title, parent, sect, param )
02010 {
02011   myCheck = new QCheckBox( title );
02012   myCheck->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
02013   setWidget( myCheck );
02014 }
02015 
02019 QtxPagePrefCheckItem::~QtxPagePrefCheckItem()
02020 {
02021 }
02022 
02027 void QtxPagePrefCheckItem::setTitle( const QString& txt )
02028 {
02029   QtxPagePrefItem::setTitle( txt );
02030 
02031   myCheck->setText( title() );
02032 }
02033 
02038 void QtxPagePrefCheckItem::store()
02039 {
02040   setBoolean( myCheck->isChecked() );
02041 }
02042 
02047 void QtxPagePrefCheckItem::retrieve()
02048 {
02049   myCheck->setChecked( getBoolean() );
02050 }
02051 
02058 static void fixupAndSet( QLineEdit* le, const QString& txt )
02059 {
02060   if ( le ) {
02061     QString val = txt;
02062     if ( le->validator() ) {
02063       const QDoubleValidator* de = dynamic_cast<const QDoubleValidator*>( le->validator() );
02064       if ( de ) {
02065        int dec = de->decimals();
02066        int idx = val.lastIndexOf( QRegExp( QString("[.|%1]").arg( le->locale().decimalPoint () ) ) );
02067        if ( idx >= 0 ) {
02068          QString tmp = val.mid( idx+1 );
02069          QString exp;
02070          val = val.left( idx+1 );
02071          idx = tmp.indexOf( QRegExp( QString("[e|E]") ) );
02072          if ( idx >= 0 ) {
02073            exp = tmp.mid( idx );
02074            tmp = tmp.left( idx );
02075          }
02076          tmp.truncate( dec );
02077          val = val + tmp + exp;
02078        }
02079       }
02080       int pos = 0;
02081       if ( le->validator()->validate( val, pos ) == QValidator::Invalid )
02082        val.clear();
02083     }
02084     le->setText( val );
02085   }
02086 }
02087 
02098 QtxPagePrefEditItem::QtxPagePrefEditItem( const QString& title, QtxPreferenceItem* parent,
02099                                           const QString& sect, const QString& param )
02100 : QtxPageNamedPrefItem( title, parent, sect, param ),
02101   myType( String ),
02102   myDecimals( 1000 ),
02103   myEchoMode( 0 )
02104 {
02105   setControl( myEditor = new QLineEdit() );
02106   updateEditor();
02107 }
02108 
02121 QtxPagePrefEditItem::QtxPagePrefEditItem( const int type, const QString& title,
02122                                           QtxPreferenceItem* parent, const QString& sect,
02123                                           const QString& param )
02124 : QtxPageNamedPrefItem( title, parent, sect, param ),
02125   myType( type ),
02126   myDecimals( 1000 ),
02127   myEchoMode( 0 )
02128 {
02129   setControl( myEditor = new QLineEdit() );
02130   updateEditor();
02131 }
02132 
02136 QtxPagePrefEditItem::~QtxPagePrefEditItem()
02137 {
02138 }
02139 
02145 int QtxPagePrefEditItem::inputType() const
02146 {
02147   return myType;
02148 }
02149 
02155 void QtxPagePrefEditItem::setInputType( const int type )
02156 {
02157   if ( myType == type )
02158     return;
02159 
02160   myType = type;
02161   updateEditor();
02162 }
02163 
02169 int QtxPagePrefEditItem::decimals() const
02170 {
02171   return myDecimals;
02172 }
02173 
02179 void QtxPagePrefEditItem::setDecimals( const int dec )
02180 {
02181   if ( myDecimals == dec )
02182     return;
02183   
02184   myDecimals = dec;
02185   updateEditor();
02186 }
02187 
02193 int QtxPagePrefEditItem::echoMode() const
02194 {
02195   return myEchoMode;
02196 }
02197 
02203 void QtxPagePrefEditItem::setEchoMode( const int echo )
02204 {   
02205   if ( myEchoMode == echo )
02206     return;
02207   
02208   myEchoMode = echo;
02209   updateEditor();
02210 }
02211 
02216 void QtxPagePrefEditItem::store()
02217 {
02218   setString( myEditor->text() );
02219 }
02220 
02225 void QtxPagePrefEditItem::retrieve()
02226 {
02227   QString txt = getString();
02228   fixupAndSet( myEditor, txt );
02229 }
02230 
02237 QVariant QtxPagePrefEditItem::optionValue( const QString& name ) const
02238 {
02239   if ( name == "input_type" || name == "type" )
02240     return inputType();
02241   else if ( name == "precision" || name == "prec" || name == "decimals" )
02242     return decimals();
02243   else if ( name == "echo" || name == "echo_mode" || name == "echomode")
02244     return echoMode();
02245   else
02246     return QtxPageNamedPrefItem::optionValue( name );
02247 }
02248 
02255 void QtxPagePrefEditItem::setOptionValue( const QString& name, const QVariant& val )
02256 {
02257   if ( name == "input_type" || name == "type" )
02258   {
02259     if ( val.canConvert( QVariant::Int ) )
02260       setInputType( val.toInt() );
02261   }
02262   else if ( name == "precision" || name == "prec" || name == "decimals" ) {
02263     if ( val.canConvert( QVariant::Int ) )
02264       setDecimals( val.toInt() );
02265   }
02266   else if ( name == "echo" || name == "echo_mode" || name == "echomode") {
02267     if ( val.canConvert( QVariant::Int ) )
02268       setEchoMode( val.toInt() );
02269   }
02270   else
02271     QtxPageNamedPrefItem::setOptionValue( name, val );
02272 }
02273 
02277 void QtxPagePrefEditItem::updateEditor()
02278 {
02279   switch (myEchoMode)
02280   {
02281     case 0:
02282       myEditor->setEchoMode(QLineEdit::Normal);
02283       break;
02284     case 1:
02285       myEditor->setEchoMode(QLineEdit::NoEcho);
02286       break;
02287     case 2:
02288       myEditor->setEchoMode(QLineEdit::Password);
02289       break;
02290     case 3:
02291       myEditor->setEchoMode(QLineEdit::PasswordEchoOnEdit);
02292       break;
02293     default:
02294       myEditor->setEchoMode(QLineEdit::Normal);
02295   }
02296   
02297   QValidator* val = 0;
02298   switch ( inputType() )
02299   {
02300   case Integer:
02301     val = new QIntValidator( myEditor );
02302     break;
02303   case Double:
02304     val = new QDoubleValidator( myEditor );
02305     dynamic_cast<QDoubleValidator*>( val )->setDecimals( myDecimals < 0 ? 1000 : myDecimals );
02306     break;
02307   default:
02308     break;
02309   }
02310 
02311   QString txt = myEditor->text();
02312   delete myEditor->validator();
02313   myEditor->setValidator( val );
02314   fixupAndSet( myEditor, txt );
02315 }
02316 
02331 QtxPagePrefSliderItem::QtxPagePrefSliderItem( const QString& title, QtxPreferenceItem* parent,
02332                                               const QString& sect, const QString& param )
02333 : QtxPageNamedPrefItem( title, parent, sect, param )
02334 {
02335   setControl( mySlider = new QSlider( Qt::Horizontal ) );
02336   widget()->layout()->addWidget( myLabel = new QLabel( ) );
02337     
02338   setMinimum( 0 );
02339   setMaximum( 0 );
02340   setSingleStep( 1 );
02341   setPageStep( 1 );
02342   
02343   mySlider->setTickPosition( QSlider::TicksBothSides );
02344   
02345   connect (mySlider, SIGNAL(valueChanged(int)), this, SLOT(setIcon(int)));
02346   updateSlider();
02347 }
02348 
02352 QtxPagePrefSliderItem::~QtxPagePrefSliderItem()
02353 {
02354 }
02355 
02361 int QtxPagePrefSliderItem::singleStep() const
02362 {
02363   return mySlider->singleStep();
02364 }
02365 
02371 int QtxPagePrefSliderItem::pageStep() const
02372 {
02373   return mySlider->pageStep();
02374 }
02375 
02381 int QtxPagePrefSliderItem::minimum() const
02382 {
02383     return mySlider->minimum();
02384 }
02385 
02391 int QtxPagePrefSliderItem::maximum() const
02392 {
02393     return mySlider->maximum();
02394 }
02395 
02401 QList<QIcon> QtxPagePrefSliderItem::icons() const
02402 {
02403   return myIcons;
02404 }
02405 
02411 void QtxPagePrefSliderItem::setSingleStep( const int& step )
02412 {
02413   mySlider->setSingleStep( step );
02414 }
02415 
02421 void QtxPagePrefSliderItem::setPageStep( const int& step )
02422 {
02423   mySlider->setPageStep( step );
02424 }
02425 
02431 void QtxPagePrefSliderItem::setMinimum( const int& min )
02432 {
02433   mySlider->setMinimum( min );
02434   setIcon( mySlider->value() );
02435 }
02436 
02442 void QtxPagePrefSliderItem::setMaximum( const int& max )
02443 {
02444   mySlider->setMaximum( max );
02445   setIcon( mySlider->value() );
02446 }
02447 
02453 void QtxPagePrefSliderItem::setIcons( const QList<QIcon>& icns )
02454 {
02455   if ( icns.isEmpty() ) 
02456     return;
02457   myIcons = icns;
02458   
02459   QSize maxsize(0, 0); 
02460   for ( QList<QIcon>::const_iterator it = myIcons.begin(); it != myIcons.end(); ++it ) {
02461     if ( (*it).isNull() ) continue;
02462     maxsize = maxsize.expandedTo( (*it).availableSizes().first() );
02463   }
02464   myLabel->setFixedSize( maxsize );
02465   
02466   updateSlider();
02467 }
02468 
02473 void QtxPagePrefSliderItem::store()
02474 {
02475   setInteger( mySlider->value() );
02476 }
02477 
02482 void QtxPagePrefSliderItem::retrieve()
02483 {
02484   mySlider->setValue( getInteger( mySlider->value() ) );
02485 }
02486 
02493 QVariant QtxPagePrefSliderItem::optionValue( const QString& name ) const
02494 {
02495   if ( name == "minimum" || name == "min" )
02496     return minimum();
02497   else if ( name == "maximum" || name == "max" )
02498     return maximum();
02499   else if ( name == "single_step" )
02500     return singleStep();
02501   else if ( name == "page_step" )
02502     return pageStep();
02503   else if ( name == "icons" || name == "pixmaps" )
02504   {
02505     QList<QVariant> lst;
02506     QList<QIcon> ics = icons();
02507     for ( QList<QIcon>::const_iterator it = ics.begin(); it != ics.end(); ++it )
02508       lst.append( *it );
02509     return lst;
02510   }
02511   else
02512     return QtxPageNamedPrefItem::optionValue( name );
02513 }
02514 
02521 void QtxPagePrefSliderItem::setOptionValue( const QString& name, const QVariant& val )
02522 {
02523   if ( val.canConvert( QVariant::Int ) )
02524   {
02525     if ( name == "minimum" || name == "min" )
02526       setMinimum( val.toInt() );
02527     else if ( name == "maximum" || name == "max" )
02528       setMaximum( val.toInt() );
02529     else if ( name == "single_step" )
02530       setSingleStep( val.toInt() );
02531     else if ( name == "page_step" )
02532       setPageStep( val.toInt() );
02533     else
02534       QtxPageNamedPrefItem::setOptionValue( name, val );
02535   }
02536   else if ( name == "icons" || name == "pixmaps" )
02537     setIcons( val );
02538   else
02539     QtxPageNamedPrefItem::setOptionValue( name, val );
02540 }
02541 
02542 void QtxPagePrefSliderItem::setIcon( int pos )
02543 {
02544   int index = pos - mySlider->minimum();
02545   if ( !myIcons.isEmpty() && index >= 0 && index < myIcons.size() && !myIcons[index].isNull() )
02546     myLabel->setPixmap( myIcons[index].pixmap( myIcons[index].availableSizes().first() ) );
02547   else
02548     myLabel->clear();
02549 }
02550 
02554 void QtxPagePrefSliderItem::updateSlider()
02555 {
02556   int val = mySlider->value();
02557   int stp = singleStep();
02558   int ptp = pageStep();
02559   int min = minimum();
02560   int max = maximum();
02561 
02562   control()->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
02563   mySlider->setFocusPolicy(Qt::StrongFocus);
02564   
02565   mySlider->setValue( val );
02566   setSingleStep( stp );
02567   setPageStep( ptp );
02568   setMinimum( min );
02569   setMaximum( max );
02570   
02571   myLabel->setVisible( !myIcons.empty() );
02572   widget()->layout()->setSpacing( !myIcons.empty() ? 6 : 0 );
02573 }
02574 
02580 void  QtxPagePrefSliderItem::setIcons( const QVariant& var )
02581 {
02582   if ( var.type() != QVariant::List )
02583     return;
02584 
02585   QList<QIcon> lst;
02586   QList<QVariant> varList = var.toList();
02587   for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it )
02588   {
02589     if ( (*it).canConvert<QIcon>() )
02590       lst.append( (*it).value<QIcon>() );
02591     else if ( (*it).canConvert<QPixmap>() )
02592       lst.append( (*it).value<QPixmap>() );
02593     else
02594       lst.append( QIcon() );
02595   }
02596   setIcons( lst );
02597 }
02598 
02620 QtxPagePrefSelectItem::QtxPagePrefSelectItem( const QString& title, QtxPreferenceItem* parent,
02621                                               const QString& sect, const QString& param )
02622 : QtxPageNamedPrefItem( title, parent, sect, param ),
02623   myType( NoInput )
02624 {
02625   setControl( mySelector = new QtxComboBox() );
02626   mySelector->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
02627   mySelector->setDuplicatesEnabled( false );
02628   updateSelector();
02629 }
02630 
02643 QtxPagePrefSelectItem::QtxPagePrefSelectItem( const int type, const QString& title, QtxPreferenceItem* parent,
02644                                               const QString& sect, const QString& param )
02645 : QtxPageNamedPrefItem( title, parent, sect, param ),
02646   myType( type )
02647 {
02648   setControl( mySelector = new QtxComboBox() );
02649   mySelector->setDuplicatesEnabled( false );
02650   updateSelector();
02651 }
02652 
02656 QtxPagePrefSelectItem::~QtxPagePrefSelectItem()
02657 {
02658 }
02659 
02665 int QtxPagePrefSelectItem::inputType() const
02666 {
02667   return myType;
02668 }
02669 
02675 void QtxPagePrefSelectItem::setInputType( const int type )
02676 {
02677   if ( myType == type )
02678     return;
02679 
02680   myType = type;
02681   updateSelector();
02682 }
02683 
02689 QStringList QtxPagePrefSelectItem::strings() const
02690 {
02691   QStringList res;
02692   for ( uint i = 0; i < mySelector->count(); i++ )
02693     res.append( mySelector->itemText( i ) );
02694   return res;
02695 }
02696 
02702 QList<int> QtxPagePrefSelectItem::numbers() const
02703 {
02704   QList<int> res;
02705   for ( uint i = 0; i < mySelector->count(); i++ )
02706   {
02707     if ( mySelector->hasId( i ) )
02708       res.append( mySelector->id( i ) );
02709   }
02710   return res;
02711 }
02712 
02718 QList<QIcon> QtxPagePrefSelectItem::icons() const
02719 {
02720   QList<QIcon> res;
02721   for ( uint i = 0; i < mySelector->count(); i++ )
02722     res.append( mySelector->itemIcon( i ) );
02723   return res;
02724 }
02725 
02731 void QtxPagePrefSelectItem::setStrings( const QStringList& lst )
02732 {
02733   mySelector->clear();
02734   mySelector->addItems( lst );
02735 }
02736 
02742 void QtxPagePrefSelectItem::setNumbers( const QList<int>& ids )
02743 {
02744   uint i = 0;
02745   for ( QList<int>::const_iterator it = ids.begin(); it != ids.end(); ++it, i++ ) {
02746     if ( i >= mySelector->count() )
02747       mySelector->addItem(QString("") );
02748     
02749     mySelector->setId( i, *it );
02750   }
02751 }
02752 
02761 void QtxPagePrefSelectItem::setIcons( const QList<QIcon>& icns )
02762 {
02763   uint i = 0;
02764   for ( QList<QIcon>::const_iterator it = icns.begin(); it != icns.end() && i < mySelector->count(); ++it, i++ )
02765     mySelector->setItemIcon( i, *it );
02766 }
02767 
02772 void QtxPagePrefSelectItem::store()
02773 {
02774   if ( mySelector->isCleared() )
02775     return;
02776 
02777   int idx = mySelector->currentIndex();
02778 
02779   if ( mySelector->hasId( idx ) )
02780     setInteger( mySelector->id( idx ) );
02781   else if ( idx >= 0 )
02782     setString( mySelector->itemText( idx ) );
02783 }
02784 
02789 void QtxPagePrefSelectItem::retrieve()
02790 {
02791   QString txt = getString();
02792 
02793   int idx = -1;
02794 
02795   bool ok = false;
02796   int num = txt.toInt( &ok );
02797   if ( ok )
02798     idx = mySelector->index( num );
02799   else
02800   {
02801     for ( uint i = 0; i < mySelector->count() && idx == -1; i++ )
02802     {
02803       if ( mySelector->itemText( i ) == txt )
02804         idx = i;
02805     }
02806   }
02807 
02808   if ( idx != -1 )
02809     mySelector->setCurrentIndex( idx );
02810   else if ( mySelector->isEditable() )
02811   {
02812     int pos = 0;
02813     if ( mySelector->validator() &&
02814          mySelector->validator()->validate( txt, pos ) == QValidator::Invalid )
02815       mySelector->setCleared( true );
02816     else
02817     {
02818       mySelector->setCleared( false );
02819       mySelector->addItem( txt );
02820       mySelector->setCurrentIndex( mySelector->count() - 1 );
02821     }
02822   }
02823 }
02824 
02831 QVariant QtxPagePrefSelectItem::optionValue( const QString& name ) const
02832 {
02833   if ( name == "input_type" || name == "type" )
02834     return inputType();
02835   else if ( name == "strings" || name == "labels" )
02836     return strings();
02837   else if ( name == "numbers" || name == "ids" || name == "indexes" )
02838   {
02839     QList<QVariant> lst;
02840     QList<int> nums = numbers();
02841     for ( QList<int>::const_iterator it = nums.begin(); it != nums.end(); ++it )
02842       lst.append( *it );
02843     return lst;
02844   }
02845   else if ( name == "icons" || name == "pixmaps" )
02846   {
02847     QList<QVariant> lst;
02848     QList<QIcon> ics = icons();
02849     for ( QList<QIcon>::const_iterator it = ics.begin(); it != ics.end(); ++it )
02850       lst.append( *it );
02851     return lst;
02852   }
02853   else
02854     return QtxPageNamedPrefItem::optionValue( name );
02855 }
02856 
02863 void QtxPagePrefSelectItem::setOptionValue( const QString& name, const QVariant& val )
02864 {
02865   if ( name == "input_type" || name == "type" )
02866   {
02867     if ( val.canConvert( QVariant::Int ) )
02868       setInputType( val.toInt() );
02869   }
02870   else if ( name == "strings" || name == "labels" )
02871     setStrings( val );
02872   else if ( name == "numbers" || name == "ids" || name == "indexes" )
02873     setNumbers( val );
02874   else if ( name == "icons" || name == "pixmaps" )
02875     setIcons( val );
02876   else
02877     QtxPageNamedPrefItem::setOptionValue( name, val );
02878 }
02879 
02885 void QtxPagePrefSelectItem::setStrings( const QVariant& var )
02886 {
02887   if ( var.type() != QVariant::StringList )
02888     return;
02889 
02890   setStrings( var.toStringList() );
02891 }
02892 
02898 void QtxPagePrefSelectItem::setNumbers( const QVariant& var )
02899 {
02900   if ( var.type() != QVariant::List )
02901     return;
02902 
02903   QList<int> lst;
02904   QList<QVariant> varList = var.toList();
02905   for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it )
02906   {
02907     if ( (*it).canConvert( QVariant::Int ) )
02908       lst.append( (*it).toInt() );
02909   }
02910   setNumbers( lst );
02911 }
02912 
02918 void QtxPagePrefSelectItem::setIcons( const QVariant& var )
02919 {
02920   if ( var.type() != QVariant::List )
02921     return;
02922 
02923   QList<QIcon> lst;
02924   QList<QVariant> varList = var.toList();
02925   for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it )
02926   {
02927     if ( (*it).canConvert<QIcon>() )
02928       lst.append( (*it).value<QIcon>() );
02929     else if ( (*it).canConvert<QPixmap>() )
02930       lst.append( (*it).value<QPixmap>() );
02931     else
02932       lst.append( QIcon() );
02933   }
02934   setIcons( lst );
02935 }
02936 
02940 void QtxPagePrefSelectItem::updateSelector()
02941 {
02942   QValidator* val = 0;
02943   switch ( inputType() )
02944   {
02945   case Integer:
02946     val = new QIntValidator( mySelector );
02947     break;
02948   case Double:
02949     val = new QDoubleValidator( mySelector );
02950     break;
02951   default:
02952     break;
02953   }
02954 
02955   mySelector->setEditable( inputType() != NoInput );
02956 
02957   if ( mySelector->isEditable() && !mySelector->currentText().isEmpty() && val )
02958   {
02959     int pos = 0;
02960     QString str = mySelector->currentText();
02961     if ( val->validate( str, pos ) == QValidator::Invalid )
02962       mySelector->clearEditText();
02963   }
02964 
02965   delete mySelector->validator();
02966   mySelector->setValidator( val );
02967 }
02968 
02985 QtxPagePrefSpinItem::QtxPagePrefSpinItem( const QString& title, QtxPreferenceItem* parent,
02986                                           const QString& sect, const QString& param )
02987 : QtxPageNamedPrefItem( title, parent, sect, param ),
02988   myType( Integer )
02989 {
02990   updateSpinBox();
02991 }
02992 
03005 QtxPagePrefSpinItem::QtxPagePrefSpinItem( const int type, const QString& title,
03006                                           QtxPreferenceItem* parent, const QString& sect,
03007                                           const QString& param )
03008 : QtxPageNamedPrefItem( title, parent, sect, param ),
03009   myType( type )
03010 {
03011   updateSpinBox();
03012 }
03013 
03017 QtxPagePrefSpinItem::~QtxPagePrefSpinItem()
03018 {
03019 }
03020 
03026 int QtxPagePrefSpinItem::inputType() const
03027 {
03028   return myType;
03029 }
03030 
03036 void QtxPagePrefSpinItem::setInputType( const int type )
03037 {
03038   if ( myType == type )
03039     return;
03040 
03041   myType = type;
03042   updateSpinBox();
03043 }
03044 
03050 QVariant QtxPagePrefSpinItem::step() const
03051 {
03052   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
03053     return isb->singleStep();
03054   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
03055     return dsb->singleStep();
03056   else
03057     return QVariant();
03058 }
03059 
03065 QVariant QtxPagePrefSpinItem::precision() const
03066 {
03067   if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
03068     return dsb->decimals();
03069   else
03070     return QVariant();
03071 }
03072 
03078 QVariant QtxPagePrefSpinItem::minimum() const
03079 {
03080   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
03081     return isb->minimum();
03082   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
03083     return dsb->minimum();
03084   else
03085     return QVariant();
03086 }
03087 
03093 QVariant QtxPagePrefSpinItem::maximum() const
03094 {
03095   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
03096     return isb->maximum();
03097   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
03098     return dsb->maximum();
03099   else
03100     return QVariant();
03101 }
03102 
03108 QString QtxPagePrefSpinItem::prefix() const
03109 {
03110   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
03111     return isb->prefix();
03112   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
03113     return dsb->prefix();
03114   else
03115     return QString();
03116 }
03117 
03123 QString QtxPagePrefSpinItem::suffix() const
03124 {
03125   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
03126     return isb->suffix();
03127   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
03128     return dsb->suffix();
03129   else
03130     return QString();
03131 }
03132 
03139 QString QtxPagePrefSpinItem::specialValueText() const
03140 {
03141   QAbstractSpinBox* sb = ::qobject_cast<QAbstractSpinBox*>( control() );
03142   if ( sb )
03143     return sb->specialValueText();
03144   else
03145     return QString();
03146 }
03147 
03153 void QtxPagePrefSpinItem::setStep( const QVariant& step )
03154 {
03155   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
03156   {
03157     if ( step.canConvert( QVariant::Int ) )
03158       isb->setSingleStep( step.toInt() );
03159   }
03160   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
03161   {
03162     if ( step.canConvert( QVariant::Double ) )
03163       dsb->setSingleStep( step.toDouble() );
03164   }
03165 }
03166 
03172 void QtxPagePrefSpinItem::setPrecision( const QVariant& prec )
03173 {
03174   if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
03175   {
03176     if ( prec.canConvert( QVariant::Int ) ) {
03177       dsb->setDecimals( qAbs( prec.toInt() ) );
03178       dsb->setPrecision( prec.toInt() );
03179     }
03180   }
03181 }
03182 
03188 void QtxPagePrefSpinItem::setMinimum( const QVariant& min )
03189 {
03190   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
03191   {
03192     if ( min.canConvert( QVariant::Int ) )
03193       isb->setMinimum( min.toInt() );
03194   }
03195   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
03196   {
03197     if ( min.canConvert( QVariant::Double ) )
03198       dsb->setMinimum( min.toDouble() );
03199   }
03200 }
03201 
03207 void QtxPagePrefSpinItem::setMaximum( const QVariant& max )
03208 {
03209   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
03210   {
03211     if ( max.canConvert( QVariant::Int ) )
03212       isb->setMaximum( max.toInt() );
03213   }
03214   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
03215   {
03216     if ( max.canConvert( QVariant::Double ) )
03217       dsb->setMaximum( max.toDouble() );
03218   }
03219 }
03220 
03226 void QtxPagePrefSpinItem::setPrefix( const QString& txt )
03227 {
03228   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
03229     isb->setPrefix( txt );
03230   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
03231     dsb->setPrefix( txt );
03232 }
03233 
03239 void QtxPagePrefSpinItem::setSuffix( const QString& txt )
03240 {
03241   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
03242     isb->setSuffix( txt );
03243   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
03244     dsb->setSuffix( txt );
03245 }
03246 
03253 void QtxPagePrefSpinItem::setSpecialValueText( const QString& txt )
03254 {
03255   QAbstractSpinBox* sb = ::qobject_cast<QAbstractSpinBox*>( control() );
03256   if ( sb )
03257     sb->setSpecialValueText( txt );
03258 }
03259 
03264 void QtxPagePrefSpinItem::store()
03265 {
03266   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
03267     setInteger( isb->value() );
03268   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
03269     setDouble( dsb->value() );
03270 }
03271 
03276 void QtxPagePrefSpinItem::retrieve()
03277 {
03278   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
03279     isb->setValue( getInteger( isb->value() ) );
03280   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
03281     dsb->setValue( getDouble( dsb->value() ) );
03282 }
03283 
03290 QVariant QtxPagePrefSpinItem::optionValue( const QString& name ) const
03291 {
03292   if ( name == "input_type" || name == "type" )
03293     return inputType();
03294   else if ( name == "minimum" || name == "min" )
03295     return minimum();
03296   else if ( name == "maximum" || name == "max" )
03297     return maximum();
03298   else if ( name == "step" )
03299     return step();
03300   else if ( name == "precision" )
03301     return precision();
03302   else if ( name == "prefix" )
03303     return prefix();
03304   else if ( name == "suffix" )
03305     return suffix();
03306   else if ( name == "special" )
03307     return specialValueText();
03308   else
03309     return QtxPageNamedPrefItem::optionValue( name );
03310 }
03311 
03318 void QtxPagePrefSpinItem::setOptionValue( const QString& name, const QVariant& val )
03319 {
03320   if ( name == "input_type" || name == "type" )
03321   {
03322     if ( val.canConvert( QVariant::Int ) )
03323       setInputType( val.toInt() );
03324   }
03325   else if ( name == "minimum" || name == "min" )
03326     setMinimum( val );
03327   else if ( name == "maximum" || name == "max" )
03328     setMaximum( val );
03329   else if ( name == "step" )
03330     setStep( val );
03331   else if ( name == "precision" )
03332     setPrecision( val );
03333   else if ( name == "prefix" )
03334   {
03335     if ( val.canConvert( QVariant::String ) )
03336       setPrefix( val.toString() );
03337   }
03338   else if ( name == "suffix" )
03339   {
03340     if ( val.canConvert( QVariant::String ) )
03341       setSuffix( val.toString() );
03342   }
03343   else if ( name == "special" )
03344   {
03345     if ( val.canConvert( QVariant::String ) )
03346       setSpecialValueText( val.toString() );
03347   }
03348   else
03349     QtxPageNamedPrefItem::setOptionValue( name, val );
03350 }
03351 
03355 void QtxPagePrefSpinItem::updateSpinBox()
03356 {
03357   QVariant val;
03358   QVariant stp = step();
03359   QVariant prec = precision();
03360   QVariant min = minimum();
03361   QVariant max = maximum();
03362 
03363   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
03364     val = isb->value();
03365   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
03366     val = dsb->value();
03367 
03368   switch ( inputType() )
03369   {
03370   case Integer:
03371     setControl( new QtxIntSpinBox() );
03372     break;
03373   case Double:
03374     setControl( new QtxDoubleSpinBox() );
03375     break;
03376   default:
03377     break;
03378   }
03379 
03380   control()->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
03381 
03382   setStep( stp );
03383   setPrecision( prec );
03384   setMinimum( min );
03385   setMaximum( max );
03386 
03387   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
03388   {
03389     if ( val.canConvert( QVariant::Int ) )
03390       isb->setValue( val.toInt() );
03391   }
03392   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
03393   {
03394     if ( val.canConvert( QVariant::Double ) )
03395       dsb->setValue( val.toDouble() );
03396   }
03397 }
03398 
03411 QtxPagePrefTextItem::QtxPagePrefTextItem( QtxPreferenceItem* parent, const QString& sect,
03412                                           const QString& param )
03413 : QtxPageNamedPrefItem( QString(), parent, sect, param )
03414 {
03415   myEditor = new QTextEdit();
03416   myEditor->setAcceptRichText( false );
03417 
03418   setControl( myEditor );
03419 }
03420 
03428 QtxPagePrefTextItem::QtxPagePrefTextItem( const QString& title, QtxPreferenceItem* parent,
03429                                           const QString& sect, const QString& param )
03430 : QtxPageNamedPrefItem( title, parent, sect, param )
03431 {
03432   myEditor = new QTextEdit();
03433   myEditor->setAcceptRichText( false );
03434 
03435   setControl( myEditor );
03436 }
03437 
03441 QtxPagePrefTextItem::~QtxPagePrefTextItem()
03442 {
03443 }
03444 
03449 void QtxPagePrefTextItem::store()
03450 {
03451   setString( myEditor->toPlainText() );
03452 }
03453 
03458 void QtxPagePrefTextItem::retrieve()
03459 {
03460   myEditor->setPlainText( getString() );
03461 }
03462 
03475 QtxPagePrefColorItem::QtxPagePrefColorItem( const QString& title, QtxPreferenceItem* parent,
03476                                             const QString& sect, const QString& param )
03477 : QtxPageNamedPrefItem( title, parent, sect, param )
03478 {
03479   //  QtxPagePrefGroupItem* aGroup 0; //= dynamic_cast<QtxPagePrefGroupItem*>( parent );
03480 
03481   //  setControl( myColor = new QtxColorButton( aGroup ? aGroup->gridBox() : 0 ) );
03482   setControl( myColor = new QtxColorButton( 0 ) );
03483   myColor->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
03484 }
03485 
03489 QtxPagePrefColorItem::~QtxPagePrefColorItem()
03490 {
03491 }
03492 
03497 void QtxPagePrefColorItem::store()
03498 {
03499   setColor( myColor->color() );
03500 }
03501 
03506 void QtxPagePrefColorItem::retrieve()
03507 {
03508   myColor->setColor( getColor() );
03509 }
03510 
03527 QtxPagePrefBiColorItem::QtxPagePrefBiColorItem( const QString& title, QtxPreferenceItem* parent,
03528                                           const QString& sect, const QString& param )
03529 : QtxPageNamedPrefItem( title, parent, sect, param )
03530 {
03531   setControl( myColors = new QtxBiColorTool( 0 ) );
03532 }
03533 
03537 QtxPagePrefBiColorItem::~QtxPagePrefBiColorItem()
03538 {
03539 }
03540 
03546 QString QtxPagePrefBiColorItem::text() const
03547 {
03548   return myColors->text();
03549 }
03550 
03556 void QtxPagePrefBiColorItem::setText( const QString& t )
03557 {
03558   myColors->setText( t );
03559 }
03560 
03565 void QtxPagePrefBiColorItem::store()
03566 {
03567   setString( Qtx::biColorToString( myColors->mainColor(), myColors->delta() ) );
03568 }
03569 
03574 void QtxPagePrefBiColorItem::retrieve()
03575 {
03576   QColor c;
03577   int d;
03578   Qtx::stringToBiColor( getString(), c, d );
03579   myColors->setMainColor( c );
03580   myColors->setDelta( d );
03581 }
03582 
03589 QVariant QtxPagePrefBiColorItem::optionValue( const QString& name ) const
03590 {
03591   if ( name == "text" )
03592     return text();
03593   else
03594     return QtxPageNamedPrefItem::optionValue( name );
03595 }
03596 
03603 void QtxPagePrefBiColorItem::setOptionValue( const QString& name, const QVariant& val )
03604 {
03605   if ( name == "text" )
03606   {
03607     if ( val.canConvert( QVariant::String ) )
03608       setText( val.toString() );
03609   }
03610   else
03611     QtxPageNamedPrefItem::setOptionValue( name, val );
03612 }
03613 
03627 QtxPagePrefFontItem::QtxPagePrefFontItem( const int feat, const QString& title,
03628                                           QtxPreferenceItem* parent, const QString& sect,
03629                                           const QString& param )
03630 : QtxPageNamedPrefItem( title, parent, sect, param )
03631 {
03632   setControl( myFont = new QtxFontEdit( feat ) );
03633 }
03634 
03642 QtxPagePrefFontItem::QtxPagePrefFontItem( const QString& title, QtxPreferenceItem* parent,
03643                                           const QString& sect, const QString& param )
03644 : QtxPageNamedPrefItem( title, parent, sect, param )
03645 {
03646   setControl( myFont = new QtxFontEdit() );
03647 }
03648 
03652 QtxPagePrefFontItem::~QtxPagePrefFontItem()
03653 {
03654 }
03655 
03661 int QtxPagePrefFontItem::features() const
03662 {
03663   return myFont->features();
03664 }
03665 
03671 void QtxPagePrefFontItem::setFeatures( const int f )
03672 {
03673   myFont->setFeatures( f );
03674 }
03675 
03684 void QtxPagePrefFontItem::setMode( const int mode )
03685 {
03686   myFont->setMode( mode );
03687 }
03688 
03694 int QtxPagePrefFontItem::mode() const
03695 {
03696   return myFont->mode();
03697 }
03698 
03705 void QtxPagePrefFontItem::setFonts( const QStringList& fams )
03706 {
03707   myFont->setFonts( fams );
03708 }
03709 
03715 QStringList QtxPagePrefFontItem::fonts() const
03716 {
03717   return myFont->fonts();
03718 }
03719 
03727 void QtxPagePrefFontItem::setSizes( const QList<int>& sizes )
03728 {
03729   myFont->setSizes( sizes );
03730 }
03731 
03737 QList<int> QtxPagePrefFontItem::sizes() const
03738 {
03739   return myFont->sizes();
03740 }
03741 
03746 void QtxPagePrefFontItem::store()
03747 {
03748   setFont( myFont->currentFont() );
03749 }
03750 
03755 void QtxPagePrefFontItem::retrieve()
03756 {
03757   myFont->setCurrentFont( getFont() );
03758 }
03759 
03766 QVariant QtxPagePrefFontItem::optionValue( const QString& name ) const
03767 {
03768   if ( name == "features" )
03769     return features();
03770   else if ( name == "mode" )
03771     return mode();
03772   else if ( name == "fonts" || name == "families" )
03773     return fonts();
03774   else if ( name == "sizes" )
03775   {
03776     QList<QVariant> lst;
03777     QList<int> nums = sizes();
03778     for ( QList<int>::const_iterator it = nums.begin(); it != nums.end(); ++it )
03779       lst.append( *it );
03780     return lst;
03781   }
03782   else
03783     return QtxPageNamedPrefItem::optionValue( name );
03784 }
03785 
03792 void QtxPagePrefFontItem::setOptionValue( const QString& name, const QVariant& val )
03793 {
03794   if ( name == "features" )
03795   {
03796     if ( val.canConvert( QVariant::Int ) )
03797       setFeatures( val.toInt() );
03798   }
03799   else if ( name == "mode" )
03800   {
03801     if ( val.canConvert( QVariant::Int ) )
03802       setMode( val.toInt() );
03803   }
03804   else if ( name == "fonts" || name == "families" )
03805   {
03806     if ( val.canConvert( QVariant::StringList ) )
03807       setFonts( val.toStringList() );
03808   }
03809   else if ( name == "sizes" )
03810   {
03811     if ( val.type() == QVariant::List )
03812     {
03813       QList<int> lst;
03814       QList<QVariant> varList = val.toList();
03815       for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it )
03816       {
03817         if ( (*it).canConvert( QVariant::Int ) )
03818           lst.append( (*it).toInt() );
03819       }
03820       setSizes( lst );
03821     }
03822   }
03823   else
03824     QtxPageNamedPrefItem::setOptionValue( name, val );
03825 }
03826 
03840 QtxPagePrefPathItem::QtxPagePrefPathItem( const Qtx::PathType type, const QString& title,
03841                                           QtxPreferenceItem* parent, const QString& sect, const QString& param )
03842 : QtxPageNamedPrefItem( title, parent, sect, param )
03843 {
03844   setControl( myPath = new QtxPathEdit( type ) );
03845 }
03846 
03854 QtxPagePrefPathItem::QtxPagePrefPathItem( const QString& title, QtxPreferenceItem* parent,
03855                                           const QString& sect, const QString& param )
03856 : QtxPageNamedPrefItem( title, parent, sect, param )
03857 {
03858   setControl( myPath = new QtxPathEdit() );
03859 }
03860 
03864 QtxPagePrefPathItem::~QtxPagePrefPathItem()
03865 {
03866 }
03867 
03873 Qtx::PathType QtxPagePrefPathItem::pathType() const
03874 {
03875   return myPath->pathType();
03876 }
03877 
03883 void QtxPagePrefPathItem::setPathType( const Qtx::PathType type )
03884 {
03885   myPath->setPathType( type );
03886 }
03887 
03893 QString QtxPagePrefPathItem::pathFilter() const
03894 {
03895   return myPath->pathFilter();
03896 }
03897 
03903 void QtxPagePrefPathItem::setPathFilter( const QString& f )
03904 {
03905   myPath->setPathFilter( f );
03906 }
03907 
03912 void QtxPagePrefPathItem::store()
03913 {
03914   setString( myPath->path() );
03915 }
03916 
03921 void QtxPagePrefPathItem::retrieve()
03922 {
03923   myPath->setPath( getString() );
03924 }
03925 
03932 QVariant QtxPagePrefPathItem::optionValue( const QString& name ) const
03933 {
03934   if ( name == "path_type" )
03935     return pathType();
03936   else if ( name == "path_filter" )
03937     return pathFilter();
03938   else
03939     return QtxPageNamedPrefItem::optionValue( name );
03940 }
03941 
03948 void QtxPagePrefPathItem::setOptionValue( const QString& name, const QVariant& val )
03949 {
03950   if ( name == "path_type" )
03951   {
03952     if ( val.canConvert( QVariant::Int ) )
03953       setPathType( (Qtx::PathType)val.toInt() );
03954   }
03955   else if ( name == "path_filter" )
03956   {
03957     if ( val.canConvert( QVariant::String ) )
03958       setPathFilter( val.toString() );
03959   }
03960   else
03961     QtxPageNamedPrefItem::setOptionValue( name, val );
03962 }
03963 
03975 QtxPagePrefPathListItem::QtxPagePrefPathListItem( QtxPreferenceItem* parent,
03976                                                   const QString& sect, const QString& param )
03977 : QtxPageNamedPrefItem( QString(), parent, sect, param )
03978 {
03979   setControl( myPaths = new QtxPathListEdit() );
03980 }
03981 
03990 QtxPagePrefPathListItem::QtxPagePrefPathListItem( const Qtx::PathType type, const QString& title,
03991                                                   QtxPreferenceItem* parent, const QString& sect, const QString& param )
03992 : QtxPageNamedPrefItem( title, parent, sect, param )
03993 {
03994   setControl( myPaths = new QtxPathListEdit( type ) );
03995 }
03996 
04004 QtxPagePrefPathListItem::QtxPagePrefPathListItem( const QString& title, QtxPreferenceItem* parent,
04005                                                   const QString& sect, const QString& param )
04006 : QtxPageNamedPrefItem( title, parent, sect, param )
04007 {
04008   setControl( myPaths = new QtxPathListEdit() );
04009 }
04010 
04014 QtxPagePrefPathListItem::~QtxPagePrefPathListItem()
04015 {
04016 }
04017 
04023 Qtx::PathType QtxPagePrefPathListItem::pathType() const
04024 {
04025   return myPaths->pathType();
04026 }
04027 
04033 void QtxPagePrefPathListItem::setPathType( const Qtx::PathType type )
04034 {
04035   myPaths->setPathType( type );
04036 }
04037 
04042 void QtxPagePrefPathListItem::store()
04043 {
04044   setString( myPaths->pathList().join( ";" ) );
04045 }
04046 
04051 void QtxPagePrefPathListItem::retrieve()
04052 {
04053   myPaths->setPathList( getString().split( ";" ) );
04054 }
04055 
04062 QVariant QtxPagePrefPathListItem::optionValue( const QString& name ) const
04063 {
04064   if ( name == "path_type" )
04065     return pathType();
04066   else
04067     return QtxPageNamedPrefItem::optionValue( name );
04068 }
04069 
04076 void QtxPagePrefPathListItem::setOptionValue( const QString& name, const QVariant& val )
04077 {
04078   if ( name == "path_type" )
04079   {
04080     if ( val.canConvert( QVariant::Int ) )
04081       setPathType( (Qtx::PathType)val.toInt() );
04082   }
04083   else
04084     QtxPageNamedPrefItem::setOptionValue( name, val );
04085 }
04086 
04102 QtxPagePrefDateTimeItem::QtxPagePrefDateTimeItem( const QString& title, QtxPreferenceItem* parent,
04103                                                   const QString& sect, const QString& param )
04104 : QtxPageNamedPrefItem( title, parent, sect, param ),
04105   myType( DateTime )
04106 {
04107   setControl( myDateTime = new QDateTimeEdit() );
04108   myDateTime->setCalendarPopup( true );
04109   myDateTime->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
04110   updateDateTime();
04111 }
04112 
04125 QtxPagePrefDateTimeItem::QtxPagePrefDateTimeItem( const int type, const QString& title, QtxPreferenceItem* parent,
04126                                                   const QString& sect, const QString& param )
04127 : QtxPageNamedPrefItem( title, parent, sect, param ),
04128   myType( type )
04129 {
04130   setControl( myDateTime = new QDateTimeEdit() );
04131   myDateTime->setCalendarPopup( true );
04132   myDateTime->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
04133   updateDateTime();
04134 }
04135 
04139 QtxPagePrefDateTimeItem::~QtxPagePrefDateTimeItem()
04140 {
04141 }
04142 
04148 int QtxPagePrefDateTimeItem::inputType() const
04149 {
04150   return myType;
04151 }
04152 
04158 void QtxPagePrefDateTimeItem::setInputType( const int type )
04159 {
04160   if ( myType == type )
04161     return;
04162 
04163   myType = type;
04164   updateDateTime();
04165 }
04166 
04171 bool QtxPagePrefDateTimeItem::calendar() const
04172 {
04173   return myDateTime->calendarPopup();
04174 }
04175 
04180 void QtxPagePrefDateTimeItem::setCalendar( const bool on )
04181 {
04182   myDateTime->setCalendarPopup( on );
04183 }
04184 
04190 QDate QtxPagePrefDateTimeItem::maximumDate() const
04191 {
04192   return myDateTime->maximumDate();
04193 }
04194 
04200 QTime QtxPagePrefDateTimeItem::maximumTime() const
04201 {
04202   return myDateTime->maximumTime();
04203 }
04204 
04210 QDate QtxPagePrefDateTimeItem::minimumDate() const
04211 {
04212   return myDateTime->minimumDate();
04213 }
04214 
04220 QTime QtxPagePrefDateTimeItem::minimumTime() const
04221 {
04222   return myDateTime->minimumTime();
04223 }
04224 
04230 void QtxPagePrefDateTimeItem::setMaximumDate( const QDate& d )
04231 {
04232   if ( d.isValid() )
04233     myDateTime->setMaximumDate( d );
04234   else
04235     myDateTime->clearMaximumDate();
04236 }
04237 
04243 void QtxPagePrefDateTimeItem::setMaximumTime( const QTime& t )
04244 {
04245   if ( t.isValid() )
04246     myDateTime->setMaximumTime( t );
04247   else
04248     myDateTime->clearMaximumTime();
04249 }
04250 
04256 void QtxPagePrefDateTimeItem::setMinimumDate( const QDate& d )
04257 {
04258   if ( d.isValid() )
04259     myDateTime->setMinimumDate( d );
04260   else
04261     myDateTime->clearMinimumDate();
04262 }
04263 
04269 void QtxPagePrefDateTimeItem::setMinimumTime( const QTime& t )
04270 {
04271   if ( t.isValid() )
04272     myDateTime->setMinimumTime( t );
04273   else
04274     myDateTime->clearMinimumTime();
04275 }
04276 
04281 void QtxPagePrefDateTimeItem::store()
04282 {
04283   QString str;
04284   switch ( inputType() )
04285   {
04286   case Date:
04287     str = myDateTime->date().toString( Qt::ISODate );
04288     break;
04289   case Time:
04290     str = myDateTime->time().toString( Qt::ISODate );
04291     break;
04292   case DateTime:
04293     str = myDateTime->dateTime().toString( Qt::ISODate );
04294     break;
04295   }
04296 
04297   setString( str );
04298 }
04299 
04304 void QtxPagePrefDateTimeItem::retrieve()
04305 {
04306   QString str = getString();
04307   switch ( inputType() )
04308   {
04309   case Date:
04310     myDateTime->setDate( QDate::fromString( str, Qt::ISODate ) );
04311     break;
04312   case Time:
04313     myDateTime->setTime( QTime::fromString( str, Qt::ISODate ) );
04314     break;
04315   case DateTime:
04316     myDateTime->setDateTime( QDateTime::fromString( str, Qt::ISODate ) );
04317     break;
04318   }
04319 }
04320 
04327 QVariant QtxPagePrefDateTimeItem::optionValue( const QString& name ) const
04328 {
04329   if ( name == "input_type" || name == "type" )
04330     return inputType();
04331   else if ( name == "minimum_date" || name == "min_date" )
04332     return minimumDate();
04333   else if ( name == "maximum_date" || name == "max_date" )
04334     return maximumDate();
04335   else if ( name == "minimum_time" || name == "min_time" )
04336     return minimumTime();
04337   else if ( name == "maximum_time" || name == "max_time" )
04338     return maximumTime();
04339   else
04340     return QtxPageNamedPrefItem::optionValue( name );
04341 }
04342 
04349 void QtxPagePrefDateTimeItem::setOptionValue( const QString& name, const QVariant& val )
04350 {
04351   if ( name == "input_type" || name == "type" )
04352   {
04353     if ( val.canConvert( QVariant::Int ) )
04354       setInputType( val.toInt() );
04355   }
04356   else if ( name == "minimum_date" || name == "min_date" )
04357   {
04358     if ( val.canConvert( QVariant::Date ) )
04359       setMinimumDate( val.toDate() );
04360   }
04361   else if ( name == "maximum_date" || name == "max_date" )
04362   {
04363     if ( val.canConvert( QVariant::Date ) )
04364       setMaximumDate( val.toDate() );
04365   }
04366   else if ( name == "minimum_time" || name == "min_time" )
04367   {
04368     if ( val.canConvert( QVariant::Time ) )
04369       setMinimumTime( val.toTime() );
04370   }
04371   else if ( name == "maximum_time" || name == "max_time" )
04372   {
04373     if ( val.canConvert( QVariant::Time ) )
04374       setMaximumTime( val.toTime() );
04375   }
04376   else
04377     QtxPageNamedPrefItem::setOptionValue( name, val );
04378 }
04379 
04383 void QtxPagePrefDateTimeItem::updateDateTime()
04384 {
04385   QString dispFmt;
04386   switch ( inputType() )
04387   {
04388   case Date:
04389     dispFmt = QDateEdit().displayFormat();
04390     break;
04391   case Time:
04392     dispFmt = QTimeEdit().displayFormat();
04393     break;
04394   case DateTime:
04395     dispFmt = QDateTimeEdit().displayFormat();
04396     break;
04397   }
04398 
04399   myDateTime->setDisplayFormat( dispFmt );
04400 }
04401 
04409 QtxPagePrefShortcutBtnsItem::QtxPagePrefShortcutBtnsItem( const QString& title, QtxPreferenceItem* parent, const QString& sect,
04410                                                           const QString& param ): QtxPageNamedPrefItem( title, parent, sect, param )
04411 {
04412   setControl( myShortcut = new QtxShortcutEdit() );
04413 }
04414 
04418 QtxPagePrefShortcutBtnsItem::~QtxPagePrefShortcutBtnsItem()
04419 {
04420 }
04421 
04426 void QtxPagePrefShortcutBtnsItem::store()
04427 {
04428   setString( myShortcut->shortcut().toString() );
04429 }
04430 
04435 void QtxPagePrefShortcutBtnsItem::retrieve()
04436 {
04437   myShortcut->setShortcut( QKeySequence::fromString( getString() ) );
04438 }
04439 
04450 QtxPagePrefShortcutTreeItem::QtxPagePrefShortcutTreeItem( const QString& title, QtxPreferenceItem* parent, const QString& sect, 
04451                                                           const QString& param ): QtxPageNamedPrefItem( title, parent, sect, "" )
04452 {
04453   mySection = sect;
04454 
04455   myShortcutTree = new QtxShortcutTree();
04456 
04457   // Retrieve shortcuts common sections from resources
04458   QtxResourceMgr* resMgr = resourceMgr();
04459   if ( resMgr ){
04460     QString generalSections = resourceMgr()->stringValue( "shortcuts_settings", "general_sections", QString() );
04461     QStringList sectionsList = generalSections.split( ";", QString::SkipEmptyParts );
04462     myShortcutTree->setGeneralSections( sectionsList );
04463   }
04464  
04465   setControl( myShortcutTree );
04466 }
04467 
04471 QtxPagePrefShortcutTreeItem::~QtxPagePrefShortcutTreeItem()
04472 {
04473 }
04474                                               
04479 void QtxPagePrefShortcutTreeItem::retrieve()
04480 {
04481   QtxResourceMgr* resMgr = resourceMgr();
04482   if ( resMgr ){
04483     QStringList secLst = resMgr->subSections( mySection, false );
04484     ShortcutMap aMap; QStringList paramLst;
04485     for( int i = 0; i < secLst.size(); i++ ) {
04486       paramLst = resMgr->parameters( QStringList() << mySection << secLst.at( i ) );
04487       for( int j = 0; j < paramLst.size(); j++ )
04488         resMgr->value( mySection + resMgr->sectionsToken() + secLst.at( i ), paramLst.at( j ),aMap[ paramLst.at( j ) ], false );
04489       myShortcutTree->setBindings( secLst.at( i ), aMap );
04490       aMap.clear();
04491     }
04492   }
04493 }
04494              
04499 void QtxPagePrefShortcutTreeItem::store()
04500 {
04501   QStringList lst = myShortcutTree->sections();
04502   QString aSection;
04503   QtxResourceMgr* resMgr = resourceMgr();
04504   
04505   if ( resMgr ) {
04506     for( int i = 0; i < lst.size(); i++ ) {
04507       ShortcutMap* aMap( myShortcutTree->bindings( lst.at( i ) ) );
04508       aSection = mySection + resMgr->sectionsToken() + lst.at( i );
04509       for( ShortcutMap::const_iterator it = aMap->constBegin(); it != aMap->constEnd(); ++it )
04510        resMgr->setValue( aSection, it.key(), it.value() );
04511     }
04512   }
04513 }
04514 
04544 QtxPagePrefBackgroundItem::QtxPagePrefBackgroundItem( const QString& title, QtxPreferenceItem* parent,
04545                                                 const QString& sect, const QString& param )
04546 : QtxPageNamedPrefItem( title, parent, sect, param )
04547 {
04548   setControl( myBgTool = new QtxBackgroundTool( 0 ) );
04549 }
04550 
04554 QtxPagePrefBackgroundItem::~QtxPagePrefBackgroundItem()
04555 {
04556 }
04557 
04563 void QtxPagePrefBackgroundItem::gradients( QStringList& gradList, QIntList& idList ) const
04564 {
04565   myBgTool->gradients( gradList, idList );
04566 }
04567 
04573 void QtxPagePrefBackgroundItem::setGradients( const QStringList& gradients, const QIntList& ids )
04574 {
04575   myBgTool->setGradients( gradients, ids );
04576 }
04577 
04584 bool QtxPagePrefBackgroundItem::isModeAllowed( Qtx::BackgroundMode mode ) const
04585 {
04586   return myBgTool->isModeAllowed( mode );
04587 }
04588 
04595 void QtxPagePrefBackgroundItem::setModeAllowed( Qtx::BackgroundMode mode, bool on )
04596 {
04597   myBgTool->setModeAllowed( mode, on );
04598 }
04599 
04606 bool QtxPagePrefBackgroundItem::isTextureModeAllowed( Qtx::TextureMode mode ) const
04607 {
04608   return myBgTool->isTextureModeAllowed( mode );
04609 }
04610 
04617 void QtxPagePrefBackgroundItem::setTextureModeAllowed( Qtx::TextureMode mode, bool on )
04618 {
04619   myBgTool->setTextureModeAllowed( mode, on );
04620 }
04621 
04627 bool QtxPagePrefBackgroundItem::isTextureAllowed() const
04628 {
04629   return myBgTool->isTextureAllowed();
04630 }
04631 
04637 void QtxPagePrefBackgroundItem::setTextureAllowed( bool on )
04638 {
04639   myBgTool->setTextureAllowed( on );
04640 }
04641 
04646 QString QtxPagePrefBackgroundItem::imageFormats() const
04647 {
04648   return myBgTool->imageFormats();
04649 }
04650 
04655 void QtxPagePrefBackgroundItem::setImageFormats( const QString& formats )
04656 {
04657   myBgTool->setImageFormats( formats );
04658 }
04659 
04664 Qt::Orientation QtxPagePrefBackgroundItem::orientation() const
04665 {
04666   return myBgTool->orientation();
04667 }
04668 
04673 void QtxPagePrefBackgroundItem::setOrientation( Qt::Orientation o )
04674 {
04675   myBgTool->setOrientation( o );
04676 }
04677 
04682 void QtxPagePrefBackgroundItem::store()
04683 {
04684   setString( Qtx::backgroundToString( myBgTool->data() ) );
04685 }
04686 
04691 void QtxPagePrefBackgroundItem::retrieve()
04692 {
04693   myBgTool->setData( Qtx::stringToBackground( getString() ) );
04694 }
04695 
04702 QVariant QtxPagePrefBackgroundItem::optionValue( const QString& name ) const
04703 {
04704   if ( name == "texture_enabled" )
04705     return isTextureAllowed();
04706   else if ( name == "color_enabled" )
04707     return isModeAllowed( Qtx::ColorBackground );
04708   else if ( name == "gradient_enabled" )
04709     return isModeAllowed( Qtx::SimpleGradientBackground );
04710   else if ( name == "custom_enabled" )
04711     return isModeAllowed( Qtx::CustomGradientBackground );
04712   else if ( name == "texture_center_enabled" )
04713     return isTextureModeAllowed( Qtx::CenterTexture );
04714   else if ( name == "texture_tile_enabled" )
04715     return isTextureModeAllowed( Qtx::TileTexture );
04716   else if ( name == "texture_stretch_enabled" )
04717     return isTextureModeAllowed( Qtx::StretchTexture );
04718   else if ( name == "orientation" )
04719     return orientation();
04720   else if ( name == "image_formats" )
04721     return imageFormats();
04722   else if ( name == "gradient_names" ) {
04723     QStringList grList;
04724     QIntList    idList;
04725     gradients( grList, idList );
04726     return grList;
04727   }
04728   else if ( name == "gradient_ids" ) {
04729     QStringList grList;
04730     QIntList    idList;
04731     gradients( grList, idList );
04732     QList<QVariant> lst;
04733     for ( QIntList::const_iterator it = idList.begin(); it != idList.end(); ++it )
04734       lst.append( *it );
04735     return lst;
04736   }
04737   else
04738     return QtxPageNamedPrefItem::optionValue( name );
04739 }
04740 
04747 void QtxPagePrefBackgroundItem::setOptionValue( const QString& name, const QVariant& val )
04748 {
04749   if ( name == "texture_enabled" ) {
04750     if ( val.canConvert( QVariant::Bool ) )
04751       setTextureAllowed( val.toBool() );
04752   }
04753   else if ( name == "color_enabled" ) {
04754     if ( val.canConvert( QVariant::Bool ) )
04755       setModeAllowed( Qtx::ColorBackground, val.toBool() );
04756   }
04757   else if ( name == "gradient_enabled" ) {
04758     if ( val.canConvert( QVariant::Bool ) )
04759       setModeAllowed( Qtx::SimpleGradientBackground, val.toBool() );
04760   }
04761   else if ( name == "custom_enabled" ) {
04762     if ( val.canConvert( QVariant::Bool ) )
04763       setModeAllowed( Qtx::CustomGradientBackground, val.toBool() );
04764   }
04765   else if ( name == "texture_center_enabled" ) {
04766     if ( val.canConvert( QVariant::Bool ) )
04767       setTextureModeAllowed( Qtx::CenterTexture, val.toBool() );
04768   }
04769   else if ( name == "texture_tile_enabled" ) {
04770     if ( val.canConvert( QVariant::Bool ) )
04771       setTextureModeAllowed( Qtx::TileTexture, val.toBool() );
04772   }
04773   else if ( name == "texture_stretch_enabled" ) {
04774     if ( val.canConvert( QVariant::Bool ) )
04775       setTextureModeAllowed( Qtx::StretchTexture, val.toBool() );
04776   }
04777   else if ( name == "orientation" ) {
04778     if ( val.canConvert( QVariant::Int ) )
04779       setOrientation( (Qt::Orientation)val.toInt() );
04780   }
04781   else if ( name == "image_formats" ) {
04782     if ( val.canConvert( QVariant::String ) )
04783       setImageFormats( val.toString() );
04784   }
04785   else if ( name == "gradient_names" ) {
04786     if ( val.canConvert( QVariant::StringList ) )
04787       setGradients( val.toStringList() );
04788   }
04789   else if ( name == "gradient_ids" ) {
04790     if ( val.canConvert( QVariant::List ) ) {
04791       QStringList grList;
04792       QIntList    idList;
04793       gradients( grList, idList );
04794       idList.clear();
04795       QList<QVariant> varList = val.toList();
04796       for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it ) {
04797        if ( (*it).canConvert( QVariant::Int ) )
04798          idList.append( (*it).toInt() );
04799       }
04800       setGradients( grList, idList );
04801     }
04802   }
04803   else
04804     QtxPageNamedPrefItem::setOptionValue( name, val );
04805 }
04806 
04817 QtxUserDefinedItem::QtxUserDefinedItem( QtxPreferenceItem* parent )
04818   : QtxPageNamedPrefItem(QString(), parent), myContent(0)
04819 {
04820 }
04821   
04826 void QtxUserDefinedItem::store()
04827 {
04828   if (myContent) {
04829     myContent->store( resourceMgr(), preferenceMgr());
04830   }
04831 }
04832 
04837 void QtxUserDefinedItem::retrieve()
04838 {
04839   if (myContent) {
04840     myContent->retrieve( resourceMgr(), preferenceMgr());
04841   }
04842 }
04843 
04849 QVariant QtxUserDefinedItem::optionValue( const QString& theName ) const
04850 {
04851   if ( theName == "content" )
04852     return (qint64) myContent;
04853   else
04854     return QtxPreferenceItem::optionValue( theName );
04855 }
04856 
04862 void QtxUserDefinedItem::setOptionValue( const QString& theName, const QVariant& theVal)
04863 {
04864   if ( theName == "content" ) {
04865     if ( theVal.canConvert( QVariant::ULongLong ) ) {
04866       setContent( (QtxUserDefinedContent*)theVal.toULongLong() );
04867     }
04868   } else
04869     QtxPreferenceItem::setOptionValue( theName, theVal );
04870 }
04871   
04877 void QtxUserDefinedItem::setContent( QtxUserDefinedContent* theContent ) 
04878 { 
04879   myContent = theContent; 
04880   setControl(myContent);
04881 }