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