kchart

kchartConfigDialog.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 1999,2000 Matthias Kalle Dalheimer <kalle@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 "kchartConfigDialog.h"
00022 #include "kchartConfigDialog.moc"
00023 
00024 
00025 #include "kchartBackgroundPixmapConfigPage.h"
00026 #include "kchartSubTypeChartPage.h"
00027 #include "kchartHeaderFooterConfigPage.h"
00028 #include "kchartColorConfigPage.h"
00029 #include "kchartParameterPieConfigPage.h"
00030 #include "kchartFontConfigPage.h"
00031 #include "kchartDataConfigPage.h"
00032 #include "kchartComboConfigPage.h"
00033 #include "kchartParameterConfigPage.h"
00034 #include "kchartPieConfigPage.h"
00035 #include "kchartParameter3dConfigPage.h"
00036 #include "kchartLegendConfigPage.h"
00037 #include "kchartLine3dConfigPage.h"
00038 #include "kchartParameterPolarConfigPage.h"
00039 
00040 #include <kapplication.h>
00041 #include <klocale.h>
00042 #include <kdebug.h>
00043 
00044 #include <qradiobutton.h>
00045 
00046 #include "kchart_params.h"
00047 
00048 namespace KChart
00049 {
00050 
00051 KChartConfigDialog::KChartConfigDialog( KChartParams* params,
00052                     QWidget* parent, int flags,
00053                     KDChartTableData *dat ) :
00054     QTabDialog( parent, "Chart config dialog", true ),
00055     m_params( params ),
00056 
00057     m_dataPage(0),
00058     m_subTypePage(0),
00059 
00060     _parameter3dpage(0),
00061     _linepage3d(0),
00062     _parameterpiepage(0),
00063     _polarpage(0),
00064 
00065     m_headerfooterpage(0),
00066     m_legendPage(0),
00067     m_axespage(0),
00068 
00069     _colorpage(0),
00070     _parameterfontpage(0),
00071     _backgroundpixpage(0)
00072     //_piepage(0),
00073 {
00074     // Geometry page
00075     //_geompage = new KChartGeometryConfigPage( this );
00076     //addTab( _geompage, i18n( "&Geometry" ) );
00077     setCaption( i18n( "Chart Setup" ) );
00078 
00079     if (flags & KC_DATAFORMAT) {
00080         m_dataPage = new KChartDataConfigPage(m_params, this, dat);
00081         addTab( m_dataPage, i18n( "&Data" ) );
00082     }
00083     else if (flags & KC_SUBTYPE) {
00084         subtypePage();
00085     }
00086     else if (flags & KC_HEADERFOOTER) {
00087         m_headerfooterpage=new KChartHeaderFooterConfigPage(m_params,this);
00088         addTab( m_headerfooterpage,i18n("Header/Footer"));
00089     }
00090     else if (flags & KC_COLORS ) {
00091         _colorpage = new KChartColorConfigPage( m_params,  this, dat );
00092         addTab( _colorpage, i18n( "&Colors" ) );
00093     }
00094     else if ( flags & KC_FONT ) {
00095         _parameterfontpage = new KChartFontConfigPage(m_params,this, dat );
00096         addTab( _parameterfontpage, i18n( "&Font" ) );
00097     }
00098     else if ( flags & KC_BACK ) {
00099         _backgroundpixpage = new KChartBackgroundPixmapConfigPage( m_params, this );
00100         addTab( _backgroundpixpage, i18n( "&Background" ) );
00101     }
00102     else if ( flags & KC_LEGEND ) {
00103         m_legendPage = new KChartLegendConfigPage(m_params,this );
00104         addTab( m_legendPage,i18n("Legend"));
00105     }
00106     else if ( flags & KC_ALL ) {
00107     // The data page
00108         m_dataPage = new KChartDataConfigPage(m_params, this, dat);
00109         addTab( m_dataPage, i18n( "&Data" ) );
00110 
00111     // The subtype page
00112         subtypePage();
00113 
00114     // The subtype configuration page (not for all types).
00115         if ( m_params->chartType() == KChartParams::Bar ) {
00116             _parameter3dpage = new KChartParameter3dConfigPage(m_params,this );
00117             addTab( _parameter3dpage,i18n("Bar"));
00118         }
00119         else if ( m_params->chartType() == KChartParams::Line) {
00120             _linepage3d= new KChartLine3dConfigPage(m_params,this);
00121             addTab( _linepage3d,i18n("Line"));
00122         }
00123 #if 0
00124         else if ( m_params->chartType() == KChartParams::BarLines) {
00125             m_barslinesPage = new KChartBarslinesConfigPage(m_params, this);
00126             addTab( _linepage3d,i18n("Line"));
00127         }
00128 #endif
00129     else if ( m_params->chartType() == KChartParams::Pie ) {
00130 
00131             _parameterpiepage = new KChartParameterPieConfigPage(m_params, 
00132                                  this );
00133             addTab( _parameterpiepage, i18n( "&Pie" ) );
00134 
00135 #if 0 // Disabled for 1.4.
00136             _piepage = new KChartPieConfigPage(m_params, this, dat );
00137             addTab( _piepage, i18n( "&Piedata" ) );
00138 #endif
00139         }
00140         else if ( m_params->chartType() == KChartParams::Polar) {
00141             _polarpage=new KChartParameterPolarConfigPage(m_params,this);
00142             addTab( _polarpage,i18n("&Polar"));
00143         }
00144 
00145 
00146     // The Header/Footer page
00147         m_headerfooterpage=new KChartHeaderFooterConfigPage(m_params, this);
00148         addTab( m_headerfooterpage, i18n("Header/Footer"));
00149 
00150     // The legend page
00151     m_legendPage = new KChartLegendConfigPage(m_params,this );
00152         addTab( m_legendPage,i18n("Legend"));
00153 
00154     // Add axes page if applicable (all except Pie, Ring).
00155         if ( m_params->chartType() != KChartParams::Pie
00156          && m_params->chartType() != KChartParams::Ring ) {
00157 
00158             m_axespage = new KChartParameterConfigPage(m_params,this );
00159             addTab( m_axespage, i18n( "&Axes" ) );
00160         } 
00161 
00162         _colorpage = new KChartColorConfigPage( m_params,  this, dat );
00163         addTab( _colorpage, i18n( "&Colors" ) );
00164 
00165         _parameterfontpage = new KChartFontConfigPage(m_params,this, dat );
00166         addTab( _parameterfontpage, i18n( "&Font" ) );
00167 
00168         _backgroundpixpage = new KChartBackgroundPixmapConfigPage( m_params, 
00169                                    this );
00170         addTab( _backgroundpixpage, i18n( "&Background" ) );
00171 
00172         if ( m_params->chartType() == KChartParams::HiLo &&
00173             ( m_params->hiLoChartSubType() == KChartParams::HiLoClose ||
00174               m_params->hiLoChartSubType() == KChartParams::HiLoOpenClose ) ) {
00175             // PENDING(kalle) Combo page needs to be redone completely.
00176             //         _hlcChart=new KChartComboPage(m_params,this);
00177 //         addTab( _hlcChart, i18n( "HLC Chart" ) );
00178         }
00179     }
00180 
00181     // Get data into the tabs.
00182     init();
00183 
00184     // Setup main buttons.
00185     setOKButton( i18n( "&OK" ) );
00186     setApplyButton( i18n( "&Apply" ) );
00187 #if 0
00188     setDefaultButton( i18n( "&Defaults" ) );
00189 #else
00190     setDefaultButton( QString::null );
00191 #endif
00192     setCancelButton( i18n( "&Cancel" ) );
00193 
00194     connect( this, SIGNAL( applyButtonPressed() ),   this, SLOT( apply() ) );
00195     connect( this, SIGNAL( defaultButtonPressed() ), this, SLOT( defaults() ) );
00196 }
00197 
00198 
00199 void KChartConfigDialog::init()
00200 {
00201     // Data page
00202     if (m_dataPage)
00203         m_dataPage->init();
00204 
00205     // Color page
00206     if (_colorpage) {
00207         _colorpage->setLineColor( m_params->outlineDataColor() );
00208         KDChartAxisParams leftparams;
00209         leftparams = m_params->axisParams( KDChartAxisParams::AxisPosLeft );
00210         KDChartAxisParams rightparams;
00211         rightparams = m_params->axisParams( KDChartAxisParams::AxisPosRight );
00212         KDChartAxisParams bottomparams;
00213         bottomparams = m_params->axisParams( KDChartAxisParams::AxisPosBottom );
00214         _colorpage->setGridColor( leftparams.axisGridColor() );
00215         _colorpage->setXTitleColor( m_params->axisTitleColor( KDChartAxisParams::AxisPosLeft ) );
00216         _colorpage->setYTitleColor( m_params->axisTitleColor( KDChartAxisParams::AxisPosBottom ) );
00217 #if 0
00218         _colorpage->setYTitle2Color( rightparams.axisLineColor() );
00219 #endif
00220         _colorpage->setXLabelColor( bottomparams.axisLabelsColor() );
00221         _colorpage->setYLabelColor( leftparams.axisLabelsColor() );
00222 #if 0
00223         _colorpage->setYLabel2Color( rightparams.axisLabelsColor() );
00224 #endif
00225         _colorpage->setXLineColor( bottomparams.axisLineColor() );
00226         _colorpage->setYLineColor( leftparams.axisLineColor() );
00227 #if 0
00228         _colorpage->setYLine2Color( rightparams.axisLineColor() );
00229 #endif
00230         _colorpage->setXZeroLineColor( bottomparams.axisZeroLineColor() );
00231         _colorpage->setYZeroLineColor( leftparams.axisZeroLineColor() );
00232 #if 0
00233         _colorpage->setYZeroLine2Color( rightparams.axisZeroLineColor() );
00234 #endif
00235         // PENDING(kalle) Replace with KDChart equivalents
00236         //     _colorpage->setBackgroundColor( m_params->BGColor );
00237         //     _colorpage->setPlotColor( m_params->PlotColor );
00238         //     _colorpage->setVolColor( m_params->VolColor );
00239         //_colorpage->setEdgeColor( m_params->EdgeColor );
00240     }
00241 
00242     if (m_axespage )
00243     m_axespage->init();
00244 
00245 #if 0
00246     if (_piepage)
00247     _piepage->init();
00248 #endif
00249     if (_parameterpiepage)
00250     _parameterpiepage->init();
00251 
00252     if (_parameter3dpage)
00253         _parameter3dpage->init();
00254 
00255     if ( _linepage3d && m_params->chartType() == KChartParams::Line)
00256         _linepage3d->init();
00257 
00258     if (_parameterfontpage)
00259         _parameterfontpage->init();
00260 
00261     if ( m_subTypePage )
00262         m_subTypePage->init();
00263 
00264 /*    if( _hlcChart)
00265     {
00266         if( m_params->chartType() == KDChartParams::HiLo &&
00267             ( m_params->hiLoChartSubType() == KDChartParams::HiLoClose ||
00268               m_params->hiLoChartSubType() == KDChartParams::HiLoOpenClose ) ) {
00269             _hlcChart->init();
00270         }
00271         }*/
00272     if (_backgroundpixpage)
00273         _backgroundpixpage->init();
00274 
00275     if (m_legendPage)
00276         m_legendPage->init();
00277 //     for( uint i = 0; i < NUMDATACOLORS; i++ )
00278 //          _colorpage->setDataColor( i, m_params->dataColor( i ) );
00279 
00280     if (m_headerfooterpage)
00281         m_headerfooterpage->init();
00282     if (_polarpage)
00283         _polarpage->init();
00284 }
00285 
00286 
00287 void KChartConfigDialog::apply()
00288 {
00289     kdDebug(35001) << "***KChartConfig::apply()\n";
00290     // Copy application data from dialog into parameter structure that is also
00291     // being used by the application.
00292 
00293     // Data page
00294     if (m_dataPage)
00295         m_dataPage->apply();
00296 
00297     // color page
00298 
00299     // PENDING(kalle) Replace with equivalents
00300     //     m_params->BGColor = _colorpage->backgroundColor();
00301     //     m_params->PlotColor = _colorpage->plotColor();
00302     //m_params->EdgeColor = _colorpage->edgeColor();
00303     //     m_params->VolColor = _colorpage->volColor();
00304 
00305     if (_colorpage) {
00306 
00307         KDChartAxisParams leftparams;
00308         leftparams = m_params->axisParams( KDChartAxisParams::AxisPosLeft );
00309         leftparams.setAxisGridColor( _colorpage->gridColor() );
00310         m_params->setOutlineDataColor( _colorpage->lineColor() );
00311 
00312         KDChartAxisParams rightparams;
00313         rightparams = m_params->axisParams( KDChartAxisParams::AxisPosRight );
00314         KDChartAxisParams bottomparams;
00315         bottomparams = m_params->axisParams( KDChartAxisParams::AxisPosBottom );
00316         if( _colorpage->xTitleColor().isValid() )
00317             m_params->setAxisTitleColor( KDChartAxisParams::AxisPosBottom, _colorpage->xTitleColor() );
00318         else
00319             m_params->setAxisTitleColor( KDChartAxisParams::AxisPosBottom, QColor() );
00320         if( _colorpage->yTitleColor().isValid() )
00321             m_params->setAxisTitleColor( KDChartAxisParams::AxisPosLeft, _colorpage->yTitleColor() );
00322         else
00323             m_params->setAxisTitleColor( KDChartAxisParams::AxisPosLeft, QColor() );
00324 #if 0
00325         if( _colorpage->yTitle2Color().isValid() )
00326             rightparams.setAxisLineColor( _colorpage->yTitle2Color() );
00327         else
00328             rightparams.setAxisLineColor( QColor() );
00329 #endif
00330 
00331         bottomparams.setAxisLabelsColor( _colorpage->xLabelColor() );
00332         leftparams.setAxisLabelsColor( _colorpage->yLabelColor() );
00333 #if 0
00334         rightparams.setAxisLabelsColor( _colorpage->yLabel2Color() );
00335 #endif
00336 
00337         bottomparams.setAxisLineColor( _colorpage->xLineColor() );
00338         leftparams.setAxisLineColor( _colorpage->yLineColor() );
00339 #if 0
00340         rightparams.setAxisLineColor( _colorpage->yLine2Color() );
00341 #endif
00342 
00343         bottomparams.setAxisZeroLineColor( _colorpage->xZeroLineColor() );
00344         leftparams.setAxisZeroLineColor( _colorpage->yZeroLineColor() );
00345 #if 0
00346         rightparams.setAxisZeroLineColor( _colorpage->yZeroLine2Color() );
00347 #endif
00348         m_params->setAxisParams( KDChartAxisParams::AxisPosBottom, bottomparams );
00349         m_params->setAxisParams( KDChartAxisParams::AxisPosLeft,   leftparams );
00350 #if 0
00351         m_params->setAxisParams( KDChartAxisParams::AxisPosRight,  rightparams );
00352 #endif
00353     }
00354 
00355     if (m_axespage)
00356     m_axespage->apply();
00357 
00358     if (_parameterpiepage)
00359     _parameterpiepage->apply();
00360 #if 0
00361     if (_piepage)
00362     _piepage->apply();
00363 #endif
00364     if( _parameter3dpage && m_params->chartType() == KChartParams::Bar  )
00365         _parameter3dpage->apply();
00366 
00367     if( _linepage3d && m_params->chartType() == KChartParams::Line)
00368         _linepage3d->apply();
00369 
00370     if(_parameterfontpage)
00371         _parameterfontpage->apply();
00372 
00373     if(_colorpage)
00374         _colorpage->apply();
00375 
00376     if( m_subTypePage )
00377         m_subTypePage->apply();
00378 
00379     if ( m_params->chartType() == KChartParams::HiLo &&
00380         ( m_params->hiLoChartSubType() == KChartParams::HiLoClose ||
00381           m_params->hiLoChartSubType() == KChartParams::HiLoOpenClose ) )
00382     {
00383         /* if( _hlcChart)
00384            _hlcChart->apply();*/
00385     }
00386 
00387     if (_backgroundpixpage)
00388         _backgroundpixpage->apply();
00389 
00390     //     for( uint i = 0; i < NUMDATACOLORS; i++ )
00391     //  m_params->_datacolors.setColor( i, _colorpage->dataColor( i ) );
00392     if (m_legendPage)
00393         m_legendPage->apply();
00394 
00395     if (m_headerfooterpage)
00396         m_headerfooterpage->apply();
00397     if (_polarpage)
00398         _polarpage->apply();
00399 
00400     // Data in the params struct has changed; notify the application.
00401     emit dataChanged();
00402 }
00403 
00404 
00405 void KChartConfigDialog::subtypePage()
00406 {
00407     switch( m_params->chartType() ) {
00408     case KDChartParams::Bar:
00409         m_subTypePage = new KChartBarSubTypeChartPage( m_params, this );
00410         break;
00411     case KDChartParams::Area:
00412         m_subTypePage = new KChartAreaSubTypeChartPage( m_params, this );
00413         break;
00414     case KDChartParams::Line:
00415         m_subTypePage = new KChartLineSubTypeChartPage( m_params, this );
00416         break;
00417     case KDChartParams::HiLo:
00418         m_subTypePage = new KChartHiloSubTypeChartPage( m_params, this );
00419         break;
00420     case KDChartParams::Polar:
00421         m_subTypePage = new KChartPolarSubTypeChartPage( m_params, this );
00422         break;
00423     default:
00424     // Do nothing.  In particular, don't add a page.
00425     return;
00426         ; 
00427     }
00428     addTab( m_subTypePage, i18n( "Chart &Sub-type" ) );
00429 }
00430 
00431 
00432 void KChartConfigDialog::defaults()
00433 {
00434   //FIXME: NYI
00435 }
00436 
00437 
00438 }  //KChart namespace
KDE Home | KDE Accessibility Home | Description of Access Keys