kchart

kchartSubTypeChartPage.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#include <stdlib.h>
21
22#include "kchartSubTypeChartPage.h"
23#include "kchartSubTypeChartPage.moc"
24
25#include <tdeapplication.h>
26#include <tdelocale.h>
27#include <kiconloader.h>
28#include <kdebug.h>
29#include <tqvbuttongroup.h>
30#include <tqradiobutton.h>
31#include <tqspinbox.h>
32#include <tqlabel.h>
33#include <tqhgroupbox.h>
34#include <tqlayout.h>
35#include <tqwhatsthis.h>
36#include <tqvbox.h>
37
38#include "kchart_params.h"
39
40#include "kchart_factory.h"
41
42namespace KChart
43{
44
45KChartHiloSubTypeChartPage::KChartHiloSubTypeChartPage( KChartParams* params,
46 TQWidget* parent ) :
47 KChartSubTypeChartPage( params, parent )
48{
49 TQHBoxLayout* toplevel = new TQHBoxLayout( this, 10 );
50 TQVButtonGroup* subtypeBG = new TQVButtonGroup( i18n( "Sub-type" ), this );
51 TQWhatsThis::add(subtypeBG, i18n("Select the desired sub-type of a chart. The available sub-types depend on the chart type. Some chart types have no sub-type at all, in which case this configuration page is not shown."));
52 toplevel->addWidget( subtypeBG, AlignCenter| AlignVCenter );
53 normal = new TQRadioButton( i18n( "Normal" ), subtypeBG );
54 subtypeBG->insert( normal, KDChartParams::AreaNormal );
55 stacked = new TQRadioButton(i18n("HiLoClose"), subtypeBG );
56 subtypeBG->insert( stacked, KDChartParams::AreaStacked );
57 percent = new TQRadioButton( i18n("HiLoOpenClose"), subtypeBG );
58 subtypeBG->insert( percent, KDChartParams::AreaPercent );
59 subtypeBG->setFixedWidth( subtypeBG->sizeHint().width() );
60 connect( subtypeBG, TQ_SIGNAL( clicked( int ) ),
61 this, TQ_SLOT( slotChangeSubType( int ) ) );
62
63 TQHGroupBox* exampleGB = new TQHGroupBox( i18n( "Example" ), this );
64 TQWhatsThis::add(exampleGB, i18n("Preview the sub-type you choose."));
65 toplevel->addWidget( exampleGB, 2 );
66 exampleLA = new TQLabel( exampleGB );
67 exampleLA->setAlignment( AlignCenter | AlignVCenter );
68 // PENDING(kalle) Make image scale with available space once TQt 2.2 is out.
69}
70
71void KChartHiloSubTypeChartPage::init()
72{
73 switch( m_params->hiLoChartSubType() ) {
74 case KDChartParams::HiLoNormal:
75 normal->setChecked( true );
76 break;
77 case KDChartParams::HiLoClose:
78 stacked->setChecked( true );
79 break;
80 case KDChartParams::HiLoOpenClose:
81 percent->setChecked( true );
82 break;
83 default:
84 {
85 kdDebug( 35001 ) << "Error in stack_type" << endl;
86 abort();
87 break;
88 }
89 }
90
91 slotChangeSubType( m_params->hiLoChartSubType() );
92}
93
94void KChartHiloSubTypeChartPage::slotChangeSubType( int type )
95{
96 switch( type ) {
97 case KDChartParams::HiLoNormal:
98 exampleLA->setPixmap( UserIcon( "chart_hilo_normal", KChartFactory::global() ) );
99 break;
100 case KDChartParams::HiLoClose:
101 exampleLA->setPixmap( UserIcon( "chart_hilo_close", KChartFactory::global() ) );
102 break;
103 case KDChartParams::HiLoOpenClose:
104 exampleLA->setPixmap( UserIcon( "chart_hilo_openclose", KChartFactory::global() ) );
105 break;
106 };
107}
108
109
110
111void KChartHiloSubTypeChartPage::apply()
112{
113 if( normal->isChecked() )
114 m_params->setHiLoChartSubType( KDChartParams::HiLoNormal );
115 else if( stacked->isChecked() )
116 m_params->setHiLoChartSubType( KDChartParams::HiLoClose );
117 else if( percent->isChecked() )
118 m_params->setHiLoChartSubType( KDChartParams::HiLoOpenClose );
119 else {
120 kdDebug( 35001 ) << "Error in groupbutton" << endl;
121 }
122}
123
124KChartAreaSubTypeChartPage::KChartAreaSubTypeChartPage( KChartParams* params,
125 TQWidget* parent ) :
126 KChartSubTypeChartPage( params, parent )
127{
128 TQHBoxLayout* toplevel = new TQHBoxLayout( this, 10 );
129 TQVButtonGroup* subtypeBG = new TQVButtonGroup( i18n( "Sub-type" ), this );
130 TQWhatsThis::add(subtypeBG, i18n("Select the desired sub-type of a chart. The available sub-types depend on the chart type. Some chart types have no sub-type at all, in which case this configuration page is not shown."));
131 toplevel->addWidget( subtypeBG, AlignCenter| AlignVCenter );
132 normal = new TQRadioButton( i18n( "Normal" ), subtypeBG );
133 subtypeBG->insert( normal, KDChartParams::AreaNormal );
134 stacked = new TQRadioButton( i18n( "Stacked" ), subtypeBG );
135 subtypeBG->insert( stacked, KDChartParams::AreaStacked );
136 percent = new TQRadioButton( i18n( "Percent" ), subtypeBG );
137 subtypeBG->insert( percent, KDChartParams::AreaPercent );
138 subtypeBG->setFixedWidth( subtypeBG->sizeHint().width() );
139 connect( subtypeBG, TQ_SIGNAL( clicked( int ) ),
140 this, TQ_SLOT( slotChangeSubType( int ) ) );
141
142 TQHGroupBox* exampleGB = new TQHGroupBox( i18n( "Example" ), this );
143 TQWhatsThis::add(exampleGB, i18n("Preview the sub-type you choose."));
144 toplevel->addWidget( exampleGB, 2 );
145 exampleLA = new TQLabel( exampleGB );
146 exampleLA->setAlignment( AlignCenter | AlignVCenter );
147 // PENDING(kalle) Make image scale with available space once TQt 2.2 is out.
148}
149
150
151void KChartAreaSubTypeChartPage::init()
152{
153 switch( m_params->areaChartSubType() ) {
154 case KDChartParams::AreaNormal:
155 normal->setChecked( true );
156 break;
157 case KDChartParams::AreaStacked:
158 stacked->setChecked( true );
159 break;
160 case KDChartParams::AreaPercent:
161 percent->setChecked( true );
162 break;
163 default:
164 {
165 kdDebug( 35001 ) << "Error in stack_type" << endl;
166 abort();
167 break;
168 }
169 }
170
171 slotChangeSubType( m_params->areaChartSubType() );
172}
173
174void KChartAreaSubTypeChartPage::slotChangeSubType( int type )
175{
176 switch( type ) {
177 case KDChartParams::AreaNormal:
178 exampleLA->setPixmap( UserIcon( "chart_area_normal", KChartFactory::global() ) );
179 break;
180 case KDChartParams::AreaStacked:
181 exampleLA->setPixmap( UserIcon( "chart_area_stacked", KChartFactory::global() ) );
182 break;
183 case KDChartParams::AreaPercent:
184 exampleLA->setPixmap( UserIcon( "chart_area_percent", KChartFactory::global() ) );
185 break;
186 };
187}
188
189
190
191void KChartAreaSubTypeChartPage::apply()
192{
193 if( normal->isChecked() )
194 m_params->setAreaChartSubType( KDChartParams::AreaNormal );
195 else if( stacked->isChecked() )
196 m_params->setAreaChartSubType( KDChartParams::AreaStacked );
197 else if( percent->isChecked() )
198 m_params->setAreaChartSubType( KDChartParams::AreaPercent );
199 else {
200 kdDebug( 35001 ) << "Error in groupbutton" << endl;
201 }
202}
203
204KChartBarSubTypeChartPage::KChartBarSubTypeChartPage( KChartParams* params,
205 TQWidget* parent ) :
206 KChartSubTypeChartPage( params, parent )
207{
208 TQHBoxLayout* toplevel = new TQHBoxLayout( this, 10 );
209 TQVBox *left = new TQVBox( this );
210 TQVButtonGroup* subtypeBG = new TQVButtonGroup( i18n( "Sub-type" ), left );
211 TQWhatsThis::add(subtypeBG, i18n("Select the desired sub-type of a chart. The available sub-types depend on the chart type. Some chart types have no sub-type at all, in which case this configuration page is not shown."));
212 //toplevel->addWidget( subtypeBG, AlignCenter );
213 toplevel->addWidget( left, AlignCenter );
214
215 normal = new TQRadioButton( i18n( "Normal" ), subtypeBG );
216 subtypeBG->insert( normal, KDChartParams::BarNormal );
217 stacked = new TQRadioButton( i18n( "Stacked" ), subtypeBG );
218 subtypeBG->insert( stacked, KDChartParams::BarStacked );
219 percent = new TQRadioButton( i18n( "Percent" ), subtypeBG );
220 subtypeBG->insert( percent, KDChartParams::BarPercent );
221
222 subtypeBG->setFixedWidth( subtypeBG->sizeHint().width() );
223 connect( subtypeBG, TQ_SIGNAL( clicked( int ) ),
224 this, TQ_SLOT( slotChangeSubType( int ) ) );
225
226 //TQHBox *hbox = new TQHBox( this );
227 new TQLabel( i18n( "Number of lines: "), left );
228 m_numLines = new TQSpinBox( left );
229 // FIXME: Use a grid layout instead
230 new TQLabel( "", left);
231 left->setStretchFactor( left, 1 );
232
233 TQHGroupBox* exampleGB = new TQHGroupBox( i18n( "Example" ), this );
234 TQWhatsThis::add(exampleGB, i18n("Preview the sub-type you choose."));
235 toplevel->addWidget( exampleGB, 2 );
236 exampleLA = new TQLabel( exampleGB );
237 exampleLA->setAlignment( AlignCenter | AlignVCenter );
238}
239
240void KChartBarSubTypeChartPage::init()
241{
242 // SUM is for areas only and therefore not configurable here.
243 switch( m_params->barChartSubType() ) {
244 case KDChartParams::BarNormal:
245 normal->setChecked( true );
246 break;
247 case KDChartParams::BarStacked:
248 stacked->setChecked( true );
249 break;
250 case KDChartParams::BarPercent:
251 percent->setChecked( true );
252 break;
253 default:
254 {
255 kdDebug( 35001 ) << "Error in stack_type" << endl;
256 break;
257 }
258 }
259
260 m_numLines->setValue( m_params->barNumLines() );
261
262 slotChangeSubType( m_params->barChartSubType() );
263}
264
265
266void KChartBarSubTypeChartPage::slotChangeSubType( int type )
267{
268 switch( type ) {
269 case KDChartParams::BarStacked:
270 exampleLA->setPixmap( UserIcon( "chart_bar_layer", KChartFactory::global() ) );
271 break;
272 case KDChartParams::BarNormal:
273 exampleLA->setPixmap( UserIcon( "chart_bar_beside", KChartFactory::global() ) );
274 break;
275 case KDChartParams::BarPercent:
276 exampleLA->setPixmap( UserIcon( "chart_bar_percent", KChartFactory::global() ) );
277 break;
278 };
279}
280
281
282void KChartBarSubTypeChartPage::apply()
283{
284 if( normal->isChecked() ) {
285 m_params->setBarChartSubType( KDChartParams::BarNormal );
286 } else if( stacked->isChecked() ) {
287 m_params->setBarChartSubType( KDChartParams::BarStacked );
288 } else if( percent->isChecked() ) {
289 m_params->setBarChartSubType( KDChartParams::BarPercent );
290 } else {
291 kdDebug( 35001 ) << "Error in groupbutton" << endl;
292 }
293
294 // FIXME: Error controls.
295 m_params->setBarNumLines( m_numLines->value() );
296}
297
298KChartLineSubTypeChartPage::KChartLineSubTypeChartPage( KChartParams* params,
299 TQWidget* parent ) :
300 KChartSubTypeChartPage( params, parent )
301{
302 TQHBoxLayout* toplevel = new TQHBoxLayout( this, 10 );
303 TQVButtonGroup* subtypeBG = new TQVButtonGroup( i18n( "Sub-type" ), this );
304 TQWhatsThis::add(subtypeBG, i18n("Select the desired sub-type of a chart. The available sub-types depend on the chart type. Some chart types have no sub-type at all, in which case this configuration page is not shown."));
305 toplevel->addWidget( subtypeBG, AlignCenter| AlignVCenter );
306 normal = new TQRadioButton( i18n( "Normal" ), subtypeBG );
307 subtypeBG->insert( normal, KDChartParams::AreaNormal );
308 stacked = new TQRadioButton( i18n( "Stacked" ), subtypeBG );
309 subtypeBG->insert( stacked, KDChartParams::AreaStacked );
310 percent = new TQRadioButton( i18n( "Percent" ), subtypeBG );
311 subtypeBG->insert( percent, KDChartParams::AreaPercent );
312 subtypeBG->setFixedWidth( subtypeBG->sizeHint().width() );
313 connect( subtypeBG, TQ_SIGNAL( clicked( int ) ),
314 this, TQ_SLOT( slotChangeSubType( int ) ) );
315
316 TQHGroupBox* exampleGB = new TQHGroupBox( i18n( "Example" ), this );
317 TQWhatsThis::add(exampleGB, i18n("Preview the sub-type you choose."));
318 toplevel->addWidget( exampleGB, 2 );
319 exampleLA = new TQLabel( exampleGB );
320 exampleLA->setAlignment( AlignCenter | AlignVCenter );
321 // PENDING(kalle) Make image scale with available space once TQt 2.2 is out.
322}
323
324void KChartLineSubTypeChartPage::init()
325{
326 switch( m_params->lineChartSubType() ) {
327 case KDChartParams::LineNormal:
328 normal->setChecked( true );
329 break;
330 case KDChartParams::LineStacked:
331 stacked->setChecked( true );
332 break;
333 case KDChartParams::LinePercent:
334 percent->setChecked( true );
335 break;
336 default:
337 {
338 kdDebug( 35001 ) << "Error in stack_type" << endl;
339 abort();
340 break;
341 }
342 }
343
344 slotChangeSubType( m_params->lineChartSubType() );
345}
346
347void KChartLineSubTypeChartPage::slotChangeSubType( int type )
348{
349 switch( type ) {
350 case KDChartParams::AreaNormal:
351 exampleLA->setPixmap( UserIcon( "chart_line_normal", KChartFactory::global() ) );
352 break;
353 case KDChartParams::AreaStacked:
354 exampleLA->setPixmap( UserIcon( "chart_line_stacked", KChartFactory::global() ) );
355 break;
356 case KDChartParams::AreaPercent:
357 exampleLA->setPixmap( UserIcon( "chart_line_percent", KChartFactory::global() ) );
358 break;
359 };
360}
361
362
363
364void KChartLineSubTypeChartPage::apply()
365{
366 if( normal->isChecked() )
367 m_params->setLineChartSubType( KDChartParams::LineNormal );
368 else if( stacked->isChecked() )
369 m_params->setLineChartSubType( KDChartParams::LineStacked );
370 else if( percent->isChecked() )
371 m_params->setLineChartSubType( KDChartParams::LinePercent );
372 else {
373 kdDebug( 35001 ) << "Error in groupbutton" << endl;
374 }
375}
376
377KChartPolarSubTypeChartPage::KChartPolarSubTypeChartPage( KChartParams* params,
378 TQWidget* parent ) :
379 KChartSubTypeChartPage( params, parent )
380{
381 TQHBoxLayout* toplevel = new TQHBoxLayout( this, 10 );
382 TQVButtonGroup* subtypeBG = new TQVButtonGroup( i18n( "Sub-type" ), this );
383 TQWhatsThis::add(subtypeBG, i18n("Select the desired sub-type of a chart. The available sub-types depend on the chart type. Some chart types have no sub-type at all, in which case this configuration page is not shown."));
384 toplevel->addWidget( subtypeBG, AlignCenter| AlignVCenter );
385 normal = new TQRadioButton( i18n( "Normal" ), subtypeBG );
386 subtypeBG->insert( normal, KDChartParams::AreaNormal );
387 stacked = new TQRadioButton( i18n( "Stacked" ), subtypeBG );
388 subtypeBG->insert( stacked, KDChartParams::AreaStacked );
389 percent = new TQRadioButton( i18n( "Percent" ), subtypeBG );
390 subtypeBG->insert( percent, KDChartParams::AreaPercent );
391 subtypeBG->setFixedWidth( subtypeBG->sizeHint().width() );
392 connect( subtypeBG, TQ_SIGNAL( clicked( int ) ),
393 this, TQ_SLOT( slotChangeSubType( int ) ) );
394
395 TQHGroupBox* exampleGB = new TQHGroupBox( i18n( "Example" ), this );
396 TQWhatsThis::add(exampleGB, i18n("Preview the sub-type you choose."));
397 toplevel->addWidget( exampleGB, 2 );
398 exampleLA = new TQLabel( exampleGB );
399 exampleLA->setAlignment( AlignCenter | AlignVCenter );
400 // PENDING(kalle) Make image scale with available space once TQt 2.2 is out.
401}
402
403void KChartPolarSubTypeChartPage::init()
404{
405 switch( m_params->polarChartSubType() ) {
406 case KDChartParams::PolarNormal:
407 normal->setChecked( true );
408 break;
409 case KDChartParams::PolarStacked:
410 stacked->setChecked( true );
411 break;
412 case KDChartParams::PolarPercent:
413 percent->setChecked( true );
414 break;
415 default:
416 {
417 kdDebug( 35001 ) << "Error in stack_type" << endl;
418 abort();
419 break;
420 }
421 }
422
423 slotChangeSubType( m_params->lineChartSubType() );
424}
425
426void KChartPolarSubTypeChartPage::slotChangeSubType( int type )
427{
428 switch( type ) {
429 case KDChartParams::PolarNormal:
430 exampleLA->setPixmap( UserIcon( "chart_polar_normal", KChartFactory::global() ) );
431 break;
432 case KDChartParams::PolarStacked:
433 exampleLA->setPixmap( UserIcon( "chart_polar_stacked", KChartFactory::global() ) );
434 break;
435 case KDChartParams::PolarPercent:
436 exampleLA->setPixmap( UserIcon( "chart_polar_percent", KChartFactory::global() ) );
437 break;
438 };
439}
440
441
442
443void KChartPolarSubTypeChartPage::apply()
444{
445 if( normal->isChecked() )
446 m_params->setPolarChartSubType( KDChartParams::PolarNormal );
447 else if( stacked->isChecked() )
448 m_params->setPolarChartSubType( KDChartParams::PolarStacked );
449 else if( percent->isChecked() )
450 m_params->setPolarChartSubType( KDChartParams::PolarPercent );
451 else {
452 kdDebug( 35001 ) << "Error in groupbutton" << endl;
453 }
454}
455
456} //KChart namespace