Salome HOME
a12fad46b8127b8ee893e717bb50760097262000
[modules/visu.git] / src / VISUGUI / VisuGUI_SetupPlot2dDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : VisuGUI_SetupPlot2dDlg.cxx
23 //  Author : Vadim SANDLER
24 //  Module : SALOME
25 //  $Header$
26 //
27 #include "VisuGUI_SetupPlot2dDlg.h"
28 #include "VisuGUI.h"
29 #include "SPlot2d_Curve.h"
30
31 #include "SUIT_Tools.h"
32 #include "SUIT_MessageBox.h"
33 #include "SUIT_ResourceMgr.h"
34 #include "SUIT_Session.h"
35
36 #include "LightApp_Application.h"
37
38 #include <QtxColorButton.h>
39
40 #include <SALOMEDSClient_AttributeTableOfInteger.hxx>
41 #include <SALOMEDSClient_AttributeTableOfReal.hxx>
42
43 #include <QLabel>
44 #include <QPushButton>
45 #include <QCheckBox>
46 #include <QToolButton>
47 #include <QComboBox>
48 #include <QScrollArea>
49 #include <QLayout>
50 #include <QColorDialog>
51 #include <QSpinBox>
52 #include <QKeyEvent>
53 #include <QFrame>
54
55 #include <vector>
56 #include <string>
57
58 #include "utilities.h"
59
60 using namespace std;
61
62 #define DLG_SIZE_WIDTH    500 
63 #define DLG_SIZE_HEIGHT   400
64 #define MAX_LINE_WIDTH    100
65 #define MARGIN_SIZE       11
66 #define SPACING_SIZE      6
67
68 /*!
69   Constructor
70 */
71 VisuGUI_SetupPlot2dDlg::VisuGUI_SetupPlot2dDlg( _PTR(SObject) object, QWidget* parent )
72     : QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
73 {
74   setModal( true );
75   setWindowTitle( tr("TLT_SETUP_PLOT2D") );
76   setSizeGripEnabled( TRUE );
77   QGridLayout* topLayout = new QGridLayout( this ); 
78   topLayout->setSpacing( SPACING_SIZE );
79   topLayout->setMargin( MARGIN_SIZE );
80
81   //myItems.setAutoDelete( false );
82
83   myObject = object;
84
85   /* Top scroll view */
86   myView = new QScrollArea( this );
87   QFrame* frame  = new QFrame( myView );
88   frame->setFrameStyle( QFrame::Plain | QFrame::NoFrame );
89   QGridLayout* frameLayout = new QGridLayout( frame );
90   frameLayout->setMargin( MARGIN_SIZE ); frameLayout->setSpacing( SPACING_SIZE );
91   
92   QFrame* lin;
93
94   QLabel* labAxis = new QLabel( tr( "AXIS_LBL" ),       frame );
95   QLabel* labAssigned = new QLabel( tr( "ASSIGNED" ),   frame );
96   QLabel* labData = new QLabel( tr( "DATA_LBL" ),       frame );
97   QLabel* labUnit = new QLabel( tr( "UNITS_LBL" ),      frame );
98   QLabel* labAttr = new QLabel( tr( "ATTRIBUTES_LBL" ), frame );
99   labAxis->setAlignment( Qt::AlignCenter );
100   labAssigned->setAlignment( Qt::AlignCenter );
101   labData->setAlignment( Qt::AlignCenter );
102   labUnit->setAlignment( Qt::AlignCenter );
103   labAttr->setAlignment( Qt::AlignCenter );
104   QFont font = labAxis->font(); font.setBold( true );
105   labAxis->setFont( font );
106   labAssigned->setFont( font );
107   labData->setFont( font );
108   labUnit->setFont( font );
109   labAttr->setFont( font );
110
111   frameLayout->addWidget( labAxis, 0, 0, 1, 2 );
112       lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
113       frameLayout->addWidget( lin,          0,     2 );
114
115   frameLayout->addWidget( labAssigned,      0,     3 );
116       lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
117       frameLayout->addWidget( lin,          0,     4 );
118
119   frameLayout->addWidget( labData,          0,     5 );
120       lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
121       frameLayout->addWidget( lin,          0,     6 );
122   frameLayout->addWidget( labUnit,          0,     7 );
123       lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
124       frameLayout->addWidget( lin,          0,     8 );
125   frameLayout->addWidget( labAttr, 0,  9, 1, 5 );
126   //frameLayout->setColStretch(               14, 5 );
127   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::HLine | QFrame::Sunken );
128   frameLayout->addWidget( lin, 1, 0, 1, 15 );
129
130   int row = 2;
131   _PTR(GenericAttribute)        anAttr;
132   _PTR(AttributeTableOfInteger) tblIntAttr;
133   _PTR(AttributeTableOfReal)    tblRealAttr;
134   
135   /* Try table of integer */
136   if ( myObject->FindAttribute( anAttr, "AttributeTableOfInteger" ) ) {
137     tblIntAttr = anAttr;
138     if ( tblIntAttr ) {
139       try {
140         int nbRows = tblIntAttr->GetNbRows() ; 
141         vector<string> rowTitles = tblIntAttr->GetRowTitles();
142         vector<string> rowUnits  = tblIntAttr->GetRowUnits();
143         QStringList rows;
144         for ( int i = 0; i < nbRows; i++ )
145           rows.append( rowTitles[i].c_str() );
146
147         for ( int i = 0; i < nbRows; i++ ) {
148           VisuGUI_ItemContainer* item = new VisuGUI_ItemContainer( this );
149           item->createWidgets( frame, rows );
150           frameLayout->addWidget( item->myHBtn,        row, 0 );
151           frameLayout->addWidget( item->myVBtn,        row, 1 );
152           frameLayout->addWidget( item->myAssigned,    row, 3 );
153
154           frameLayout->addWidget( item->myTitleLab,    row, 5 );
155           if ( rowTitles.size() > 0 )
156             item->myTitleLab->setText( QString( rowTitles[ i ].c_str() ) );
157           frameLayout->addWidget( item->myUnitLab,     row, 7 );
158           if ( rowUnits.size() > 0 )
159             item->myUnitLab->setText( QString( rowUnits[ i ].c_str() ) );
160           frameLayout->addWidget( item->myAutoCheck,   row, 9 );
161           frameLayout->addWidget( item->myLineCombo,   row, 10 );
162           frameLayout->addWidget( item->myLineSpin,    row, 11 );
163           frameLayout->addWidget( item->myMarkerCombo, row, 12 );
164           frameLayout->addWidget( item->myColorBtn,    row, 13 );
165           connect( item, SIGNAL( horToggled( bool ) ), this, SLOT( onHBtnToggled( bool ) ) );
166           connect( item, SIGNAL( verToggled( bool ) ), this, SLOT( onVBtnToggled( bool ) ) );
167           myItems.append( item );
168           row++;
169         }
170       }
171       catch( ... ) {
172         MESSAGE("VisuGUI_SetupPlot2dDlg::VisuGUI_SetupPlot2dDlg : Exception has been caught (int)!!!");
173       }
174     }
175   }
176   /* Try table of real */
177   else if ( myObject->FindAttribute( anAttr, "AttributeTableOfReal" ) ) {
178     tblRealAttr = anAttr;
179     if ( tblRealAttr ) {
180       try {
181         int nbRows = tblRealAttr->GetNbRows() ; 
182         vector<string> rowTitles = tblRealAttr->GetRowTitles();
183         vector<string> rowUnits  = tblRealAttr->GetRowUnits();
184         QStringList rows;
185         for ( int i = 0; i < nbRows; i++ )
186           rows.append( rowTitles[i].c_str() );
187
188         for ( int i = 0; i < nbRows; i++ ) {
189           VisuGUI_ItemContainer* item = new VisuGUI_ItemContainer( this );
190           item->createWidgets( frame, rows );
191           frameLayout->addWidget( item->myHBtn,        row, 0 );
192           frameLayout->addWidget( item->myVBtn,        row, 1 );
193           frameLayout->addWidget( item->myAssigned,    row, 3 );
194
195           frameLayout->addWidget( item->myTitleLab,    row, 5 );
196           if ( rowTitles.size() > 0 )
197             item->myTitleLab->setText( QString( rowTitles[ i ].c_str() ) );
198           frameLayout->addWidget( item->myUnitLab,     row, 7 );
199           if ( rowUnits.size() > 0 )
200             item->myUnitLab->setText( QString( rowUnits[ i ].c_str() ) );
201           frameLayout->addWidget( item->myAutoCheck,   row, 9 );
202           frameLayout->addWidget( item->myLineCombo,   row, 10 );
203           frameLayout->addWidget( item->myLineSpin,    row, 11 );
204           frameLayout->addWidget( item->myMarkerCombo, row, 12 );
205           frameLayout->addWidget( item->myColorBtn,    row, 13 );
206           connect( item, SIGNAL( horToggled( bool ) ), this, SLOT( onHBtnToggled( bool ) ) );
207           connect( item, SIGNAL( verToggled( bool ) ), this, SLOT( onVBtnToggled( bool ) ) );
208           myItems.append( item );
209           row++;
210         }
211       }
212       catch( ... ) {
213         MESSAGE("VisuGUI_SetupPlot2dDlg::VisuGUI_SetupPlot2dDlg : Exception has been caught (real)!!!");
214       }
215     }
216   }
217   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
218   frameLayout->addWidget( lin, 2, 2, row, 1 );
219   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
220   frameLayout->addWidget( lin, 2, 4, row, 1 );
221   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
222   frameLayout->addWidget( lin, 2, 6, row, 1 );
223   //frameLayout->setRowStretch( row+1, 5 );
224
225   myView->setWidget( frame );
226   myView->setAlignment( Qt::AlignCenter );
227   myView->setWidgetResizable( true );
228   
229   myView->setMinimumWidth( frame->sizeHint().width() + MARGIN_SIZE * 2 );
230
231   /* OK/Cancel/Help buttons */
232   myOkBtn = new QPushButton( tr( "BUT_OK" ), this );
233   myOkBtn->setAutoDefault( TRUE );
234   myOkBtn->setDefault( TRUE );
235   myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this );
236   myCancelBtn->setAutoDefault( TRUE );
237   myHelpBtn = new QPushButton( tr( "BUT_HELP" ), this );
238   myHelpBtn->setAutoDefault( TRUE );
239
240   topLayout->addWidget( myView, 0, 0, 1, 4 );
241   topLayout->addWidget( myOkBtn, 1, 0 );
242   //topLayout->setColStretch( 1, 5 );
243   topLayout->addWidget( myCancelBtn, 1, 2 );
244   topLayout->addWidget( myHelpBtn, 1, 3 );
245
246   connect( myOkBtn,     SIGNAL( clicked() ), this, SLOT( accept() ) );
247   connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
248   connect( myHelpBtn,   SIGNAL( clicked() ), this, SLOT( onHelp() ) );
249
250   enableControls();
251
252   /* Center widget inside it's parent widget */
253   resize( DLG_SIZE_WIDTH, DLG_SIZE_HEIGHT  );
254   SUIT_Tools::centerWidget( this, parentWidget() );
255 }
256 /*!
257   Destructor
258 */
259 VisuGUI_SetupPlot2dDlg::~VisuGUI_SetupPlot2dDlg()
260 {
261 }
262 /*!
263   Gets curves info ( indexes of row data in the table for horizontal and verical axes )
264 */
265 void VisuGUI_SetupPlot2dDlg::getCurvesSource( int& horIndex, QList<int>& verIndexes,
266                                               QList<int>& zIndices )
267 {
268   /* collecting horizontal and vertical axis items */
269   horIndex = -1;
270   int i;
271   for ( i = 0; i < myItems.count(); i++ ) {
272     if ( myItems.at( i )->isHorizontalOn() ) {
273       horIndex = i;
274     }
275     else if ( myItems.at( i )->isVerticalOn() ) {
276       verIndexes.append( i );
277       zIndices.append( myItems.at( i )->assigned() );
278     }
279     
280   }
281 }
282 /*!
283   Gets curve attributes
284 */
285 bool VisuGUI_SetupPlot2dDlg::getCurveAttributes( const int vIndex, 
286                                                    bool&     isAuto, 
287                                                    int&      marker, 
288                                                    int&      line, 
289                                                    int&      lineWidth, 
290                                                    QColor&   color)
291 {
292   if ( vIndex >= 0 && vIndex < myItems.count() ) {
293     isAuto    = myItems.at( vIndex )->isAutoAssign();
294     marker    = myItems.at( vIndex )->getMarker();
295     line      = myItems.at( vIndex )->getLine();
296     lineWidth = myItems.at( vIndex )->getLineWidth();
297     color     = myItems.at( vIndex )->getColor();
298     return true;
299   }
300   return false;
301 }
302 /*!
303   Creates and returns curves presentations
304 */
305 void VisuGUI_SetupPlot2dDlg::getCurves( QList<Plot2d_Curve*>& container )
306 {
307   _PTR(GenericAttribute)        anAttr;
308   _PTR(AttributeTableOfInteger) tblIntAttr;
309   _PTR(AttributeTableOfReal)    tblRealAttr;
310   
311   /* clearing container contents */
312   container.clear();
313
314   /* collecting horizontal and vertical axis items */
315   int horIndex;
316   int i, j;
317   QList<int> verIndex, zIndices;
318   getCurvesSource( horIndex, verIndex, zIndices );
319   if ( horIndex < 0 || verIndex.isEmpty() ) /* no curves can be created */
320     return;
321     
322   /* Try table of integer */
323   if ( myObject->FindAttribute( anAttr, "AttributeTableOfInteger" ) ) {
324     tblIntAttr = anAttr;
325     if ( tblIntAttr ) {
326       try {
327         int nbCols = tblIntAttr->GetNbColumns() ; 
328         vector<string> rowTitles = tblIntAttr->GetRowTitles();
329         vector<string> rowUnits  = tblIntAttr->GetRowUnits();
330
331         for ( i = 0; i < verIndex.count(); i++ ) {
332           SPlot2d_Curve* curve = new SPlot2d_Curve();
333           // curve titles
334           if ( rowTitles.size() > 0 ) {
335             curve->setHorTitle( QString( rowTitles[ horIndex ].c_str() ) );
336             curve->setVerTitle( QString( rowTitles[ verIndex[i] ].c_str() ) );
337           }
338           // curve units
339           if ( rowUnits.size() > 0 ) {
340             curve->setHorUnits( QString( rowUnits[ horIndex ].c_str() ) );
341             curve->setVerUnits( QString( rowUnits[ verIndex[i] ].c_str() ) );
342           }
343           // curve data
344           int nbPoints = 0;
345           for ( j = 1; j <= nbCols; j++ ) {
346             if ( tblIntAttr->HasValue( horIndex+1, j ) && tblIntAttr->HasValue( verIndex[i]+1, j ) )
347               nbPoints++;
348           }
349           if ( nbPoints > 0 ) {
350             double* xList = new double[ nbPoints ];
351             double* yList = new double[ nbPoints ];
352             QStringList zList;
353             for ( j = 1; j <= nbCols; j++ ) {
354               if ( tblIntAttr->HasValue( horIndex+1, j ) && tblIntAttr->HasValue( verIndex[i]+1, j ) ) {
355                 xList[j-1] = tblIntAttr->GetValue( horIndex   +1, j );
356                 yList[j-1] = tblIntAttr->GetValue( verIndex[i]+1, j );
357                 zList.append( QString( "%1" ).arg( tblIntAttr->GetValue( zIndices[i]+1, j ) ) );
358               }
359             }
360             curve->setData( xList, yList, nbPoints, zList );
361           }
362           // curve attributes
363           curve->setLine( (Plot2d::LineType)myItems.at( verIndex[i] )->getLine(), myItems.at( verIndex[i] )->getLineWidth() );
364           curve->setMarker( (Plot2d::MarkerType)myItems.at( verIndex[i] )->getMarker() );
365           curve->setColor( myItems.at( verIndex[i] )->getColor() );
366           curve->setAutoAssign( myItems.at( verIndex[i] )->isAutoAssign() );
367           // add curve into container
368           container.append( curve );
369         }
370       }
371       catch( ... ) {
372         MESSAGE("VisuGUI_SetupPlot2dDlg::getCurves : Exception has been caught (int)!!!");
373       }
374     }
375   }
376   /* Try table of real */
377   else if ( myObject->FindAttribute( anAttr, "AttributeTableOfReal" ) ) {
378     tblRealAttr = anAttr;
379     if ( tblRealAttr ) {
380       try {
381         int nbCols = tblRealAttr->GetNbColumns() ; 
382         vector<string> rowTitles = tblRealAttr->GetRowTitles();
383         vector<string> rowUnits  = tblRealAttr->GetRowUnits();
384
385         for ( i = 0; i < verIndex.count(); i++ ) {
386           SPlot2d_Curve* curve = new SPlot2d_Curve();
387           // curve titles
388           if ( rowTitles.size() > 0 ) {
389             curve->setHorTitle( QString( rowTitles[ horIndex ].c_str() ) );
390             curve->setVerTitle( QString( rowTitles[ verIndex[i] ].c_str() ) );
391           }
392           // curve units
393           if ( rowUnits.size() > 0 ) {
394             curve->setHorUnits( QString( rowUnits[ horIndex ].c_str() ) );
395             curve->setVerUnits( QString( rowUnits[ verIndex[i] ].c_str() ) );
396           }
397           // curve data
398           int nbPoints = 0;
399           for ( j = 1; j <= nbCols; j++ ) {
400             if ( tblRealAttr->HasValue( horIndex+1, j ) && tblRealAttr->HasValue( verIndex[i]+1, j ) )
401               nbPoints++;
402           }
403           if ( nbPoints > 0 ) {
404             double* xList = new double[ nbPoints ];
405             double* yList = new double[ nbPoints ];
406             QStringList zList;
407             for ( j = 1; j <= nbCols; j++ ) {
408               if ( tblRealAttr->HasValue( horIndex+1, j ) && tblRealAttr->HasValue( verIndex[i]+1, j ) ) {
409                 xList[j-1] = tblRealAttr->GetValue( horIndex   +1, j );
410                 yList[j-1] = tblRealAttr->GetValue( verIndex[i]+1, j );
411                 zList.append( QString( "%1" ).arg( tblIntAttr->GetValue( zIndices[i]+1, j ) ) );
412               }
413             }
414             curve->setData( xList, yList, nbPoints, zList );
415           }
416           // curve attributes
417           curve->setLine( (Plot2d::LineType)myItems.at( verIndex[i] )->getLine(), myItems.at( verIndex[i] )->getLineWidth() );
418           curve->setMarker( (Plot2d::MarkerType)myItems.at( verIndex[i] )->getMarker() );
419           curve->setColor( myItems.at( verIndex[i] )->getColor() );
420           curve->setAutoAssign( myItems.at( verIndex[i] )->isAutoAssign() );
421           // add curve into container
422           container.append( curve );
423         }
424       }
425       catch( ... ) {
426         MESSAGE("VisuGUI_SetupPlot2dDlg::getCurves : Exception has been caught (real)!!!");
427       }
428     }
429   }
430 }
431 /*!
432   Slot, called when any <H> button is clicked
433 */
434 void VisuGUI_SetupPlot2dDlg::onHBtnToggled( bool on )
435 {
436   VisuGUI_ItemContainer* item = ( VisuGUI_ItemContainer* )sender();
437   if ( on ) {
438     for ( int i = 0; i < myItems.count(); i++ ) {
439       if ( myItems.at( i ) != item )
440         myItems.at( i )->setHorizontalOn( false );
441     }
442   }
443   enableControls();
444 }
445 /*!
446   Slot, called when any <V> button is clicked
447 */
448 void VisuGUI_SetupPlot2dDlg::onVBtnToggled( bool on )
449 {
450   VisuGUI_ItemContainer* item = ( VisuGUI_ItemContainer* )sender();
451   QList<VisuGUI_ItemContainer*> itemList;
452   //itemList.setAutoDelete( false );
453   item->myAssigned->setEnabled( on );
454   int i;
455   if ( on ) {
456     int totalOn = 0;
457     for ( i = 0; i < myItems.count(); i++ ) {
458       if ( myItems.at( i ) != item && !myItems.at( i )->isHorizontalOn() ) {
459         if ( myItems.at( i )->myUnitLab->text() == item->myUnitLab->text() ) {
460           if ( myItems.at( i )->isVerticalOn() )
461             totalOn++;
462           else
463             itemList.append( myItems.at( i ) );
464         }
465         else {
466           myItems.at( i )->setVerticalOn( false );
467         }
468       }
469     }
470     if ( totalOn == 0 && !itemList.isEmpty() && 
471          SUIT_MessageBox::information( this, 
472                                        this->windowTitle(), 
473                                        tr( "QUE_WANT_SAME_UNITS" ),
474                                        tr( "BUT_YES" ), 
475                                        tr( "BUT_NO" ), 
476                                        1, 1 ) == 0 )
477     {
478       for ( i = 0; i < itemList.count(); i++ ) {
479         itemList.at( i )->blockSignals( true );
480         itemList.at( i )->setVerticalOn( true );
481         itemList.at( i )->blockSignals( false );
482       }
483     }
484   }
485   enableControls();
486 }
487 /*!
488   Slot, called when <Help> button is clicked
489 */
490 void VisuGUI_SetupPlot2dDlg::onHelp()
491 {
492   QString aHelpFileName = "creating_curves_page.html";
493   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
494   if (app) {
495     VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
496     app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
497   }
498   else {
499                 QString platform;
500 #ifdef WIN32
501                 platform = "winapplication";
502 #else
503                 platform = "application";
504 #endif
505     SUIT_MessageBox::warning(0, tr("WRN_WARNING"),
506                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
507                              arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
508                              tr("BUT_OK"));
509   }
510 }
511 /*!
512   Enables/disables buttons 
513 */
514 void VisuGUI_SetupPlot2dDlg::enableControls()
515 {
516   bool bHSet = false;
517   bool bVSet = false;
518   for ( int i = 0; i < myItems.count(); i++ ) {
519     if ( myItems.at( i )->isHorizontalOn() ) {
520       bHSet = true;
521       break;
522     }
523   }
524   for ( int i = 0; i < myItems.count(); i++ ) {
525     if ( myItems.at( i )->isVerticalOn() )
526       bVSet = true;
527     myItems.at( i )->enableWidgets( bHSet && myItems.at( i )->isVerticalOn() );
528   }
529   myOkBtn->setEnabled( bHSet && bVSet );
530 }
531
532 /*!
533   Provides help on F1 button click
534 */
535 void VisuGUI_SetupPlot2dDlg::keyPressEvent( QKeyEvent* e )
536 {
537   QDialog::keyPressEvent( e );
538   if ( e->isAccepted() )
539     return;
540
541   if ( e->key() == Qt::Key_F1 )
542     {
543       e->accept();
544       onHelp();
545     }
546 }
547
548 // ====================================================================================
549 /*!
550   Constructor
551 */
552 VisuGUI_ItemContainer::VisuGUI_ItemContainer( QObject* parent )
553      : QObject( parent ), 
554        myEnabled( true )
555 {
556 }
557 /*!
558   Creates widgets
559 */
560 void VisuGUI_ItemContainer::createWidgets( QWidget* parentWidget, const QStringList& lst )
561 {
562   myHBtn = new QToolButton( parentWidget );
563   myHBtn->setText( tr( "H" ) );
564   myHBtn->setCheckable( true );
565   myHBtn->setChecked( false );
566
567   myVBtn = new QToolButton( parentWidget );
568   myVBtn->setText( tr( "V" ) );
569   myVBtn->setCheckable( true );
570   myVBtn->setChecked( false );
571   
572   myTitleLab = new QLabel( parentWidget );
573   myUnitLab  = new QLabel( parentWidget );
574   myUnitLab->setAlignment( Qt::AlignCenter);
575   
576   myAutoCheck = new QCheckBox( tr( "AUTO_CHECK_LBL" ), parentWidget );
577   myAutoCheck->setChecked( true );
578
579   myLineCombo = new QComboBox( parentWidget );
580   myLineCombo->addItem( tr( "NONE_LINE_LBL" ) );
581   myLineCombo->addItem( tr( "SOLID_LINE_LBL" ) );
582   myLineCombo->addItem( tr( "DASH_LINE_LBL" ) );
583   myLineCombo->addItem( tr( "DOT_LINE_LBL" ) );
584   myLineCombo->addItem( tr( "DASHDOT_LINE_LBL" ) );
585   myLineCombo->addItem( tr( "DAHSDOTDOT_LINE_LBL" ) );
586   myLineCombo->setCurrentIndex( 1 ); // SOLID by default
587
588   myLineSpin = new QSpinBox( parentWidget );
589   myLineSpin->setMinimum( 0 );
590   myLineSpin->setMaximum( MAX_LINE_WIDTH );
591   myLineSpin->setSingleStep( 1 );
592   myLineSpin->setValue( 0 );        // width = 0 by default
593
594   myMarkerCombo = new QComboBox( parentWidget );
595   myMarkerCombo->addItem( tr( "NONE_MARKER_LBL" ) );
596   myMarkerCombo->addItem( tr( "CIRCLE_MARKER_LBL" ) );
597   myMarkerCombo->addItem( tr( "RECTANGLE_MARKER_LBL" ) );
598   myMarkerCombo->addItem( tr( "DIAMOND_MARKER_LBL" ) );
599   myMarkerCombo->addItem( tr( "DTRIANGLE_MARKER_LBL" ) );
600   myMarkerCombo->addItem( tr( "UTRIANGLE_MARKER_LBL" ) );
601   myMarkerCombo->addItem( tr( "LTRIANGLE_MARKER_LBL" ) );
602   myMarkerCombo->addItem( tr( "RTRIANGLE_MARKER_LBL" ) );
603   myMarkerCombo->addItem( tr( "CROSS_MARKER_LBL" ) );
604   myMarkerCombo->addItem( tr( "XCROSS_MARKER_LBL" ) );
605   myMarkerCombo->setCurrentIndex( 1 ); // CIRCLE by default
606
607   myColorBtn = new QtxColorButton( parentWidget );
608   myColorBtn->setMinimumWidth( 20 );
609
610   myAssigned = new QComboBox( parentWidget );
611   myAssigned->addItem( "" );
612   QStringList::const_iterator anIt = lst.begin(), aLast = lst.end();
613   for( ; anIt!=aLast; anIt++ )
614     myAssigned->addItem( *anIt );
615   myAssigned->setEnabled( false );
616  
617   connect( myAutoCheck, SIGNAL( clicked() ),       this, SLOT( onAutoChanged() ) );
618   //connect( myColorBtn,  SIGNAL( clicked() ),       this, SLOT( onColorChanged() ) );
619   connect( myHBtn,      SIGNAL( toggled( bool ) ), this, SLOT( onHVToggled( bool ) ) );
620   connect( myVBtn,      SIGNAL( toggled( bool ) ), this, SLOT( onHVToggled( bool ) ) );
621   setColor( QColor( 0, 0, 0 ) );
622   updateState();
623 }
624 /*!
625   Enables attributes widgets
626 */
627 void VisuGUI_ItemContainer::enableWidgets( bool enable )
628 {
629   myEnabled = enable;
630   updateState();
631 }
632 /*!
633   Sets horizontal button's state on
634 */
635 void VisuGUI_ItemContainer::setHorizontalOn( bool on )
636 {
637   myHBtn->setChecked( on );
638 }
639 /*!
640   Gets horizontal button's state
641 */
642 bool VisuGUI_ItemContainer::isHorizontalOn() const
643 {
644   return myHBtn->isChecked();
645 }
646 /*!
647   Sets vertical button's state on
648 */
649 void VisuGUI_ItemContainer::setVerticalOn( bool on )
650 {
651   myVBtn->setChecked( on );
652 }
653 /*!
654   Gets vertical button's state
655 */
656 bool VisuGUI_ItemContainer::isVerticalOn() const
657 {
658   return myVBtn->isChecked();
659 }
660 /*!
661   Sets item AutoAssign flag state
662 */
663 void VisuGUI_ItemContainer::setAutoAssign( bool on )
664 {
665   myAutoCheck->setChecked( on );
666   updateState();
667 }
668 /*!
669   Gets item AutoAssign flag state
670 */
671 bool VisuGUI_ItemContainer::isAutoAssign() const
672 {
673   return myAutoCheck->isChecked();
674 }
675 /*!
676   Sets item line type and width
677 */
678 void VisuGUI_ItemContainer::setLine( const int line, const int width )
679 {
680   myLineCombo->setCurrentIndex( line );
681 }
682 /*!
683   Gets item line type
684 */
685 int VisuGUI_ItemContainer::getLine() const
686 {
687   return myLineCombo->currentIndex();
688 }
689 /*!
690   Gets item line width
691 */
692 int VisuGUI_ItemContainer::getLineWidth() const
693 {
694   return myLineSpin->value();
695 }
696 /*!
697   Sets item marker type
698 */
699 void VisuGUI_ItemContainer::setMarker( const int marker )
700 {
701   myMarkerCombo->setCurrentIndex( marker );
702 }
703 /*!
704   Gets item marker type
705 */
706 int VisuGUI_ItemContainer::getMarker() const
707 {
708   return myMarkerCombo->currentIndex();
709 }
710 /*!
711   Sets item color
712 */
713
714 void VisuGUI_ItemContainer::setColor( const QColor& color )
715 {
716   //QPalette pal = myColorBtn->palette();
717   //pal.setColor( myColorBtn->backgroundRole(), color );
718   myColorBtn->setColor( color );
719 }
720 /*!
721   Gets item color
722 */
723 QColor VisuGUI_ItemContainer::getColor() const
724 {
725   return myColorBtn->color();//palette().color( myColorBtn->backgroundRole() );
726 }
727 /*!
728   Enables/disables widgets
729 */
730 void VisuGUI_ItemContainer::updateState()
731 {
732   myAutoCheck->setEnabled( myEnabled );
733   myLineCombo->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
734   myLineSpin->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
735   myMarkerCombo->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
736   myColorBtn->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
737 }
738 /*!
739   Slot, called when user clickes <Auto assign> check box
740 */
741 void VisuGUI_ItemContainer::onAutoChanged()
742 {
743   updateState();
744   emit( autoClicked() );
745 }
746 /*!
747   <Color> button slot, invokes color selection dialog box
748 */
749 /*void VisuGUI_ItemContainer::onColorChanged()
750 {
751   QColor color = QColorDialog::getColor( getColor() );
752   if ( color.isValid() ) {
753     setColor( color );
754   }
755 }*/
756 /*!
757   <H> and <V> buttons slot
758 */
759 void VisuGUI_ItemContainer::onHVToggled( bool on )
760 {
761   const QObject* snd = sender();
762   if ( snd == myHBtn ) {
763     if ( on ) {
764       if ( myVBtn->isChecked() ) {
765 //      blockSignals( true );
766         myVBtn->setChecked( false );
767 //      blockSignals( false );
768       }
769     }
770     emit horToggled( on );
771   }
772   else {
773     if ( on ) {
774       if ( myHBtn->isChecked() ) {
775 //      blockSignals( true );
776         myHBtn->setChecked( false );
777 //      blockSignals( false );
778       }
779     }
780     emit verToggled( on );
781   }
782 }
783
784 /*!
785   \return index of assigned row (0, if there is no assigned row)
786 */
787 int VisuGUI_ItemContainer::assigned() const
788 {
789   if( isVerticalOn() )
790     return myAssigned->currentIndex()-1;
791   else
792     return -1;
793 }