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