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