1 // Copyright (C) 2003 CEA/DEN, EDF R&D
5 // File : Plot2d_SetupViewDlg.cxx
6 // Author : Vadim SANDLER
10 #include "Plot2d_SetupViewDlg.h"
11 #include "QAD_Tools.h"
13 #include <qcheckbox.h>
14 #include <qlineedit.h>
15 #include <qcombobox.h>
17 #include <qtoolbutton.h>
19 #include <qgroupbox.h>
21 #include <qpushbutton.h>
22 #include <qcolordialog.h>
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
34 Plot2d_SetupViewDlg::Plot2d_SetupViewDlg( QWidget* parent, bool showDefCheck )
35 : QDialog( parent, "Plot2d_SetupViewDlg", true,
36 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
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 );
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" ) );
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" ) );
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 );
82 QLabel* aBGLab = new QLabel( tr( "PLOT2D_BACKGROUND_COLOR_LBL" ), this );
83 myBackgroundBtn = new QToolButton( this );
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 );
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" ) );
104 aScaleLayout->addWidget( xScaleLab, 0, 0 );
105 aScaleLayout->addWidget( myXModeCombo, 0, 1 );
106 aScaleLayout->addWidget( yScaleLab, 0, 2 );
107 aScaleLayout->addWidget( myYModeCombo, 0, 3 );
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 );
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 );
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 );
142 /* "Set as default" check box */
143 myDefCheck = new QCheckBox( tr( "PLOT2D_SET_AS_DEFAULT_CHECK" ), this );
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 );
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 );
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() ) );
192 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
193 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
195 /* Center widget inside it's parent widget */
196 QAD_Tools::centerWidget( this, parentWidget() );
199 setBackgroundColor( Qt::gray );
200 onMainTitleChecked();
204 onXGridMajorChecked();
205 onYGridMajorChecked();
206 onXGridMinorChecked();
207 onYGridMinorChecked();
213 Plot2d_SetupViewDlg::~Plot2d_SetupViewDlg()
217 Sets main title attributes
219 void Plot2d_SetupViewDlg::setMainTitle( bool enable, const QString& title )
221 myTitleCheck->setChecked( enable );
222 if ( !title.isNull() )
223 myTitleEdit->setText( title );
224 onMainTitleChecked();
227 Returns TRUE if main title is enabled
229 bool Plot2d_SetupViewDlg::isMainTitleEnabled()
231 return myTitleCheck->isChecked();
236 QString Plot2d_SetupViewDlg::getMainTitle()
238 return myTitleEdit->text();
241 Sets horizontal axis title attributes
243 void Plot2d_SetupViewDlg::setXTitle( bool enable, const QString& title )
245 myTitleXCheck->setChecked( enable );
246 if ( !title.isNull() )
247 myTitleXEdit->setText( title );
251 Returns TRUE if horizontal axis title is enabled
253 bool Plot2d_SetupViewDlg::isXTitleEnabled()
255 return myTitleXCheck->isChecked();
258 Gets horizontal axis title
260 QString Plot2d_SetupViewDlg::getXTitle()
262 return myTitleXEdit->text();
265 Sets horizontal axis title attributes
267 void Plot2d_SetupViewDlg::setYTitle( bool enable, const QString& title )
269 myTitleYCheck->setChecked( enable );
270 if ( !title.isNull() )
271 myTitleYEdit->setText( title );
275 Returns TRUE if vertical axis title is enabled
277 bool Plot2d_SetupViewDlg::isYTitleEnabled()
279 return myTitleYCheck->isChecked();
282 Gets vertical axis title
284 QString Plot2d_SetupViewDlg::getYTitle()
286 return myTitleYEdit->text();
289 Sets curve type : 0 - points, 1 - lines, 2 - splines
291 void Plot2d_SetupViewDlg::setCurveType( const int type )
293 myCurveCombo->setCurrentItem( type );
296 Gets curve type : 0 - points, 1 - lines, 2 - splines
298 int Plot2d_SetupViewDlg::getCurveType()
300 return myCurveCombo->currentItem();
303 Sets legend attributes : pos = 0 - left, 1 - right, 2 - top, 3 - bottom
305 void Plot2d_SetupViewDlg::setLegend( bool enable, int pos )
307 myLegendCheck->setChecked( enable );
308 myLegendCombo->setCurrentItem( pos );
312 Returns TRUE if legend is enabled
314 bool Plot2d_SetupViewDlg::isLegendEnabled()
316 return myLegendCheck->isChecked();
319 Returns legend position
321 int Plot2d_SetupViewDlg::getLegendPos()
323 return myLegendCombo->currentItem();
328 void Plot2d_SetupViewDlg::setMarkerSize( const int size )
330 myMarkerSpin->setValue( size );
335 int Plot2d_SetupViewDlg::getMarkerSize()
337 return myMarkerSpin->value();
340 Sets background color
342 void Plot2d_SetupViewDlg::setBackgroundColor( const QColor& color )
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 );
350 pal.setInactive( ci );
351 myBackgroundBtn->setPalette( pal );
354 Gets background color
356 QColor Plot2d_SetupViewDlg::getBackgroundColor()
358 return myBackgroundBtn->palette().active().button();
361 Sets major grid parameters
363 void Plot2d_SetupViewDlg::setMajorGrid( bool enableX, const int divX, bool enableY, const int divY )
365 myXGridCheck->setChecked( enableX );
366 myXGridSpin->setValue( divX );
367 myYGridCheck->setChecked( enableY );
368 myYGridSpin->setValue( divY );
369 onXGridMajorChecked();
370 onYGridMajorChecked();
373 Gets major grid parameters
375 void Plot2d_SetupViewDlg::getMajorGrid( bool& enableX, int& divX, bool& enableY, int& divY )
377 enableX = myXGridCheck->isChecked();
378 divX = myXGridSpin->value();
379 enableY = myYGridCheck->isChecked();
380 divY = myYGridSpin->value();
383 Sets minor grid parameters
385 void Plot2d_SetupViewDlg::setMinorGrid( bool enableX, const int divX, bool enableY, const int divY )
387 myXMinGridCheck->setChecked( enableX );
388 myXMinGridSpin->setValue( divX );
389 myYMinGridCheck->setChecked( enableY );
390 myYMinGridSpin->setValue( divY );
391 onXGridMinorChecked();
392 onYGridMinorChecked();
395 Gets minor grid parameters
397 void Plot2d_SetupViewDlg::getMinorGrid( bool& enableX, int& divX, bool& enableY, int& divY )
399 enableX = myXMinGridCheck->isChecked();
400 divX = myXMinGridSpin->value();
401 enableY = myYMinGridCheck->isChecked();
402 divY = myYMinGridSpin->value();
405 Sets scale mode for hor. and ver. axes : 0 - linear, 1 - logarithmic
407 void Plot2d_SetupViewDlg::setScaleMode( const int xMode, const int yMode )
409 myXModeCombo->setCurrentItem( xMode );
410 myYModeCombo->setCurrentItem( yMode );
413 Gets scale mode for hor. axis : 0 - linear, 1 - logarithmic
415 int Plot2d_SetupViewDlg::getXScaleMode()
417 return myXModeCombo->currentItem();
420 Gets scale mode for hor. axis : 0 - linear, 1 - logarithmic
422 int Plot2d_SetupViewDlg::getYScaleMode()
424 return myYModeCombo->currentItem();
427 Slot, called when user clicks "Show main title" check box
429 void Plot2d_SetupViewDlg::onMainTitleChecked()
431 myTitleEdit->setEnabled( myTitleCheck->isChecked() );
434 Slot, called when user clicks "Show horizontal axis title" check box
436 void Plot2d_SetupViewDlg::onXTitleChecked()
438 myTitleXEdit->setEnabled( myTitleXCheck->isChecked() );
441 Slot, called when user clicks "Show vertical axis title" check box
443 void Plot2d_SetupViewDlg::onYTitleChecked()
445 myTitleYEdit->setEnabled( myTitleYCheck->isChecked() );
448 Slot, called when user clicks "Change bacground color" button
450 void Plot2d_SetupViewDlg::onBackgroundClicked()
452 QColor color = QColorDialog::getColor( getBackgroundColor() );
453 if ( color.isValid() ) {
454 setBackgroundColor( color );
458 Slot, called when user clicks "Show Legend" check box
460 void Plot2d_SetupViewDlg::onLegendChecked()
462 myLegendCombo->setEnabled( myLegendCheck->isChecked() );
465 Slot, called when user clicks "Enable hor. major grid" check box
467 void Plot2d_SetupViewDlg::onXGridMajorChecked()
469 myXMinGridCheck->setEnabled( myXGridCheck->isChecked() );
472 Slot, called when user clicks "Enable ver. major grid" check box
474 void Plot2d_SetupViewDlg::onYGridMajorChecked()
476 myYMinGridCheck->setEnabled( myYGridCheck->isChecked() );
479 Slot, called when user clicks "Enable hor. minor grid" check box
481 void Plot2d_SetupViewDlg::onXGridMinorChecked()
485 Slot, called when user clicks "Enable ver. minor grid" check box
487 void Plot2d_SetupViewDlg::onYGridMinorChecked()
491 Retursns true if "Set as default" check box is on
493 bool Plot2d_SetupViewDlg::isSetAsDefault()
495 return myDefCheck->isChecked();