Salome HOME
a561c46a4c9eec16eeb9c4ea9bcbb4059b7cac64
[modules/gui.git] / src / Qtx / QtxPagePrefMgr.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File:      QtxPagePrefMgr.cxx
21 // Author:    Sergey TELKOV
22 //
23 #include "QtxPagePrefMgr.h"
24
25 #include "QtxGridBox.h"
26 #include "QtxFontEdit.h"
27 #include "QtxGroupBox.h"
28 #include "QtxComboBox.h"
29 #include "QtxIntSpinBox.h"
30 #include "QtxColorButton.h"
31 #include "QtxBiColorTool.h"
32 #include "QtxDoubleSpinBox.h"
33 #include "QtxBackgroundTool.h"
34 #include "QtxResourceMgr.h"
35
36 #include <QEvent>
37 #include <QLayout>
38 #include <QToolBox>
39 #include <QLineEdit>
40 #include <QTextEdit>
41 #include <QCheckBox>
42 #include <QSplitter>
43 #include <QTabWidget>
44 #include <QListWidget>
45 #include <QApplication>
46 #include <QDateTimeEdit>
47 #include <QStackedWidget>
48 #include <QSlider>
49 #include <QScrollArea>
50
51 #include <stdio.h>
52
53 namespace
54 {
55   bool toStringList(const QVariant& value, QStringList& result)
56   {
57     bool ok = false;
58     if ( value.type() == QVariant::StringList )
59     {
60       result = value.toStringList();
61       ok = true;
62     }
63     else if ( value.type() == QVariant::List )
64     {
65       QList<QVariant> valueList = value.toList();
66       for ( QList<QVariant>::const_iterator it = valueList.begin(); it != valueList.end(); ++it )
67       {
68         if ( (*it).canConvert( QVariant::String ) )
69           result.append( (*it).toString() );
70       }
71       ok = true;
72     }
73     return ok;
74   }
75 }
76
77 /*!
78   \class QtxPagePrefMgr
79   \brief GUI implementation of the QtxPreferenceMgr class: preferences manager.
80 */
81
82 /*!
83   \brief Constructor.
84   \param resMgr resource manager
85   \param parent parent widget
86 */
87 QtxPagePrefMgr::QtxPagePrefMgr( QtxResourceMgr* resMgr, QWidget* parent )
88 : QFrame( parent ),
89   QtxPreferenceMgr( resMgr ),
90   myInit( false )
91 {
92   myBox = new QtxGridBox( 1, Qt::Horizontal, this, 0 );
93   QVBoxLayout* base = new QVBoxLayout( this );
94   base->setMargin( 5 );
95   base->setSpacing( 0 );
96   base->addWidget( myBox );
97 }
98
99 /*!
100   \brief Destructor
101 */
102 QtxPagePrefMgr::~QtxPagePrefMgr()
103 {
104 }
105
106 /*!
107   \brief Get recommended size for the widget.
108   \return recommended widget size
109 */
110 QSize QtxPagePrefMgr::sizeHint() const
111 {
112   return QFrame::sizeHint();
113 }
114
115 /*!
116   \brief Get recommended minimum size for the widget.
117   \return recommended minimum widget size
118 */
119 QSize QtxPagePrefMgr::minimumSizeHint() const
120 {
121   return QFrame::minimumSizeHint();
122 }
123
124 /*!
125   \brief Customize show/hide widget operation.
126   \param on if \c true the widget is being shown, otherswise
127   it is being hidden
128 */
129 void QtxPagePrefMgr::setVisible( bool on )
130 {
131   if ( on )
132     initialize();
133
134   QApplication::instance()->processEvents();
135
136   QFrame::setVisible( on );
137 }
138
139 /*!
140   \brief Update widget contents.
141 */
142 void QtxPagePrefMgr::updateContents()
143 {
144   QtxPreferenceMgr::updateContents();
145
146   QList<QtxPreferenceItem*> lst = childItems();
147   for ( QList<QtxPreferenceItem*>::const_iterator it = lst.begin(); it != lst.end(); ++it )
148   {
149     QtxPagePrefItem* item = dynamic_cast<QtxPagePrefItem*>( *it );
150     if ( item && item->widget() && item->widget()->parent() != myBox )
151       item->widget()->setParent( myBox );
152   }
153
154   setWindowIcon( icon() );
155 }
156
157 /*!
158   \brief Callback function which is called when the child
159   preference item is added.
160   \param item child item being added
161   \sa itemRemoved(), itemChanged()
162 */
163 void QtxPagePrefMgr::itemAdded( QtxPreferenceItem* /*item*/ )
164 {
165   triggerUpdate();
166 }
167
168 /*!
169   \brief Callback function which is called when the child
170   preference item is removed.
171   \param item child item being removed
172   \sa itemAdded(), itemChanged()
173 */
174 void QtxPagePrefMgr::itemRemoved( QtxPreferenceItem* /*item*/ )
175 {
176   triggerUpdate();
177 }
178
179 /*!
180   \brief Callback function which is called when the child
181   preference item is modified.
182   \param item child item being modified
183   \sa itemAdded(), itemRemoved()
184 */
185 void QtxPagePrefMgr::itemChanged( QtxPreferenceItem* /*item*/ )
186 {
187   triggerUpdate();
188 }
189
190 /*!
191   \brief Get preference item option value.
192   \param name option name
193   \return property value or null QVariant if option is not set
194   \sa setOptionValue()
195 */
196 QVariant QtxPagePrefMgr::optionValue( const QString& name ) const
197 {
198   if ( name == "orientation" )
199     return myBox->orientation() == Qt::Horizontal ? Qt::Vertical : Qt::Horizontal;
200   else
201     return QtxPreferenceMgr::optionValue( name );
202 }
203
204 /*!
205   \brief Set preference item option value.
206   \param name option name
207   \param val new property value
208   \sa optionValue()
209 */
210 void QtxPagePrefMgr::setOptionValue( const QString& name, const QVariant& val )
211 {
212   if ( name == "orientation" )
213   {
214     if ( val.canConvert( QVariant::Int ) )
215       myBox->setOrientation( val.toInt() == Qt::Horizontal ? Qt::Vertical : Qt::Horizontal );
216   }
217   else
218     QtxPreferenceMgr::setOptionValue( name, val );
219 }
220
221 /*!
222   \brief Perform internal initialization.
223 */
224 void QtxPagePrefMgr::initialize() const
225 {
226   //  if ( myInit )
227   //    return;
228
229   QtxPagePrefMgr* that = (QtxPagePrefMgr*)this;
230   that->initialize( that );
231
232   //  that->myInit = true;
233 }
234
235 void QtxPagePrefMgr::initialize( QtxPreferenceItem* item )
236 {
237   if ( !item )
238     return;
239
240   QList<QtxPreferenceItem*> lst = item->childItems( false );
241   for ( QList<QtxPreferenceItem*>::iterator it = lst.begin(); it != lst.end(); ++it )
242     initialize( *it );
243
244   updateContents();
245 }
246
247 /*!
248   \class QtxPagePrefItem
249   \brief Base class for implementation of all the widget-based
250   preference items.
251 */
252
253 class QtxPagePrefItem::Listener : public QObject
254 {
255 public:
256   Listener( QtxPagePrefItem* );
257   virtual ~Listener();
258
259   virtual bool eventFilter( QObject*, QEvent* );
260
261 private:
262   QtxPagePrefItem* myItem;
263 };
264
265 QtxPagePrefItem::Listener::Listener( QtxPagePrefItem* item )
266 : QObject( 0 ),
267   myItem( item )
268 {
269 }
270
271 QtxPagePrefItem::Listener::~Listener()
272 {
273 }
274
275 bool QtxPagePrefItem::Listener::eventFilter( QObject* o, QEvent* e )
276 {
277   if ( !myItem || myItem->widget() != o )
278     return false;
279
280   if ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent )
281     myItem->widgetShown();
282   if ( e->type() == QEvent::Hide || e->type() == QEvent::HideToParent )
283     myItem->widgetHided();
284
285   return false;
286 }
287
288 /*!
289   \brief Constructor.
290   \param title preference item title
291   \param parent parent preference item
292   \param sect resource file section associated with the preference item
293   \param param resource file parameter associated with the preference item
294 */
295 QtxPagePrefItem::QtxPagePrefItem( const QString& title, QtxPreferenceItem* parent,
296                                   const QString& sect, const QString& param )
297 : QtxPreferenceItem( title, sect, param, parent ),
298   myWidget( 0 ),
299   myListener( 0 )
300 {
301 }
302
303 /*!
304   \brief Destructor.
305 */
306 QtxPagePrefItem::~QtxPagePrefItem()
307 {
308   delete myWidget;
309   delete myListener;
310 }
311
312 void QtxPagePrefItem::activate()
313 {
314   QtxPreferenceItem::activate();
315
316   if ( widget() )
317     widget()->setFocus();
318 }
319
320 /*!
321   \brief Get preference item editor widget.
322   \return editor widget
323   \sa setWidget()
324 */
325 QWidget* QtxPagePrefItem::widget() const
326 {
327   return myWidget;
328 }
329
330 /*!
331   \brief Set preference item editor widget.
332   \param wid editor widget
333   \sa widget()
334 */
335 void QtxPagePrefItem::setWidget( QWidget* wid )
336 {
337   if ( myWidget && myListener )
338     myWidget->removeEventFilter( myListener );
339
340   myWidget = wid;
341
342   if ( myWidget )
343   {
344     if ( !myListener )
345       myListener = new Listener( this );
346     myWidget->installEventFilter( myListener );
347   }
348
349   sendItemChanges();
350 }
351
352 /*!
353   \brief Callback function which is called when the child
354   preference item is added.
355   \param item child item being added
356   \sa itemRemoved(), itemChanged()
357 */
358 void QtxPagePrefItem::itemAdded( QtxPreferenceItem* /*item*/ )
359 {
360   contentChanged();
361 }
362
363 /*!
364   \brief Callback function which is called when the child
365   preference item is removed.
366   \param item child item being removed
367   \sa itemAdded(), itemChanged()
368 */
369 void QtxPagePrefItem::itemRemoved( QtxPreferenceItem* /*item*/ )
370 {
371   contentChanged();
372 }
373
374 /*!
375   \brief Callback function which is called when the child
376   preference item is modified.
377   \param item child item being modified
378   \sa itemAdded(), itemRemoved()
379 */
380 void QtxPagePrefItem::itemChanged( QtxPreferenceItem* /*item*/ )
381 {
382   contentChanged();
383 }
384
385 /*!
386   \brief Store preference item to the resource manager.
387
388   This method should be reimplemented in the subclasses.
389   Base implementation does nothing.
390
391   \sa retrieve()
392 */
393 void QtxPagePrefItem::store()
394 {
395 }
396
397 /*!
398   \brief Retrieve preference item from the resource manager.
399
400   This method should be reimplemented in the subclasses.
401   Base implementation does nothing.
402
403   \sa store()
404 */
405 void QtxPagePrefItem::retrieve()
406 {
407 }
408
409 /*!
410   \brief Invoked when preference item widget is shown.
411 */
412 void QtxPagePrefItem::widgetShown()
413 {
414 }
415
416 /*!
417   \brief Invoked when preference item widget is hided.
418 */
419 void QtxPagePrefItem::widgetHided()
420 {
421 }
422
423 void QtxPagePrefItem::ensureVisible( QtxPreferenceItem* i )
424 {
425   QtxPreferenceItem::ensureVisible();
426
427   QtxPagePrefItem* item = dynamic_cast<QtxPagePrefItem*>( i );
428   if ( item && item->widget() )
429     item->widget()->setVisible( true );
430 }
431
432 /*!
433   \brief Find all child items of the QtxPagePrefItem type.
434   \param list used to return list of child items
435   \param rec if \c true, perform recursive search
436 */
437 void QtxPagePrefItem::pageChildItems( QList<QtxPagePrefItem*>& list, const bool rec ) const
438 {
439   QList<QtxPreferenceItem*> lst = childItems( rec );
440   for ( QList<QtxPreferenceItem*>::const_iterator it = lst.begin(); it != lst.end(); ++it )
441   {
442     QtxPagePrefItem* item = dynamic_cast<QtxPagePrefItem*>( *it );
443     if ( item )
444       list.append( item );
445   }
446 }
447
448 /*!
449   \brief Called when contents is changed (item is added, removed or modified).
450
451   Triggers the item update.
452 */
453 void QtxPagePrefItem::contentChanged()
454 {
455   triggerUpdate();
456 }
457
458 /*!
459   \class QtxPageNamedPrefItem
460   \brief Base class for implementation of the named preference items
461   (items with text labels).
462 */
463
464 /*!
465   \brief Constructor.
466   \param title preference item title
467   \param parent parent preference item
468   \param sect resource file section associated with the preference item
469   \param param resource file parameter associated with the preference item
470 */
471 QtxPageNamedPrefItem::QtxPageNamedPrefItem( const QString& title, QtxPreferenceItem* parent,
472                                             const QString& sect, const QString& param )
473 : QtxPagePrefItem( title, parent, sect, param ),
474   myControl( 0 )
475 {
476   QWidget* main = new QWidget();
477
478   //  QtxPagePrefGroupItem* aGroup = 0;//dynamic_cast<QtxPagePrefGroupItem*>(parent);
479   //  if ( !aGroup )
480   //  {
481     QHBoxLayout* base = new QHBoxLayout( main );
482     base->setMargin( 0 );
483     base->setSpacing( 5 );
484
485     myLabel = new QLabel( title, main );
486     base->addWidget( myLabel );
487     //  }
488     //  else
489     //    myLabel = new QLabel( title, aGroup->gridBox() );
490
491   setWidget( main );
492
493   myLabel->setVisible( !title.isEmpty() );
494 }
495
496 /*!
497   \brief Destructor.
498 */
499 QtxPageNamedPrefItem::~QtxPageNamedPrefItem()
500 {
501 }
502
503 /*!
504   \brief Set preference title.
505   \param txt new preference title.
506 */
507 void QtxPageNamedPrefItem::setTitle( const QString& txt )
508 {
509   QtxPagePrefItem::setTitle( txt );
510
511   label()->setText( title() );
512   if ( !title().isEmpty() )
513     label()->setVisible( true );
514 }
515
516 /*!
517   \brief Get label widget corresponding to the preference item.
518   \return label widget
519 */
520 QLabel* QtxPageNamedPrefItem::label() const
521 {
522   return myLabel;
523 }
524
525 /*!
526   \brief Get control widget corresponding to the preference item.
527   \return control widget
528   \sa setControl()
529 */
530 QWidget* QtxPageNamedPrefItem::control() const
531 {
532   return myControl;
533 }
534
535 /*!
536   \brief Set control widget corresponding to the preference item.
537   \param wid control widget
538   \sa control()
539 */
540 void QtxPageNamedPrefItem::setControl( QWidget* wid )
541 {
542   if ( myControl == wid )
543     return;
544
545   delete myControl;
546   myControl = wid;
547
548   if ( myControl )
549   {
550     //    QtxPagePrefGroupItem* aGroup = 0;//dynamic_cast<QtxPagePrefGroupItem*>(parentItem());
551     //    if ( !aGroup )
552     widget()->layout()->addWidget( myControl );
553     widget()->setFocusProxy( myControl );
554       //    else myControl->setParent( aGroup->gridBox() );
555   }
556 }
557
558 void QtxPageNamedPrefItem::adjustLabels( QtxPagePrefItem* parent )
559 {
560   if ( !parent )
561     return;
562
563   QList<QtxPreferenceItem*> childList = parent->childItems();
564
565   QList<QtxPageNamedPrefItem*> namedItems;
566   for ( QList<QtxPreferenceItem*>::iterator it = childList.begin(); it != childList.end(); ++it )
567   {
568     QtxPageNamedPrefItem* item = dynamic_cast<QtxPageNamedPrefItem*>( *it );
569     if ( item )
570       namedItems.append( item );
571   }
572
573   int sz = 0;
574   for ( QList<QtxPageNamedPrefItem*>::iterator it1 = namedItems.begin(); it1 != namedItems.end(); ++it1 )
575   {
576     QtxPageNamedPrefItem* item = *it1;
577     if ( item->label() )
578       sz = qMax( sz, item->label()->sizeHint().width() );
579   }
580
581   for ( QList<QtxPageNamedPrefItem*>::iterator it2 = namedItems.begin(); it2 != namedItems.end(); ++it2 )
582   {
583     QtxPageNamedPrefItem* item = *it2;
584     if ( item->label() )
585       item->label()->setMinimumWidth( sz );
586   }
587 }
588
589 /*!
590   \class QtxPagePrefListItem
591   \brief GUI implementation of the list container preference item.
592 */
593
594 /*!
595   \brief Constructor.
596   \param title preference item title
597   \param parent parent preference item
598   \param sect resource file section associated with the preference item
599   \param param resource file parameter associated with the preference item
600 */
601 QtxPagePrefListItem::QtxPagePrefListItem( const QString& title, QtxPreferenceItem* parent,
602                                           const QString& sect, const QString& param )
603 : QtxPagePrefItem( title, parent, sect, param ),
604   myFix( false )
605 {
606   QSplitter* main = new QSplitter( Qt::Horizontal );
607   main->setChildrenCollapsible( false );
608
609   main->addWidget( myList = new QListWidget( main ) );
610   main->addWidget( myStack = new QStackedWidget( main ) );
611
612   myList->setSelectionMode( QListWidget::SingleSelection );
613
614   myStack->addWidget( myInfLabel = new QLabel( myStack ) );
615   myInfLabel->setAlignment( Qt::AlignCenter );
616
617   connect( myList, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) );
618
619   setWidget( main );
620 }
621
622 /*!
623   \brief Destructor.
624 */
625 QtxPagePrefListItem::~QtxPagePrefListItem()
626 {
627 }
628
629 /*!
630   \brief Get message text which is shown if the container is empty.
631   \return message text
632   \sa setEmptyInfo()
633 */
634 QString QtxPagePrefListItem::emptyInfo() const
635 {
636   return myInfText;
637 }
638
639 /*!
640   \brief Set message text which is shown if the container is empty.
641   \param new message text
642   \sa emptyInfo()
643 */
644 void QtxPagePrefListItem::setEmptyInfo( const QString& inf )
645 {
646   if ( myInfText == inf )
647     return;
648
649   myInfText = inf;
650
651   updateVisible();
652 }
653
654 /*!
655   \brief Check if the preference item widget is of fixed size.
656   \return \c true if the widget has the fixed size
657   \sa setFixedSize()
658 */
659 bool QtxPagePrefListItem::isFixedSize() const
660 {
661   return myFix;
662 }
663
664 /*!
665   \brief Set the preference item widget to be of fixed size.
666   \param on if \c true, the widget will have the fixed size
667   \sa isFixedSize()
668 */
669 void QtxPagePrefListItem::setFixedSize( const bool on )
670 {
671   if ( myFix == on )
672     return;
673
674   myFix = on;
675
676   updateGeom();
677 }
678
679 /*!
680   \brief Update widget contents.
681 */
682 void QtxPagePrefListItem::updateContents()
683 {
684   QtxPagePrefItem::updateContents();
685   updateVisible();
686 }
687
688 /*!
689   \brief Get preference item option value.
690   \param name option name
691   \return property value or null QVariant if option is not set
692   \sa setOptionValue()
693 */
694 QVariant QtxPagePrefListItem::optionValue( const QString& name ) const
695 {
696   if ( name == "fixed_size" )
697     return isFixedSize();
698   else if ( name == "empty_info" || name == "info" )
699     return emptyInfo();
700   else
701     return QtxPagePrefItem::optionValue( name );
702 }
703
704 /*!
705   \brief Set preference item option value.
706   \param name option name
707   \param val new property value
708   \sa optionValue()
709 */
710 void QtxPagePrefListItem::setOptionValue( const QString& name, const QVariant& val )
711 {
712   if ( name == "fixed_size" )
713   {
714     if ( val.canConvert( QVariant::Bool ) )
715       setFixedSize( val.toBool() );
716   }
717   else if ( name == "empty_info" || name == "info" )
718   {
719     if ( val.canConvert( QVariant::String ) )
720       setEmptyInfo( val.toString() );
721   }
722   else
723     QtxPagePrefItem::setOptionValue( name, val );
724 }
725
726 void QtxPagePrefListItem::widgetShown()
727 {
728   updateState();
729 }
730
731 void QtxPagePrefListItem::ensureVisible( QtxPreferenceItem* i )
732 {
733   if ( !i )
734     return;
735
736   QtxPreferenceItem::ensureVisible( i );
737
738   setSelected( i->id() );
739   updateState();
740 }
741
742 /*!
743   \brief Called when the selection in the list box is changed.
744 */
745 void QtxPagePrefListItem::onItemSelectionChanged()
746 {
747   updateState();
748 }
749
750 /*!
751   \brief Update information label widget.
752 */
753 void QtxPagePrefListItem::updateInfo()
754 {
755   QString infoText;
756   QtxPagePrefItem* item = selectedItem();
757   if ( item )
758   {
759     infoText = emptyInfo();
760     QRegExp rx( "%([%|N])" );
761
762     int idx = 0;
763     while ( ( idx = rx.indexIn( infoText ) ) != -1 )
764     {
765       if ( rx.cap() == QString( "%%" ) )
766         infoText.replace( idx, rx.matchedLength(), "%" );
767       else if ( rx.cap() == QString( "%N" ) )
768         infoText.replace( idx, rx.matchedLength(), item->title() );
769     }
770   }
771   myInfLabel->setText( infoText );
772 }
773
774 /*!
775   \brief Update widget state.
776 */
777 void QtxPagePrefListItem::updateState()
778 {
779   QtxPagePrefItem* item = selectedItem();
780   QWidget* wid = item && !item->isEmpty() ? item->widget() : myInfLabel;
781   if ( wid )
782     myStack->setCurrentWidget( wid );
783
784   updateInfo();
785 }
786
787 /*!
788   \brief Update visibile child widgets.
789 */
790 void QtxPagePrefListItem::updateVisible()
791 {
792   QList<QtxPagePrefItem*> items;
793   pageChildItems( items );
794
795   QMap<QWidget*, int> map;
796   for ( int i = 0; i < (int)myStack->count(); i++ )
797     map.insert( myStack->widget( i ), 0 );
798
799   int selId = selected();
800   myList->clear();
801   for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end(); ++it )
802   {
803     if ( (*it)->isEmpty() && myInfText.isEmpty() )
804       continue;
805
806     myList->addItem( (*it)->title() );
807     myList->item( myList->count() - 1 )->setIcon( (*it)->icon() );
808     myList->item( myList->count() - 1 )->setData( Qt::UserRole, (*it)->id() );
809
810     QWidget* wid = (*it)->widget();
811     if ( !map.contains( wid ) )
812       myStack->addWidget( wid );
813
814     map.remove( wid );
815   }
816
817   map.remove( myInfLabel );
818
819   for ( QMap<QWidget*, int>::const_iterator it = map.begin(); it != map.end(); ++it )
820     myStack->removeWidget( it.key() );
821
822   setSelected( selId );
823   if ( selected() == -1 && myList->count() )
824     setSelected( myList->item( 0 )->data( Qt::UserRole ).toInt() );
825
826   //myList->setVisible( myList->count() > 1 );
827
828   updateState();
829   updateGeom();
830 }
831
832 /*!
833   \brief Update widget geometry.
834 */
835 void QtxPagePrefListItem::updateGeom()
836 {
837   if ( myFix )
838     myList->setFixedWidth( myList->minimumSizeHint().width() + 10 );
839   else
840   {
841     myList->setMinimumWidth( 0 );
842     myList->setMaximumWidth( 16777215 );
843
844     QSplitter* s = ::qobject_cast<QSplitter*>( widget() );
845     if ( s )
846     {
847       int w = myList->minimumSizeHint().width() + 30;
848       QList<int> szList;
849       szList.append( w );
850       szList.append( s->width() - w );
851       s->setSizes( szList );
852     }
853   }
854 }
855
856 /*!
857   \brief Get identifier of the currently selected preference item.
858   \return identifier of the currently selected item or -1 if no item is selected
859   \sa setSelected()
860 */
861 int QtxPagePrefListItem::selected() const
862 {
863   QList<QListWidgetItem*> selList = myList->selectedItems();
864   if ( selList.isEmpty() )
865     return -1;
866
867   QVariant v = selList.first()->data( Qt::UserRole );
868   return v.canConvert( QVariant::Int ) ? v.toInt() : -1;
869 }
870
871 /*!
872   \brief Get currently selected preference item.
873   \return currently selected item or 0 if no item is selected
874   \sa setSelected()
875 */
876 QtxPagePrefItem* QtxPagePrefListItem::selectedItem() const
877 {
878   int selId = selected();
879
880   QList<QtxPagePrefItem*> items;
881   pageChildItems( items );
882
883   QtxPagePrefItem* item = 0;
884   for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end() && !item; ++it )
885   {
886     if ( (*it)->id() == selId )
887       item = *it;
888   }
889   return item;
890 }
891
892 /*!
893   \brief Set currently selected preference item.
894   \param id identifier of the preference item to make selected
895 */
896 void QtxPagePrefListItem::setSelected( const int id )
897 {
898   int idx = -1;
899   for ( int i = 0; i < (int)myList->count() && idx < 0; i++ )
900   {
901     QVariant v = myList->item( i )->data( Qt::UserRole );
902     if ( v.canConvert( QVariant::Int ) && v.toInt() == id )
903       idx = i;
904   }
905
906   QItemSelection sel;
907   QItemSelectionModel* selModel = myList->selectionModel();
908
909   if ( idx >= 0 )
910     sel.select( myList->model()->index( idx, 0 ), myList->model()->index( idx, 0 ) );
911
912   selModel->select( sel, QItemSelectionModel::ClearAndSelect );
913 }
914
915 /*!
916   \class QtxPagePrefToolBoxItem
917   \brief GUI implementation of the tool box container preference item.
918 */
919
920 /*!
921   \brief Constructor.
922   \param title preference item title
923   \param parent parent preference item
924   \param sect resource file section associated with the preference item
925   \param param resource file parameter associated with the preference item
926 */
927 QtxPagePrefToolBoxItem::QtxPagePrefToolBoxItem( const QString& title, QtxPreferenceItem* parent,
928                                                 const QString& sect, const QString& param )
929 : QtxPagePrefItem( title, parent, sect, param )
930 {
931   setWidget( myToolBox = new QToolBox( 0 ) );
932 }
933
934 /*!
935   \brief Destructor.
936 */
937 QtxPagePrefToolBoxItem::~QtxPagePrefToolBoxItem()
938 {
939 }
940
941 /*!
942   \brief Update widget contents.
943 */
944 void QtxPagePrefToolBoxItem::updateContents()
945 {
946   QtxPagePrefItem::updateContents();
947   updateToolBox();
948 }
949
950 /*!
951   \brief Update tool box widget.
952 */
953 void QtxPagePrefToolBoxItem::updateToolBox()
954 {
955   QList<QtxPagePrefItem*> items;
956   pageChildItems( items );
957
958   QWidget* cur = myToolBox->currentWidget();
959
960   int i = 0;
961   QMap<QWidget*, int> map;
962   for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end(); ++it )
963   {
964     QWidget* wid = (*it)->widget();
965     if ( !wid )
966       continue;
967
968     if ( myToolBox->widget( i ) != wid )
969     {
970       if ( myToolBox->indexOf( wid ) != -1 )
971         myToolBox->removeItem( myToolBox->indexOf( wid ) );
972
973       myToolBox->insertItem( i, wid, (*it)->title() );
974     }
975     else
976       myToolBox->setItemText( i, (*it)->title() );
977
978     myToolBox->setItemIcon( i, (*it)->icon() );
979
980     i++;
981     map.insert( wid, 0 );
982   }
983
984   QList<QWidget*> del;
985   for ( int idx = 0; idx < (int)myToolBox->count(); idx++ )
986   {
987     QWidget* w = myToolBox->widget( idx );
988     if ( !map.contains( w ) )
989       del.append( w );
990   }
991
992   for ( QList<QWidget*>::const_iterator itr = del.begin(); itr != del.end(); ++itr )
993     myToolBox->removeItem( myToolBox->indexOf( *itr ) );
994
995   if ( cur )
996     myToolBox->setCurrentWidget( cur );
997 }
998
999 void QtxPagePrefToolBoxItem::ensureVisible( QtxPreferenceItem* i )
1000 {
1001   if ( !i )
1002     return;
1003
1004   QtxPreferenceItem::ensureVisible( i );
1005
1006   QtxPagePrefItem* item = dynamic_cast<QtxPagePrefItem*>( i );
1007   if ( item && item->widget() )
1008     myToolBox->setCurrentWidget( item->widget() );
1009 }
1010
1011 /*!
1012   \class QtxPagePrefTabsItem
1013   \brief GUI implementation of the tab widget container.
1014 */
1015
1016 /*!
1017   \brief Constructor.
1018   \param title preference item title
1019   \param parent parent preference item
1020   \param sect resource file section associated with the preference item
1021   \param param resource file parameter associated with the preference item
1022 */
1023 QtxPagePrefTabsItem::QtxPagePrefTabsItem( const QString& title, QtxPreferenceItem* parent,
1024                                           const QString& sect, const QString& param )
1025 : QtxPagePrefItem( title, parent, sect, param )
1026 {
1027   setWidget( myTabs = new QTabWidget( 0 ) );
1028 }
1029
1030 /*!
1031   \brief Destructor.
1032 */
1033 QtxPagePrefTabsItem::~QtxPagePrefTabsItem()
1034 {
1035 }
1036
1037 /*!
1038   \brief Update widget contents.
1039 */
1040 void QtxPagePrefTabsItem::updateContents()
1041 {
1042   QtxPagePrefItem::updateContents();
1043   updateTabs();
1044 }
1045
1046 /*!
1047   \brief Get tabs position.
1048   \return current tabs position (QTabWidget::TabPosition)
1049   \sa setTabPosition()
1050 */
1051 int QtxPagePrefTabsItem::tabPosition() const
1052 {
1053   return myTabs->tabPosition();
1054 }
1055
1056 /*!
1057   \brief Set tabs position.
1058   \param tp new tabs position (QTabWidget::TabPosition)
1059   \sa tabPosition()
1060 */
1061 void QtxPagePrefTabsItem::setTabPosition( const int tp )
1062 {
1063   myTabs->setTabPosition( (QTabWidget::TabPosition)tp );
1064 }
1065
1066 /*!
1067   \brief Get tabs shape.
1068   \return current tabs shape (QTabWidget::TabShape)
1069   \sa setTabShape()
1070 */
1071 int QtxPagePrefTabsItem::tabShape() const
1072 {
1073   return myTabs->tabShape();
1074 }
1075
1076 /*!
1077   \brief Set tabs shape.
1078   \param ts new tabs shape (QTabWidget::TabShape)
1079   \sa tabShape()
1080 */
1081 void QtxPagePrefTabsItem::setTabShape( const int ts )
1082 {
1083   myTabs->setTabShape( (QTabWidget::TabShape)ts );
1084 }
1085
1086 /*!
1087   \brief Get tabs icon size.
1088   \return current tabs icon size
1089   \sa setTabIconSize()
1090 */
1091 QSize QtxPagePrefTabsItem::tabIconSize() const
1092 {
1093   return myTabs->iconSize();
1094 }
1095
1096 /*!
1097   \brief Set tabs icon size.
1098   \param sz new tabs icon size
1099   \sa tabIconSize()
1100 */
1101 void QtxPagePrefTabsItem::setTabIconSize( const QSize& sz )
1102 {
1103   myTabs->setIconSize( sz );
1104 }
1105
1106 /*!
1107   \brief Get preference item option value.
1108   \param name option name
1109   \return property value or null QVariant if option is not set
1110   \sa setOptionValue()
1111 */
1112 QVariant QtxPagePrefTabsItem::optionValue( const QString& name ) const
1113 {
1114   if ( name == "position" )
1115     return tabPosition();
1116   else if ( name == "shape" )
1117     return tabShape();
1118   else if ( name == "icon_size" )
1119     return tabIconSize();
1120   else
1121     return QtxPagePrefItem::optionValue( name );
1122 }
1123
1124 /*!
1125   \brief Set preference item option value.
1126   \param name option name
1127   \param val new property value
1128   \sa optionValue()
1129 */
1130 void QtxPagePrefTabsItem::setOptionValue( const QString& name, const QVariant& val )
1131 {
1132   if ( name == "position" )
1133   {
1134     if ( val.canConvert( QVariant::Int ) )
1135       setTabPosition( val.toInt() );
1136   }
1137   else if ( name == "shape" )
1138   {
1139     if ( val.canConvert( QVariant::Int ) )
1140       setTabShape( val.toInt() );
1141   }
1142   else if ( name == "icon_size" )
1143   {
1144     if ( val.canConvert( QVariant::Size ) )
1145       setTabIconSize( val.toSize() );
1146   }
1147   else
1148     QtxPagePrefItem::setOptionValue( name, val );
1149 }
1150
1151 void QtxPagePrefTabsItem::ensureVisible( QtxPreferenceItem* i )
1152 {
1153   if ( !i )
1154     return;
1155
1156   QtxPreferenceItem::ensureVisible( i );
1157
1158   QtxPagePrefItem* item = dynamic_cast<QtxPagePrefItem*>( i );
1159   if ( item && item->widget() )
1160     myTabs->setCurrentWidget( item->widget() );
1161 }
1162
1163 /*!
1164   \brief Update tabs.
1165 */
1166 void QtxPagePrefTabsItem::updateTabs()
1167 {
1168   QList<QtxPagePrefItem*> items;
1169   pageChildItems( items );
1170
1171   QWidget* cur = myTabs->currentWidget();
1172
1173   int i = 0;
1174   QMap<QWidget*, int> map;
1175   for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end(); ++it )
1176   {
1177     QWidget* wid = (*it)->widget();
1178     if ( !wid )
1179       continue;
1180
1181     if ( myTabs->widget( i ) != wid )
1182     {
1183       if ( myTabs->indexOf( wid ) != -1 )
1184         myTabs->removeTab( myTabs->indexOf( wid ) );
1185
1186       myTabs->insertTab( i, wid, (*it)->title() );
1187     }
1188     else
1189       myTabs->setTabText( i, (*it)->title() );
1190
1191     myTabs->setTabIcon( i, (*it)->icon() );
1192
1193     i++;
1194     map.insert( wid, 0 );
1195   }
1196
1197   QList<QWidget*> del;
1198   for ( int idx = 0; idx < (int)myTabs->count(); idx++ )
1199   {
1200     QWidget* w = myTabs->widget( idx );
1201     if ( !map.contains( w ) )
1202       del.append( w );
1203   }
1204
1205   for ( QList<QWidget*>::const_iterator itr = del.begin(); itr != del.end(); ++itr )
1206     myTabs->removeTab( myTabs->indexOf( *itr ) );
1207
1208   if ( cur )
1209     myTabs->setCurrentWidget( cur );
1210 }
1211
1212 /*!
1213   \class QtxPagePrefFrameItem
1214   \brief GUI implementation of the frame widget container.
1215 */
1216
1217 /*!
1218   \brief Constructor.
1219   \param title preference item title
1220   \param parent parent preference item
1221   \param sect resource file section associated with the preference item
1222   \param param resource file parameter associated with the preference item
1223 */
1224 QtxPagePrefFrameItem::QtxPagePrefFrameItem( const QString& title, QtxPreferenceItem* parent,
1225                                             const QString& sect, const QString& param, const bool scrollable )
1226 : QtxPagePrefItem( title, parent, sect, param )
1227 {
1228   QWidget* main = new QWidget();
1229   QVBoxLayout* base = new QVBoxLayout( main );
1230   base->setMargin( 0 );
1231   base->setSpacing( 0 );
1232
1233   base->addWidget( myBox = new QtxGridBox( 1, Qt::Horizontal, main, 5, 5 ) );
1234   base->addStretch();
1235
1236   if ( scrollable ) {
1237     QScrollArea* scroll = new QScrollArea();
1238     scroll->setWidget( main );
1239     scroll->setWidgetResizable( true );
1240     base->layout()->setSizeConstraint(QLayout::SetMinAndMaxSize);
1241     main = scroll;
1242   }
1243
1244   setWidget( main );
1245 }
1246
1247 /*!
1248   \brief Destructor.
1249 */
1250 QtxPagePrefFrameItem::~QtxPagePrefFrameItem()
1251 {
1252 }
1253
1254 /*!
1255   \brief Update widget contents.
1256 */
1257 void QtxPagePrefFrameItem::updateContents()
1258 {
1259   QtxPagePrefItem::updateContents();
1260
1261   updateFrame();
1262
1263   QtxPageNamedPrefItem::adjustLabels( this );
1264 }
1265
1266 /*!
1267   \brief Get frame margin.
1268   \return current frame margin
1269   \sa setMargin()
1270 */
1271 int QtxPagePrefFrameItem::margin() const
1272 {
1273   return myBox->insideMargin();
1274 }
1275
1276 /*!
1277   \brief Get frame margin.
1278   \param m new frame margin
1279   \sa margin()
1280 */
1281 void QtxPagePrefFrameItem::setMargin( const int m )
1282 {
1283   myBox->setInsideMargin( m );
1284 }
1285
1286 /*!
1287   \brief Get frame spacing.
1288   \return current frame spacing
1289   \sa setSpacing()
1290 */
1291 int QtxPagePrefFrameItem::spacing() const
1292 {
1293   return myBox->insideSpacing();
1294 }
1295
1296 /*!
1297   \brief Set frame spacing.
1298   \param s new frame spacing
1299   \sa spacing()
1300 */
1301 void QtxPagePrefFrameItem::setSpacing( const int s )
1302 {
1303   myBox->setInsideSpacing( s );
1304 }
1305
1306 /*!
1307   \brief Get number of frame columns.
1308   \return current columns number
1309   \sa setColumns()
1310 */
1311 int QtxPagePrefFrameItem::columns() const
1312 {
1313   return myBox->columns();
1314 }
1315
1316 /*!
1317   \brief Set number of frame columns.
1318   \param c new columns number
1319   \sa columns()
1320 */
1321 void QtxPagePrefFrameItem::setColumns( const int c )
1322 {
1323   myBox->setColumns( c );
1324 }
1325
1326 /*!
1327   \brief Get frame box orientation.
1328   \return current frame orientation
1329   \sa setOrientation()
1330 */
1331 Qt::Orientation QtxPagePrefFrameItem::orientation() const
1332 {
1333   return myBox->orientation();
1334 }
1335
1336 /*!
1337   \brief Set frame box orientation.
1338   \param o new frame orientation
1339   \sa orientation()
1340 */
1341 void QtxPagePrefFrameItem::setOrientation( const Qt::Orientation o )
1342 {
1343   myBox->setOrientation( o );
1344 }
1345
1346 /*!
1347   \brief Check if the frame widget stretching is enabled.
1348   \return \c true if the widget is stretchable
1349   \sa setStretch()
1350 */
1351 bool QtxPagePrefFrameItem::stretch() const
1352 {
1353   QSpacerItem* s = 0;
1354   QLayout* l = widget() ? widget()->layout() : 0;
1355   for ( int i = 0; l && i < l->count() && !s; i++ )
1356     s = l->itemAt( i )->spacerItem();
1357
1358   return s ? (bool)( s->expandingDirections() & Qt::Vertical ) : false;
1359 }
1360
1361 /*!
1362   \brief Enable/disable frame widget stretching.
1363   \param on new stretchable state
1364   \sa stretch()
1365 */
1366 void QtxPagePrefFrameItem::setStretch( const bool on )
1367 {
1368   QSpacerItem* s = 0;
1369   QWidget* w = widget();
1370   if ( qobject_cast<QScrollArea*>( w ) )
1371     w = qobject_cast<QScrollArea*>( w )->widget();
1372   QLayout* l = w ? w->layout() : 0;
1373   for ( int i = 0; l && i < l->count() && !s; i++ )
1374     s = l->itemAt( i )->spacerItem();
1375
1376   if ( s )
1377     s->changeSize( 0, 0, QSizePolicy::Minimum, on ? QSizePolicy::Expanding : QSizePolicy::Minimum );
1378 }
1379
1380 /*!
1381   \brief Get preference item option value.
1382   \param name option name
1383   \return property value or null QVariant if option is not set
1384   \sa setOptionValue()
1385 */
1386 QVariant QtxPagePrefFrameItem::optionValue( const QString& name ) const
1387 {
1388   if ( name == "margin" )
1389     return margin();
1390   else if ( name == "spacing" )
1391     return spacing();
1392   else if ( name == "columns" )
1393     return columns();
1394   else if ( name == "orientation" )
1395     return orientation();
1396   else if ( name == "stretch" )
1397     return stretch();
1398   else
1399     return QtxPagePrefItem::optionValue( name );
1400 }
1401
1402 /*!
1403   \brief Set preference item option value.
1404   \param name option name
1405   \param val new property value
1406   \sa optionValue()
1407 */
1408 void QtxPagePrefFrameItem::setOptionValue( const QString& name, const QVariant& val )
1409 {
1410   if ( name == "margin" )
1411   {
1412     if ( val.canConvert( QVariant::Int ) )
1413       setMargin( val.toInt() );
1414   }
1415   else if ( name == "spacing" )
1416   {
1417     if ( val.canConvert( QVariant::Int ) )
1418       setSpacing( val.toInt() );
1419   }
1420   else if ( name == "columns" )
1421   {
1422     if ( val.canConvert( QVariant::Int ) )
1423       setColumns( val.toInt() );
1424   }
1425   else if ( name == "orientation" )
1426   {
1427     if ( val.canConvert( QVariant::Int ) )
1428       setOrientation( (Qt::Orientation)val.toInt() );
1429   }
1430   else if ( name == "stretch" )
1431   {
1432     if ( val.canConvert( QVariant::Bool ) )
1433       setStretch( val.toBool() );
1434   }
1435   else
1436     QtxPagePrefItem::setOptionValue( name, val );
1437 }
1438
1439 void QtxPagePrefFrameItem::widgetShown()
1440 {
1441   QtxPagePrefItem::widgetShown();
1442
1443   QtxPageNamedPrefItem::adjustLabels( this );
1444 }
1445
1446 /*!
1447   \brief Update frame widget.
1448 */
1449 void QtxPagePrefFrameItem::updateFrame()
1450 {
1451   QList<QtxPagePrefItem*> items;
1452   pageChildItems( items );
1453
1454   for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end(); ++it )
1455   {
1456     QWidget* wid = (*it)->widget();
1457     if ( !wid )
1458       continue;
1459
1460     if ( wid->parent() != myBox )
1461       wid->setParent( myBox );
1462   }
1463 }
1464
1465 /*!
1466   \class QtxPagePrefGroupItem
1467   \brief GUI implementation of the group widget container.
1468 */
1469
1470 /*!
1471   \brief Constructor.
1472   \param title preference item title
1473   \param parent parent preference item
1474   \param sect resource file section associated with the preference item
1475   \param param resource file parameter associated with the preference item
1476 */
1477 QtxPagePrefGroupItem::QtxPagePrefGroupItem( const QString& title, QtxPreferenceItem* parent,
1478                                             const QString& sect, const QString& param )
1479 : QtxPagePrefItem( title, parent, sect, param )
1480 {
1481   myGroup = new QtxGroupBox( title, 0 );
1482   myBox = new QtxGridBox( 1, Qt::Horizontal, myGroup, 5, 5 );
1483   myGroup->setWidget( myBox );
1484
1485   setWidget( myGroup );
1486
1487   updateState();
1488 }
1489
1490 /*!
1491   \brief Constructor.
1492   \param cols columns number
1493   \param title preference item title
1494   \param parent parent preference item
1495   \param sect resource file section associated with the preference item
1496   \param param resource file parameter associated with the preference item
1497 */
1498 QtxPagePrefGroupItem::QtxPagePrefGroupItem( const int cols, const QString& title, QtxPreferenceItem* parent,
1499                                             const QString& sect, const QString& param )
1500 : QtxPagePrefItem( title, parent, sect, param )
1501 {
1502   myGroup = new QtxGroupBox( title, 0 );
1503   myBox = new QtxGridBox( cols, Qt::Horizontal, myGroup, 5, 5 );
1504   myGroup->setWidget( myBox );
1505
1506   setWidget( myGroup );
1507
1508   updateState();
1509 }
1510
1511 /*!
1512   \brief Destructor.
1513 */
1514 QtxPagePrefGroupItem::~QtxPagePrefGroupItem()
1515 {
1516 }
1517
1518 /*!
1519   \brief Assign resource file settings to the preference item.
1520   \param sect resource file section name
1521   \param param resource file parameter name
1522   \sa resource()
1523 */
1524 void QtxPagePrefGroupItem::setResource( const QString& sect, const QString& param )
1525 {
1526   QtxPagePrefItem::setResource( sect, param );
1527   updateState();
1528 }
1529
1530 /*!
1531   \brief Update widget contents.
1532 */
1533 void QtxPagePrefGroupItem::updateContents()
1534 {
1535   QtxPagePrefItem::updateContents();
1536
1537   myGroup->setTitle( title() );
1538
1539   updateState();
1540   updateGroup();
1541
1542   QtxPageNamedPrefItem::adjustLabels( this );
1543 }
1544
1545 /*!
1546   \brief Get group box margin.
1547   \return current group box margin
1548   \sa setMargin()
1549 */
1550 int QtxPagePrefGroupItem::margin() const
1551 {
1552   return myBox->insideMargin();
1553 }
1554
1555 /*!
1556   \brief Get group box margin.
1557   \param m new group box margin
1558   \sa margin()
1559 */
1560 void QtxPagePrefGroupItem::setMargin( const int m )
1561 {
1562   myBox->setInsideMargin( m );
1563 }
1564
1565 /*!
1566   \brief Get group box spacing.
1567   \return current group box spacing
1568   \sa setSpacing()
1569 */
1570 int QtxPagePrefGroupItem::spacing() const
1571 {
1572   return myBox->insideSpacing();
1573 }
1574
1575 /*!
1576   \brief Set group box spacing.
1577   \param s new group box spacing
1578   \sa spacing()
1579 */
1580 void QtxPagePrefGroupItem::setSpacing( const int s )
1581 {
1582   myBox->setInsideSpacing( s );
1583 }
1584
1585 /*!
1586   \brief Get number of group box columns.
1587   \return current columns number
1588   \sa setColumns()
1589 */
1590 int QtxPagePrefGroupItem::columns() const
1591 {
1592   return myBox->columns();
1593 }
1594
1595 /*!
1596   \brief Set number of group box columns.
1597   \param c new columns number
1598   \sa columns()
1599 */
1600 void QtxPagePrefGroupItem::setColumns( const int c )
1601 {
1602   myBox->setColumns( c );
1603 }
1604
1605 /*!
1606   \brief Get group box orientation.
1607   \return current group box orientation
1608   \sa setOrientation()
1609 */
1610 Qt::Orientation QtxPagePrefGroupItem::orientation() const
1611 {
1612   return myBox->orientation();
1613 }
1614
1615 /*!
1616   \brief Set group box orientation.
1617   \param o new group box orientation
1618   \sa orientation()
1619 */
1620 void QtxPagePrefGroupItem::setOrientation( const Qt::Orientation o )
1621 {
1622   myBox->setOrientation( o );
1623 }
1624
1625 /*!
1626   \brief Get 'flat' flag of the group box widget.
1627   \return \c true if the group box is flat
1628 */
1629 bool QtxPagePrefGroupItem::isFlat() const
1630 {
1631   return myGroup->isFlat();
1632 }
1633
1634 /*!
1635   \brief Get 'flat' flag of the group box widget.
1636   \param on if \c true the group box will be made flat
1637 */
1638 void QtxPagePrefGroupItem::setFlat( const bool on )
1639 {
1640   myGroup->setFlat( on );
1641 }
1642
1643 /*!
1644   \brief Store preference item to the resource manager.
1645   \sa retrieve()
1646 */
1647 void QtxPagePrefGroupItem::store()
1648 {
1649   if ( myGroup->isCheckable() )
1650     setBoolean( myGroup->isChecked() );
1651 }
1652
1653 /*!
1654   \brief Return widget contained grid layout of this group.
1655 */
1656 QtxGridBox* QtxPagePrefGroupItem::gridBox() const
1657 {
1658   return myBox;
1659 }
1660
1661 /*!
1662   \brief Retrieve preference item from the resource manager.
1663   \sa store()
1664 */
1665 void QtxPagePrefGroupItem::retrieve()
1666 {
1667   if ( myGroup->isCheckable() )
1668     myGroup->setChecked( getBoolean() );
1669 }
1670
1671 /*!
1672   \brief Get preference item option value.
1673   \param name option name
1674   \return property value or null QVariant if option is not set
1675   \sa setOptionValue()
1676 */
1677 QVariant QtxPagePrefGroupItem::optionValue( const QString& name ) const
1678 {
1679   if ( name == "margin" )
1680     return margin();
1681   else if ( name == "spacing" )
1682     return spacing();
1683   else if ( name == "columns" )
1684     return columns();
1685   else if ( name == "orientation" )
1686     return orientation();
1687   else if ( name == "flat" )
1688     return isFlat();
1689   else
1690     return QtxPagePrefItem::optionValue( name );
1691 }
1692
1693 /*!
1694   \brief Set preference item option value.
1695   \param name option name
1696   \param val new property value
1697   \sa optionValue()
1698 */
1699 void QtxPagePrefGroupItem::setOptionValue( const QString& name, const QVariant& val )
1700 {
1701   if ( name == "margin" )
1702   {
1703     if ( val.canConvert( QVariant::Int ) )
1704       setMargin( val.toInt() );
1705   }
1706   else if ( name == "spacing" )
1707   {
1708     if ( val.canConvert( QVariant::Int ) )
1709       setSpacing( val.toInt() );
1710   }
1711   else if ( name == "columns" )
1712   {
1713     if ( val.canConvert( QVariant::Int ) )
1714       setColumns( val.toInt() );
1715   }
1716   else if ( name == "orientation" )
1717   {
1718     if ( val.canConvert( QVariant::Int ) )
1719       setOrientation( (Qt::Orientation)val.toInt() );
1720   }
1721   else if ( name == "flat" )
1722   {
1723     if ( val.canConvert( QVariant::Bool ) )
1724       setFlat( val.toBool() );
1725   }
1726   else
1727     QtxPagePrefItem::setOptionValue( name, val );
1728 }
1729
1730 void QtxPagePrefGroupItem::widgetShown()
1731 {
1732   QtxPagePrefItem::widgetShown();
1733
1734   QtxPageNamedPrefItem::adjustLabels( this );
1735 }
1736
1737 /*!
1738   \brief Update widget state.
1739 */
1740 void QtxPagePrefGroupItem::updateState()
1741 {
1742   QString section, param;
1743   resource( section, param );
1744   myGroup->setCheckable( !title().isEmpty() && !section.isEmpty() && !param.isEmpty() );
1745 }
1746
1747 /*!
1748   \brief Update group box widget.
1749 */
1750 void QtxPagePrefGroupItem::updateGroup()
1751 {
1752   QList<QtxPagePrefItem*> items;
1753   pageChildItems( items );
1754
1755   for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end(); ++it )
1756   {
1757     QWidget* wid = (*it)->widget();
1758     if ( !wid )
1759       continue;
1760
1761     if ( wid->parent() != myBox )
1762       wid->setParent( myBox );
1763   }
1764 }
1765
1766 /*!
1767   \class QtxPagePrefLabelItem
1768   \brief Label item which can be used in the preferences editor dialog box.
1769 */
1770
1771 /*!
1772   \brief Constructor.
1773
1774   Creates label item with specified title.
1775
1776   \param text label text
1777   \param parent parent preference item
1778 */
1779 QtxPagePrefLabelItem::QtxPagePrefLabelItem( const QString& text, QtxPreferenceItem* parent )
1780 : QtxPagePrefItem( text, parent )
1781 {
1782   setWidget( myLabel = new QLabel( text ) );
1783 }
1784
1785 QtxPagePrefLabelItem::QtxPagePrefLabelItem( Qt::Alignment align, const QString& text, QtxPreferenceItem* parent )
1786 : QtxPagePrefItem( text, parent )
1787 {
1788   setWidget( myLabel = new QLabel( text ) );
1789   myLabel->setAlignment( align );
1790 }
1791
1792 QtxPagePrefLabelItem::~QtxPagePrefLabelItem()
1793 {
1794 }
1795
1796 void QtxPagePrefLabelItem::setTitle( const QString& text )
1797 {
1798   QtxPagePrefItem::setTitle( text );
1799
1800   if ( myLabel )
1801     myLabel->setText( text );
1802 }
1803
1804 Qt::Alignment QtxPagePrefLabelItem::alignment() const
1805 {
1806   return myLabel->alignment();
1807 }
1808
1809 void QtxPagePrefLabelItem::setAlignment( Qt::Alignment align )
1810 {
1811   myLabel->setAlignment( align );
1812 }
1813
1814 QVariant QtxPagePrefLabelItem::optionValue( const QString& name ) const
1815 {
1816   QVariant val;
1817   if ( name == "alignment" )
1818     val = (int)alignment();
1819   return val;
1820 }
1821
1822 void QtxPagePrefLabelItem::setOptionValue( const QString& name, const QVariant& val )
1823 {
1824   if ( name == "alignment" )
1825   {
1826     if ( val.canConvert( QVariant::Int ) )
1827       setAlignment( (Qt::Alignment)val.toInt() );
1828   }
1829 }
1830
1831 /*!
1832   \class QtxPagePrefSpaceItem
1833   \brief Simple spacer item which can be used in the preferences
1834   editor dialog box.
1835 */
1836
1837 /*!
1838   \brief Constructor.
1839
1840   Creates spacer item with zero width and height and expanding
1841   on both directions (by height and width).
1842
1843   \param parent parent preference item
1844 */
1845 QtxPagePrefSpaceItem::QtxPagePrefSpaceItem( QtxPreferenceItem* parent )
1846 : QtxPagePrefItem( QString(), parent )
1847 {
1848   initialize( 0, 0, 1, 1 );
1849 }
1850
1851 /*!
1852   \brief Constructor.
1853
1854   Creates spacer item with zero width and height and expanding
1855   according to the specified orientation.
1856
1857   \param o spacer orientation
1858   \param parent parent preference item
1859 */
1860 QtxPagePrefSpaceItem::QtxPagePrefSpaceItem( Qt::Orientation o, QtxPreferenceItem* parent )
1861 : QtxPagePrefItem( QString(), parent )
1862 {
1863   if ( o == Qt::Horizontal )
1864     initialize( 0, 0, 1, 0 );
1865   else
1866     initialize( 0, 0, 0, 1 );
1867 }
1868
1869 /*!
1870   \brief Constructor.
1871
1872   Creates spacer item with specified width and height. The spacing
1873   item is expanding horizontally if \a w <= 0 and vertically
1874   if \a h <= 0.
1875
1876   \param w spacer width
1877   \param h spacer height
1878   \param parent parent preference item
1879 */
1880 QtxPagePrefSpaceItem::QtxPagePrefSpaceItem( const int w, const int h, QtxPreferenceItem* parent )
1881 : QtxPagePrefItem( QString(), parent )
1882 {
1883   initialize( w, h, w > 0 ? 0 : 1, h > 0 ? 0 : 1 );
1884 }
1885
1886 /*!
1887   \brief Destructor.
1888 */
1889 QtxPagePrefSpaceItem::~QtxPagePrefSpaceItem()
1890 {
1891 }
1892
1893 /*!
1894   \brief Get spacer item size for the specified direction.
1895   \param o direction
1896   \return size for the specified direction
1897   \sa setSize()
1898 */
1899 int QtxPagePrefSpaceItem::size( Qt::Orientation o ) const
1900 {
1901   return o == Qt::Horizontal ? widget()->minimumWidth() : widget()->minimumHeight();
1902 }
1903
1904 /*!
1905   \brief Set spacer item size for the specified direction.
1906   \param o direction
1907   \param sz new size for the specified direction
1908   \sa size()
1909 */
1910 void QtxPagePrefSpaceItem::setSize( Qt::Orientation o, const int sz )
1911 {
1912   if ( o == Qt::Horizontal )
1913     widget()->setMinimumWidth( sz );
1914   else
1915     widget()->setMinimumHeight( sz );
1916 }
1917
1918 /*!
1919   \brief Get spacer item stretch factor for the specified direction.
1920   \param o direction
1921   \return stretch factor for the specified direction
1922   \sa setStretch()
1923 */
1924 int QtxPagePrefSpaceItem::stretch( Qt::Orientation o ) const
1925 {
1926   QSizePolicy sp = widget()->sizePolicy();
1927   return o == Qt::Horizontal ? sp.horizontalStretch() : sp.verticalStretch();
1928 }
1929
1930 /*!
1931   \brief Set spacer item stretch factor for the specified direction.
1932   \param o direction
1933   \param sf new stretch factor for the specified direction
1934   \sa stretch()
1935 */
1936 void QtxPagePrefSpaceItem::setStretch( Qt::Orientation o, const int sf )
1937 {
1938   QSizePolicy sp = widget()->sizePolicy();
1939   if ( o == Qt::Horizontal )
1940   {
1941     sp.setHorizontalStretch( sf );
1942     sp.setHorizontalPolicy( sf > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed );
1943   }
1944   else
1945   {
1946     sp.setVerticalStretch( sf );
1947     sp.setVerticalPolicy( sf > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed );
1948   }
1949
1950   widget()->setSizePolicy( sp );
1951 }
1952
1953 /*!
1954   \brief Get preference item option value.
1955   \param name option name
1956   \return property value or null QVariant if option is not set
1957   \sa setOptionValue()
1958 */
1959 QVariant QtxPagePrefSpaceItem::optionValue( const QString& name ) const
1960 {
1961   if ( name == "horizontal_size" || name == "hsize" )
1962     return size( Qt::Horizontal );
1963   else if ( name == "vertical_size" || name == "vsize" )
1964     return size( Qt::Vertical );
1965   else if ( name == "horizontal_stretch" || name == "hstretch" )
1966     return stretch( Qt::Horizontal );
1967   else if ( name == "vertical_stretch" || name == "vstretch" )
1968     return stretch( Qt::Vertical );
1969   else
1970     return QtxPagePrefItem::optionValue( name );
1971 }
1972
1973 /*!
1974   \brief Set preference item option value.
1975   \param name option name
1976   \param val new property value
1977   \sa optionValue()
1978 */
1979 void QtxPagePrefSpaceItem::setOptionValue( const QString& name, const QVariant& val )
1980 {
1981   if ( name == "horizontal_size" || name == "hsize" )
1982   {
1983     if ( val.canConvert( QVariant::Int ) )
1984       setSize( Qt::Horizontal, val.toInt() );
1985   }
1986   else if ( name == "vertical_size" || name == "vsize" )
1987   {
1988     if ( val.canConvert( QVariant::Int ) )
1989       setSize( Qt::Vertical, val.toInt() );
1990   }
1991   else if ( name == "horizontal_stretch" || name == "hstretch" )
1992   {
1993     if ( val.canConvert( QVariant::Int ) )
1994       setStretch( Qt::Horizontal, val.toInt() );
1995   }
1996   else if ( name == "vertical_stretch" || name == "vstretch" )
1997   {
1998     if ( val.canConvert( QVariant::Int ) )
1999       setStretch( Qt::Vertical, val.toInt() );
2000   }
2001   else
2002     QtxPagePrefItem::setOptionValue( name, val );
2003 }
2004
2005 /*!
2006   \brief Perform internal initialization.
2007   \param w spacer item width
2008   \param h spacer item height
2009   \param ws spacer item horizontal stretch factor
2010   \param hs spacer item vertical stretch factor
2011 */
2012 void QtxPagePrefSpaceItem::initialize( const int w, const int h, const int hs, const int vs )
2013 {
2014   QSizePolicy sp;
2015   sp.setHorizontalPolicy( hs > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed );
2016   sp.setVerticalPolicy( vs > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed );
2017
2018   sp.setHorizontalStretch( hs );
2019   sp.setVerticalStretch( vs );
2020
2021   QWidget* wid = new QWidget();
2022   wid->setSizePolicy( sp );
2023
2024   wid->setMinimumSize( w, h );
2025
2026   setWidget( wid );
2027 }
2028
2029 /*!
2030   \class  QtxPagePrefCheckItem
2031   \brief GUI implementation of the resources check box item (boolean).
2032 */
2033
2034 /*!
2035   \brief Constructor.
2036   \param title preference item title
2037   \param parent parent preference item
2038   \param sect resource file section associated with the preference item
2039   \param param resource file parameter associated with the preference item
2040 */
2041 QtxPagePrefCheckItem::QtxPagePrefCheckItem( const QString& title, QtxPreferenceItem* parent,
2042                                             const QString& sect, const QString& param )
2043
2044 : QtxPagePrefItem( title, parent, sect, param )
2045 {
2046   myCheck = new QCheckBox( title );
2047   myCheck->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
2048   setWidget( myCheck );
2049 }
2050
2051 /*!
2052   \brief Destructor.
2053 */
2054 QtxPagePrefCheckItem::~QtxPagePrefCheckItem()
2055 {
2056 }
2057
2058 /*!
2059   \brief Set preference item title.
2060   \param txt new preference title.
2061 */
2062 void QtxPagePrefCheckItem::setTitle( const QString& txt )
2063 {
2064   QtxPagePrefItem::setTitle( txt );
2065
2066   myCheck->setText( title() );
2067 }
2068
2069 /*!
2070   \brief Store preference item to the resource manager.
2071   \sa retrieve()
2072 */
2073 void QtxPagePrefCheckItem::store()
2074 {
2075   setBoolean( myCheck->isChecked() );
2076 }
2077
2078 /*!
2079   \brief Retrieve preference item from the resource manager.
2080   \sa store()
2081 */
2082 void QtxPagePrefCheckItem::retrieve()
2083 {
2084   myCheck->setChecked( getBoolean() );
2085 }
2086
2087 /*!
2088   \class QtxPagePrefEditItem
2089   \brief GUI implementation of the resources line edit box item
2090   for string, integer and double values.
2091 */
2092
2093 static void fixupAndSet( QLineEdit* le, const QString& txt )
2094 {
2095   if ( le ) {
2096     QString val = txt;
2097     if ( le->validator() ) {
2098       const QDoubleValidator* de = dynamic_cast<const QDoubleValidator*>( le->validator() );
2099       if ( de ) {
2100         int dec = de->decimals();
2101         int idx = val.lastIndexOf( QRegExp( QString("[.|%1]").arg( le->locale().decimalPoint () ) ) );
2102         if ( idx >= 0 ) {
2103           QString tmp = val.mid( idx+1 );
2104           QString exp;
2105           val = val.left( idx+1 );
2106           idx = tmp.indexOf( QRegExp( QString("[e|E]") ) );
2107           if ( idx >= 0 ) {
2108             exp = tmp.mid( idx );
2109             tmp = tmp.left( idx );
2110           }
2111           tmp.truncate( dec );
2112           val = val + tmp + exp;
2113         }
2114       }
2115       int pos = 0;
2116       if ( le->validator()->validate( val, pos ) == QValidator::Invalid )
2117         val.clear();
2118     }
2119     le->setText( val );
2120   }
2121 }
2122
2123 /*!
2124   \brief Constructor.
2125
2126   Creates preference item for string value editing.
2127
2128   \param title preference item title
2129   \param parent parent preference item
2130   \param sect resource file section associated with the preference item
2131   \param param resource file parameter associated with the preference item
2132 */
2133 QtxPagePrefEditItem::QtxPagePrefEditItem( const QString& title, QtxPreferenceItem* parent,
2134                                           const QString& sect, const QString& param )
2135 : QtxPageNamedPrefItem( title, parent, sect, param ),
2136   myType( String ),
2137   myDecimals( 1000 ),
2138   myEchoMode( 0 )
2139 {
2140   setControl( myEditor = new QLineEdit() );
2141   updateEditor();
2142 }
2143
2144 /*!
2145   \brief Constructor.
2146
2147   Creates preference item for editing of the value which type
2148   is specified by parameter \a type.
2149
2150   \param type preference item input type (QtxPagePrefEditItem::InputType)
2151   \param title preference item title
2152   \param parent parent preference item
2153   \param sect resource file section associated with the preference item
2154   \param param resource file parameter associated with the preference item
2155 */
2156 QtxPagePrefEditItem::QtxPagePrefEditItem( const int type, const QString& title,
2157                                           QtxPreferenceItem* parent, const QString& sect,
2158                                           const QString& param )
2159 : QtxPageNamedPrefItem( title, parent, sect, param ),
2160   myType( type ),
2161   myDecimals( 1000 ),
2162   myEchoMode( 0 )
2163 {
2164   setControl( myEditor = new QLineEdit() );
2165   updateEditor();
2166 }
2167
2168 /*!
2169   \brief Destructor.
2170 */
2171 QtxPagePrefEditItem::~QtxPagePrefEditItem()
2172 {
2173 }
2174
2175 /*!
2176   \brief Get edit box preference item input type.
2177   \return preference item input type (QtxPagePrefEditItem::InputType)
2178   \sa setInputType()
2179 */
2180 int QtxPagePrefEditItem::inputType() const
2181 {
2182   return myType;
2183 }
2184
2185 /*!
2186   \brief Set edit box preference item input type.
2187   \param type new preference item input type (QtxPagePrefEditItem::InputType)
2188   \sa inputType()
2189 */
2190 void QtxPagePrefEditItem::setInputType( const int type )
2191 {
2192   if ( myType == type )
2193     return;
2194
2195   myType = type;
2196   updateEditor();
2197 }
2198
2199 /*!
2200   \brief Get number of digits after decimal point (for Double input type)
2201   \return preference item decimals value
2202   \sa setDecimals()
2203 */
2204 int QtxPagePrefEditItem::decimals() const
2205 {
2206   return myDecimals;
2207 }
2208
2209 /*!
2210   \brief Set number of digits after decimal point (for Double input type)
2211   \param dec new preference item decimals value
2212   \sa decimals()
2213 */
2214 void QtxPagePrefEditItem::setDecimals( const int dec )
2215 {
2216   if ( myDecimals == dec )
2217     return;
2218
2219   myDecimals = dec;
2220   updateEditor();
2221 }
2222
2223 /*!
2224   \brief Get the line edit's echo mode
2225   \return preference item echo mode value
2226   \sa setEchoMode()
2227 */
2228 int QtxPagePrefEditItem::echoMode() const
2229 {
2230   return myEchoMode;
2231 }
2232
2233 /*!
2234   \brief Set the line edit's echo mode
2235   \param echo new preference item echo mode value
2236   \sa echoMode()
2237 */
2238 void QtxPagePrefEditItem::setEchoMode( const int echo )
2239 {
2240   if ( myEchoMode == echo )
2241     return;
2242
2243   myEchoMode = echo;
2244   updateEditor();
2245 }
2246
2247 /*!
2248   \brief Store preference item to the resource manager.
2249   \sa retrieve()
2250 */
2251 void QtxPagePrefEditItem::store()
2252 {
2253   setString( myEditor->text() );
2254 }
2255
2256 /*!
2257   \brief Retrieve preference item from the resource manager.
2258   \sa store()
2259 */
2260 void QtxPagePrefEditItem::retrieve()
2261 {
2262   QString txt = getString();
2263   fixupAndSet( myEditor, txt );
2264 }
2265
2266 /*!
2267   \brief Get preference item option value.
2268   \param name option name
2269   \return property value or null QVariant if option is not set
2270   \sa setOptionValue()
2271 */
2272 QVariant QtxPagePrefEditItem::optionValue( const QString& name ) const
2273 {
2274   if ( name == "input_type" || name == "type" )
2275     return inputType();
2276   else if ( name == "precision" || name == "prec" || name == "decimals" )
2277     return decimals();
2278   else if ( name == "echo" || name == "echo_mode" || name == "echomode")
2279     return echoMode();
2280   else
2281     return QtxPageNamedPrefItem::optionValue( name );
2282 }
2283
2284 /*!
2285   \brief Set preference item option value.
2286   \param name option name
2287   \param val new property value
2288   \sa optionValue()
2289 */
2290 void QtxPagePrefEditItem::setOptionValue( const QString& name, const QVariant& val )
2291 {
2292   if ( name == "input_type" || name == "type" )
2293   {
2294     if ( val.canConvert( QVariant::Int ) )
2295       setInputType( val.toInt() );
2296   }
2297   else if ( name == "precision" || name == "prec" || name == "decimals" ) {
2298     if ( val.canConvert( QVariant::Int ) )
2299       setDecimals( val.toInt() );
2300   }
2301   else if ( name == "echo" || name == "echo_mode" || name == "echomode") {
2302     if ( val.canConvert( QVariant::Int ) )
2303       setEchoMode( val.toInt() );
2304   }
2305   else
2306     QtxPageNamedPrefItem::setOptionValue( name, val );
2307 }
2308
2309 /*!
2310   \brief Update edit box widget.
2311 */
2312 void QtxPagePrefEditItem::updateEditor()
2313 {
2314   switch (myEchoMode)
2315   {
2316     case 0:
2317       myEditor->setEchoMode(QLineEdit::Normal);
2318       break;
2319     case 1:
2320       myEditor->setEchoMode(QLineEdit::NoEcho);
2321       break;
2322     case 2:
2323       myEditor->setEchoMode(QLineEdit::Password);
2324       break;
2325     case 3:
2326       myEditor->setEchoMode(QLineEdit::PasswordEchoOnEdit);
2327       break;
2328     default:
2329       myEditor->setEchoMode(QLineEdit::Normal);
2330   }
2331
2332   QValidator* val = 0;
2333   switch ( inputType() )
2334   {
2335   case Integer:
2336     val = new QIntValidator( myEditor );
2337     break;
2338   case Double:
2339     val = new QDoubleValidator( myEditor );
2340     dynamic_cast<QDoubleValidator*>( val )->setDecimals( myDecimals < 0 ? 1000 : myDecimals );
2341     break;
2342   default:
2343     break;
2344   }
2345
2346   QString txt = myEditor->text();
2347   delete myEditor->validator();
2348   myEditor->setValidator( val );
2349   fixupAndSet( myEditor, txt );
2350 }
2351
2352 /*!
2353   \class QtxPagePrefSliderItem
2354 */
2355
2356 /*!
2357   \brief Constructor.
2358
2359   Creates preference item with slider widget
2360
2361   \param title preference item title
2362   \param parent parent preference item
2363   \param sect resource file section associated with the preference item
2364   \param param resource file parameter associated with the preference item
2365 */
2366 QtxPagePrefSliderItem::QtxPagePrefSliderItem( const QString& title, QtxPreferenceItem* parent,
2367                                               const QString& sect, const QString& param )
2368 : QtxPageNamedPrefItem( title, parent, sect, param )
2369 {
2370   setControl( mySlider = new QSlider( Qt::Horizontal ) );
2371   widget()->layout()->addWidget( myLabel = new QLabel( ) );
2372
2373   setMinimum( 0 );
2374   setMaximum( 0 );
2375   setSingleStep( 1 );
2376   setPageStep( 1 );
2377
2378   mySlider->setTickPosition( QSlider::TicksBothSides );
2379
2380   connect (mySlider, SIGNAL(valueChanged(int)), this, SLOT(setIcon(int)));
2381   updateSlider();
2382 }
2383
2384 /*!
2385   \brief Destructor.
2386 */
2387 QtxPagePrefSliderItem::~QtxPagePrefSliderItem()
2388 {
2389 }
2390
2391 /*!
2392   \brief Get slider preference item step value.
2393   \return slider single step value
2394   \sa setSingleStep()
2395 */
2396 int QtxPagePrefSliderItem::singleStep() const
2397 {
2398   return mySlider->singleStep();
2399 }
2400
2401 /*!
2402   \brief Get slider preference item step value.
2403   \return slider page step value
2404   \sa setPageStep()
2405 */
2406 int QtxPagePrefSliderItem::pageStep() const
2407 {
2408   return mySlider->pageStep();
2409 }
2410
2411 /*!
2412   \brief Get slider preference item minimum value.
2413   \return slider minimum value
2414   \sa setMinimum()
2415 */
2416 int QtxPagePrefSliderItem::minimum() const
2417 {
2418     return mySlider->minimum();
2419 }
2420
2421 /*!
2422   \brief Get slider preference item maximum value.
2423   \return slider maximum value
2424   \sa setMaximum()
2425 */
2426 int QtxPagePrefSliderItem::maximum() const
2427 {
2428     return mySlider->maximum();
2429 }
2430
2431 /*!
2432   \brief Get the list of the icons associated with the selection widget items
2433   \return list of icons
2434   \sa setIcons()
2435 */
2436 QList<QIcon> QtxPagePrefSliderItem::icons() const
2437 {
2438   return myIcons;
2439 }
2440
2441 /*!
2442   \brief Set slider preference item step value.
2443   \param step new slider single step value
2444   \sa step()
2445 */
2446 void QtxPagePrefSliderItem::setSingleStep( const int& step )
2447 {
2448   mySlider->setSingleStep( step );
2449 }
2450
2451 /*!
2452   \brief Set slider preference item step value.
2453   \param step new slider single step value
2454   \sa step()
2455 */
2456 void QtxPagePrefSliderItem::setPageStep( const int& step )
2457 {
2458   mySlider->setPageStep( step );
2459 }
2460
2461 /*!
2462   \brief Set slider preference item minimum value.
2463   \param min new slider minimum value
2464   \sa minimum()
2465 */
2466 void QtxPagePrefSliderItem::setMinimum( const int& min )
2467 {
2468   mySlider->setMinimum( min );
2469   setIcon( mySlider->value() );
2470 }
2471
2472 /*!
2473   \brief Set slider preference item maximum value.
2474   \param max new slider maximum value
2475   \sa maximum()
2476 */
2477 void QtxPagePrefSliderItem::setMaximum( const int& max )
2478 {
2479   mySlider->setMaximum( max );
2480   setIcon( mySlider->value() );
2481 }
2482
2483 /*!
2484   \brief Set the list of the icons to the selection widget items
2485   \param icns new list of icons
2486   \sa icons()
2487 */
2488 void QtxPagePrefSliderItem::setIcons( const QList<QIcon>& icns )
2489 {
2490   if ( icns.isEmpty() )
2491     return;
2492   myIcons = icns;
2493
2494   QSize maxsize(0, 0);
2495   for ( QList<QIcon>::const_iterator it = myIcons.begin(); it != myIcons.end(); ++it ) {
2496     if ( (*it).isNull() ) continue;
2497     maxsize = maxsize.expandedTo( (*it).availableSizes().first() );
2498   }
2499   myLabel->setFixedSize( maxsize );
2500
2501   updateSlider();
2502 }
2503
2504 /*!
2505   \brief Store preference item to the resource manager.
2506   \sa retrieve()
2507 */
2508 void QtxPagePrefSliderItem::store()
2509 {
2510   setInteger( mySlider->value() );
2511 }
2512
2513 /*!
2514   \brief Retrieve preference item from the resource manager.
2515   \sa store()
2516 */
2517 void QtxPagePrefSliderItem::retrieve()
2518 {
2519   mySlider->setValue( getInteger( mySlider->value() ) );
2520 }
2521
2522 /*!
2523   \brief Get preference item option value.
2524   \param name option name
2525   \return property value or null integer if option is not set
2526   \sa setOptionValue()
2527 */
2528 QVariant QtxPagePrefSliderItem::optionValue( const QString& name ) const
2529 {
2530   if ( name == "minimum" || name == "min" )
2531     return minimum();
2532   else if ( name == "maximum" || name == "max" )
2533     return maximum();
2534   else if ( name == "single_step" )
2535     return singleStep();
2536   else if ( name == "page_step" )
2537     return pageStep();
2538   else if ( name == "icons" || name == "pixmaps" )
2539   {
2540     QList<QVariant> lst;
2541     QList<QIcon> ics = icons();
2542     for ( QList<QIcon>::const_iterator it = ics.begin(); it != ics.end(); ++it )
2543       lst.append( *it );
2544     return lst;
2545   }
2546   else
2547     return QtxPageNamedPrefItem::optionValue( name );
2548 }
2549
2550 /*!
2551   \brief Set preference item option value.
2552   \param name option name
2553   \param val new property value
2554   \sa optionValue()
2555 */
2556 void QtxPagePrefSliderItem::setOptionValue( const QString& name, const QVariant& val )
2557 {
2558   if ( val.canConvert( QVariant::Int ) )
2559   {
2560     if ( name == "minimum" || name == "min" )
2561       setMinimum( val.toInt() );
2562     else if ( name == "maximum" || name == "max" )
2563       setMaximum( val.toInt() );
2564     else if ( name == "single_step" )
2565       setSingleStep( val.toInt() );
2566     else if ( name == "page_step" )
2567       setPageStep( val.toInt() );
2568     else
2569       QtxPageNamedPrefItem::setOptionValue( name, val );
2570   }
2571   else if ( name == "icons" || name == "pixmaps" )
2572     setIcons( val );
2573   else
2574     QtxPageNamedPrefItem::setOptionValue( name, val );
2575 }
2576
2577 void QtxPagePrefSliderItem::setIcon( int pos )
2578 {
2579   int index = pos - mySlider->minimum();
2580   if ( !myIcons.isEmpty() && index >= 0 && index < myIcons.size() && !myIcons[index].isNull() )
2581     myLabel->setPixmap( myIcons[index].pixmap( myIcons[index].availableSizes().first() ) );
2582   else
2583     myLabel->clear();
2584 }
2585
2586 /*!
2587   \brief Update slider widget.
2588 */
2589 void QtxPagePrefSliderItem::updateSlider()
2590 {
2591   int val = mySlider->value();
2592   int stp = singleStep();
2593   int ptp = pageStep();
2594   int min = minimum();
2595   int max = maximum();
2596
2597   control()->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
2598   mySlider->setFocusPolicy(Qt::StrongFocus);
2599
2600   mySlider->setValue( val );
2601   setSingleStep( stp );
2602   setPageStep( ptp );
2603   setMinimum( min );
2604   setMaximum( max );
2605
2606   myLabel->setVisible( !myIcons.empty() );
2607   widget()->layout()->setSpacing( !myIcons.empty() ? 6 : 0 );
2608 }
2609
2610 /*!
2611   \brief Set the list of the icons from the resource manager.
2612   \param var new icons list
2613   \internal
2614 */
2615 void  QtxPagePrefSliderItem::setIcons( const QVariant& var )
2616 {
2617   if ( var.type() != QVariant::List )
2618     return;
2619
2620   QList<QIcon> lst;
2621   QList<QVariant> varList = var.toList();
2622   for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it )
2623   {
2624     if ( (*it).canConvert<QIcon>() )
2625       lst.append( (*it).value<QIcon>() );
2626     else if ( (*it).canConvert<QPixmap>() )
2627       lst.append( (*it).value<QPixmap>() );
2628     else
2629       lst.append( QIcon() );
2630   }
2631   setIcons( lst );
2632 }
2633
2634 /*!
2635   \class QtxPagePrefSelectItem
2636   \brief GUI implementation of the resources selector item
2637   (string, integer or double values list).
2638
2639   All items in the list (represented as combo box) should be specified
2640   by the unique identifier which is stored to the resource file instead
2641   of the value itself.
2642 */
2643
2644 /*!
2645   \brief Constructor.
2646
2647   Creates preference item with combo box widget which is not editable
2648   (direct value entering is disabled).
2649
2650   \param title preference item title
2651   \param parent parent preference item
2652   \param sect resource file section associated with the preference item
2653   \param param resource file parameter associated with the preference item
2654 */
2655 QtxPagePrefSelectItem::QtxPagePrefSelectItem( const QString& title, QtxPreferenceItem* parent,
2656                                               const QString& sect, const QString& param )
2657 : QtxPageNamedPrefItem( title, parent, sect, param ),
2658   myType( NoInput )
2659 {
2660   setControl( mySelector = new QtxComboBox() );
2661   mySelector->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
2662   mySelector->setDuplicatesEnabled( false );
2663   updateSelector();
2664 }
2665
2666 /*!
2667   \brief Constructor.
2668
2669   Creates preference item with combo box widget which is editable
2670   according to the specified input type (integer, double or string values).
2671
2672   \param type input type (QtxPagePrefSelectItem::InputType)
2673   \param title preference item title
2674   \param parent parent preference item
2675   \param sect resource file section associated with the preference item
2676   \param param resource file parameter associated with the preference item
2677 */
2678 QtxPagePrefSelectItem::QtxPagePrefSelectItem( const int type, const QString& title, QtxPreferenceItem* parent,
2679                                               const QString& sect, const QString& param )
2680 : QtxPageNamedPrefItem( title, parent, sect, param ),
2681   myType( type )
2682 {
2683   setControl( mySelector = new QtxComboBox() );
2684   mySelector->setDuplicatesEnabled( false );
2685   updateSelector();
2686 }
2687
2688 /*!
2689   \brief Destructor.
2690 */
2691 QtxPagePrefSelectItem::~QtxPagePrefSelectItem()
2692 {
2693 }
2694
2695 /*!
2696   \brief Get edit box preference item input type.
2697   \return preference item input type (QtxPagePrefSelectItem::InputType)
2698   \sa setInputType()
2699 */
2700 int QtxPagePrefSelectItem::inputType() const
2701 {
2702   return myType;
2703 }
2704
2705 /*!
2706   \brief Set edit box preference item input type.
2707   \param type new preference item input type (QtxPagePrefSelectItem::InputType)
2708   \sa inputType()
2709 */
2710 void QtxPagePrefSelectItem::setInputType( const int type )
2711 {
2712   if ( myType == type )
2713     return;
2714
2715   myType = type;
2716   updateSelector();
2717 }
2718
2719 /*!
2720   \brief Get the list of the values from the selection widget.
2721   \return list of values
2722   \sa numbers(), icons(), setStrings()
2723 */
2724 QStringList QtxPagePrefSelectItem::strings() const
2725 {
2726   QStringList res;
2727   for ( int i = 0; i < mySelector->count(); i++ )
2728     res.append( mySelector->itemText( i ) );
2729   return res;
2730 }
2731
2732 /*!
2733   \brief Get the list of the values identifiers from the selection widget.
2734   \return list of values IDs
2735   \sa strings(), icons(), setNumbers()
2736 */
2737 QList<QVariant> QtxPagePrefSelectItem::numbers() const
2738 {
2739   QList<QVariant> res;
2740   for ( int i = 0; i < mySelector->count(); i++ )
2741   {
2742     if ( mySelector->hasId( i ) )
2743       res.append( mySelector->id( i ) );
2744   }
2745   return res;
2746 }
2747
2748 /*!
2749   \brief Get the list of the icons associated with the selection widget.items
2750   \return list of icons
2751   \sa strings(), numbers(), setIcons()
2752 */
2753 QList<QIcon> QtxPagePrefSelectItem::icons() const
2754 {
2755   QList<QIcon> res;
2756   for ( int i = 0; i < mySelector->count(); i++ )
2757     res.append( mySelector->itemIcon( i ) );
2758   return res;
2759 }
2760
2761 /*!
2762   \brief Set the list of the values to the selection widget.
2763   \param lst new list of values
2764   \sa strings(), setNumbers(), setIcons()
2765 */
2766 void QtxPagePrefSelectItem::setStrings( const QStringList& lst )
2767 {
2768   mySelector->clear();
2769   mySelector->addItems( lst );
2770 }
2771
2772 /*!
2773   \brief Set the list of the values identifiers to the selection widget
2774   \param ids new list of values IDs
2775   \sa numbers(), setStrings(), setIcons()
2776 */
2777 void QtxPagePrefSelectItem::setNumbers( const QList<QVariant>& ids )
2778 {
2779   int i = 0;
2780   for ( QList<QVariant>::const_iterator it = ids.begin(); it != ids.end(); ++it, i++ ) {
2781     if ( i >= mySelector->count() )
2782       mySelector->addItem(QString("") );
2783
2784     mySelector->setId( i, *it );
2785   }
2786 }
2787
2788 /*!
2789   \brief Set the list of the icons to the selection widget items
2790
2791   Important: call this method after setStrings() or setNumbers()
2792
2793   \param icns new list of icons
2794   \sa icons(), setStrings(), setNumbers()
2795 */
2796 void QtxPagePrefSelectItem::setIcons( const QList<QIcon>& icns )
2797 {
2798   int i = 0;
2799   for ( QList<QIcon>::const_iterator it = icns.begin(); it != icns.end() && i < mySelector->count(); ++it, i++ )
2800     mySelector->setItemIcon( i, *it );
2801 }
2802
2803 /*!
2804   \brief Store preference item to the resource manager.
2805   \sa retrieve()
2806 */
2807 void QtxPagePrefSelectItem::store()
2808 {
2809   if ( mySelector->isCleared() )
2810     return;
2811
2812   int idx = mySelector->currentIndex();
2813
2814   if ( mySelector->hasId( idx ) ) {
2815     QVariant id = mySelector->id( idx );
2816     if ( id.type() == QVariant::Int )
2817       setInteger( id.toInt() );
2818     else if ( id.type() == QVariant::String )
2819       setString( id.toString() );
2820   }
2821   else if ( idx >= 0 ) {
2822     setString( mySelector->itemText( idx ) );
2823   }
2824 }
2825
2826 /*!
2827   \brief Retrieve preference item from the resource manager.
2828   \sa store()
2829 */
2830 void QtxPagePrefSelectItem::retrieve()
2831 {
2832   QString txt = getString();
2833
2834   // try to find via the id
2835   int idx = mySelector->index( txt );
2836   if ( idx < 0 )
2837   {
2838     for ( int i = 0; i < mySelector->count() && idx == -1; i++ )
2839     {
2840       if ( mySelector->itemText( i ) == txt )
2841         idx = i;
2842     }
2843   }
2844
2845   if ( idx != -1 )
2846     mySelector->setCurrentIndex( idx );
2847   else if ( mySelector->isEditable() )
2848   {
2849     int pos = 0;
2850     if ( mySelector->validator() &&
2851          mySelector->validator()->validate( txt, pos ) == QValidator::Invalid )
2852       mySelector->setCleared( true );
2853     else
2854     {
2855       mySelector->setCleared( false );
2856       mySelector->addItem( txt );
2857       mySelector->setCurrentIndex( mySelector->count() - 1 );
2858     }
2859   }
2860 }
2861
2862 /*!
2863   \brief Get preference item option value.
2864   \param name option name
2865   \return property value or null QVariant if option is not set
2866   \sa setOptionValue()
2867 */
2868 QVariant QtxPagePrefSelectItem::optionValue( const QString& name ) const
2869 {
2870   if ( name == "input_type" || name == "type" )
2871     return inputType();
2872   else if ( name == "strings" || name == "labels" )
2873     return strings();
2874   else if ( name == "numbers" || name == "ids" || name == "indexes" )
2875   {
2876     return numbers();
2877   }
2878   else if ( name == "icons" || name == "pixmaps" )
2879   {
2880     QList<QVariant> lst;
2881     QList<QIcon> ics = icons();
2882     for ( QList<QIcon>::const_iterator it = ics.begin(); it != ics.end(); ++it )
2883       lst.append( *it );
2884     return lst;
2885   }
2886   else
2887     return QtxPageNamedPrefItem::optionValue( name );
2888 }
2889
2890 /*!
2891   \brief Set preference item option value.
2892   \param name option name
2893   \param val new property value
2894   \sa optionValue()
2895 */
2896 void QtxPagePrefSelectItem::setOptionValue( const QString& name, const QVariant& val )
2897 {
2898   if ( name == "input_type" || name == "type" )
2899   {
2900     if ( val.canConvert( QVariant::Int ) )
2901       setInputType( val.toInt() );
2902   }
2903   else if ( name == "strings" || name == "labels" )
2904     setStrings( val );
2905   else if ( name == "numbers" || name == "ids" || name == "indexes" )
2906     setNumbers( val );
2907   else if ( name == "icons" || name == "pixmaps" )
2908     setIcons( val );
2909   else
2910     QtxPageNamedPrefItem::setOptionValue( name, val );
2911 }
2912
2913 /*!
2914   \brief Set the list of the values from the resource manager.
2915   \param var new values list
2916   \internal
2917 */
2918 void QtxPagePrefSelectItem::setStrings( const QVariant& var )
2919 {
2920   QStringList values;
2921   if ( toStringList( var, values ) )
2922     setStrings( values );
2923 }
2924
2925 /*!
2926   \brief Set the list of the values identifiers from the resource manager.
2927   \param var new values IDs list
2928   \internal
2929 */
2930 void QtxPagePrefSelectItem::setNumbers( const QVariant& var )
2931 {
2932   if ( var.type() != QVariant::List )
2933     return;
2934
2935   setNumbers( var.toList() );
2936 }
2937
2938 /*!
2939   \brief Set the list of the icons from the resource manager.
2940   \param var new icons list
2941   \internal
2942 */
2943 void QtxPagePrefSelectItem::setIcons( const QVariant& var )
2944 {
2945   if ( var.type() != QVariant::List )
2946     return;
2947
2948   QList<QIcon> lst;
2949   QList<QVariant> varList = var.toList();
2950   for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it )
2951   {
2952     if ( (*it).canConvert<QIcon>() )
2953       lst.append( (*it).value<QIcon>() );
2954     else if ( (*it).canConvert<QPixmap>() )
2955       lst.append( (*it).value<QPixmap>() );
2956     else
2957       lst.append( QIcon() );
2958   }
2959   setIcons( lst );
2960 }
2961
2962 /*!
2963   \brief Update selector widget.
2964 */
2965 void QtxPagePrefSelectItem::updateSelector()
2966 {
2967   QValidator* val = 0;
2968   switch ( inputType() )
2969   {
2970   case Integer:
2971     val = new QIntValidator( mySelector );
2972     break;
2973   case Double:
2974     val = new QDoubleValidator( mySelector );
2975     break;
2976   default:
2977     break;
2978   }
2979
2980   mySelector->setEditable( inputType() != NoInput );
2981
2982   if ( mySelector->isEditable() && !mySelector->currentText().isEmpty() && val )
2983   {
2984     int pos = 0;
2985     QString str = mySelector->currentText();
2986     if ( val->validate( str, pos ) == QValidator::Invalid )
2987       mySelector->clearEditText();
2988   }
2989
2990   delete mySelector->validator();
2991   mySelector->setValidator( val );
2992 }
2993
2994 /*!
2995   \class QtxPagePrefSpinItem
2996   \brief GUI implementation of the resources spin box item
2997   (for integer or double value).
2998 */
2999
3000 /*!
3001   \brief Constructor.
3002
3003   Creates spin box preference item for the entering integer values.
3004
3005   \param title preference item title
3006   \param parent parent preference item
3007   \param sect resource file section associated with the preference item
3008   \param param resource file parameter associated with the preference item
3009 */
3010 QtxPagePrefSpinItem::QtxPagePrefSpinItem( const QString& title, QtxPreferenceItem* parent,
3011                                           const QString& sect, const QString& param )
3012 : QtxPageNamedPrefItem( title, parent, sect, param ),
3013   myType( Integer )
3014 {
3015   updateSpinBox();
3016 }
3017
3018 /*!
3019   \brief Constructor.
3020
3021   Creates spin box preference item for the entering values which type
3022   is specified by the parameter \a type.
3023
3024   \param type input type (QtxPagePrefSpinItem::InputType).
3025   \param title preference item title
3026   \param parent parent preference item
3027   \param sect resource file section associated with the preference item
3028   \param param resource file parameter associated with the preference item
3029 */
3030 QtxPagePrefSpinItem::QtxPagePrefSpinItem( const int type, const QString& title,
3031                                           QtxPreferenceItem* parent, const QString& sect,
3032                                           const QString& param )
3033 : QtxPageNamedPrefItem( title, parent, sect, param ),
3034   myType( type )
3035 {
3036   updateSpinBox();
3037 }
3038
3039 /*!
3040   \brief Destructor.
3041 */
3042 QtxPagePrefSpinItem::~QtxPagePrefSpinItem()
3043 {
3044 }
3045
3046 /*!
3047   \brief Get spin box preference item input type.
3048   \return preference item input type (QtxPagePrefSpinItem::InputType)
3049   \sa setInputType()
3050 */
3051 int QtxPagePrefSpinItem::inputType() const
3052 {
3053   return myType;
3054 }
3055
3056 /*!
3057   \brief Set spin box preference item input type.
3058   \param type new preference item input type (QtxPagePrefSpinItem::InputType)
3059   \sa inputType()
3060 */
3061 void QtxPagePrefSpinItem::setInputType( const int type )
3062 {
3063   if ( myType == type )
3064     return;
3065
3066   myType = type;
3067   updateSpinBox();
3068 }
3069
3070 /*!
3071   \brief Get spin box preference item step value.
3072   \return spin box single step value
3073   \sa setStep()
3074 */
3075 QVariant QtxPagePrefSpinItem::step() const
3076 {
3077   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3078     return isb->singleStep();
3079   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3080     return dsb->singleStep();
3081   else
3082     return QVariant();
3083 }
3084
3085 /*!
3086   \brief Get double spin box preference item precision value.
3087   \return double spin box precision
3088   \sa setPrecision()
3089 */
3090 QVariant QtxPagePrefSpinItem::precision() const
3091 {
3092   if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3093     return dsb->decimals();
3094   else
3095     return QVariant();
3096 }
3097
3098 /*!
3099   \brief Get spin box preference item minimum value.
3100   \return spin box minimum value
3101   \sa setMinimum()
3102 */
3103 QVariant QtxPagePrefSpinItem::minimum() const
3104 {
3105   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3106     return isb->minimum();
3107   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3108     return dsb->minimum();
3109   else
3110     return QVariant();
3111 }
3112
3113 /*!
3114   \brief Get spin box preference item maximum value.
3115   \return spin box maximum value
3116   \sa setMaximum()
3117 */
3118 QVariant QtxPagePrefSpinItem::maximum() const
3119 {
3120   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3121     return isb->maximum();
3122   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3123     return dsb->maximum();
3124   else
3125     return QVariant();
3126 }
3127
3128 /*!
3129   \brief Get spin box preference item prefix string.
3130   \return spin box prefix string
3131   \sa setPrefix()
3132 */
3133 QString QtxPagePrefSpinItem::prefix() const
3134 {
3135   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3136     return isb->prefix();
3137   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3138     return dsb->prefix();
3139   else
3140     return QString();
3141 }
3142
3143 /*!
3144   \brief Get spin box preference item suffix string.
3145   \return spin box suffix string
3146   \sa setSuffix()
3147 */
3148 QString QtxPagePrefSpinItem::suffix() const
3149 {
3150   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3151     return isb->suffix();
3152   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3153     return dsb->suffix();
3154   else
3155     return QString();
3156 }
3157
3158 /*!
3159   \brief Get spin box preference item special value text (which is shown
3160   when the spin box reaches minimum value).
3161   \return spin box special value text
3162   \sa setSpecialValueText()
3163 */
3164 QString QtxPagePrefSpinItem::specialValueText() const
3165 {
3166   QAbstractSpinBox* sb = ::qobject_cast<QAbstractSpinBox*>( control() );
3167   if ( sb )
3168     return sb->specialValueText();
3169   else
3170     return QString();
3171 }
3172
3173 /*!
3174   \brief Set spin box preference item step value.
3175   \param step new spin box single step value
3176   \sa step()
3177 */
3178 void QtxPagePrefSpinItem::setStep( const QVariant& step )
3179 {
3180   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3181   {
3182     if ( step.canConvert( QVariant::Int ) )
3183       isb->setSingleStep( step.toInt() );
3184   }
3185   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3186   {
3187     if ( step.canConvert( QVariant::Double ) )
3188       dsb->setSingleStep( step.toDouble() );
3189   }
3190 }
3191
3192 /*!
3193   \brief Set double spin box preference item precision value.
3194   \param step new double spin box precision value
3195   \sa precision()
3196 */
3197 void QtxPagePrefSpinItem::setPrecision( const QVariant& prec )
3198 {
3199   if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3200   {
3201     if ( prec.canConvert( QVariant::Int ) ) {
3202       dsb->setDecimals( qAbs( prec.toInt() ) );
3203       dsb->setPrecision( prec.toInt() );
3204     }
3205   }
3206 }
3207
3208 /*!
3209   \brief Set spin box preference item minimum value.
3210   \param min new spin box minimum value
3211   \sa minimum()
3212 */
3213 void QtxPagePrefSpinItem::setMinimum( const QVariant& min )
3214 {
3215   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3216   {
3217     if ( min.canConvert( QVariant::Int ) )
3218       isb->setMinimum( min.toInt() );
3219   }
3220   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3221   {
3222     if ( min.canConvert( QVariant::Double ) )
3223       dsb->setMinimum( min.toDouble() );
3224   }
3225 }
3226
3227 /*!
3228   \brief Set spin box preference item maximum value.
3229   \param min new spin box maximum value
3230   \sa maximum()
3231 */
3232 void QtxPagePrefSpinItem::setMaximum( const QVariant& max )
3233 {
3234   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3235   {
3236     if ( max.canConvert( QVariant::Int ) )
3237       isb->setMaximum( max.toInt() );
3238   }
3239   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3240   {
3241     if ( max.canConvert( QVariant::Double ) )
3242       dsb->setMaximum( max.toDouble() );
3243   }
3244 }
3245
3246 /*!
3247   \brief Set spin box preference item prefix string.
3248   \param txt new spin box prefix string
3249   \sa prefix()
3250 */
3251 void QtxPagePrefSpinItem::setPrefix( const QString& txt )
3252 {
3253   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3254     isb->setPrefix( txt );
3255   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3256     dsb->setPrefix( txt );
3257 }
3258
3259 /*!
3260   \brief Set spin box preference item suffix string.
3261   \param txt new spin box suffix string
3262   \sa suffix()
3263 */
3264 void QtxPagePrefSpinItem::setSuffix( const QString& txt )
3265 {
3266   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3267     isb->setSuffix( txt );
3268   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3269     dsb->setSuffix( txt );
3270 }
3271
3272 /*!
3273   \brief Set spin box preference item special value text (which is shown
3274   when the spin box reaches minimum value).
3275   \param txt new spin box special value text
3276   \sa specialValueText()
3277 */
3278 void QtxPagePrefSpinItem::setSpecialValueText( const QString& txt )
3279 {
3280   QAbstractSpinBox* sb = ::qobject_cast<QAbstractSpinBox*>( control() );
3281   if ( sb )
3282     sb->setSpecialValueText( txt );
3283 }
3284
3285 /*!
3286   \brief Store preference item to the resource manager.
3287   \sa retrieve()
3288 */
3289 void QtxPagePrefSpinItem::store()
3290 {
3291   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3292     setInteger( isb->value() );
3293   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3294     setDouble( dsb->value() );
3295 }
3296
3297 /*!
3298   \brief Retrieve preference item from the resource manager.
3299   \sa store()
3300 */
3301 void QtxPagePrefSpinItem::retrieve()
3302 {
3303   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3304     isb->setValue( getInteger( isb->value() ) );
3305   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3306     dsb->setValue( getDouble( dsb->value() ) );
3307 }
3308
3309 /*!
3310   \brief Get preference item option value.
3311   \param name option name
3312   \return property value or null QVariant if option is not set
3313   \sa setOptionValue()
3314 */
3315 QVariant QtxPagePrefSpinItem::optionValue( const QString& name ) const
3316 {
3317   if ( name == "input_type" || name == "type" )
3318     return inputType();
3319   else if ( name == "minimum" || name == "min" )
3320     return minimum();
3321   else if ( name == "maximum" || name == "max" )
3322     return maximum();
3323   else if ( name == "step" )
3324     return step();
3325   else if ( name == "precision" )
3326     return precision();
3327   else if ( name == "prefix" )
3328     return prefix();
3329   else if ( name == "suffix" )
3330     return suffix();
3331   else if ( name == "special" )
3332     return specialValueText();
3333   else
3334     return QtxPageNamedPrefItem::optionValue( name );
3335 }
3336
3337 /*!
3338   \brief Set preference item option value.
3339   \param name option name
3340   \param val new property value
3341   \sa optionValue()
3342 */
3343 void QtxPagePrefSpinItem::setOptionValue( const QString& name, const QVariant& val )
3344 {
3345   if ( name == "input_type" || name == "type" )
3346   {
3347     if ( val.canConvert( QVariant::Int ) )
3348       setInputType( val.toInt() );
3349   }
3350   else if ( name == "minimum" || name == "min" )
3351     setMinimum( val );
3352   else if ( name == "maximum" || name == "max" )
3353     setMaximum( val );
3354   else if ( name == "step" )
3355     setStep( val );
3356   else if ( name == "precision" )
3357     setPrecision( val );
3358   else if ( name == "prefix" )
3359   {
3360     if ( val.canConvert( QVariant::String ) )
3361       setPrefix( val.toString() );
3362   }
3363   else if ( name == "suffix" )
3364   {
3365     if ( val.canConvert( QVariant::String ) )
3366       setSuffix( val.toString() );
3367   }
3368   else if ( name == "special" )
3369   {
3370     if ( val.canConvert( QVariant::String ) )
3371       setSpecialValueText( val.toString() );
3372   }
3373   else
3374     QtxPageNamedPrefItem::setOptionValue( name, val );
3375 }
3376
3377 /*!
3378   \brief Update spin box widget.
3379 */
3380 void QtxPagePrefSpinItem::updateSpinBox()
3381 {
3382   QVariant val;
3383   QVariant stp = step();
3384   QVariant prec = precision();
3385   QVariant min = minimum();
3386   QVariant max = maximum();
3387
3388   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3389     val = isb->value();
3390   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3391     val = dsb->value();
3392
3393   switch ( inputType() )
3394   {
3395   case Integer:
3396     setControl( new QtxIntSpinBox() );
3397     break;
3398   case Double:
3399     setControl( new QtxDoubleSpinBox() );
3400     break;
3401   default:
3402     break;
3403   }
3404
3405   control()->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
3406
3407   setStep( stp );
3408   setPrecision( prec );
3409   setMinimum( min );
3410   setMaximum( max );
3411
3412   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3413   {
3414     if ( val.canConvert( QVariant::Int ) )
3415       isb->setValue( val.toInt() );
3416   }
3417   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3418   {
3419     if ( val.canConvert( QVariant::Double ) )
3420       dsb->setValue( val.toDouble() );
3421   }
3422 }
3423
3424 /*!
3425   \class  QtxPagePrefTextItem
3426   \brief GUI implementation of the resources text box edit item
3427   (for large text data).
3428 */
3429
3430 /*!
3431   \brief Constructor.
3432   \param parent parent preference item
3433   \param sect resource file section associated with the preference item
3434   \param param resource file parameter associated with the preference item
3435 */
3436 QtxPagePrefTextItem::QtxPagePrefTextItem( QtxPreferenceItem* parent, const QString& sect,
3437                                           const QString& param )
3438 : QtxPageNamedPrefItem( QString(), parent, sect, param )
3439 {
3440   myEditor = new QTextEdit();
3441   myEditor->setAcceptRichText( false );
3442
3443   setControl( myEditor );
3444 }
3445
3446 /*!
3447   \brief Constructor.
3448   \param title preference item title
3449   \param parent parent preference item
3450   \param sect resource file section associated with the preference item
3451   \param param resource file parameter associated with the preference item
3452 */
3453 QtxPagePrefTextItem::QtxPagePrefTextItem( const QString& title, QtxPreferenceItem* parent,
3454                                           const QString& sect, const QString& param )
3455 : QtxPageNamedPrefItem( title, parent, sect, param )
3456 {
3457   myEditor = new QTextEdit();
3458   myEditor->setAcceptRichText( false );
3459
3460   setControl( myEditor );
3461 }
3462
3463 /*!
3464   \brief Destructor.
3465 */
3466 QtxPagePrefTextItem::~QtxPagePrefTextItem()
3467 {
3468 }
3469
3470 /*!
3471   \brief Store preference item to the resource manager.
3472   \sa retrieve()
3473 */
3474 void QtxPagePrefTextItem::store()
3475 {
3476   setString( myEditor->toPlainText() );
3477 }
3478
3479 /*!
3480   \brief Retrieve preference item from the resource manager.
3481   \sa store()
3482 */
3483 void QtxPagePrefTextItem::retrieve()
3484 {
3485   myEditor->setPlainText( getString() );
3486 }
3487
3488 /*!
3489   \class QtxPagePrefColorItem
3490   \brief GUI implementation of the resources color item.
3491 */
3492
3493 /*!
3494   \brief Constructor.
3495   \param title preference item title
3496   \param parent parent preference item
3497   \param sect resource file section associated with the preference item
3498   \param param resource file parameter associated with the preference item
3499 */
3500 QtxPagePrefColorItem::QtxPagePrefColorItem( const QString& title, QtxPreferenceItem* parent,
3501                                             const QString& sect, const QString& param )
3502 : QtxPageNamedPrefItem( title, parent, sect, param )
3503 {
3504   //  QtxPagePrefGroupItem* aGroup 0; //= dynamic_cast<QtxPagePrefGroupItem*>( parent );
3505
3506   //  setControl( myColor = new QtxColorButton( aGroup ? aGroup->gridBox() : 0 ) );
3507   setControl( myColor = new QtxColorButton( 0 ) );
3508   myColor->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
3509 }
3510
3511 /*!
3512   \brief Destructor.
3513 */
3514 QtxPagePrefColorItem::~QtxPagePrefColorItem()
3515 {
3516 }
3517
3518 /*!
3519   \brief Store preference item to the resource manager.
3520   \sa retrieve()
3521 */
3522 void QtxPagePrefColorItem::store()
3523 {
3524   setColor( myColor->color() );
3525 }
3526
3527 /*!
3528   \brief Retrieve preference item from the resource manager.
3529   \sa store()
3530 */
3531 void QtxPagePrefColorItem::retrieve()
3532 {
3533   myColor->setColor( getColor() );
3534 }
3535
3536 /*!
3537   \class QtxPagePrefBiColorItem
3538   \brief GUI implementation of the resources item to store a bi-color value.
3539
3540   The main color is specified explicitly. The secondary color is calculated
3541   by changing "value" and "saturation" parameters of the main color in the
3542   HSV notation using specified delta.
3543 */
3544
3545 /*!
3546   \brief Constructor.
3547   \param title preference item title
3548   \param parent parent preference item
3549   \param sect resource file section associated with the preference item
3550   \param param resource file parameter associated with the preference item
3551 */
3552 QtxPagePrefBiColorItem::QtxPagePrefBiColorItem( const QString& title, QtxPreferenceItem* parent,
3553                                                 const QString& sect, const QString& param )
3554 : QtxPageNamedPrefItem( title, parent, sect, param )
3555 {
3556   setControl( myColors = new QtxBiColorTool( 0 ) );
3557 }
3558
3559 /*!
3560   \brief Destructor.
3561 */
3562 QtxPagePrefBiColorItem::~QtxPagePrefBiColorItem()
3563 {
3564 }
3565
3566 /*!
3567   \bried Get auxiliary text
3568   \return text assigned to the item
3569   \sa setText()
3570 */
3571 QString QtxPagePrefBiColorItem::text() const
3572 {
3573   return myColors->text();
3574 }
3575
3576 /*!
3577   \bried Set auxiliary text
3578   \param t text being assigned to the item
3579   \sa text()
3580 */
3581 void QtxPagePrefBiColorItem::setText( const QString& t )
3582 {
3583   myColors->setText( t );
3584 }
3585
3586 /*!
3587   \brief Store preference item to the resource manager.
3588   \sa retrieve()
3589 */
3590 void QtxPagePrefBiColorItem::store()
3591 {
3592   setString( Qtx::biColorToString( myColors->mainColor(), myColors->delta() ) );
3593 }
3594
3595 /*!
3596   \brief Retrieve preference item from the resource manager.
3597   \sa store()
3598 */
3599 void QtxPagePrefBiColorItem::retrieve()
3600 {
3601   QColor c;
3602   int d;
3603   Qtx::stringToBiColor( getString(), c, d );
3604   myColors->setMainColor( c );
3605   myColors->setDelta( d );
3606 }
3607
3608 /*!
3609   \brief Get preference item option value.
3610   \param name option name
3611   \return property value or null QVariant if option is not set
3612   \sa setOptionValue()
3613 */
3614 QVariant QtxPagePrefBiColorItem::optionValue( const QString& name ) const
3615 {
3616   if ( name == "text" )
3617     return text();
3618   else
3619     return QtxPageNamedPrefItem::optionValue( name );
3620 }
3621
3622 /*!
3623   \brief Set preference item option value.
3624   \param name option name
3625   \param val new property value
3626   \sa optionValue()
3627 */
3628 void QtxPagePrefBiColorItem::setOptionValue( const QString& name, const QVariant& val )
3629 {
3630   if ( name == "text" )
3631   {
3632     if ( val.canConvert( QVariant::String ) )
3633       setText( val.toString() );
3634   }
3635   else
3636     QtxPageNamedPrefItem::setOptionValue( name, val );
3637 }
3638
3639 /*!
3640   \class QtxPagePrefFontItem
3641   \brief GUI implementation of the resources font item.
3642 */
3643
3644 /*!
3645   \brief Constructor.
3646   \param feat font editor widget features (QtxFontEdit::Features)
3647   \param title preference item title
3648   \param parent parent preference item
3649   \param sect resource file section associated with the preference item
3650   \param param resource file parameter associated with the preference item
3651 */
3652 QtxPagePrefFontItem::QtxPagePrefFontItem( const int feat, const QString& title,
3653                                           QtxPreferenceItem* parent, const QString& sect,
3654                                           const QString& param )
3655 : QtxPageNamedPrefItem( title, parent, sect, param )
3656 {
3657   setControl( myFont = new QtxFontEdit( feat ) );
3658 }
3659
3660 /*!
3661   \brief Constructor.
3662   \param title preference item title
3663   \param parent parent preference item
3664   \param sect resource file section associated with the preference item
3665   \param param resource file parameter associated with the preference item
3666 */
3667 QtxPagePrefFontItem::QtxPagePrefFontItem( const QString& title, QtxPreferenceItem* parent,
3668                                           const QString& sect, const QString& param )
3669 : QtxPageNamedPrefItem( title, parent, sect, param )
3670 {
3671   setControl( myFont = new QtxFontEdit() );
3672 }
3673
3674 /*!
3675   \brief Destructor.
3676 */
3677 QtxPagePrefFontItem::~QtxPagePrefFontItem()
3678 {
3679 }
3680
3681 /*!
3682   \brief Get font widget features.
3683   \return font widget features (ORed QtxFontEdit::Features flags)
3684   \sa setFeatures()
3685 */
3686 int QtxPagePrefFontItem::features() const
3687 {
3688   return myFont->features();
3689 }
3690
3691 /*!
3692   \brief Set font widget features.
3693   \param f new font widget features (ORed QtxFontEdit::Features flags)
3694   \sa features()
3695 */
3696 void QtxPagePrefFontItem::setFeatures( const int f )
3697 {
3698   myFont->setFeatures( f );
3699 }
3700
3701 /*!
3702   \brief Specifies whether widget works in Native or Custom mode. Native mode
3703   is intended for working with system fonts. Custom mode is intended for
3704   working with manually defined set of fonts. Set of custom fonts can be
3705   specified with setFonts() method
3706   \param mode mode from QtxFontEdit::Mode enumeration
3707   \sa mode()
3708 */
3709 void QtxPagePrefFontItem::setMode( const int mode )
3710 {
3711   myFont->setMode( mode );
3712 }
3713
3714 /*!
3715   \brief Verifies whether widget works in Native or Custom mode
3716   \return Native or Custom mode
3717   \sa setMode()
3718 */
3719 int QtxPagePrefFontItem::mode() const
3720 {
3721   return myFont->mode();
3722 }
3723
3724 /*!
3725   \brief Sets list of custom fonts.
3726   <b>This method is intended for working in Custom mode only.</b>
3727   \param fams list of families
3728   \sa fonts(), setMode()
3729 */
3730 void QtxPagePrefFontItem::setFonts( const QStringList& fams )
3731 {
3732   myFont->setFonts( fams );
3733 }
3734
3735 /*!
3736   \brief Gets list of custom fonts
3737   \return list of families
3738   \sa setFonts(), setMode()
3739 */
3740 QStringList QtxPagePrefFontItem::fonts() const
3741 {
3742   return myFont->fonts();
3743 }
3744
3745 /*!
3746   \brief Sets list of available font sizes.
3747   <b>This method is intended for working in Custom mode only.</b> The list of sizes can
3748   be empty. In this case system generate listof size automatically from 8 till 72.
3749   \param sizes list of sizes
3750   \sa sizes(), setMode()
3751 */
3752 void QtxPagePrefFontItem::setSizes( const QList<int>& sizes )
3753 {
3754   myFont->setSizes( sizes );
3755 }
3756
3757 /*!
3758   \brief Gets list of custom fonts
3759   \return list of families
3760   \sa setFonts(), setMode()
3761 */
3762 QList<int> QtxPagePrefFontItem::sizes() const
3763 {
3764   return myFont->sizes();
3765 }
3766
3767 /*!
3768   \brief Store preference item to the resource manager.
3769   \sa retrieve()
3770 */
3771 void QtxPagePrefFontItem::store()
3772 {
3773   setFont( myFont->currentFont() );
3774 }
3775
3776 /*!
3777   \brief Retrieve preference item from the resource manager.
3778   \sa store()
3779 */
3780 void QtxPagePrefFontItem::retrieve()
3781 {
3782   myFont->setCurrentFont( getFont() );
3783 }
3784
3785 /*!
3786   \brief Get preference item option value.
3787   \param name option name
3788   \return property value or null QVariant if option is not set
3789   \sa setOptionValue()
3790 */
3791 QVariant QtxPagePrefFontItem::optionValue( const QString& name ) const
3792 {
3793   if ( name == "features" )
3794     return features();
3795   else if ( name == "mode" )
3796     return mode();
3797   else if ( name == "fonts" || name == "families" )
3798     return fonts();
3799   else if ( name == "sizes" )
3800   {
3801     QList<QVariant> lst;
3802     QList<int> nums = sizes();
3803     for ( QList<int>::const_iterator it = nums.begin(); it != nums.end(); ++it )
3804       lst.append( *it );
3805     return lst;
3806   }
3807   else
3808     return QtxPageNamedPrefItem::optionValue( name );
3809 }
3810
3811 /*!
3812   \brief Set preference item option value.
3813   \param name option name
3814   \param val new property value
3815   \sa optionValue()
3816 */
3817 void QtxPagePrefFontItem::setOptionValue( const QString& name, const QVariant& val )
3818 {
3819   if ( name == "features" )
3820   {
3821     if ( val.canConvert( QVariant::Int ) )
3822       setFeatures( val.toInt() );
3823   }
3824   else if ( name == "mode" )
3825   {
3826     if ( val.canConvert( QVariant::Int ) )
3827       setMode( val.toInt() );
3828   }
3829   else if ( name == "fonts" || name == "families" )
3830   {
3831     QStringList values;
3832     if ( toStringList( val, values ) )
3833       setFonts( values );
3834   }
3835   else if ( name == "sizes" )
3836   {
3837     if ( val.type() == QVariant::List )
3838     {
3839       QList<int> lst;
3840       QList<QVariant> varList = val.toList();
3841       for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it )
3842       {
3843         if ( (*it).canConvert( QVariant::Int ) )
3844           lst.append( (*it).toInt() );
3845       }
3846       setSizes( lst );
3847     }
3848   }
3849   else
3850     QtxPageNamedPrefItem::setOptionValue( name, val );
3851 }
3852
3853 /*!
3854   \class  QtxPagePrefPathItem
3855   \brief GUI implementation of the resources file/directory path item.
3856 */
3857
3858 /*!
3859   \brief Constructor.
3860   \param type path widget mode (Qtx::PathType )
3861   \param title preference item title
3862   \param parent parent preference item
3863   \param sect resource file section associated with the preference item
3864   \param param resource file parameter associated with the preference item
3865 */
3866 QtxPagePrefPathItem::QtxPagePrefPathItem( const Qtx::PathType type, const QString& title,
3867                                           QtxPreferenceItem* parent, const QString& sect, const QString& param )
3868 : QtxPageNamedPrefItem( title, parent, sect, param )
3869 {
3870   setControl( myPath = new QtxPathEdit( type ) );
3871 }
3872
3873 /*!
3874   \brief Constructor.
3875   \param title preference item title
3876   \param parent parent preference item
3877   \param sect resource file section associated with the preference item
3878   \param param resource file parameter associated with the preference item
3879 */
3880 QtxPagePrefPathItem::QtxPagePrefPathItem( const QString& title, QtxPreferenceItem* parent,
3881                                           const QString& sect, const QString& param )
3882 : QtxPageNamedPrefItem( title, parent, sect, param )
3883 {
3884   setControl( myPath = new QtxPathEdit() );
3885 }
3886
3887 /*!
3888   \brief Destructor.
3889 */
3890 QtxPagePrefPathItem::~QtxPagePrefPathItem()
3891 {
3892 }
3893
3894 /*!
3895   \brief Get path widget mode.
3896   \return current path widget mode (Qtx::PathType)
3897   \sa setPathType()
3898 */
3899 Qtx::PathType QtxPagePrefPathItem::pathType() const
3900 {
3901   return myPath->pathType();
3902 }
3903
3904 /*!
3905   \brief Set path widget mode.
3906   \param type new path widget mode (Qtx::PathType)
3907   \sa pathType()
3908 */
3909 void QtxPagePrefPathItem::setPathType( const Qtx::PathType type )
3910 {
3911   myPath->setPathType( type );
3912 }
3913
3914 /*!
3915   \brief Get currently used path widget filters.
3916   \return file or directory path filters
3917   \sa setPathFilter()
3918 */
3919 QString QtxPagePrefPathItem::pathFilter() const
3920 {
3921   return myPath->pathFilter();
3922 }
3923
3924 /*!
3925   \brief Set path widget filters.
3926   \param f new file or directory path filters
3927   \sa pathFilter()
3928 */
3929 void QtxPagePrefPathItem::setPathFilter( const QString& f )
3930 {
3931   myPath->setPathFilter( f );
3932 }
3933
3934 /*!
3935   \brief Get currently used path widget options.
3936   \return file or directory path options
3937   \sa setPathOptions()
3938 */
3939 QFileDialog::Options QtxPagePrefPathItem::pathOptions() const
3940 {
3941   return myPath->pathOptions();
3942 }
3943
3944 /*!
3945   \brief Set path widget options.
3946   \param f new file or directory path options
3947   \sa pathOptions()
3948 */
3949 void QtxPagePrefPathItem::setPathOptions( const QFileDialog::Options options )
3950 {
3951   myPath->setPathOptions( options );
3952 }
3953
3954
3955 /*!
3956   \brief Store preference item to the resource manager.
3957   \sa retrieve()
3958 */
3959 void QtxPagePrefPathItem::store()
3960 {
3961   setString( myPath->path() );
3962 }
3963
3964 /*!
3965   \brief Retrieve preference item from the resource manager.
3966   \sa store()
3967 */
3968 void QtxPagePrefPathItem::retrieve()
3969 {
3970   myPath->setPath( getString() );
3971 }
3972
3973 /*!
3974   \brief Get preference item option value.
3975   \param name option name
3976   \return property value or null QVariant if option is not set
3977   \sa setOptionValue()
3978 */
3979 QVariant QtxPagePrefPathItem::optionValue( const QString& name ) const
3980 {
3981   if ( name == "path_type" )
3982     return pathType();
3983   else if ( name == "path_filter" )
3984     return pathFilter();
3985   else if ( name == "path_options" )
3986     return QVariant::fromValue(pathOptions());
3987   else
3988     return QtxPageNamedPrefItem::optionValue( name );
3989 }
3990
3991 /*!
3992   \brief Set preference item option value.
3993   \param name option name
3994   \param val new property value
3995   \sa optionValue()
3996 */
3997 void QtxPagePrefPathItem::setOptionValue( const QString& name, const QVariant& val )
3998 {
3999   if ( name == "path_type" )
4000   {
4001     if ( val.canConvert( QVariant::Int ) )
4002       setPathType( (Qtx::PathType)val.toInt() );
4003   }
4004   else if ( name == "path_filter" )
4005   {
4006     if ( val.canConvert( QVariant::String ) )
4007       setPathFilter( val.toString() );
4008   }
4009   else if ( name == "path_options" )
4010   {
4011     if ( val.canConvert( QVariant::Int ) )
4012       setPathOptions( (QFileDialog::Options)val.toInt() );
4013   }
4014   else
4015     QtxPageNamedPrefItem::setOptionValue( name, val );
4016 }
4017
4018 /*!
4019   \class QtxPagePrefPathListItem
4020   \brief GUI implementation of the resources files/directories list item.
4021 */
4022
4023 /*!
4024   \brief Constructor.
4025   \param parent parent preference item
4026   \param sect resource file section associated with the preference item
4027   \param param resource file parameter associated with the preference item
4028 */
4029 QtxPagePrefPathListItem::QtxPagePrefPathListItem( QtxPreferenceItem* parent,
4030                                                   const QString& sect, const QString& param )
4031 : QtxPageNamedPrefItem( QString(), parent, sect, param )
4032 {
4033   setControl( myPaths = new QtxPathListEdit() );
4034 }
4035
4036 /*!
4037   \brief Constructor.
4038   \param type path list widget mode (Qtx::PathType)
4039   \param title preference item title
4040   \param parent parent preference item
4041   \param sect resource file section associated with the preference item
4042   \param param resource file parameter associated with the preference item
4043 */
4044 QtxPagePrefPathListItem::QtxPagePrefPathListItem( const Qtx::PathType type, const QString& title,
4045                                                   QtxPreferenceItem* parent, const QString& sect, const QString& param )
4046 : QtxPageNamedPrefItem( title, parent, sect, param )
4047 {
4048   setControl( myPaths = new QtxPathListEdit( type ) );
4049 }
4050
4051 /*!
4052   \brief Constructor.
4053   \param title preference item title
4054   \param parent parent preference item
4055   \param sect resource file section associated with the preference item
4056   \param param resource file parameter associated with the preference item
4057 */
4058 QtxPagePrefPathListItem::QtxPagePrefPathListItem( const QString& title, QtxPreferenceItem* parent,
4059                                                   const QString& sect, const QString& param )
4060 : QtxPageNamedPrefItem( title, parent, sect, param )
4061 {
4062   setControl( myPaths = new QtxPathListEdit() );
4063 }
4064
4065 /*!
4066   \brief Destructor.
4067 */
4068 QtxPagePrefPathListItem::~QtxPagePrefPathListItem()
4069 {
4070 }
4071
4072 /*!
4073   \brief Get path list widget mode.
4074   \return currently used path list widget mode (Qtx::PathType)
4075   \sa setPathType()
4076 */
4077 Qtx::PathType QtxPagePrefPathListItem::pathType() const
4078 {
4079   return myPaths->pathType();
4080 }
4081
4082 /*!
4083   \brief Set path list widget mode.
4084   \param type new path list widget mode (Qtx::PathType)
4085   \sa pathType()
4086 */
4087 void QtxPagePrefPathListItem::setPathType( const Qtx::PathType type )
4088 {
4089   myPaths->setPathType( type );
4090 }
4091
4092 /*!
4093   \brief Store preference item to the resource manager.
4094   \sa retrieve()
4095 */
4096 void QtxPagePrefPathListItem::store()
4097 {
4098   setString( myPaths->pathList().join( ";" ) );
4099 }
4100
4101 /*!
4102   \brief Retrieve preference item from the resource manager.
4103   \sa store()
4104 */
4105 void QtxPagePrefPathListItem::retrieve()
4106 {
4107   myPaths->setPathList( getString().split( ";" ) );
4108 }
4109
4110 /*!
4111   \brief Get preference item option value.
4112   \param name option name
4113   \return property value or null QVariant if option is not set
4114   \sa setOptionValue()
4115 */
4116 QVariant QtxPagePrefPathListItem::optionValue( const QString& name ) const
4117 {
4118   if ( name == "path_type" )
4119     return pathType();
4120   else
4121     return QtxPageNamedPrefItem::optionValue( name );
4122 }
4123
4124 /*!
4125   \brief Set preference item option value.
4126   \param name option name
4127   \param val new property value
4128   \sa optionValue()
4129 */
4130 void QtxPagePrefPathListItem::setOptionValue( const QString& name, const QVariant& val )
4131 {
4132   if ( name == "path_type" )
4133   {
4134     if ( val.canConvert( QVariant::Int ) )
4135       setPathType( (Qtx::PathType)val.toInt() );
4136   }
4137   else
4138     QtxPageNamedPrefItem::setOptionValue( name, val );
4139 }
4140
4141 /*!
4142   \class  QtxPagePrefDateTimeItem
4143   \brief GUI implementation of resources date/time item.
4144 */
4145
4146 /*!
4147   \brief Constructor.
4148
4149   Creates an item to enter date and time.
4150
4151   \param title preference item title
4152   \param parent parent preference item
4153   \param sect resource file section associated with the preference item
4154   \param param resource file parameter associated with the preference item
4155 */
4156 QtxPagePrefDateTimeItem::QtxPagePrefDateTimeItem( const QString& title, QtxPreferenceItem* parent,
4157                                                   const QString& sect, const QString& param )
4158 : QtxPageNamedPrefItem( title, parent, sect, param ),
4159   myType( DateTime )
4160 {
4161   setControl( myDateTime = new QDateTimeEdit() );
4162   myDateTime->setCalendarPopup( true );
4163   myDateTime->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
4164   updateDateTime();
4165 }
4166
4167 /*!
4168   \brief Constructor.
4169
4170   Creates preference item for editing of the date and/or time value:
4171   the type is specified by parameter \a type.
4172
4173   \param type preference item input type (QtxPagePrefDateTimeItem::InputType)
4174   \param title preference item title
4175   \param parent parent preference item
4176   \param sect resource file section associated with the preference item
4177   \param param resource file parameter associated with the preference item
4178 */
4179 QtxPagePrefDateTimeItem::QtxPagePrefDateTimeItem( const int type, const QString& title, QtxPreferenceItem* parent,
4180                                                   const QString& sect, const QString& param )
4181 : QtxPageNamedPrefItem( title, parent, sect, param ),
4182   myType( type )
4183 {
4184   setControl( myDateTime = new QDateTimeEdit() );
4185   myDateTime->setCalendarPopup( true );
4186   myDateTime->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
4187   updateDateTime();
4188 }
4189
4190 /*!
4191   \brief Destructor.
4192 */
4193 QtxPagePrefDateTimeItem::~QtxPagePrefDateTimeItem()
4194 {
4195 }
4196
4197 /*!
4198   \brief Get date/time box preference item input type.
4199   \return preference item input type (QtxPagePrefDateTimeItem::InputType)
4200   \sa setInputType()
4201 */
4202 int QtxPagePrefDateTimeItem::inputType() const
4203 {
4204   return myType;
4205 }
4206
4207 /*!
4208   \brief Set date/time box preference item input type.
4209   \param type new preference item input type (QtxPagePrefDateTimeItem::InputType)
4210   \sa inputType()
4211 */
4212 void QtxPagePrefDateTimeItem::setInputType( const int type )
4213 {
4214   if ( myType == type )
4215     return;
4216
4217   myType = type;
4218   updateDateTime();
4219 }
4220
4221 /*!
4222   \brief Check if the popup calendar menu is enabled.
4223   \return \c true if calendar popup menu is enabled
4224 */
4225 bool QtxPagePrefDateTimeItem::calendar() const
4226 {
4227   return myDateTime->calendarPopup();
4228 }
4229
4230 /*!
4231   \brief Enable/disable popup calendar menu.
4232   \param on new flag state
4233 */
4234 void QtxPagePrefDateTimeItem::setCalendar( const bool on )
4235 {
4236   myDateTime->setCalendarPopup( on );
4237 }
4238
4239 /*!
4240   \brief Get maximum date value.
4241   \return maximum date value
4242   \sa setMaximumDate(), minimumDate(), maximumTime(), minimumTime()
4243 */
4244 QDate QtxPagePrefDateTimeItem::maximumDate() const
4245 {
4246   return myDateTime->maximumDate();
4247 }
4248
4249 /*!
4250   \brief Get maximum time value.
4251   \return maximum time value
4252   \sa setMaximumTime(), minimumTime(), maximumDate(), minimumDate()
4253 */
4254 QTime QtxPagePrefDateTimeItem::maximumTime() const
4255 {
4256   return myDateTime->maximumTime();
4257 }
4258
4259 /*!
4260   \brief Get minimum date value.
4261   \return minimum date value
4262   \sa setMinimumDate(), maximumDate(), maximumTime(), minimumTime()
4263 */
4264 QDate QtxPagePrefDateTimeItem::minimumDate() const
4265 {
4266   return myDateTime->minimumDate();
4267 }
4268
4269 /*!
4270   \brief Get minimum time value.
4271   \return maximum time value
4272   \sa setMinimumTime(), maximumTime(), maximumDate(), minimumDate()
4273 */
4274 QTime QtxPagePrefDateTimeItem::minimumTime() const
4275 {
4276   return myDateTime->minimumTime();
4277 }
4278
4279 /*!
4280   \brief Set maximum date value.
4281   \param d new maximum date value
4282   \sa maximumDate(), minimumDate(), maximumTime(), minimumTime()
4283 */
4284 void QtxPagePrefDateTimeItem::setMaximumDate( const QDate& d )
4285 {
4286   if ( d.isValid() )
4287     myDateTime->setMaximumDate( d );
4288   else
4289     myDateTime->clearMaximumDate();
4290 }
4291
4292 /*!
4293   \brief Set maximum time value.
4294   \param t new maximum time value
4295   \sa maximumTime(), minimumTime(), maximumDate(), minimumDate()
4296 */
4297 void QtxPagePrefDateTimeItem::setMaximumTime( const QTime& t )
4298 {
4299   if ( t.isValid() )
4300     myDateTime->setMaximumTime( t );
4301   else
4302     myDateTime->clearMaximumTime();
4303 }
4304
4305 /*!
4306   \brief Set minimum date value.
4307   \param d new minimum date value
4308   \sa minimumDate(), maximumDate(), maximumTime(), minimumTime()
4309 */
4310 void QtxPagePrefDateTimeItem::setMinimumDate( const QDate& d )
4311 {
4312   if ( d.isValid() )
4313     myDateTime->setMinimumDate( d );
4314   else
4315     myDateTime->clearMinimumDate();
4316 }
4317
4318 /*!
4319   \brief Set minimum time value.
4320   \param t new minimum time value
4321   \sa minimumTime(), maximumTime(), maximumDate(), minimumDate()
4322 */
4323 void QtxPagePrefDateTimeItem::setMinimumTime( const QTime& t )
4324 {
4325   if ( t.isValid() )
4326     myDateTime->setMinimumTime( t );
4327   else
4328     myDateTime->clearMinimumTime();
4329 }
4330
4331 /*!
4332   \brief Store preference item to the resource manager.
4333   \sa retrieve()
4334 */
4335 void QtxPagePrefDateTimeItem::store()
4336 {
4337   QString str;
4338   switch ( inputType() )
4339   {
4340   case Date:
4341     str = myDateTime->date().toString( Qt::ISODate );
4342     break;
4343   case Time:
4344     str = myDateTime->time().toString( Qt::ISODate );
4345     break;
4346   case DateTime:
4347     str = myDateTime->dateTime().toString( Qt::ISODate );
4348     break;
4349   }
4350
4351   setString( str );
4352 }
4353
4354 /*!
4355   \brief Retrieve preference item from the resource manager.
4356   \sa store()
4357 */
4358 void QtxPagePrefDateTimeItem::retrieve()
4359 {
4360   QString str = getString();
4361   switch ( inputType() )
4362   {
4363   case Date:
4364     myDateTime->setDate( QDate::fromString( str, Qt::ISODate ) );
4365     break;
4366   case Time:
4367     myDateTime->setTime( QTime::fromString( str, Qt::ISODate ) );
4368     break;
4369   case DateTime:
4370     myDateTime->setDateTime( QDateTime::fromString( str, Qt::ISODate ) );
4371     break;
4372   }
4373 }
4374
4375 /*!
4376   \brief Get preference item option value.
4377   \param name option name
4378   \return property value or null QVariant if option is not set
4379   \sa setOptionValue()
4380 */
4381 QVariant QtxPagePrefDateTimeItem::optionValue( const QString& name ) const
4382 {
4383   if ( name == "input_type" || name == "type" )
4384     return inputType();
4385   else if ( name == "minimum_date" || name == "min_date" )
4386     return minimumDate();
4387   else if ( name == "maximum_date" || name == "max_date" )
4388     return maximumDate();
4389   else if ( name == "minimum_time" || name == "min_time" )
4390     return minimumTime();
4391   else if ( name == "maximum_time" || name == "max_time" )
4392     return maximumTime();
4393   else
4394     return QtxPageNamedPrefItem::optionValue( name );
4395 }
4396
4397 /*!
4398   \brief Set preference item option value.
4399   \param name option name
4400   \param val new property value
4401   \sa optionValue()
4402 */
4403 void QtxPagePrefDateTimeItem::setOptionValue( const QString& name, const QVariant& val )
4404 {
4405   if ( name == "input_type" || name == "type" )
4406   {
4407     if ( val.canConvert( QVariant::Int ) )
4408       setInputType( val.toInt() );
4409   }
4410   else if ( name == "minimum_date" || name == "min_date" )
4411   {
4412     if ( val.canConvert( QVariant::Date ) )
4413       setMinimumDate( val.toDate() );
4414   }
4415   else if ( name == "maximum_date" || name == "max_date" )
4416   {
4417     if ( val.canConvert( QVariant::Date ) )
4418       setMaximumDate( val.toDate() );
4419   }
4420   else if ( name == "minimum_time" || name == "min_time" )
4421   {
4422     if ( val.canConvert( QVariant::Time ) )
4423       setMinimumTime( val.toTime() );
4424   }
4425   else if ( name == "maximum_time" || name == "max_time" )
4426   {
4427     if ( val.canConvert( QVariant::Time ) )
4428       setMaximumTime( val.toTime() );
4429   }
4430   else
4431     QtxPageNamedPrefItem::setOptionValue( name, val );
4432 }
4433
4434 /*!
4435   \brief Update date/time widget.
4436 */
4437 void QtxPagePrefDateTimeItem::updateDateTime()
4438 {
4439   QString dispFmt;
4440   switch ( inputType() )
4441   {
4442   case Date:
4443     dispFmt = QDateEdit().displayFormat();
4444     break;
4445   case Time:
4446     dispFmt = QTimeEdit().displayFormat();
4447     break;
4448   case DateTime:
4449     dispFmt = QDateTimeEdit().displayFormat();
4450     break;
4451   }
4452
4453   myDateTime->setDisplayFormat( dispFmt );
4454 }
4455
4456
4457 /*!
4458   \class QtxPagePrefBackgroundItem
4459   \brief GUI implementation of the resources item to store background data.
4460
4461   Preference item allows specifying background data in different ways:
4462   - solid color
4463   - texture image file
4464   - simple two-color gradient
4465   - complex custom gradient (NOT IMPLEMENTED YET)
4466
4467   Allowed background modes can be specified using setModeAllowed() method.
4468   Texture modes can be enabled/disabled using setTextureModeAllowed() method.
4469   Also, showing texture controls can be enabled/disabled by means of
4470   setTextureAllowed() method.
4471   Verical or horizontal orientation of the widget can be chosen via setOrientation()
4472   method (default orientation is horizontal).
4473
4474   Simple gradient types can be specified using setGradients() method.
4475
4476   \sa Qtx::BackgroundData, QtxBackgroundTool
4477 */
4478
4479 /*!
4480   \brief Constructor.
4481   \param title preference item title
4482   \param parent parent preference item
4483   \param sect resource file section associated with the preference item
4484   \param param resource file parameter associated with the preference item
4485 */
4486 QtxPagePrefBackgroundItem::QtxPagePrefBackgroundItem( const QString& title, QtxPreferenceItem* parent,
4487                                                       const QString& sect, const QString& param )
4488 : QtxPageNamedPrefItem( title, parent, sect, param )
4489 {
4490   setControl( myBgTool = new QtxBackgroundTool( 0 ) );
4491 }
4492
4493 /*!
4494   \brief Destructor.
4495 */
4496 QtxPagePrefBackgroundItem::~QtxPagePrefBackgroundItem()
4497 {
4498 }
4499
4500 /*!
4501   \brief Get allowed two-color gradients to the widget
4502   \param gradients gradients names are returned via this parameter
4503   \param ids gradients identifiers are returned via this parameter (empty list can be returned)
4504 */
4505 void QtxPagePrefBackgroundItem::gradients( QStringList& gradList, QIntList& idList ) const
4506 {
4507   myBgTool->gradients( gradList, idList );
4508 }
4509
4510 /*!
4511   \brief Set allowed two-color gradients to the widget
4512   \param gradients gradients names
4513   \param ids optional gradients identifiers; if not specified, gradients are automatically numbered starting from 0
4514 */
4515 void QtxPagePrefBackgroundItem::setGradients( const QStringList& gradients, const QIntList& ids )
4516 {
4517   myBgTool->setGradients( gradients, ids );
4518 }
4519
4520 /*!
4521   \brief Check if specific background mode is allowed
4522   \param mode background mode
4523   \return \c true if specified background mode is enabled or \c false otherwise
4524   \sa setModeAllowed()
4525 */
4526 bool QtxPagePrefBackgroundItem::isModeAllowed( Qtx::BackgroundMode mode ) const
4527 {
4528   return myBgTool->isModeAllowed( mode );
4529 }
4530
4531 /*!
4532   \brief Enable / disable specific background mode
4533   \param mode background mode
4534   \param on enable / disable flag
4535   \sa isModeAllowed()
4536 */
4537 void QtxPagePrefBackgroundItem::setModeAllowed( Qtx::BackgroundMode mode, bool on )
4538 {
4539   myBgTool->setModeAllowed( mode, on );
4540 }
4541
4542 /*!
4543   \brief Check if specific texture mode is allowed
4544   \param mode texture mode
4545   \return \c true if specified texture mode is enabled or \c false otherwise
4546   \sa setTextureModeAllowed(), setTextureAllowed()
4547 */
4548 bool QtxPagePrefBackgroundItem::isTextureModeAllowed( Qtx::TextureMode mode ) const
4549 {
4550   return myBgTool->isTextureModeAllowed( mode );
4551 }
4552
4553 /*!
4554   \brief Enable / disable specific texture mode
4555   \param mode texture mode
4556   \param on enable / disable flag (\c true by default)
4557   \sa isTextureModeAllowed(), setTextureAllowed()
4558 */
4559 void QtxPagePrefBackgroundItem::setTextureModeAllowed( Qtx::TextureMode mode, bool on )
4560 {
4561   myBgTool->setTextureModeAllowed( mode, on );
4562 }
4563
4564 /*!
4565   \brief Check if texture controls are allowed (shown)
4566   \return \c true if texture controls are enabled or \c false otherwise
4567   \sa setTextureAllowed(), setTextureModeAllowed()
4568 */
4569 bool QtxPagePrefBackgroundItem::isTextureAllowed() const
4570 {
4571   return myBgTool->isTextureAllowed();
4572 }
4573
4574 /*!
4575   \brief Enable / disable texture controls
4576   \param on enable / disable flag (\c true by default)
4577   \sa isTextureAllowed(), setTextureModeAllowed()
4578 */
4579 void QtxPagePrefBackgroundItem::setTextureAllowed( bool on )
4580 {
4581   myBgTool->setTextureAllowed( on );
4582 }
4583
4584 /*!
4585   \brief Get allowed image formats
4586   \return image formats
4587 */
4588 QString QtxPagePrefBackgroundItem::imageFormats() const
4589 {
4590   return myBgTool->imageFormats();
4591 }
4592
4593 /*!
4594   \brief Set allowed image formats
4595   \param formats image formats
4596 */
4597 void QtxPagePrefBackgroundItem::setImageFormats( const QString& formats )
4598 {
4599   myBgTool->setImageFormats( formats );
4600 }
4601
4602 /*!
4603   \brief Get widget editor orientation
4604   \return orientation
4605 */
4606 Qt::Orientation QtxPagePrefBackgroundItem::orientation() const
4607 {
4608   return myBgTool->orientation();
4609 }
4610
4611 /*!
4612   \brief Set widget editor orientation
4613   \param o orientation
4614 */
4615 void QtxPagePrefBackgroundItem::setOrientation( Qt::Orientation o )
4616 {
4617   myBgTool->setOrientation( o );
4618 }
4619
4620 /*!
4621   \brief Store preference item to the resource manager.
4622   \sa retrieve()
4623 */
4624 void QtxPagePrefBackgroundItem::store()
4625 {
4626   setString( Qtx::backgroundToString( myBgTool->data() ) );
4627 }
4628
4629 /*!
4630   \brief Retrieve preference item from the resource manager.
4631   \sa store()
4632 */
4633 void QtxPagePrefBackgroundItem::retrieve()
4634 {
4635   myBgTool->setData( Qtx::stringToBackground( getString() ) );
4636 }
4637
4638 /*!
4639   \brief Get preference item option value.
4640   \param name option name
4641   \return property value or null QVariant if option is not set
4642   \sa setOptionValue()
4643 */
4644 QVariant QtxPagePrefBackgroundItem::optionValue( const QString& name ) const
4645 {
4646   if ( name == "texture_enabled" )
4647     return isTextureAllowed();
4648   else if ( name == "color_enabled" )
4649     return isModeAllowed( Qtx::ColorBackground );
4650   else if ( name == "gradient_enabled" )
4651     return isModeAllowed( Qtx::SimpleGradientBackground );
4652   else if ( name == "custom_enabled" )
4653     return isModeAllowed( Qtx::CustomGradientBackground );
4654   else if ( name == "texture_center_enabled" )
4655     return isTextureModeAllowed( Qtx::CenterTexture );
4656   else if ( name == "texture_tile_enabled" )
4657     return isTextureModeAllowed( Qtx::TileTexture );
4658   else if ( name == "texture_stretch_enabled" )
4659     return isTextureModeAllowed( Qtx::StretchTexture );
4660   else if ( name == "orientation" )
4661     return orientation();
4662   else if ( name == "image_formats" )
4663     return imageFormats();
4664   else if ( name == "gradient_names" ) {
4665     QStringList grList;
4666     QIntList    idList;
4667     gradients( grList, idList );
4668     return grList;
4669   }
4670   else if ( name == "gradient_ids" ) {
4671     QStringList grList;
4672     QIntList    idList;
4673     gradients( grList, idList );
4674     QList<QVariant> lst;
4675     for ( QIntList::const_iterator it = idList.begin(); it != idList.end(); ++it )
4676       lst.append( *it );
4677     return lst;
4678   }
4679   else
4680     return QtxPageNamedPrefItem::optionValue( name );
4681 }
4682
4683 /*!
4684   \brief Set preference item option value.
4685   \param name option name
4686   \param val new property value
4687   \sa optionValue()
4688 */
4689 void QtxPagePrefBackgroundItem::setOptionValue( const QString& name, const QVariant& val )
4690 {
4691   if ( name == "texture_enabled" ) {
4692     if ( val.canConvert( QVariant::Bool ) )
4693       setTextureAllowed( val.toBool() );
4694   }
4695   else if ( name == "color_enabled" ) {
4696     if ( val.canConvert( QVariant::Bool ) )
4697       setModeAllowed( Qtx::ColorBackground, val.toBool() );
4698   }
4699   else if ( name == "gradient_enabled" ) {
4700     if ( val.canConvert( QVariant::Bool ) )
4701       setModeAllowed( Qtx::SimpleGradientBackground, val.toBool() );
4702   }
4703   else if ( name == "custom_enabled" ) {
4704     if ( val.canConvert( QVariant::Bool ) )
4705       setModeAllowed( Qtx::CustomGradientBackground, val.toBool() );
4706   }
4707   else if ( name == "texture_center_enabled" ) {
4708     if ( val.canConvert( QVariant::Bool ) )
4709       setTextureModeAllowed( Qtx::CenterTexture, val.toBool() );
4710   }
4711   else if ( name == "texture_tile_enabled" ) {
4712     if ( val.canConvert( QVariant::Bool ) )
4713       setTextureModeAllowed( Qtx::TileTexture, val.toBool() );
4714   }
4715   else if ( name == "texture_stretch_enabled" ) {
4716     if ( val.canConvert( QVariant::Bool ) )
4717       setTextureModeAllowed( Qtx::StretchTexture, val.toBool() );
4718   }
4719   else if ( name == "orientation" ) {
4720     if ( val.canConvert( QVariant::Int ) )
4721       setOrientation( (Qt::Orientation)val.toInt() );
4722   }
4723   else if ( name == "image_formats" ) {
4724     if ( val.canConvert( QVariant::String ) )
4725       setImageFormats( val.toString() );
4726   }
4727   else if ( name == "gradient_names" ) {
4728     QStringList values;
4729     if ( toStringList( val, values ) )
4730       setGradients( values );
4731   }
4732   else if ( name == "gradient_ids" ) {
4733     if ( val.canConvert( QVariant::List ) ) {
4734       QStringList grList;
4735       QIntList    idList;
4736       gradients( grList, idList );
4737       idList.clear();
4738       QList<QVariant> varList = val.toList();
4739       for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it ) {
4740         if ( (*it).canConvert( QVariant::Int ) )
4741           idList.append( (*it).toInt() );
4742       }
4743       setGradients( grList, idList );
4744     }
4745   }
4746   else
4747     QtxPageNamedPrefItem::setOptionValue( name, val );
4748 }
4749
4750 /*!
4751   \brief Constructor.
4752
4753   Creates preference item of user defined widget. The item widget has to be inherited from
4754   QtxUserDefinedContent class. An instance of this class has to be installed into the item
4755   with help of setContent method. Methods optionValue and setOptionValue use pointer on the
4756   content widget an qint64 value.
4757
4758   \param parent parent preference item
4759 */
4760 QtxUserDefinedItem::QtxUserDefinedItem( QtxPreferenceItem* parent )
4761   : QtxPageNamedPrefItem(QString(), parent), myContent(0)
4762 {
4763 }
4764
4765 /*!
4766   \brief Lets to Store preferences for content instance
4767   \sa retrieve()
4768 */
4769 void QtxUserDefinedItem::store()
4770 {
4771   if (myContent) {
4772     myContent->store( resourceMgr(), preferenceMgr());
4773   }
4774 }
4775
4776 /*!
4777   \brief Lets to Retrieve preferences for content instance
4778   \sa store()
4779 */
4780 void QtxUserDefinedItem::retrieve()
4781 {
4782   if (myContent) {
4783     myContent->retrieve( resourceMgr(), preferenceMgr());
4784   }
4785 }
4786
4787 /*!
4788  * \brief Returns option value
4789  * \param theName is a string "content"
4790  * \return pointer on QtxUserDefinedContent class instance as a qint64 value
4791  */
4792 QVariant QtxUserDefinedItem::optionValue( const QString& theName ) const
4793 {
4794   if ( theName == "content" )
4795     return (qint64) myContent;
4796   else
4797     return QtxPreferenceItem::optionValue( theName );
4798 }
4799
4800 /*!
4801  * \brief Sets option value
4802  * \param theName is a string "content"
4803  * \param theVal is a pointer on QtxUserDefinedContent class instance represented as qint64 value
4804  */
4805 void QtxUserDefinedItem::setOptionValue( const QString& theName, const QVariant& theVal)
4806 {
4807   if ( theName == "content" ) {
4808     if ( theVal.canConvert( QVariant::ULongLong ) ) {
4809       setContent( (QtxUserDefinedContent*)theVal.toULongLong() );
4810     }
4811   } else
4812     QtxPreferenceItem::setOptionValue( theName, theVal );
4813 }
4814
4815 /*!
4816  * \brief Defines content of the property item as a Widget which has to be inherited from
4817  * QtxUserDefinedContent class.
4818  * \param theContent is an QtxUserDefinedContent class instance.
4819  */
4820 void QtxUserDefinedItem::setContent( QtxUserDefinedContent* theContent )
4821 {
4822   myContent = theContent;
4823   setControl(myContent);
4824 }