Salome HOME
PR: merge from branch BR_UnitTests tag mergeto_trunk_17oct05
[modules/kernel.git] / src / Plot2d / Plot2d_SetupViewDlg.cxx
1 //  Copyright (C) 2003  CEA/DEN, EDF R&D
2 //
3 //
4 //
5 //  File   : Plot2d_SetupViewDlg.cxx
6 //  Author : Vadim SANDLER
7 //  Module : SALOME
8 //  $Header$
9
10 #include "Plot2d_SetupViewDlg.h"
11 #include "QAD_Tools.h"
12
13 #include <qcheckbox.h>
14 #include <qlineedit.h>
15 #include <qcombobox.h>
16 #include <qspinbox.h>
17 #include <qtoolbutton.h>
18 #include <qlayout.h>
19 #include <qgroupbox.h>
20 #include <qlabel.h>
21 #include <qpushbutton.h>
22 #include <qcolordialog.h>
23 using namespace std;
24
25 #define MARGIN_SIZE          11
26 #define SPACING_SIZE         6
27 #define MIN_EDIT_WIDTH       200
28 #define MIN_COMBO_WIDTH      100
29 #define MIN_SPIN_WIDTH       70
30
31 /*!
32   Constructor
33 */
34 Plot2d_SetupViewDlg::Plot2d_SetupViewDlg( QWidget* parent, bool showDefCheck )
35     : QDialog( parent, "Plot2d_SetupViewDlg", true, 
36                WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
37 {
38   setCaption( tr("TLT_SETUP_PLOT2D_VIEW") );
39   setSizeGripEnabled( TRUE );
40   QGridLayout* topLayout = new QGridLayout( this ); 
41   topLayout->setSpacing( SPACING_SIZE );
42   topLayout->setMargin( MARGIN_SIZE );
43   
44   // main title
45   myTitleCheck = new QCheckBox( tr( "PLOT2D_ENABLE_MAIN_TITLE" ), this );
46   myTitleEdit  = new QLineEdit( this );
47   myTitleEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
48   myTitleEdit->setMinimumWidth( MIN_EDIT_WIDTH );
49   // horizontal axis title
50   myTitleXCheck = new QCheckBox( tr( "PLOT2D_ENABLE_HOR_TITLE" ), this );
51   myTitleXEdit  = new QLineEdit( this );
52   myTitleXEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
53   myTitleXEdit->setMinimumWidth( MIN_EDIT_WIDTH );
54   // vertical axis title
55   myTitleYCheck = new QCheckBox( tr( "PLOT2D_ENABLE_VER_TITLE" ), this );
56   myTitleYEdit  = new QLineEdit( this );
57   myTitleYEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
58   myTitleYEdit->setMinimumWidth( MIN_EDIT_WIDTH );
59   // curve type : points, lines, spline
60   QLabel* aCurveLab = new QLabel( tr( "PLOT2D_CURVE_TYPE_LBL" ), this );
61   myCurveCombo      = new QComboBox( false, this );
62   myCurveCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
63   myCurveCombo->setMinimumWidth( MIN_COMBO_WIDTH );
64   myCurveCombo->insertItem( tr( "PLOT2D_CURVE_TYPE_POINTS" ) );
65   myCurveCombo->insertItem( tr( "PLOT2D_CURVE_TYPE_LINES" ) );
66   myCurveCombo->insertItem( tr( "PLOT2D_CURVE_TYPE_SPLINE" ) );
67   // legend
68   myLegendCheck = new QCheckBox( tr( "PLOT2D_ENABLE_LEGEND" ), this );
69   myLegendCombo = new QComboBox( false, this );
70   myLegendCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
71   myLegendCombo->setMinimumWidth( MIN_COMBO_WIDTH );
72   myLegendCombo->insertItem( tr( "PLOT2D_LEGEND_POSITION_LEFT" ) );
73   myLegendCombo->insertItem( tr( "PLOT2D_LEGEND_POSITION_RIGHT" ) );
74   myLegendCombo->insertItem( tr( "PLOT2D_LEGEND_POSITION_TOP" ) );
75   myLegendCombo->insertItem( tr( "PLOT2D_LEGEND_POSITION_BOTTOM" ) );
76   // marker size
77   QLabel* aMarkerLab  = new QLabel( tr( "PLOT2D_MARKER_SIZE_LBL" ), this );
78   myMarkerSpin = new QSpinBox( 0, 100, 1, this );
79   myMarkerSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
80   myMarkerSpin->setMinimumWidth( MIN_SPIN_WIDTH );
81   // background color
82   QLabel* aBGLab  = new QLabel( tr( "PLOT2D_BACKGROUND_COLOR_LBL" ), this );
83   myBackgroundBtn = new QToolButton( this );
84   // scale mode
85   QGroupBox* aScaleGrp = new QGroupBox( tr( "PLOT2D_SCALE_TLT" ), this );
86   aScaleGrp->setColumnLayout(0, Qt::Vertical );
87   aScaleGrp->layout()->setSpacing( 0 );  aScaleGrp->layout()->setMargin( 0 );
88   QGridLayout* aScaleLayout = new QGridLayout( aScaleGrp->layout() );
89   aScaleLayout->setMargin( MARGIN_SIZE ); aScaleLayout->setSpacing( SPACING_SIZE );
90
91   QLabel* xScaleLab = new QLabel( tr( "PLOT2D_SCALE_MODE_HOR" ), aScaleGrp );
92   myXModeCombo = new QComboBox( false, aScaleGrp );
93   myXModeCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
94   myXModeCombo->setMinimumWidth( MIN_COMBO_WIDTH );
95   myXModeCombo->insertItem( tr( "PLOT2D_SCALE_MODE_LINEAR" ) );
96   myXModeCombo->insertItem( tr( "PLOT2D_SCALE_MODE_LOGARITHMIC" ) );
97   QLabel* yScaleLab = new QLabel( tr( "PLOT2D_SCALE_MODE_VER" ), aScaleGrp );
98   myYModeCombo = new QComboBox( false, aScaleGrp );
99   myYModeCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
100   myYModeCombo->setMinimumWidth( MIN_COMBO_WIDTH );
101   myYModeCombo->insertItem( tr( "PLOT2D_SCALE_MODE_LINEAR" ) );
102   myYModeCombo->insertItem( tr( "PLOT2D_SCALE_MODE_LOGARITHMIC" ) );
103
104   aScaleLayout->addWidget( xScaleLab,    0, 0 );
105   aScaleLayout->addWidget( myXModeCombo, 0, 1 );
106   aScaleLayout->addWidget( yScaleLab,    0, 2 );
107   aScaleLayout->addWidget( myYModeCombo, 0, 3 );
108
109   // grid
110   QGroupBox* aGridGrp = new QGroupBox( tr( "PLOT2D_GRID_TLT" ), this );
111   aGridGrp->setColumnLayout(0, Qt::Vertical );
112   aGridGrp->layout()->setSpacing( 0 );  aGridGrp->layout()->setMargin( 0 );
113   QGridLayout* aGridLayout = new QGridLayout( aGridGrp->layout() );
114   aGridLayout->setMargin( MARGIN_SIZE ); aGridLayout->setSpacing( SPACING_SIZE );
115
116   myXGridCheck      = new QCheckBox( tr( "PLOT2D_GRID_ENABLE_HOR_MAJOR" ), aGridGrp );
117   myXGridSpin       = new QSpinBox( 1, 100, 1, aGridGrp );
118   myXGridSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
119   myXGridSpin->setMinimumWidth( MIN_SPIN_WIDTH );
120   myYGridCheck      = new QCheckBox( tr( "PLOT2D_GRID_ENABLE_VER_MAJOR" ), aGridGrp );
121   myYGridSpin       = new QSpinBox( 1, 100, 1, aGridGrp );
122   myYGridSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
123   myYGridSpin->setMinimumWidth( MIN_SPIN_WIDTH );
124   myXMinGridCheck      = new QCheckBox( tr( "PLOT2D_GRID_ENABLE_HOR_MINOR" ), aGridGrp );
125   myXMinGridSpin       = new QSpinBox( 1, 100, 1, aGridGrp );
126   myXMinGridSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
127   myXMinGridSpin->setMinimumWidth( MIN_SPIN_WIDTH );
128   myYMinGridCheck      = new QCheckBox( tr( "PLOT2D_GRID_ENABLE_VER_MINOR" ), aGridGrp );
129   myYMinGridSpin       = new QSpinBox( 1, 100, 1, aGridGrp );
130   myYMinGridSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
131   myYMinGridSpin->setMinimumWidth( MIN_SPIN_WIDTH );
132
133   aGridLayout->addWidget( myXGridCheck,    0, 0 );
134   aGridLayout->addWidget( myXGridSpin,     0, 1 );
135   aGridLayout->addWidget( myYGridCheck,    0, 2 );
136   aGridLayout->addWidget( myYGridSpin,     0, 3 );
137   aGridLayout->addWidget( myXMinGridCheck, 1, 0 );
138   aGridLayout->addWidget( myXMinGridSpin,  1, 1 );
139   aGridLayout->addWidget( myYMinGridCheck, 1, 2 );
140   aGridLayout->addWidget( myYMinGridSpin,  1, 3 );
141
142   /* "Set as default" check box */
143   myDefCheck = new QCheckBox( tr( "PLOT2D_SET_AS_DEFAULT_CHECK" ), this );
144
145   /* OK/Cancel buttons */
146   myOkBtn = new QPushButton( tr( "BUT_OK" ), this );
147   myOkBtn->setAutoDefault( TRUE );
148   myOkBtn->setDefault( TRUE );
149   myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this );
150   myCancelBtn->setAutoDefault( TRUE );
151   QHBoxLayout* btnLayout = new QHBoxLayout;
152   btnLayout->addWidget( myOkBtn );
153   btnLayout->addStretch();
154   btnLayout->addWidget( myCancelBtn );
155   
156   // layout widgets
157   topLayout->addWidget( myTitleCheck,          0,    0    );
158   topLayout->addMultiCellWidget( myTitleEdit,  0, 0, 1, 3 );
159   topLayout->addWidget( myTitleXCheck,         1,    0    );
160   topLayout->addMultiCellWidget( myTitleXEdit, 1, 1, 1, 3 );
161   topLayout->addWidget( myTitleYCheck,         2,    0    );
162   topLayout->addMultiCellWidget( myTitleYEdit, 2, 2, 1, 3 );
163   topLayout->addWidget( aCurveLab,             3,    0    );
164   topLayout->addWidget( myCurveCombo,          3,    1    );
165   topLayout->addWidget( myLegendCheck,         3,    2    );
166   topLayout->addWidget( myLegendCombo,         3,    3    );
167   topLayout->addWidget( aMarkerLab,            4,    0    );
168   topLayout->addWidget( myMarkerSpin,          4,    1    );
169   QHBoxLayout* bgLayout = new QHBoxLayout;
170   bgLayout->addWidget( myBackgroundBtn ); bgLayout->addStretch();
171   topLayout->addWidget( aBGLab,                4,    2    );
172   topLayout->addLayout( bgLayout,              4,    3    );
173   topLayout->addMultiCellWidget( aScaleGrp,    5, 5, 0, 3 );
174   topLayout->addMultiCellWidget( aGridGrp,     6, 6, 0, 3 );
175   topLayout->addMultiCellWidget( myDefCheck,   7, 7, 0, 3 );
176   topLayout->setRowStretch( 8, 5 );
177   topLayout->addMultiCellLayout( btnLayout,    9, 9, 0, 3 );
178   
179   if ( !showDefCheck )
180     myDefCheck->hide();
181
182   connect( myTitleCheck,    SIGNAL( clicked() ), this, SLOT( onMainTitleChecked() ) );
183   connect( myTitleXCheck,   SIGNAL( clicked() ), this, SLOT( onXTitleChecked() ) );
184   connect( myTitleYCheck,   SIGNAL( clicked() ), this, SLOT( onYTitleChecked() ) );
185   connect( myBackgroundBtn, SIGNAL( clicked() ), this, SLOT( onBackgroundClicked() ) );
186   connect( myLegendCheck,   SIGNAL( clicked() ), this, SLOT( onLegendChecked() ) );
187   connect( myXGridCheck,    SIGNAL( clicked() ), this, SLOT( onXGridMajorChecked() ) );
188   connect( myYGridCheck,    SIGNAL( clicked() ), this, SLOT( onYGridMajorChecked() ) );
189   connect( myXMinGridCheck, SIGNAL( clicked() ), this, SLOT( onXGridMinorChecked() ) );
190   connect( myYMinGridCheck, SIGNAL( clicked() ), this, SLOT( onYGridMinorChecked() ) );
191
192   connect( myOkBtn,         SIGNAL( clicked() ), this, SLOT( accept() ) );
193   connect( myCancelBtn,     SIGNAL( clicked() ), this, SLOT( reject() ) );
194
195   /* Center widget inside it's parent widget */
196   QAD_Tools::centerWidget( this, parentWidget() );
197
198   // init fields
199   setBackgroundColor( Qt::gray );
200   onMainTitleChecked();
201   onXTitleChecked();
202   onYTitleChecked();
203   onLegendChecked();
204   onXGridMajorChecked();
205   onYGridMajorChecked();
206   onXGridMinorChecked();
207   onYGridMinorChecked();
208 }
209
210 /*!
211   Destructor
212 */
213 Plot2d_SetupViewDlg::~Plot2d_SetupViewDlg()
214 {
215 }
216 /*!
217   Sets main title attributes
218 */
219 void Plot2d_SetupViewDlg::setMainTitle( bool enable, const QString& title )
220 {
221   myTitleCheck->setChecked( enable );
222   if ( !title.isNull() )
223     myTitleEdit->setText( title );
224   onMainTitleChecked();
225 }
226 /*!
227   Returns TRUE if main title is enabled
228 */
229 bool Plot2d_SetupViewDlg::isMainTitleEnabled()
230 {
231   return myTitleCheck->isChecked();
232 }
233 /*!
234   Gets main title
235 */
236 QString Plot2d_SetupViewDlg::getMainTitle()
237 {
238   return myTitleEdit->text();
239 }
240 /*!
241   Sets horizontal axis title attributes
242 */
243 void Plot2d_SetupViewDlg::setXTitle( bool enable, const QString& title )
244 {
245   myTitleXCheck->setChecked( enable );
246   if ( !title.isNull() )
247     myTitleXEdit->setText( title );
248   onXTitleChecked();
249 }
250 /*!
251   Returns TRUE if horizontal axis title is enabled
252 */
253 bool Plot2d_SetupViewDlg::isXTitleEnabled()
254 {
255   return myTitleXCheck->isChecked();
256 }
257 /*!
258   Gets horizontal axis title
259 */
260 QString Plot2d_SetupViewDlg::getXTitle()
261 {
262   return myTitleXEdit->text();
263 }
264 /*!
265   Sets horizontal axis title attributes
266 */
267 void Plot2d_SetupViewDlg::setYTitle( bool enable, const QString& title )
268 {
269   myTitleYCheck->setChecked( enable );
270   if ( !title.isNull() )
271     myTitleYEdit->setText( title );
272   onYTitleChecked();
273 }
274 /*!
275   Returns TRUE if vertical axis title is enabled
276 */
277 bool Plot2d_SetupViewDlg::isYTitleEnabled()
278 {
279   return myTitleYCheck->isChecked();
280 }
281 /*!
282   Gets vertical axis title
283 */
284 QString Plot2d_SetupViewDlg::getYTitle()
285 {
286   return myTitleYEdit->text();
287 }
288 /*!
289   Sets curve type : 0 - points, 1 - lines, 2 - splines
290 */
291 void Plot2d_SetupViewDlg::setCurveType( const int type )
292 {
293   myCurveCombo->setCurrentItem( type );
294 }
295 /*!
296   Gets curve type : 0 - points, 1 - lines, 2 - splines
297 */
298 int Plot2d_SetupViewDlg::getCurveType()
299 {
300   return myCurveCombo->currentItem();
301 }
302 /*!
303   Sets legend attributes : pos = 0 - left, 1 - right, 2 - top, 3 - bottom
304 */
305 void Plot2d_SetupViewDlg::setLegend( bool enable, int pos )
306 {
307   myLegendCheck->setChecked( enable );
308   myLegendCombo->setCurrentItem( pos );
309   onLegendChecked();
310 }
311 /*!
312   Returns TRUE if legend is enabled
313 */
314 bool Plot2d_SetupViewDlg::isLegendEnabled()
315 {
316   return myLegendCheck->isChecked();
317 }
318 /*!
319   Returns legend position
320 */
321 int Plot2d_SetupViewDlg::getLegendPos()
322 {
323   return myLegendCombo->currentItem();
324 }
325 /*!
326   Sets marker size
327 */
328 void Plot2d_SetupViewDlg::setMarkerSize( const int size )
329 {
330   myMarkerSpin->setValue( size );
331 }
332 /*!
333   Gets marker size
334 */
335 int Plot2d_SetupViewDlg::getMarkerSize()
336 {
337   return myMarkerSpin->value();
338 }
339 /*!
340   Sets background color
341 */
342 void Plot2d_SetupViewDlg::setBackgroundColor( const QColor& color )
343 {
344   QPalette pal = myBackgroundBtn->palette();
345   QColorGroup ca = pal.active();
346   ca.setColor( QColorGroup::Button, color );
347   QColorGroup ci = pal.inactive();
348   ci.setColor( QColorGroup::Button, color );
349   pal.setActive( ca );
350   pal.setInactive( ci );
351   myBackgroundBtn->setPalette( pal );
352 }
353 /*!
354   Gets background color
355 */
356 QColor Plot2d_SetupViewDlg::getBackgroundColor()
357 {
358   return myBackgroundBtn->palette().active().button();
359 }
360 /*!
361   Sets major grid parameters
362 */
363 void Plot2d_SetupViewDlg::setMajorGrid( bool enableX, const int divX, bool enableY, const int divY )
364 {
365   myXGridCheck->setChecked( enableX );
366   myXGridSpin->setValue( divX );
367   myYGridCheck->setChecked( enableY );
368   myYGridSpin->setValue( divY );
369   onXGridMajorChecked();
370   onYGridMajorChecked();
371 }
372 /*!
373   Gets major grid parameters
374 */
375 void Plot2d_SetupViewDlg::getMajorGrid( bool& enableX, int& divX, bool& enableY, int& divY )
376 {
377   enableX = myXGridCheck->isChecked();
378   divX    = myXGridSpin->value();
379   enableY = myYGridCheck->isChecked();
380   divY    = myYGridSpin->value();
381 }
382 /*!
383   Sets minor grid parameters
384 */
385 void Plot2d_SetupViewDlg::setMinorGrid( bool enableX, const int divX, bool enableY, const int divY )
386 {
387   myXMinGridCheck->setChecked( enableX );
388   myXMinGridSpin->setValue( divX );
389   myYMinGridCheck->setChecked( enableY );
390   myYMinGridSpin->setValue( divY );
391   onXGridMinorChecked();
392   onYGridMinorChecked();
393 }
394 /*!
395   Gets minor grid parameters
396 */
397 void Plot2d_SetupViewDlg::getMinorGrid( bool& enableX, int& divX, bool& enableY, int& divY )
398 {
399   enableX = myXMinGridCheck->isChecked();
400   divX    = myXMinGridSpin->value();
401   enableY = myYMinGridCheck->isChecked();
402   divY    = myYMinGridSpin->value();
403 }
404 /*!
405   Sets scale mode for hor. and ver. axes : 0 - linear, 1 - logarithmic
406 */
407 void Plot2d_SetupViewDlg::setScaleMode( const int xMode, const int yMode )
408 {
409   myXModeCombo->setCurrentItem( xMode );
410   myYModeCombo->setCurrentItem( yMode );
411 }
412 /*!
413   Gets scale mode for hor. axis : 0 - linear, 1 - logarithmic
414 */
415 int  Plot2d_SetupViewDlg::getXScaleMode()
416 {
417   return myXModeCombo->currentItem();
418 }
419 /*!
420   Gets scale mode for hor. axis : 0 - linear, 1 - logarithmic
421 */
422 int  Plot2d_SetupViewDlg::getYScaleMode()
423 {
424   return myYModeCombo->currentItem();
425 }
426 /*!
427   Slot, called when user clicks "Show main title" check box
428 */
429 void Plot2d_SetupViewDlg::onMainTitleChecked()
430 {
431   myTitleEdit->setEnabled( myTitleCheck->isChecked() );
432 }
433 /*!
434   Slot, called when user clicks "Show horizontal axis title" check box
435 */
436 void Plot2d_SetupViewDlg::onXTitleChecked()
437 {
438   myTitleXEdit->setEnabled( myTitleXCheck->isChecked() );
439 }
440 /*!
441   Slot, called when user clicks "Show vertical axis title" check box
442 */
443 void Plot2d_SetupViewDlg::onYTitleChecked()
444 {
445   myTitleYEdit->setEnabled( myTitleYCheck->isChecked() );
446 }
447 /*!
448   Slot, called when user clicks "Change bacground color" button
449 */
450 void Plot2d_SetupViewDlg::onBackgroundClicked()
451 {
452   QColor color = QColorDialog::getColor( getBackgroundColor() );
453   if ( color.isValid() ) {
454     setBackgroundColor( color );
455   }
456 }
457 /*!
458   Slot, called when user clicks "Show Legend" check box
459 */
460 void Plot2d_SetupViewDlg::onLegendChecked()
461 {
462   myLegendCombo->setEnabled( myLegendCheck->isChecked() );
463 }
464 /*!
465   Slot, called when user clicks "Enable hor. major grid" check box
466 */
467 void Plot2d_SetupViewDlg::onXGridMajorChecked()
468 {
469   myXMinGridCheck->setEnabled( myXGridCheck->isChecked() );
470 }
471 /*!
472   Slot, called when user clicks  "Enable ver. major grid" check box
473 */
474 void Plot2d_SetupViewDlg::onYGridMajorChecked()
475 {
476   myYMinGridCheck->setEnabled( myYGridCheck->isChecked() );
477 }
478 /*!
479   Slot, called when user clicks  "Enable hor. minor grid" check box
480 */
481 void Plot2d_SetupViewDlg::onXGridMinorChecked()
482 {
483 }
484 /*!
485   Slot, called when user clicks  "Enable ver. minor grid" check box
486 */
487 void Plot2d_SetupViewDlg::onYGridMinorChecked()
488 {
489 }
490 /*!
491   Retursns true if "Set as default" check box is on
492 */
493 bool Plot2d_SetupViewDlg::isSetAsDefault()
494 {
495   return myDefCheck->isChecked();
496 }