00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kchartParameterConfigPage.h"
00022 #include "kchartParameterConfigPage.moc"
00023
00024 #include <kapplication.h>
00025 #include <klocale.h>
00026 #include <qlayout.h>
00027 #include <qlabel.h>
00028 #include <qcheckbox.h>
00029 #include <qlineedit.h>
00030 #include <qspinbox.h>
00031 #include <qbuttongroup.h>
00032 #include <qradiobutton.h>
00033 #include <qvbuttongroup.h>
00034 #include <kfontdialog.h>
00035 #include <qwhatsthis.h>
00036
00037 #include "kdchart/KDChartAxisParams.h"
00038 #include "kchart_params.h"
00039
00040 namespace KChart
00041 {
00042
00043 KChartParameterConfigPage::KChartParameterConfigPage( KChartParams* params,
00044 QWidget* parent ) :
00045 QWidget( parent ),_params( params )
00046 {
00047
00048 QVBoxLayout* toplevel = new QVBoxLayout( this, 10 );
00049
00050 QGridLayout* layout = new QGridLayout( 1, 3 );
00051 toplevel->addLayout( layout );
00052
00053
00054 QButtonGroup* gb1 = new QButtonGroup( 0, Qt::Vertical, i18n("Parameters"), this );
00055 gb1->layout()->setSpacing(KDialog::spacingHint());
00056 gb1->layout()->setMargin(KDialog::marginHint());
00057 QGridLayout *grid1 = new QGridLayout(gb1->layout(),9,1);
00058
00059 grid = new QCheckBox( i18n( "Grid" ), gb1 );
00060 QWhatsThis::add(grid, i18n("If this is checked, the grid is shown. If you uncheck this option, the grid will not be displayed anymore."));
00061 grid1->addWidget(grid, 0, 0);
00062
00063
00064 yaxis = new QCheckBox( i18n( "Y-axis" ), gb1);
00065 QWhatsThis::add(yaxis, i18n("If this is checked, the Y-axis is shown. If you uncheck this option, the Y-axis and the Y grid lines will not be displayed anymore."));
00066 connect( yaxis, SIGNAL( clicked() ), this, SLOT( axisChanged() ) );
00067 grid1->addWidget(yaxis, 1, 0);
00068
00069
00070 xaxis = new QCheckBox( i18n( "X-axis" ), gb1 );
00071 QWhatsThis::add(xaxis, i18n("If this is checked, the X-axis is shown. If you uncheck this option, the X-axis and the X grid lines will not be displayed anymore."));
00072 connect( xaxis, SIGNAL( clicked() ), this, SLOT( axisChanged() ) );
00073 grid1->addWidget(xaxis, 2, 0);
00074
00075
00076 #if 0
00077 xlabel = new QCheckBox( i18n( "Has X-label" ), gb1 );
00078 grid1->addWidget(xlabel,3,0);
00079
00080 yaxis2 = new QCheckBox( i18n( "Y-axis 2" ), gb1 );
00081 grid1->addWidget(yaxis2,4,0);
00082 #endif
00083
00084 #if 0 // Moved to the Line page
00085 lineMarker = new QCheckBox( i18n( "Line marker" ), gb1 );
00086 grid1->addWidget(lineMarker, 4, 0);
00087 #endif
00088 #if 0
00089 llabel = new QCheckBox( i18n( "Legend" ), gb1 );
00090 grid1->addWidget(llabel,6,0);
00091 #endif
00092
00093
00094 QButtonGroup* gb2 = new QButtonGroup( 0, Qt::Vertical,
00095 i18n("Settings"), this );
00096 gb2->layout()->setSpacing(KDialog::spacingHint());
00097 gb2->layout()->setMargin(KDialog::marginHint());
00098 QGridLayout *grid2 = new QGridLayout(gb2->layout(),8,1);
00099
00100 QBoxLayout * l = new QVBoxLayout( grid2 );
00101
00102 QHBoxLayout * top = new QHBoxLayout( l );
00103
00104 QLabel *tmpLabel = new QLabel( i18n( "X-title:" ), gb2 );
00105 top->addWidget(tmpLabel);
00106
00107 tmpLabel = new QLabel( i18n( "Y-title:" ), gb2 );
00108 top->addWidget(tmpLabel);
00109
00110 QHBoxLayout * bottom = new QHBoxLayout( l );
00111 xtitle= new QLineEdit( gb2 );
00112 QWhatsThis::add(xtitle, i18n("Write the title for the X-axis here, if you want a title. The color for this title is set in the Colors tab, in the same dialog, and the font is set in the Font tab."));
00113 bottom->addWidget(xtitle);
00114 ytitle= new QLineEdit( gb2 );
00115 QWhatsThis::add(ytitle, i18n("Write the title for the Y-axis here, if you want a title. The color for this title is set in the Colors tab, in the same dialog, and the font is set in the Font tab."));
00116 bottom->addWidget(ytitle);
00117
00118
00119 QVButtonGroup *scaletype = new QVButtonGroup(i18n("Scale Types"), gb2);
00120 lin = new QRadioButton( i18n("Linear scale"), scaletype);
00121 QWhatsThis::add(lin, i18n("This sets the Y-axis to be linear. This is default."));
00122 log = new QRadioButton( i18n("Logarithmic scale"), scaletype);
00123 QWhatsThis::add(log, i18n("This sets the Y-axis to be logarithmic."));
00124 grid2->addWidget(scaletype, 1, 0);
00125
00126
00127 QVButtonGroup *precision = new QVButtonGroup(i18n("Precision for Numerical Left Axis"), gb2);
00128 grid2->addWidget(precision, 2, 0);
00129 QRadioButton * automatic_precision = new QRadioButton( i18n("Automatic precision"), precision);
00130 QWhatsThis::add(automatic_precision, i18n("This sets the precision as automatic which means that KChart decides what precision to apply."));
00131 automatic_precision->setChecked(true);
00132 max = new QRadioButton( i18n("Decimal precision:"), precision);
00133 QWhatsThis::add(max, i18n("This sets the Y-axis precision. For example, if you choose a precision of 2, the value 5 will be displayed as 5.00 alongside the Y-axis."));
00134 connect(automatic_precision, SIGNAL(toggled(bool)), this,
00135 SLOT(automatic_precision_toggled(bool)) );
00136 maximum_length = new QSpinBox(0, 15, 1, precision );
00137 QWhatsThis::add(maximum_length, i18n("Set the precision you want to display for the Y-axis, if you choose Decimal precision. The range is 0 to 15; 2 being the default."));
00138 maximum_length->setValue(2);
00139
00140 #if 0
00141 tmpLabel = new QLabel( i18n( "Y-label format:" ), gb2 );
00142 grid2->addWidget(tmpLabel,0,1);
00143
00144 ylabel_fmt= new QLineEdit( gb2 );
00145 ylabel_fmt->setMaximumWidth(130);
00146 grid2->addWidget(ylabel_fmt,1,1);
00147 ylabel_fmt->setEnabled(false);
00148
00149 tmpLabel = new QLabel( i18n( "Y-title 2:" ), gb2 );
00150 grid2->addWidget(tmpLabel,2,1);
00151
00152 ytitle2= new QLineEdit( gb2 );
00153 ytitle2->setMaximumWidth(130);
00154 grid2->addWidget(ytitle2,3,1);
00155
00156 tmpLabel = new QLabel( i18n( "Y-label format 2:" ), gb2 );
00157 grid2->addWidget(tmpLabel,4,1);
00158
00159 ylabel2_fmt= new QLineEdit( gb2 );
00160 ylabel2_fmt->setMaximumWidth(130);
00161 grid2->addWidget(ylabel2_fmt,5,1);
00162 #endif
00163 layout->addWidget(gb1,0,0);
00164 layout->addWidget(gb2,0,1);
00165
00166 #if 0
00167 grid1->activate();
00168 grid2->activate();
00169 #endif
00170
00171
00172
00173
00174 }
00175
00176
00177 void KChartParameterConfigPage::changeXaxisState(bool )
00178 {
00179 #if 0
00180 if(state)
00181 xlabel->setEnabled(true);
00182 else
00183 xlabel->setEnabled(false);
00184 #endif
00185 }
00186
00187 void KChartParameterConfigPage::init()
00188 {
00189
00190
00191
00192
00193 grid->setChecked(_params->showGrid());
00194
00195 xaxis->setChecked(_params->axisVisible(KDChartAxisParams::AxisPosBottom));
00196 yaxis->setChecked(_params->axisVisible(KDChartAxisParams::AxisPosLeft));
00197
00198 #if 0
00199 llabel->setChecked(_params->legendPosition()!=KDChartParams::NoLegend);
00200 #endif
00201
00202 #if 0
00203 if ( _params->chartType() == KDChartParams::Line ) {
00204 lineMarker->setEnabled(true);
00205 lineMarker->setChecked(_params->lineMarker());
00206 }
00207 else {
00208 lineMarker->setEnabled(false);
00209 lineMarker->setChecked(false);
00210 }
00211 #endif
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 #if 0
00224 {
00225 yaxis2->setEnabled(false);
00226 ylabel2_fmt->setEnabled(false);
00227 ytitle2->setEnabled(false);
00228 }
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239 xlabel->setEnabled(false);
00240 #endif
00241
00242 xtitle->setText( _params->axisTitle( KDChartAxisParams::AxisPosBottom) );
00243 ytitle->setText( _params->axisTitle( KDChartAxisParams::AxisPosLeft) );
00244 axisChanged();
00245
00246
00247 if ( _params->axisParams( KDChartAxisParams::AxisPosLeft ).axisCalcMode() ==
00248 KDChartAxisParams::AxisCalcLinear )
00249 lin->setChecked(true);
00250 else
00251 log->setChecked(true);
00252
00253 if ( _params->axisParams( KDChartAxisParams::AxisPosLeft ).axisDigitsBehindComma() ==
00254 KDCHART_AXIS_LABELS_AUTO_DIGITS )
00255 maximum_length->setEnabled(false);
00256 else
00257 {
00258 max->setChecked(true);
00259 maximum_length->setValue( _params->axisParams( KDChartAxisParams::AxisPosLeft ).axisDigitsBehindComma() );
00260 }
00261 }
00262
00263
00264 void KChartParameterConfigPage::apply()
00265 {
00266 #if 0
00267 _params->setLegendPosition(llabel->isChecked() ? KDChartParams::LegendRight : KDChartParams::NoLegend);
00268 #endif
00269
00270 _params->setAxisVisible(KDChartAxisParams::AxisPosBottom,xaxis->isChecked());
00271 _params->setAxisVisible(KDChartAxisParams::AxisPosLeft,yaxis->isChecked());
00272
00273 _params->setAxisShowGrid(KDChartAxisParams::AxisPosLeft,
00274 grid->isChecked() );
00275 _params->setAxisShowGrid(KDChartAxisParams::AxisPosBottom,
00276 grid->isChecked() );
00277
00278 _params->setAxisTitle( KDChartAxisParams::AxisPosBottom, xtitle->text() );
00279 _params->setAxisTitle( KDChartAxisParams::AxisPosLeft, ytitle->text() );
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320 #if 0
00321 if( _params->chartType() == KDChartParams::Line )
00322 _params->setLineMarker(lineMarker->isChecked());
00323 #endif
00324
00325
00326 {
00327 KDChartAxisParams params;
00328 params = _params->axisParams( KDChartAxisParams::AxisPosLeft );
00329
00330 if (lin->isChecked())
00331 params.setAxisCalcMode(KDChartAxisParams::AxisCalcLinear);
00332 else
00333 {
00334 if(params.axisCalcMode() != KDChartAxisParams::AxisCalcLogarithmic)
00335 {
00336
00337
00338 _params->setChartType( KChartParams::Line );
00339 }
00340 params.setAxisCalcMode(KDChartAxisParams::AxisCalcLogarithmic);
00341 }
00342
00343 if ( maximum_length->isEnabled() )
00344 params.setAxisDigitsBehindComma( maximum_length->value() );
00345 else
00346 params.setAxisDigitsBehindComma( KDCHART_AXIS_LABELS_AUTO_DIGITS );
00347
00348 _params->setAxisParams( KDChartAxisParams::AxisPosLeft, params );
00349 }
00350 }
00351
00352 void KChartParameterConfigPage::automatic_precision_toggled(bool toggled)
00353 {
00354 if (toggled)
00355 maximum_length->setEnabled(false);
00356 else
00357 maximum_length->setEnabled(true);
00358 }
00359
00360 void KChartParameterConfigPage::axisChanged()
00361 {
00362 if ( !xaxis->isChecked() || !yaxis->isChecked() )
00363 {
00364 xtitle->setEnabled( false );
00365 ytitle->setEnabled( false );
00366 }
00367 else
00368 {
00369 xtitle->setEnabled( true );
00370 ytitle->setEnabled( true );
00371 }
00372 }
00373
00374 }