1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: QtxPagePrefMgr.cxx
23 // Author: Sergey TELKOV
25 #include "QtxPagePrefMgr.h"
27 #include "QtxGridBox.h"
28 #include "QtxFontEdit.h"
29 #include "QtxGroupBox.h"
30 #include "QtxComboBox.h"
31 #include "QtxIntSpinBox.h"
32 #include "QtxColorButton.h"
33 #include "QtxDoubleSpinBox.h"
43 #include <QListWidget>
44 #include <QApplication>
45 #include <QDateTimeEdit>
46 #include <QStackedWidget>
50 \brief GUI implementation of the QtxPreferenceMgr class: preferences manager.
55 \param resMgr resource manager
56 \param parent parent widget
58 QtxPagePrefMgr::QtxPagePrefMgr( QtxResourceMgr* resMgr, QWidget* parent )
60 QtxPreferenceMgr( resMgr ),
63 myBox = new QtxGridBox( 1, Qt::Horizontal, this, 0 );
64 QVBoxLayout* base = new QVBoxLayout( this );
66 base->setSpacing( 0 );
67 base->addWidget( myBox );
73 QtxPagePrefMgr::~QtxPagePrefMgr()
78 \brief Get recommended size for the widget.
79 \return recommended widget size
81 QSize QtxPagePrefMgr::sizeHint() const
83 return QFrame::sizeHint();
87 \brief Get recommended minimum size for the widget.
88 \return recommended minimum widget size
90 QSize QtxPagePrefMgr::minimumSizeHint() const
92 return QFrame::minimumSizeHint();
96 \brief Customize show/hide widget operation.
97 \param on if \c true the widget is being shown, otherswise
100 void QtxPagePrefMgr::setVisible( bool on )
105 QApplication::instance()->processEvents();
107 QFrame::setVisible( on );
111 \brief Update widget contents.
113 void QtxPagePrefMgr::updateContents()
115 QtxPreferenceMgr::updateContents();
117 QList<QtxPreferenceItem*> lst = childItems();
118 for ( QList<QtxPreferenceItem*>::const_iterator it = lst.begin(); it != lst.end(); ++it )
120 QtxPagePrefItem* item = dynamic_cast<QtxPagePrefItem*>( *it );
121 if ( item && item->widget() && item->widget()->parent() != myBox )
122 item->widget()->setParent( myBox );
125 setWindowIcon( icon() );
129 \brief Callback function which is called when the child
130 preference item is added.
131 \param item child item being added
132 \sa itemRemoved(), itemChanged()
134 void QtxPagePrefMgr::itemAdded( QtxPreferenceItem* /*item*/ )
140 \brief Callback function which is called when the child
141 preference item is removed.
142 \param item child item being removed
143 \sa itemAdded(), itemChanged()
145 void QtxPagePrefMgr::itemRemoved( QtxPreferenceItem* /*item*/ )
151 \brief Callback function which is called when the child
152 preference item is modified.
153 \param item child item being modified
154 \sa itemAdded(), itemRemoved()
156 void QtxPagePrefMgr::itemChanged( QtxPreferenceItem* /*item*/ )
162 \brief Get preference item option value.
163 \param name option name
164 \return property value or null QVariant if option is not set
167 QVariant QtxPagePrefMgr::optionValue( const QString& name ) const
169 if ( name == "orientation" )
170 return myBox->orientation() == Qt::Horizontal ? Qt::Vertical : Qt::Horizontal;
172 return QtxPreferenceMgr::optionValue( name );
176 \brief Set preference item option value.
177 \param name option name
178 \param val new property value
181 void QtxPagePrefMgr::setOptionValue( const QString& name, const QVariant& val )
183 if ( name == "orientation" )
185 if ( val.canConvert( QVariant::Int ) )
186 myBox->setOrientation( val.toInt() == Qt::Horizontal ? Qt::Vertical : Qt::Horizontal );
189 QtxPreferenceMgr::setOptionValue( name, val );
193 \brief Perform internal initialization.
195 void QtxPagePrefMgr::initialize() const
200 QtxPagePrefMgr* that = (QtxPagePrefMgr*)this;
201 that->initialize( that );
203 // that->myInit = true;
206 void QtxPagePrefMgr::initialize( QtxPreferenceItem* item )
211 QList<QtxPreferenceItem*> lst = item->childItems( false );
212 for ( QList<QtxPreferenceItem*>::iterator it = lst.begin(); it != lst.end(); ++it )
219 \class QtxPagePrefItem
220 \brief Base class for implementation of all the widget-based
224 class QtxPagePrefItem::Listener : public QObject
227 Listener( QtxPagePrefItem* );
230 virtual bool eventFilter( QObject*, QEvent* );
233 QtxPagePrefItem* myItem;
236 QtxPagePrefItem::Listener::Listener( QtxPagePrefItem* item )
242 QtxPagePrefItem::Listener::~Listener()
246 bool QtxPagePrefItem::Listener::eventFilter( QObject* o, QEvent* e )
248 if ( !myItem || myItem->widget() != o )
251 if ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent )
252 myItem->widgetShown();
253 if ( e->type() == QEvent::Hide || e->type() == QEvent::HideToParent )
254 myItem->widgetHided();
261 \param title preference item title
262 \param parent parent preference item
263 \param sect resource file section associated with the preference item
264 \param param resource file parameter associated with the preference item
266 QtxPagePrefItem::QtxPagePrefItem( const QString& title, QtxPreferenceItem* parent,
267 const QString& sect, const QString& param )
268 : QtxPreferenceItem( title, sect, param, parent ),
277 QtxPagePrefItem::~QtxPagePrefItem()
283 void QtxPagePrefItem::activate()
285 QtxPreferenceItem::activate();
288 widget()->setFocus();
292 \brief Get preference item editor widget.
293 \return editor widget
296 QWidget* QtxPagePrefItem::widget() const
302 \brief Set preference item editor widget.
303 \param wid editor widget
306 void QtxPagePrefItem::setWidget( QWidget* wid )
308 if ( myWidget && myListener )
309 myWidget->removeEventFilter( myListener );
316 myListener = new Listener( this );
317 myWidget->installEventFilter( myListener );
324 \brief Callback function which is called when the child
325 preference item is added.
326 \param item child item being added
327 \sa itemRemoved(), itemChanged()
329 void QtxPagePrefItem::itemAdded( QtxPreferenceItem* /*item*/ )
335 \brief Callback function which is called when the child
336 preference item is removed.
337 \param item child item being removed
338 \sa itemAdded(), itemChanged()
340 void QtxPagePrefItem::itemRemoved( QtxPreferenceItem* /*item*/ )
346 \brief Callback function which is called when the child
347 preference item is modified.
348 \param item child item being modified
349 \sa itemAdded(), itemRemoved()
351 void QtxPagePrefItem::itemChanged( QtxPreferenceItem* /*item*/ )
357 \brief Store preference item to the resource manager.
359 This method should be reimplemented in the subclasses.
360 Base implementation does nothing.
364 void QtxPagePrefItem::store()
369 \brief Retrieve preference item from the resource manager.
371 This method should be reimplemented in the subclasses.
372 Base implementation does nothing.
376 void QtxPagePrefItem::retrieve()
381 \brief Invoked when preference item widget is shown.
383 void QtxPagePrefItem::widgetShown()
388 \brief Invoked when preference item widget is hided.
390 void QtxPagePrefItem::widgetHided()
394 void QtxPagePrefItem::ensureVisible( QtxPreferenceItem* i )
396 QtxPreferenceItem::ensureVisible();
398 QtxPagePrefItem* item = dynamic_cast<QtxPagePrefItem*>( i );
399 if ( item && item->widget() )
400 item->widget()->setVisible( true );
404 \brief Find all child items of the QtxPagePrefItem type.
405 \param list used to return list of child items
406 \param rec if \c true, perform recursive search
408 void QtxPagePrefItem::pageChildItems( QList<QtxPagePrefItem*>& list, const bool rec ) const
410 QList<QtxPreferenceItem*> lst = childItems( rec );
411 for ( QList<QtxPreferenceItem*>::const_iterator it = lst.begin(); it != lst.end(); ++it )
413 QtxPagePrefItem* item = dynamic_cast<QtxPagePrefItem*>( *it );
420 \brief Called when contents is changed (item is added, removed or modified).
422 Triggers the item update.
424 void QtxPagePrefItem::contentChanged()
430 \class QtxPageNamedPrefItem
431 \brief Base class for implementation of the named preference items
432 (items with text labels).
437 \param title preference item title
438 \param parent parent preference item
439 \param sect resource file section associated with the preference item
440 \param param resource file parameter associated with the preference item
442 QtxPageNamedPrefItem::QtxPageNamedPrefItem( const QString& title, QtxPreferenceItem* parent,
443 const QString& sect, const QString& param )
444 : QtxPagePrefItem( title, parent, sect, param ),
447 QWidget* main = new QWidget();
449 // QtxPagePrefGroupItem* aGroup = 0;//dynamic_cast<QtxPagePrefGroupItem*>(parent);
452 QHBoxLayout* base = new QHBoxLayout( main );
453 base->setMargin( 0 );
454 base->setSpacing( 5 );
456 myLabel = new QLabel( title, main );
457 base->addWidget( myLabel );
460 // myLabel = new QLabel( title, aGroup->gridBox() );
464 myLabel->setVisible( !title.isEmpty() );
470 QtxPageNamedPrefItem::~QtxPageNamedPrefItem()
475 \brief Set preference title.
476 \param txt new preference title.
478 void QtxPageNamedPrefItem::setTitle( const QString& txt )
480 QtxPagePrefItem::setTitle( txt );
482 label()->setText( title() );
483 if ( !title().isEmpty() )
484 label()->setVisible( true );
488 \brief Get label widget corresponding to the preference item.
491 QLabel* QtxPageNamedPrefItem::label() const
497 \brief Get control widget corresponding to the preference item.
498 \return control widget
501 QWidget* QtxPageNamedPrefItem::control() const
507 \brief Set control widget corresponding to the preference item.
508 \param wid control widget
511 void QtxPageNamedPrefItem::setControl( QWidget* wid )
513 if ( myControl == wid )
521 // QtxPagePrefGroupItem* aGroup = 0;//dynamic_cast<QtxPagePrefGroupItem*>(parentItem());
523 widget()->layout()->addWidget( myControl );
524 widget()->setFocusProxy( myControl );
525 // else myControl->setParent( aGroup->gridBox() );
529 void QtxPageNamedPrefItem::adjustLabels( QtxPagePrefItem* parent )
534 QList<QtxPreferenceItem*> childList = parent->childItems();
536 QList<QtxPageNamedPrefItem*> namedItems;
537 for ( QList<QtxPreferenceItem*>::iterator it = childList.begin(); it != childList.end(); ++it )
539 QtxPageNamedPrefItem* item = dynamic_cast<QtxPageNamedPrefItem*>( *it );
541 namedItems.append( item );
545 for ( QList<QtxPageNamedPrefItem*>::iterator it1 = namedItems.begin(); it1 != namedItems.end(); ++it1 )
547 QtxPageNamedPrefItem* item = *it1;
549 sz = qMax( sz, item->label()->sizeHint().width() );
552 for ( QList<QtxPageNamedPrefItem*>::iterator it2 = namedItems.begin(); it2 != namedItems.end(); ++it2 )
554 QtxPageNamedPrefItem* item = *it2;
556 item->label()->setMinimumWidth( sz );
561 \class QtxPagePrefListItem
562 \brief GUI implementation of the list container preference item.
567 \param title preference item title
568 \param parent parent preference item
569 \param sect resource file section associated with the preference item
570 \param param resource file parameter associated with the preference item
572 QtxPagePrefListItem::QtxPagePrefListItem( const QString& title, QtxPreferenceItem* parent,
573 const QString& sect, const QString& param )
574 : QtxPagePrefItem( title, parent, sect, param ),
577 QSplitter* main = new QSplitter( Qt::Horizontal );
578 main->setChildrenCollapsible( false );
580 main->addWidget( myList = new QListWidget( main ) );
581 main->addWidget( myStack = new QStackedWidget( main ) );
583 myList->setSelectionMode( QListWidget::SingleSelection );
585 myStack->addWidget( myInfLabel = new QLabel( myStack ) );
586 myInfLabel->setAlignment( Qt::AlignCenter );
588 connect( myList, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) );
596 QtxPagePrefListItem::~QtxPagePrefListItem()
601 \brief Get message text which is shown if the container is empty.
605 QString QtxPagePrefListItem::emptyInfo() const
611 \brief Set message text which is shown if the container is empty.
612 \param new message text
615 void QtxPagePrefListItem::setEmptyInfo( const QString& inf )
617 if ( myInfText == inf )
626 \brief Check if the preference item widget is of fixed size.
627 \return \c true if the widget has the fixed size
630 bool QtxPagePrefListItem::isFixedSize() const
636 \brief Set the preference item widget to be of fixed size.
637 \param on if \c true, the widget will have the fixed size
640 void QtxPagePrefListItem::setFixedSize( const bool on )
651 \brief Update widget contents.
653 void QtxPagePrefListItem::updateContents()
655 QtxPagePrefItem::updateContents();
660 \brief Get preference item option value.
661 \param name option name
662 \return property value or null QVariant if option is not set
665 QVariant QtxPagePrefListItem::optionValue( const QString& name ) const
667 if ( name == "fixed_size" )
668 return isFixedSize();
669 else if ( name == "empty_info" || name == "info" )
672 return QtxPagePrefItem::optionValue( name );
676 \brief Set preference item option value.
677 \param name option name
678 \param val new property value
681 void QtxPagePrefListItem::setOptionValue( const QString& name, const QVariant& val )
683 if ( name == "fixed_size" )
685 if ( val.canConvert( QVariant::Bool ) )
686 setFixedSize( val.toBool() );
688 else if ( name == "empty_info" || name == "info" )
690 if ( val.canConvert( QVariant::String ) )
691 setEmptyInfo( val.toString() );
694 QtxPagePrefItem::setOptionValue( name, val );
697 void QtxPagePrefListItem::widgetShown()
702 void QtxPagePrefListItem::ensureVisible( QtxPreferenceItem* i )
707 QtxPreferenceItem::ensureVisible( i );
709 setSelected( i->id() );
714 \brief Called when the selection in the list box is changed.
716 void QtxPagePrefListItem::onItemSelectionChanged()
722 \brief Update information label widget.
724 void QtxPagePrefListItem::updateInfo()
727 QtxPagePrefItem* item = selectedItem();
730 infoText = emptyInfo();
731 QRegExp rx( "%([%|N])" );
734 while ( ( idx = rx.indexIn( infoText ) ) != -1 )
736 if ( rx.cap() == QString( "%%" ) )
737 infoText.replace( idx, rx.matchedLength(), "%" );
738 else if ( rx.cap() == QString( "%N" ) )
739 infoText.replace( idx, rx.matchedLength(), item->title() );
742 myInfLabel->setText( infoText );
746 \brief Update widget state.
748 void QtxPagePrefListItem::updateState()
750 QtxPagePrefItem* item = selectedItem();
751 QWidget* wid = item && !item->isEmpty() ? item->widget() : myInfLabel;
753 myStack->setCurrentWidget( wid );
759 \brief Update visibile child widgets.
761 void QtxPagePrefListItem::updateVisible()
763 QList<QtxPagePrefItem*> items;
764 pageChildItems( items );
766 QMap<QWidget*, int> map;
767 for ( int i = 0; i < (int)myStack->count(); i++ )
768 map.insert( myStack->widget( i ), 0 );
770 int selId = selected();
772 for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end(); ++it )
774 if ( (*it)->isEmpty() && myInfText.isEmpty() )
777 myList->addItem( (*it)->title() );
778 myList->item( myList->count() - 1 )->setIcon( (*it)->icon() );
779 myList->item( myList->count() - 1 )->setData( Qt::UserRole, (*it)->id() );
781 QWidget* wid = (*it)->widget();
782 if ( !map.contains( wid ) )
783 myStack->addWidget( wid );
788 map.remove( myInfLabel );
790 for ( QMap<QWidget*, int>::const_iterator it = map.begin(); it != map.end(); ++it )
791 myStack->removeWidget( it.key() );
793 setSelected( selId );
794 if ( selected() == -1 && myList->count() )
795 setSelected( myList->item( 0 )->data( Qt::UserRole ).toInt() );
797 //myList->setVisible( myList->count() > 1 );
804 \brief Update widget geometry.
806 void QtxPagePrefListItem::updateGeom()
809 myList->setFixedWidth( myList->minimumSizeHint().width() + 10 );
812 myList->setMinimumWidth( 0 );
813 myList->setMaximumWidth( 16777215 );
815 QSplitter* s = ::qobject_cast<QSplitter*>( widget() );
818 int w = myList->minimumSizeHint().width() + 30;
821 szList.append( s->width() - w );
822 s->setSizes( szList );
828 \brief Get identifier of the currently selected preference item.
829 \return identifier of the currently selected item or -1 if no item is selected
832 int QtxPagePrefListItem::selected() const
834 QList<QListWidgetItem*> selList = myList->selectedItems();
835 if ( selList.isEmpty() )
838 QVariant v = selList.first()->data( Qt::UserRole );
839 return v.canConvert( QVariant::Int ) ? v.toInt() : -1;
843 \brief Get currently selected preference item.
844 \return currently selected item or 0 if no item is selected
847 QtxPagePrefItem* QtxPagePrefListItem::selectedItem() const
849 int selId = selected();
851 QList<QtxPagePrefItem*> items;
852 pageChildItems( items );
854 QtxPagePrefItem* item = 0;
855 for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end() && !item; ++it )
857 if ( (*it)->id() == selId )
864 \brief Set currently selected preference item.
865 \param id identifier of the preference item to make selected
867 void QtxPagePrefListItem::setSelected( const int id )
870 for ( int i = 0; i < (int)myList->count() && idx < 0; i++ )
872 QVariant v = myList->item( i )->data( Qt::UserRole );
873 if ( v.canConvert( QVariant::Int ) && v.toInt() == id )
878 QItemSelectionModel* selModel = myList->selectionModel();
881 sel.select( myList->model()->index( idx, 0 ), myList->model()->index( idx, 0 ) );
883 selModel->select( sel, QItemSelectionModel::ClearAndSelect );
887 \class QtxPagePrefToolBoxItem
888 \brief GUI implementation of the tool box container preference item.
893 \param title preference item title
894 \param parent parent preference item
895 \param sect resource file section associated with the preference item
896 \param param resource file parameter associated with the preference item
898 QtxPagePrefToolBoxItem::QtxPagePrefToolBoxItem( const QString& title, QtxPreferenceItem* parent,
899 const QString& sect, const QString& param )
900 : QtxPagePrefItem( title, parent, sect, param )
902 setWidget( myToolBox = new QToolBox( 0 ) );
908 QtxPagePrefToolBoxItem::~QtxPagePrefToolBoxItem()
913 \brief Update widget contents.
915 void QtxPagePrefToolBoxItem::updateContents()
917 QtxPagePrefItem::updateContents();
922 \brief Update tool box widget.
924 void QtxPagePrefToolBoxItem::updateToolBox()
926 QList<QtxPagePrefItem*> items;
927 pageChildItems( items );
929 QWidget* cur = myToolBox->currentWidget();
932 QMap<QWidget*, int> map;
933 for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end(); ++it )
935 QWidget* wid = (*it)->widget();
939 if ( myToolBox->widget( i ) != wid )
941 if ( myToolBox->indexOf( wid ) != -1 )
942 myToolBox->removeItem( myToolBox->indexOf( wid ) );
944 myToolBox->insertItem( i, wid, (*it)->title() );
947 myToolBox->setItemText( i, (*it)->title() );
949 myToolBox->setItemIcon( i, (*it)->icon() );
952 map.insert( wid, 0 );
956 for ( int idx = 0; idx < (int)myToolBox->count(); idx++ )
958 QWidget* w = myToolBox->widget( idx );
959 if ( !map.contains( w ) )
963 for ( QList<QWidget*>::const_iterator itr = del.begin(); itr != del.end(); ++itr )
964 myToolBox->removeItem( myToolBox->indexOf( *itr ) );
967 myToolBox->setCurrentWidget( cur );
970 void QtxPagePrefToolBoxItem::ensureVisible( QtxPreferenceItem* i )
975 QtxPreferenceItem::ensureVisible( i );
977 QtxPagePrefItem* item = dynamic_cast<QtxPagePrefItem*>( i );
978 if ( item && item->widget() )
979 myToolBox->setCurrentWidget( item->widget() );
983 \class QtxPagePrefTabsItem
984 \brief GUI implementation of the tab widget container.
989 \param title preference item title
990 \param parent parent preference item
991 \param sect resource file section associated with the preference item
992 \param param resource file parameter associated with the preference item
994 QtxPagePrefTabsItem::QtxPagePrefTabsItem( const QString& title, QtxPreferenceItem* parent,
995 const QString& sect, const QString& param )
996 : QtxPagePrefItem( title, parent, sect, param )
998 setWidget( myTabs = new QTabWidget( 0 ) );
1004 QtxPagePrefTabsItem::~QtxPagePrefTabsItem()
1009 \brief Update widget contents.
1011 void QtxPagePrefTabsItem::updateContents()
1013 QtxPagePrefItem::updateContents();
1018 \brief Get tabs position.
1019 \return current tabs position (QTabWidget::TabPosition)
1020 \sa setTabPosition()
1022 int QtxPagePrefTabsItem::tabPosition() const
1024 return myTabs->tabPosition();
1028 \brief Set tabs position.
1029 \param tp new tabs position (QTabWidget::TabPosition)
1032 void QtxPagePrefTabsItem::setTabPosition( const int tp )
1034 myTabs->setTabPosition( (QTabWidget::TabPosition)tp );
1038 \brief Get tabs shape.
1039 \return current tabs shape (QTabWidget::TabShape)
1042 int QtxPagePrefTabsItem::tabShape() const
1044 return myTabs->tabShape();
1048 \brief Set tabs shape.
1049 \param ts new tabs shape (QTabWidget::TabShape)
1052 void QtxPagePrefTabsItem::setTabShape( const int ts )
1054 myTabs->setTabShape( (QTabWidget::TabShape)ts );
1058 \brief Get tabs icon size.
1059 \return current tabs icon size
1060 \sa setTabIconSize()
1062 QSize QtxPagePrefTabsItem::tabIconSize() const
1064 return myTabs->iconSize();
1068 \brief Set tabs icon size.
1069 \param sz new tabs icon size
1072 void QtxPagePrefTabsItem::setTabIconSize( const QSize& sz )
1074 myTabs->setIconSize( sz );
1078 \brief Get preference item option value.
1079 \param name option name
1080 \return property value or null QVariant if option is not set
1081 \sa setOptionValue()
1083 QVariant QtxPagePrefTabsItem::optionValue( const QString& name ) const
1085 if ( name == "position" )
1086 return tabPosition();
1087 else if ( name == "shape" )
1089 else if ( name == "icon_size" )
1090 return tabIconSize();
1092 return QtxPagePrefItem::optionValue( name );
1096 \brief Set preference item option value.
1097 \param name option name
1098 \param val new property value
1101 void QtxPagePrefTabsItem::setOptionValue( const QString& name, const QVariant& val )
1103 if ( name == "position" )
1105 if ( val.canConvert( QVariant::Int ) )
1106 setTabPosition( val.toInt() );
1108 else if ( name == "shape" )
1110 if ( val.canConvert( QVariant::Int ) )
1111 setTabShape( val.toInt() );
1113 else if ( name == "icon_size" )
1115 if ( val.canConvert( QVariant::Size ) )
1116 setTabIconSize( val.toSize() );
1119 QtxPagePrefItem::setOptionValue( name, val );
1122 void QtxPagePrefTabsItem::ensureVisible( QtxPreferenceItem* i )
1127 QtxPreferenceItem::ensureVisible( i );
1129 QtxPagePrefItem* item = dynamic_cast<QtxPagePrefItem*>( i );
1130 if ( item && item->widget() )
1131 myTabs->setCurrentWidget( item->widget() );
1137 void QtxPagePrefTabsItem::updateTabs()
1139 QList<QtxPagePrefItem*> items;
1140 pageChildItems( items );
1142 QWidget* cur = myTabs->currentWidget();
1145 QMap<QWidget*, int> map;
1146 for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end(); ++it )
1148 QWidget* wid = (*it)->widget();
1152 if ( myTabs->widget( i ) != wid )
1154 if ( myTabs->indexOf( wid ) != -1 )
1155 myTabs->removeTab( myTabs->indexOf( wid ) );
1157 myTabs->insertTab( i, wid, (*it)->title() );
1160 myTabs->setTabText( i, (*it)->title() );
1162 myTabs->setTabIcon( i, (*it)->icon() );
1165 map.insert( wid, 0 );
1168 QList<QWidget*> del;
1169 for ( int idx = 0; idx < (int)myTabs->count(); idx++ )
1171 QWidget* w = myTabs->widget( idx );
1172 if ( !map.contains( w ) )
1176 for ( QList<QWidget*>::const_iterator itr = del.begin(); itr != del.end(); ++itr )
1177 myTabs->removeTab( myTabs->indexOf( *itr ) );
1180 myTabs->setCurrentWidget( cur );
1184 \class QtxPagePrefFrameItem
1185 \brief GUI implementation of the frame widget container.
1190 \param title preference item title
1191 \param parent parent preference item
1192 \param sect resource file section associated with the preference item
1193 \param param resource file parameter associated with the preference item
1195 QtxPagePrefFrameItem::QtxPagePrefFrameItem( const QString& title, QtxPreferenceItem* parent,
1196 const QString& sect, const QString& param )
1197 : QtxPagePrefItem( title, parent, sect, param )
1199 QWidget* main = new QWidget();
1200 QVBoxLayout* base = new QVBoxLayout( main );
1201 base->setMargin( 0 );
1202 base->setSpacing( 0 );
1204 base->addWidget( myBox = new QtxGridBox( 1, Qt::Horizontal, main, 5, 5 ) );
1205 base->addItem( new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
1213 QtxPagePrefFrameItem::~QtxPagePrefFrameItem()
1218 \brief Update widget contents.
1220 void QtxPagePrefFrameItem::updateContents()
1222 QtxPagePrefItem::updateContents();
1226 QtxPageNamedPrefItem::adjustLabels( this );
1230 \brief Get frame margin.
1231 \return current frame margin
1234 int QtxPagePrefFrameItem::margin() const
1236 return myBox->insideMargin();
1240 \brief Get frame margin.
1241 \param m new frame margin
1244 void QtxPagePrefFrameItem::setMargin( const int m )
1246 myBox->setInsideMargin( m );
1250 \brief Get frame spacing.
1251 \return current frame spacing
1254 int QtxPagePrefFrameItem::spacing() const
1256 return myBox->insideSpacing();
1260 \brief Set frame spacing.
1261 \param s new frame spacing
1264 void QtxPagePrefFrameItem::setSpacing( const int s )
1266 myBox->setInsideSpacing( s );
1270 \brief Get number of frame columns.
1271 \return current columns number
1274 int QtxPagePrefFrameItem::columns() const
1276 return myBox->columns();
1280 \brief Set number of frame columns.
1281 \param c new columns number
1284 void QtxPagePrefFrameItem::setColumns( const int c )
1286 myBox->setColumns( c );
1290 \brief Get frame box orientation.
1291 \return current frame orientation
1292 \sa setOrientation()
1294 Qt::Orientation QtxPagePrefFrameItem::orientation() const
1296 return myBox->orientation();
1300 \brief Set frame box orientation.
1301 \param o new frame orientation
1304 void QtxPagePrefFrameItem::setOrientation( const Qt::Orientation o )
1306 myBox->setOrientation( o );
1310 \brief Check if the frame widget stretching is enabled.
1311 \return \c true if the widget is stretchable
1314 bool QtxPagePrefFrameItem::stretch() const
1317 QLayout* l = widget() ? widget()->layout() : 0;
1318 for ( int i = 0; l && i < l->count() && !s; i++ )
1319 s = l->itemAt( i )->spacerItem();
1321 return s ? (bool)( s->expandingDirections() & Qt::Vertical ) : false;
1325 \brief Enable/disable frame widget stretching.
1326 \param on new stretchable state
1329 void QtxPagePrefFrameItem::setStretch( const bool on )
1332 QLayout* l = widget() ? widget()->layout() : 0;
1333 for ( int i = 0; l && i < l->count() && !s; i++ )
1334 s = l->itemAt( i )->spacerItem();
1337 s->changeSize( 0, 0, QSizePolicy::Minimum, on ? QSizePolicy::Expanding : QSizePolicy::Minimum );
1341 \brief Get preference item option value.
1342 \param name option name
1343 \return property value or null QVariant if option is not set
1344 \sa setOptionValue()
1346 QVariant QtxPagePrefFrameItem::optionValue( const QString& name ) const
1348 if ( name == "margin" )
1350 else if ( name == "spacing" )
1352 else if ( name == "columns" )
1354 else if ( name == "orientation" )
1355 return orientation();
1356 else if ( name == "stretch" )
1359 return QtxPagePrefItem::optionValue( name );
1363 \brief Set preference item option value.
1364 \param name option name
1365 \param val new property value
1368 void QtxPagePrefFrameItem::setOptionValue( const QString& name, const QVariant& val )
1370 if ( name == "margin" )
1372 if ( val.canConvert( QVariant::Int ) )
1373 setMargin( val.toInt() );
1375 else if ( name == "spacing" )
1377 if ( val.canConvert( QVariant::Int ) )
1378 setSpacing( val.toInt() );
1380 else if ( name == "columns" )
1382 if ( val.canConvert( QVariant::Int ) )
1383 setColumns( val.toInt() );
1385 else if ( name == "orientation" )
1387 if ( val.canConvert( QVariant::Int ) )
1388 setOrientation( (Qt::Orientation)val.toInt() );
1390 else if ( name == "stretch" )
1392 if ( val.canConvert( QVariant::Bool ) )
1393 setStretch( val.toBool() );
1396 QtxPagePrefItem::setOptionValue( name, val );
1399 void QtxPagePrefFrameItem::widgetShown()
1401 QtxPagePrefItem::widgetShown();
1403 QtxPageNamedPrefItem::adjustLabels( this );
1407 \brief Update frame widget.
1409 void QtxPagePrefFrameItem::updateFrame()
1411 QList<QtxPagePrefItem*> items;
1412 pageChildItems( items );
1414 for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end(); ++it )
1416 QWidget* wid = (*it)->widget();
1420 if ( wid->parent() != myBox )
1421 wid->setParent( myBox );
1426 \class QtxPagePrefGroupItem
1427 \brief GUI implementation of the group widget container.
1432 \param title preference item title
1433 \param parent parent preference item
1434 \param sect resource file section associated with the preference item
1435 \param param resource file parameter associated with the preference item
1437 QtxPagePrefGroupItem::QtxPagePrefGroupItem( const QString& title, QtxPreferenceItem* parent,
1438 const QString& sect, const QString& param )
1439 : QtxPagePrefItem( title, parent, sect, param )
1441 myGroup = new QtxGroupBox( title, 0 );
1442 myBox = new QtxGridBox( 1, Qt::Horizontal, myGroup, 5, 5 );
1443 myGroup->setWidget( myBox );
1445 setWidget( myGroup );
1452 \param cols columns number
1453 \param title preference item title
1454 \param parent parent preference item
1455 \param sect resource file section associated with the preference item
1456 \param param resource file parameter associated with the preference item
1458 QtxPagePrefGroupItem::QtxPagePrefGroupItem( const int cols, const QString& title, QtxPreferenceItem* parent,
1459 const QString& sect, const QString& param )
1460 : QtxPagePrefItem( title, parent, sect, param )
1462 myGroup = new QtxGroupBox( title, 0 );
1463 myBox = new QtxGridBox( cols, Qt::Horizontal, myGroup, 5, 5 );
1464 myGroup->setWidget( myBox );
1466 setWidget( myGroup );
1474 QtxPagePrefGroupItem::~QtxPagePrefGroupItem()
1479 \brief Assign resource file settings to the preference item.
1480 \param sect resource file section name
1481 \param param resource file parameter name
1484 void QtxPagePrefGroupItem::setResource( const QString& sect, const QString& param )
1486 QtxPagePrefItem::setResource( sect, param );
1491 \brief Update widget contents.
1493 void QtxPagePrefGroupItem::updateContents()
1495 QtxPagePrefItem::updateContents();
1497 myGroup->setTitle( title() );
1502 QtxPageNamedPrefItem::adjustLabels( this );
1506 \brief Get group box margin.
1507 \return current group box margin
1510 int QtxPagePrefGroupItem::margin() const
1512 return myBox->insideMargin();
1516 \brief Get group box margin.
1517 \param m new group box margin
1520 void QtxPagePrefGroupItem::setMargin( const int m )
1522 myBox->setInsideMargin( m );
1526 \brief Get group box spacing.
1527 \return current group box spacing
1530 int QtxPagePrefGroupItem::spacing() const
1532 return myBox->insideSpacing();
1536 \brief Set group box spacing.
1537 \param s new group box spacing
1540 void QtxPagePrefGroupItem::setSpacing( const int s )
1542 myBox->setInsideSpacing( s );
1546 \brief Get number of group box columns.
1547 \return current columns number
1550 int QtxPagePrefGroupItem::columns() const
1552 return myBox->columns();
1556 \brief Set number of group box columns.
1557 \param c new columns number
1560 void QtxPagePrefGroupItem::setColumns( const int c )
1562 myBox->setColumns( c );
1566 \brief Get group box orientation.
1567 \return current group box orientation
1568 \sa setOrientation()
1570 Qt::Orientation QtxPagePrefGroupItem::orientation() const
1572 return myBox->orientation();
1576 \brief Set group box orientation.
1577 \param o new group box orientation
1580 void QtxPagePrefGroupItem::setOrientation( const Qt::Orientation o )
1582 myBox->setOrientation( o );
1586 \brief Get 'flat' flag of the group box widget.
1587 \return \c true if the group box is flat
1589 bool QtxPagePrefGroupItem::isFlat() const
1591 return myGroup->isFlat();
1595 \brief Get 'flat' flag of the group box widget.
1596 \param on if \c true the group box will be made flat
1598 void QtxPagePrefGroupItem::setFlat( const bool on )
1600 myGroup->setFlat( on );
1604 \brief Store preference item to the resource manager.
1607 void QtxPagePrefGroupItem::store()
1609 if ( myGroup->isCheckable() )
1610 setBoolean( myGroup->isChecked() );
1614 \brief Return widget contained grid layout of this group.
1616 QtxGridBox* QtxPagePrefGroupItem::gridBox() const
1622 \brief Retrieve preference item from the resource manager.
1625 void QtxPagePrefGroupItem::retrieve()
1627 if ( myGroup->isCheckable() )
1628 myGroup->setChecked( getBoolean() );
1632 \brief Get preference item option value.
1633 \param name option name
1634 \return property value or null QVariant if option is not set
1635 \sa setOptionValue()
1637 QVariant QtxPagePrefGroupItem::optionValue( const QString& name ) const
1639 if ( name == "margin" )
1641 else if ( name == "spacing" )
1643 else if ( name == "columns" )
1645 else if ( name == "orientation" )
1646 return orientation();
1647 else if ( name == "flat" )
1650 return QtxPagePrefItem::optionValue( name );
1654 \brief Set preference item option value.
1655 \param name option name
1656 \param val new property value
1659 void QtxPagePrefGroupItem::setOptionValue( const QString& name, const QVariant& val )
1661 if ( name == "margin" )
1663 if ( val.canConvert( QVariant::Int ) )
1664 setMargin( val.toInt() );
1666 else if ( name == "spacing" )
1668 if ( val.canConvert( QVariant::Int ) )
1669 setSpacing( val.toInt() );
1671 else if ( name == "columns" )
1673 if ( val.canConvert( QVariant::Int ) )
1674 setColumns( val.toInt() );
1676 else if ( name == "orientation" )
1678 if ( val.canConvert( QVariant::Int ) )
1679 setOrientation( (Qt::Orientation)val.toInt() );
1681 else if ( name == "flat" )
1683 if ( val.canConvert( QVariant::Bool ) )
1684 setFlat( val.toBool() );
1687 QtxPagePrefItem::setOptionValue( name, val );
1690 void QtxPagePrefGroupItem::widgetShown()
1692 QtxPagePrefItem::widgetShown();
1694 QtxPageNamedPrefItem::adjustLabels( this );
1698 \brief Update widget state.
1700 void QtxPagePrefGroupItem::updateState()
1702 QString section, param;
1703 resource( section, param );
1704 myGroup->setCheckable( !title().isEmpty() && !section.isEmpty() && !param.isEmpty() );
1708 \brief Update group box widget.
1710 void QtxPagePrefGroupItem::updateGroup()
1712 QList<QtxPagePrefItem*> items;
1713 pageChildItems( items );
1715 for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end(); ++it )
1717 QWidget* wid = (*it)->widget();
1721 if ( wid->parent() != myBox )
1722 wid->setParent( myBox );
1727 \class QtxPagePrefLabelItem
1728 \brief Label item which can be used in the preferences editor dialog box.
1734 Creates label item with specified title.
1736 \param text label text
1737 \param parent parent preference item
1739 QtxPagePrefLabelItem::QtxPagePrefLabelItem( const QString& text, QtxPreferenceItem* parent )
1740 : QtxPagePrefItem( text, parent )
1742 setWidget( myLabel = new QLabel( text ) );
1745 QtxPagePrefLabelItem::QtxPagePrefLabelItem( Qt::Alignment align, const QString& text, QtxPreferenceItem* parent )
1746 : QtxPagePrefItem( text, parent )
1748 setWidget( myLabel = new QLabel( text ) );
1749 myLabel->setAlignment( align );
1752 QtxPagePrefLabelItem::~QtxPagePrefLabelItem()
1756 void QtxPagePrefLabelItem::setTitle( const QString& text )
1758 QtxPagePrefItem::setTitle( text );
1761 myLabel->setText( text );
1764 Qt::Alignment QtxPagePrefLabelItem::alignment() const
1766 return myLabel->alignment();
1769 void QtxPagePrefLabelItem::setAlignment( Qt::Alignment align )
1771 myLabel->setAlignment( align );
1774 QVariant QtxPagePrefLabelItem::optionValue( const QString& name ) const
1777 if ( name == "alignment" )
1778 val = (int)alignment();
1782 void QtxPagePrefLabelItem::setOptionValue( const QString& name, const QVariant& val )
1784 if ( name == "alignment" )
1786 if ( val.canConvert( QVariant::Int ) )
1787 setAlignment( (Qt::Alignment)val.toInt() );
1792 \class QtxPagePrefSpaceItem
1793 \brief Simple spacer item which can be used in the preferences
1800 Creates spacer item with zero width and height and expanding
1801 on both directions (by height and width).
1803 \param parent parent preference item
1805 QtxPagePrefSpaceItem::QtxPagePrefSpaceItem( QtxPreferenceItem* parent )
1806 : QtxPagePrefItem( QString(), parent )
1808 initialize( 0, 0, 1, 1 );
1814 Creates spacer item with zero width and height and expanding
1815 according to the specified orientation.
1817 \param o spacer orientation
1818 \param parent parent preference item
1820 QtxPagePrefSpaceItem::QtxPagePrefSpaceItem( Qt::Orientation o, QtxPreferenceItem* parent )
1821 : QtxPagePrefItem( QString(), parent )
1823 if ( o == Qt::Horizontal )
1824 initialize( 0, 0, 1, 0 );
1826 initialize( 0, 0, 0, 1 );
1832 Creates spacer item with specified width and height. The spacing
1833 item is expanding horizontally if \a w <= 0 and vertically
1836 \param w spacer width
1837 \param h spacer height
1838 \param parent parent preference item
1840 QtxPagePrefSpaceItem::QtxPagePrefSpaceItem( const int w, const int h, QtxPreferenceItem* parent )
1841 : QtxPagePrefItem( QString(), parent )
1843 initialize( w, h, w > 0 ? 0 : 1, h > 0 ? 0 : 1 );
1849 QtxPagePrefSpaceItem::~QtxPagePrefSpaceItem()
1854 \brief Get spacer item size for the specified direction.
1856 \return size for the specified direction
1859 int QtxPagePrefSpaceItem::size( Qt::Orientation o ) const
1861 return o == Qt::Horizontal ? widget()->minimumWidth() : widget()->minimumHeight();
1865 \brief Set spacer item size for the specified direction.
1867 \param sz new size for the specified direction
1870 void QtxPagePrefSpaceItem::setSize( Qt::Orientation o, const int sz )
1872 if ( o == Qt::Horizontal )
1873 widget()->setMinimumWidth( sz );
1875 widget()->setMinimumHeight( sz );
1879 \brief Get spacer item stretch factor for the specified direction.
1881 \return stretch factor for the specified direction
1884 int QtxPagePrefSpaceItem::stretch( Qt::Orientation o ) const
1886 QSizePolicy sp = widget()->sizePolicy();
1887 return o == Qt::Horizontal ? sp.horizontalStretch() : sp.verticalStretch();
1891 \brief Set spacer item stretch factor for the specified direction.
1893 \param sf new stretch factor for the specified direction
1896 void QtxPagePrefSpaceItem::setStretch( Qt::Orientation o, const int sf )
1898 QSizePolicy sp = widget()->sizePolicy();
1899 if ( o == Qt::Horizontal )
1901 sp.setHorizontalStretch( sf );
1902 sp.setHorizontalPolicy( sf > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed );
1906 sp.setVerticalStretch( sf );
1907 sp.setVerticalPolicy( sf > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed );
1910 widget()->setSizePolicy( sp );
1914 \brief Get preference item option value.
1915 \param name option name
1916 \return property value or null QVariant if option is not set
1917 \sa setOptionValue()
1919 QVariant QtxPagePrefSpaceItem::optionValue( const QString& name ) const
1921 if ( name == "horizontal_size" || name == "hsize" )
1922 return size( Qt::Horizontal );
1923 else if ( name == "vertical_size" || name == "vsize" )
1924 return size( Qt::Vertical );
1925 else if ( name == "horizontal_stretch" || name == "hstretch" )
1926 return stretch( Qt::Horizontal );
1927 else if ( name == "vertical_stretch" || name == "vstretch" )
1928 return stretch( Qt::Vertical );
1930 return QtxPagePrefItem::optionValue( name );
1934 \brief Set preference item option value.
1935 \param name option name
1936 \param val new property value
1939 void QtxPagePrefSpaceItem::setOptionValue( const QString& name, const QVariant& val )
1941 if ( name == "horizontal_size" || name == "hsize" )
1943 if ( val.canConvert( QVariant::Int ) )
1944 setSize( Qt::Horizontal, val.toInt() );
1946 else if ( name == "vertical_size" || name == "vsize" )
1948 if ( val.canConvert( QVariant::Int ) )
1949 setSize( Qt::Vertical, val.toInt() );
1951 else if ( name == "horizontal_stretch" || name == "hstretch" )
1953 if ( val.canConvert( QVariant::Int ) )
1954 setStretch( Qt::Horizontal, val.toInt() );
1956 else if ( name == "vertical_stretch" || name == "vstretch" )
1958 if ( val.canConvert( QVariant::Int ) )
1959 setStretch( Qt::Vertical, val.toInt() );
1962 QtxPagePrefItem::setOptionValue( name, val );
1966 \brief Perform internal initialization.
1967 \param w spacer item width
1968 \param h spacer item height
1969 \param ws spacer item horizontal stretch factor
1970 \param hs spacer item vertical stretch factor
1972 void QtxPagePrefSpaceItem::initialize( const int w, const int h, const int hs, const int vs )
1975 sp.setHorizontalPolicy( hs > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed );
1976 sp.setVerticalPolicy( vs > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed );
1978 sp.setHorizontalStretch( hs );
1979 sp.setVerticalStretch( vs );
1981 QWidget* wid = new QWidget();
1982 wid->setSizePolicy( sp );
1984 wid->setMinimumSize( w, h );
1990 \class QtxPagePrefCheckItem
1991 \brief GUI implementation of the resources check box item (boolean).
1996 \param title preference item title
1997 \param parent parent preference item
1998 \param sect resource file section associated with the preference item
1999 \param param resource file parameter associated with the preference item
2001 QtxPagePrefCheckItem::QtxPagePrefCheckItem( const QString& title, QtxPreferenceItem* parent,
2002 const QString& sect, const QString& param )
2004 : QtxPagePrefItem( title, parent, sect, param )
2006 myCheck = new QCheckBox( title );
2007 myCheck->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
2008 setWidget( myCheck );
2014 QtxPagePrefCheckItem::~QtxPagePrefCheckItem()
2019 \brief Set preference item title.
2020 \param txt new preference title.
2022 void QtxPagePrefCheckItem::setTitle( const QString& txt )
2024 QtxPagePrefItem::setTitle( txt );
2026 myCheck->setText( title() );
2030 \brief Store preference item to the resource manager.
2033 void QtxPagePrefCheckItem::store()
2035 setBoolean( myCheck->isChecked() );
2039 \brief Retrieve preference item from the resource manager.
2042 void QtxPagePrefCheckItem::retrieve()
2044 myCheck->setChecked( getBoolean() );
2048 \class QtxPagePrefEditItem
2049 \brief GUI implementation of the resources line edit box item
2050 for string, integer and double values.
2056 Creates preference item for string value editing.
2058 \param title preference item title
2059 \param parent parent preference item
2060 \param sect resource file section associated with the preference item
2061 \param param resource file parameter associated with the preference item
2063 QtxPagePrefEditItem::QtxPagePrefEditItem( const QString& title, QtxPreferenceItem* parent,
2064 const QString& sect, const QString& param )
2065 : QtxPageNamedPrefItem( title, parent, sect, param ),
2068 setControl( myEditor = new QLineEdit() );
2075 Creates preference item for editing of the value which type
2076 is specified by parameter \a type.
2078 \param type preference item input type (QtxPagePrefEditItem::InputType)
2079 \param title preference item title
2080 \param parent parent preference item
2081 \param sect resource file section associated with the preference item
2082 \param param resource file parameter associated with the preference item
2084 QtxPagePrefEditItem::QtxPagePrefEditItem( const int type, const QString& title,
2085 QtxPreferenceItem* parent, const QString& sect,
2086 const QString& param )
2087 : QtxPageNamedPrefItem( title, parent, sect, param ),
2090 setControl( myEditor = new QLineEdit() );
2097 QtxPagePrefEditItem::~QtxPagePrefEditItem()
2102 \brief Get edit box preference item input type.
2103 \return preference item input type (QtxPagePrefEditItem::InputType)
2106 int QtxPagePrefEditItem::inputType() const
2112 \brief Set edit box preference item input type.
2113 \param type new preference item input type (QtxPagePrefEditItem::InputType)
2116 void QtxPagePrefEditItem::setInputType( const int type )
2118 if ( myType == type )
2126 \brief Store preference item to the resource manager.
2129 void QtxPagePrefEditItem::store()
2131 setString( myEditor->text() );
2135 \brief Retrieve preference item from the resource manager.
2138 void QtxPagePrefEditItem::retrieve()
2140 QString txt = getString();
2141 if ( myEditor->validator() )
2144 if ( myEditor->validator()->validate( txt, pos ) == QValidator::Invalid )
2147 myEditor->setText( txt );
2151 \brief Get preference item option value.
2152 \param name option name
2153 \return property value or null QVariant if option is not set
2154 \sa setOptionValue()
2156 QVariant QtxPagePrefEditItem::optionValue( const QString& name ) const
2158 if ( name == "input_type" || name == "type" )
2161 return QtxPageNamedPrefItem::optionValue( name );
2165 \brief Set preference item option value.
2166 \param name option name
2167 \param val new property value
2170 void QtxPagePrefEditItem::setOptionValue( const QString& name, const QVariant& val )
2172 if ( name == "input_type" || name == "type" )
2174 if ( val.canConvert( QVariant::Int ) )
2175 setInputType( val.toInt() );
2178 QtxPageNamedPrefItem::setOptionValue( name, val );
2182 \brief Update edit box widget.
2184 void QtxPagePrefEditItem::updateEditor()
2186 QValidator* val = 0;
2187 switch ( inputType() )
2190 val = new QIntValidator( myEditor );
2193 val = new QDoubleValidator( myEditor );
2199 if ( !myEditor->text().isEmpty() && val )
2202 QString str = myEditor->text();
2203 if ( val->validate( str, pos ) == QValidator::Invalid )
2207 delete myEditor->validator();
2208 myEditor->setValidator( val );
2212 \class QtxPagePrefSelectItem
2213 \brief GUI implementation of the resources selector item
2214 (string, integer or double values list).
2216 All items in the list (represented as combo box) should be specified
2217 by the unique identifier which is stored to the resource file instead
2218 of the value itself.
2224 Creates preference item with combo box widget which is not editable
2225 (direct value entering is disabled).
2227 \param title preference item title
2228 \param parent parent preference item
2229 \param sect resource file section associated with the preference item
2230 \param param resource file parameter associated with the preference item
2232 QtxPagePrefSelectItem::QtxPagePrefSelectItem( const QString& title, QtxPreferenceItem* parent,
2233 const QString& sect, const QString& param )
2234 : QtxPageNamedPrefItem( title, parent, sect, param ),
2237 setControl( mySelector = new QtxComboBox() );
2238 mySelector->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
2239 mySelector->setDuplicatesEnabled( false );
2246 Creates preference item with combo box widget which is editable
2247 according to the specified input type (integer, double or string values).
2249 \param type input type (QtxPagePrefSelectItem::InputType)
2250 \param title preference item title
2251 \param parent parent preference item
2252 \param sect resource file section associated with the preference item
2253 \param param resource file parameter associated with the preference item
2255 QtxPagePrefSelectItem::QtxPagePrefSelectItem( const int type, const QString& title, QtxPreferenceItem* parent,
2256 const QString& sect, const QString& param )
2257 : QtxPageNamedPrefItem( title, parent, sect, param ),
2260 setControl( mySelector = new QtxComboBox() );
2261 mySelector->setDuplicatesEnabled( false );
2268 QtxPagePrefSelectItem::~QtxPagePrefSelectItem()
2273 \brief Get edit box preference item input type.
2274 \return preference item input type (QtxPagePrefSelectItem::InputType)
2277 int QtxPagePrefSelectItem::inputType() const
2283 \brief Set edit box preference item input type.
2284 \param type new preference item input type (QtxPagePrefSelectItem::InputType)
2287 void QtxPagePrefSelectItem::setInputType( const int type )
2289 if ( myType == type )
2297 \brief Get the list of the values from the selection widget.
2298 \return list of values
2299 \sa numbers(), setStrings()
2301 QStringList QtxPagePrefSelectItem::strings() const
2304 for ( uint i = 0; i < mySelector->count(); i++ )
2305 res.append( mySelector->itemText( i ) );
2310 \brief Get the list of the values identifiers from the selection widget.
2311 \return list of values IDs
2312 \sa strings(), setNumbers()
2314 QList<int> QtxPagePrefSelectItem::numbers() const
2317 for ( uint i = 0; i < mySelector->count(); i++ )
2319 if ( mySelector->hasId( i ) )
2320 res.append( mySelector->id( i ) );
2326 \brief Set the list of the values to the selection widget.
2327 \param lst new list of values
2328 \sa strings(), setNumbers()
2330 void QtxPagePrefSelectItem::setStrings( const QStringList& lst )
2332 mySelector->clear();
2333 mySelector->addItems( lst );
2337 \brief Set the list of the values identifiers to the selection widget.
2338 \param ids new list of values IDs
2339 \sa numbers(), setStrings()
2341 void QtxPagePrefSelectItem::setNumbers( const QList<int>& ids )
2344 for ( QList<int>::const_iterator it = ids.begin(); it != ids.end() && i < mySelector->count(); ++it, i++ )
2345 mySelector->setId( i, *it );
2349 \brief Store preference item to the resource manager.
2352 void QtxPagePrefSelectItem::store()
2354 if ( mySelector->isCleared() )
2357 int idx = mySelector->currentIndex();
2359 if ( mySelector->hasId( idx ) )
2360 setInteger( mySelector->id( idx ) );
2361 else if ( idx >= 0 )
2362 setString( mySelector->itemText( idx ) );
2366 \brief Retrieve preference item from the resource manager.
2369 void QtxPagePrefSelectItem::retrieve()
2371 QString txt = getString();
2376 int num = txt.toInt( &ok );
2378 idx = mySelector->index( num );
2381 for ( uint i = 0; i < mySelector->count() && idx == -1; i++ )
2383 if ( mySelector->itemText( i ) == txt )
2389 mySelector->setCurrentIndex( idx );
2390 else if ( mySelector->isEditable() )
2393 if ( mySelector->validator() &&
2394 mySelector->validator()->validate( txt, pos ) == QValidator::Invalid )
2395 mySelector->setCleared( true );
2398 mySelector->setCleared( false );
2399 mySelector->addItem( txt );
2400 mySelector->setCurrentIndex( mySelector->count() - 1 );
2406 \brief Get preference item option value.
2407 \param name option name
2408 \return property value or null QVariant if option is not set
2409 \sa setOptionValue()
2411 QVariant QtxPagePrefSelectItem::optionValue( const QString& name ) const
2413 if ( name == "input_type" || name == "type" )
2415 else if ( name == "strings" || name == "labels" )
2417 else if ( name == "numbers" || name == "ids" || name == "indexes" )
2419 QList<QVariant> lst;
2420 QList<int> nums = numbers();
2421 for ( QList<int>::const_iterator it = nums.begin(); it != nums.end(); ++it )
2426 return QtxPageNamedPrefItem::optionValue( name );
2430 \brief Set preference item option value.
2431 \param name option name
2432 \param val new property value
2435 void QtxPagePrefSelectItem::setOptionValue( const QString& name, const QVariant& val )
2437 if ( name == "input_type" || name == "type" )
2439 if ( val.canConvert( QVariant::Int ) )
2440 setInputType( val.toInt() );
2442 else if ( name == "strings" || name == "labels" )
2444 else if ( name == "numbers" || name == "ids" || name == "indexes" )
2447 QtxPageNamedPrefItem::setOptionValue( name, val );
2451 \brief Set the list of the values from the resource manager.
2452 \param var new values list
2455 void QtxPagePrefSelectItem::setStrings( const QVariant& var )
2457 if ( var.type() != QVariant::StringList )
2460 setStrings( var.toStringList() );
2464 \brief Set the list of the values identifiers from the resource manager.
2465 \param var new values IDs list
2468 void QtxPagePrefSelectItem::setNumbers( const QVariant& var )
2470 if ( var.type() != QVariant::List )
2474 QList<QVariant> varList = var.toList();
2475 for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it )
2477 if ( (*it).canConvert( QVariant::Int ) )
2478 lst.append( (*it).toInt() );
2484 \brief Update selector widget.
2486 void QtxPagePrefSelectItem::updateSelector()
2488 QValidator* val = 0;
2489 switch ( inputType() )
2492 val = new QIntValidator( mySelector );
2495 val = new QDoubleValidator( mySelector );
2501 mySelector->setEditable( inputType() != NoInput );
2503 if ( mySelector->isEditable() && !mySelector->currentText().isEmpty() && val )
2506 QString str = mySelector->currentText();
2507 if ( val->validate( str, pos ) == QValidator::Invalid )
2508 mySelector->clearEditText();
2511 delete mySelector->validator();
2512 mySelector->setValidator( val );
2516 \class QtxPagePrefSpinItem
2517 \brief GUI implementation of the resources spin box item
2518 (for integer or double value).
2524 Creates spin box preference item for the entering integer values.
2526 \param title preference item title
2527 \param parent parent preference item
2528 \param sect resource file section associated with the preference item
2529 \param param resource file parameter associated with the preference item
2531 QtxPagePrefSpinItem::QtxPagePrefSpinItem( const QString& title, QtxPreferenceItem* parent,
2532 const QString& sect, const QString& param )
2533 : QtxPageNamedPrefItem( title, parent, sect, param ),
2542 Creates spin box preference item for the entering values which type
2543 is specified by the parameter \a type.
2545 \param type input type (QtxPagePrefSpinItem::InputType).
2546 \param title preference item title
2547 \param parent parent preference item
2548 \param sect resource file section associated with the preference item
2549 \param param resource file parameter associated with the preference item
2551 QtxPagePrefSpinItem::QtxPagePrefSpinItem( const int type, const QString& title,
2552 QtxPreferenceItem* parent, const QString& sect,
2553 const QString& param )
2554 : QtxPageNamedPrefItem( title, parent, sect, param ),
2563 QtxPagePrefSpinItem::~QtxPagePrefSpinItem()
2568 \brief Get spin box preference item input type.
2569 \return preference item input type (QtxPagePrefSpinItem::InputType)
2572 int QtxPagePrefSpinItem::inputType() const
2578 \brief Set spin box preference item input type.
2579 \param type new preference item input type (QtxPagePrefSpinItem::InputType)
2582 void QtxPagePrefSpinItem::setInputType( const int type )
2584 if ( myType == type )
2592 \brief Get spin box preference item step value.
2593 \return spin box single step value
2596 QVariant QtxPagePrefSpinItem::step() const
2598 if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
2599 return isb->singleStep();
2600 else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
2601 return dsb->singleStep();
2607 \brief Get spin box preference item minimum value.
2608 \return spin box minimum value
2611 QVariant QtxPagePrefSpinItem::minimum() const
2613 if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
2614 return isb->minimum();
2615 else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
2616 return dsb->minimum();
2622 \brief Get spin box preference item maximum value.
2623 \return spin box maximum value
2626 QVariant QtxPagePrefSpinItem::maximum() const
2628 if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
2629 return isb->maximum();
2630 else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
2631 return dsb->maximum();
2637 \brief Get spin box preference item prefix string.
2638 \return spin box prefix string
2641 QString QtxPagePrefSpinItem::prefix() const
2643 if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
2644 return isb->prefix();
2645 else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
2646 return dsb->prefix();
2652 \brief Get spin box preference item suffix string.
2653 \return spin box suffix string
2656 QString QtxPagePrefSpinItem::suffix() const
2658 if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
2659 return isb->suffix();
2660 else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
2661 return dsb->suffix();
2667 \brief Get spin box preference item special value text (which is shown
2668 when the spin box reaches minimum value).
2669 \return spin box special value text
2670 \sa setSpecialValueText()
2672 QString QtxPagePrefSpinItem::specialValueText() const
2674 QAbstractSpinBox* sb = ::qobject_cast<QAbstractSpinBox*>( control() );
2676 return sb->specialValueText();
2682 \brief Set spin box preference item step value.
2683 \param step new spin box single step value
2686 void QtxPagePrefSpinItem::setStep( const QVariant& step )
2688 if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
2690 if ( step.canConvert( QVariant::Int ) )
2691 isb->setSingleStep( step.toInt() );
2693 else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
2695 if ( step.canConvert( QVariant::Double ) )
2696 dsb->setSingleStep( step.toDouble() );
2701 \brief Set spin box preference item minimum value.
2702 \param min new spin box minimum value
2705 void QtxPagePrefSpinItem::setMinimum( const QVariant& min )
2707 if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
2709 if ( min.canConvert( QVariant::Int ) )
2710 isb->setMinimum( min.toInt() );
2712 else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
2714 if ( min.canConvert( QVariant::Double ) )
2715 dsb->setMinimum( min.toDouble() );
2720 \brief Set spin box preference item maximum value.
2721 \param min new spin box maximum value
2724 void QtxPagePrefSpinItem::setMaximum( const QVariant& max )
2726 if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
2728 if ( max.canConvert( QVariant::Int ) )
2729 isb->setMaximum( max.toInt() );
2731 else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
2733 if ( max.canConvert( QVariant::Double ) )
2734 dsb->setMaximum( max.toDouble() );
2739 \brief Set spin box preference item prefix string.
2740 \param txt new spin box prefix string
2743 void QtxPagePrefSpinItem::setPrefix( const QString& txt )
2745 if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
2746 isb->setPrefix( txt );
2747 else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
2748 dsb->setPrefix( txt );
2752 \brief Set spin box preference item suffix string.
2753 \param txt new spin box suffix string
2756 void QtxPagePrefSpinItem::setSuffix( const QString& txt )
2758 if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
2759 isb->setSuffix( txt );
2760 else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
2761 dsb->setSuffix( txt );
2765 \brief Set spin box preference item special value text (which is shown
2766 when the spin box reaches minimum value).
2767 \param txt new spin box special value text
2768 \sa specialValueText()
2770 void QtxPagePrefSpinItem::setSpecialValueText( const QString& txt )
2772 QAbstractSpinBox* sb = ::qobject_cast<QAbstractSpinBox*>( control() );
2774 sb->setSpecialValueText( txt );
2778 \brief Store preference item to the resource manager.
2781 void QtxPagePrefSpinItem::store()
2783 if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
2784 setInteger( isb->value() );
2785 else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
2786 setDouble( dsb->value() );
2790 \brief Retrieve preference item from the resource manager.
2793 void QtxPagePrefSpinItem::retrieve()
2795 if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
2796 isb->setValue( getInteger( isb->value() ) );
2797 else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
2798 dsb->setValue( getDouble( dsb->value() ) );
2802 \brief Get preference item option value.
2803 \param name option name
2804 \return property value or null QVariant if option is not set
2805 \sa setOptionValue()
2807 QVariant QtxPagePrefSpinItem::optionValue( const QString& name ) const
2809 if ( name == "input_type" || name == "type" )
2811 else if ( name == "minimum" || name == "min" )
2813 else if ( name == "maximum" || name == "max" )
2815 else if ( name == "step" )
2817 else if ( name == "prefix" )
2819 else if ( name == "suffix" )
2821 else if ( name == "special" )
2822 return specialValueText();
2824 return QtxPageNamedPrefItem::optionValue( name );
2828 \brief Set preference item option value.
2829 \param name option name
2830 \param val new property value
2833 void QtxPagePrefSpinItem::setOptionValue( const QString& name, const QVariant& val )
2835 if ( name == "input_type" || name == "type" )
2837 if ( val.canConvert( QVariant::Int ) )
2838 setInputType( val.toInt() );
2840 else if ( name == "minimum" || name == "min" )
2842 else if ( name == "maximum" || name == "max" )
2844 else if ( name == "step" )
2846 else if ( name == "prefix" )
2848 if ( val.canConvert( QVariant::String ) )
2849 setPrefix( val.toString() );
2851 else if ( name == "suffix" )
2853 if ( val.canConvert( QVariant::String ) )
2854 setSuffix( val.toString() );
2856 else if ( name == "special" )
2858 if ( val.canConvert( QVariant::String ) )
2859 setSpecialValueText( val.toString() );
2862 QtxPageNamedPrefItem::setOptionValue( name, val );
2866 \brief Update spin box widget.
2868 void QtxPagePrefSpinItem::updateSpinBox()
2871 QVariant stp = step();
2872 QVariant min = minimum();
2873 QVariant max = maximum();
2875 if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
2877 else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
2880 switch ( inputType() )
2883 setControl( new QtxIntSpinBox() );
2886 setControl( new QtxDoubleSpinBox() );
2892 control()->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
2898 if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
2900 if ( val.canConvert( QVariant::Int ) )
2901 isb->setValue( val.toInt() );
2903 else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
2905 if ( val.canConvert( QVariant::Double ) )
2906 dsb->setValue( val.toDouble() );
2911 \class QtxPagePrefTextItem
2912 \brief GUI implementation of the resources text box edit item
2913 (for large text data).
2918 \param parent parent preference item
2919 \param sect resource file section associated with the preference item
2920 \param param resource file parameter associated with the preference item
2922 QtxPagePrefTextItem::QtxPagePrefTextItem( QtxPreferenceItem* parent, const QString& sect,
2923 const QString& param )
2924 : QtxPageNamedPrefItem( QString(), parent, sect, param )
2926 myEditor = new QTextEdit();
2927 myEditor->setAcceptRichText( false );
2929 setControl( myEditor );
2934 \param title preference item title
2935 \param parent parent preference item
2936 \param sect resource file section associated with the preference item
2937 \param param resource file parameter associated with the preference item
2939 QtxPagePrefTextItem::QtxPagePrefTextItem( const QString& title, QtxPreferenceItem* parent,
2940 const QString& sect, const QString& param )
2941 : QtxPageNamedPrefItem( title, parent, sect, param )
2943 myEditor = new QTextEdit();
2944 myEditor->setAcceptRichText( false );
2946 setControl( myEditor );
2952 QtxPagePrefTextItem::~QtxPagePrefTextItem()
2957 \brief Store preference item to the resource manager.
2960 void QtxPagePrefTextItem::store()
2962 setString( myEditor->toPlainText() );
2966 \brief Retrieve preference item from the resource manager.
2969 void QtxPagePrefTextItem::retrieve()
2971 myEditor->setPlainText( getString() );
2975 \class QtxPagePrefColorItem
2976 \brief GUI implementation of the resources color item.
2981 \param title preference item title
2982 \param parent parent preference item
2983 \param sect resource file section associated with the preference item
2984 \param param resource file parameter associated with the preference item
2986 QtxPagePrefColorItem::QtxPagePrefColorItem( const QString& title, QtxPreferenceItem* parent,
2987 const QString& sect, const QString& param )
2988 : QtxPageNamedPrefItem( title, parent, sect, param )
2990 // QtxPagePrefGroupItem* aGroup 0; //= dynamic_cast<QtxPagePrefGroupItem*>( parent );
2992 // setControl( myColor = new QtxColorButton( aGroup ? aGroup->gridBox() : 0 ) );
2993 setControl( myColor = new QtxColorButton( 0 ) );
2994 myColor->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
3000 QtxPagePrefColorItem::~QtxPagePrefColorItem()
3005 \brief Store preference item to the resource manager.
3008 void QtxPagePrefColorItem::store()
3010 setColor( myColor->color() );
3014 \brief Retrieve preference item from the resource manager.
3017 void QtxPagePrefColorItem::retrieve()
3019 myColor->setColor( getColor() );
3023 \class QtxPagePrefFontItem
3024 \brief GUI implementation of the resources font item.
3029 \param feat font editor widget features (QtxFontEdit::Features)
3030 \param title preference item title
3031 \param parent parent preference item
3032 \param sect resource file section associated with the preference item
3033 \param param resource file parameter associated with the preference item
3035 QtxPagePrefFontItem::QtxPagePrefFontItem( const int feat, const QString& title,
3036 QtxPreferenceItem* parent, const QString& sect,
3037 const QString& param )
3038 : QtxPageNamedPrefItem( title, parent, sect, param )
3040 setControl( myFont = new QtxFontEdit( feat ) );
3045 \param title preference item title
3046 \param parent parent preference item
3047 \param sect resource file section associated with the preference item
3048 \param param resource file parameter associated with the preference item
3050 QtxPagePrefFontItem::QtxPagePrefFontItem( const QString& title, QtxPreferenceItem* parent,
3051 const QString& sect, const QString& param )
3052 : QtxPageNamedPrefItem( title, parent, sect, param )
3054 setControl( myFont = new QtxFontEdit() );
3060 QtxPagePrefFontItem::~QtxPagePrefFontItem()
3065 \brief Get font widget features.
3066 \return font widget features (ORed QtxFontEdit::Features flags)
3069 int QtxPagePrefFontItem::features() const
3071 return myFont->features();
3075 \brief Set font widget features.
3076 \param f new font widget features (ORed QtxFontEdit::Features flags)
3079 void QtxPagePrefFontItem::setFeatures( const int f )
3081 myFont->setFeatures( f );
3085 \brief Specifies whether widget works in Native or Custom mode. Native mode
3086 is intended for working with system fonts. Custom mode is intended for
3087 working with manually defined set of fonts. Set of custom fonts can be
3088 specified with setFonts() method
3089 \param mode mode from QtxFontEdit::Mode enumeration
3092 void QtxPagePrefFontItem::setMode( const int mode )
3094 myFont->setMode( mode );
3098 \brief Verifies whether widget works in Native or Custom mode
3099 \return Native or Custom mode
3102 int QtxPagePrefFontItem::mode() const
3104 return myFont->mode();
3108 \brief Sets list of custom fonts.
3109 <b>This method is intended for working in Custom mode only.</b>
3110 \param fams list of families
3111 \sa fonts(), setMode()
3113 void QtxPagePrefFontItem::setFonts( const QStringList& fams )
3115 myFont->setFonts( fams );
3119 \brief Gets list of custom fonts
3120 \return list of families
3121 \sa setFonts(), setMode()
3123 QStringList QtxPagePrefFontItem::fonts() const
3125 return myFont->fonts();
3129 \brief Sets list of available font sizes.
3130 <b>This method is intended for working in Custom mode only.</b> The list of sizes can
3131 be empty. In this case system generate listof size automatically from 8 till 72.
3132 \param sizes list of sizes
3133 \sa sizes(), setMode()
3135 void QtxPagePrefFontItem::setSizes( const QList<int>& sizes )
3137 myFont->setSizes( sizes );
3141 \brief Gets list of custom fonts
3142 \return list of families
3143 \sa setFonts(), setMode()
3145 QList<int> QtxPagePrefFontItem::sizes() const
3147 return myFont->sizes();
3151 \brief Store preference item to the resource manager.
3154 void QtxPagePrefFontItem::store()
3156 setFont( myFont->currentFont() );
3160 \brief Retrieve preference item from the resource manager.
3163 void QtxPagePrefFontItem::retrieve()
3165 myFont->setCurrentFont( getFont() );
3169 \brief Get preference item option value.
3170 \param name option name
3171 \return property value or null QVariant if option is not set
3172 \sa setOptionValue()
3174 QVariant QtxPagePrefFontItem::optionValue( const QString& name ) const
3176 if ( name == "features" )
3178 else if ( name == "mode" )
3180 else if ( name == "fonts" || name == "families" )
3182 else if ( name == "sizes" )
3184 QList<QVariant> lst;
3185 QList<int> nums = sizes();
3186 for ( QList<int>::const_iterator it = nums.begin(); it != nums.end(); ++it )
3191 return QtxPageNamedPrefItem::optionValue( name );
3195 \brief Set preference item option value.
3196 \param name option name
3197 \param val new property value
3200 void QtxPagePrefFontItem::setOptionValue( const QString& name, const QVariant& val )
3202 if ( name == "features" )
3204 if ( val.canConvert( QVariant::Int ) )
3205 setFeatures( val.toInt() );
3207 else if ( name == "mode" )
3209 if ( val.canConvert( QVariant::Int ) )
3210 setMode( val.toInt() );
3212 else if ( name == "fonts" || name == "families" )
3214 if ( val.canConvert( QVariant::StringList ) )
3215 setFonts( val.toStringList() );
3217 else if ( name == "sizes" )
3219 if ( val.type() == QVariant::List )
3222 QList<QVariant> varList = val.toList();
3223 for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it )
3225 if ( (*it).canConvert( QVariant::Int ) )
3226 lst.append( (*it).toInt() );
3232 QtxPageNamedPrefItem::setOptionValue( name, val );
3236 \class QtxPagePrefPathItem
3237 \brief GUI implementation of the resources file/directory path item.
3242 \param type path widget mode (Qtx::PathType )
3243 \param title preference item title
3244 \param parent parent preference item
3245 \param sect resource file section associated with the preference item
3246 \param param resource file parameter associated with the preference item
3248 QtxPagePrefPathItem::QtxPagePrefPathItem( const Qtx::PathType type, const QString& title,
3249 QtxPreferenceItem* parent, const QString& sect, const QString& param )
3250 : QtxPageNamedPrefItem( title, parent, sect, param )
3252 setControl( myPath = new QtxPathEdit( type ) );
3257 \param title preference item title
3258 \param parent parent preference item
3259 \param sect resource file section associated with the preference item
3260 \param param resource file parameter associated with the preference item
3262 QtxPagePrefPathItem::QtxPagePrefPathItem( const QString& title, QtxPreferenceItem* parent,
3263 const QString& sect, const QString& param )
3264 : QtxPageNamedPrefItem( title, parent, sect, param )
3266 setControl( myPath = new QtxPathEdit() );
3272 QtxPagePrefPathItem::~QtxPagePrefPathItem()
3277 \brief Get path widget mode.
3278 \return current path widget mode (Qtx::PathType)
3281 Qtx::PathType QtxPagePrefPathItem::pathType() const
3283 return myPath->pathType();
3287 \brief Set path widget mode.
3288 \param type new path widget mode (Qtx::PathType)
3291 void QtxPagePrefPathItem::setPathType( const Qtx::PathType type )
3293 myPath->setPathType( type );
3297 \brief Get currently used path widget filters.
3298 \return file or directory path filters
3301 QString QtxPagePrefPathItem::pathFilter() const
3303 return myPath->pathFilter();
3307 \brief Set path widget filters.
3308 \param f new file or directory path filters
3311 void QtxPagePrefPathItem::setPathFilter( const QString& f )
3313 myPath->setPathFilter( f );
3317 \brief Store preference item to the resource manager.
3320 void QtxPagePrefPathItem::store()
3322 setString( myPath->path() );
3326 \brief Retrieve preference item from the resource manager.
3329 void QtxPagePrefPathItem::retrieve()
3331 myPath->setPath( getString() );
3335 \brief Get preference item option value.
3336 \param name option name
3337 \return property value or null QVariant if option is not set
3338 \sa setOptionValue()
3340 QVariant QtxPagePrefPathItem::optionValue( const QString& name ) const
3342 if ( name == "path_type" )
3344 else if ( name == "path_filter" )
3345 return pathFilter();
3347 return QtxPageNamedPrefItem::optionValue( name );
3351 \brief Set preference item option value.
3352 \param name option name
3353 \param val new property value
3356 void QtxPagePrefPathItem::setOptionValue( const QString& name, const QVariant& val )
3358 if ( name == "path_type" )
3360 if ( val.canConvert( QVariant::Int ) )
3361 setPathType( (Qtx::PathType)val.toInt() );
3363 else if ( name == "path_filter" )
3365 if ( val.canConvert( QVariant::String ) )
3366 setPathFilter( val.toString() );
3369 QtxPageNamedPrefItem::setOptionValue( name, val );
3373 \class QtxPagePrefPathListItem
3374 \brief GUI implementation of the resources files/directories list item.
3379 \param parent parent preference item
3380 \param sect resource file section associated with the preference item
3381 \param param resource file parameter associated with the preference item
3383 QtxPagePrefPathListItem::QtxPagePrefPathListItem( QtxPreferenceItem* parent,
3384 const QString& sect, const QString& param )
3385 : QtxPageNamedPrefItem( QString(), parent, sect, param )
3387 setControl( myPaths = new QtxPathListEdit() );
3392 \param type path list widget mode (Qtx::PathType)
3393 \param title preference item title
3394 \param parent parent preference item
3395 \param sect resource file section associated with the preference item
3396 \param param resource file parameter associated with the preference item
3398 QtxPagePrefPathListItem::QtxPagePrefPathListItem( const Qtx::PathType type, const QString& title,
3399 QtxPreferenceItem* parent, const QString& sect, const QString& param )
3400 : QtxPageNamedPrefItem( title, parent, sect, param )
3402 setControl( myPaths = new QtxPathListEdit( type ) );
3407 \param title preference item title
3408 \param parent parent preference item
3409 \param sect resource file section associated with the preference item
3410 \param param resource file parameter associated with the preference item
3412 QtxPagePrefPathListItem::QtxPagePrefPathListItem( const QString& title, QtxPreferenceItem* parent,
3413 const QString& sect, const QString& param )
3414 : QtxPageNamedPrefItem( title, parent, sect, param )
3416 setControl( myPaths = new QtxPathListEdit() );
3422 QtxPagePrefPathListItem::~QtxPagePrefPathListItem()
3427 \brief Get path list widget mode.
3428 \return currently used path list widget mode (Qtx::PathType)
3431 Qtx::PathType QtxPagePrefPathListItem::pathType() const
3433 return myPaths->pathType();
3437 \brief Set path list widget mode.
3438 \param type new path list widget mode (Qtx::PathType)
3441 void QtxPagePrefPathListItem::setPathType( const Qtx::PathType type )
3443 myPaths->setPathType( type );
3447 \brief Store preference item to the resource manager.
3450 void QtxPagePrefPathListItem::store()
3452 setString( myPaths->pathList().join( ";" ) );
3456 \brief Retrieve preference item from the resource manager.
3459 void QtxPagePrefPathListItem::retrieve()
3461 myPaths->setPathList( getString().split( ";" ) );
3465 \brief Get preference item option value.
3466 \param name option name
3467 \return property value or null QVariant if option is not set
3468 \sa setOptionValue()
3470 QVariant QtxPagePrefPathListItem::optionValue( const QString& name ) const
3472 if ( name == "path_type" )
3475 return QtxPageNamedPrefItem::optionValue( name );
3479 \brief Set preference item option value.
3480 \param name option name
3481 \param val new property value
3484 void QtxPagePrefPathListItem::setOptionValue( const QString& name, const QVariant& val )
3486 if ( name == "path_type" )
3488 if ( val.canConvert( QVariant::Int ) )
3489 setPathType( (Qtx::PathType)val.toInt() );
3492 QtxPageNamedPrefItem::setOptionValue( name, val );
3496 \class QtxPagePrefDateTimeItem
3497 \brief GUI implementation of resources date/time item.
3503 Creates an item to enter date and time.
3505 \param title preference item title
3506 \param parent parent preference item
3507 \param sect resource file section associated with the preference item
3508 \param param resource file parameter associated with the preference item
3510 QtxPagePrefDateTimeItem::QtxPagePrefDateTimeItem( const QString& title, QtxPreferenceItem* parent,
3511 const QString& sect, const QString& param )
3512 : QtxPageNamedPrefItem( title, parent, sect, param ),
3515 setControl( myDateTime = new QDateTimeEdit() );
3516 myDateTime->setCalendarPopup( true );
3517 myDateTime->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
3524 Creates preference item for editing of the date and/or time value:
3525 the type is specified by parameter \a type.
3527 \param type preference item input type (QtxPagePrefDateTimeItem::InputType)
3528 \param title preference item title
3529 \param parent parent preference item
3530 \param sect resource file section associated with the preference item
3531 \param param resource file parameter associated with the preference item
3533 QtxPagePrefDateTimeItem::QtxPagePrefDateTimeItem( const int type, const QString& title, QtxPreferenceItem* parent,
3534 const QString& sect, const QString& param )
3535 : QtxPageNamedPrefItem( title, parent, sect, param ),
3538 setControl( myDateTime = new QDateTimeEdit() );
3539 myDateTime->setCalendarPopup( true );
3540 myDateTime->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
3547 QtxPagePrefDateTimeItem::~QtxPagePrefDateTimeItem()
3552 \brief Get date/time box preference item input type.
3553 \return preference item input type (QtxPagePrefDateTimeItem::InputType)
3556 int QtxPagePrefDateTimeItem::inputType() const
3562 \brief Set date/time box preference item input type.
3563 \param type new preference item input type (QtxPagePrefDateTimeItem::InputType)
3566 void QtxPagePrefDateTimeItem::setInputType( const int type )
3568 if ( myType == type )
3576 \brief Check if the popup calendar menu is enabled.
3577 \return \c true if calendar popup menu is enabled
3579 bool QtxPagePrefDateTimeItem::calendar() const
3581 return myDateTime->calendarPopup();
3585 \brief Enable/disable popup calendar menu.
3586 \param on new flag state
3588 void QtxPagePrefDateTimeItem::setCalendar( const bool on )
3590 myDateTime->setCalendarPopup( on );
3594 \brief Get maximum date value.
3595 \return maximum date value
3596 \sa setMaximumDate(), minimumDate(), maximumTime(), minimumTime()
3598 QDate QtxPagePrefDateTimeItem::maximumDate() const
3600 return myDateTime->maximumDate();
3604 \brief Get maximum time value.
3605 \return maximum time value
3606 \sa setMaximumTime(), minimumTime(), maximumDate(), minimumDate()
3608 QTime QtxPagePrefDateTimeItem::maximumTime() const
3610 return myDateTime->maximumTime();
3614 \brief Get minimum date value.
3615 \return minimum date value
3616 \sa setMinimumDate(), maximumDate(), maximumTime(), minimumTime()
3618 QDate QtxPagePrefDateTimeItem::minimumDate() const
3620 return myDateTime->minimumDate();
3624 \brief Get minimum time value.
3625 \return maximum time value
3626 \sa setMinimumTime(), maximumTime(), maximumDate(), minimumDate()
3628 QTime QtxPagePrefDateTimeItem::minimumTime() const
3630 return myDateTime->minimumTime();
3634 \brief Set maximum date value.
3635 \param d new maximum date value
3636 \sa maximumDate(), minimumDate(), maximumTime(), minimumTime()
3638 void QtxPagePrefDateTimeItem::setMaximumDate( const QDate& d )
3641 myDateTime->setMaximumDate( d );
3643 myDateTime->clearMaximumDate();
3647 \brief Set maximum time value.
3648 \param t new maximum time value
3649 \sa maximumTime(), minimumTime(), maximumDate(), minimumDate()
3651 void QtxPagePrefDateTimeItem::setMaximumTime( const QTime& t )
3654 myDateTime->setMaximumTime( t );
3656 myDateTime->clearMaximumTime();
3660 \brief Set minimum date value.
3661 \param d new minimum date value
3662 \sa minimumDate(), maximumDate(), maximumTime(), minimumTime()
3664 void QtxPagePrefDateTimeItem::setMinimumDate( const QDate& d )
3667 myDateTime->setMinimumDate( d );
3669 myDateTime->clearMinimumDate();
3673 \brief Set minimum time value.
3674 \param t new minimum time value
3675 \sa minimumTime(), maximumTime(), maximumDate(), minimumDate()
3677 void QtxPagePrefDateTimeItem::setMinimumTime( const QTime& t )
3680 myDateTime->setMinimumTime( t );
3682 myDateTime->clearMinimumTime();
3686 \brief Store preference item to the resource manager.
3689 void QtxPagePrefDateTimeItem::store()
3692 switch ( inputType() )
3695 str = myDateTime->date().toString( Qt::ISODate );
3698 str = myDateTime->time().toString( Qt::ISODate );
3701 str = myDateTime->dateTime().toString( Qt::ISODate );
3709 \brief Retrieve preference item from the resource manager.
3712 void QtxPagePrefDateTimeItem::retrieve()
3714 QString str = getString();
3715 switch ( inputType() )
3718 myDateTime->setDate( QDate::fromString( str, Qt::ISODate ) );
3721 myDateTime->setTime( QTime::fromString( str, Qt::ISODate ) );
3724 myDateTime->setDateTime( QDateTime::fromString( str, Qt::ISODate ) );
3730 \brief Get preference item option value.
3731 \param name option name
3732 \return property value or null QVariant if option is not set
3733 \sa setOptionValue()
3735 QVariant QtxPagePrefDateTimeItem::optionValue( const QString& name ) const
3737 if ( name == "input_type" || name == "type" )
3739 else if ( name == "minimum_date" || name == "min_date" )
3740 return minimumDate();
3741 else if ( name == "maximum_date" || name == "max_date" )
3742 return maximumDate();
3743 else if ( name == "minimum_time" || name == "min_time" )
3744 return minimumTime();
3745 else if ( name == "maximum_time" || name == "max_time" )
3746 return maximumTime();
3748 return QtxPageNamedPrefItem::optionValue( name );
3752 \brief Set preference item option value.
3753 \param name option name
3754 \param val new property value
3757 void QtxPagePrefDateTimeItem::setOptionValue( const QString& name, const QVariant& val )
3759 if ( name == "input_type" || name == "type" )
3761 if ( val.canConvert( QVariant::Int ) )
3762 setInputType( val.toInt() );
3764 else if ( name == "minimum_date" || name == "min_date" )
3766 if ( val.canConvert( QVariant::Date ) )
3767 setMinimumDate( val.toDate() );
3769 else if ( name == "maximum_date" || name == "max_date" )
3771 if ( val.canConvert( QVariant::Date ) )
3772 setMaximumDate( val.toDate() );
3774 else if ( name == "minimum_time" || name == "min_time" )
3776 if ( val.canConvert( QVariant::Time ) )
3777 setMinimumTime( val.toTime() );
3779 else if ( name == "maximum_time" || name == "max_time" )
3781 if ( val.canConvert( QVariant::Time ) )
3782 setMaximumTime( val.toTime() );
3785 QtxPageNamedPrefItem::setOptionValue( name, val );
3789 \brief Update date/time widget.
3791 void QtxPagePrefDateTimeItem::updateDateTime()
3794 switch ( inputType() )
3797 dispFmt = QDateEdit().displayFormat();
3800 dispFmt = QTimeEdit().displayFormat();
3803 dispFmt = QDateTimeEdit().displayFormat();
3807 myDateTime->setDisplayFormat( dispFmt );