kchart

kchartConfigDialog.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1999,2000 Matthias Kalle Dalheimer <kalle@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20
21#include "kchartConfigDialog.h"
22#include "kchartConfigDialog.moc"
23
24
25#include "kchartBackgroundPixmapConfigPage.h"
26#include "kchartSubTypeChartPage.h"
27#include "kchartHeaderFooterConfigPage.h"
28#include "kchartColorConfigPage.h"
29#include "kchartParameterPieConfigPage.h"
30#include "kchartFontConfigPage.h"
31#include "kchartDataConfigPage.h"
32#include "kchartComboConfigPage.h"
33#include "kchartParameterConfigPage.h"
34#include "kchartPieConfigPage.h"
35#include "kchartParameter3dConfigPage.h"
36#include "kchartLegendConfigPage.h"
37#include "kchartLine3dConfigPage.h"
38#include "kchartParameterPolarConfigPage.h"
39
40#include <tdeapplication.h>
41#include <tdelocale.h>
42#include <kdebug.h>
43
44#include <tqradiobutton.h>
45
46#include "kchart_params.h"
47
48namespace KChart
49{
50
51KChartConfigDialog::KChartConfigDialog( KChartParams* params,
52 TQWidget* parent, int flags,
53 KDChartTableData *dat ) :
54 TQTabDialog( parent, "Chart config dialog", true ),
55 m_params( params ),
56
57 m_dataPage(0),
58 m_subTypePage(0),
59
60 _parameter3dpage(0),
61 _linepage3d(0),
62 _parameterpiepage(0),
63 _polarpage(0),
64
65 m_headerfooterpage(0),
66 m_legendPage(0),
67 m_axespage(0),
68
69 _colorpage(0),
70 _parameterfontpage(0),
71 _backgroundpixpage(0)
72 //_piepage(0),
73{
74 // Geometry page
75 //_geompage = new KChartGeometryConfigPage( this );
76 //addTab( _geompage, i18n( "&Geometry" ) );
77 setCaption( i18n( "Chart Setup" ) );
78
79 if (flags & KC_DATAFORMAT) {
80 m_dataPage = new KChartDataConfigPage(m_params, this, dat);
81 addTab( m_dataPage, i18n( "&Data" ) );
82 }
83 else if (flags & KC_SUBTYPE) {
84 subtypePage();
85 }
86 else if (flags & KC_HEADERFOOTER) {
87 m_headerfooterpage=new KChartHeaderFooterConfigPage(m_params,this);
88 addTab( m_headerfooterpage,i18n("Header/Footer"));
89 }
90 else if (flags & KC_COLORS ) {
91 _colorpage = new KChartColorConfigPage( m_params, this, dat );
92 addTab( _colorpage, i18n( "&Colors" ) );
93 }
94 else if ( flags & KC_FONT ) {
95 _parameterfontpage = new KChartFontConfigPage(m_params,this, dat );
96 addTab( _parameterfontpage, i18n( "&Font" ) );
97 }
98 else if ( flags & KC_BACK ) {
99 _backgroundpixpage = new KChartBackgroundPixmapConfigPage( m_params, this );
100 addTab( _backgroundpixpage, i18n( "&Background" ) );
101 }
102 else if ( flags & KC_LEGEND ) {
103 m_legendPage = new KChartLegendConfigPage(m_params,this );
104 addTab( m_legendPage,i18n("Legend"));
105 }
106 else if ( flags & KC_ALL ) {
107 // The data page
108 m_dataPage = new KChartDataConfigPage(m_params, this, dat);
109 addTab( m_dataPage, i18n( "&Data" ) );
110
111 // The subtype page
112 subtypePage();
113
114 // The subtype configuration page (not for all types).
115 if ( m_params->chartType() == KChartParams::Bar ) {
116 _parameter3dpage = new KChartParameter3dConfigPage(m_params,this );
117 addTab( _parameter3dpage,i18n("Bar"));
118 }
119 else if ( m_params->chartType() == KChartParams::Line) {
120 _linepage3d= new KChartLine3dConfigPage(m_params,this);
121 addTab( _linepage3d,i18n("Line"));
122 }
123#if 0
124 else if ( m_params->chartType() == KChartParams::BarLines) {
125 m_barslinesPage = new KChartBarslinesConfigPage(m_params, this);
126 addTab( _linepage3d,i18n("Line"));
127 }
128#endif
129 else if ( m_params->chartType() == KChartParams::Pie ) {
130
131 _parameterpiepage = new KChartParameterPieConfigPage(m_params,
132 this );
133 addTab( _parameterpiepage, i18n( "&Pie" ) );
134
135#if 0 // Disabled for 1.4.
136 _piepage = new KChartPieConfigPage(m_params, this, dat );
137 addTab( _piepage, i18n( "&Piedata" ) );
138#endif
139 }
140 else if ( m_params->chartType() == KChartParams::Polar) {
141 _polarpage=new KChartParameterPolarConfigPage(m_params,this);
142 addTab( _polarpage,i18n("&Polar"));
143 }
144
145
146 // The Header/Footer page
147 m_headerfooterpage=new KChartHeaderFooterConfigPage(m_params, this);
148 addTab( m_headerfooterpage, i18n("Header/Footer"));
149
150 // The legend page
151 m_legendPage = new KChartLegendConfigPage(m_params,this );
152 addTab( m_legendPage,i18n("Legend"));
153
154 // Add axes page if applicable (all except Pie, Ring).
155 if ( m_params->chartType() != KChartParams::Pie
156 && m_params->chartType() != KChartParams::Ring ) {
157
158 m_axespage = new KChartParameterConfigPage(m_params,this );
159 addTab( m_axespage, i18n( "&Axes" ) );
160 }
161
162 _colorpage = new KChartColorConfigPage( m_params, this, dat );
163 addTab( _colorpage, i18n( "&Colors" ) );
164
165 _parameterfontpage = new KChartFontConfigPage(m_params,this, dat );
166 addTab( _parameterfontpage, i18n( "&Font" ) );
167
168 _backgroundpixpage = new KChartBackgroundPixmapConfigPage( m_params,
169 this );
170 addTab( _backgroundpixpage, i18n( "&Background" ) );
171
172 if ( m_params->chartType() == KChartParams::HiLo &&
173 ( m_params->hiLoChartSubType() == KChartParams::HiLoClose ||
174 m_params->hiLoChartSubType() == KChartParams::HiLoOpenClose ) ) {
175 // PENDING(kalle) Combo page needs to be redone completely.
176 // _hlcChart=new KChartComboPage(m_params,this);
177// addTab( _hlcChart, i18n( "HLC Chart" ) );
178 }
179 }
180
181 // Get data into the tabs.
182 init();
183
184 // Setup main buttons.
185 setOKButton( i18n( "&OK" ) );
186 setApplyButton( i18n( "&Apply" ) );
187#if 0
188 setDefaultButton( i18n( "&Defaults" ) );
189#else
190 setDefaultButton( TQString() );
191#endif
192 setCancelButton( i18n( "&Cancel" ) );
193
194 connect( this, TQ_SIGNAL( applyButtonPressed() ), this, TQ_SLOT( apply() ) );
195 connect( this, TQ_SIGNAL( defaultButtonPressed() ), this, TQ_SLOT( defaults() ) );
196}
197
198
199void KChartConfigDialog::init()
200{
201 // Data page
202 if (m_dataPage)
203 m_dataPage->init();
204
205 // Color page
206 if (_colorpage) {
207 _colorpage->setLineColor( m_params->outlineDataColor() );
208 KDChartAxisParams leftparams;
209 leftparams = m_params->axisParams( KDChartAxisParams::AxisPosLeft );
210 KDChartAxisParams rightparams;
211 rightparams = m_params->axisParams( KDChartAxisParams::AxisPosRight );
212 KDChartAxisParams bottomparams;
213 bottomparams = m_params->axisParams( KDChartAxisParams::AxisPosBottom );
214 _colorpage->setGridColor( leftparams.axisGridColor() );
215 _colorpage->setXTitleColor( m_params->axisTitleColor( KDChartAxisParams::AxisPosLeft ) );
216 _colorpage->setYTitleColor( m_params->axisTitleColor( KDChartAxisParams::AxisPosBottom ) );
217#if 0
218 _colorpage->setYTitle2Color( rightparams.axisLineColor() );
219#endif
220 _colorpage->setXLabelColor( bottomparams.axisLabelsColor() );
221 _colorpage->setYLabelColor( leftparams.axisLabelsColor() );
222#if 0
223 _colorpage->setYLabel2Color( rightparams.axisLabelsColor() );
224#endif
225 _colorpage->setXLineColor( bottomparams.axisLineColor() );
226 _colorpage->setYLineColor( leftparams.axisLineColor() );
227#if 0
228 _colorpage->setYLine2Color( rightparams.axisLineColor() );
229#endif
230 _colorpage->setXZeroLineColor( bottomparams.axisZeroLineColor() );
231 _colorpage->setYZeroLineColor( leftparams.axisZeroLineColor() );
232#if 0
233 _colorpage->setYZeroLine2Color( rightparams.axisZeroLineColor() );
234#endif
235 // PENDING(kalle) Replace with KDChart equivalents
236 // _colorpage->setBackgroundColor( m_params->BGColor );
237 // _colorpage->setPlotColor( m_params->PlotColor );
238 // _colorpage->setVolColor( m_params->VolColor );
239 //_colorpage->setEdgeColor( m_params->EdgeColor );
240 }
241
242 if (m_axespage )
243 m_axespage->init();
244
245#if 0
246 if (_piepage)
247 _piepage->init();
248#endif
249 if (_parameterpiepage)
250 _parameterpiepage->init();
251
252 if (_parameter3dpage)
253 _parameter3dpage->init();
254
255 if ( _linepage3d && m_params->chartType() == KChartParams::Line)
256 _linepage3d->init();
257
258 if (_parameterfontpage)
259 _parameterfontpage->init();
260
261 if ( m_subTypePage )
262 m_subTypePage->init();
263
264/* if( _hlcChart)
265 {
266 if( m_params->chartType() == KDChartParams::HiLo &&
267 ( m_params->hiLoChartSubType() == KDChartParams::HiLoClose ||
268 m_params->hiLoChartSubType() == KDChartParams::HiLoOpenClose ) ) {
269 _hlcChart->init();
270 }
271 }*/
272 if (_backgroundpixpage)
273 _backgroundpixpage->init();
274
275 if (m_legendPage)
276 m_legendPage->init();
277// for( uint i = 0; i < NUMDATACOLORS; i++ )
278// _colorpage->setDataColor( i, m_params->dataColor( i ) );
279
280 if (m_headerfooterpage)
281 m_headerfooterpage->init();
282 if (_polarpage)
283 _polarpage->init();
284}
285
286
287void KChartConfigDialog::apply()
288{
289 kdDebug(35001) << "***KChartConfig::apply()\n";
290 // Copy application data from dialog into parameter structure that is also
291 // being used by the application.
292
293 // Data page
294 if (m_dataPage)
295 m_dataPage->apply();
296
297 // color page
298
299 // PENDING(kalle) Replace with equivalents
300 // m_params->BGColor = _colorpage->backgroundColor();
301 // m_params->PlotColor = _colorpage->plotColor();
302 //m_params->EdgeColor = _colorpage->edgeColor();
303 // m_params->VolColor = _colorpage->volColor();
304
305 if (_colorpage) {
306
307 KDChartAxisParams leftparams;
308 leftparams = m_params->axisParams( KDChartAxisParams::AxisPosLeft );
309 leftparams.setAxisGridColor( _colorpage->gridColor() );
310 m_params->setOutlineDataColor( _colorpage->lineColor() );
311
312 KDChartAxisParams rightparams;
313 rightparams = m_params->axisParams( KDChartAxisParams::AxisPosRight );
314 KDChartAxisParams bottomparams;
315 bottomparams = m_params->axisParams( KDChartAxisParams::AxisPosBottom );
316 if( _colorpage->xTitleColor().isValid() )
317 m_params->setAxisTitleColor( KDChartAxisParams::AxisPosBottom, _colorpage->xTitleColor() );
318 else
319 m_params->setAxisTitleColor( KDChartAxisParams::AxisPosBottom, TQColor() );
320 if( _colorpage->yTitleColor().isValid() )
321 m_params->setAxisTitleColor( KDChartAxisParams::AxisPosLeft, _colorpage->yTitleColor() );
322 else
323 m_params->setAxisTitleColor( KDChartAxisParams::AxisPosLeft, TQColor() );
324#if 0
325 if( _colorpage->yTitle2Color().isValid() )
326 rightparams.setAxisLineColor( _colorpage->yTitle2Color() );
327 else
328 rightparams.setAxisLineColor( TQColor() );
329#endif
330
331 bottomparams.setAxisLabelsColor( _colorpage->xLabelColor() );
332 leftparams.setAxisLabelsColor( _colorpage->yLabelColor() );
333#if 0
334 rightparams.setAxisLabelsColor( _colorpage->yLabel2Color() );
335#endif
336
337 bottomparams.setAxisLineColor( _colorpage->xLineColor() );
338 leftparams.setAxisLineColor( _colorpage->yLineColor() );
339#if 0
340 rightparams.setAxisLineColor( _colorpage->yLine2Color() );
341#endif
342
343 bottomparams.setAxisZeroLineColor( _colorpage->xZeroLineColor() );
344 leftparams.setAxisZeroLineColor( _colorpage->yZeroLineColor() );
345#if 0
346 rightparams.setAxisZeroLineColor( _colorpage->yZeroLine2Color() );
347#endif
348 m_params->setAxisParams( KDChartAxisParams::AxisPosBottom, bottomparams );
349 m_params->setAxisParams( KDChartAxisParams::AxisPosLeft, leftparams );
350#if 0
351 m_params->setAxisParams( KDChartAxisParams::AxisPosRight, rightparams );
352#endif
353 }
354
355 if (m_axespage)
356 m_axespage->apply();
357
358 if (_parameterpiepage)
359 _parameterpiepage->apply();
360#if 0
361 if (_piepage)
362 _piepage->apply();
363#endif
364 if( _parameter3dpage && m_params->chartType() == KChartParams::Bar )
365 _parameter3dpage->apply();
366
367 if( _linepage3d && m_params->chartType() == KChartParams::Line)
368 _linepage3d->apply();
369
370 if(_parameterfontpage)
371 _parameterfontpage->apply();
372
373 if(_colorpage)
374 _colorpage->apply();
375
376 if( m_subTypePage )
377 m_subTypePage->apply();
378
379 if ( m_params->chartType() == KChartParams::HiLo &&
380 ( m_params->hiLoChartSubType() == KChartParams::HiLoClose ||
381 m_params->hiLoChartSubType() == KChartParams::HiLoOpenClose ) )
382 {
383 /* if( _hlcChart)
384 _hlcChart->apply();*/
385 }
386
387 if (_backgroundpixpage)
388 _backgroundpixpage->apply();
389
390 // for( uint i = 0; i < NUMDATACOLORS; i++ )
391 // m_params->_datacolors.setColor( i, _colorpage->dataColor( i ) );
392 if (m_legendPage)
393 m_legendPage->apply();
394
395 if (m_headerfooterpage)
396 m_headerfooterpage->apply();
397 if (_polarpage)
398 _polarpage->apply();
399
400 // Data in the params struct has changed; notify the application.
401 emit dataChanged();
402}
403
404
405void KChartConfigDialog::subtypePage()
406{
407 switch( m_params->chartType() ) {
408 case KDChartParams::Bar:
409 m_subTypePage = new KChartBarSubTypeChartPage( m_params, this );
410 break;
411 case KDChartParams::Area:
412 m_subTypePage = new KChartAreaSubTypeChartPage( m_params, this );
413 break;
414 case KDChartParams::Line:
415 m_subTypePage = new KChartLineSubTypeChartPage( m_params, this );
416 break;
417 case KDChartParams::HiLo:
418 m_subTypePage = new KChartHiloSubTypeChartPage( m_params, this );
419 break;
420 case KDChartParams::Polar:
421 m_subTypePage = new KChartPolarSubTypeChartPage( m_params, this );
422 break;
423 default:
424 // Do nothing. In particular, don't add a page.
425 return;
426 ;
427 }
428 addTab( m_subTypePage, i18n( "Chart &Sub-type" ) );
429}
430
431
432void KChartConfigDialog::defaults()
433{
434 //FIXME: NYI
435}
436
437
438} //KChart namespace
access the chart axis parameters.
TQColor axisLabelsColor() const
Returns the axis labels colour.
TQColor axisGridColor() const
Returns the axis grid color.
void setAxisLineColor(TQColor axisLineColor)
Specifies the axis line colour.
void setAxisZeroLineColor(TQColor axisZeroLineColor)
Specifies the colour of the zero-line that is drawn if zero is not at the lower edge of the chart.
void setAxisGridColor(TQColor axisGridColor)
Specifies the axis grid colour.
TQColor axisLineColor() const
Returns the axis line colour.
void setAxisLabelsColor(TQColor axisLabelsColor)
Specifies the axis labels colour.
TQColor axisZeroLineColor() const
Returns the colour used for the zero-value line that is drawn if zero is not at the lower edge of the...