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