]> SALOME platform Git repositories - modules/gui.git/blob - src/Qtx/QtxListResourceEdit.cxx
Salome HOME
bc3bcccb614f955c60ea2bd00d905c621f9ae130
[modules/gui.git] / src / Qtx / QtxListResourceEdit.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19 // File:      QtxListResourceEdit.cxx
20 // Author:    Sergey TELKOV
21
22 #include "QtxListResourceEdit.h"
23
24 #include <qhbox.h>
25 #include <qvbox.h>
26 #include <qlabel.h>
27 #include <qlayout.h>
28 #include <qlistbox.h>
29 #include <qcombobox.h>
30 #include <qlineedit.h>
31 #include <qcheckbox.h>
32 #include <qtabwidget.h>
33 #include <qvalidator.h>
34 #include <qobjectlist.h>
35 #include <qcolordialog.h>
36 #include <qwidgetstack.h>
37 #include <qtoolbutton.h>
38 #include <qfontdialog.h>
39 #include <qfontdatabase.h>
40 #include <qfileinfo.h>
41 #include <qfiledialog.h>
42 #include <qapplication.h>
43
44 #include "QtxIntSpinBox.h"
45 #include "QtxDblSpinBox.h"
46 #include "QtxComboBox.h"
47 #include "QtxDirListEditor.h"
48
49 /*!
50   Constructor
51 */
52 QtxListResourceEdit::QtxListResourceEdit( QtxResourceMgr* mgr, QWidget* parent )
53 : QFrame( parent ),
54 QtxResourceEdit( mgr )
55 {
56   QVBoxLayout* main = new QVBoxLayout( this, 0, 5 );
57   QGroupBox* base = new QGroupBox( 1, Qt::Vertical, "", this );
58   base->setFrameStyle( QFrame::NoFrame );
59   base->setInsideMargin( 0 );
60   main->addWidget( base );
61
62   myList  = new QListBox( base );
63   myStack = new QWidgetStack( base );
64
65   myList->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) );
66   myStack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
67
68   myList->setSelectionMode( QListBox::Single );
69
70   connect( myList, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
71
72   setFocusProxy( myList );
73
74   updateState();
75 }
76
77 /*!
78   Destructor
79 */
80 QtxListResourceEdit::~QtxListResourceEdit()
81 {
82 }
83
84 /*!
85   Sets value to widget
86   \param id - id of widget
87   \param prop - name of resource
88   \param val - value of resource
89 */
90 void QtxListResourceEdit::setItemProperty( const int id, const QString& prop, const QVariant& val )
91 {
92   Item* i = item( id );
93   if ( !i )
94     return;
95
96   bool prev = i->isEmpty();
97
98   QtxResourceEdit::setItemProperty( id, prop, val );
99
100   bool next = i->isEmpty();
101
102   if ( prev != next )
103     updateVisible();
104 }
105
106 /*!
107   SLOT: called if main list selection changed, raises resource group widgets
108 */
109 void QtxListResourceEdit::onSelectionChanged()
110 {
111   QString title = myList->text( myList->index( myList->selectedItem() ) );
112   if ( title.isEmpty() )
113     return;
114
115   Item* i = 0;
116   QPtrList<Item> lst;
117   childItems( lst );
118   for ( QPtrListIterator<Item> it( lst ); it.current() && !i; ++it )
119   {
120     if ( it.current()->title() == title )
121       i = it.current();
122   }
123
124   if ( i )
125     myStack->raiseWidget( i->id() );
126 }
127
128 /*!
129   Custom activity after item addition
130   \param i - added item
131 */
132 void QtxListResourceEdit::itemAdded( QtxResourceEdit::Item* i )
133 {
134   if ( !i )
135     return;
136
137   QPtrList<Item> items;
138   childItems( items );
139
140   if ( items.contains( i ) || items.contains( i->parentItem() ) )
141     updateVisible();
142 }
143
144 /*!
145   Creates and \return category
146   \param title - category title
147 */
148 QtxResourceEdit::Item* QtxListResourceEdit::createItem( const QString& title, const int )
149 {
150   Item* i = item( title, -1 );
151   if ( i )
152     return i;
153
154   Category* category = new Category( this, myStack );
155   myStack->addWidget( category, category->id() );
156
157   updateVisible();
158
159   if ( !myList->selectedItem() )
160     myList->setSelected( 0, true );
161
162   updateState();
163
164   return category;
165 }
166
167 /*!
168   Emits signal about resource changing
169   \param map - map of changed resources
170 */
171 void QtxListResourceEdit::changedResources( const QMap<Item*, QString>& map )
172 {
173   QMap<int, QString> idMap;
174   for ( QMap<Item*, QString>::ConstIterator it = map.begin(); it != map.end(); ++it )
175   {
176     idMap.insert( it.key()->id(), it.data() );
177
178     emit resourceChanged( it.key()->id() );
179
180     QString sec, param;
181     it.key()->resource( sec, param );
182     emit resourceChanged( sec, param );
183   }
184
185   emit resourcesChanged( idMap );
186 }
187
188 /*!
189   Updates widgets with accordance with main list selection
190 */
191 void QtxListResourceEdit::updateState()
192 {
193   if ( myList->selectedItem() &&  myStack->visibleWidget() )
194     myStack->show();
195   else
196     myStack->hide();
197
198   myList->setShown( myList->count() > 1 );
199 }
200
201 /*!
202   Updates visibility state
203 */
204 void QtxListResourceEdit::updateVisible()
205 {
206   QPtrList<Item> items;
207   childItems( items );
208
209   QString name = myList->text( myList->index( myList->selectedItem() ) );
210
211   myList->clear();
212   for ( QPtrListIterator<Item> it( items ); it.current(); ++it )
213   {
214     if ( it.current()->isEmpty() )
215       continue;
216
217     myList->insertItem( it.current()->title() );
218   }
219
220   int idx = -1;
221   for ( int i = 0; i < (int)myList->count() && idx == -1; i++ )
222   {
223     if ( myList->text( i ) == name )
224       idx = i;
225   }
226
227   myList->setSelected( QMAX( idx, 0 ), true );
228
229   updateState();
230 }
231
232 /*!
233   Constructor
234 */
235 QtxListResourceEdit::Category::Category( QtxListResourceEdit* edit, QWidget* parent )
236 : QFrame( parent ),
237 Item( edit )
238 {
239   QVBoxLayout* main = new QVBoxLayout( this );
240   QGroupBox* base = new QGroupBox( 1, Qt::Horizontal, "", this );
241   base->setFrameStyle( QFrame::NoFrame );
242   base->setInsideMargin( 0 );
243   main->addWidget( base, 1 );
244
245   myTabs = new QTabWidget( base );
246   myInfo = new QLabel( base );
247
248   myInfo->setAlignment( Qt::AlignCenter );
249   myInfo->setFrameStyle( QFrame::WinPanel | QFrame::Raised );
250   myInfo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
251
252   updateState();
253 }
254
255 /*!
256   Destructor
257 */
258 QtxListResourceEdit::Category::~Category()
259 {
260 }
261
262 /*!
263   \return true if it is empty
264 */
265 bool QtxListResourceEdit::Category::isEmpty() const
266 {
267   return Item::isEmpty() && myInfo->text().isEmpty();
268 }
269
270 /*!
271   \return category type
272 */
273 int QtxListResourceEdit::Category::type() const
274 {
275   return -1;
276 }
277
278 /*!
279   Default empty implementation of resources storing
280 */
281 void QtxListResourceEdit::Category::store()
282 {
283 }
284
285 /*!
286   Default empty implementation of resources retrieving
287 */
288 void QtxListResourceEdit::Category::retrieve()
289 {
290 }
291
292 /*!
293   \return value of property
294   \param prop - property name
295 */
296 QVariant QtxListResourceEdit::Category::property( const QString& prop ) const
297 {
298   QVariant var;
299   if ( prop == QString( "information" ) || prop == QString( "info" ) )
300     var = myInfo->text();
301   return var;
302 }
303
304 /*!
305   Sets property value
306   \param name - name of property
307   \param var - value of property
308 */
309 void QtxListResourceEdit::Category::setProperty( const QString& name, const QVariant& var )
310 {
311   QVariant prop = var;
312   if ( !prop.cast( QVariant::String ) )
313     return;
314
315   if ( name == QString( "information" ) || name == QString( "info" ) )
316     myInfo->setText( prop.toString() );
317
318   updateState();
319 }
320
321 /*!
322   Creates new tab
323   \param title - name of tab
324 */
325 QtxResourceEdit::Item* QtxListResourceEdit::Category::createItem( const QString& title, const int )
326 {
327   Item* i = item( title, id() );
328   if ( i )
329     return i;
330
331   Tab* tab = new Tab( resourceEdit(), this, this );
332   myTabs->addTab( tab, title );
333
334   updateState();
335
336   return tab;
337 }
338
339 /*!
340   Updates category
341 */
342 void QtxListResourceEdit::Category::updateState()
343 {
344   if ( myTabs->count() )
345     myTabs->show();
346   else
347     myTabs->hide();
348
349   if ( !myTabs->count() && !myInfo->text().isEmpty() )
350     myInfo->show();
351   else
352     myInfo->hide();
353 }
354
355
356 /*!
357   Constructor
358 */
359 QtxListResourceEdit::Tab::Tab( QtxResourceEdit* edit, Item* pItem, QWidget* parent )
360 : QFrame( parent ),
361 Item( edit, pItem )
362 {
363   QVBoxLayout* main = new QVBoxLayout( this );
364   QVBox* vbox = new QVBox( this );
365   vbox->setMargin( 5 );
366   myMainFrame = vbox;
367   main->addWidget( myMainFrame );
368   main->addStretch( 1 );
369 }
370
371 /*!
372   Destructor
373 */
374 QtxListResourceEdit::Tab::~Tab()
375 {
376 }
377
378 /*!
379   \return tab type
380 */
381 int QtxListResourceEdit::Tab::type() const
382 {
383   return -1;
384 }
385
386 /*!
387   Default empty implementation of resources storing
388 */
389 void QtxListResourceEdit::Tab::store()
390 {
391 }
392
393 /*!
394   Default empty implementation of resources retrieving
395 */
396 void QtxListResourceEdit::Tab::retrieve()
397 {
398 }
399
400 /*!
401   Delayed initialization of a widget
402 */
403 void QtxListResourceEdit::Tab::polish()
404 {
405   QFrame::polish();
406
407   adjustLabels();
408 }
409
410 /*!
411   Creates new group
412   \param title - name of group
413 */
414 QtxResourceEdit::Item* QtxListResourceEdit::Tab::createItem( const QString& title, const int )
415 {
416   Item* i = item( title, id() );
417   if ( i )
418     return i;
419
420   Group* group = new Group( title, resourceEdit(), this, myMainFrame );
421
422   return group;
423 }
424
425 /*!
426   Adjusts sizes of labels
427 */
428 void QtxListResourceEdit::Tab::adjustLabels()
429 {
430   QObjectList* labels = queryList( "QLabel" );
431   if ( labels )
432   {
433     int w = 0;
434     for ( QObjectListIt it1( *labels ); it1.current(); ++it1 )
435     {
436       if ( it1.current()->isWidgetType() )
437       {
438         QWidget* wid = (QWidget*)it1.current();
439         w = QMAX( w, wid->sizeHint().width() );
440       }
441     }
442     for ( QObjectListIt it2( *labels ); it2.current(); ++it2 )
443     {
444       if ( it2.current()->isWidgetType() )
445       {
446         QWidget* wid = (QWidget*)it2.current();
447         wid->setMinimumWidth( w );
448       }
449     }
450     delete labels;
451   }
452 }
453
454 /*!
455   Constructor
456 */
457 QtxListResourceEdit::Group::Group( const QString& title, QtxResourceEdit* edit, Item* pItem, QWidget* parent )
458 : QGroupBox( 2, Qt::Horizontal, title, parent ),
459 Item( edit, pItem )
460 {
461 }
462
463 /*!
464   Destructor
465 */
466 QtxListResourceEdit::Group::~Group()
467 {
468 }
469
470 /*!
471   \return group type
472 */
473 int QtxListResourceEdit::Group::type() const
474 {
475   return -1;
476 }
477
478 /*!
479   Default empty implementation of resources storing
480 */
481 void QtxListResourceEdit::Group::store()
482 {
483 }
484
485 /*!
486   Default empty implementation of resources retrieving
487 */
488 void QtxListResourceEdit::Group::retrieve()
489 {
490 }
491
492 /*!
493   \return value of property
494   \param prop - property name
495 */
496 QVariant QtxListResourceEdit::Group::property( const QString& prop ) const
497 {
498   QVariant var;
499   if ( prop == "columns" )
500     var = QVariant( columns() );
501   else if ( prop == "orientation" )
502     var = QVariant( orientation() );
503   else if ( prop == "frame" )
504     var = QVariant( frameStyle() != QFrame::NoFrame );
505   return var;
506 }
507
508 /*!
509   Sets property value
510   \param name - name of property
511   \param var - value of property
512 */
513 void QtxListResourceEdit::Group::setProperty( const QString& name, const QVariant& var )
514 {
515   QVariant prop = var;
516   if ( !prop.cast( QVariant::Int ) )
517     return;
518
519   if ( name == QString( "columns" ) && prop.cast( QVariant::Int ) && prop.toInt() > 0 )
520     setColumns( prop.toInt() );
521   else if ( name == QString( "orientation" ) && prop.cast( QVariant::Int ) )
522   {
523     int o = prop.toInt();
524     if ( o == Qt::Horizontal || o == Qt::Vertical )
525       setOrientation( (Orientation)o );
526   }
527   else if ( name == "frame" && prop.cast( QVariant::Bool ) )
528   {
529     setInsideMargin( prop.toBool() ? 5 : 0 );
530     QGroupBox::setTitle( prop.toBool() ? Item::title() : QString::null );
531     setFrameStyle( prop.toBool() ? QFrame::Box | QFrame::Sunken : QFrame::NoFrame );
532   }
533 }
534
535 /*!
536   Sets title of group
537   \param title - new title of group
538 */
539 void QtxListResourceEdit::Group::setTitle( const QString& title )
540 {
541   Item::setTitle( title );
542   QGroupBox::setTitle( title );
543 }
544
545 /*!
546   Creates new item
547   \param title - title of new item
548   \type - type of new item
549 */
550 QtxResourceEdit::Item* QtxListResourceEdit::Group::createItem( const QString& title, const int type )
551 {
552   Item* item = 0;
553
554   switch ( type )
555   {
556   case Color:
557     item = new ColorItem( title, resourceEdit(), this, this );
558     break;
559   case Bool:
560     item = new StateItem( title, resourceEdit(), this, this );
561     break;
562   case String:
563     item = new StringItem( title, resourceEdit(), this, this );
564     break;
565   case Selector:
566     item = new SelectItem( title, resourceEdit(), this, this );
567     break;
568   case DblSpin:
569     item = new DoubleSpinItem( title, resourceEdit(), this, this );
570     break;
571   case IntSpin:
572     item = new IntegerSpinItem( title, resourceEdit(), this, this );
573     break;
574   case Double:
575     item = new DoubleEditItem( title, resourceEdit(), this, this );
576     break;
577   case Integer:
578     item = new IntegerEditItem( title, resourceEdit(), this, this );
579     break;
580   case Space:
581     item = new Spacer( resourceEdit(), this, this );
582     break;
583   case GroupBox:
584     item = new Group( title, resourceEdit(), this, this );
585     break;
586   case Font:
587     item = new FontItem( title, resourceEdit(), this, this );
588     break;
589   case DirList:
590     item = new DirListItem( title, resourceEdit(), this, this );
591     break;
592   case File:
593     item = new FileItem( title, resourceEdit(), this, this );
594     break;
595   }
596
597   return item;
598 }
599
600 /*!
601   Constructor
602 */
603 QtxListResourceEdit::PrefItem::PrefItem( const int type, QtxResourceEdit* edit, Item* pi, QWidget* parent )
604 : QHBox( parent ),
605 Item( edit, pi ),
606 myType( type )
607 {
608   setSpacing( 5 );
609 }
610
611 /*!
612   Destructor
613 */
614 QtxListResourceEdit::PrefItem::~PrefItem()
615 {
616 }
617
618 /*!
619   \return preference item type
620 */
621 int QtxListResourceEdit::PrefItem::type() const
622 {
623   return myType;
624 }
625
626 /*!
627   Doesn't create item, \return 0 by default
628 */
629 QtxResourceEdit::Item* QtxListResourceEdit::PrefItem::createItem( const QString&, const int )
630 {
631   return 0;
632 }
633
634 /*!
635   Constructor
636 */
637 QtxListResourceEdit::Spacer::Spacer( QtxResourceEdit* edit, Item* pItem, QWidget* parent )
638 : PrefItem( Space, edit, pItem, parent )
639 {
640   setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
641 }
642
643 /*!
644   Destructor
645 */
646 QtxListResourceEdit::Spacer::~Spacer()
647 {
648 }
649
650 /*!
651   Default empty implementation of resources storing
652 */
653 void QtxListResourceEdit::Spacer::store()
654 {
655 }
656
657 /*!
658   Default empty implementation of resources retrieving
659 */
660 void QtxListResourceEdit::Spacer::retrieve()
661 {
662 }
663
664 /*!
665   Constructor
666 */
667 QtxListResourceEdit::SelectItem::SelectItem( const QString& title, QtxResourceEdit* edit,
668                                              Item* pItem, QWidget* parent )
669 : PrefItem( Selector, edit, pItem, parent )
670 {
671   new QLabel( title, this );
672   myList = new QComboBox( false, this );
673   myList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
674 }
675
676 /*!
677   Destructor
678 */
679 QtxListResourceEdit::SelectItem::~SelectItem()
680 {
681 }
682
683 /*!
684   Stores value to resource manager
685 */
686 void QtxListResourceEdit::SelectItem::store()
687 {
688   int idx = myList->currentItem();
689   if ( myIndex.contains( idx ) )
690     setInteger( myIndex[idx] );
691 }
692
693 /*!
694   Retrieve value to resource manager
695 */
696 void QtxListResourceEdit::SelectItem::retrieve()
697 {
698   int id = getInteger( -1 );
699
700   int idx = -1;
701   for ( QMap<int, int>::ConstIterator it = myIndex.begin(); it != myIndex.end() && idx == -1; ++it )
702   {
703     if ( it.data() == id )
704       idx = it.key();
705   }
706
707   myList->setCurrentItem( idx );
708 }
709
710 /*!
711   \return value of property
712   \param prop - property name
713 */
714 QVariant QtxListResourceEdit::SelectItem::property( const QString& name ) const
715 {
716   QVariant val;
717   if ( name == QString( "strings" ) )
718   {
719     QStringList lst;
720     for ( int i = 0; i < (int)myList->count(); i++ )
721       lst.append( myList->text( i ) );
722     val = QVariant( lst );
723   }
724   else if ( name == QString( "indexes" ) )
725   {
726     QValueList<QVariant> lst;
727     for ( int i = 0; i < (int)myList->count(); i++ )
728       lst.append( myIndex.contains( i ) ? myIndex[i] : 0 );
729     val = QVariant( lst );
730   }
731   return val;
732 }
733
734 /*!
735   Sets property value
736   \param name - name of property
737   \param var - value of property
738 */
739 void QtxListResourceEdit::SelectItem::setProperty( const QString& name, const QVariant& val )
740 {
741   if ( name == QString( "strings" ) )
742     setStrings( val );
743   else if ( name == QString( "indexes" ) )
744     setIndexes( val );
745 }
746
747 /*!
748   Sets property "strings" - items for selection in combo box
749   \param var - must be string list: list of items
750 */
751 void QtxListResourceEdit::SelectItem::setStrings( const QVariant& var )
752 {
753   if ( var.type() != QVariant::StringList )
754     return;
755
756   setStrings( var.toStringList() );
757 }
758
759 /*!
760   Sets property "indexes" - corresponding indices of items in combo box
761   \param var - must be list of integer variants: list of indices
762 */
763 void QtxListResourceEdit::SelectItem::setIndexes( const QVariant& var )
764 {
765   if ( var.type() != QVariant::List )
766     return;
767
768   QValueList<QVariant> varList = var.toList();
769   QValueList<int> lst;
770   for ( QValueList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it )
771   {
772     if ( (*it).canCast( QVariant::Int ) )
773       lst.append( (*it).toInt() );
774   }
775   setIndexes( lst );
776 }
777
778 /*!
779   Sets property "strings" - items for selection in combo box
780   \param lst - list of items
781 */
782 void QtxListResourceEdit::SelectItem::setStrings( const QStringList& lst )
783 {
784   myList->clear();
785   myList->insertStringList( lst );
786 }
787
788 /*!
789   Sets property "indexes" - corresponding indices of items in combo box
790   \param var - list of indices
791 */
792 void QtxListResourceEdit::SelectItem::setIndexes( const QValueList<int>& lst )
793 {
794   myIndex.clear();
795
796   int idx = 0;
797   for ( QValueList<int>::const_iterator it = lst.begin(); it != lst.end(); ++it, idx++ )
798     myIndex.insert( idx, *it );
799 }
800
801 /*!
802   Constructor
803 */
804 QtxListResourceEdit::StateItem::StateItem( const QString& title, QtxResourceEdit* edit,
805                                            Item* pItem, QWidget* parent )
806 : PrefItem( Bool, edit, pItem, parent )
807 {
808   myState = new QCheckBox( title, this );
809   myState->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
810 }
811
812 /*!
813   Destructor
814 */
815 QtxListResourceEdit::StateItem::~StateItem()
816 {
817 }
818
819 /*!
820   Stores value to resource manager
821 */
822 void QtxListResourceEdit::StateItem::store()
823 {
824   setBoolean( myState->isChecked() );
825 }
826
827 /*!
828   Retrieve value to resource manager
829 */
830 void QtxListResourceEdit::StateItem::retrieve()
831 {
832   myState->setChecked( getBoolean() );
833 }
834
835 /*!
836   Constructor
837 */
838 QtxListResourceEdit::StringItem::StringItem( const QString& title, QtxResourceEdit* edit,
839                                              Item* pItem, QWidget* parent )
840 : PrefItem( String, edit, pItem, parent )
841 {
842   new QLabel( title, this );
843   myString = new QLineEdit( this );
844   myString->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
845 }
846
847 /*!
848   Destructor
849 */
850 QtxListResourceEdit::StringItem::~StringItem()
851 {
852 }
853
854 /*!
855   Stores value to resource manager
856 */
857 void QtxListResourceEdit::StringItem::store()
858 {
859   setString( myString->text() );
860 }
861
862 /*!
863   Retrieve value to resource manager
864 */
865 void QtxListResourceEdit::StringItem::retrieve()
866 {
867   myString->setText( getString() );
868 }
869
870 /*!
871   Constructor
872 */
873 QtxListResourceEdit::IntegerEditItem::IntegerEditItem( const QString& title, QtxResourceEdit* edit, Item* pItem, QWidget* parent )
874 : PrefItem( Integer, edit, pItem, parent )
875 {
876   new QLabel( title, this );
877   myInteger = new QLineEdit( this );
878   myInteger->setValidator( new QIntValidator( myInteger ) );
879   myInteger->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
880 }
881
882 /*!
883   Destructor
884 */
885 QtxListResourceEdit::IntegerEditItem::~IntegerEditItem()
886 {
887 }
888
889 /*!
890   Stores value to resource manager
891 */
892 void QtxListResourceEdit::IntegerEditItem::store()
893 {
894   setString( myInteger->text() );
895 }
896
897 /*!
898   Retrieve value to resource manager
899 */
900 void QtxListResourceEdit::IntegerEditItem::retrieve()
901 {
902   myInteger->setText( getString() );
903 }
904
905 /*!
906   Constructor
907 */
908 QtxListResourceEdit::IntegerSpinItem::IntegerSpinItem( const QString& title, QtxResourceEdit* edit, Item* pItem, QWidget* parent )
909 : PrefItem( IntSpin, edit, pItem, parent )
910 {
911   new QLabel( title, this );
912   myInteger = new QtxIntSpinBox( this );
913   myInteger->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
914 }
915
916 /*!
917   Destructor
918 */
919 QtxListResourceEdit::IntegerSpinItem::~IntegerSpinItem()
920 {
921 }
922
923 /*!
924   Stores value to resource manager
925 */
926 void QtxListResourceEdit::IntegerSpinItem::store()
927 {
928   setInteger( myInteger->value() );
929 }
930
931 /*!
932   Retrieve value to resource manager
933 */
934 void QtxListResourceEdit::IntegerSpinItem::retrieve()
935 {
936   myInteger->setValue( getInteger() );
937 }
938
939 /*!
940   \return value of property
941   \param prop - property name
942 */
943 QVariant QtxListResourceEdit::IntegerSpinItem::property( const QString& name ) const
944 {
945   QVariant var;
946   if ( name == QString( "minimum" ) || name == QString( "min" ) )
947     var = QVariant( myInteger->minValue() );
948   else if ( name == QString( "maximum" ) || name == QString( "max" ) )
949     var = QVariant( myInteger->maxValue() );
950   else if ( name == QString( "step" ) )
951     var = QVariant( myInteger->lineStep() );
952   else if ( name == QString( "special" ) )
953     var = QVariant( myInteger->specialValueText() );
954   else if ( name == QString( "prefix" ) )
955     var = QVariant( myInteger->prefix() );
956   else if ( name == QString( "suffix" ) )
957     var = QVariant( myInteger->suffix() );
958   return var;
959 }
960
961 /*!
962   Sets property value
963   \param name - name of property
964   \param var - value of property
965 */
966 void QtxListResourceEdit::IntegerSpinItem::setProperty( const QString& name, const QVariant& var )
967 {
968   QVariant prop = var;
969
970   if ( ( name == QString( "minimum" ) || name == QString( "min" ) ) && prop.cast( QVariant::Int ) )
971     myInteger->setMinValue( prop.toInt() );
972   else if ( ( name == QString( "maximum" ) || name == QString( "max" ) ) && prop.cast( QVariant::Int ) )
973     myInteger->setMaxValue( prop.toInt() );
974   else if ( name == QString( "step" ) && prop.cast( QVariant::Int ) && prop.toInt() > 0 )
975     myInteger->setLineStep( prop.toInt() );
976   else if ( name == QString( "special" ) && prop.cast( QVariant::String ) )
977     myInteger->setSpecialValueText( prop.toString() );
978   else if ( name == QString( "prefix" ) && prop.cast( QVariant::String ) )
979     myInteger->setPrefix( prop.toString() );
980   else if ( name == QString( "suffix" ) && prop.cast( QVariant::String ) )
981     myInteger->setSuffix( prop.toString() );
982 }
983
984 /*!
985   Constructor
986 */
987 QtxListResourceEdit::DoubleEditItem::DoubleEditItem( const QString& title, QtxResourceEdit* edit,
988                                                      Item* pItem, QWidget* parent )
989 : PrefItem( Double, edit, pItem, parent )
990 {
991   new QLabel( title, this );
992   myDouble = new QLineEdit( this );
993   myDouble->setValidator( new QDoubleValidator( myDouble ) );
994   myDouble->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
995 }
996
997 /*!
998   Destructor
999 */
1000 QtxListResourceEdit::DoubleEditItem::~DoubleEditItem()
1001 {
1002 }
1003
1004 /*!
1005   Stores value to resource manager
1006 */
1007 void QtxListResourceEdit::DoubleEditItem::store()
1008 {
1009   setString( myDouble->text() );
1010 }
1011
1012 /*!
1013   Retrieve value to resource manager
1014 */
1015 void QtxListResourceEdit::DoubleEditItem::retrieve()
1016 {
1017   myDouble->setText( getString() );
1018 }
1019
1020 /*!
1021   Constructor
1022 */
1023 QtxListResourceEdit::DoubleSpinItem::DoubleSpinItem( const QString& title, QtxResourceEdit* edit,
1024                                                      Item* pItem, QWidget* parent )
1025 : PrefItem( DblSpin, edit, pItem, parent )
1026 {
1027   new QLabel( title, this );
1028   myDouble = new QtxDblSpinBox( this );
1029   myDouble->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1030 }
1031
1032 /*!
1033   Destructor
1034 */
1035 QtxListResourceEdit::DoubleSpinItem::~DoubleSpinItem()
1036 {
1037 }
1038
1039 /*!
1040   Stores value to resource manager
1041 */
1042 void QtxListResourceEdit::DoubleSpinItem::store()
1043 {
1044   setDouble( myDouble->value() );
1045 }
1046
1047 /*!
1048   Retrieve value to resource manager
1049 */
1050 void QtxListResourceEdit::DoubleSpinItem::retrieve()
1051 {
1052   myDouble->setValue( getDouble() );
1053 }
1054
1055 /*!
1056   \return value of property
1057   \param prop - property name
1058 */
1059 QVariant QtxListResourceEdit::DoubleSpinItem::property( const QString& name ) const
1060 {
1061   QVariant var;
1062   if ( name == QString( "minimum" ) || name == QString( "min" ) )
1063     var = QVariant( myDouble->minValue() );
1064   else if ( name == QString( "maximum" ) || name == QString( "max" ) )
1065     var = QVariant( myDouble->maxValue() );
1066   else if ( name == QString( "precision" ) )
1067     var = QVariant( myDouble->precision() );
1068   else if ( name == QString( "step" ) )
1069     var = QVariant( myDouble->lineStep() );
1070   else if ( name == QString( "special" ) )
1071     var = QVariant( myDouble->specialValueText() );
1072   else if ( name == QString( "prefix" ) )
1073     var = QVariant( myDouble->prefix() );
1074   else if ( name == QString( "suffix" ) )
1075     var = QVariant( myDouble->suffix() );
1076   return var;
1077 }
1078
1079 /*!
1080   Sets property value
1081   \param name - name of property
1082   \param var - value of property
1083 */
1084 void QtxListResourceEdit::DoubleSpinItem::setProperty( const QString& name, const QVariant& var )
1085 {
1086   QVariant prop = var;
1087
1088   if ( ( name == QString( "minimum" ) || name == QString( "min" ) ) && prop.cast( QVariant::Double ) )
1089     myDouble->setMinValue( prop.toDouble() );
1090   else if ( ( name == QString( "maximum" ) || name == QString( "max" ) ) && prop.cast( QVariant::Double ) )
1091     myDouble->setMaxValue( prop.toDouble() );
1092   else if ( name == QString( "step" ) && prop.cast( QVariant::Double ) && prop.toDouble() > 0 )
1093     myDouble->setLineStep( prop.toDouble() );
1094   else if ( name == QString( "precision" ) && prop.cast( QVariant::Int ) && prop.toInt() > 0 )
1095     myDouble->setPrecision( prop.toInt() );
1096   else if ( name == QString( "special" ) && prop.cast( QVariant::String ) )
1097     myDouble->setSpecialValueText( prop.toString() );
1098   else if ( name == QString( "prefix" ) && prop.cast( QVariant::String ) )
1099     myDouble->setPrefix( prop.toString() );
1100   else if ( name == QString( "suffix" ) && prop.cast( QVariant::String ) )
1101     myDouble->setSuffix( prop.toString() );
1102 }
1103
1104 /*!
1105   Constructor
1106 */
1107 QtxListResourceEdit::ColorItem::ColorItem( const QString& title, QtxResourceEdit* edit,
1108                                            Item* pItem, QWidget* parent )
1109 : PrefItem( Color, edit, pItem, parent )
1110 {
1111   /*!
1112     \class QtxListResourceEdit::ColorItem::ColorSelector
1113     \brief Label, showing color and allowing to pick color with help of standard color dialog
1114   */
1115   class ColorSelector : public QLabel
1116   {
1117   public:
1118     ColorSelector( QWidget* parent = 0 ) : QLabel( parent )
1119     {
1120       setFrameStyle( WinPanel | Raised );
1121     }
1122     virtual ~ColorSelector() {}
1123     virtual QSize minimumSizeHint() const
1124     {
1125       return QLabel::minimumSizeHint() + QSize( 0, 2 );
1126     }
1127
1128   protected:
1129     virtual void mousePressEvent( QMouseEvent* e )
1130     {
1131       if ( e->button() == LeftButton )
1132       {
1133         setFrameStyle( WinPanel | Sunken );
1134         QColor c = QColorDialog::getColor( paletteBackgroundColor(), this );
1135         if ( c.isValid() )
1136           setPaletteBackgroundColor( c );
1137
1138         setFrameStyle( WinPanel | Raised );
1139       }
1140     }
1141   };
1142
1143   new QLabel( title, this );
1144   myColor = new ColorSelector( this );
1145   myColor->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1146 }
1147
1148 /*!
1149   Destructor
1150 */
1151 QtxListResourceEdit::ColorItem::~ColorItem()
1152 {
1153 }
1154
1155 /*!
1156   Stores value to resource manager
1157 */
1158 void QtxListResourceEdit::ColorItem::store()
1159 {
1160   setColor( myColor->paletteBackgroundColor() );
1161 }
1162
1163 /*!
1164   Retrieve value to resource manager
1165 */
1166 void QtxListResourceEdit::ColorItem::retrieve()
1167 {
1168   myColor->setPaletteBackgroundColor( getColor() );
1169 }
1170
1171
1172 /*!
1173   Constructor
1174 */
1175 QtxListResourceEdit::FontItem::FontItem( const QString& title, QtxResourceEdit* edit,
1176                                          Item* pItem, QWidget* parent )
1177 : PrefItem( Font, edit, pItem, parent )
1178 {
1179   new QLabel( title, this );
1180   myFamilies = new QtxComboBox( false, this );
1181   mySizes = new QtxComboBox( true, this );
1182   mySizes->setInsertionPolicy( QComboBox::NoInsertion );
1183   myBold = new QCheckBox( tr( "Bold" ), this );
1184   myItalic = new QCheckBox( tr( "Italic" ), this );
1185   myUnderline = new QCheckBox( tr( "Underline" ), this );
1186   myPreview = new QToolButton( this );
1187   myPreview->setText( "..." );
1188
1189   myFamilies->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
1190   mySizes->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
1191
1192   connect( myFamilies, SIGNAL( activated( int ) ), this, SLOT( onActivateFamily( int ) ) );
1193   connect( myPreview, SIGNAL( clicked() ), this, SLOT( onPreview() ) );
1194
1195   setProperty( "system", ( bool )true );
1196   setProperty( "widget_flags", ( int )All );
1197 }
1198
1199 /*!
1200   Destructor
1201 */
1202 QtxListResourceEdit::FontItem::~FontItem()
1203 {
1204 }
1205
1206 /*!
1207   Stores value to resource manager
1208 */
1209 void QtxListResourceEdit::FontItem::store()
1210 {
1211   QFont f( family(), size() );
1212   bool bold, italic, underline;
1213   params( bold, italic, underline );
1214   f.setBold( bold );
1215   f.setItalic( italic );
1216   f.setUnderline( underline );
1217   Item::setFont( f );
1218 }
1219
1220 /*!
1221   Retrieve value to resource manager
1222 */
1223 void QtxListResourceEdit::FontItem::retrieve()
1224 {
1225   QFont f = getFont();
1226   setFamily( f.family() );
1227   setSize( f.pointSize() );
1228   setParams( f.bold(), f.italic(), f.underline() );
1229 }
1230
1231 /*!
1232   \return value of property
1233   \param prop - property name
1234 */
1235 QVariant QtxListResourceEdit::FontItem::property( const QString& name ) const
1236 {
1237   if( name=="system" )
1238     return myIsSystem;
1239
1240   else if( name=="widget_flags" )
1241     return ( int )myFlags;
1242   
1243   if( myIsSystem )
1244   {
1245     if( name=="families" )
1246     {
1247       QFontDatabase fdb;
1248       return fdb.families();
1249     }
1250
1251     else if( name=="default_family" )
1252     {
1253       QFontDatabase fdb;
1254       QStringList fam = fdb.families();
1255       if( fam.count()>0 )
1256         return fam.first();
1257       else
1258         return QString::null;
1259     }
1260
1261     else
1262     {
1263       QStringList parts = QStringList::split( ":", name );
1264       if( parts.count()==2 )
1265       {
1266         if( parts[1]=="default_bold" || parts[1]=="default_italic" || parts[1]=="default_underline" )
1267           return false;
1268
1269         else if( parts[1]=="sizes" )
1270         {
1271           QFontDatabase fdb;
1272           QValueList<int> sizes = fdb.pointSizes( parts[0] );
1273           QValueList<QVariant> vsizes;
1274           QValueList<int>::const_iterator anIt = sizes.begin(),
1275                                           aLast = sizes.end();
1276           for( ; anIt!=aLast; anIt++ )
1277             vsizes.append( *anIt );
1278
1279           return vsizes;
1280         }
1281
1282         else if( parts[1]=="default_size" )
1283         {
1284           if( parts[0].isEmpty() )
1285             return 0;
1286             
1287           QFontDatabase fdb;
1288           QValueList<int> sizes = fdb.pointSizes( parts[0] );
1289           if( sizes.count()>0 )
1290             return sizes.first();
1291           else
1292             return 0;
1293         }
1294       }
1295     }
1296   }
1297
1298   else if( myProperties.contains( name ) )
1299     return myProperties[ name ];
1300
1301   return QVariant();
1302 }
1303
1304 /*!
1305   Sets property value
1306   \param name - name of property
1307   \param var - value of property
1308 */
1309 void QtxListResourceEdit::FontItem::setProperty( const QString& name, const QVariant& value )
1310 {
1311   if( name=="system" )
1312   {
1313     if( !value.canCast( QVariant::Bool ) )
1314       return;
1315
1316     bool isSystem = value.toBool();
1317     if( myIsSystem==isSystem )
1318       return;
1319
1320     myIsSystem = isSystem;
1321
1322     QVariant families = property( "families" );
1323     QString fam = family();
1324
1325     myFamilies->clear();
1326     if( families.canCast( QVariant::StringList ) )
1327     {
1328       QStringList list = families.toStringList();
1329       myFamilies->insertStringList( list );
1330     }
1331
1332     setFamily( fam );
1333     setSize( -1 ); //set default size
1334   }
1335   
1336   else if( name=="widget_flags" )
1337   {
1338     if( !value.canCast( QVariant::Int ) )
1339       return;
1340
1341     int wf = value.toInt();
1342     
1343     myFlags = wf;
1344     myFamilies ->setShown( wf & Family );
1345     mySizes    ->setShown( wf & Size );
1346     mySizes->lineEdit()->setReadOnly( ( wf & UserSize )==0 );
1347     myBold     ->setShown( wf & Bold );
1348     myItalic   ->setShown( wf & Italic );
1349     myUnderline->setShown( wf & Underline );
1350     bool isSystem = property( "system" ).canCast( QVariant::Bool ) ? property( "system" ).toBool() : false;
1351     myPreview->setShown( ( wf & Preview ) && isSystem );
1352
1353     internalUpdate();
1354   }
1355   
1356   else
1357     myProperties[ name ] = value;
1358 }
1359
1360 /*!
1361   Sets family of font
1362   \param f - new family
1363 */
1364 void QtxListResourceEdit::FontItem::setFamily( const QString& f )
1365 {
1366   QString curtext;
1367   if( myFamilies->isShown() )
1368   {
1369     if( myFamilies->listBox()->findItem( f, Qt::ExactMatch ) )
1370       curtext = f;
1371   }
1372   else
1373   {
1374     QVariant deffam = property( "default_family" );
1375     if( deffam.canCast( QVariant::String ) )
1376       curtext = deffam.toString();
1377   }
1378   
1379   if ( curtext.isEmpty() )
1380     curtext = (QApplication::font()).family();
1381
1382   int idx = -1;
1383   for ( int i = 0; i < (int)myFamilies->count() && idx < 0; i++ )
1384   {
1385     if ( myFamilies->text( i ) == curtext )
1386       idx = i;
1387   }
1388
1389   if ( idx >= 0 )
1390     myFamilies->setCurrentItem( idx );
1391
1392   onActivateFamily( idx );  
1393 }
1394
1395 /*!
1396   \return family of font
1397 */
1398 QString QtxListResourceEdit::FontItem::family() const
1399 {
1400   return myFamilies->currentText();
1401 }
1402
1403 /*!
1404   Sets size of font
1405   \param s - new size of font
1406 */
1407 void QtxListResourceEdit::FontItem::setSize( const int s )
1408 {
1409   int cursize = -1;
1410   if( mySizes->isShown() && s>0 )
1411   {
1412     if( ( myFlags & UserSize ) || mySizes->listBox()->findItem( QString( "%1" ).arg( s ), Qt::ExactMatch ) )
1413       cursize = s;
1414   }
1415   else
1416   {
1417     QVariant defsize = property( QString( "%1:default_size" ).arg( family() ) );
1418     if( defsize.canCast( QVariant::Int ) )
1419       cursize = defsize.toInt();
1420   }
1421
1422   mySizes->setCurrentText( cursize>0 ? QString( "%1" ).arg( cursize ) : "" );
1423 }
1424
1425 /*!
1426   \return size of font
1427 */
1428 int QtxListResourceEdit::FontItem::size() const
1429 {
1430   QString s = mySizes->currentText();
1431   bool ok;
1432   int pSize = s.toInt( &ok );
1433   return ( ok ? pSize : 0 );
1434 }
1435
1436 /*!
1437   Sets font parameters
1438   \param bold - is font bold
1439   \param italic - is font italic
1440   \param underline - is font underlined
1441 */
1442 void QtxListResourceEdit::FontItem::setParams( const bool bold, const bool italic, const bool underline )
1443 {
1444   bool curbold = false, curitalic = false, curunderline = false;
1445   if( myBold->isShown() )
1446     curbold = bold;
1447   else
1448   {
1449     QVariant def = property( QString( "%1:default_bold" ).arg( family() ) );
1450     if( def.canCast( QVariant::Bool ) )
1451       curbold = def.toBool();
1452   }
1453   if( myItalic->isShown() )
1454     curitalic = italic;
1455   else
1456   {
1457     QVariant def = property( QString( "%1:default_italic" ).arg( family() ) );
1458     if( def.canCast( QVariant::Bool ) )
1459       curitalic = def.toBool();
1460   }
1461   if( myUnderline->isShown() )
1462     curunderline = underline;
1463   else
1464   {
1465     QVariant def = property( QString( "%1:default_underline" ).arg( family() ) );
1466     if( def.canCast( QVariant::Bool ) )
1467       curunderline = def.toBool();
1468   }
1469   myBold->setChecked( curbold );
1470   myItalic->setChecked( curitalic );
1471   myUnderline->setChecked( curunderline );
1472 }
1473
1474 /*!
1475   \return font parameters
1476   \param bold - is font bold
1477   \param italic - is font italic
1478   \param underline - is font underlined
1479 */
1480 void QtxListResourceEdit::FontItem::params( bool& bold, bool& italic, bool& underline )
1481 {
1482   bold = myBold->isChecked();
1483   italic = myItalic->isChecked();
1484   underline = myUnderline->isChecked();
1485 }
1486
1487 /*!
1488   Updates internal selection of font properties
1489 */
1490 void QtxListResourceEdit::FontItem::internalUpdate()
1491 {
1492   setFamily( family() );
1493   setSize( size() );
1494   bool b1, b2, b3;
1495   params( b1, b2, b3 );
1496   setParams( b1, b2, b3 );
1497 }
1498
1499 /*!
1500   SLOT: called if family is activated, updates list of possible sizes
1501 */
1502 void QtxListResourceEdit::FontItem::onActivateFamily( int )
1503 {
1504   QVariant sizes = property( QString( "%1:sizes" ).arg( family() ) );
1505
1506   int s = size();
1507   mySizes->clear();
1508   if( sizes.canCast( QVariant::List ) )
1509   {
1510     QValueList<QVariant> list = sizes.toList();
1511     QStringList sizeItems;
1512     QValueList<QVariant>::const_iterator anIt = list.begin(),
1513                                          aLast = list.end();
1514     for( ; anIt!=aLast; anIt++ )
1515       if( (*anIt).canCast( QVariant::Int ) && (*anIt).toInt()>0 )
1516         sizeItems.append( QString( "%1" ).arg( (*anIt).toInt() ) );
1517     mySizes->insertStringList( sizeItems );
1518   }
1519   setSize( s );
1520 }
1521
1522 /*!
1523   SLOT: called if it is necessary to show font preview
1524 */
1525 void QtxListResourceEdit::FontItem::onPreview()
1526 {
1527   QFont f( family(), size() );
1528   bool bold, italic, underline;
1529   params( bold, italic, underline );
1530   f.setBold( bold );
1531   f.setItalic( italic );
1532   f.setUnderline( underline );
1533
1534   bool ok;
1535   f = QFontDialog::getFont( &ok, f );
1536
1537   if( ok )
1538   {
1539     setFamily( f.family() );
1540     setSize( f.pointSize() );
1541     setParams( f.bold(), f.italic(), f.underline() );
1542   }
1543 }
1544
1545
1546
1547 /*!
1548   Constructor
1549 */
1550 QtxListResourceEdit::DirListItem::DirListItem( const QString& title, QtxResourceEdit* edit, Item* pItem, QWidget* parent )
1551 : PrefItem( Font, edit, pItem, parent )
1552 {
1553   myDirListEditor = new QtxDirListEditor( this ); 
1554 }
1555
1556 /*!
1557   Destructor
1558 */
1559 QtxListResourceEdit::DirListItem::~DirListItem()
1560 {
1561 }
1562
1563 /*!
1564   Stores value to resource manager
1565 */
1566 void QtxListResourceEdit::DirListItem::store()
1567 {
1568   QStringList list;
1569   myDirListEditor->getPathList(list);
1570   setString( QString(list.join(";")) );
1571 }
1572
1573 /*!
1574   Retrieve value to resource manager
1575 */
1576 void QtxListResourceEdit::DirListItem::retrieve()
1577 {
1578   myDirListEditor->setPathList(QStringList::split(";", getString()));
1579 }
1580
1581
1582
1583 /*!
1584   Constructor
1585 */
1586 QtxListResourceEdit::FileItem::FileItem( const QString& title, QtxResourceEdit* edit,
1587                                          Item* pItem, QWidget* parent )
1588 : PrefItem( Font, edit, pItem, parent ),
1589   myFlags( QFileInfo::ReadUser ),
1590   myIsExisting( true ),
1591   myIsReadOnly ( true ),
1592   myFileDlg( 0 )
1593 {
1594   new QLabel( title, this );
1595   myFile = new QLineEdit( this );
1596   myFile->setValidator( new FileValidator( this, myFile ) );
1597   myFile->setReadOnly( myIsReadOnly );
1598   myOpenFile = new QToolButton( this );
1599   myOpenFile->setText( "..." );
1600   connect( myOpenFile, SIGNAL( clicked() ), this, SLOT( onOpenFile() ) );
1601 }
1602
1603 /*!
1604   Destructor
1605 */
1606 QtxListResourceEdit::FileItem::~FileItem()
1607 {
1608   if( myFileDlg ) 
1609     delete myFileDlg;
1610 }
1611
1612 /*!
1613   Stores value to resource manager
1614 */
1615 void QtxListResourceEdit::FileItem::store()
1616 {
1617   setString( myFile->text() );
1618 }
1619
1620 /*!
1621   Retrieve value to resource manager
1622 */
1623 void QtxListResourceEdit::FileItem::retrieve()
1624 {
1625   myFile->setText( getString() );
1626 }
1627
1628 /*!
1629   \return value of property
1630   \param prop - property name
1631 */
1632 QVariant QtxListResourceEdit::FileItem::property( const QString& name ) const
1633 {
1634   if( name=="filter" )
1635     return myFilter;
1636   else if( name=="existing" )
1637     return myIsExisting;
1638   else if( name=="flags" )
1639     return myFlags;
1640   else if( name=="readOnly")
1641     return myIsReadOnly;
1642
1643   return QVariant();
1644 }
1645
1646 /*!
1647   Sets property value
1648   \param name - name of property
1649   \param var - value of property
1650 */
1651 void QtxListResourceEdit::FileItem::setProperty( const QString& name, const QVariant& value )
1652 {
1653   if( name=="filter" )
1654   {
1655     if( value.canCast( QVariant::String ) )
1656     {
1657       myFilter.clear();
1658       myFilter.append( value.toString() );
1659     }
1660     else if( value.canCast( QVariant::StringList ) )
1661       myFilter = value.toStringList();
1662   }
1663   else if( name=="existing" && value.canCast( QVariant::Bool ) )
1664     myIsExisting = value.toBool();
1665
1666   else if( name=="flags" && value.canCast( QVariant::UInt ) )
1667     myFlags = value.toUInt();
1668
1669   else if( name=="readOnly" && value.canCast( QVariant::Bool) ) {
1670     myIsReadOnly = value.toBool();
1671     myFile->setReadOnly( myIsReadOnly );
1672   }
1673 }
1674
1675 /*!
1676   SLOT: called if user click "Open File" button, shows dialog 
1677 */
1678 void QtxListResourceEdit::FileItem::onOpenFile()
1679 {
1680   if( !myFileDlg )
1681   {
1682     myFileDlg = new QFileDialog( "." );
1683     connect( myFileDlg, SIGNAL( fileHighlighted( const QString& ) ), this, SLOT( onFileSelected( const QString& ) ) );
1684   }
1685   
1686   myFileDlg->setCaption( title() );
1687   myFileDlg->setFilters( myFilter );
1688   myFileDlg->setMode( myIsExisting ? QFileDialog::ExistingFile : QFileDialog::AnyFile );
1689
1690   if( myFileDlg->exec()==QDialog::Accepted )
1691   {
1692     myFile->setText( myFileDlg->selectedFile() ); 
1693   }
1694 }
1695
1696 /*!
1697   \return true if file satisfies permissions
1698   \param f - file name
1699 */
1700 bool QtxListResourceEdit::FileItem::isFileCorrect( const QString& f ) const
1701 {
1702   bool res = false;
1703   QFileInfo info( f );
1704   if( !myIsExisting || info.exists() )
1705     res = info.isFile() && info.permission( myFlags );
1706
1707   return res;
1708 }
1709
1710 /*!
1711   SLOT: called if user has selected file in file dialog, checks file permissions and passes it's name to widget
1712   \param f - file name
1713 */
1714 void QtxListResourceEdit::FileItem::onFileSelected( const QString& f )
1715 {
1716   if( myFileDlg && !isFileCorrect( f ) )
1717     myFileDlg->setSelection( "" );
1718 }
1719
1720
1721 /*!
1722   Constructor
1723 */
1724 QtxListResourceEdit::FileItem::FileValidator::FileValidator( FileItem* item, QObject* parent )
1725 : QValidator( parent ),
1726   myItem( item )
1727 {
1728 }
1729
1730 /*!
1731   Destructor
1732 */
1733 QtxListResourceEdit::FileItem::FileValidator::~FileValidator()
1734 {
1735 }
1736
1737 /*!
1738   Check file permissions
1739   \param f - file name
1740 */
1741 QValidator::State QtxListResourceEdit::FileItem::FileValidator::validate( QString& f, int& ) const
1742 {
1743   if( myItem && myItem->isFileCorrect( f ) )
1744     return QValidator::Acceptable;
1745   else
1746     return QValidator::Intermediate;
1747 }