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