1 // File : Plot2d_SetupViewDlg.cxx
2 // Created : Wed Jun 27 16:38:42 2001
3 // Author : Vadim SANDLER
6 // Copyright : Open CASCADE
9 #include "Plot2d_SetupViewDlg.h"
10 #include "QAD_Tools.h"
12 #include <qcheckbox.h>
13 #include <qlineedit.h>
14 #include <qcombobox.h>
16 #include <qtoolbutton.h>
18 #include <qgroupbox.h>
20 #include <qpushbutton.h>
21 #include <qcolordialog.h>
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
32 Plot2d_SetupViewDlg::Plot2d_SetupViewDlg( QWidget* parent, bool showDefCheck )
33 : QDialog( parent, "Plot2d_SetupViewDlg", true,
34 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
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 );
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" ) );
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" ) );
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 );
80 QLabel* aBGLab = new QLabel( tr( "PLOT2D_BACKGROUND_COLOR_LBL" ), this );
81 myBackgroundBtn = new QToolButton( this );
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 );
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" ) );
102 aScaleLayout->addWidget( xScaleLab, 0, 0 );
103 aScaleLayout->addWidget( myXModeCombo, 0, 1 );
104 aScaleLayout->addWidget( yScaleLab, 0, 2 );
105 aScaleLayout->addWidget( myYModeCombo, 0, 3 );
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 );
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 );
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 );
140 /* "Set as default" check box */
141 myDefCheck = new QCheckBox( tr( "PLOT2D_SET_AS_DEFAULT_CHECK" ), this );
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 );
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 );
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() ) );
190 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
191 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
193 /* Center widget inside it's parent widget */
194 QAD_Tools::centerWidget( this, parentWidget() );
197 setBackgroundColor( Qt::gray );
198 onMainTitleChecked();
202 onXGridMajorChecked();
203 onYGridMajorChecked();
204 onXGridMinorChecked();
205 onYGridMinorChecked();
211 Plot2d_SetupViewDlg::~Plot2d_SetupViewDlg()
215 Sets main title attributes
217 void Plot2d_SetupViewDlg::setMainTitle( bool enable, const QString& title )
219 myTitleCheck->setChecked( enable );
220 if ( !title.isNull() )
221 myTitleEdit->setText( title );
222 onMainTitleChecked();
225 Returns TRUE if main title is enabled
227 bool Plot2d_SetupViewDlg::isMainTitleEnabled()
229 return myTitleCheck->isChecked();
234 QString Plot2d_SetupViewDlg::getMainTitle()
236 return myTitleEdit->text();
239 Sets horizontal axis title attributes
241 void Plot2d_SetupViewDlg::setXTitle( bool enable, const QString& title )
243 myTitleXCheck->setChecked( enable );
244 if ( !title.isNull() )
245 myTitleXEdit->setText( title );
249 Returns TRUE if horizontal axis title is enabled
251 bool Plot2d_SetupViewDlg::isXTitleEnabled()
253 return myTitleXCheck->isChecked();
256 Gets horizontal axis title
258 QString Plot2d_SetupViewDlg::getXTitle()
260 return myTitleXEdit->text();
263 Sets horizontal axis title attributes
265 void Plot2d_SetupViewDlg::setYTitle( bool enable, const QString& title )
267 myTitleYCheck->setChecked( enable );
268 if ( !title.isNull() )
269 myTitleYEdit->setText( title );
273 Returns TRUE if vertical axis title is enabled
275 bool Plot2d_SetupViewDlg::isYTitleEnabled()
277 return myTitleYCheck->isChecked();
280 Gets vertical axis title
282 QString Plot2d_SetupViewDlg::getYTitle()
284 return myTitleYEdit->text();
287 Sets curve type : 0 - points, 1 - lines, 2 - splines
289 void Plot2d_SetupViewDlg::setCurveType( const int type )
291 myCurveCombo->setCurrentItem( type );
294 Gets curve type : 0 - points, 1 - lines, 2 - splines
296 int Plot2d_SetupViewDlg::getCurveType()
298 return myCurveCombo->currentItem();
301 Sets legend attributes : pos = 0 - left, 1 - right, 2 - top, 3 - bottom
303 void Plot2d_SetupViewDlg::setLegend( bool enable, int pos )
305 myLegendCheck->setChecked( enable );
306 myLegendCombo->setCurrentItem( pos );
310 Returns TRUE if legend is enabled
312 bool Plot2d_SetupViewDlg::isLegendEnabled()
314 return myLegendCheck->isChecked();
317 Returns legend position
319 int Plot2d_SetupViewDlg::getLegendPos()
321 return myLegendCombo->currentItem();
326 void Plot2d_SetupViewDlg::setMarkerSize( const int size )
328 myMarkerSpin->setValue( size );
333 int Plot2d_SetupViewDlg::getMarkerSize()
335 return myMarkerSpin->value();
338 Sets background color
340 void Plot2d_SetupViewDlg::setBackgroundColor( const QColor& color )
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 );
348 pal.setInactive( ci );
349 myBackgroundBtn->setPalette( pal );
352 Gets background color
354 QColor Plot2d_SetupViewDlg::getBackgroundColor()
356 return myBackgroundBtn->palette().active().button();
359 Sets major grid parameters
361 void Plot2d_SetupViewDlg::setMajorGrid( bool enableX, const int divX, bool enableY, const int divY )
363 myXGridCheck->setChecked( enableX );
364 myXGridSpin->setValue( divX );
365 myYGridCheck->setChecked( enableY );
366 myYGridSpin->setValue( divY );
367 onXGridMajorChecked();
368 onYGridMajorChecked();
371 Gets major grid parameters
373 void Plot2d_SetupViewDlg::getMajorGrid( bool& enableX, int& divX, bool& enableY, int& divY )
375 enableX = myXGridCheck->isChecked();
376 divX = myXGridSpin->value();
377 enableY = myYGridCheck->isChecked();
378 divY = myYGridSpin->value();
381 Sets minor grid parameters
383 void Plot2d_SetupViewDlg::setMinorGrid( bool enableX, const int divX, bool enableY, const int divY )
385 myXMinGridCheck->setChecked( enableX );
386 myXMinGridSpin->setValue( divX );
387 myYMinGridCheck->setChecked( enableY );
388 myYMinGridSpin->setValue( divY );
389 onXGridMinorChecked();
390 onYGridMinorChecked();
393 Gets minor grid parameters
395 void Plot2d_SetupViewDlg::getMinorGrid( bool& enableX, int& divX, bool& enableY, int& divY )
397 enableX = myXMinGridCheck->isChecked();
398 divX = myXMinGridSpin->value();
399 enableY = myYMinGridCheck->isChecked();
400 divY = myYMinGridSpin->value();
403 Sets scale mode for hor. and ver. axes : 0 - linear, 1 - logarithmic
405 void Plot2d_SetupViewDlg::setScaleMode( const int xMode, const int yMode )
407 myXModeCombo->setCurrentItem( xMode );
408 myYModeCombo->setCurrentItem( yMode );
411 Gets scale mode for hor. axis : 0 - linear, 1 - logarithmic
413 int Plot2d_SetupViewDlg::getXScaleMode()
415 return myXModeCombo->currentItem();
418 Gets scale mode for hor. axis : 0 - linear, 1 - logarithmic
420 int Plot2d_SetupViewDlg::getYScaleMode()
422 return myYModeCombo->currentItem();
425 Slot, called when user clicks "Show main title" check box
427 void Plot2d_SetupViewDlg::onMainTitleChecked()
429 myTitleEdit->setEnabled( myTitleCheck->isChecked() );
432 Slot, called when user clicks "Show horizontal axis title" check box
434 void Plot2d_SetupViewDlg::onXTitleChecked()
436 myTitleXEdit->setEnabled( myTitleXCheck->isChecked() );
439 Slot, called when user clicks "Show vertical axis title" check box
441 void Plot2d_SetupViewDlg::onYTitleChecked()
443 myTitleYEdit->setEnabled( myTitleYCheck->isChecked() );
446 Slot, called when user clicks "Change bacground color" button
448 void Plot2d_SetupViewDlg::onBackgroundClicked()
450 QColor color = QColorDialog::getColor( getBackgroundColor() );
451 if ( color.isValid() ) {
452 setBackgroundColor( color );
456 Slot, called when user clicks "Show Legend" check box
458 void Plot2d_SetupViewDlg::onLegendChecked()
460 myLegendCombo->setEnabled( myLegendCheck->isChecked() );
463 Slot, called when user clicks "Enable hor. major grid" check box
465 void Plot2d_SetupViewDlg::onXGridMajorChecked()
467 myXMinGridCheck->setEnabled( myXGridCheck->isChecked() );
470 Slot, called when user clicks "Enable ver. major grid" check box
472 void Plot2d_SetupViewDlg::onYGridMajorChecked()
474 myYMinGridCheck->setEnabled( myYGridCheck->isChecked() );
477 Slot, called when user clicks "Enable hor. minor grid" check box
479 void Plot2d_SetupViewDlg::onXGridMinorChecked()
483 Slot, called when user clicks "Enable ver. minor grid" check box
485 void Plot2d_SetupViewDlg::onYGridMinorChecked()
489 Retursns true if "Set as default" check box is on
491 bool Plot2d_SetupViewDlg::isSetAsDefault()
493 return myDefCheck->isChecked();