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