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