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>
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
33 Plot2d_SetupViewDlg::Plot2d_SetupViewDlg( QWidget* parent, bool showDefCheck )
34 : QDialog( parent, "Plot2d_SetupViewDlg", true,
35 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
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 );
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" ) );
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" ) );
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 );
81 QLabel* aBGLab = new QLabel( tr( "PLOT2D_BACKGROUND_COLOR_LBL" ), this );
82 myBackgroundBtn = new QToolButton( this );
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 );
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" ) );
103 aScaleLayout->addWidget( xScaleLab, 0, 0 );
104 aScaleLayout->addWidget( myXModeCombo, 0, 1 );
105 aScaleLayout->addWidget( yScaleLab, 0, 2 );
106 aScaleLayout->addWidget( myYModeCombo, 0, 3 );
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 );
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 );
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 );
141 /* "Set as default" check box */
142 myDefCheck = new QCheckBox( tr( "PLOT2D_SET_AS_DEFAULT_CHECK" ), this );
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 );
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 );
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() ) );
191 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
192 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
194 /* Center widget inside it's parent widget */
195 QAD_Tools::centerWidget( this, parentWidget() );
198 setBackgroundColor( Qt::gray );
199 onMainTitleChecked();
203 onXGridMajorChecked();
204 onYGridMajorChecked();
205 onXGridMinorChecked();
206 onYGridMinorChecked();
212 Plot2d_SetupViewDlg::~Plot2d_SetupViewDlg()
216 Sets main title attributes
218 void Plot2d_SetupViewDlg::setMainTitle( bool enable, const QString& title )
220 myTitleCheck->setChecked( enable );
221 if ( !title.isNull() )
222 myTitleEdit->setText( title );
223 onMainTitleChecked();
226 Returns TRUE if main title is enabled
228 bool Plot2d_SetupViewDlg::isMainTitleEnabled()
230 return myTitleCheck->isChecked();
235 QString Plot2d_SetupViewDlg::getMainTitle()
237 return myTitleEdit->text();
240 Sets horizontal axis title attributes
242 void Plot2d_SetupViewDlg::setXTitle( bool enable, const QString& title )
244 myTitleXCheck->setChecked( enable );
245 if ( !title.isNull() )
246 myTitleXEdit->setText( title );
250 Returns TRUE if horizontal axis title is enabled
252 bool Plot2d_SetupViewDlg::isXTitleEnabled()
254 return myTitleXCheck->isChecked();
257 Gets horizontal axis title
259 QString Plot2d_SetupViewDlg::getXTitle()
261 return myTitleXEdit->text();
264 Sets horizontal axis title attributes
266 void Plot2d_SetupViewDlg::setYTitle( bool enable, const QString& title )
268 myTitleYCheck->setChecked( enable );
269 if ( !title.isNull() )
270 myTitleYEdit->setText( title );
274 Returns TRUE if vertical axis title is enabled
276 bool Plot2d_SetupViewDlg::isYTitleEnabled()
278 return myTitleYCheck->isChecked();
281 Gets vertical axis title
283 QString Plot2d_SetupViewDlg::getYTitle()
285 return myTitleYEdit->text();
288 Sets curve type : 0 - points, 1 - lines, 2 - splines
290 void Plot2d_SetupViewDlg::setCurveType( const int type )
292 myCurveCombo->setCurrentItem( type );
295 Gets curve type : 0 - points, 1 - lines, 2 - splines
297 int Plot2d_SetupViewDlg::getCurveType()
299 return myCurveCombo->currentItem();
302 Sets legend attributes : pos = 0 - left, 1 - right, 2 - top, 3 - bottom
304 void Plot2d_SetupViewDlg::setLegend( bool enable, int pos )
306 myLegendCheck->setChecked( enable );
307 myLegendCombo->setCurrentItem( pos );
311 Returns TRUE if legend is enabled
313 bool Plot2d_SetupViewDlg::isLegendEnabled()
315 return myLegendCheck->isChecked();
318 Returns legend position
320 int Plot2d_SetupViewDlg::getLegendPos()
322 return myLegendCombo->currentItem();
327 void Plot2d_SetupViewDlg::setMarkerSize( const int size )
329 myMarkerSpin->setValue( size );
334 int Plot2d_SetupViewDlg::getMarkerSize()
336 return myMarkerSpin->value();
339 Sets background color
341 void Plot2d_SetupViewDlg::setBackgroundColor( const QColor& color )
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 );
349 pal.setInactive( ci );
350 myBackgroundBtn->setPalette( pal );
353 Gets background color
355 QColor Plot2d_SetupViewDlg::getBackgroundColor()
357 return myBackgroundBtn->palette().active().button();
360 Sets major grid parameters
362 void Plot2d_SetupViewDlg::setMajorGrid( bool enableX, const int divX, bool enableY, const int divY )
364 myXGridCheck->setChecked( enableX );
365 myXGridSpin->setValue( divX );
366 myYGridCheck->setChecked( enableY );
367 myYGridSpin->setValue( divY );
368 onXGridMajorChecked();
369 onYGridMajorChecked();
372 Gets major grid parameters
374 void Plot2d_SetupViewDlg::getMajorGrid( bool& enableX, int& divX, bool& enableY, int& divY )
376 enableX = myXGridCheck->isChecked();
377 divX = myXGridSpin->value();
378 enableY = myYGridCheck->isChecked();
379 divY = myYGridSpin->value();
382 Sets minor grid parameters
384 void Plot2d_SetupViewDlg::setMinorGrid( bool enableX, const int divX, bool enableY, const int divY )
386 myXMinGridCheck->setChecked( enableX );
387 myXMinGridSpin->setValue( divX );
388 myYMinGridCheck->setChecked( enableY );
389 myYMinGridSpin->setValue( divY );
390 onXGridMinorChecked();
391 onYGridMinorChecked();
394 Gets minor grid parameters
396 void Plot2d_SetupViewDlg::getMinorGrid( bool& enableX, int& divX, bool& enableY, int& divY )
398 enableX = myXMinGridCheck->isChecked();
399 divX = myXMinGridSpin->value();
400 enableY = myYMinGridCheck->isChecked();
401 divY = myYMinGridSpin->value();
404 Sets scale mode for hor. and ver. axes : 0 - linear, 1 - logarithmic
406 void Plot2d_SetupViewDlg::setScaleMode( const int xMode, const int yMode )
408 myXModeCombo->setCurrentItem( xMode );
409 myYModeCombo->setCurrentItem( yMode );
412 Gets scale mode for hor. axis : 0 - linear, 1 - logarithmic
414 int Plot2d_SetupViewDlg::getXScaleMode()
416 return myXModeCombo->currentItem();
419 Gets scale mode for hor. axis : 0 - linear, 1 - logarithmic
421 int Plot2d_SetupViewDlg::getYScaleMode()
423 return myYModeCombo->currentItem();
426 Slot, called when user clicks "Show main title" check box
428 void Plot2d_SetupViewDlg::onMainTitleChecked()
430 myTitleEdit->setEnabled( myTitleCheck->isChecked() );
433 Slot, called when user clicks "Show horizontal axis title" check box
435 void Plot2d_SetupViewDlg::onXTitleChecked()
437 myTitleXEdit->setEnabled( myTitleXCheck->isChecked() );
440 Slot, called when user clicks "Show vertical axis title" check box
442 void Plot2d_SetupViewDlg::onYTitleChecked()
444 myTitleYEdit->setEnabled( myTitleYCheck->isChecked() );
447 Slot, called when user clicks "Change bacground color" button
449 void Plot2d_SetupViewDlg::onBackgroundClicked()
451 QColor color = QColorDialog::getColor( getBackgroundColor() );
452 if ( color.isValid() ) {
453 setBackgroundColor( color );
457 Slot, called when user clicks "Show Legend" check box
459 void Plot2d_SetupViewDlg::onLegendChecked()
461 myLegendCombo->setEnabled( myLegendCheck->isChecked() );
464 Slot, called when user clicks "Enable hor. major grid" check box
466 void Plot2d_SetupViewDlg::onXGridMajorChecked()
468 myXMinGridCheck->setEnabled( myXGridCheck->isChecked() );
471 Slot, called when user clicks "Enable ver. major grid" check box
473 void Plot2d_SetupViewDlg::onYGridMajorChecked()
475 myYMinGridCheck->setEnabled( myYGridCheck->isChecked() );
478 Slot, called when user clicks "Enable hor. minor grid" check box
480 void Plot2d_SetupViewDlg::onXGridMinorChecked()
484 Slot, called when user clicks "Enable ver. minor grid" check box
486 void Plot2d_SetupViewDlg::onYGridMinorChecked()
490 Retursns true if "Set as default" check box is on
492 bool Plot2d_SetupViewDlg::isSetAsDefault()
494 return myDefCheck->isChecked();