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         // PENDING(kalle) Replace with KDChart equivalents
00226         //     _colorpage->setBackgroundColor( m_params->BGColor );
00227         //     _colorpage->setPlotColor( m_params->PlotColor );
00228         //     _colorpage->setVolColor( m_params->VolColor );
00229         //_colorpage->setEdgeColor( m_params->EdgeColor );
00230     }
00231 
00232     if (m_axespage )
00233     m_axespage->init();
00234 
00235 #if 0
00236     if (_piepage)
00237     _piepage->init();
00238 #endif
00239     if (_parameterpiepage)
00240     _parameterpiepage->init();
00241 
00242     if (_parameter3dpage)
00243         _parameter3dpage->init();
00244 
00245     if ( _linepage3d && m_params->chartType() == KChartParams::Line)
00246         _linepage3d->init();
00247 
00248     if (_parameterfontpage)
00249         _parameterfontpage->init();
00250 
00251     if ( m_subTypePage )
00252         m_subTypePage->init();
00253 
00254 /*    if( _hlcChart)
00255     {
00256         if( m_params->chartType() == KDChartParams::HiLo &&
00257             ( m_params->hiLoChartSubType() == KDChartParams::HiLoClose ||
00258               m_params->hiLoChartSubType() == KDChartParams::HiLoOpenClose ) ) {
00259             _hlcChart->init();
00260         }
00261         }*/
00262     if (_backgroundpixpage)
00263         _backgroundpixpage->init();
00264 
00265     if (m_legendPage)
00266         m_legendPage->init();
00267 //     for( uint i = 0; i < NUMDATACOLORS; i++ )
00268 //          _colorpage->setDataColor( i, m_params->dataColor( i ) );
00269 
00270     if (m_headerfooterpage)
00271         m_headerfooterpage->init();
00272     if (_polarpage)
00273         _polarpage->init();
00274 }
00275 
00276 
00277 void KChartConfigDialog::apply()
00278 {
00279     kdDebug(35001) << "***KChartConfig::apply()\n";
00280     // Copy application data from dialog into parameter structure that is also
00281     // being used by the application.
00282 
00283     // Data page
00284     if (m_dataPage)
00285         m_dataPage->apply();
00286 
00287     // color page
00288 
00289     // PENDING(kalle) Replace with equivalents
00290     //     m_params->BGColor = _colorpage->backgroundColor();
00291     //     m_params->PlotColor = _colorpage->plotColor();
00292     //m_params->EdgeColor = _colorpage->edgeColor();
00293     //     m_params->VolColor = _colorpage->volColor();
00294 
00295     if (_colorpage) {
00296 
00297         KDChartAxisParams leftparams;
00298         leftparams = m_params->axisParams( KDChartAxisParams::AxisPosLeft );
00299         leftparams.setAxisGridColor( _colorpage->gridColor() );
00300         m_params->setOutlineDataColor( _colorpage->lineColor() );
00301         KDChartAxisParams rightparams;
00302         rightparams = m_params->axisParams( KDChartAxisParams::AxisPosRight );
00303         KDChartAxisParams bottomparams;
00304         bottomparams = m_params->axisParams( KDChartAxisParams::AxisPosBottom );
00305         if( _colorpage->xTitleColor().isValid() )
00306             m_params->setAxisTitleColor( KDChartAxisParams::AxisPosBottom, _colorpage->xTitleColor() );
00307         else
00308             m_params->setAxisTitleColor( KDChartAxisParams::AxisPosBottom, QColor() );
00309         if( _colorpage->yTitleColor().isValid() )
00310             m_params->setAxisTitleColor( KDChartAxisParams::AxisPosLeft, _colorpage->yTitleColor() );
00311         else
00312             m_params->setAxisTitleColor( KDChartAxisParams::AxisPosLeft, QColor() );
00313 #if 0
00314         if( _colorpage->yTitle2Color().isValid() )
00315             rightparams.setAxisLineColor( _colorpage->yTitle2Color() );
00316         else
00317             rightparams.setAxisLineColor( QColor() );
00318 #endif
00319         bottomparams.setAxisLabelsColor( _colorpage->xLabelColor() );
00320         leftparams.setAxisLabelsColor( _colorpage->yLabelColor() );
00321 #if 0
00322         rightparams.setAxisLabelsColor( _colorpage->yLabel2Color() );
00323 #endif
00324         m_params->setAxisParams( KDChartAxisParams::AxisPosBottom, bottomparams );
00325         m_params->setAxisParams( KDChartAxisParams::AxisPosLeft,   leftparams );
00326 #if 0
00327         m_params->setAxisParams( KDChartAxisParams::AxisPosRight,  rightparams );
00328 #endif
00329     }
00330 
00331     if (m_axespage)
00332     m_axespage->apply();
00333 
00334     if (_parameterpiepage)
00335     _parameterpiepage->apply();
00336 #if 0
00337     if (_piepage)
00338     _piepage->apply();
00339 #endif
00340     if( _parameter3dpage && m_params->chartType() == KChartParams::Bar  )
00341         _parameter3dpage->apply();
00342 
00343     if( _linepage3d && m_params->chartType() == KChartParams::Line)
00344         _linepage3d->apply();
00345 
00346     if(_parameterfontpage)
00347         _parameterfontpage->apply();
00348 
00349     if(_colorpage)
00350         _colorpage->apply();
00351 
00352     if( m_subTypePage )
00353         m_subTypePage->apply();
00354 
00355     if ( m_params->chartType() == KChartParams::HiLo &&
00356         ( m_params->hiLoChartSubType() == KChartParams::HiLoClose ||
00357           m_params->hiLoChartSubType() == KChartParams::HiLoOpenClose ) )
00358     {
00359         /* if( _hlcChart)
00360            _hlcChart->apply();*/
00361     }
00362 
00363     if (_backgroundpixpage)
00364         _backgroundpixpage->apply();
00365 
00366     //     for( uint i = 0; i < NUMDATACOLORS; i++ )
00367     //  m_params->_datacolors.setColor( i, _colorpage->dataColor( i ) );
00368     if (m_legendPage)
00369         m_legendPage->apply();
00370 
00371     if (m_headerfooterpage)
00372         m_headerfooterpage->apply();
00373     if (_polarpage)
00374         _polarpage->apply();
00375 
00376     // Data in the params struct has changed; notify the application.
00377     emit dataChanged();
00378 }
00379 
00380 
00381 void KChartConfigDialog::subtypePage()
00382 {
00383     switch( m_params->chartType() ) {
00384     case KDChartParams::Bar:
00385         m_subTypePage = new KChartBarSubTypeChartPage( m_params, this );
00386         break;
00387     case KDChartParams::Area:
00388         m_subTypePage = new KChartAreaSubTypeChartPage( m_params, this );
00389         break;
00390     case KDChartParams::Line:
00391         m_subTypePage = new KChartLineSubTypeChartPage( m_params, this );
00392         break;
00393     case KDChartParams::HiLo:
00394         m_subTypePage = new KChartHiloSubTypeChartPage( m_params, this );
00395         break;
00396     case KDChartParams::Polar:
00397         m_subTypePage = new KChartPolarSubTypeChartPage( m_params, this );
00398         break;
00399     default:
00400     // Do nothing.  In particular, don't add a page.
00401     return;
00402         ; 
00403     }
00404     addTab( m_subTypePage, i18n( "Chart &Sub-type" ) );
00405 }
00406 
00407 
00408 void KChartConfigDialog::defaults()
00409 {
00410   //FIXME: NYI
00411 }
00412 
00413 
00414 }  //KChart namespace
KDE Home | KDE Accessibility Home | Description of Access Keys