Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / VISUGUI / VisuGUI_SetupPlot2dDlg.cxx
1 //  Copyright (C) 2003  CEA/DEN, EDF R&D
2 //
3 //
4 //
5 //  File   : VisuGUI_SetupPlot2dDlg.cxx
6 //  Author : Vadim SANDLER
7 //  Module : SALOME
8 //  $Header$
9
10 #include "VisuGUI_SetupPlot2dDlg.h"
11 #include "SPlot2d_Curve.h"
12
13 #include "SUIT_Tools.h"
14 #include "SUIT_MessageBox.h"
15
16 #include <SALOMEDSClient_AttributeTableOfInteger.hxx>
17 #include <SALOMEDSClient_AttributeTableOfReal.hxx>
18
19 #include <qlabel.h>
20 #include <qpushbutton.h>
21 #include <qcheckbox.h>
22 #include <qtoolbutton.h>
23 #include <qcombobox.h>
24 #include <qscrollview.h>
25 #include <qlayout.h>
26 #include <qcolordialog.h>
27 #include <qspinbox.h>
28
29 #include <vector>
30 #include <string>
31
32 #include "utilities.h"
33
34 using namespace std;
35
36 #define DLG_SIZE_WIDTH    500 
37 #define DLG_SIZE_HEIGHT   400
38 #define MAX_LINE_WIDTH    100
39 #define MARGIN_SIZE       11
40 #define SPACING_SIZE      6
41
42 /*!
43   Constructor
44 */
45 VisuGUI_SetupPlot2dDlg::VisuGUI_SetupPlot2dDlg( _PTR(SObject) object, QWidget* parent )
46     : QDialog( parent, 
47                "VisuGUI_SetupPlot2dDlg", 
48                true, 
49                WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
50 {
51   setCaption( tr("TLT_SETUP_PLOT2D") );
52   setSizeGripEnabled( TRUE );
53   QGridLayout* topLayout = new QGridLayout( this ); 
54   topLayout->setSpacing( SPACING_SIZE );
55   topLayout->setMargin( MARGIN_SIZE );
56
57   myItems.setAutoDelete( false );
58
59   myObject = object;
60
61   /* Top scroll view */
62   myView = new QScrollView( this );
63   QFrame* frame  = new QFrame( myView );
64   frame->setFrameStyle( QFrame::Plain | QFrame::NoFrame );
65   QGridLayout* frameLayout = new QGridLayout( frame, 1, 12 );
66   frameLayout->setMargin( MARGIN_SIZE ); frameLayout->setSpacing( SPACING_SIZE );
67   
68   QFrame* lin;
69
70   QLabel* labAxis = new QLabel( tr( "AXIS_LBL" ),       frame );
71   QLabel* labData = new QLabel( tr( "DATA_LBL" ),       frame );
72   QLabel* labUnit = new QLabel( tr( "UNITS_LBL" ),      frame );
73   QLabel* labAttr = new QLabel( tr( "ATTRIBUTES_LBL" ), frame );
74   labAxis->setAlignment( AlignCenter );
75   labData->setAlignment( AlignCenter );
76   labUnit->setAlignment( AlignCenter );
77   labAttr->setAlignment( AlignCenter );
78   QFont font = labAxis->font(); font.setBold( true );
79   labAxis->setFont( font );
80   labData->setFont( font );
81   labUnit->setFont( font );
82   labAttr->setFont( font );
83
84   frameLayout->addMultiCellWidget( labAxis, 0,  0, 0, 1 );
85       lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
86       frameLayout->addWidget( lin,          0,     2 );
87   frameLayout->addWidget( labData,          0,     3 );
88       lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
89       frameLayout->addWidget( lin,          0,     4 );
90   frameLayout->addWidget( labUnit,          0,     5 );
91       lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
92       frameLayout->addWidget( lin,          0,     6 );
93   frameLayout->addMultiCellWidget( labAttr, 0,  0, 7, 11 );
94   frameLayout->setColStretch(               12, 5 );
95   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::HLine | QFrame::Sunken );
96   frameLayout->addMultiCellWidget( lin, 1, 1, 0, 12 );
97
98   int row = 2;
99   _PTR(GenericAttribute)        anAttr;
100   _PTR(AttributeTableOfInteger) tblIntAttr;
101   _PTR(AttributeTableOfReal)    tblRealAttr;
102   
103   /* Try table of integer */
104   if ( myObject->FindAttribute( anAttr, "AttributeTableOfInteger" ) ) {
105     tblIntAttr = anAttr;
106     if ( tblIntAttr ) {
107       try {
108         int nbRows = tblIntAttr->GetNbRows() ; 
109         vector<string> rowTitles = tblIntAttr->GetRowTitles();
110         vector<string> rowUnits  = tblIntAttr->GetRowUnits();
111         for ( int i = 0; i < nbRows; i++ ) {
112           VisuGUI_ItemContainer* item = new VisuGUI_ItemContainer( this );
113           item->createWidgets( frame );
114           frameLayout->addWidget( item->myHBtn,        row, 0 );
115           frameLayout->addWidget( item->myVBtn,        row, 1 );
116           frameLayout->addWidget( item->myTitleLab,    row, 3 );
117           if ( rowTitles.size() > 0 )
118             item->myTitleLab->setText( QString( rowTitles[ i ].c_str() ) );
119           frameLayout->addWidget( item->myUnitLab,     row, 5 );
120           if ( rowUnits.size() > 0 )
121             item->myUnitLab->setText( QString( rowUnits[ i ].c_str() ) );
122           frameLayout->addWidget( item->myAutoCheck,   row, 7 );
123           frameLayout->addWidget( item->myLineCombo,   row, 8 );
124           frameLayout->addWidget( item->myLineSpin,    row, 9 );
125           frameLayout->addWidget( item->myMarkerCombo, row, 10 );
126           frameLayout->addWidget( item->myColorBtn,    row, 11 );
127           connect( item, SIGNAL( horToggled( bool ) ), this, SLOT( onHBtnToggled( bool ) ) );
128           connect( item, SIGNAL( verToggled( bool ) ), this, SLOT( onVBtnToggled( bool ) ) );
129           myItems.append( item );
130           row++;
131         }
132       }
133       catch( ... ) {
134         MESSAGE("VisuGUI_SetupPlot2dDlg::VisuGUI_SetupPlot2dDlg : Exception has been caught (int)!!!");
135       }
136     }
137   }
138   /* Try table of real */
139   else if ( myObject->FindAttribute( anAttr, "AttributeTableOfReal" ) ) {
140     tblRealAttr = anAttr;
141     if ( tblRealAttr ) {
142       try {
143         int nbRows = tblRealAttr->GetNbRows() ; 
144         vector<string> rowTitles = tblRealAttr->GetRowTitles();
145         vector<string> rowUnits  = tblRealAttr->GetRowUnits();
146         for ( int i = 0; i < nbRows; i++ ) {
147           VisuGUI_ItemContainer* item = new VisuGUI_ItemContainer( this );
148           item->createWidgets( frame );
149           frameLayout->addWidget( item->myHBtn,        row, 0 );
150           frameLayout->addWidget( item->myVBtn,        row, 1 );
151           frameLayout->addWidget( item->myTitleLab,    row, 3 );
152           if ( rowTitles.size() > 0 )
153             item->myTitleLab->setText( QString( rowTitles[ i ].c_str() ) );
154           frameLayout->addWidget( item->myUnitLab,     row, 5 );
155           if ( rowUnits.size() > 0 )
156             item->myUnitLab->setText( QString( rowUnits[ i ].c_str() ) );
157           frameLayout->addWidget( item->myAutoCheck,   row, 7 );
158           frameLayout->addWidget( item->myLineCombo,   row, 8 );
159           frameLayout->addWidget( item->myLineSpin,    row, 9 );
160           frameLayout->addWidget( item->myMarkerCombo, row, 10 );
161           frameLayout->addWidget( item->myColorBtn,    row, 11 );
162           connect( item, SIGNAL( horToggled( bool ) ), this, SLOT( onHBtnToggled( bool ) ) );
163           connect( item, SIGNAL( verToggled( bool ) ), this, SLOT( onVBtnToggled( bool ) ) );
164           myItems.append( item );
165           row++;
166         }
167       }
168       catch( ... ) {
169         MESSAGE("VisuGUI_SetupPlot2dDlg::VisuGUI_SetupPlot2dDlg : Exception has been caught (real)!!!");
170       }
171     }
172   }
173   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
174   frameLayout->addMultiCellWidget( lin, 2, row+1, 2, 2 );
175   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
176   frameLayout->addMultiCellWidget( lin, 2, row+1, 4, 4 );
177   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
178   frameLayout->addMultiCellWidget( lin, 2, row+1, 6, 6 );
179   frameLayout->setRowStretch( row+1, 5 );
180
181   myView->addChild( frame, 0, 0 );
182   myView->setResizePolicy( QScrollView::AutoOneFit );
183   
184   myView->setMinimumWidth( frame->sizeHint().width() + MARGIN_SIZE * 2 );
185
186   /* OK/Cancel buttons */
187   myOkBtn = new QPushButton( tr( "BUT_OK" ), this, "buttonOk" );
188   myOkBtn->setAutoDefault( TRUE );
189   myOkBtn->setDefault( TRUE );
190   myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this, "buttonCancel" );
191   myCancelBtn->setAutoDefault( TRUE );
192
193   topLayout->addMultiCellWidget( myView, 0, 0, 0, 2 );
194   topLayout->addWidget( myOkBtn, 1, 0 );
195   topLayout->setColStretch( 1, 5 );
196   topLayout->addWidget( myCancelBtn, 1, 2 );
197
198   connect( myOkBtn,     SIGNAL( clicked() ), this, SLOT( accept() ) );
199   connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
200
201   enableControls();
202
203   /* Center widget inside it's parent widget */
204   resize( DLG_SIZE_WIDTH, DLG_SIZE_HEIGHT  );
205   SUIT_Tools::centerWidget( this, parentWidget() );
206 }
207 /*!
208   Destructor
209 */
210 VisuGUI_SetupPlot2dDlg::~VisuGUI_SetupPlot2dDlg()
211 {
212 }
213 /*!
214   Gets curves info ( indexes of row data in the table for horizontal and verical axes )
215 */
216 void VisuGUI_SetupPlot2dDlg::getCurvesSource( int& horIndex, QValueList<int>& verIndexes )
217 {
218   /* collecting horizontal and vertical axis items */
219   horIndex = -1;
220   int i;
221   for ( i = 0; i < myItems.count(); i++ ) {
222     if ( myItems.at( i )->isHorizontalOn() ) {
223       horIndex = i;
224     }
225     else if ( myItems.at( i )->isVerticalOn() ) {
226       verIndexes.append( i );
227     }
228   }
229 }
230 /*!
231   Gets curve attributes
232 */
233 bool VisuGUI_SetupPlot2dDlg::getCurveAttributes( const int vIndex, 
234                                                    bool&     isAuto, 
235                                                    int&      marker, 
236                                                    int&      line, 
237                                                    int&      lineWidth, 
238                                                    QColor&   color)
239 {
240   if ( vIndex >= 0 && vIndex < myItems.count() ) {
241     isAuto    = myItems.at( vIndex )->isAutoAssign();
242     marker    = myItems.at( vIndex )->getMarker();
243     line      = myItems.at( vIndex )->getLine();
244     lineWidth = myItems.at( vIndex )->getLineWidth();
245     color     = myItems.at( vIndex )->getColor();
246     return true;
247   }
248   return false;
249 }
250 /*!
251   Creates and returns curves presentations
252 */
253 void VisuGUI_SetupPlot2dDlg::getCurves( QPtrList<Plot2d_Curve>& container )
254 {
255   _PTR(GenericAttribute)        anAttr;
256   _PTR(AttributeTableOfInteger) tblIntAttr;
257   _PTR(AttributeTableOfReal)    tblRealAttr;
258   
259   /* clearing container contents */
260   container.clear();
261
262   /* collecting horizontal and vertical axis items */
263   int horIndex;
264   int i, j;
265   QValueList<int> verIndex;
266   getCurvesSource( horIndex, verIndex );
267   if ( horIndex < 0 || verIndex.isEmpty() ) /* no curves can be created */
268     return;
269     
270   /* Try table of integer */
271   if ( myObject->FindAttribute( anAttr, "AttributeTableOfInteger" ) ) {
272     tblIntAttr = anAttr;
273     if ( tblIntAttr ) {
274       try {
275         int nbCols = tblIntAttr->GetNbColumns() ; 
276         vector<string> rowTitles = tblIntAttr->GetRowTitles();
277         vector<string> rowUnits  = tblIntAttr->GetRowUnits();
278
279         for ( i = 0; i < verIndex.count(); i++ ) {
280           SPlot2d_Curve* curve = new SPlot2d_Curve();
281           // curve titles
282           if ( rowTitles.size() > 0 ) {
283             curve->setHorTitle( QString( rowTitles[ horIndex ].c_str() ) );
284             curve->setVerTitle( QString( rowTitles[ verIndex[i] ].c_str() ) );
285           }
286           // curve units
287           if ( rowUnits.size() > 0 ) {
288             curve->setHorUnits( QString( rowUnits[ horIndex ].c_str() ) );
289             curve->setVerUnits( QString( rowUnits[ verIndex[i] ].c_str() ) );
290           }
291           // curve data
292           int nbPoints = 0;
293           for ( j = 1; j <= nbCols; j++ ) {
294             if ( tblIntAttr->HasValue( horIndex+1, j ) && tblIntAttr->HasValue( verIndex[i]+1, j ) )
295               nbPoints++;
296           }
297           if ( nbPoints > 0 ) {
298             double* xList = new double[ nbPoints ];
299             double* yList = new double[ nbPoints ];
300             for ( j = 1; j <= nbCols; j++ ) {
301               if ( tblIntAttr->HasValue( horIndex+1, j ) && tblIntAttr->HasValue( verIndex[i]+1, j ) ) {
302                 xList[j-1] = tblIntAttr->GetValue( horIndex   +1, j );
303                 yList[j-1] = tblIntAttr->GetValue( verIndex[i]+1, j );
304               }
305             }
306             curve->setData( xList, yList, nbPoints );
307           }
308           // curve attributes
309           curve->setLine( (Plot2d_Curve::LineType)myItems.at( verIndex[i] )->getLine(), myItems.at( verIndex[i] )->getLineWidth() );
310           curve->setMarker( (Plot2d_Curve::MarkerType)myItems.at( verIndex[i] )->getMarker() );
311           curve->setColor( myItems.at( verIndex[i] )->getColor() );
312           curve->setAutoAssign( myItems.at( verIndex[i] )->isAutoAssign() );
313           // add curve into container
314           container.append( curve );
315         }
316       }
317       catch( ... ) {
318         MESSAGE("VisuGUI_SetupPlot2dDlg::getCurves : Exception has been caught (int)!!!");
319       }
320     }
321   }
322   /* Try table of real */
323   else if ( myObject->FindAttribute( anAttr, "AttributeTableOfReal" ) ) {
324     tblRealAttr = anAttr;
325     if ( tblRealAttr ) {
326       try {
327         int nbCols = tblRealAttr->GetNbColumns() ; 
328         vector<string> rowTitles = tblRealAttr->GetRowTitles();
329         vector<string> rowUnits  = tblRealAttr->GetRowUnits();
330
331         for ( i = 0; i < verIndex.count(); i++ ) {
332           SPlot2d_Curve* curve = new SPlot2d_Curve();
333           // curve titles
334           if ( rowTitles.size() > 0 ) {
335             curve->setHorTitle( QString( rowTitles[ horIndex ].c_str() ) );
336             curve->setVerTitle( QString( rowTitles[ verIndex[i] ].c_str() ) );
337           }
338           // curve units
339           if ( rowUnits.size() > 0 ) {
340             curve->setHorUnits( QString( rowUnits[ horIndex ].c_str() ) );
341             curve->setVerUnits( QString( rowUnits[ verIndex[i] ].c_str() ) );
342           }
343           // curve data
344           int nbPoints = 0;
345           for ( j = 1; j <= nbCols; j++ ) {
346             if ( tblRealAttr->HasValue( horIndex+1, j ) && tblRealAttr->HasValue( verIndex[i]+1, j ) )
347               nbPoints++;
348           }
349           if ( nbPoints > 0 ) {
350             double* xList = new double[ nbPoints ];
351             double* yList = new double[ nbPoints ];
352             for ( j = 1; j <= nbCols; j++ ) {
353               if ( tblRealAttr->HasValue( horIndex+1, j ) && tblRealAttr->HasValue( verIndex[i]+1, j ) ) {
354                 xList[j-1] = tblRealAttr->GetValue( horIndex   +1, j );
355                 yList[j-1] = tblRealAttr->GetValue( verIndex[i]+1, j );
356               }
357             }
358             curve->setData( xList, yList, nbPoints );
359           }
360           // curve attributes
361           curve->setLine( (Plot2d_Curve::LineType)myItems.at( verIndex[i] )->getLine(), myItems.at( verIndex[i] )->getLineWidth() );
362           curve->setMarker( (Plot2d_Curve::MarkerType)myItems.at( verIndex[i] )->getMarker() );
363           curve->setColor( myItems.at( verIndex[i] )->getColor() );
364           curve->setAutoAssign( myItems.at( verIndex[i] )->isAutoAssign() );
365           // add curve into container
366           container.append( curve );
367         }
368       }
369       catch( ... ) {
370         MESSAGE("VisuGUI_SetupPlot2dDlg::getCurves : Exception has been caught (real)!!!");
371       }
372     }
373   }
374 }
375 /*!
376   Slot, called when any <H> button is clicked
377 */
378 void VisuGUI_SetupPlot2dDlg::onHBtnToggled( bool on )
379 {
380   VisuGUI_ItemContainer* item = ( VisuGUI_ItemContainer* )sender();
381   if ( on ) {
382     for ( int i = 0; i < myItems.count(); i++ ) {
383       if ( myItems.at( i ) != item )
384         myItems.at( i )->setHorizontalOn( false );
385     }
386   }
387   enableControls();
388 }
389 /*!
390   Slot, called when any <V> button is clicked
391 */
392 void VisuGUI_SetupPlot2dDlg::onVBtnToggled( bool on )
393 {
394   VisuGUI_ItemContainer* item = ( VisuGUI_ItemContainer* )sender();
395   QPtrList<VisuGUI_ItemContainer> itemList;
396   itemList.setAutoDelete( false );
397   int i;
398   if ( on ) {
399     int totalOn = 0;
400     for ( i = 0; i < myItems.count(); i++ ) {
401       if ( myItems.at( i ) != item && !myItems.at( i )->isHorizontalOn() ) {
402         if ( myItems.at( i )->myUnitLab->text() == item->myUnitLab->text() ) {
403           if ( myItems.at( i )->isVerticalOn() )
404             totalOn++;
405           else
406             itemList.append( myItems.at( i ) );
407         }
408         else {
409           myItems.at( i )->setVerticalOn( false );
410         }
411       }
412     }
413     if ( totalOn == 0 && !itemList.isEmpty() && 
414          SUIT_MessageBox::info2( this, 
415                                 this->caption(), 
416                                 tr( "QUE_WANT_SAME_UNITS" ),
417                                 tr( "BUT_YES" ), 
418                                 tr( "BUT_NO" ), 
419                                 0, 1, 1 ) == 0 ) {
420       for ( i = 0; i < itemList.count(); i++ ) {
421         itemList.at( i )->blockSignals( true );
422         itemList.at( i )->setVerticalOn( true );
423         itemList.at( i )->blockSignals( false );
424       }
425     }
426   }
427   enableControls();
428 }
429 /*!
430   Enables/disables buttons 
431 */
432 void VisuGUI_SetupPlot2dDlg::enableControls()
433 {
434   bool bHSet = false;
435   bool bVSet = false;
436   for ( int i = 0; i < myItems.count(); i++ ) {
437     if ( myItems.at( i )->isHorizontalOn() ) {
438       bHSet = true;
439       break;
440     }
441   }
442 #ifndef WNT
443   for ( int i = 0; i < myItems.count(); i++ ) {
444 #else
445   for ( i = 0; i < myItems.count(); i++ ) {
446 #endif
447     if ( myItems.at( i )->isVerticalOn() )
448       bVSet = true;
449     myItems.at( i )->enableWidgets( bHSet && myItems.at( i )->isVerticalOn() );
450   }
451   myOkBtn->setEnabled( bHSet && bVSet );
452 }
453
454 // ====================================================================================
455 /*!
456   Constructor
457 */
458 VisuGUI_ItemContainer::VisuGUI_ItemContainer( QObject* parent, const char* name )
459      : QObject( parent, name ), 
460        myEnabled( true )
461 {
462 }
463 /*!
464   Creates widgets
465 */
466 void VisuGUI_ItemContainer::createWidgets( QWidget* parentWidget )
467 {
468   myHBtn = new QToolButton( parentWidget );
469   myHBtn->setText( tr( "H" ) );
470   myHBtn->setToggleButton( true );
471   myHBtn->setOn( false );
472
473   myVBtn = new QToolButton( parentWidget );
474   myVBtn->setText( tr( "V" ) );
475   myVBtn->setToggleButton( true );
476   myVBtn->setOn( false );
477   
478   myTitleLab = new QLabel( parentWidget );
479   myUnitLab  = new QLabel( parentWidget );
480   myUnitLab->setAlignment( AlignCenter);
481   
482   myAutoCheck = new QCheckBox( tr( "AUTO_CHECK_LBL" ), parentWidget );
483   myAutoCheck->setChecked( true );
484
485   myLineCombo = new QComboBox( false, parentWidget );
486   myLineCombo->insertItem( tr( "NONE_LINE_LBL" ) );
487   myLineCombo->insertItem( tr( "SOLID_LINE_LBL" ) );
488   myLineCombo->insertItem( tr( "DASH_LINE_LBL" ) );
489   myLineCombo->insertItem( tr( "DOT_LINE_LBL" ) );
490   myLineCombo->insertItem( tr( "DASHDOT_LINE_LBL" ) );
491   myLineCombo->insertItem( tr( "DAHSDOTDOT_LINE_LBL" ) );
492   myLineCombo->setCurrentItem( 1 ); // SOLID by default
493
494   myLineSpin = new QSpinBox( 0, MAX_LINE_WIDTH, 1, parentWidget );
495   myLineSpin->setValue( 0 );        // width = 0 by default
496
497   myMarkerCombo = new QComboBox( false, parentWidget );
498   myMarkerCombo->insertItem( tr( "NONE_MARKER_LBL" ) );
499   myMarkerCombo->insertItem( tr( "CIRCLE_MARKER_LBL" ) );
500   myMarkerCombo->insertItem( tr( "RECTANGLE_MARKER_LBL" ) );
501   myMarkerCombo->insertItem( tr( "DIAMOND_MARKER_LBL" ) );
502   myMarkerCombo->insertItem( tr( "DTRIANGLE_MARKER_LBL" ) );
503   myMarkerCombo->insertItem( tr( "UTRIANGLE_MARKER_LBL" ) );
504   myMarkerCombo->insertItem( tr( "LTRIANGLE_MARKER_LBL" ) );
505   myMarkerCombo->insertItem( tr( "RTRIANGLE_MARKER_LBL" ) );
506   myMarkerCombo->insertItem( tr( "CROSS_MARKER_LBL" ) );
507   myMarkerCombo->insertItem( tr( "XCROSS_MARKER_LBL" ) );
508   myMarkerCombo->setCurrentItem( 1 ); // CIRCLE by default
509
510   myColorBtn = new QToolButton( parentWidget );
511   myColorBtn->setMinimumWidth( 20 );
512  
513   connect( myAutoCheck, SIGNAL( clicked() ),       this, SLOT( onAutoChanged() ) );
514   connect( myColorBtn,  SIGNAL( clicked() ),       this, SLOT( onColorChanged() ) );
515   connect( myHBtn,      SIGNAL( toggled( bool ) ), this, SLOT( onHVToggled( bool ) ) );
516   connect( myVBtn,      SIGNAL( toggled( bool ) ), this, SLOT( onHVToggled( bool ) ) );
517   setColor( QColor( 0, 0, 0 ) );
518   updateState();
519 }
520 /*!
521   Enables attributes widgets
522 */
523 void VisuGUI_ItemContainer::enableWidgets( bool enable )
524 {
525   myEnabled = enable;
526   updateState();
527 }
528 /*!
529   Sets horizontal button's state on
530 */
531 void VisuGUI_ItemContainer::setHorizontalOn( bool on )
532 {
533   myHBtn->setOn( on );
534 }
535 /*!
536   Gets horizontal button's state
537 */
538 bool VisuGUI_ItemContainer::isHorizontalOn() const
539 {
540   return myHBtn->isOn();
541 }
542 /*!
543   Sets vertical button's state on
544 */
545 void VisuGUI_ItemContainer::setVerticalOn( bool on )
546 {
547   myVBtn->setOn( on );
548 }
549 /*!
550   Gets vertical button's state
551 */
552 bool VisuGUI_ItemContainer::isVerticalOn() const
553 {
554   return myVBtn->isOn();
555 }
556 /*!
557   Sets item AutoAssign flag state
558 */
559 void VisuGUI_ItemContainer::setAutoAssign( bool on )
560 {
561   myAutoCheck->setChecked( on );
562   updateState();
563 }
564 /*!
565   Gets item AutoAssign flag state
566 */
567 bool VisuGUI_ItemContainer::isAutoAssign() const
568 {
569   return myAutoCheck->isChecked();
570 }
571 /*!
572   Sets item line type and width
573 */
574 void VisuGUI_ItemContainer::setLine( const int line, const int width )
575 {
576   myLineCombo->setCurrentItem( line );
577 }
578 /*!
579   Gets item line type
580 */
581 int VisuGUI_ItemContainer::getLine() const
582 {
583   return myLineCombo->currentItem();
584 }
585 /*!
586   Gets item line width
587 */
588 int VisuGUI_ItemContainer::getLineWidth() const
589 {
590   return myLineSpin->value();
591 }
592 /*!
593   Sets item marker type
594 */
595 void VisuGUI_ItemContainer::setMarker( const int marker )
596 {
597   myMarkerCombo->setCurrentItem( marker );
598 }
599 /*!
600   Gets item marker type
601 */
602 int VisuGUI_ItemContainer::getMarker() const
603 {
604   return myMarkerCombo->currentItem();
605 }
606 /*!
607   Sets item color
608 */
609 void VisuGUI_ItemContainer::setColor( const QColor& color )
610 {
611   QPalette pal = myColorBtn->palette();
612   QColorGroup ca = pal.active();
613   ca.setColor( QColorGroup::Button, color );
614   QColorGroup ci = pal.inactive();
615   ci.setColor( QColorGroup::Button, color );
616   pal.setActive( ca );
617   pal.setInactive( ci );
618   myColorBtn->setPalette( pal );
619 }
620 /*!
621   Gets item color
622 */
623 QColor VisuGUI_ItemContainer::getColor() const
624 {
625   return myColorBtn->palette().active().button();
626 }
627 /*!
628   Enables/disables widgets
629 */
630 void VisuGUI_ItemContainer::updateState()
631 {
632   myAutoCheck->setEnabled( myEnabled );
633   myLineCombo->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
634   myLineSpin->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
635   myMarkerCombo->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
636   myColorBtn->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
637 }
638 /*!
639   Slot, called when user clickes <Auto assign> check box
640 */
641 void VisuGUI_ItemContainer::onAutoChanged()
642 {
643   updateState();
644   emit( autoClicked() );
645 }
646 /*!
647   <Color> button slot, invokes color selection dialog box
648 */
649 void VisuGUI_ItemContainer::onColorChanged()
650 {
651   QColor color = QColorDialog::getColor( getColor() );
652   if ( color.isValid() ) {
653     setColor( color );
654   }
655 }
656 /*!
657   <H> and <V> buttons slot
658 */
659 void VisuGUI_ItemContainer::onHVToggled( bool on )
660 {
661   const QObject* snd = sender();
662   if ( snd == myHBtn ) {
663     if ( on ) {
664       if ( myVBtn->isOn() ) {
665 //      blockSignals( true );
666         myVBtn->setOn( false );
667 //      blockSignals( false );
668       }
669     }
670     emit horToggled( on );
671   }
672   else {
673     if ( on ) {
674       if ( myHBtn->isOn() ) {
675 //      blockSignals( true );
676         myHBtn->setOn( false );
677 //      blockSignals( false );
678       }
679     }
680     emit verToggled( on );
681   }
682 }
683
684
685
686
687