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