1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
/* This file is part of the KDE project
Copyright (C) 2001,2002,2003,2004 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "kchartParameterConfigPage.h"
#include "kchartParameterConfigPage.moc"
#include <tdeapplication.h>
#include <tdelocale.h>
#include <tqlayout.h>
#include <tqlabel.h>
#include <tqcheckbox.h>
#include <tqlineedit.h>
#include <tqspinbox.h>
#include <tqbuttongroup.h>
#include <tqradiobutton.h>
#include <tqvbuttongroup.h>
#include <tdefontdialog.h>
#include <tqwhatsthis.h>
#include "kdchart/KDChartAxisParams.h"
#include "kchart_params.h"
namespace KChart
{
KChartParameterConfigPage::KChartParameterConfigPage( KChartParams* params,
TQWidget* parent ) :
TQWidget( parent ),_params( params )
{
// toplevel layout
TQVBoxLayout* toplevel = new TQVBoxLayout( this, 10 );
TQGridLayout* layout = new TQGridLayout( 1, 3 );
toplevel->addLayout( layout );
// The "Parameters" button group
TQButtonGroup* gb1 = new TQButtonGroup( 0, TQt::Vertical, i18n("Parameters"), this );
gb1->layout()->setSpacing(KDialog::spacingHint());
gb1->layout()->setMargin(KDialog::marginHint());
TQGridLayout *grid1 = new TQGridLayout(gb1->layout(),9,1);
grid = new TQCheckBox( i18n( "Grid" ), gb1 );
TQWhatsThis::add(grid, i18n("If this is checked, the grid is shown. If you uncheck this option, the grid will not be displayed anymore."));
grid1->addWidget(grid, 0, 0);
//gb1->insert(grid);
yaxis = new TQCheckBox( i18n( "Y-axis" ), gb1);
TQWhatsThis::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."));
connect( yaxis, TQT_SIGNAL( clicked() ), this, TQT_SLOT( axisChanged() ) );
grid1->addWidget(yaxis, 1, 0);
//gb1->insert(yaxis);
xaxis = new TQCheckBox( i18n( "X-axis" ), gb1 );
TQWhatsThis::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."));
connect( xaxis, TQT_SIGNAL( clicked() ), this, TQT_SLOT( axisChanged() ) );
grid1->addWidget(xaxis, 2, 0);
//gb1->insert(xaxis);
#if 0
xlabel = new TQCheckBox( i18n( "Has X-label" ), gb1 );
grid1->addWidget(xlabel,3,0);
yaxis2 = new TQCheckBox( i18n( "Y-axis 2" ), gb1 );
grid1->addWidget(yaxis2,4,0);
#endif
#if 0 // Moved to the Line page
lineMarker = new TQCheckBox( i18n( "Line marker" ), gb1 );
grid1->addWidget(lineMarker, 4, 0);
#endif
#if 0
llabel = new TQCheckBox( i18n( "Legend" ), gb1 );
grid1->addWidget(llabel,6,0);
#endif
// The "Settings" button group
TQButtonGroup* gb2 = new TQButtonGroup( 0, TQt::Vertical,
i18n("Settings"), this );
gb2->layout()->setSpacing(KDialog::spacingHint());
gb2->layout()->setMargin(KDialog::marginHint());
TQGridLayout *grid2 = new TQGridLayout(gb2->layout(),8,1);
TQBoxLayout * l = new TQVBoxLayout( grid2 );
TQHBoxLayout * top = new TQHBoxLayout( l );
// The X axis title
TQLabel *tmpLabel = new TQLabel( i18n( "X-title:" ), gb2 );
top->addWidget(tmpLabel);
// The Y axis title
tmpLabel = new TQLabel( i18n( "Y-title:" ), gb2 );
top->addWidget(tmpLabel);
TQHBoxLayout * bottom = new TQHBoxLayout( l );
xtitle= new TQLineEdit( gb2 );
TQWhatsThis::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."));
bottom->addWidget(xtitle);
ytitle= new TQLineEdit( gb2 );
TQWhatsThis::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."));
bottom->addWidget(ytitle);
// Linear or logarithmic scale
TQVButtonGroup *scaletype = new TQVButtonGroup(i18n("Scale Types"), gb2);
lin = new TQRadioButton( i18n("Linear scale"), scaletype);
TQWhatsThis::add(lin, i18n("This sets the Y-axis to be linear. This is default."));
log = new TQRadioButton( i18n("Logarithmic scale"), scaletype);
TQWhatsThis::add(log, i18n("This sets the Y-axis to be logarithmic."));
grid2->addWidget(scaletype, 1, 0);
// Decimal precision
TQVButtonGroup *precision = new TQVButtonGroup(i18n("Precision for Numerical Left Axis"), gb2);
grid2->addWidget(precision, 2, 0);
TQRadioButton * automatic_precision = new TQRadioButton( i18n("Automatic precision"), precision);
TQWhatsThis::add(automatic_precision, i18n("This sets the precision as automatic which means that KChart decides what precision to apply."));
automatic_precision->setChecked(true);
max = new TQRadioButton( i18n("Decimal precision:"), precision);
TQWhatsThis::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."));
connect(automatic_precision, TQT_SIGNAL(toggled(bool)), this,
TQT_SLOT(automatic_precision_toggled(bool)) );
maximum_length = new TQSpinBox(0, 15, 1, precision );
TQWhatsThis::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."));
maximum_length->setValue(2);
#if 0
tmpLabel = new TQLabel( i18n( "Y-label format:" ), gb2 );
grid2->addWidget(tmpLabel,0,1);
ylabel_fmt= new TQLineEdit( gb2 );
ylabel_fmt->setMaximumWidth(130);
grid2->addWidget(ylabel_fmt,1,1);
ylabel_fmt->setEnabled(false);
tmpLabel = new TQLabel( i18n( "Y-title 2:" ), gb2 );
grid2->addWidget(tmpLabel,2,1);
ytitle2= new TQLineEdit( gb2 );
ytitle2->setMaximumWidth(130);
grid2->addWidget(ytitle2,3,1);
tmpLabel = new TQLabel( i18n( "Y-label format 2:" ), gb2 );
grid2->addWidget(tmpLabel,4,1);
ylabel2_fmt= new TQLineEdit( gb2 );
ylabel2_fmt->setMaximumWidth(130);
grid2->addWidget(ylabel2_fmt,5,1);
#endif
layout->addWidget(gb1,0,0);
layout->addWidget(gb2,0,1);
#if 0
grid1->activate();
grid2->activate();
#endif
/*connect( grid, TQT_SIGNAL( toggled( bool ) ),
this, TQT_SLOT( changeState( bool ) ) );*/
/*connect( xaxis, TQT_SIGNAL( toggled( bool ) ),
this, TQT_SLOT( changeXaxisState( bool ) ) );*/
}
void KChartParameterConfigPage::changeXaxisState(bool /*state*/)
{
#if 0
if(state)
xlabel->setEnabled(true);
else
xlabel->setEnabled(false);
#endif
}
void KChartParameterConfigPage::init()
{
// PENDING(kalle) adapt these to KDChart
// grid->setChecked(_params->grid);
// xlabel->setChecked(_params->hasxlabel);
grid->setChecked(_params->showGrid());
xaxis->setChecked(_params->axisVisible(KDChartAxisParams::AxisPosBottom));
yaxis->setChecked(_params->axisVisible(KDChartAxisParams::AxisPosLeft));
#if 0
llabel->setChecked(_params->legendPosition()!=KDChartParams::NoLegend);
#endif
#if 0
if ( _params->chartType() == KDChartParams::Line ) {
lineMarker->setEnabled(true);
lineMarker->setChecked(_params->lineMarker());
}
else {
lineMarker->setEnabled(false);
lineMarker->setChecked(false);
}
#endif
// PENDING(kalle) Adapt this
// if(_params->has_yaxis2())
// {
// yaxis2->setChecked(_params->yaxis2);
// int len=_params->ylabel2_fmt.length();
// ylabel2_fmt->setText(_params->ylabel2_fmt.right(len-3));
// ytitle2->setText(_params->ytitle2);
// }
// else
#if 0
{
yaxis2->setEnabled(false);
ylabel2_fmt->setEnabled(false);
ytitle2->setEnabled(false);
}
// PENDING(kalle) Adapt this
// xtitle->setText(_params->xtitle);
// ytitle->setText(_params->ytitle);
// int len=_params->ylabel_fmt.length();
// ylabel_fmt->setText(_params->ylabel_fmt.right(len-3));
// if(_params->xaxis)
// xlabel->setEnabled(true);
// else
xlabel->setEnabled(false);
#endif
xtitle->setText( _params->axisTitle( KDChartAxisParams::AxisPosBottom) );
ytitle->setText( _params->axisTitle( KDChartAxisParams::AxisPosLeft) );
axisChanged();
// Linear / logarithmic Y axis
if ( _params->axisParams( KDChartAxisParams::AxisPosLeft ).axisCalcMode() ==
KDChartAxisParams::AxisCalcLinear )
lin->setChecked(true);
else
log->setChecked(true);
if ( _params->axisParams( KDChartAxisParams::AxisPosLeft ).axisDigitsBehindComma() ==
KDCHART_AXIS_LABELS_AUTO_DIGITS )
maximum_length->setEnabled(false);
else
{
max->setChecked(true);
maximum_length->setValue( _params->axisParams( KDChartAxisParams::AxisPosLeft ).axisDigitsBehindComma() );
}
}
void KChartParameterConfigPage::apply()
{
#if 0
_params->setLegendPosition(llabel->isChecked() ? KDChartParams::LegendRight : KDChartParams::NoLegend);
#endif
_params->setAxisVisible(KDChartAxisParams::AxisPosBottom,xaxis->isChecked());
_params->setAxisVisible(KDChartAxisParams::AxisPosLeft,yaxis->isChecked());
_params->setAxisShowGrid(KDChartAxisParams::AxisPosLeft,
grid->isChecked() );
_params->setAxisShowGrid(KDChartAxisParams::AxisPosBottom,
grid->isChecked() );
_params->setAxisTitle( KDChartAxisParams::AxisPosBottom, xtitle->text() );
_params->setAxisTitle( KDChartAxisParams::AxisPosLeft, ytitle->text() );
// PENDING(kalle) Adapt this
// _params->border=border->isChecked();
// _params->llabel=llabel->isChecked();
// if(xaxis->isChecked())
// _params->hasxlabel=xlabel->isChecked();
// if(_params->has_yaxis2())
// {
// _params->yaxis2=yaxis2->isChecked();
// if(!ylabel2_fmt->text().isEmpty())
// _params->ylabel2_fmt="%g "+ylabel2_fmt->text();
// _params->ytitle2=ytitle2->text();
// }
// PENDING(kalle) Adapt this
// if(grid->isChecked())
// _params->shelf=shelf->isChecked();
// _params->xtitle=xtitle->text();
// _params->ytitle=ytitle->text();
// if(!ylabel_fmt->text().isEmpty())
// _params->ylabel_fmt="%g "+ylabel_fmt->text();
// PENDING(kalle) Adapt this
// if(annotation->text().isEmpty()) {
// if(_params->annotation) {
// delete _params->annotation;
// _params->annotation=0;
// }
// }
// else
// {
// if(!_params->annotation)
// _params->annotation=new KChartAnnotationType;
// _params->annotation->note=annotation->text();
// _params->annotation->color=color->color();
// _params->annotation->point=element->value()-1;
// _params->setAnnotationFont( annotationFont );
// }
#if 0
if( _params->chartType() == KDChartParams::Line )
_params->setLineMarker(lineMarker->isChecked());
#endif
// Set the scale for the Y axis (linear / logarithmic)
{
KDChartAxisParams params;
params = _params->axisParams( KDChartAxisParams::AxisPosLeft );
if (lin->isChecked())
params.setAxisCalcMode(KDChartAxisParams::AxisCalcLinear);
else
{
if(params.axisCalcMode() != KDChartAxisParams::AxisCalcLogarithmic)
{
// Since in this version of kdChart logarithmic scales only work for Line charts,
// lets switch now
_params->setChartType( KChartParams::Line );
}
params.setAxisCalcMode(KDChartAxisParams::AxisCalcLogarithmic);
}
if ( maximum_length->isEnabled() )
params.setAxisDigitsBehindComma( maximum_length->value() );
else
params.setAxisDigitsBehindComma( KDCHART_AXIS_LABELS_AUTO_DIGITS );
_params->setAxisParams( KDChartAxisParams::AxisPosLeft, params );
}
}
void KChartParameterConfigPage::automatic_precision_toggled(bool toggled)
{
if (toggled)
maximum_length->setEnabled(false);
else
maximum_length->setEnabled(true);
}
void KChartParameterConfigPage::axisChanged()
{
if ( !xaxis->isChecked() || !yaxis->isChecked() )
{
xtitle->setEnabled( false );
ytitle->setEnabled( false );
}
else
{
xtitle->setEnabled( true );
ytitle->setEnabled( true );
}
}
} //KChart namespace
|