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