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     // toplevel layout
00048     QVBoxLayout* toplevel = new QVBoxLayout( this, 10 );
00049 
00050     QGridLayout* layout = new QGridLayout( 1, 3 );
00051     toplevel->addLayout( layout );
00052 
00053     // The "Parameters" button group
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     //gb1->insert(grid);
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     //gb1->insert(yaxis);
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     //gb1->insert(xaxis);
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     // The "Settings" button group
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     // The X axis title
00104     QLabel *tmpLabel = new QLabel( i18n( "X-title:" ), gb2 );
00105     top->addWidget(tmpLabel);
00106     // The Y axis title
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     // Linear or logarithmic scale
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     // Decimal precision
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     /*connect( grid, SIGNAL( toggled( bool ) ),
00171       this, SLOT( changeState( bool ) ) );*/
00172     /*connect( xaxis, SIGNAL( toggled( bool ) ),
00173       this, SLOT( changeXaxisState( bool ) ) );*/
00174 }
00175 
00176 
00177     void KChartParameterConfigPage::changeXaxisState(bool /*state*/)
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     // PENDING(kalle) adapt these to KDChart
00190     //     grid->setChecked(_params->grid);
00191     //     xlabel->setChecked(_params->hasxlabel);
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     // PENDING(kalle) Adapt this
00214     //     if(_params->has_yaxis2())
00215     //      {
00216     //      yaxis2->setChecked(_params->yaxis2);
00217     //      int len=_params->ylabel2_fmt.length();
00218     //         ylabel2_fmt->setText(_params->ylabel2_fmt.right(len-3));
00219 
00220     //      ytitle2->setText(_params->ytitle2);
00221     //      }
00222     //     else
00223 #if 0
00224     {
00225         yaxis2->setEnabled(false);
00226         ylabel2_fmt->setEnabled(false);
00227         ytitle2->setEnabled(false);
00228     }
00229 
00230     // PENDING(kalle) Adapt this
00231     //     xtitle->setText(_params->xtitle);
00232     //     ytitle->setText(_params->ytitle);
00233     //     int len=_params->ylabel_fmt.length();
00234     //     ylabel_fmt->setText(_params->ylabel_fmt.right(len-3));
00235 
00236     //     if(_params->xaxis)
00237     //      xlabel->setEnabled(true);
00238     //     else
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     // Linear / logarithmic Y axis
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 // PENDING(kalle) Adapt this
00282     //     _params->border=border->isChecked();
00283     //     _params->llabel=llabel->isChecked();
00284     //     if(xaxis->isChecked())
00285     //      _params->hasxlabel=xlabel->isChecked();
00286     //     if(_params->has_yaxis2())
00287     //      {
00288     //      _params->yaxis2=yaxis2->isChecked();
00289     //      if(!ylabel2_fmt->text().isEmpty())
00290     //          _params->ylabel2_fmt="%g "+ylabel2_fmt->text();
00291     //      _params->ytitle2=ytitle2->text();
00292     //      }
00293 
00294 
00295     // PENDING(kalle) Adapt this
00296     //     if(grid->isChecked())
00297     //      _params->shelf=shelf->isChecked();
00298     //     _params->xtitle=xtitle->text();
00299     //     _params->ytitle=ytitle->text();
00300     //     if(!ylabel_fmt->text().isEmpty())
00301     //      _params->ylabel_fmt="%g "+ylabel_fmt->text();
00302 
00303     // PENDING(kalle) Adapt this
00304     //     if(annotation->text().isEmpty()) {
00305     //         if(_params->annotation) {
00306     //                 delete _params->annotation;
00307     //                 _params->annotation=0;
00308     //                 }
00309     //         }
00310     //     else
00311     //         {
00312     //         if(!_params->annotation)
00313     //                 _params->annotation=new KChartAnnotationType;
00314     //         _params->annotation->note=annotation->text();
00315     //         _params->annotation->color=color->color();
00316     //         _params->annotation->point=element->value()-1;
00317     //         _params->setAnnotationFont( annotationFont );
00318     //         }
00319 
00320 #if 0
00321     if( _params->chartType() == KDChartParams::Line )
00322         _params->setLineMarker(lineMarker->isChecked());
00323 #endif
00324 
00325     // Set the scale for the Y axis (linear / logarithmic)
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                 // Since in this version of kdChart logarithmic scales only work for Line charts,
00337                 // lets switch now
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 }  //KChart namespace
KDE Home | KDE Accessibility Home | Description of Access Keys