Salome HOME
Initial version
[modules/gui.git] / src / SalomeApp / SalomeApp_ResourceEditor.cxx
1 // File:      SalomeApp_ResourceEditor.cxx
2 // Created:   
3 // Author:    Alexander Sladkov
4 // Copyright: 
5
6 #include "SalomeApp_ResourceEditor.h"
7
8 #include <qlabel.h>
9 #include <qlayout.h>
10 #include <qspinbox.h>
11 #include <qcombobox.h>
12 #include <qlineedit.h>
13 #include <qcheckbox.h>
14 #include <qvalidator.h>
15 #include <qcolordialog.h>
16 #include <qlistbox.h>
17 #include <qwidgetstack.h>
18 #include <qobjectlist.h>
19
20 #include <QtxDblSpinBox.h>
21 #include <SUIT_OverrideCursor.h>
22
23 #include<stdarg.h>
24
25 /*
26   Class: SalomeApp_ResourceEditor::ListItem
27   Descr: GUI implementation of resources list item.
28 */
29
30 SalomeApp_ResourceEditor::ListItem::ListItem( SalomeApp_ResourceEditor* ed, QWidget* parent )
31 : Item( ed )
32 {
33   mypName = new QLabel( parent );
34   mypList = new QComboBox( false, parent );
35 }
36
37 SalomeApp_ResourceEditor::ListItem::~ListItem()
38 {
39 }
40
41 void SalomeApp_ResourceEditor::ListItem::Set( const QString& sect, const QString& key,
42                                               const int type, const QString& label )
43 {
44   Item::Set( sect, key, type, label );
45   mypName->setText( label );
46 }
47
48 void SalomeApp_ResourceEditor::ListItem::SetList( const QValueList<int>& ids,
49                                                   const QStringList& names )
50 {
51   myIndex.clear();
52   mypList->clear();
53
54   for ( uint i = 0; i < QMIN( ids.count(), names.count() ); i++ )
55   {
56     mypList->insertItem( *names.at( i ) );
57     myIndex.insert( mypList->count() - 1, *ids.at( i ) );
58   }
59 }
60
61 void SalomeApp_ResourceEditor::ListItem::Store()
62 {
63   int type;
64   QString key, label;
65   QString sect = Get( key, type, label );
66
67   if ( !sect.isEmpty() )
68   {
69     QString sVal;
70     int iVal, index = mypList->currentItem();
71     if ( GetInteger( sect, key, iVal ) && myIndex.contains( index ) )
72       SetInteger( sect, key, myIndex[index] );
73     else if ( GetString( sect, key, sVal ) )
74       SetString( sect, key, mypList->text( index ) );
75   }
76 }
77
78 void SalomeApp_ResourceEditor::ListItem::Retrieve()
79 {
80   int type;
81   QString key, label;
82   QString sect = Get( key, type, label );
83
84   int index = -1;
85   if ( !sect.isEmpty() )
86   {
87     int iVal;
88     QString sVal;
89     if ( GetInteger( sect, key, iVal ) )
90     {
91       for ( QMap<int, int>::ConstIterator it = myIndex.begin(); it != myIndex.end() && index == -1; ++it )
92         if ( it.data() == iVal )
93           index = it.key();
94     }
95     else if ( GetString( sect, key, sVal ) )
96     {
97       for ( int i = 0; i < (int)mypList->count() && index == -1; i++ )
98         if ( mypList->text( i ) == sVal )
99           index = i;
100     }
101   }
102   mypList->setCurrentItem( index );
103 }
104
105 /*
106   Class: SalomeApp_ResourceEditor::ColorItem
107   Descr: GUI implementation of resources color item.
108 */
109
110 SalomeApp_ResourceEditor::ColorItem::ColorItem( SalomeApp_ResourceEditor* ed, QWidget* parent )
111 : Item( ed )
112 {
113   mypName = new QLabel( parent );
114   mypColor = new ColorButton( parent );
115   mypColor->setAutoDefault( false );
116 }
117
118 SalomeApp_ResourceEditor::ColorItem::~ColorItem()
119 {
120 }
121
122 void SalomeApp_ResourceEditor::ColorItem::Set( const QString& sect, const QString& key,
123                                                const int type, const QString& label )
124 {
125   Item::Set( sect, key, type, label );
126   mypName->setText( label );
127 }
128
129 void SalomeApp_ResourceEditor::ColorItem::Store()
130 {
131   int type;
132   QString key, label;
133   QString sect = Get( key, type, label );
134
135   if ( !sect.isEmpty() )
136     SetColor( sect, key, mypColor->paletteBackgroundColor() );
137 }
138
139 void SalomeApp_ResourceEditor::ColorItem::Retrieve()
140 {
141   int type;
142   QColor color;
143   QString key, label;
144   QString sect = Get( key, type, label );
145
146   if ( !sect.isEmpty() && GetColor( sect, key, color ) )
147     mypColor->setPaletteBackgroundColor( color );
148 }
149
150 /*
151   Class: SalomeApp_ResourceEditor::StateItem
152   Descr: GUI implementation of resources bool item.
153 */
154
155 SalomeApp_ResourceEditor::StateItem::StateItem( SalomeApp_ResourceEditor* ed, QWidget* parent )
156 : Item( ed )
157 {
158   mypName = new QLabel( parent );
159   mypState = new QCheckBox( parent );
160 }
161
162 SalomeApp_ResourceEditor::StateItem::~StateItem()
163 {
164 }
165
166 void SalomeApp_ResourceEditor::StateItem::Set( const QString& sect, const QString& key,
167                                                const int type, const QString& label )
168 {
169   Item::Set( sect, key, type, label );
170   mypName->setText( label );
171 }
172
173 void SalomeApp_ResourceEditor::StateItem::Store()
174 {
175   int type;
176   QString key, label;
177   QString sect = Get( key, type, label );
178   if ( !sect.isEmpty() )
179     SetBoolean( sect, key, mypState->isChecked() );
180 }
181
182 void SalomeApp_ResourceEditor::StateItem::Retrieve()
183 {
184   int type;
185   bool state;
186   QString key, label;
187   QString sect = Get( key, type, label );
188   if ( !sect.isEmpty() && GetBoolean( sect, key, state ) )
189     mypState->setChecked( state );
190 }
191
192 /*
193   Class: SalomeApp_ResourceEditor::StringItem
194   Descr: GUI implementation of resources string item.
195 */
196
197 SalomeApp_ResourceEditor::StringItem::StringItem( SalomeApp_ResourceEditor* ed, QWidget* parent )
198 : Item( ed )
199 {
200   mypName = new QLabel( parent );
201   mypString = new QLineEdit( parent );
202 }
203
204 SalomeApp_ResourceEditor::StringItem::~StringItem()
205 {
206 }
207
208 void SalomeApp_ResourceEditor::StringItem::Set( const QString& sect, const QString& key,
209                                                 const int type, const QString& label )
210 {
211   Item::Set( sect, key, type, label );
212   mypName->setText( label );
213 }
214
215 void SalomeApp_ResourceEditor::StringItem::Store()
216 {
217   int type;
218   QString key, label;
219   QString sect = Get( key, type, label );
220   if ( !sect.isEmpty() )
221     SetString( sect, key, mypString->text() );
222 }
223
224 void SalomeApp_ResourceEditor::StringItem::Retrieve()
225 {
226   int type;
227   QString val, key, label;
228   QString sect = Get( key, type, label );
229   if ( !sect.isEmpty() && GetString( sect, key, val ) )
230     mypString->setText( val );
231 }
232
233 /*
234   Class: SalomeApp_ResourceEditor::DoubleSpinItem
235   Descr: GUI implementation of resources string item.
236 */
237
238 SalomeApp_ResourceEditor::DoubleSpinItem::DoubleSpinItem
239   ( SalomeApp_ResourceEditor* ed, QWidget* parent )
240 : Item( ed )
241 {
242   mypName = new QLabel( parent );
243   mypDouble = new QtxDblSpinBox( parent, "spinboxdouble" );
244   mypDouble->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed ) ); 
245 }
246
247 SalomeApp_ResourceEditor::DoubleSpinItem::~DoubleSpinItem()
248 {
249 }
250
251 void SalomeApp_ResourceEditor::DoubleSpinItem::Set( const QString& sect, const QString& key,
252                                                     const int type, const QString& label )
253 {
254   Item::Set( sect, key, type, label );
255   mypName->setText( label );
256   mypDouble->setName( label ); // for debug purposes..
257 }
258
259 void SalomeApp_ResourceEditor::DoubleSpinItem::SetRange( const double min, const double max,
260                                                          const double prec, const double step )
261 {
262   mypDouble->setMinValue( min );
263   mypDouble->setMaxValue( max );
264   mypDouble->setPrecision( prec );
265   if ( step > 0 )
266     mypDouble->setSteps( step, step*5 );
267 }
268
269 void SalomeApp_ResourceEditor::DoubleSpinItem::Store()
270 {
271   int type;
272   QString key, label;
273   QString sect = Get( key, type, label );
274   if ( !sect.isEmpty() )
275     SetDouble( sect, key, mypDouble->value() );
276 }
277
278 void SalomeApp_ResourceEditor::DoubleSpinItem::Retrieve()
279 {
280   int type;
281   double val;
282   QString key, label;
283   QString sect = Get( key, type, label );
284   if ( sect.isEmpty() && GetDouble( sect, key, val ) )
285     mypDouble->setValue( val );
286 }
287
288 /*
289   Class: SalomeApp_ResourceEditor::DoubleEditItem
290   Descr: GUI implementation of resources string item.
291 */
292
293 SalomeApp_ResourceEditor::DoubleEditItem::DoubleEditItem
294   ( SalomeApp_ResourceEditor* ed, QWidget* parent )
295 : Item( ed )
296 {
297   mypName = new QLabel( parent );
298   mypDouble = new QLineEdit( parent );
299   mypDouble->setValidator( new QDoubleValidator( mypDouble ) );
300 }
301
302 SalomeApp_ResourceEditor::DoubleEditItem::~DoubleEditItem()
303 {
304 }
305
306 void SalomeApp_ResourceEditor::DoubleEditItem::Set( const QString& sect, const QString& key,
307                                                     const int type, const QString& label )
308 {
309   Item::Set( sect, key, type, label );
310   mypName->setText( label );
311 }
312
313 void SalomeApp_ResourceEditor::DoubleEditItem::Store()
314 {
315   int type;
316   QString key, label;
317   QString sect = Get( key, type, label );
318   if ( !sect.isEmpty() )
319     SetDouble( sect, key, mypDouble->text().toDouble() );
320 }
321
322 void SalomeApp_ResourceEditor::DoubleEditItem::Retrieve()
323 {
324   int type;
325   double val;
326   QString key, label;
327   QString sect = Get( key, type, label );
328   if ( sect.isEmpty() && GetDouble( sect, key, val ) )
329     mypDouble->setText( QString().setNum( val, 'g', 16 ) );
330 }
331
332 /*
333   Class: SalomeApp_ResourceEditor::IntegerSpinItem
334   Descr: GUI implementation of resources integer item.
335 */
336
337 SalomeApp_ResourceEditor::IntegerSpinItem::IntegerSpinItem
338 ( SalomeApp_ResourceEditor* ed, QWidget* parent )
339 : Item( ed )
340 {
341   mypName = new QLabel( parent );
342   mypInteger = new QSpinBox( parent );
343 }
344
345 SalomeApp_ResourceEditor::IntegerSpinItem::~IntegerSpinItem()
346 {
347 }
348
349 void SalomeApp_ResourceEditor::IntegerSpinItem::Set( const QString& sect, const QString& key,
350                                                      const int type, const QString& label )
351 {
352   Item::Set( sect, key, type, label );
353   mypName->setText( label );
354 }
355
356 void SalomeApp_ResourceEditor::IntegerSpinItem::SetRange( const double min, const double max,
357                                                           const double, const double step )
358 {
359   mypInteger->setMinValue( (int)min );
360   mypInteger->setMaxValue( (int)max );
361   int aStep = (int)step;
362   if ( aStep > 0 )
363     mypInteger->setLineStep( aStep );
364 }
365
366 void SalomeApp_ResourceEditor::IntegerSpinItem::Store()
367 {
368   int type;
369   QString key, label;
370   QString sect = Get( key, type, label );
371   if ( !sect.isEmpty() )
372     SetInteger( sect, key, mypInteger->value() );
373 }
374
375 void SalomeApp_ResourceEditor::IntegerSpinItem::Retrieve()
376 {
377   int val, type;
378   QString key, label;
379   QString sect = Get( key, type, label );
380   if ( !sect.isEmpty() && GetInteger( sect, key, val ) )
381     mypInteger->setValue( val );
382 }
383
384 /*
385   Class: SalomeApp_ResourceEditor::IntegerEditItem
386   Descr: GUI implementation of resources integer item.
387 */
388
389 SalomeApp_ResourceEditor::IntegerEditItem::IntegerEditItem
390   ( SalomeApp_ResourceEditor* ed, QWidget* parent )
391 : Item( ed )
392 {
393   mypName = new QLabel( parent );
394   mypInteger = new QLineEdit( parent );
395   mypInteger->setValidator( new QIntValidator( mypInteger ) );
396 }
397
398 SalomeApp_ResourceEditor::IntegerEditItem::~IntegerEditItem()
399 {
400 }
401
402 void SalomeApp_ResourceEditor::IntegerEditItem::Set( const QString& sect, const QString& key,
403                                                      const int type, const QString& label )
404 {
405   Item::Set( sect, key, type, label );
406   mypName->setText( label );
407 }
408
409 void SalomeApp_ResourceEditor::IntegerEditItem::Store()
410 {
411   int type;
412   QString key, label;
413   QString sect = Get( key, type, label );
414   if ( !sect.isEmpty() )
415     SetInteger( sect, key, mypInteger->text().toInt() );
416 }
417
418 void SalomeApp_ResourceEditor::IntegerEditItem::Retrieve()
419 {
420   int val, type;
421   QString key, label;
422   QString sect = Get( key, type, label );
423   if ( !sect.isEmpty() && GetInteger( sect, key, val ) )
424     mypInteger->setText( QString().setNum( val ) );
425 }
426
427 /*
428   Class: SalomeApp_ResourceEditor::Spacing 
429   Descr: GUI implementation of resources spacer.
430 */
431
432 SalomeApp_ResourceEditor::Spacing::Spacing( SalomeApp_ResourceEditor* ed, QWidget* parent )
433 : Item( ed )
434 {
435   new QLabel( parent );
436   new QLabel( parent );
437 }
438
439 SalomeApp_ResourceEditor::Spacing::~Spacing()
440 {
441 }
442
443 void SalomeApp_ResourceEditor::Spacing::Store()
444 {
445 }
446
447 void SalomeApp_ResourceEditor::Spacing::Retrieve()
448 {
449 }
450
451 /*
452   Class: SalomeApp_ResourceEditor::PrefGroup
453   Descr: GUI implementation of resources group.
454 */
455
456 SalomeApp_ResourceEditor::PrefGroup::PrefGroup( const QString& name,
457                                                 SalomeApp_ResourceEditor* ed,
458                                                 QWidget* parent )
459 : QGroupBox( 4, Qt::Horizontal, name, parent ),
460   Group( name ),
461   myEditor( ed )
462 {
463 }
464
465 SalomeApp_ResourceEditor::PrefGroup::~PrefGroup()
466 {
467 }
468
469 void SalomeApp_ResourceEditor::PrefGroup::SetColumns( const int cols )
470 {
471   setColumns( 2 * cols );
472 }
473
474 void SalomeApp_ResourceEditor::PrefGroup::SetTitle( const QString& title )
475 {
476   setTitle( title );
477 }
478
479 SalomeApp_ResourceEditor::Item* SalomeApp_ResourceEditor::PrefGroup::createItem( const int type, const QString& label )
480 {
481   Item* item = 0;
482
483   switch ( type )
484   {
485   case Color:
486     item = new ColorItem( myEditor, this );
487     break;
488   case Bool:
489     item = new StateItem( myEditor, this );
490     break;
491   case String:
492     item = new StringItem( myEditor, this );
493     break;
494   case List:
495     item = new ListItem( myEditor, this );
496     break;
497   case RealSpin:
498     item = new DoubleSpinItem( myEditor, this );
499     break;
500   case IntegerSpin:
501     item = new IntegerSpinItem( myEditor, this );
502     break;
503   case RealEdit:
504     item = new DoubleEditItem( myEditor, this );
505     break;
506   case IntegerEdit:
507     item = new IntegerEditItem( myEditor, this );
508     break;
509   case Space:
510     item = new Spacing( myEditor, this );
511     break;
512   }
513
514   return item;
515 }
516
517 /*
518   Class: SalomeApp_ResourceEditor::PrefTab
519   Descr: GUI implementation of resources tab.
520 */
521
522 SalomeApp_ResourceEditor::PrefTab::PrefTab( const QString& name, 
523                                             SalomeApp_ResourceEditor* ed,
524                                             QTabWidget* parent )
525 : QFrame( parent ),
526 Tab( name ),
527 mypTabWidget( parent ),
528 myEditor( ed )
529 {
530   QVBoxLayout* main = new QVBoxLayout( this );
531   mypMainFrame = new QGroupBox( 1, Qt::Horizontal, "", this );
532   mypMainFrame->setFrameStyle( QFrame::NoFrame );
533   mypMainFrame->setInsideMargin( 5 );
534   main->addWidget( mypMainFrame );
535 }
536
537 SalomeApp_ResourceEditor::PrefTab::~PrefTab()
538 {
539 }
540
541 void SalomeApp_ResourceEditor::PrefTab::SetTitle( const QString& title )
542 {
543   if ( !mypTabWidget )
544     return;
545
546   mypTabWidget->setTabLabel( this, title );
547 }
548
549 void SalomeApp_ResourceEditor::PrefTab::adjustLabels()
550 {
551   QObjectList* labels = queryList( "QLabel" );
552   if ( labels )
553   {
554     int w = 0;
555     for ( QObjectListIt it1( *labels ); it1.current(); ++it1 )
556     {
557       if ( it1.current()->isWidgetType() )
558       {
559         QWidget* wid = (QWidget*)it1.current();
560         w = QMAX( w, wid->sizeHint().width() );
561       }
562     }
563     for ( QObjectListIt it2( *labels ); it2.current(); ++it2 )
564     {
565       if ( it2.current()->isWidgetType() )
566       {
567         QWidget* wid = (QWidget*)it2.current();
568         wid->setMinimumWidth( w );
569       }
570     }
571     delete labels;
572   }
573 }
574
575 SalomeApp_ResourceEditor::Group* SalomeApp_ResourceEditor::PrefTab::createGroup( const QString& name )
576 {
577   return new PrefGroup( name, myEditor, mypMainFrame );
578 }
579
580
581 /*
582   Class: SalomeApp_ResourceEditor::PrefCategory
583   Descr: GUI implementation of preferences category.
584 */
585
586 SalomeApp_ResourceEditor::PrefCategory::PrefCategory( const QString& name,
587                                                       SalomeApp_ResourceEditor* ed,
588                                                       QListBox* listBox,
589                                                       QWidgetStack* parent )
590 : QTabWidget( parent ),
591 Category( name ),
592 mypListBox( listBox ),
593 mypWidgetStack( parent ),
594 myEditor( ed )
595 {
596 }
597
598 SalomeApp_ResourceEditor::PrefCategory::~PrefCategory()
599 {
600 }
601
602 void SalomeApp_ResourceEditor::PrefCategory::SetTitle( const QString& title )
603 {
604   if ( !mypWidgetStack || !mypListBox )
605     return;
606
607   int id = mypWidgetStack->id( this );
608   if ( id < 0 )
609     return;
610
611   //int idx = mypListBox->index( mypListBox->selectedItem() );
612   int idx = mypListBox->currentItem();
613
614   mypListBox->changeItem( title, id );
615   mypListBox->setSelected( idx, true );
616 }
617
618 void SalomeApp_ResourceEditor::PrefCategory::adjustLabels()
619 {
620   for ( int i = 0; i < count(); i++ )
621   {
622     QWidget* wid = page( i );
623     if ( wid )
624     {
625       PrefTab* tab = (PrefTab*)wid;
626       tab->adjustLabels();
627     }
628   }
629 }
630
631 SalomeApp_ResourceEditor::Tab* SalomeApp_ResourceEditor::PrefCategory::createTab( const QString& name )
632 {
633   PrefTab* aTab = new PrefTab( name, myEditor, this );
634   addTab( aTab, name );
635   return aTab;
636 }
637
638 //=======================================================================
639 //function : SalomeApp_ResourceEditor
640 //purpose  : 
641 //=======================================================================
642
643 SalomeApp_ResourceEditor::SalomeApp_ResourceEditor( QtxResourceMgr* theMgr,
644                                                     QWidget* theParent )
645 : QtxDialog( theParent, 0, true, false, Standard | Apply ),
646   QtxResourceEditor( theMgr )
647 {
648   setCaption( tr( "CAPTION" ) );
649
650   QHBoxLayout* main = new QHBoxLayout( mainFrame(), 5, 5 );
651
652   mypCatList = new QListBox( mainFrame() );
653   mypCatStack = new QWidgetStack( mainFrame() );
654
655   main->addWidget( mypCatList );
656   main->addWidget( mypCatStack );
657
658   mypCatList->setSelectionMode( QListBox::Single );
659
660   //int defId = addUserButton( tr( "DEFAULT" ) );
661   //QButton* defButton = userButton( defId );
662
663   //if ( defId != -1 )
664   //  setUserButtonPosition( Right, defId );
665
666   setTabOrder( button( OK ), button( Cancel ),
667                /*defButton,*/ button( Help ), 0 );
668
669   connect( this, SIGNAL( dlgHelp() ),  this, SLOT( onHelp() ) );
670   connect( this, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
671   connect( mypCatList, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
672
673 /*  if ( defButton )
674     connect( defButton, SIGNAL( clicked() ), this, SLOT( onDefault() ) );*/
675
676   setFocusProxy( mypCatList );
677 }
678
679 //=======================================================================
680 //function : ~SalomeApp_ResourceEditor
681 //purpose  : 
682 //=======================================================================
683
684 SalomeApp_ResourceEditor::~SalomeApp_ResourceEditor()
685 {
686 }
687
688 //=======================================================================
689 //function : show
690 //purpose  : 
691 //=======================================================================
692
693 void SalomeApp_ResourceEditor::show()
694 {
695   SUIT_OverrideCursor c;
696
697   setAlignment( 0 );
698 /*
699   for ( QPtrListIterator<Category> it( categories() ); it.current(); ++it )
700   {
701     PrefCategory* aCat = (PrefCategory*)it.current();
702     aCat->adjustLabels();
703   }
704 */
705   Update(); // update all tabs, groups, items.
706
707 //  Backup();
708   Retrieve();
709
710   QtxDialog::show();
711 }
712
713 //=======================================================================
714 //function : accept
715 //purpose  : 
716 //=======================================================================
717
718 void SalomeApp_ResourceEditor::accept()
719 {
720   SUIT_OverrideCursor c;
721
722   QtxDialog::accept();
723
724   Store();
725   updateViewer();
726 }
727
728 //=======================================================================
729 //function : reject
730 //purpose  : 
731 //=======================================================================
732
733 void SalomeApp_ResourceEditor::reject()
734 {
735   SUIT_OverrideCursor c;
736
737   QtxDialog::reject();
738
739 //  Restore();
740   updateViewer();
741 }
742
743 //=======================================================================
744 //function : onHelp
745 //purpose  : 
746 //=======================================================================
747
748 void SalomeApp_ResourceEditor::onHelp()
749 {
750   /*LH3DGui_Desktop* desk = LH3DGui_Desktop::getDesktop();
751   if ( desk )
752   {
753     LH3DGui_Helper* helper = desk->getHelper();
754     if ( helper )
755       helper->ShowPage( "preferences" );
756   }*/
757 }
758
759 //=======================================================================
760 //function : onApply
761 //purpose  : 
762 //=======================================================================
763
764 void SalomeApp_ResourceEditor::onApply()
765 {
766   SUIT_OverrideCursor c;
767
768   Store();
769   updateViewer();
770 }
771
772 //=======================================================================
773 //function : onSelectionChanged
774 //purpose  : 
775 //=======================================================================
776
777 void SalomeApp_ResourceEditor::onSelectionChanged()
778 {
779   //int index = mypCatList->index( mypCatList->selectedItem() );
780   int index = mypCatList->currentItem();
781   if ( index < 0 )
782     return;
783
784   mypCatStack->raiseWidget( index );
785 }
786
787 //=======================================================================
788 //function : updateViewer
789 //purpose  : 
790 //=======================================================================
791
792 void SalomeApp_ResourceEditor::updateViewer()
793 {
794 /*  LH3DGui_Desktop* desktop = LH3DGui_Desktop::getDesktop();
795   if ( !desktop )
796     return;
797
798   LH3DGui_Modeler* active = desktop->getActiveModeler();
799   if ( !active )
800     return;
801
802   active->Update( LH3DGui_Desktop::Viewer3d );
803   if ( desktop->getViewer3d() )
804     desktop->getViewer3d()->update();*/
805 }
806
807 //=======================================================================
808 //function : createCategory
809 //purpose  : 
810 //=======================================================================
811
812 SalomeApp_ResourceEditor::Category* SalomeApp_ResourceEditor::createCategory( const QString& name )
813 {
814   PrefCategory* aCat = new PrefCategory( name, this, mypCatList, mypCatStack );
815   mypCatList->insertItem( name );
816   int id = mypCatList->count() - 1;
817   mypCatStack->addWidget( aCat, id );
818
819   if ( !mypCatList->currentItem() )
820     mypCatList->setSelected( 0, true );
821
822   return aCat;
823 }
824
825 //=======================================================================
826 //function : setTabOrder
827 //purpose  : 
828 //=======================================================================
829
830 void SalomeApp_ResourceEditor::setTabOrder( QObject* first, ... )
831 {
832   va_list objs;
833   va_start( objs, first );
834
835   QObjectList objList;
836
837   QObject* cur = first;
838   while ( cur )
839   {
840     objList.append( cur );
841     cur = va_arg( objs, QObject* );
842   }
843
844   setTabOrder( objList );
845 }
846
847 //=======================================================================
848 //function : setTabOrder
849 //purpose  : 
850 //=======================================================================
851
852 void SalomeApp_ResourceEditor::setTabOrder( const QObjectList& objs )
853 {
854   QPtrList<QWidget> widgets;
855
856   for ( QObjectListIt it( objs ); it.current(); ++it )
857   {
858     QWidget* wid = 0;
859     QObject* cur = *it;
860     if ( cur->isWidgetType() )
861       wid = (QWidget*)cur;
862     if ( wid )
863       widgets.append( wid );
864   }
865
866   if ( widgets.count() < 2 )
867     return;
868
869   QWidget* prev = widgets.first();
870   for ( QWidget* next = widgets.at( 1 ); next; next = widgets.next() )
871   {
872     QWidget::setTabOrder( prev, next );
873     prev = next;
874   }
875 }
876
877
878
879
880 ColorButton::ColorButton( QWidget* parent )
881 : QPushButton( parent )
882 {
883   connect( this, SIGNAL( clicked() ), this, SLOT( onColor() ) );
884 }
885
886 ColorButton::~ColorButton()
887 {
888 }
889
890 void ColorButton::onColor()
891 {
892   setDown( true );
893
894   QColor c = QColorDialog::getColor( paletteBackgroundColor(), this );
895   if ( c.isValid() )
896     setPaletteBackgroundColor( c );
897
898   setDown( false );
899 }
900