kchart

kchartParameterConfigPage.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001,2002,2003,2004 Laurent Montel <montel@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
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     // The X axis title
00096     QLabel *tmpLabel = new QLabel( i18n( "X-title:" ), gb2 );
00097     top->addWidget(tmpLabel);
00098     // The Y axis title
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     // Linear or logarithmic scale
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     // Decimal precision
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     /*connect( grid, SIGNAL( toggled( bool ) ),
00168       this, SLOT( changeState( bool ) ) );*/
00169     /*connect( xaxis, SIGNAL( toggled( bool ) ),
00170       this, SLOT( changeXaxisState( bool ) ) );*/
00171 }
00172 
00173 
00174     void KChartParameterConfigPage::changeXaxisState(bool /*state*/)
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     // PENDING(kalle) adapt these to KDChart
00187     //     grid->setChecked(_params->grid);
00188     //     xlabel->setChecked(_params->hasxlabel);
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     // PENDING(kalle) Adapt this
00211     //     if(_params->has_yaxis2())
00212     //      {
00213     //      yaxis2->setChecked(_params->yaxis2);
00214     //      int len=_params->ylabel2_fmt.length();
00215     //         ylabel2_fmt->setText(_params->ylabel2_fmt.right(len-3));
00216 
00217     //      ytitle2->setText(_params->ytitle2);
00218     //      }
00219     //     else
00220 #if 0
00221     {
00222         yaxis2->setEnabled(false);
00223         ylabel2_fmt->setEnabled(false);
00224         ytitle2->setEnabled(false);
00225     }
00226 
00227     // PENDING(kalle) Adapt this
00228     //     xtitle->setText(_params->xtitle);
00229     //     ytitle->setText(_params->ytitle);
00230     //     int len=_params->ylabel_fmt.length();
00231     //     ylabel_fmt->setText(_params->ylabel_fmt.right(len-3));
00232 
00233     //     if(_params->xaxis)
00234     //      xlabel->setEnabled(true);
00235     //     else
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     // Linear / logarithmic Y axis
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 // PENDING(kalle) Adapt this
00279     //     _params->border=border->isChecked();
00280     //     _params->llabel=llabel->isChecked();
00281     //     if(xaxis->isChecked())
00282     //      _params->hasxlabel=xlabel->isChecked();
00283     //     if(_params->has_yaxis2())
00284     //      {
00285     //      _params->yaxis2=yaxis2->isChecked();
00286     //      if(!ylabel2_fmt->text().isEmpty())
00287     //          _params->ylabel2_fmt="%g "+ylabel2_fmt->text();
00288     //      _params->ytitle2=ytitle2->text();
00289     //      }
00290 
00291 
00292     // PENDING(kalle) Adapt this
00293     //     if(grid->isChecked())
00294     //      _params->shelf=shelf->isChecked();
00295     //     _params->xtitle=xtitle->text();
00296     //     _params->ytitle=ytitle->text();
00297     //     if(!ylabel_fmt->text().isEmpty())
00298     //      _params->ylabel_fmt="%g "+ylabel_fmt->text();
00299 
00300     // PENDING(kalle) Adapt this
00301     //     if(annotation->text().isEmpty()) {
00302     //         if(_params->annotation) {
00303     //                 delete _params->annotation;
00304     //                 _params->annotation=0;
00305     //                 }
00306     //         }
00307     //     else
00308     //         {
00309     //         if(!_params->annotation)
00310     //                 _params->annotation=new KChartAnnotationType;
00311     //         _params->annotation->note=annotation->text();
00312     //         _params->annotation->color=color->color();
00313     //         _params->annotation->point=element->value()-1;
00314     //         _params->setAnnotationFont( annotationFont );
00315     //         }
00316 
00317 #if 0
00318     if( _params->chartType() == KDChartParams::Line )
00319         _params->setLineMarker(lineMarker->isChecked());
00320 #endif
00321 
00322     // Set the scale for the Y axis (linear / logarithmic)
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                 // Since in this version of kdChart logarithmic scales only work for Line charts,
00334                 // lets switch now
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 }  //KChart namespace
KDE Home | KDE Accessibility Home | Description of Access Keys