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 QVBoxLayout* toplevel = new QVBoxLayout( this, 10 );
00048
00049 QGridLayout* layout = new QGridLayout( 1, 3 );
00050 toplevel->addLayout( layout );
00051
00052 QButtonGroup* gb1 = new QButtonGroup( 0, Qt::Vertical, i18n("Parameters"), this );
00053 gb1->layout()->setSpacing(KDialog::spacingHint());
00054 gb1->layout()->setMargin(KDialog::marginHint());
00055 QGridLayout *grid1 = new QGridLayout(gb1->layout(),9,1);
00056
00057 grid = new QCheckBox( i18n( "Grid" ), gb1 );
00058 QWhatsThis::add(grid, i18n("If this is checked, the grid is shown. If you uncheck this option, the grid will not be displayed anymore."));
00059 grid1->addWidget(grid, 0, 0);
00060
00061 yaxis = new QCheckBox( i18n( "Y-axis" ), gb1);
00062 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."));
00063 connect( yaxis, SIGNAL( clicked() ), this, SLOT( axisChanged() ) );
00064 grid1->addWidget(yaxis, 1, 0);
00065
00066 xaxis = new QCheckBox( i18n( "X-axis" ), gb1 );
00067 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."));
00068 connect( xaxis, SIGNAL( clicked() ), this, SLOT( axisChanged() ) );
00069 grid1->addWidget(xaxis, 2, 0);
00070
00071 #if 0
00072 xlabel = new QCheckBox( i18n( "Has X-label" ), gb1 );
00073 grid1->addWidget(xlabel,3,0);
00074
00075 yaxis2 = new QCheckBox( i18n( "Y-axis 2" ), gb1 );
00076 grid1->addWidget(yaxis2,4,0);
00077 #endif
00078
00079 #if 0 // Moved to the Line page
00080 lineMarker = new QCheckBox( i18n( "Line marker" ), gb1 );
00081 grid1->addWidget(lineMarker, 4, 0);
00082 #endif
00083 #if 0
00084 llabel = new QCheckBox( i18n( "Legend" ), gb1 );
00085 grid1->addWidget(llabel,6,0);
00086 #endif
00087
00088 QButtonGroup* gb2 = new QButtonGroup( 0, Qt::Vertical,
00089 i18n("Settings"), this );
00090 gb2->layout()->setSpacing(KDialog::spacingHint());
00091 gb2->layout()->setMargin(KDialog::marginHint());
00092 QGridLayout *grid2 = new QGridLayout(gb2->layout(),8,1);
00093
00094 QHBoxLayout * top = new QHBoxLayout( this );
00095
00096 QLabel *tmpLabel = new QLabel( i18n( "X-title:" ), gb2 );
00097 top->addWidget(tmpLabel);
00098
00099 tmpLabel = new QLabel( i18n( "Y-title:" ), gb2 );
00100 top->addWidget(tmpLabel);
00101
00102 QHBoxLayout * bottom = new QHBoxLayout( this );
00103 xtitle= new QLineEdit( gb2 );
00104 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."));
00105 bottom->addWidget(xtitle);
00106 QBoxLayout * l = new QVBoxLayout( this );
00107 ytitle= new QLineEdit( gb2 );
00108 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."));
00109 bottom->addWidget(ytitle);
00110
00111 l->addLayout(top);
00112 l->addLayout(bottom);
00113 grid2->addLayout(l, 0, 0);
00114
00115
00116 QVButtonGroup *scaletype = new QVButtonGroup(i18n("Scale Types"), gb2);
00117 lin = new QRadioButton( i18n("Linear scale"), scaletype);
00118 QWhatsThis::add(lin, i18n("This sets the Y-axis to be linear. This is default."));
00119 log = new QRadioButton( i18n("Logarithmic scale"), scaletype);
00120 QWhatsThis::add(log, i18n("This sets the Y-axis to be logarithmic."));
00121 grid2->addWidget(scaletype, 1, 0);
00122
00123
00124 QVButtonGroup *precision = new QVButtonGroup(i18n("Precision for Numerical Left Axis"), gb2);
00125 grid2->addWidget(precision, 2, 0);
00126 QRadioButton * automatic_precision = new QRadioButton( i18n("Automatic precision"), precision);
00127 QWhatsThis::add(automatic_precision, i18n("This sets the precision as automatic which means that KChart decides what precision to apply."));
00128 automatic_precision->setChecked(true);
00129 max = new QRadioButton( i18n("Decimal precision:"), precision);
00130 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."));
00131 connect(automatic_precision, SIGNAL(toggled(bool)), this,
00132 SLOT(automatic_precision_toggled(bool)) );
00133 maximum_length = new QSpinBox(0, 15, 1, precision );
00134 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."));
00135 maximum_length->setValue(2);
00136
00137 #if 0
00138 tmpLabel = new QLabel( i18n( "Y-label format:" ), gb2 );
00139 grid2->addWidget(tmpLabel,0,1);
00140
00141 ylabel_fmt= new QLineEdit( gb2 );
00142 ylabel_fmt->setMaximumWidth(130);
00143 grid2->addWidget(ylabel_fmt,1,1);
00144 ylabel_fmt->setEnabled(false);
00145
00146 tmpLabel = new QLabel( i18n( "Y-title 2:" ), gb2 );
00147 grid2->addWidget(tmpLabel,2,1);
00148
00149 ytitle2= new QLineEdit( gb2 );
00150 ytitle2->setMaximumWidth(130);
00151 grid2->addWidget(ytitle2,3,1);
00152
00153 tmpLabel = new QLabel( i18n( "Y-label format 2:" ), gb2 );
00154 grid2->addWidget(tmpLabel,4,1);
00155
00156 ylabel2_fmt= new QLineEdit( gb2 );
00157 ylabel2_fmt->setMaximumWidth(130);
00158 grid2->addWidget(ylabel2_fmt,5,1);
00159 #endif
00160 layout->addWidget(gb1,0,0);
00161 layout->addWidget(gb2,0,1);
00162
00163 #if 0
00164 grid1->activate();
00165 grid2->activate();
00166 #endif
00167
00168
00169
00170
00171 }
00172
00173
00174 void KChartParameterConfigPage::changeXaxisState(bool )
00175 {
00176 #if 0
00177 if(state)
00178 xlabel->setEnabled(true);
00179 else
00180 xlabel->setEnabled(false);
00181 #endif
00182 }
00183
00184 void KChartParameterConfigPage::init()
00185 {
00186
00187
00188
00189
00190 grid->setChecked(_params->showGrid());
00191
00192 xaxis->setChecked(_params->axisVisible(KDChartAxisParams::AxisPosBottom));
00193 yaxis->setChecked(_params->axisVisible(KDChartAxisParams::AxisPosLeft));
00194
00195 #if 0
00196 llabel->setChecked(_params->legendPosition()!=KDChartParams::NoLegend);
00197 #endif
00198
00199 #if 0
00200 if ( _params->chartType() == KDChartParams::Line ) {
00201 lineMarker->setEnabled(true);
00202 lineMarker->setChecked(_params->lineMarker());
00203 }
00204 else {
00205 lineMarker->setEnabled(false);
00206 lineMarker->setChecked(false);
00207 }
00208 #endif
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 #if 0
00221 {
00222 yaxis2->setEnabled(false);
00223 ylabel2_fmt->setEnabled(false);
00224 ytitle2->setEnabled(false);
00225 }
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 xlabel->setEnabled(false);
00237 #endif
00238
00239 xtitle->setText( _params->axisTitle( KDChartAxisParams::AxisPosBottom) );
00240 ytitle->setText( _params->axisTitle( KDChartAxisParams::AxisPosLeft) );
00241 axisChanged();
00242
00243
00244 if ( _params->axisParams( KDChartAxisParams::AxisPosLeft ).axisCalcMode() ==
00245 KDChartAxisParams::AxisCalcLinear )
00246 lin->setChecked(true);
00247 else
00248 log->setChecked(true);
00249
00250 if ( _params->axisParams( KDChartAxisParams::AxisPosLeft ).axisDigitsBehindComma() ==
00251 KDCHART_AXIS_LABELS_AUTO_DIGITS )
00252 maximum_length->setEnabled(false);
00253 else
00254 {
00255 max->setChecked(true);
00256 maximum_length->setValue( _params->axisParams( KDChartAxisParams::AxisPosLeft ).axisDigitsBehindComma() );
00257 }
00258 }
00259
00260
00261 void KChartParameterConfigPage::apply()
00262 {
00263 #if 0
00264 _params->setLegendPosition(llabel->isChecked() ? KDChartParams::LegendRight : KDChartParams::NoLegend);
00265 #endif
00266
00267 _params->setAxisVisible(KDChartAxisParams::AxisPosBottom,xaxis->isChecked());
00268 _params->setAxisVisible(KDChartAxisParams::AxisPosLeft,yaxis->isChecked());
00269
00270 _params->setAxisShowGrid(KDChartAxisParams::AxisPosLeft,
00271 grid->isChecked() );
00272 _params->setAxisShowGrid(KDChartAxisParams::AxisPosBottom,
00273 grid->isChecked() );
00274
00275 _params->setAxisTitle( KDChartAxisParams::AxisPosBottom, xtitle->text() );
00276 _params->setAxisTitle( KDChartAxisParams::AxisPosLeft, ytitle->text() );
00277
00278
00279
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 #if 0
00318 if( _params->chartType() == KDChartParams::Line )
00319 _params->setLineMarker(lineMarker->isChecked());
00320 #endif
00321
00322
00323 {
00324 KDChartAxisParams params;
00325 params = _params->axisParams( KDChartAxisParams::AxisPosLeft );
00326
00327 if (lin->isChecked())
00328 params.setAxisCalcMode(KDChartAxisParams::AxisCalcLinear);
00329 else
00330 {
00331 if(params.axisCalcMode() != KDChartAxisParams::AxisCalcLogarithmic)
00332 {
00333
00334
00335 _params->setChartType( KChartParams::Line );
00336 }
00337 params.setAxisCalcMode(KDChartAxisParams::AxisCalcLogarithmic);
00338 }
00339
00340 if ( maximum_length->isEnabled() )
00341 params.setAxisDigitsBehindComma( maximum_length->value() );
00342 else
00343 params.setAxisDigitsBehindComma( KDCHART_AXIS_LABELS_AUTO_DIGITS );
00344
00345 _params->setAxisParams( KDChartAxisParams::AxisPosLeft, params );
00346 }
00347 }
00348
00349 void KChartParameterConfigPage::automatic_precision_toggled(bool toggled)
00350 {
00351 if (toggled)
00352 maximum_length->setEnabled(false);
00353 else
00354 maximum_length->setEnabled(true);
00355 }
00356
00357 void KChartParameterConfigPage::axisChanged()
00358 {
00359 if ( !xaxis->isChecked() || !yaxis->isChecked() )
00360 {
00361 xtitle->setEnabled( false );
00362 ytitle->setEnabled( false );
00363 }
00364 else
00365 {
00366 xtitle->setEnabled( true );
00367 ytitle->setEnabled( true );
00368 }
00369 }
00370
00371 }