Salome HOME
Merge branch 'V7_dev'
[modules/gui.git] / src / Qtx / QtxPagePrefMgr.cxx
1 // Copyright (C) 2007-2016  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   QWidget* w = widget();
1347   if ( qobject_cast<QScrollArea*>( w ) )
1348     w = qobject_cast<QScrollArea*>( w )->widget();
1349   QLayout* l = w ? w->layout() : 0;
1350   for ( int i = 0; l && i < l->count() && !s; i++ )
1351     s = l->itemAt( i )->spacerItem();
1352
1353   if ( s )
1354     s->changeSize( 0, 0, QSizePolicy::Minimum, on ? QSizePolicy::Expanding : QSizePolicy::Minimum );
1355 }
1356
1357 /*!
1358   \brief Get preference item option value.
1359   \param name option name
1360   \return property value or null QVariant if option is not set
1361   \sa setOptionValue()
1362 */
1363 QVariant QtxPagePrefFrameItem::optionValue( const QString& name ) const
1364 {
1365   if ( name == "margin" )
1366     return margin();
1367   else if ( name == "spacing" )
1368     return spacing();
1369   else if ( name == "columns" )
1370     return columns();
1371   else if ( name == "orientation" )
1372     return orientation();
1373   else if ( name == "stretch" )
1374     return stretch();
1375   else
1376     return QtxPagePrefItem::optionValue( name );
1377 }
1378
1379 /*!
1380   \brief Set preference item option value.
1381   \param name option name
1382   \param val new property value
1383   \sa optionValue()
1384 */
1385 void QtxPagePrefFrameItem::setOptionValue( const QString& name, const QVariant& val )
1386 {
1387   if ( name == "margin" )
1388   {
1389     if ( val.canConvert( QVariant::Int ) )
1390       setMargin( val.toInt() );
1391   }
1392   else if ( name == "spacing" )
1393   {
1394     if ( val.canConvert( QVariant::Int ) )
1395       setSpacing( val.toInt() );
1396   }
1397   else if ( name == "columns" )
1398   {
1399     if ( val.canConvert( QVariant::Int ) )
1400       setColumns( val.toInt() );
1401   }
1402   else if ( name == "orientation" )
1403   {
1404     if ( val.canConvert( QVariant::Int ) )
1405       setOrientation( (Qt::Orientation)val.toInt() );
1406   }
1407   else if ( name == "stretch" )
1408   {
1409     if ( val.canConvert( QVariant::Bool ) )
1410       setStretch( val.toBool() );
1411   }
1412   else
1413     QtxPagePrefItem::setOptionValue( name, val );
1414 }
1415
1416 void QtxPagePrefFrameItem::widgetShown()
1417 {
1418   QtxPagePrefItem::widgetShown();
1419
1420   QtxPageNamedPrefItem::adjustLabels( this );
1421 }
1422
1423 /*!
1424   \brief Update frame widget.
1425 */
1426 void QtxPagePrefFrameItem::updateFrame()
1427 {
1428   QList<QtxPagePrefItem*> items;
1429   pageChildItems( items );
1430
1431   for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end(); ++it )
1432   {
1433     QWidget* wid = (*it)->widget();
1434     if ( !wid )
1435       continue;
1436
1437     if ( wid->parent() != myBox )
1438       wid->setParent( myBox );
1439   }
1440 }
1441
1442 /*!
1443   \class QtxPagePrefGroupItem
1444   \brief GUI implementation of the group widget container.
1445 */
1446
1447 /*!
1448   \brief Constructor.
1449   \param title preference item title
1450   \param parent parent preference item
1451   \param sect resource file section associated with the preference item
1452   \param param resource file parameter associated with the preference item
1453 */
1454 QtxPagePrefGroupItem::QtxPagePrefGroupItem( const QString& title, QtxPreferenceItem* parent,
1455                                             const QString& sect, const QString& param )
1456 : QtxPagePrefItem( title, parent, sect, param )
1457 {
1458   myGroup = new QtxGroupBox( title, 0 );
1459   myBox = new QtxGridBox( 1, Qt::Horizontal, myGroup, 5, 5 );
1460   myGroup->setWidget( myBox );
1461
1462   setWidget( myGroup );
1463
1464   updateState();
1465 }
1466
1467 /*!
1468   \brief Constructor.
1469   \param cols columns number
1470   \param title preference item title
1471   \param parent parent preference item
1472   \param sect resource file section associated with the preference item
1473   \param param resource file parameter associated with the preference item
1474 */
1475 QtxPagePrefGroupItem::QtxPagePrefGroupItem( const int cols, const QString& title, QtxPreferenceItem* parent,
1476                                             const QString& sect, const QString& param )
1477 : QtxPagePrefItem( title, parent, sect, param )
1478 {
1479   myGroup = new QtxGroupBox( title, 0 );
1480   myBox = new QtxGridBox( cols, Qt::Horizontal, myGroup, 5, 5 );
1481   myGroup->setWidget( myBox );
1482
1483   setWidget( myGroup );
1484
1485   updateState();
1486 }
1487
1488 /*!
1489   \brief Destructor.
1490 */
1491 QtxPagePrefGroupItem::~QtxPagePrefGroupItem()
1492 {
1493 }
1494
1495 /*!
1496   \brief Assign resource file settings to the preference item.
1497   \param sect resource file section name
1498   \param param resource file parameter name
1499   \sa resource()
1500 */
1501 void QtxPagePrefGroupItem::setResource( const QString& sect, const QString& param )
1502 {
1503   QtxPagePrefItem::setResource( sect, param );
1504   updateState();
1505 }
1506
1507 /*!
1508   \brief Update widget contents.
1509 */
1510 void QtxPagePrefGroupItem::updateContents()
1511 {
1512   QtxPagePrefItem::updateContents();
1513
1514   myGroup->setTitle( title() );
1515
1516   updateState();
1517   updateGroup();
1518
1519   QtxPageNamedPrefItem::adjustLabels( this );
1520 }
1521
1522 /*!
1523   \brief Get group box margin.
1524   \return current group box margin
1525   \sa setMargin()
1526 */
1527 int QtxPagePrefGroupItem::margin() const
1528 {
1529   return myBox->insideMargin();
1530 }
1531
1532 /*!
1533   \brief Get group box margin.
1534   \param m new group box margin
1535   \sa margin()
1536 */
1537 void QtxPagePrefGroupItem::setMargin( const int m )
1538 {
1539   myBox->setInsideMargin( m );
1540 }
1541
1542 /*!
1543   \brief Get group box spacing.
1544   \return current group box spacing
1545   \sa setSpacing()
1546 */
1547 int QtxPagePrefGroupItem::spacing() const
1548 {
1549   return myBox->insideSpacing();
1550 }
1551
1552 /*!
1553   \brief Set group box spacing.
1554   \param s new group box spacing
1555   \sa spacing()
1556 */
1557 void QtxPagePrefGroupItem::setSpacing( const int s )
1558 {
1559   myBox->setInsideSpacing( s );
1560 }
1561
1562 /*!
1563   \brief Get number of group box columns.
1564   \return current columns number
1565   \sa setColumns()
1566 */
1567 int QtxPagePrefGroupItem::columns() const
1568 {
1569   return myBox->columns();
1570 }
1571
1572 /*!
1573   \brief Set number of group box columns.
1574   \param c new columns number
1575   \sa columns()
1576 */
1577 void QtxPagePrefGroupItem::setColumns( const int c )
1578 {
1579   myBox->setColumns( c );
1580 }
1581
1582 /*!
1583   \brief Get group box orientation.
1584   \return current group box orientation
1585   \sa setOrientation()
1586 */
1587 Qt::Orientation QtxPagePrefGroupItem::orientation() const
1588 {
1589   return myBox->orientation();
1590 }
1591
1592 /*!
1593   \brief Set group box orientation.
1594   \param o new group box orientation
1595   \sa orientation()
1596 */
1597 void QtxPagePrefGroupItem::setOrientation( const Qt::Orientation o )
1598 {
1599   myBox->setOrientation( o );
1600 }
1601
1602 /*!
1603   \brief Get 'flat' flag of the group box widget.
1604   \return \c true if the group box is flat
1605 */
1606 bool QtxPagePrefGroupItem::isFlat() const
1607 {
1608   return myGroup->isFlat();
1609 }
1610
1611 /*!
1612   \brief Get 'flat' flag of the group box widget.
1613   \param on if \c true the group box will be made flat
1614 */
1615 void QtxPagePrefGroupItem::setFlat( const bool on )
1616 {
1617   myGroup->setFlat( on );
1618 }
1619
1620 /*!
1621   \brief Store preference item to the resource manager.
1622   \sa retrieve()
1623 */
1624 void QtxPagePrefGroupItem::store()
1625 {
1626   if ( myGroup->isCheckable() )
1627     setBoolean( myGroup->isChecked() );
1628 }
1629
1630 /*!
1631   \brief Return widget contained grid layout of this group.
1632 */
1633 QtxGridBox* QtxPagePrefGroupItem::gridBox() const
1634 {
1635   return myBox;
1636 }
1637
1638 /*!
1639   \brief Retrieve preference item from the resource manager.
1640   \sa store()
1641 */
1642 void QtxPagePrefGroupItem::retrieve()
1643 {
1644   if ( myGroup->isCheckable() )
1645     myGroup->setChecked( getBoolean() );
1646 }
1647
1648 /*!
1649   \brief Get preference item option value.
1650   \param name option name
1651   \return property value or null QVariant if option is not set
1652   \sa setOptionValue()
1653 */
1654 QVariant QtxPagePrefGroupItem::optionValue( const QString& name ) const
1655 {
1656   if ( name == "margin" )
1657     return margin();
1658   else if ( name == "spacing" )
1659     return spacing();
1660   else if ( name == "columns" )
1661     return columns();
1662   else if ( name == "orientation" )
1663     return orientation();
1664   else if ( name == "flat" )
1665     return isFlat();
1666   else
1667     return QtxPagePrefItem::optionValue( name );
1668 }
1669
1670 /*!
1671   \brief Set preference item option value.
1672   \param name option name
1673   \param val new property value
1674   \sa optionValue()
1675 */
1676 void QtxPagePrefGroupItem::setOptionValue( const QString& name, const QVariant& val )
1677 {
1678   if ( name == "margin" )
1679   {
1680     if ( val.canConvert( QVariant::Int ) )
1681       setMargin( val.toInt() );
1682   }
1683   else if ( name == "spacing" )
1684   {
1685     if ( val.canConvert( QVariant::Int ) )
1686       setSpacing( val.toInt() );
1687   }
1688   else if ( name == "columns" )
1689   {
1690     if ( val.canConvert( QVariant::Int ) )
1691       setColumns( val.toInt() );
1692   }
1693   else if ( name == "orientation" )
1694   {
1695     if ( val.canConvert( QVariant::Int ) )
1696       setOrientation( (Qt::Orientation)val.toInt() );
1697   }
1698   else if ( name == "flat" )
1699   {
1700     if ( val.canConvert( QVariant::Bool ) )
1701       setFlat( val.toBool() );
1702   }
1703   else
1704     QtxPagePrefItem::setOptionValue( name, val );
1705 }
1706
1707 void QtxPagePrefGroupItem::widgetShown()
1708 {
1709   QtxPagePrefItem::widgetShown();
1710
1711   QtxPageNamedPrefItem::adjustLabels( this );
1712 }
1713
1714 /*!
1715   \brief Update widget state.
1716 */
1717 void QtxPagePrefGroupItem::updateState()
1718 {
1719   QString section, param;
1720   resource( section, param );
1721   myGroup->setCheckable( !title().isEmpty() && !section.isEmpty() && !param.isEmpty() );
1722 }
1723
1724 /*!
1725   \brief Update group box widget.
1726 */
1727 void QtxPagePrefGroupItem::updateGroup()
1728 {
1729   QList<QtxPagePrefItem*> items;
1730   pageChildItems( items );
1731
1732   for ( QList<QtxPagePrefItem*>::const_iterator it = items.begin(); it != items.end(); ++it )
1733   {
1734     QWidget* wid = (*it)->widget();
1735     if ( !wid )
1736       continue;
1737
1738     if ( wid->parent() != myBox )
1739       wid->setParent( myBox );
1740   }
1741 }
1742
1743 /*!
1744   \class QtxPagePrefLabelItem
1745   \brief Label item which can be used in the preferences editor dialog box.
1746 */
1747
1748 /*!
1749   \brief Constructor.
1750
1751   Creates label item with specified title.
1752
1753   \param text label text
1754   \param parent parent preference item
1755 */
1756 QtxPagePrefLabelItem::QtxPagePrefLabelItem( const QString& text, QtxPreferenceItem* parent )
1757 : QtxPagePrefItem( text, parent )
1758 {
1759   setWidget( myLabel = new QLabel( text ) );
1760 }
1761
1762 QtxPagePrefLabelItem::QtxPagePrefLabelItem( Qt::Alignment align, const QString& text, QtxPreferenceItem* parent )
1763 : QtxPagePrefItem( text, parent )
1764 {
1765   setWidget( myLabel = new QLabel( text ) );
1766   myLabel->setAlignment( align );
1767 }
1768
1769 QtxPagePrefLabelItem::~QtxPagePrefLabelItem()
1770 {
1771 }
1772
1773 void QtxPagePrefLabelItem::setTitle( const QString& text )
1774 {
1775   QtxPagePrefItem::setTitle( text );
1776
1777   if ( myLabel )
1778     myLabel->setText( text );
1779 }
1780
1781 Qt::Alignment QtxPagePrefLabelItem::alignment() const
1782 {
1783   return myLabel->alignment();
1784 }
1785
1786 void QtxPagePrefLabelItem::setAlignment( Qt::Alignment align )
1787 {
1788   myLabel->setAlignment( align );
1789 }
1790
1791 QVariant QtxPagePrefLabelItem::optionValue( const QString& name ) const
1792 {
1793   QVariant val;
1794   if ( name == "alignment" )
1795     val = (int)alignment();
1796   return val;
1797 }
1798
1799 void QtxPagePrefLabelItem::setOptionValue( const QString& name, const QVariant& val )
1800 {
1801   if ( name == "alignment" )
1802   {
1803     if ( val.canConvert( QVariant::Int ) )
1804       setAlignment( (Qt::Alignment)val.toInt() );
1805   }
1806 }
1807
1808 /*!
1809   \class QtxPagePrefSpaceItem
1810   \brief Simple spacer item which can be used in the preferences
1811   editor dialog box.
1812 */
1813
1814 /*!
1815   \brief Constructor.
1816
1817   Creates spacer item with zero width and height and expanding
1818   on both directions (by height and width).
1819
1820   \param parent parent preference item
1821 */
1822 QtxPagePrefSpaceItem::QtxPagePrefSpaceItem( QtxPreferenceItem* parent )
1823 : QtxPagePrefItem( QString(), parent )
1824 {
1825   initialize( 0, 0, 1, 1 );
1826 }
1827
1828 /*!
1829   \brief Constructor.
1830
1831   Creates spacer item with zero width and height and expanding
1832   according to the specified orientation.
1833
1834   \param o spacer orientation
1835   \param parent parent preference item
1836 */
1837 QtxPagePrefSpaceItem::QtxPagePrefSpaceItem( Qt::Orientation o, QtxPreferenceItem* parent )
1838 : QtxPagePrefItem( QString(), parent )
1839 {
1840   if ( o == Qt::Horizontal )
1841     initialize( 0, 0, 1, 0 );
1842   else
1843     initialize( 0, 0, 0, 1 );
1844 }
1845
1846 /*!
1847   \brief Constructor.
1848
1849   Creates spacer item with specified width and height. The spacing
1850   item is expanding horizontally if \a w <= 0 and vertically
1851   if \a h <= 0.
1852
1853   \param w spacer width
1854   \param h spacer height
1855   \param parent parent preference item
1856 */
1857 QtxPagePrefSpaceItem::QtxPagePrefSpaceItem( const int w, const int h, QtxPreferenceItem* parent )
1858 : QtxPagePrefItem( QString(), parent )
1859 {
1860   initialize( w, h, w > 0 ? 0 : 1, h > 0 ? 0 : 1 );
1861 }
1862
1863 /*!
1864   \brief Destructor.
1865 */
1866 QtxPagePrefSpaceItem::~QtxPagePrefSpaceItem()
1867 {
1868 }
1869
1870 /*!
1871   \brief Get spacer item size for the specified direction.
1872   \param o direction
1873   \return size for the specified direction
1874   \sa setSize()
1875 */
1876 int QtxPagePrefSpaceItem::size( Qt::Orientation o ) const
1877 {
1878   return o == Qt::Horizontal ? widget()->minimumWidth() : widget()->minimumHeight();
1879 }
1880
1881 /*!
1882   \brief Set spacer item size for the specified direction.
1883   \param o direction
1884   \param sz new size for the specified direction
1885   \sa size()
1886 */
1887 void QtxPagePrefSpaceItem::setSize( Qt::Orientation o, const int sz )
1888 {
1889   if ( o == Qt::Horizontal )
1890     widget()->setMinimumWidth( sz );
1891   else
1892     widget()->setMinimumHeight( sz );
1893 }
1894
1895 /*!
1896   \brief Get spacer item stretch factor for the specified direction.
1897   \param o direction
1898   \return stretch factor for the specified direction
1899   \sa setStretch()
1900 */
1901 int QtxPagePrefSpaceItem::stretch( Qt::Orientation o ) const
1902 {
1903   QSizePolicy sp = widget()->sizePolicy();
1904   return o == Qt::Horizontal ? sp.horizontalStretch() : sp.verticalStretch();
1905 }
1906
1907 /*!
1908   \brief Set spacer item stretch factor for the specified direction.
1909   \param o direction
1910   \param sf new stretch factor for the specified direction
1911   \sa stretch()
1912 */
1913 void QtxPagePrefSpaceItem::setStretch( Qt::Orientation o, const int sf )
1914 {
1915   QSizePolicy sp = widget()->sizePolicy();
1916   if ( o == Qt::Horizontal )
1917   {
1918     sp.setHorizontalStretch( sf );
1919     sp.setHorizontalPolicy( sf > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed );
1920   }
1921   else
1922   {
1923     sp.setVerticalStretch( sf );
1924     sp.setVerticalPolicy( sf > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed );
1925   }
1926
1927   widget()->setSizePolicy( sp );
1928 }
1929
1930 /*!
1931   \brief Get preference item option value.
1932   \param name option name
1933   \return property value or null QVariant if option is not set
1934   \sa setOptionValue()
1935 */
1936 QVariant QtxPagePrefSpaceItem::optionValue( const QString& name ) const
1937 {
1938   if ( name == "horizontal_size" || name == "hsize" )
1939     return size( Qt::Horizontal );
1940   else if ( name == "vertical_size" || name == "vsize" )
1941     return size( Qt::Vertical );
1942   else if ( name == "horizontal_stretch" || name == "hstretch" )
1943     return stretch( Qt::Horizontal );
1944   else if ( name == "vertical_stretch" || name == "vstretch" )
1945     return stretch( Qt::Vertical );
1946   else
1947     return QtxPagePrefItem::optionValue( name );
1948 }
1949
1950 /*!
1951   \brief Set preference item option value.
1952   \param name option name
1953   \param val new property value
1954   \sa optionValue()
1955 */
1956 void QtxPagePrefSpaceItem::setOptionValue( const QString& name, const QVariant& val )
1957 {
1958   if ( name == "horizontal_size" || name == "hsize" )
1959   {
1960     if ( val.canConvert( QVariant::Int ) )
1961       setSize( Qt::Horizontal, val.toInt() );
1962   }
1963   else if ( name == "vertical_size" || name == "vsize" )
1964   {
1965     if ( val.canConvert( QVariant::Int ) )
1966       setSize( Qt::Vertical, val.toInt() );
1967   }
1968   else if ( name == "horizontal_stretch" || name == "hstretch" )
1969   {
1970     if ( val.canConvert( QVariant::Int ) )
1971       setStretch( Qt::Horizontal, val.toInt() );
1972   }
1973   else if ( name == "vertical_stretch" || name == "vstretch" )
1974   {
1975     if ( val.canConvert( QVariant::Int ) )
1976       setStretch( Qt::Vertical, val.toInt() );
1977   }
1978   else
1979     QtxPagePrefItem::setOptionValue( name, val );
1980 }
1981
1982 /*!
1983   \brief Perform internal initialization.
1984   \param w spacer item width
1985   \param h spacer item height
1986   \param ws spacer item horizontal stretch factor
1987   \param hs spacer item vertical stretch factor
1988 */
1989 void QtxPagePrefSpaceItem::initialize( const int w, const int h, const int hs, const int vs )
1990 {
1991   QSizePolicy sp;
1992   sp.setHorizontalPolicy( hs > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed );
1993   sp.setVerticalPolicy( vs > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed );
1994
1995   sp.setHorizontalStretch( hs );
1996   sp.setVerticalStretch( vs );
1997
1998   QWidget* wid = new QWidget();
1999   wid->setSizePolicy( sp );
2000
2001   wid->setMinimumSize( w, h );
2002
2003   setWidget( wid );
2004 }
2005
2006 /*!
2007   \class  QtxPagePrefCheckItem
2008   \brief GUI implementation of the resources check box item (boolean).
2009 */
2010
2011 /*!
2012   \brief Constructor.
2013   \param title preference item title
2014   \param parent parent preference item
2015   \param sect resource file section associated with the preference item
2016   \param param resource file parameter associated with the preference item
2017 */
2018 QtxPagePrefCheckItem::QtxPagePrefCheckItem( const QString& title, QtxPreferenceItem* parent,
2019                                             const QString& sect, const QString& param )
2020
2021 : QtxPagePrefItem( title, parent, sect, param )
2022 {
2023   myCheck = new QCheckBox( title );
2024   myCheck->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
2025   setWidget( myCheck );
2026 }
2027
2028 /*!
2029   \brief Destructor.
2030 */
2031 QtxPagePrefCheckItem::~QtxPagePrefCheckItem()
2032 {
2033 }
2034
2035 /*!
2036   \brief Set preference item title.
2037   \param txt new preference title.
2038 */
2039 void QtxPagePrefCheckItem::setTitle( const QString& txt )
2040 {
2041   QtxPagePrefItem::setTitle( txt );
2042
2043   myCheck->setText( title() );
2044 }
2045
2046 /*!
2047   \brief Store preference item to the resource manager.
2048   \sa retrieve()
2049 */
2050 void QtxPagePrefCheckItem::store()
2051 {
2052   setBoolean( myCheck->isChecked() );
2053 }
2054
2055 /*!
2056   \brief Retrieve preference item from the resource manager.
2057   \sa store()
2058 */
2059 void QtxPagePrefCheckItem::retrieve()
2060 {
2061   myCheck->setChecked( getBoolean() );
2062 }
2063
2064 /*!
2065   \class QtxPagePrefEditItem
2066   \brief GUI implementation of the resources line edit box item
2067   for string, integer and double values.
2068 */
2069
2070 static void fixupAndSet( QLineEdit* le, const QString& txt )
2071 {
2072   if ( le ) {
2073     QString val = txt;
2074     if ( le->validator() ) {
2075       const QDoubleValidator* de = dynamic_cast<const QDoubleValidator*>( le->validator() );
2076       if ( de ) {
2077         int dec = de->decimals();
2078         int idx = val.lastIndexOf( QRegExp( QString("[.|%1]").arg( le->locale().decimalPoint () ) ) );
2079         if ( idx >= 0 ) {
2080           QString tmp = val.mid( idx+1 );
2081           QString exp;
2082           val = val.left( idx+1 );
2083           idx = tmp.indexOf( QRegExp( QString("[e|E]") ) );
2084           if ( idx >= 0 ) {
2085             exp = tmp.mid( idx );
2086             tmp = tmp.left( idx );
2087           }
2088           tmp.truncate( dec );
2089           val = val + tmp + exp;
2090         }
2091       }
2092       int pos = 0;
2093       if ( le->validator()->validate( val, pos ) == QValidator::Invalid )
2094         val.clear();
2095     }
2096     le->setText( val );
2097   }
2098 }
2099
2100 /*!
2101   \brief Constructor.
2102
2103   Creates preference item for string value editing.
2104
2105   \param title preference item title
2106   \param parent parent preference item
2107   \param sect resource file section associated with the preference item
2108   \param param resource file parameter associated with the preference item
2109 */
2110 QtxPagePrefEditItem::QtxPagePrefEditItem( const QString& title, QtxPreferenceItem* parent,
2111                                           const QString& sect, const QString& param )
2112 : QtxPageNamedPrefItem( title, parent, sect, param ),
2113   myType( String ),
2114   myDecimals( 1000 ),
2115   myEchoMode( 0 )
2116 {
2117   setControl( myEditor = new QLineEdit() );
2118   updateEditor();
2119 }
2120
2121 /*!
2122   \brief Constructor.
2123
2124   Creates preference item for editing of the value which type
2125   is specified by parameter \a type.
2126
2127   \param type preference item input type (QtxPagePrefEditItem::InputType)
2128   \param title preference item title
2129   \param parent parent preference item
2130   \param sect resource file section associated with the preference item
2131   \param param resource file parameter associated with the preference item
2132 */
2133 QtxPagePrefEditItem::QtxPagePrefEditItem( const int type, const QString& title,
2134                                           QtxPreferenceItem* parent, const QString& sect,
2135                                           const QString& param )
2136 : QtxPageNamedPrefItem( title, parent, sect, param ),
2137   myType( type ),
2138   myDecimals( 1000 ),
2139   myEchoMode( 0 )
2140 {
2141   setControl( myEditor = new QLineEdit() );
2142   updateEditor();
2143 }
2144
2145 /*!
2146   \brief Destructor.
2147 */
2148 QtxPagePrefEditItem::~QtxPagePrefEditItem()
2149 {
2150 }
2151
2152 /*!
2153   \brief Get edit box preference item input type.
2154   \return preference item input type (QtxPagePrefEditItem::InputType)
2155   \sa setInputType()
2156 */
2157 int QtxPagePrefEditItem::inputType() const
2158 {
2159   return myType;
2160 }
2161
2162 /*!
2163   \brief Set edit box preference item input type.
2164   \param type new preference item input type (QtxPagePrefEditItem::InputType)
2165   \sa inputType()
2166 */
2167 void QtxPagePrefEditItem::setInputType( const int type )
2168 {
2169   if ( myType == type )
2170     return;
2171
2172   myType = type;
2173   updateEditor();
2174 }
2175
2176 /*!
2177   \brief Get number of digits after decimal point (for Double input type)
2178   \return preference item decimals value
2179   \sa setDecimals()
2180 */
2181 int QtxPagePrefEditItem::decimals() const
2182 {
2183   return myDecimals;
2184 }
2185
2186 /*!
2187   \brief Set number of digits after decimal point (for Double input type)
2188   \param dec new preference item decimals value
2189   \sa decimals()
2190 */
2191 void QtxPagePrefEditItem::setDecimals( const int dec )
2192 {
2193   if ( myDecimals == dec )
2194     return;
2195   
2196   myDecimals = dec;
2197   updateEditor();
2198 }
2199
2200 /*!
2201   \brief Get the line edit's echo mode
2202   \return preference item echo mode value
2203   \sa setEchoMode()
2204 */
2205 int QtxPagePrefEditItem::echoMode() const
2206 {
2207   return myEchoMode;
2208 }
2209
2210 /*!
2211   \brief Set the line edit's echo mode
2212   \param echo new preference item echo mode value
2213   \sa echoMode()
2214 */
2215 void QtxPagePrefEditItem::setEchoMode( const int echo )
2216 {   
2217   if ( myEchoMode == echo )
2218     return;
2219   
2220   myEchoMode = echo;
2221   updateEditor();
2222 }
2223
2224 /*!
2225   \brief Store preference item to the resource manager.
2226   \sa retrieve()
2227 */
2228 void QtxPagePrefEditItem::store()
2229 {
2230   setString( myEditor->text() );
2231 }
2232
2233 /*!
2234   \brief Retrieve preference item from the resource manager.
2235   \sa store()
2236 */
2237 void QtxPagePrefEditItem::retrieve()
2238 {
2239   QString txt = getString();
2240   fixupAndSet( myEditor, txt );
2241 }
2242
2243 /*!
2244   \brief Get preference item option value.
2245   \param name option name
2246   \return property value or null QVariant if option is not set
2247   \sa setOptionValue()
2248 */
2249 QVariant QtxPagePrefEditItem::optionValue( const QString& name ) const
2250 {
2251   if ( name == "input_type" || name == "type" )
2252     return inputType();
2253   else if ( name == "precision" || name == "prec" || name == "decimals" )
2254     return decimals();
2255   else if ( name == "echo" || name == "echo_mode" || name == "echomode")
2256     return echoMode();
2257   else
2258     return QtxPageNamedPrefItem::optionValue( name );
2259 }
2260
2261 /*!
2262   \brief Set preference item option value.
2263   \param name option name
2264   \param val new property value
2265   \sa optionValue()
2266 */
2267 void QtxPagePrefEditItem::setOptionValue( const QString& name, const QVariant& val )
2268 {
2269   if ( name == "input_type" || name == "type" )
2270   {
2271     if ( val.canConvert( QVariant::Int ) )
2272       setInputType( val.toInt() );
2273   }
2274   else if ( name == "precision" || name == "prec" || name == "decimals" ) {
2275     if ( val.canConvert( QVariant::Int ) )
2276       setDecimals( val.toInt() );
2277   }
2278   else if ( name == "echo" || name == "echo_mode" || name == "echomode") {
2279     if ( val.canConvert( QVariant::Int ) )
2280       setEchoMode( val.toInt() );
2281   }
2282   else
2283     QtxPageNamedPrefItem::setOptionValue( name, val );
2284 }
2285
2286 /*!
2287   \brief Update edit box widget.
2288 */
2289 void QtxPagePrefEditItem::updateEditor()
2290 {
2291   switch (myEchoMode)
2292   {
2293     case 0:
2294       myEditor->setEchoMode(QLineEdit::Normal);
2295       break;
2296     case 1:
2297       myEditor->setEchoMode(QLineEdit::NoEcho);
2298       break;
2299     case 2:
2300       myEditor->setEchoMode(QLineEdit::Password);
2301       break;
2302     case 3:
2303       myEditor->setEchoMode(QLineEdit::PasswordEchoOnEdit);
2304       break;
2305     default:
2306       myEditor->setEchoMode(QLineEdit::Normal);
2307   }
2308   
2309   QValidator* val = 0;
2310   switch ( inputType() )
2311   {
2312   case Integer:
2313     val = new QIntValidator( myEditor );
2314     break;
2315   case Double:
2316     val = new QDoubleValidator( myEditor );
2317     dynamic_cast<QDoubleValidator*>( val )->setDecimals( myDecimals < 0 ? 1000 : myDecimals );
2318     break;
2319   default:
2320     break;
2321   }
2322
2323   QString txt = myEditor->text();
2324   delete myEditor->validator();
2325   myEditor->setValidator( val );
2326   fixupAndSet( myEditor, txt );
2327 }
2328
2329 /*!
2330   \class QtxPagePrefSliderItem
2331 */
2332
2333 /*!
2334   \brief Constructor.
2335
2336   Creates preference item with slider widget
2337
2338   \param title preference item title
2339   \param parent parent preference item
2340   \param sect resource file section associated with the preference item
2341   \param param resource file parameter associated with the preference item
2342 */
2343 QtxPagePrefSliderItem::QtxPagePrefSliderItem( const QString& title, QtxPreferenceItem* parent,
2344                                               const QString& sect, const QString& param )
2345 : QtxPageNamedPrefItem( title, parent, sect, param )
2346 {
2347   setControl( mySlider = new QSlider( Qt::Horizontal ) );
2348   widget()->layout()->addWidget( myLabel = new QLabel( ) );
2349     
2350   setMinimum( 0 );
2351   setMaximum( 0 );
2352   setSingleStep( 1 );
2353   setPageStep( 1 );
2354   
2355   mySlider->setTickPosition( QSlider::TicksBothSides );
2356   
2357   connect (mySlider, SIGNAL(valueChanged(int)), this, SLOT(setIcon(int)));
2358   updateSlider();
2359 }
2360
2361 /*!
2362   \brief Destructor.
2363 */
2364 QtxPagePrefSliderItem::~QtxPagePrefSliderItem()
2365 {
2366 }
2367
2368 /*!
2369   \brief Get slider preference item step value.
2370   \return slider single step value
2371   \sa setSingleStep()
2372 */
2373 int QtxPagePrefSliderItem::singleStep() const
2374 {
2375   return mySlider->singleStep();
2376 }
2377
2378 /*!
2379   \brief Get slider preference item step value.
2380   \return slider page step value
2381   \sa setPageStep()
2382 */
2383 int QtxPagePrefSliderItem::pageStep() const
2384 {
2385   return mySlider->pageStep();
2386 }
2387
2388 /*!
2389   \brief Get slider preference item minimum value.
2390   \return slider minimum value
2391   \sa setMinimum()
2392 */
2393 int QtxPagePrefSliderItem::minimum() const
2394 {
2395     return mySlider->minimum();
2396 }
2397
2398 /*!
2399   \brief Get slider preference item maximum value.
2400   \return slider maximum value
2401   \sa setMaximum()
2402 */
2403 int QtxPagePrefSliderItem::maximum() const
2404 {
2405     return mySlider->maximum();
2406 }
2407
2408 /*!
2409   \brief Get the list of the icons associated with the selection widget items
2410   \return list of icons
2411   \sa setIcons()
2412 */
2413 QList<QIcon> QtxPagePrefSliderItem::icons() const
2414 {
2415   return myIcons;
2416 }
2417
2418 /*!
2419   \brief Set slider preference item step value.
2420   \param step new slider single step value
2421   \sa step()
2422 */
2423 void QtxPagePrefSliderItem::setSingleStep( const int& step )
2424 {
2425   mySlider->setSingleStep( step );
2426 }
2427
2428 /*!
2429   \brief Set slider preference item step value.
2430   \param step new slider single step value
2431   \sa step()
2432 */
2433 void QtxPagePrefSliderItem::setPageStep( const int& step )
2434 {
2435   mySlider->setPageStep( step );
2436 }
2437
2438 /*!
2439   \brief Set slider preference item minimum value.
2440   \param min new slider minimum value
2441   \sa minimum()
2442 */
2443 void QtxPagePrefSliderItem::setMinimum( const int& min )
2444 {
2445   mySlider->setMinimum( min );
2446   setIcon( mySlider->value() );
2447 }
2448
2449 /*!
2450   \brief Set slider preference item maximum value.
2451   \param max new slider maximum value
2452   \sa maximum()
2453 */
2454 void QtxPagePrefSliderItem::setMaximum( const int& max )
2455 {
2456   mySlider->setMaximum( max );
2457   setIcon( mySlider->value() );
2458 }
2459
2460 /*!
2461   \brief Set the list of the icons to the selection widget items
2462   \param icns new list of icons
2463   \sa icons()
2464 */
2465 void QtxPagePrefSliderItem::setIcons( const QList<QIcon>& icns )
2466 {
2467   if ( icns.isEmpty() ) 
2468     return;
2469   myIcons = icns;
2470   
2471   QSize maxsize(0, 0); 
2472   for ( QList<QIcon>::const_iterator it = myIcons.begin(); it != myIcons.end(); ++it ) {
2473     if ( (*it).isNull() ) continue;
2474     maxsize = maxsize.expandedTo( (*it).availableSizes().first() );
2475   }
2476   myLabel->setFixedSize( maxsize );
2477   
2478   updateSlider();
2479 }
2480
2481 /*!
2482   \brief Store preference item to the resource manager.
2483   \sa retrieve()
2484 */
2485 void QtxPagePrefSliderItem::store()
2486 {
2487   setInteger( mySlider->value() );
2488 }
2489
2490 /*!
2491   \brief Retrieve preference item from the resource manager.
2492   \sa store()
2493 */
2494 void QtxPagePrefSliderItem::retrieve()
2495 {
2496   mySlider->setValue( getInteger( mySlider->value() ) );
2497 }
2498
2499 /*!
2500   \brief Get preference item option value.
2501   \param name option name
2502   \return property value or null integer if option is not set
2503   \sa setOptionValue()
2504 */
2505 QVariant QtxPagePrefSliderItem::optionValue( const QString& name ) const
2506 {
2507   if ( name == "minimum" || name == "min" )
2508     return minimum();
2509   else if ( name == "maximum" || name == "max" )
2510     return maximum();
2511   else if ( name == "single_step" )
2512     return singleStep();
2513   else if ( name == "page_step" )
2514     return pageStep();
2515   else if ( name == "icons" || name == "pixmaps" )
2516   {
2517     QList<QVariant> lst;
2518     QList<QIcon> ics = icons();
2519     for ( QList<QIcon>::const_iterator it = ics.begin(); it != ics.end(); ++it )
2520       lst.append( *it );
2521     return lst;
2522   }
2523   else
2524     return QtxPageNamedPrefItem::optionValue( name );
2525 }
2526
2527 /*!
2528   \brief Set preference item option value.
2529   \param name option name
2530   \param val new property value
2531   \sa optionValue()
2532 */
2533 void QtxPagePrefSliderItem::setOptionValue( const QString& name, const QVariant& val )
2534 {
2535   if ( val.canConvert( QVariant::Int ) )
2536   {
2537     if ( name == "minimum" || name == "min" )
2538       setMinimum( val.toInt() );
2539     else if ( name == "maximum" || name == "max" )
2540       setMaximum( val.toInt() );
2541     else if ( name == "single_step" )
2542       setSingleStep( val.toInt() );
2543     else if ( name == "page_step" )
2544       setPageStep( val.toInt() );
2545     else
2546       QtxPageNamedPrefItem::setOptionValue( name, val );
2547   }
2548   else if ( name == "icons" || name == "pixmaps" )
2549     setIcons( val );
2550   else
2551     QtxPageNamedPrefItem::setOptionValue( name, val );
2552 }
2553
2554 void QtxPagePrefSliderItem::setIcon( int pos )
2555 {
2556   int index = pos - mySlider->minimum();
2557   if ( !myIcons.isEmpty() && index >= 0 && index < myIcons.size() && !myIcons[index].isNull() )
2558     myLabel->setPixmap( myIcons[index].pixmap( myIcons[index].availableSizes().first() ) );
2559   else
2560     myLabel->clear();
2561 }
2562
2563 /*!
2564   \brief Update slider widget.
2565 */
2566 void QtxPagePrefSliderItem::updateSlider()
2567 {
2568   int val = mySlider->value();
2569   int stp = singleStep();
2570   int ptp = pageStep();
2571   int min = minimum();
2572   int max = maximum();
2573
2574   control()->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
2575   mySlider->setFocusPolicy(Qt::StrongFocus);
2576   
2577   mySlider->setValue( val );
2578   setSingleStep( stp );
2579   setPageStep( ptp );
2580   setMinimum( min );
2581   setMaximum( max );
2582   
2583   myLabel->setVisible( !myIcons.empty() );
2584   widget()->layout()->setSpacing( !myIcons.empty() ? 6 : 0 );
2585 }
2586
2587 /*!
2588   \brief Set the list of the icons from the resource manager.
2589   \param var new icons list
2590   \internal
2591 */
2592 void  QtxPagePrefSliderItem::setIcons( const QVariant& var )
2593 {
2594   if ( var.type() != QVariant::List )
2595     return;
2596
2597   QList<QIcon> lst;
2598   QList<QVariant> varList = var.toList();
2599   for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it )
2600   {
2601     if ( (*it).canConvert<QIcon>() )
2602       lst.append( (*it).value<QIcon>() );
2603     else if ( (*it).canConvert<QPixmap>() )
2604       lst.append( (*it).value<QPixmap>() );
2605     else
2606       lst.append( QIcon() );
2607   }
2608   setIcons( lst );
2609 }
2610
2611 /*!
2612   \class QtxPagePrefSelectItem
2613   \brief GUI implementation of the resources selector item
2614   (string, integer or double values list).
2615
2616   All items in the list (represented as combo box) should be specified
2617   by the unique identifier which is stored to the resource file instead
2618   of the value itself.
2619 */
2620
2621 /*!
2622   \brief Constructor.
2623
2624   Creates preference item with combo box widget which is not editable
2625   (direct value entering is disabled).
2626
2627   \param title preference item title
2628   \param parent parent preference item
2629   \param sect resource file section associated with the preference item
2630   \param param resource file parameter associated with the preference item
2631 */
2632 QtxPagePrefSelectItem::QtxPagePrefSelectItem( const QString& title, QtxPreferenceItem* parent,
2633                                               const QString& sect, const QString& param )
2634 : QtxPageNamedPrefItem( title, parent, sect, param ),
2635   myType( NoInput )
2636 {
2637   setControl( mySelector = new QtxComboBox() );
2638   mySelector->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
2639   mySelector->setDuplicatesEnabled( false );
2640   updateSelector();
2641 }
2642
2643 /*!
2644   \brief Constructor.
2645
2646   Creates preference item with combo box widget which is editable
2647   according to the specified input type (integer, double or string values).
2648
2649   \param type input type (QtxPagePrefSelectItem::InputType)
2650   \param title preference item title
2651   \param parent parent preference item
2652   \param sect resource file section associated with the preference item
2653   \param param resource file parameter associated with the preference item
2654 */
2655 QtxPagePrefSelectItem::QtxPagePrefSelectItem( const int type, const QString& title, QtxPreferenceItem* parent,
2656                                               const QString& sect, const QString& param )
2657 : QtxPageNamedPrefItem( title, parent, sect, param ),
2658   myType( type )
2659 {
2660   setControl( mySelector = new QtxComboBox() );
2661   mySelector->setDuplicatesEnabled( false );
2662   updateSelector();
2663 }
2664
2665 /*!
2666   \brief Destructor.
2667 */
2668 QtxPagePrefSelectItem::~QtxPagePrefSelectItem()
2669 {
2670 }
2671
2672 /*!
2673   \brief Get edit box preference item input type.
2674   \return preference item input type (QtxPagePrefSelectItem::InputType)
2675   \sa setInputType()
2676 */
2677 int QtxPagePrefSelectItem::inputType() const
2678 {
2679   return myType;
2680 }
2681
2682 /*!
2683   \brief Set edit box preference item input type.
2684   \param type new preference item input type (QtxPagePrefSelectItem::InputType)
2685   \sa inputType()
2686 */
2687 void QtxPagePrefSelectItem::setInputType( const int type )
2688 {
2689   if ( myType == type )
2690     return;
2691
2692   myType = type;
2693   updateSelector();
2694 }
2695
2696 /*!
2697   \brief Get the list of the values from the selection widget.
2698   \return list of values
2699   \sa numbers(), icons(), setStrings()
2700 */
2701 QStringList QtxPagePrefSelectItem::strings() const
2702 {
2703   QStringList res;
2704   for ( uint i = 0; i < mySelector->count(); i++ )
2705     res.append( mySelector->itemText( i ) );
2706   return res;
2707 }
2708
2709 /*!
2710   \brief Get the list of the values identifiers from the selection widget.
2711   \return list of values IDs
2712   \sa strings(), icons(), setNumbers()
2713 */
2714 QList<int> QtxPagePrefSelectItem::numbers() const
2715 {
2716   QList<int> res;
2717   for ( uint i = 0; i < mySelector->count(); i++ )
2718   {
2719     if ( mySelector->hasId( i ) )
2720       res.append( mySelector->id( i ) );
2721   }
2722   return res;
2723 }
2724
2725 /*!
2726   \brief Get the list of the icons associated with the selection widget.items
2727   \return list of icons
2728   \sa strings(), numbers(), setIcons()
2729 */
2730 QList<QIcon> QtxPagePrefSelectItem::icons() const
2731 {
2732   QList<QIcon> res;
2733   for ( uint i = 0; i < mySelector->count(); i++ )
2734     res.append( mySelector->itemIcon( i ) );
2735   return res;
2736 }
2737
2738 /*!
2739   \brief Set the list of the values to the selection widget.
2740   \param lst new list of values
2741   \sa strings(), setNumbers(), setIcons()
2742 */
2743 void QtxPagePrefSelectItem::setStrings( const QStringList& lst )
2744 {
2745   mySelector->clear();
2746   mySelector->addItems( lst );
2747 }
2748
2749 /*!
2750   \brief Set the list of the values identifiers to the selection widget
2751   \param ids new list of values IDs
2752   \sa numbers(), setStrings(), setIcons()
2753 */
2754 void QtxPagePrefSelectItem::setNumbers( const QList<int>& ids )
2755 {
2756   uint i = 0;
2757   for ( QList<int>::const_iterator it = ids.begin(); it != ids.end(); ++it, i++ ) {
2758     if ( i >= mySelector->count() )
2759       mySelector->addItem(QString("") );
2760     
2761     mySelector->setId( i, *it );
2762   }
2763 }
2764
2765 /*!
2766   \brief Set the list of the icons to the selection widget items
2767
2768   Important: call this method after setStrings() or setNumbers()
2769
2770   \param icns new list of icons
2771   \sa icons(), setStrings(), setNumbers()
2772 */
2773 void QtxPagePrefSelectItem::setIcons( const QList<QIcon>& icns )
2774 {
2775   uint i = 0;
2776   for ( QList<QIcon>::const_iterator it = icns.begin(); it != icns.end() && i < mySelector->count(); ++it, i++ )
2777     mySelector->setItemIcon( i, *it );
2778 }
2779
2780 /*!
2781   \brief Store preference item to the resource manager.
2782   \sa retrieve()
2783 */
2784 void QtxPagePrefSelectItem::store()
2785 {
2786   if ( mySelector->isCleared() )
2787     return;
2788
2789   int idx = mySelector->currentIndex();
2790
2791   if ( mySelector->hasId( idx ) )
2792     setInteger( mySelector->id( idx ) );
2793   else if ( idx >= 0 )
2794     setString( mySelector->itemText( idx ) );
2795 }
2796
2797 /*!
2798   \brief Retrieve preference item from the resource manager.
2799   \sa store()
2800 */
2801 void QtxPagePrefSelectItem::retrieve()
2802 {
2803   QString txt = getString();
2804
2805   int idx = -1;
2806
2807   bool ok = false;
2808   int num = txt.toInt( &ok );
2809   if ( ok )
2810     idx = mySelector->index( num );
2811   else
2812   {
2813     for ( uint i = 0; i < mySelector->count() && idx == -1; i++ )
2814     {
2815       if ( mySelector->itemText( i ) == txt )
2816         idx = i;
2817     }
2818   }
2819
2820   if ( idx != -1 )
2821     mySelector->setCurrentIndex( idx );
2822   else if ( mySelector->isEditable() )
2823   {
2824     int pos = 0;
2825     if ( mySelector->validator() &&
2826          mySelector->validator()->validate( txt, pos ) == QValidator::Invalid )
2827       mySelector->setCleared( true );
2828     else
2829     {
2830       mySelector->setCleared( false );
2831       mySelector->addItem( txt );
2832       mySelector->setCurrentIndex( mySelector->count() - 1 );
2833     }
2834   }
2835 }
2836
2837 /*!
2838   \brief Get preference item option value.
2839   \param name option name
2840   \return property value or null QVariant if option is not set
2841   \sa setOptionValue()
2842 */
2843 QVariant QtxPagePrefSelectItem::optionValue( const QString& name ) const
2844 {
2845   if ( name == "input_type" || name == "type" )
2846     return inputType();
2847   else if ( name == "strings" || name == "labels" )
2848     return strings();
2849   else if ( name == "numbers" || name == "ids" || name == "indexes" )
2850   {
2851     QList<QVariant> lst;
2852     QList<int> nums = numbers();
2853     for ( QList<int>::const_iterator it = nums.begin(); it != nums.end(); ++it )
2854       lst.append( *it );
2855     return lst;
2856   }
2857   else if ( name == "icons" || name == "pixmaps" )
2858   {
2859     QList<QVariant> lst;
2860     QList<QIcon> ics = icons();
2861     for ( QList<QIcon>::const_iterator it = ics.begin(); it != ics.end(); ++it )
2862       lst.append( *it );
2863     return lst;
2864   }
2865   else
2866     return QtxPageNamedPrefItem::optionValue( name );
2867 }
2868
2869 /*!
2870   \brief Set preference item option value.
2871   \param name option name
2872   \param val new property value
2873   \sa optionValue()
2874 */
2875 void QtxPagePrefSelectItem::setOptionValue( const QString& name, const QVariant& val )
2876 {
2877   if ( name == "input_type" || name == "type" )
2878   {
2879     if ( val.canConvert( QVariant::Int ) )
2880       setInputType( val.toInt() );
2881   }
2882   else if ( name == "strings" || name == "labels" )
2883     setStrings( val );
2884   else if ( name == "numbers" || name == "ids" || name == "indexes" )
2885     setNumbers( val );
2886   else if ( name == "icons" || name == "pixmaps" )
2887     setIcons( val );
2888   else
2889     QtxPageNamedPrefItem::setOptionValue( name, val );
2890 }
2891
2892 /*!
2893   \brief Set the list of the values from the resource manager.
2894   \param var new values list
2895   \internal
2896 */
2897 void QtxPagePrefSelectItem::setStrings( const QVariant& var )
2898 {
2899   if ( var.type() != QVariant::StringList )
2900     return;
2901
2902   setStrings( var.toStringList() );
2903 }
2904
2905 /*!
2906   \brief Set the list of the values identifiers from the resource manager.
2907   \param var new values IDs list
2908   \internal
2909 */
2910 void QtxPagePrefSelectItem::setNumbers( const QVariant& var )
2911 {
2912   if ( var.type() != QVariant::List )
2913     return;
2914
2915   QList<int> lst;
2916   QList<QVariant> varList = var.toList();
2917   for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it )
2918   {
2919     if ( (*it).canConvert( QVariant::Int ) )
2920       lst.append( (*it).toInt() );
2921   }
2922   setNumbers( lst );
2923 }
2924
2925 /*!
2926   \brief Set the list of the icons from the resource manager.
2927   \param var new icons list
2928   \internal
2929 */
2930 void QtxPagePrefSelectItem::setIcons( const QVariant& var )
2931 {
2932   if ( var.type() != QVariant::List )
2933     return;
2934
2935   QList<QIcon> lst;
2936   QList<QVariant> varList = var.toList();
2937   for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it )
2938   {
2939     if ( (*it).canConvert<QIcon>() )
2940       lst.append( (*it).value<QIcon>() );
2941     else if ( (*it).canConvert<QPixmap>() )
2942       lst.append( (*it).value<QPixmap>() );
2943     else
2944       lst.append( QIcon() );
2945   }
2946   setIcons( lst );
2947 }
2948
2949 /*!
2950   \brief Update selector widget.
2951 */
2952 void QtxPagePrefSelectItem::updateSelector()
2953 {
2954   QValidator* val = 0;
2955   switch ( inputType() )
2956   {
2957   case Integer:
2958     val = new QIntValidator( mySelector );
2959     break;
2960   case Double:
2961     val = new QDoubleValidator( mySelector );
2962     break;
2963   default:
2964     break;
2965   }
2966
2967   mySelector->setEditable( inputType() != NoInput );
2968
2969   if ( mySelector->isEditable() && !mySelector->currentText().isEmpty() && val )
2970   {
2971     int pos = 0;
2972     QString str = mySelector->currentText();
2973     if ( val->validate( str, pos ) == QValidator::Invalid )
2974       mySelector->clearEditText();
2975   }
2976
2977   delete mySelector->validator();
2978   mySelector->setValidator( val );
2979 }
2980
2981 /*!
2982   \class QtxPagePrefSpinItem
2983   \brief GUI implementation of the resources spin box item
2984   (for integer or double value).
2985 */
2986
2987 /*!
2988   \brief Constructor.
2989
2990   Creates spin box preference item for the entering integer values.
2991
2992   \param title preference item title
2993   \param parent parent preference item
2994   \param sect resource file section associated with the preference item
2995   \param param resource file parameter associated with the preference item
2996 */
2997 QtxPagePrefSpinItem::QtxPagePrefSpinItem( const QString& title, QtxPreferenceItem* parent,
2998                                           const QString& sect, const QString& param )
2999 : QtxPageNamedPrefItem( title, parent, sect, param ),
3000   myType( Integer )
3001 {
3002   updateSpinBox();
3003 }
3004
3005 /*!
3006   \brief Constructor.
3007
3008   Creates spin box preference item for the entering values which type
3009   is specified by the parameter \a type.
3010
3011   \param type input type (QtxPagePrefSpinItem::InputType).
3012   \param title preference item title
3013   \param parent parent preference item
3014   \param sect resource file section associated with the preference item
3015   \param param resource file parameter associated with the preference item
3016 */
3017 QtxPagePrefSpinItem::QtxPagePrefSpinItem( const int type, const QString& title,
3018                                           QtxPreferenceItem* parent, const QString& sect,
3019                                           const QString& param )
3020 : QtxPageNamedPrefItem( title, parent, sect, param ),
3021   myType( type )
3022 {
3023   updateSpinBox();
3024 }
3025
3026 /*!
3027   \brief Destructor.
3028 */
3029 QtxPagePrefSpinItem::~QtxPagePrefSpinItem()
3030 {
3031 }
3032
3033 /*!
3034   \brief Get spin box preference item input type.
3035   \return preference item input type (QtxPagePrefSpinItem::InputType)
3036   \sa setInputType()
3037 */
3038 int QtxPagePrefSpinItem::inputType() const
3039 {
3040   return myType;
3041 }
3042
3043 /*!
3044   \brief Set spin box preference item input type.
3045   \param type new preference item input type (QtxPagePrefSpinItem::InputType)
3046   \sa inputType()
3047 */
3048 void QtxPagePrefSpinItem::setInputType( const int type )
3049 {
3050   if ( myType == type )
3051     return;
3052
3053   myType = type;
3054   updateSpinBox();
3055 }
3056
3057 /*!
3058   \brief Get spin box preference item step value.
3059   \return spin box single step value
3060   \sa setStep()
3061 */
3062 QVariant QtxPagePrefSpinItem::step() const
3063 {
3064   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3065     return isb->singleStep();
3066   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3067     return dsb->singleStep();
3068   else
3069     return QVariant();
3070 }
3071
3072 /*!
3073   \brief Get double spin box preference item precision value.
3074   \return double spin box precision
3075   \sa setPrecision()
3076 */
3077 QVariant QtxPagePrefSpinItem::precision() const
3078 {
3079   if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3080     return dsb->decimals();
3081   else
3082     return QVariant();
3083 }
3084
3085 /*!
3086   \brief Get spin box preference item minimum value.
3087   \return spin box minimum value
3088   \sa setMinimum()
3089 */
3090 QVariant QtxPagePrefSpinItem::minimum() const
3091 {
3092   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3093     return isb->minimum();
3094   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3095     return dsb->minimum();
3096   else
3097     return QVariant();
3098 }
3099
3100 /*!
3101   \brief Get spin box preference item maximum value.
3102   \return spin box maximum value
3103   \sa setMaximum()
3104 */
3105 QVariant QtxPagePrefSpinItem::maximum() const
3106 {
3107   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3108     return isb->maximum();
3109   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3110     return dsb->maximum();
3111   else
3112     return QVariant();
3113 }
3114
3115 /*!
3116   \brief Get spin box preference item prefix string.
3117   \return spin box prefix string
3118   \sa setPrefix()
3119 */
3120 QString QtxPagePrefSpinItem::prefix() const
3121 {
3122   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3123     return isb->prefix();
3124   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3125     return dsb->prefix();
3126   else
3127     return QString();
3128 }
3129
3130 /*!
3131   \brief Get spin box preference item suffix string.
3132   \return spin box suffix string
3133   \sa setSuffix()
3134 */
3135 QString QtxPagePrefSpinItem::suffix() const
3136 {
3137   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3138     return isb->suffix();
3139   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3140     return dsb->suffix();
3141   else
3142     return QString();
3143 }
3144
3145 /*!
3146   \brief Get spin box preference item special value text (which is shown
3147   when the spin box reaches minimum value).
3148   \return spin box special value text
3149   \sa setSpecialValueText()
3150 */
3151 QString QtxPagePrefSpinItem::specialValueText() const
3152 {
3153   QAbstractSpinBox* sb = ::qobject_cast<QAbstractSpinBox*>( control() );
3154   if ( sb )
3155     return sb->specialValueText();
3156   else
3157     return QString();
3158 }
3159
3160 /*!
3161   \brief Set spin box preference item step value.
3162   \param step new spin box single step value
3163   \sa step()
3164 */
3165 void QtxPagePrefSpinItem::setStep( const QVariant& step )
3166 {
3167   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3168   {
3169     if ( step.canConvert( QVariant::Int ) )
3170       isb->setSingleStep( step.toInt() );
3171   }
3172   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3173   {
3174     if ( step.canConvert( QVariant::Double ) )
3175       dsb->setSingleStep( step.toDouble() );
3176   }
3177 }
3178
3179 /*!
3180   \brief Set double spin box preference item precision value.
3181   \param step new double spin box precision value
3182   \sa precision()
3183 */
3184 void QtxPagePrefSpinItem::setPrecision( const QVariant& prec )
3185 {
3186   if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3187   {
3188     if ( prec.canConvert( QVariant::Int ) ) {
3189       dsb->setDecimals( qAbs( prec.toInt() ) );
3190       dsb->setPrecision( prec.toInt() );
3191     }
3192   }
3193 }
3194
3195 /*!
3196   \brief Set spin box preference item minimum value.
3197   \param min new spin box minimum value
3198   \sa minimum()
3199 */
3200 void QtxPagePrefSpinItem::setMinimum( const QVariant& min )
3201 {
3202   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3203   {
3204     if ( min.canConvert( QVariant::Int ) )
3205       isb->setMinimum( min.toInt() );
3206   }
3207   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3208   {
3209     if ( min.canConvert( QVariant::Double ) )
3210       dsb->setMinimum( min.toDouble() );
3211   }
3212 }
3213
3214 /*!
3215   \brief Set spin box preference item maximum value.
3216   \param min new spin box maximum value
3217   \sa maximum()
3218 */
3219 void QtxPagePrefSpinItem::setMaximum( const QVariant& max )
3220 {
3221   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3222   {
3223     if ( max.canConvert( QVariant::Int ) )
3224       isb->setMaximum( max.toInt() );
3225   }
3226   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3227   {
3228     if ( max.canConvert( QVariant::Double ) )
3229       dsb->setMaximum( max.toDouble() );
3230   }
3231 }
3232
3233 /*!
3234   \brief Set spin box preference item prefix string.
3235   \param txt new spin box prefix string
3236   \sa prefix()
3237 */
3238 void QtxPagePrefSpinItem::setPrefix( const QString& txt )
3239 {
3240   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3241     isb->setPrefix( txt );
3242   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3243     dsb->setPrefix( txt );
3244 }
3245
3246 /*!
3247   \brief Set spin box preference item suffix string.
3248   \param txt new spin box suffix string
3249   \sa suffix()
3250 */
3251 void QtxPagePrefSpinItem::setSuffix( const QString& txt )
3252 {
3253   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3254     isb->setSuffix( txt );
3255   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3256     dsb->setSuffix( txt );
3257 }
3258
3259 /*!
3260   \brief Set spin box preference item special value text (which is shown
3261   when the spin box reaches minimum value).
3262   \param txt new spin box special value text
3263   \sa specialValueText()
3264 */
3265 void QtxPagePrefSpinItem::setSpecialValueText( const QString& txt )
3266 {
3267   QAbstractSpinBox* sb = ::qobject_cast<QAbstractSpinBox*>( control() );
3268   if ( sb )
3269     sb->setSpecialValueText( txt );
3270 }
3271
3272 /*!
3273   \brief Store preference item to the resource manager.
3274   \sa retrieve()
3275 */
3276 void QtxPagePrefSpinItem::store()
3277 {
3278   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3279     setInteger( isb->value() );
3280   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3281     setDouble( dsb->value() );
3282 }
3283
3284 /*!
3285   \brief Retrieve preference item from the resource manager.
3286   \sa store()
3287 */
3288 void QtxPagePrefSpinItem::retrieve()
3289 {
3290   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3291     isb->setValue( getInteger( isb->value() ) );
3292   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3293     dsb->setValue( getDouble( dsb->value() ) );
3294 }
3295
3296 /*!
3297   \brief Get preference item option value.
3298   \param name option name
3299   \return property value or null QVariant if option is not set
3300   \sa setOptionValue()
3301 */
3302 QVariant QtxPagePrefSpinItem::optionValue( const QString& name ) const
3303 {
3304   if ( name == "input_type" || name == "type" )
3305     return inputType();
3306   else if ( name == "minimum" || name == "min" )
3307     return minimum();
3308   else if ( name == "maximum" || name == "max" )
3309     return maximum();
3310   else if ( name == "step" )
3311     return step();
3312   else if ( name == "precision" )
3313     return precision();
3314   else if ( name == "prefix" )
3315     return prefix();
3316   else if ( name == "suffix" )
3317     return suffix();
3318   else if ( name == "special" )
3319     return specialValueText();
3320   else
3321     return QtxPageNamedPrefItem::optionValue( name );
3322 }
3323
3324 /*!
3325   \brief Set preference item option value.
3326   \param name option name
3327   \param val new property value
3328   \sa optionValue()
3329 */
3330 void QtxPagePrefSpinItem::setOptionValue( const QString& name, const QVariant& val )
3331 {
3332   if ( name == "input_type" || name == "type" )
3333   {
3334     if ( val.canConvert( QVariant::Int ) )
3335       setInputType( val.toInt() );
3336   }
3337   else if ( name == "minimum" || name == "min" )
3338     setMinimum( val );
3339   else if ( name == "maximum" || name == "max" )
3340     setMaximum( val );
3341   else if ( name == "step" )
3342     setStep( val );
3343   else if ( name == "precision" )
3344     setPrecision( val );
3345   else if ( name == "prefix" )
3346   {
3347     if ( val.canConvert( QVariant::String ) )
3348       setPrefix( val.toString() );
3349   }
3350   else if ( name == "suffix" )
3351   {
3352     if ( val.canConvert( QVariant::String ) )
3353       setSuffix( val.toString() );
3354   }
3355   else if ( name == "special" )
3356   {
3357     if ( val.canConvert( QVariant::String ) )
3358       setSpecialValueText( val.toString() );
3359   }
3360   else
3361     QtxPageNamedPrefItem::setOptionValue( name, val );
3362 }
3363
3364 /*!
3365   \brief Update spin box widget.
3366 */
3367 void QtxPagePrefSpinItem::updateSpinBox()
3368 {
3369   QVariant val;
3370   QVariant stp = step();
3371   QVariant prec = precision();
3372   QVariant min = minimum();
3373   QVariant max = maximum();
3374
3375   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3376     val = isb->value();
3377   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3378     val = dsb->value();
3379
3380   switch ( inputType() )
3381   {
3382   case Integer:
3383     setControl( new QtxIntSpinBox() );
3384     break;
3385   case Double:
3386     setControl( new QtxDoubleSpinBox() );
3387     break;
3388   default:
3389     break;
3390   }
3391
3392   control()->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
3393
3394   setStep( stp );
3395   setPrecision( prec );
3396   setMinimum( min );
3397   setMaximum( max );
3398
3399   if ( QtxIntSpinBox* isb = ::qobject_cast<QtxIntSpinBox*>( control() ) )
3400   {
3401     if ( val.canConvert( QVariant::Int ) )
3402       isb->setValue( val.toInt() );
3403   }
3404   else if ( QtxDoubleSpinBox* dsb = ::qobject_cast<QtxDoubleSpinBox*>( control() ) )
3405   {
3406     if ( val.canConvert( QVariant::Double ) )
3407       dsb->setValue( val.toDouble() );
3408   }
3409 }
3410
3411 /*!
3412   \class  QtxPagePrefTextItem
3413   \brief GUI implementation of the resources text box edit item
3414   (for large text data).
3415 */
3416
3417 /*!
3418   \brief Constructor.
3419   \param parent parent preference item
3420   \param sect resource file section associated with the preference item
3421   \param param resource file parameter associated with the preference item
3422 */
3423 QtxPagePrefTextItem::QtxPagePrefTextItem( QtxPreferenceItem* parent, const QString& sect,
3424                                           const QString& param )
3425 : QtxPageNamedPrefItem( QString(), parent, sect, param )
3426 {
3427   myEditor = new QTextEdit();
3428   myEditor->setAcceptRichText( false );
3429
3430   setControl( myEditor );
3431 }
3432
3433 /*!
3434   \brief Constructor.
3435   \param title preference item title
3436   \param parent parent preference item
3437   \param sect resource file section associated with the preference item
3438   \param param resource file parameter associated with the preference item
3439 */
3440 QtxPagePrefTextItem::QtxPagePrefTextItem( const QString& title, QtxPreferenceItem* parent,
3441                                           const QString& sect, const QString& param )
3442 : QtxPageNamedPrefItem( title, parent, sect, param )
3443 {
3444   myEditor = new QTextEdit();
3445   myEditor->setAcceptRichText( false );
3446
3447   setControl( myEditor );
3448 }
3449
3450 /*!
3451   \brief Destructor.
3452 */
3453 QtxPagePrefTextItem::~QtxPagePrefTextItem()
3454 {
3455 }
3456
3457 /*!
3458   \brief Store preference item to the resource manager.
3459   \sa retrieve()
3460 */
3461 void QtxPagePrefTextItem::store()
3462 {
3463   setString( myEditor->toPlainText() );
3464 }
3465
3466 /*!
3467   \brief Retrieve preference item from the resource manager.
3468   \sa store()
3469 */
3470 void QtxPagePrefTextItem::retrieve()
3471 {
3472   myEditor->setPlainText( getString() );
3473 }
3474
3475 /*!
3476   \class QtxPagePrefColorItem
3477   \brief GUI implementation of the resources color item.
3478 */
3479
3480 /*!
3481   \brief Constructor.
3482   \param title preference item title
3483   \param parent parent preference item
3484   \param sect resource file section associated with the preference item
3485   \param param resource file parameter associated with the preference item
3486 */
3487 QtxPagePrefColorItem::QtxPagePrefColorItem( const QString& title, QtxPreferenceItem* parent,
3488                                             const QString& sect, const QString& param )
3489 : QtxPageNamedPrefItem( title, parent, sect, param )
3490 {
3491   //  QtxPagePrefGroupItem* aGroup 0; //= dynamic_cast<QtxPagePrefGroupItem*>( parent );
3492
3493   //  setControl( myColor = new QtxColorButton( aGroup ? aGroup->gridBox() : 0 ) );
3494   setControl( myColor = new QtxColorButton( 0 ) );
3495   myColor->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
3496 }
3497
3498 /*!
3499   \brief Destructor.
3500 */
3501 QtxPagePrefColorItem::~QtxPagePrefColorItem()
3502 {
3503 }
3504
3505 /*!
3506   \brief Store preference item to the resource manager.
3507   \sa retrieve()
3508 */
3509 void QtxPagePrefColorItem::store()
3510 {
3511   setColor( myColor->color() );
3512 }
3513
3514 /*!
3515   \brief Retrieve preference item from the resource manager.
3516   \sa store()
3517 */
3518 void QtxPagePrefColorItem::retrieve()
3519 {
3520   myColor->setColor( getColor() );
3521 }
3522
3523 /*!
3524   \class QtxPagePrefBiColorItem
3525   \brief GUI implementation of the resources item to store a bi-color value.
3526
3527   The main color is specified explicitly. The secondary color is calculated
3528   by changing "value" and "saturation" parameters of the main color in the 
3529   HSV notation using specified delta.
3530 */
3531
3532 /*!
3533   \brief Constructor.
3534   \param title preference item title
3535   \param parent parent preference item
3536   \param sect resource file section associated with the preference item
3537   \param param resource file parameter associated with the preference item
3538 */
3539 QtxPagePrefBiColorItem::QtxPagePrefBiColorItem( const QString& title, QtxPreferenceItem* parent,
3540                                                 const QString& sect, const QString& param )
3541 : QtxPageNamedPrefItem( title, parent, sect, param )
3542 {
3543   setControl( myColors = new QtxBiColorTool( 0 ) );
3544 }
3545
3546 /*!
3547   \brief Destructor.
3548 */
3549 QtxPagePrefBiColorItem::~QtxPagePrefBiColorItem()
3550 {
3551 }
3552
3553 /*!
3554   \bried Get auxiliary text
3555   \return text assigned to the item
3556   \sa setText()
3557 */
3558 QString QtxPagePrefBiColorItem::text() const
3559 {
3560   return myColors->text();
3561 }
3562
3563 /*!
3564   \bried Set auxiliary text
3565   \param t text being assigned to the item
3566   \sa text()
3567 */
3568 void QtxPagePrefBiColorItem::setText( const QString& t )
3569 {
3570   myColors->setText( t );
3571 }
3572
3573 /*!
3574   \brief Store preference item to the resource manager.
3575   \sa retrieve()
3576 */
3577 void QtxPagePrefBiColorItem::store()
3578 {
3579   setString( Qtx::biColorToString( myColors->mainColor(), myColors->delta() ) );
3580 }
3581
3582 /*!
3583   \brief Retrieve preference item from the resource manager.
3584   \sa store()
3585 */
3586 void QtxPagePrefBiColorItem::retrieve()
3587 {
3588   QColor c;
3589   int d;
3590   Qtx::stringToBiColor( getString(), c, d );
3591   myColors->setMainColor( c );
3592   myColors->setDelta( d );
3593 }
3594
3595 /*!
3596   \brief Get preference item option value.
3597   \param name option name
3598   \return property value or null QVariant if option is not set
3599   \sa setOptionValue()
3600 */
3601 QVariant QtxPagePrefBiColorItem::optionValue( const QString& name ) const
3602 {
3603   if ( name == "text" )
3604     return text();
3605   else
3606     return QtxPageNamedPrefItem::optionValue( name );
3607 }
3608
3609 /*!
3610   \brief Set preference item option value.
3611   \param name option name
3612   \param val new property value
3613   \sa optionValue()
3614 */
3615 void QtxPagePrefBiColorItem::setOptionValue( const QString& name, const QVariant& val )
3616 {
3617   if ( name == "text" )
3618   {
3619     if ( val.canConvert( QVariant::String ) )
3620       setText( val.toString() );
3621   }
3622   else
3623     QtxPageNamedPrefItem::setOptionValue( name, val );
3624 }
3625
3626 /*!
3627   \class QtxPagePrefFontItem
3628   \brief GUI implementation of the resources font item.
3629 */
3630
3631 /*!
3632   \brief Constructor.
3633   \param feat font editor widget features (QtxFontEdit::Features)
3634   \param title preference item title
3635   \param parent parent preference item
3636   \param sect resource file section associated with the preference item
3637   \param param resource file parameter associated with the preference item
3638 */
3639 QtxPagePrefFontItem::QtxPagePrefFontItem( const int feat, const QString& title,
3640                                           QtxPreferenceItem* parent, const QString& sect,
3641                                           const QString& param )
3642 : QtxPageNamedPrefItem( title, parent, sect, param )
3643 {
3644   setControl( myFont = new QtxFontEdit( feat ) );
3645 }
3646
3647 /*!
3648   \brief Constructor.
3649   \param title preference item title
3650   \param parent parent preference item
3651   \param sect resource file section associated with the preference item
3652   \param param resource file parameter associated with the preference item
3653 */
3654 QtxPagePrefFontItem::QtxPagePrefFontItem( const QString& title, QtxPreferenceItem* parent,
3655                                           const QString& sect, const QString& param )
3656 : QtxPageNamedPrefItem( title, parent, sect, param )
3657 {
3658   setControl( myFont = new QtxFontEdit() );
3659 }
3660
3661 /*!
3662   \brief Destructor.
3663 */
3664 QtxPagePrefFontItem::~QtxPagePrefFontItem()
3665 {
3666 }
3667
3668 /*!
3669   \brief Get font widget features.
3670   \return font widget features (ORed QtxFontEdit::Features flags)
3671   \sa setFeatures()
3672 */
3673 int QtxPagePrefFontItem::features() const
3674 {
3675   return myFont->features();
3676 }
3677
3678 /*!
3679   \brief Set font widget features.
3680   \param f new font widget features (ORed QtxFontEdit::Features flags)
3681   \sa features()
3682 */
3683 void QtxPagePrefFontItem::setFeatures( const int f )
3684 {
3685   myFont->setFeatures( f );
3686 }
3687
3688 /*!
3689   \brief Specifies whether widget works in Native or Custom mode. Native mode 
3690   is intended for working with system fonts. Custom mode is intended for 
3691   working with manually defined set of fonts. Set of custom fonts can be 
3692   specified with setFonts() method 
3693   \param mode mode from QtxFontEdit::Mode enumeration
3694   \sa mode()
3695 */
3696 void QtxPagePrefFontItem::setMode( const int mode )
3697 {
3698   myFont->setMode( mode );
3699 }
3700
3701 /*!
3702   \brief Verifies whether widget works in Native or Custom mode
3703   \return Native or Custom mode
3704   \sa setMode()
3705 */
3706 int QtxPagePrefFontItem::mode() const
3707 {
3708   return myFont->mode();
3709 }
3710
3711 /*!
3712   \brief Sets list of custom fonts. 
3713   <b>This method is intended for working in Custom mode only.</b>
3714   \param fams list of families
3715   \sa fonts(), setMode()
3716 */
3717 void QtxPagePrefFontItem::setFonts( const QStringList& fams )
3718 {
3719   myFont->setFonts( fams );
3720 }
3721
3722 /*!
3723   \brief Gets list of custom fonts 
3724   \return list of families
3725   \sa setFonts(), setMode()
3726 */
3727 QStringList QtxPagePrefFontItem::fonts() const
3728 {
3729   return myFont->fonts();
3730 }
3731
3732 /*!
3733   \brief Sets list of available font sizes. 
3734   <b>This method is intended for working in Custom mode only.</b> The list of sizes can 
3735   be empty. In this case system generate listof size automatically from 8 till 72.
3736   \param sizes list of sizes
3737   \sa sizes(), setMode()
3738 */
3739 void QtxPagePrefFontItem::setSizes( const QList<int>& sizes )
3740 {
3741   myFont->setSizes( sizes );
3742 }
3743
3744 /*!
3745   \brief Gets list of custom fonts 
3746   \return list of families
3747   \sa setFonts(), setMode()
3748 */
3749 QList<int> QtxPagePrefFontItem::sizes() const
3750 {
3751   return myFont->sizes();
3752 }
3753
3754 /*!
3755   \brief Store preference item to the resource manager.
3756   \sa retrieve()
3757 */
3758 void QtxPagePrefFontItem::store()
3759 {
3760   setFont( myFont->currentFont() );
3761 }
3762
3763 /*!
3764   \brief Retrieve preference item from the resource manager.
3765   \sa store()
3766 */
3767 void QtxPagePrefFontItem::retrieve()
3768 {
3769   myFont->setCurrentFont( getFont() );
3770 }
3771
3772 /*!
3773   \brief Get preference item option value.
3774   \param name option name
3775   \return property value or null QVariant if option is not set
3776   \sa setOptionValue()
3777 */
3778 QVariant QtxPagePrefFontItem::optionValue( const QString& name ) const
3779 {
3780   if ( name == "features" )
3781     return features();
3782   else if ( name == "mode" )
3783     return mode();
3784   else if ( name == "fonts" || name == "families" )
3785     return fonts();
3786   else if ( name == "sizes" )
3787   {
3788     QList<QVariant> lst;
3789     QList<int> nums = sizes();
3790     for ( QList<int>::const_iterator it = nums.begin(); it != nums.end(); ++it )
3791       lst.append( *it );
3792     return lst;
3793   }
3794   else
3795     return QtxPageNamedPrefItem::optionValue( name );
3796 }
3797
3798 /*!
3799   \brief Set preference item option value.
3800   \param name option name
3801   \param val new property value
3802   \sa optionValue()
3803 */
3804 void QtxPagePrefFontItem::setOptionValue( const QString& name, const QVariant& val )
3805 {
3806   if ( name == "features" )
3807   {
3808     if ( val.canConvert( QVariant::Int ) )
3809       setFeatures( val.toInt() );
3810   }
3811   else if ( name == "mode" )
3812   {
3813     if ( val.canConvert( QVariant::Int ) )
3814       setMode( val.toInt() );
3815   }
3816   else if ( name == "fonts" || name == "families" )
3817   {
3818     if ( val.canConvert( QVariant::StringList ) )
3819       setFonts( val.toStringList() );
3820   }
3821   else if ( name == "sizes" )
3822   {
3823     if ( val.type() == QVariant::List )
3824     {
3825       QList<int> lst;
3826       QList<QVariant> varList = val.toList();
3827       for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it )
3828       {
3829         if ( (*it).canConvert( QVariant::Int ) )
3830           lst.append( (*it).toInt() );
3831       }
3832       setSizes( lst );
3833     }
3834   }
3835   else
3836     QtxPageNamedPrefItem::setOptionValue( name, val );
3837 }
3838
3839 /*!
3840   \class  QtxPagePrefPathItem
3841   \brief GUI implementation of the resources file/directory path item.
3842 */
3843
3844 /*!
3845   \brief Constructor.
3846   \param type path widget mode (Qtx::PathType )
3847   \param title preference item title
3848   \param parent parent preference item
3849   \param sect resource file section associated with the preference item
3850   \param param resource file parameter associated with the preference item
3851 */
3852 QtxPagePrefPathItem::QtxPagePrefPathItem( const Qtx::PathType type, const QString& title,
3853                                           QtxPreferenceItem* parent, const QString& sect, const QString& param )
3854 : QtxPageNamedPrefItem( title, parent, sect, param )
3855 {
3856   setControl( myPath = new QtxPathEdit( type ) );
3857 }
3858
3859 /*!
3860   \brief Constructor.
3861   \param title preference item title
3862   \param parent parent preference item
3863   \param sect resource file section associated with the preference item
3864   \param param resource file parameter associated with the preference item
3865 */
3866 QtxPagePrefPathItem::QtxPagePrefPathItem( const QString& title, QtxPreferenceItem* parent,
3867                                           const QString& sect, const QString& param )
3868 : QtxPageNamedPrefItem( title, parent, sect, param )
3869 {
3870   setControl( myPath = new QtxPathEdit() );
3871 }
3872
3873 /*!
3874   \brief Destructor.
3875 */
3876 QtxPagePrefPathItem::~QtxPagePrefPathItem()
3877 {
3878 }
3879
3880 /*!
3881   \brief Get path widget mode.
3882   \return current path widget mode (Qtx::PathType)
3883   \sa setPathType()
3884 */
3885 Qtx::PathType QtxPagePrefPathItem::pathType() const
3886 {
3887   return myPath->pathType();
3888 }
3889
3890 /*!
3891   \brief Set path widget mode.
3892   \param type new path widget mode (Qtx::PathType)
3893   \sa pathType()
3894 */
3895 void QtxPagePrefPathItem::setPathType( const Qtx::PathType type )
3896 {
3897   myPath->setPathType( type );
3898 }
3899
3900 /*!
3901   \brief Get currently used path widget filters.
3902   \return file or directory path filters
3903   \sa setPathFilter()
3904 */
3905 QString QtxPagePrefPathItem::pathFilter() const
3906 {
3907   return myPath->pathFilter();
3908 }
3909
3910 /*!
3911   \brief Set path widget filters.
3912   \param f new file or directory path filters
3913   \sa pathFilter()
3914 */
3915 void QtxPagePrefPathItem::setPathFilter( const QString& f )
3916 {
3917   myPath->setPathFilter( f );
3918 }
3919
3920 /*!
3921   \brief Store preference item to the resource manager.
3922   \sa retrieve()
3923 */
3924 void QtxPagePrefPathItem::store()
3925 {
3926   setString( myPath->path() );
3927 }
3928
3929 /*!
3930   \brief Retrieve preference item from the resource manager.
3931   \sa store()
3932 */
3933 void QtxPagePrefPathItem::retrieve()
3934 {
3935   myPath->setPath( getString() );
3936 }
3937
3938 /*!
3939   \brief Get preference item option value.
3940   \param name option name
3941   \return property value or null QVariant if option is not set
3942   \sa setOptionValue()
3943 */
3944 QVariant QtxPagePrefPathItem::optionValue( const QString& name ) const
3945 {
3946   if ( name == "path_type" )
3947     return pathType();
3948   else if ( name == "path_filter" )
3949     return pathFilter();
3950   else
3951     return QtxPageNamedPrefItem::optionValue( name );
3952 }
3953
3954 /*!
3955   \brief Set preference item option value.
3956   \param name option name
3957   \param val new property value
3958   \sa optionValue()
3959 */
3960 void QtxPagePrefPathItem::setOptionValue( const QString& name, const QVariant& val )
3961 {
3962   if ( name == "path_type" )
3963   {
3964     if ( val.canConvert( QVariant::Int ) )
3965       setPathType( (Qtx::PathType)val.toInt() );
3966   }
3967   else if ( name == "path_filter" )
3968   {
3969     if ( val.canConvert( QVariant::String ) )
3970       setPathFilter( val.toString() );
3971   }
3972   else
3973     QtxPageNamedPrefItem::setOptionValue( name, val );
3974 }
3975
3976 /*!
3977   \class QtxPagePrefPathListItem
3978   \brief GUI implementation of the resources files/directories list item.
3979 */
3980
3981 /*!
3982   \brief Constructor.
3983   \param parent parent preference item
3984   \param sect resource file section associated with the preference item
3985   \param param resource file parameter associated with the preference item
3986 */
3987 QtxPagePrefPathListItem::QtxPagePrefPathListItem( QtxPreferenceItem* parent,
3988                                                   const QString& sect, const QString& param )
3989 : QtxPageNamedPrefItem( QString(), parent, sect, param )
3990 {
3991   setControl( myPaths = new QtxPathListEdit() );
3992 }
3993
3994 /*!
3995   \brief Constructor.
3996   \param type path list widget mode (Qtx::PathType)
3997   \param title preference item title
3998   \param parent parent preference item
3999   \param sect resource file section associated with the preference item
4000   \param param resource file parameter associated with the preference item
4001 */
4002 QtxPagePrefPathListItem::QtxPagePrefPathListItem( const Qtx::PathType type, const QString& title,
4003                                                   QtxPreferenceItem* parent, const QString& sect, const QString& param )
4004 : QtxPageNamedPrefItem( title, parent, sect, param )
4005 {
4006   setControl( myPaths = new QtxPathListEdit( type ) );
4007 }
4008
4009 /*!
4010   \brief Constructor.
4011   \param title preference item title
4012   \param parent parent preference item
4013   \param sect resource file section associated with the preference item
4014   \param param resource file parameter associated with the preference item
4015 */
4016 QtxPagePrefPathListItem::QtxPagePrefPathListItem( const QString& title, QtxPreferenceItem* parent,
4017                                                   const QString& sect, const QString& param )
4018 : QtxPageNamedPrefItem( title, parent, sect, param )
4019 {
4020   setControl( myPaths = new QtxPathListEdit() );
4021 }
4022
4023 /*!
4024   \brief Destructor.
4025 */
4026 QtxPagePrefPathListItem::~QtxPagePrefPathListItem()
4027 {
4028 }
4029
4030 /*!
4031   \brief Get path list widget mode.
4032   \return currently used path list widget mode (Qtx::PathType)
4033   \sa setPathType()
4034 */
4035 Qtx::PathType QtxPagePrefPathListItem::pathType() const
4036 {
4037   return myPaths->pathType();
4038 }
4039
4040 /*!
4041   \brief Set path list widget mode.
4042   \param type new path list widget mode (Qtx::PathType)
4043   \sa pathType()
4044 */
4045 void QtxPagePrefPathListItem::setPathType( const Qtx::PathType type )
4046 {
4047   myPaths->setPathType( type );
4048 }
4049
4050 /*!
4051   \brief Store preference item to the resource manager.
4052   \sa retrieve()
4053 */
4054 void QtxPagePrefPathListItem::store()
4055 {
4056   setString( myPaths->pathList().join( ";" ) );
4057 }
4058
4059 /*!
4060   \brief Retrieve preference item from the resource manager.
4061   \sa store()
4062 */
4063 void QtxPagePrefPathListItem::retrieve()
4064 {
4065   myPaths->setPathList( getString().split( ";" ) );
4066 }
4067
4068 /*!
4069   \brief Get preference item option value.
4070   \param name option name
4071   \return property value or null QVariant if option is not set
4072   \sa setOptionValue()
4073 */
4074 QVariant QtxPagePrefPathListItem::optionValue( const QString& name ) const
4075 {
4076   if ( name == "path_type" )
4077     return pathType();
4078   else
4079     return QtxPageNamedPrefItem::optionValue( name );
4080 }
4081
4082 /*!
4083   \brief Set preference item option value.
4084   \param name option name
4085   \param val new property value
4086   \sa optionValue()
4087 */
4088 void QtxPagePrefPathListItem::setOptionValue( const QString& name, const QVariant& val )
4089 {
4090   if ( name == "path_type" )
4091   {
4092     if ( val.canConvert( QVariant::Int ) )
4093       setPathType( (Qtx::PathType)val.toInt() );
4094   }
4095   else
4096     QtxPageNamedPrefItem::setOptionValue( name, val );
4097 }
4098
4099 /*!
4100   \class  QtxPagePrefDateTimeItem
4101   \brief GUI implementation of resources date/time item.
4102 */
4103
4104 /*!
4105   \brief Constructor.
4106
4107   Creates an item to enter date and time.
4108
4109   \param title preference item title
4110   \param parent parent preference item
4111   \param sect resource file section associated with the preference item
4112   \param param resource file parameter associated with the preference item
4113 */
4114 QtxPagePrefDateTimeItem::QtxPagePrefDateTimeItem( const QString& title, QtxPreferenceItem* parent,
4115                                                   const QString& sect, const QString& param )
4116 : QtxPageNamedPrefItem( title, parent, sect, param ),
4117   myType( DateTime )
4118 {
4119   setControl( myDateTime = new QDateTimeEdit() );
4120   myDateTime->setCalendarPopup( true );
4121   myDateTime->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
4122   updateDateTime();
4123 }
4124
4125 /*!
4126   \brief Constructor.
4127
4128   Creates preference item for editing of the date and/or time value:
4129   the type is specified by parameter \a type.
4130
4131   \param type preference item input type (QtxPagePrefDateTimeItem::InputType)
4132   \param title preference item title
4133   \param parent parent preference item
4134   \param sect resource file section associated with the preference item
4135   \param param resource file parameter associated with the preference item
4136 */
4137 QtxPagePrefDateTimeItem::QtxPagePrefDateTimeItem( const int type, const QString& title, QtxPreferenceItem* parent,
4138                                                   const QString& sect, const QString& param )
4139 : QtxPageNamedPrefItem( title, parent, sect, param ),
4140   myType( type )
4141 {
4142   setControl( myDateTime = new QDateTimeEdit() );
4143   myDateTime->setCalendarPopup( true );
4144   myDateTime->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
4145   updateDateTime();
4146 }
4147
4148 /*!
4149   \brief Destructor.
4150 */
4151 QtxPagePrefDateTimeItem::~QtxPagePrefDateTimeItem()
4152 {
4153 }
4154
4155 /*!
4156   \brief Get date/time box preference item input type.
4157   \return preference item input type (QtxPagePrefDateTimeItem::InputType)
4158   \sa setInputType()
4159 */
4160 int QtxPagePrefDateTimeItem::inputType() const
4161 {
4162   return myType;
4163 }
4164
4165 /*!
4166   \brief Set date/time box preference item input type.
4167   \param type new preference item input type (QtxPagePrefDateTimeItem::InputType)
4168   \sa inputType()
4169 */
4170 void QtxPagePrefDateTimeItem::setInputType( const int type )
4171 {
4172   if ( myType == type )
4173     return;
4174
4175   myType = type;
4176   updateDateTime();
4177 }
4178
4179 /*!
4180   \brief Check if the popup calendar menu is enabled.
4181   \return \c true if calendar popup menu is enabled
4182 */
4183 bool QtxPagePrefDateTimeItem::calendar() const
4184 {
4185   return myDateTime->calendarPopup();
4186 }
4187
4188 /*!
4189   \brief Enable/disable popup calendar menu.
4190   \param on new flag state
4191 */
4192 void QtxPagePrefDateTimeItem::setCalendar( const bool on )
4193 {
4194   myDateTime->setCalendarPopup( on );
4195 }
4196
4197 /*!
4198   \brief Get maximum date value.
4199   \return maximum date value
4200   \sa setMaximumDate(), minimumDate(), maximumTime(), minimumTime()
4201 */
4202 QDate QtxPagePrefDateTimeItem::maximumDate() const
4203 {
4204   return myDateTime->maximumDate();
4205 }
4206
4207 /*!
4208   \brief Get maximum time value.
4209   \return maximum time value
4210   \sa setMaximumTime(), minimumTime(), maximumDate(), minimumDate()
4211 */
4212 QTime QtxPagePrefDateTimeItem::maximumTime() const
4213 {
4214   return myDateTime->maximumTime();
4215 }
4216
4217 /*!
4218   \brief Get minimum date value.
4219   \return minimum date value
4220   \sa setMinimumDate(), maximumDate(), maximumTime(), minimumTime()
4221 */
4222 QDate QtxPagePrefDateTimeItem::minimumDate() const
4223 {
4224   return myDateTime->minimumDate();
4225 }
4226
4227 /*!
4228   \brief Get minimum time value.
4229   \return maximum time value
4230   \sa setMinimumTime(), maximumTime(), maximumDate(), minimumDate()
4231 */
4232 QTime QtxPagePrefDateTimeItem::minimumTime() const
4233 {
4234   return myDateTime->minimumTime();
4235 }
4236
4237 /*!
4238   \brief Set maximum date value.
4239   \param d new maximum date value
4240   \sa maximumDate(), minimumDate(), maximumTime(), minimumTime()
4241 */
4242 void QtxPagePrefDateTimeItem::setMaximumDate( const QDate& d )
4243 {
4244   if ( d.isValid() )
4245     myDateTime->setMaximumDate( d );
4246   else
4247     myDateTime->clearMaximumDate();
4248 }
4249
4250 /*!
4251   \brief Set maximum time value.
4252   \param t new maximum time value
4253   \sa maximumTime(), minimumTime(), maximumDate(), minimumDate()
4254 */
4255 void QtxPagePrefDateTimeItem::setMaximumTime( const QTime& t )
4256 {
4257   if ( t.isValid() )
4258     myDateTime->setMaximumTime( t );
4259   else
4260     myDateTime->clearMaximumTime();
4261 }
4262
4263 /*!
4264   \brief Set minimum date value.
4265   \param d new minimum date value
4266   \sa minimumDate(), maximumDate(), maximumTime(), minimumTime()
4267 */
4268 void QtxPagePrefDateTimeItem::setMinimumDate( const QDate& d )
4269 {
4270   if ( d.isValid() )
4271     myDateTime->setMinimumDate( d );
4272   else
4273     myDateTime->clearMinimumDate();
4274 }
4275
4276 /*!
4277   \brief Set minimum time value.
4278   \param t new minimum time value
4279   \sa minimumTime(), maximumTime(), maximumDate(), minimumDate()
4280 */
4281 void QtxPagePrefDateTimeItem::setMinimumTime( const QTime& t )
4282 {
4283   if ( t.isValid() )
4284     myDateTime->setMinimumTime( t );
4285   else
4286     myDateTime->clearMinimumTime();
4287 }
4288
4289 /*!
4290   \brief Store preference item to the resource manager.
4291   \sa retrieve()
4292 */
4293 void QtxPagePrefDateTimeItem::store()
4294 {
4295   QString str;
4296   switch ( inputType() )
4297   {
4298   case Date:
4299     str = myDateTime->date().toString( Qt::ISODate );
4300     break;
4301   case Time:
4302     str = myDateTime->time().toString( Qt::ISODate );
4303     break;
4304   case DateTime:
4305     str = myDateTime->dateTime().toString( Qt::ISODate );
4306     break;
4307   }
4308
4309   setString( str );
4310 }
4311
4312 /*!
4313   \brief Retrieve preference item from the resource manager.
4314   \sa store()
4315 */
4316 void QtxPagePrefDateTimeItem::retrieve()
4317 {
4318   QString str = getString();
4319   switch ( inputType() )
4320   {
4321   case Date:
4322     myDateTime->setDate( QDate::fromString( str, Qt::ISODate ) );
4323     break;
4324   case Time:
4325     myDateTime->setTime( QTime::fromString( str, Qt::ISODate ) );
4326     break;
4327   case DateTime:
4328     myDateTime->setDateTime( QDateTime::fromString( str, Qt::ISODate ) );
4329     break;
4330   }
4331 }
4332
4333 /*!
4334   \brief Get preference item option value.
4335   \param name option name
4336   \return property value or null QVariant if option is not set
4337   \sa setOptionValue()
4338 */
4339 QVariant QtxPagePrefDateTimeItem::optionValue( const QString& name ) const
4340 {
4341   if ( name == "input_type" || name == "type" )
4342     return inputType();
4343   else if ( name == "minimum_date" || name == "min_date" )
4344     return minimumDate();
4345   else if ( name == "maximum_date" || name == "max_date" )
4346     return maximumDate();
4347   else if ( name == "minimum_time" || name == "min_time" )
4348     return minimumTime();
4349   else if ( name == "maximum_time" || name == "max_time" )
4350     return maximumTime();
4351   else
4352     return QtxPageNamedPrefItem::optionValue( name );
4353 }
4354
4355 /*!
4356   \brief Set preference item option value.
4357   \param name option name
4358   \param val new property value
4359   \sa optionValue()
4360 */
4361 void QtxPagePrefDateTimeItem::setOptionValue( const QString& name, const QVariant& val )
4362 {
4363   if ( name == "input_type" || name == "type" )
4364   {
4365     if ( val.canConvert( QVariant::Int ) )
4366       setInputType( val.toInt() );
4367   }
4368   else if ( name == "minimum_date" || name == "min_date" )
4369   {
4370     if ( val.canConvert( QVariant::Date ) )
4371       setMinimumDate( val.toDate() );
4372   }
4373   else if ( name == "maximum_date" || name == "max_date" )
4374   {
4375     if ( val.canConvert( QVariant::Date ) )
4376       setMaximumDate( val.toDate() );
4377   }
4378   else if ( name == "minimum_time" || name == "min_time" )
4379   {
4380     if ( val.canConvert( QVariant::Time ) )
4381       setMinimumTime( val.toTime() );
4382   }
4383   else if ( name == "maximum_time" || name == "max_time" )
4384   {
4385     if ( val.canConvert( QVariant::Time ) )
4386       setMaximumTime( val.toTime() );
4387   }
4388   else
4389     QtxPageNamedPrefItem::setOptionValue( name, val );
4390 }
4391
4392 /*!
4393   \brief Update date/time widget.
4394 */
4395 void QtxPagePrefDateTimeItem::updateDateTime()
4396 {
4397   QString dispFmt;
4398   switch ( inputType() )
4399   {
4400   case Date:
4401     dispFmt = QDateEdit().displayFormat();
4402     break;
4403   case Time:
4404     dispFmt = QTimeEdit().displayFormat();
4405     break;
4406   case DateTime:
4407     dispFmt = QDateTimeEdit().displayFormat();
4408     break;
4409   }
4410
4411   myDateTime->setDisplayFormat( dispFmt );
4412 }
4413
4414 /*!
4415   \brief Constructor.
4416   \param title preference item title
4417   \param parent parent preference item
4418   \param sect resource file section associated with the preference item
4419   \param param resource file parameter associated with the preference item
4420 */
4421 QtxPagePrefShortcutBtnsItem::QtxPagePrefShortcutBtnsItem( const QString& title, QtxPreferenceItem* parent, const QString& sect,
4422                                                           const QString& param ): QtxPageNamedPrefItem( title, parent, sect, param )
4423 {
4424   setControl( myShortcut = new QtxShortcutEdit() );
4425 }
4426
4427 /*!
4428   \brief Destructor.
4429 */  
4430 QtxPagePrefShortcutBtnsItem::~QtxPagePrefShortcutBtnsItem()
4431 {
4432 }
4433
4434 /*!
4435   \brief Store preference item to the resource manager.
4436   \sa retrieve()
4437 */
4438 void QtxPagePrefShortcutBtnsItem::store()
4439 {
4440   setString( myShortcut->shortcut().toString() );
4441 }
4442
4443 /*!
4444   \brief Retrieve preference item from the resource manager.
4445   \sa store()
4446 */
4447 void QtxPagePrefShortcutBtnsItem::retrieve()
4448 {
4449   myShortcut->setShortcut( QKeySequence::fromString( getString() ) );
4450 }
4451
4452 /*!
4453   \brief Constructor.
4454
4455   Creates preference item for editing of key bindings
4456
4457   \param title preference item title
4458   \param parent parent preference item
4459   \param sect resource file section associated with the preference item
4460   \param param resource file parameter associated with the preference item
4461 */
4462 QtxPagePrefShortcutTreeItem::QtxPagePrefShortcutTreeItem( const QString& title, QtxPreferenceItem* parent, const QString& sect, 
4463                                                           const QString& param ): QtxPageNamedPrefItem( title, parent, sect, "" )
4464 {
4465   mySection = sect;
4466
4467   myShortcutTree = new QtxShortcutTree();
4468
4469   // Retrieve shortcuts common sections from resources
4470   QtxResourceMgr* resMgr = resourceMgr();
4471   if ( resMgr ){
4472     QString generalSections = resourceMgr()->stringValue( "shortcuts_settings", "general_sections", QString() );
4473     QStringList sectionsList = generalSections.split( ";", QString::SkipEmptyParts );
4474     myShortcutTree->setGeneralSections( sectionsList );
4475   }
4476  
4477   setControl( myShortcutTree );
4478 }
4479
4480 /*!
4481   \brief Destructor.
4482 */
4483 QtxPagePrefShortcutTreeItem::~QtxPagePrefShortcutTreeItem()
4484 {
4485 }
4486                                                     
4487 /*!
4488   \brief Retrieve preference item from the resource manager.
4489   \sa store()
4490 */
4491 void QtxPagePrefShortcutTreeItem::retrieve()
4492 {
4493   QtxResourceMgr* resMgr = resourceMgr();
4494   if ( resMgr ){
4495     QStringList secLst = resMgr->subSections( mySection, false );
4496     ShortcutMap aMap; QStringList paramLst;
4497     for( int i = 0; i < secLst.size(); i++ ) {
4498       paramLst = resMgr->parameters( QStringList() << mySection << secLst.at( i ) );
4499       for( int j = 0; j < paramLst.size(); j++ )
4500         resMgr->value( mySection + resMgr->sectionsToken() + secLst.at( i ), paramLst.at( j ),aMap[ paramLst.at( j ) ], false );
4501       myShortcutTree->setBindings( secLst.at( i ), aMap );
4502       aMap.clear();
4503     }
4504   }
4505 }
4506               
4507 /*!
4508   \brief Store preference item to the resource manager.
4509   \sa retrieve()
4510 */
4511 void QtxPagePrefShortcutTreeItem::store()
4512 {
4513   QStringList lst = myShortcutTree->sections();
4514   QString aSection;
4515   QtxResourceMgr* resMgr = resourceMgr();
4516   
4517   if ( resMgr ) {
4518     for( int i = 0; i < lst.size(); i++ ) {
4519       ShortcutMap* aMap( myShortcutTree->bindings( lst.at( i ) ) );
4520       aSection = mySection + resMgr->sectionsToken() + lst.at( i );
4521       for( ShortcutMap::const_iterator it = aMap->constBegin(); it != aMap->constEnd(); ++it )
4522         resMgr->setValue( aSection, it.key(), it.value() );
4523     }
4524   }
4525 }
4526
4527 /*!
4528   \class QtxPagePrefBackgroundItem
4529   \brief GUI implementation of the resources item to store background data.
4530
4531   Preference item allows specifying background data in different ways:
4532   - solid color
4533   - texture image file
4534   - simple two-color gradient
4535   - complex custom gradient (NOT IMPLEMENTED YET)
4536   
4537   Allowed background modes can be specified using setModeAllowed() method.
4538   Texture modes can be enabled/disabled using setTextureModeAllowed() method.
4539   Also, showing texture controls can be enabled/disabled by means of
4540   setTextureAllowed() method.
4541   Verical or horizontal orientation of the widget can be chosen via setOrientation()
4542   method (default orientation is horizontal).
4543
4544   Simple gradient types can be specified using setGradients() method.
4545
4546   \sa Qtx::BackgroundData, QtxBackgroundTool
4547 */
4548
4549 /*!
4550   \brief Constructor.
4551   \param title preference item title
4552   \param parent parent preference item
4553   \param sect resource file section associated with the preference item
4554   \param param resource file parameter associated with the preference item
4555 */
4556 QtxPagePrefBackgroundItem::QtxPagePrefBackgroundItem( const QString& title, QtxPreferenceItem* parent,
4557                                                       const QString& sect, const QString& param )
4558 : QtxPageNamedPrefItem( title, parent, sect, param )
4559 {
4560   setControl( myBgTool = new QtxBackgroundTool( 0 ) );
4561 }
4562
4563 /*!
4564   \brief Destructor.
4565 */
4566 QtxPagePrefBackgroundItem::~QtxPagePrefBackgroundItem()
4567 {
4568 }
4569
4570 /*!
4571   \brief Get allowed two-color gradients to the widget
4572   \param gradients gradients names are returned via this parameter
4573   \param ids gradients identifiers are returned via this parameter (empty list can be returned)
4574 */
4575 void QtxPagePrefBackgroundItem::gradients( QStringList& gradList, QIntList& idList ) const
4576 {
4577   myBgTool->gradients( gradList, idList );
4578 }
4579
4580 /*!
4581   \brief Set allowed two-color gradients to the widget
4582   \param gradients gradients names
4583   \param ids optional gradients identifiers; if not specified, gradients are automatically numbered starting from 0
4584 */
4585 void QtxPagePrefBackgroundItem::setGradients( const QStringList& gradients, const QIntList& ids )
4586 {
4587   myBgTool->setGradients( gradients, ids );
4588 }
4589
4590 /*!
4591   \brief Check if specific background mode is allowed
4592   \param mode background mode
4593   \return \c true if specified background mode is enabled or \c false otherwise
4594   \sa setModeAllowed()
4595 */
4596 bool QtxPagePrefBackgroundItem::isModeAllowed( Qtx::BackgroundMode mode ) const
4597 {
4598   return myBgTool->isModeAllowed( mode );
4599 }
4600
4601 /*!
4602   \brief Enable / disable specific background mode
4603   \param mode background mode
4604   \param on enable / disable flag
4605   \sa isModeAllowed()
4606 */
4607 void QtxPagePrefBackgroundItem::setModeAllowed( Qtx::BackgroundMode mode, bool on )
4608 {
4609   myBgTool->setModeAllowed( mode, on );
4610 }
4611
4612 /*!
4613   \brief Check if specific texture mode is allowed
4614   \param mode texture mode
4615   \return \c true if specified texture mode is enabled or \c false otherwise
4616   \sa setTextureModeAllowed(), setTextureAllowed()
4617 */
4618 bool QtxPagePrefBackgroundItem::isTextureModeAllowed( Qtx::TextureMode mode ) const
4619 {
4620   return myBgTool->isTextureModeAllowed( mode );
4621 }
4622
4623 /*!
4624   \brief Enable / disable specific texture mode
4625   \param mode texture mode
4626   \param on enable / disable flag (\c true by default)
4627   \sa isTextureModeAllowed(), setTextureAllowed()
4628 */
4629 void QtxPagePrefBackgroundItem::setTextureModeAllowed( Qtx::TextureMode mode, bool on )
4630 {
4631   myBgTool->setTextureModeAllowed( mode, on );
4632 }
4633
4634 /*!
4635   \brief Check if texture controls are allowed (shown)
4636   \return \c true if texture controls are enabled or \c false otherwise
4637   \sa setTextureAllowed(), setTextureModeAllowed()
4638 */
4639 bool QtxPagePrefBackgroundItem::isTextureAllowed() const
4640 {
4641   return myBgTool->isTextureAllowed();
4642 }
4643
4644 /*!
4645   \brief Enable / disable texture controls
4646   \param on enable / disable flag (\c true by default)
4647   \sa isTextureAllowed(), setTextureModeAllowed()
4648 */
4649 void QtxPagePrefBackgroundItem::setTextureAllowed( bool on )
4650 {
4651   myBgTool->setTextureAllowed( on );
4652 }
4653
4654 /*!
4655   \brief Get allowed image formats
4656   \return image formats
4657 */
4658 QString QtxPagePrefBackgroundItem::imageFormats() const
4659 {
4660   return myBgTool->imageFormats();
4661 }
4662
4663 /*!
4664   \brief Set allowed image formats
4665   \param formats image formats
4666 */
4667 void QtxPagePrefBackgroundItem::setImageFormats( const QString& formats )
4668 {
4669   myBgTool->setImageFormats( formats );
4670 }
4671
4672 /*!
4673   \brief Get widget editor orientation
4674   \return orientation
4675 */
4676 Qt::Orientation QtxPagePrefBackgroundItem::orientation() const
4677 {
4678   return myBgTool->orientation();
4679 }
4680
4681 /*!
4682   \brief Set widget editor orientation
4683   \param o orientation
4684 */
4685 void QtxPagePrefBackgroundItem::setOrientation( Qt::Orientation o )
4686 {
4687   myBgTool->setOrientation( o );
4688 }
4689
4690 /*!
4691   \brief Store preference item to the resource manager.
4692   \sa retrieve()
4693 */
4694 void QtxPagePrefBackgroundItem::store()
4695 {
4696   setString( Qtx::backgroundToString( myBgTool->data() ) );
4697 }
4698
4699 /*!
4700   \brief Retrieve preference item from the resource manager.
4701   \sa store()
4702 */
4703 void QtxPagePrefBackgroundItem::retrieve()
4704 {
4705   myBgTool->setData( Qtx::stringToBackground( getString() ) );
4706 }
4707
4708 /*!
4709   \brief Get preference item option value.
4710   \param name option name
4711   \return property value or null QVariant if option is not set
4712   \sa setOptionValue()
4713 */
4714 QVariant QtxPagePrefBackgroundItem::optionValue( const QString& name ) const
4715 {
4716   if ( name == "texture_enabled" )
4717     return isTextureAllowed();
4718   else if ( name == "color_enabled" )
4719     return isModeAllowed( Qtx::ColorBackground );
4720   else if ( name == "gradient_enabled" )
4721     return isModeAllowed( Qtx::SimpleGradientBackground );
4722   else if ( name == "custom_enabled" )
4723     return isModeAllowed( Qtx::CustomGradientBackground );
4724   else if ( name == "texture_center_enabled" )
4725     return isTextureModeAllowed( Qtx::CenterTexture );
4726   else if ( name == "texture_tile_enabled" )
4727     return isTextureModeAllowed( Qtx::TileTexture );
4728   else if ( name == "texture_stretch_enabled" )
4729     return isTextureModeAllowed( Qtx::StretchTexture );
4730   else if ( name == "orientation" )
4731     return orientation();
4732   else if ( name == "image_formats" )
4733     return imageFormats();
4734   else if ( name == "gradient_names" ) {
4735     QStringList grList;
4736     QIntList    idList;
4737     gradients( grList, idList );
4738     return grList;
4739   }
4740   else if ( name == "gradient_ids" ) {
4741     QStringList grList;
4742     QIntList    idList;
4743     gradients( grList, idList );
4744     QList<QVariant> lst;
4745     for ( QIntList::const_iterator it = idList.begin(); it != idList.end(); ++it )
4746       lst.append( *it );
4747     return lst;
4748   }
4749   else
4750     return QtxPageNamedPrefItem::optionValue( name );
4751 }
4752
4753 /*!
4754   \brief Set preference item option value.
4755   \param name option name
4756   \param val new property value
4757   \sa optionValue()
4758 */
4759 void QtxPagePrefBackgroundItem::setOptionValue( const QString& name, const QVariant& val )
4760 {
4761   if ( name == "texture_enabled" ) {
4762     if ( val.canConvert( QVariant::Bool ) )
4763       setTextureAllowed( val.toBool() );
4764   }
4765   else if ( name == "color_enabled" ) {
4766     if ( val.canConvert( QVariant::Bool ) )
4767       setModeAllowed( Qtx::ColorBackground, val.toBool() );
4768   }
4769   else if ( name == "gradient_enabled" ) {
4770     if ( val.canConvert( QVariant::Bool ) )
4771       setModeAllowed( Qtx::SimpleGradientBackground, val.toBool() );
4772   }
4773   else if ( name == "custom_enabled" ) {
4774     if ( val.canConvert( QVariant::Bool ) )
4775       setModeAllowed( Qtx::CustomGradientBackground, val.toBool() );
4776   }
4777   else if ( name == "texture_center_enabled" ) {
4778     if ( val.canConvert( QVariant::Bool ) )
4779       setTextureModeAllowed( Qtx::CenterTexture, val.toBool() );
4780   }
4781   else if ( name == "texture_tile_enabled" ) {
4782     if ( val.canConvert( QVariant::Bool ) )
4783       setTextureModeAllowed( Qtx::TileTexture, val.toBool() );
4784   }
4785   else if ( name == "texture_stretch_enabled" ) {
4786     if ( val.canConvert( QVariant::Bool ) )
4787       setTextureModeAllowed( Qtx::StretchTexture, val.toBool() );
4788   }
4789   else if ( name == "orientation" ) {
4790     if ( val.canConvert( QVariant::Int ) )
4791       setOrientation( (Qt::Orientation)val.toInt() );
4792   }
4793   else if ( name == "image_formats" ) {
4794     if ( val.canConvert( QVariant::String ) )
4795       setImageFormats( val.toString() );
4796   }
4797   else if ( name == "gradient_names" ) {
4798     if ( val.canConvert( QVariant::StringList ) )
4799       setGradients( val.toStringList() );
4800   }
4801   else if ( name == "gradient_ids" ) {
4802     if ( val.canConvert( QVariant::List ) ) {
4803       QStringList grList;
4804       QIntList    idList;
4805       gradients( grList, idList );
4806       idList.clear();
4807       QList<QVariant> varList = val.toList();
4808       for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it ) {
4809         if ( (*it).canConvert( QVariant::Int ) )
4810           idList.append( (*it).toInt() );
4811       }
4812       setGradients( grList, idList );
4813     }
4814   }
4815   else
4816     QtxPageNamedPrefItem::setOptionValue( name, val );
4817 }
4818
4819 /*!
4820   \brief Constructor.
4821
4822   Creates preference item of user defined widget. The item widget has to be inherited from 
4823   QtxUserDefinedContent class. An instance of this class has to be installed into the item
4824   with help of setContent method. Methods optionValue and setOptionValue use pointer on the 
4825   content widget an qint64 value.
4826
4827   \param parent parent preference item
4828 */
4829 QtxUserDefinedItem::QtxUserDefinedItem( QtxPreferenceItem* parent )
4830   : QtxPageNamedPrefItem(QString(), parent), myContent(0)
4831 {
4832 }
4833   
4834 /*!
4835   \brief Lets to Store preferences for content instance
4836   \sa retrieve()
4837 */
4838 void QtxUserDefinedItem::store()
4839 {
4840   if (myContent) {
4841     myContent->store( resourceMgr(), preferenceMgr());
4842   }
4843 }
4844
4845 /*!
4846   \brief Lets to Retrieve preferences for content instance
4847   \sa store()
4848 */
4849 void QtxUserDefinedItem::retrieve()
4850 {
4851   if (myContent) {
4852     myContent->retrieve( resourceMgr(), preferenceMgr());
4853   }
4854 }
4855
4856 /*!
4857  * \brief Returns option value
4858  * \param theName is a string "content"
4859  * \return pointer on QtxUserDefinedContent class instance as a qint64 value
4860  */
4861 QVariant QtxUserDefinedItem::optionValue( const QString& theName ) const
4862 {
4863   if ( theName == "content" )
4864     return (qint64) myContent;
4865   else
4866     return QtxPreferenceItem::optionValue( theName );
4867 }
4868
4869 /*!
4870  * \brief Sets option value
4871  * \param theName is a string "content" 
4872  * \param theVal is a pointer on QtxUserDefinedContent class instance represented as qint64 value
4873  */
4874 void QtxUserDefinedItem::setOptionValue( const QString& theName, const QVariant& theVal)
4875 {
4876   if ( theName == "content" ) {
4877     if ( theVal.canConvert( QVariant::ULongLong ) ) {
4878       setContent( (QtxUserDefinedContent*)theVal.toULongLong() );
4879     }
4880   } else
4881     QtxPreferenceItem::setOptionValue( theName, theVal );
4882 }
4883   
4884 /*!
4885  * \brief Defines content of the property item as a Widget which has to be inherited from 
4886  * QtxUserDefinedContent class.
4887  * \param theContent is an QtxUserDefinedContent class instance.
4888  */
4889 void QtxUserDefinedItem::setContent( QtxUserDefinedContent* theContent ) 
4890
4891   myContent = theContent; 
4892   setControl(myContent);
4893 }