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