kchart

kchartLegendConfigPage.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001,2002,2003,2004 Laurent Montel <montel@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 "kchartLegendConfigPage.h"
21#include "kchartLegendConfigPage.moc"
22
23#include <tdeapplication.h>
24#include <tdelocale.h>
25#include <kcolorbutton.h>
26#include <tdefontdialog.h>
27#include <kiconloader.h>
28
29#include <tqlabel.h>
30#include <tqbuttongroup.h>
31#include <tqvbuttongroup.h>
32#include <tqradiobutton.h>
33#include <tqlineedit.h>
34#include <tqtooltip.h>
35#include <tqwhatsthis.h>
36
37#include "kchart_params.h"
38#include "kchart_factory.h"
39
40#include "KDFrameProfileSection.h"
41
42
43namespace KChart
44{
45
46
47KChartLegendConfigPage::KChartLegendConfigPage( KChartParams* params,
48 TQWidget* parent ) :
49 TQWidget( parent ),_params( params )
50{
51 //Layout for 4 blocks
52 TQGridLayout* layout = new TQGridLayout( this, 3, 2, KDialog::marginHint(), KDialog::spacingHint() );
53
54 //1. Block: General settings
55 TQButtonGroup* gb = new TQButtonGroup( 0, TQt::Vertical, i18n("General"), this );
56 gb->layout()->setSpacing(KDialog::spacingHint());
57 gb->layout()->setMargin(KDialog::marginHint());
58 layout->addWidget( gb, 0, 0 );
59
60 TQGridLayout *grid2 = new TQGridLayout( gb->layout(), 4, 2 );
61
62 TQLabel* lab = new TQLabel( i18n("Title:"), gb );
63 TQWhatsThis::add(lab, i18n("Write here the title of the legend, which is displayed at the top of the legend box."));
64 grid2->addWidget( lab, 0, 0 );
65
66 title = new TQLineEdit( gb );
67 grid2->addWidget( title, 0, 1 );
68
69 // 2. Block: Legend position
70 gb = new TQButtonGroup( 0, TQt::Vertical, i18n("Legend Position"), this );
71 TQWhatsThis::add(gb, i18n("<qt>Choose the location of the legend on the chart by "
72 "clicking a location button.\nUse the central button to <b>hide</b> the legend.</qt>"));
73 gb->layout()->setSpacing(KDialog::spacingHint());
74 gb->layout()->setMargin(KDialog::marginHint());
75 gb->setExclusive( true );
76
77 TQGridLayout *grid1 = new TQGridLayout( gb->layout(), 5, 5 );
78
79 lTopLeft = addButton( grid1, gb, i18n("Top-Left"), "chart_legend_topleft", 0, 0 );
80 lTopLeftTop = addButton( grid1, gb, i18n("Top-Left-Top"), "chart_legend_toplefttop", 0, 1 );
81 lTop = addButton( grid1, gb, i18n("Top"), "chart_legend_top", 0, 2 );
82 lTopRightTop = addButton( grid1, gb, i18n("Top-Right-Top"), "chart_legend_toprighttop", 0, 3 );
83 lTopRight = addButton( grid1, gb, i18n("Top-Right"), "chart_legend_topright", 0, 4 );
84
85 lTopLeftLeft = addButton( grid1, gb, i18n("Top-Left-Left"), "chart_legend_topleftleft", 1, 0 );
86 lTopRightRight = addButton( grid1, gb, i18n("Top-Right-Right"), "chart_legend_toprightright", 1, 4 );
87
88 lLeft = addButton( grid1, gb, i18n("Left"), "chart_legend_left", 2, 0 );
89 noLegend = addButton( grid1, gb, i18n("No Legend"), "chart_legend_nolegend", 2, 2 );
90 lRight = addButton( grid1, gb, i18n("Right"), "chart_legend_right", 2, 4 );
91
92 lBottomLeftLeft = addButton( grid1, gb, i18n("Bottom-Left-Left"), "chart_legend_bottomleftleft", 3, 0 );
93 lBottomRightRight = addButton( grid1, gb, i18n("Bottom-Right-Right"), "chart_legend_bottomrightright", 3, 4 );
94
95 lBottomLeft = addButton( grid1, gb, i18n("Bottom-Left"), "chart_legend_bottomleft", 4, 0 );
96 lBottomLeftBottom = addButton( grid1, gb, i18n("Bottom-Left-Bottom"), "chart_legend_bottomleftbottom", 4, 1 );
97 lBottom = addButton( grid1, gb, i18n("Bottom"), "chart_legend_bottom", 4, 2 );
98 lBottomRightBottom= addButton( grid1, gb, i18n("Bottom-Right-Bottom"), "chart_legend_bottomrightbottom",4, 3 );
99 lBottomRight = addButton( grid1, gb, i18n("Bottom-Right"), "chart_legend_bottomright", 4, 4 );
100
101 gb->setAlignment( TQt::AlignLeft );
102 layout->addMultiCellWidget( gb, 1,2, 0,0 );
103
104 // 3. Block: Font
105 gb = new TQButtonGroup( 0, TQt::Vertical, i18n("Font"), this );
106 TQWhatsThis::add(gb, i18n("This Font box can be used to set different fonts for the legend title and the individual entries."));
107 gb->layout()->setSpacing(KDialog::spacingHint());
108 gb->layout()->setMargin(KDialog::marginHint());
109 layout->addWidget( gb, 0, 1 );
110
111 TQGridLayout *grid4 = new TQGridLayout( gb->layout(), 4, 2 );
112 titleLegendFontButton = new TQPushButton( gb );
113
114 lab = new TQLabel( i18n("Legend title font:"), gb );
115 grid4->addWidget( lab, 0 ,0 );
116
117 titleLegendFontButton->setText( i18n("Select Font...") );
118 TQWhatsThis::add(titleLegendFontButton, i18n("Click here to display the TDE font chooser dialog. You will be able to change the font family, style and size for the legend title."));
119 grid4->addWidget( titleLegendFontButton, 1, 0 );
120
121 lab = new TQLabel( i18n("Legend text font:"), gb );
122 grid4->addWidget( lab, 2, 0 );
123 textLegendFontButton = new TQPushButton( gb );
124 textLegendFontButton->setText( i18n("Select Font...") );
125 TQWhatsThis::add(textLegendFontButton, i18n("Click here to display the TDE font chooser dialog. You will be able to change the font family, style and size for the legend text."));
126 grid4->addWidget( textLegendFontButton, 3, 0 );
127
128 connect( titleLegendFontButton, TQ_SIGNAL(clicked()),
129 this, TQ_SLOT(changeTitleLegendFont()));
130 connect( textLegendFontButton, TQ_SIGNAL(clicked()),
131 this, TQ_SLOT(changeTextLegendFont()));
132
133 // 4. Block: Orientation
134 orientationGroup = new TQVButtonGroup( i18n("Orientation"), this );
135 TQWhatsThis::add(orientationGroup, i18n("Select, if the legend's items should be drawn next to each other, or below each other."));
136 orientationGroup->setRadioButtonExclusive(true);
137 orientationGroup->layout()->setSpacing(KDialog::spacingHint());
138 orientationGroup->layout()->setMargin(KDialog::marginHint());
139 layout->addWidget( orientationGroup, 1, 1 );
140
141 TQRadioButton* orientation = new TQRadioButton( i18n("Vertically"), orientationGroup );
142 orientation = new TQRadioButton( i18n("Horizontally"), orientationGroup );
143 Q_UNUSED(orientation);
144
145 // 5. Block: Text Colors
146 gb = new TQButtonGroup( 0, TQt::Vertical, i18n("Color"), this );
147 TQWhatsThis::add(gb, i18n("This Color box can be used to set different colors for the legend title and text."));
148 gb->layout()->setSpacing(KDialog::spacingHint());
149 gb->layout()->setMargin(KDialog::marginHint());
150 layout->addWidget( gb, 2, 1 );
151
152 TQGridLayout *grid3 = new TQGridLayout( gb->layout(), 6, 2 );
153
154 lab = new TQLabel( i18n("Legend title color:"), gb );
155 grid3->addWidget( lab, 0, 0 );
156
157 legendTitleColor = new KColorButton( gb );
158 TQWhatsThis::add(legendTitleColor, i18n("Click here to display the TDE Select Color dialog. You will be able to change the color for the legend title."));
159 grid3->addWidget( legendTitleColor, 1, 0 );
160
161
162 lab = new TQLabel( i18n("Legend text color:"), gb );
163 grid3->addWidget( lab, 2, 0 );
164
165 legendTextColor = new KColorButton( gb );
166 TQWhatsThis::add(legendTextColor, i18n("Click here to display the TDE Select Color dialog. You will be able to change the color for the legend text."));
167 grid3->addWidget( legendTextColor, 3, 0 );
168
169
170 lab = new TQLabel( i18n("Legend frame color:"), gb );
171 grid3->addWidget( lab, 4, 0 );
172
173 legendFrameColor = new KColorButton( gb );
174 TQWhatsThis::add(legendFrameColor, i18n("Click here to display the TDE Select Color dialog. You will be able to change the color for the legend frame."));
175
176 grid3->addWidget( legendFrameColor, 5, 0 );
177
178 //it's not good but I don't know how
179 //to reduce space
180 layout->addColSpacing( 1, 300 );
181}
182
183void KChartLegendConfigPage::init()
184{
185 switch( _params->legendPosition())
186 {
187 case KDChartParams::NoLegend:
188 noLegend->setOn( true );
189 break;
190 case KDChartParams::LegendTop:
191 lTop->setOn( true );
192 break;
193 case KDChartParams::LegendBottom:
194 lBottom->setOn( true );
195 break;
196 case KDChartParams::LegendLeft:
197 lLeft->setOn( true );
198 break;
199 case KDChartParams::LegendRight:
200 lRight->setOn( true );
201 break;
202 case KDChartParams::LegendTopLeft:
203 lTopLeft->setOn( true );
204 break;
205 case KDChartParams::LegendTopLeftTop:
206 lTopLeftTop->setOn( true );
207 break;
208 case KDChartParams::LegendTopLeftLeft:
209 lTopLeftLeft->setOn( true );
210 break;
211 case KDChartParams::LegendTopRight:
212 lTopRight->setOn( true );
213 break;
214 case KDChartParams::LegendTopRightTop:
215 lTopRightTop->setOn( true );
216 break;
217 case KDChartParams::LegendTopRightRight:
218 lTopRightRight->setOn( true );
219 break;
220 case KDChartParams::LegendBottomRight:
221 lBottomRight->setOn( true );
222 break;
223 case KDChartParams::LegendBottomRightBottom:
224 lBottomRightBottom->setOn( true );
225 break;
226 case KDChartParams::LegendBottomRightRight:
227 lBottomRightRight->setOn( true );
228 break;
229 case KDChartParams::LegendBottomLeft:
230 lBottomLeft->setOn( true );
231 break;
232 case KDChartParams::LegendBottomLeftBottom:
233 lBottomLeftBottom->setOn( true );
234 break;
235 case KDChartParams::LegendBottomLeftLeft:
236 lBottomLeftLeft->setOn( true );
237 break;
238 default:
239 lRight->setOn( true );
240 break;
241 }
242
243 title->setText(_params->legendTitleText());
244
245 legendTitleColor->setColor(_params->legendTitleTextColor());
246
247 legendTextColor->setColor(_params->legendTextColor());
248
249 TQColor frameColor(TQt::black);
250 bool bFound;
251 const KDChartParams::KDChartFrameSettings * legendFrame =
252 _params->frameSettings( KDChartEnums::AreaLegend, bFound );
253 if( bFound )
254 {
255 const KDFrameProfileSection * top =
256 const_cast<KDFrameProfile&>(legendFrame->frame().profile( KDFrame::ProfileTop )).first();
257 if( top )
258 frameColor = top->pen().color();
259 }
260 legendFrameColor->setColor(frameColor);
261
262 if( _params->legendOrientation() == TQt::Vertical )
263 orientationGroup->setButton(0);
264 else
265 orientationGroup->setButton(1);
266
267 titleLegend = _params->legendTitleFont();
268 titleLegendIsRelative = _params->legendTitleFontUseRelSize()
269 ? TQButton::On
270 : TQButton::Off;
271 if( TQButton::On == titleLegendIsRelative )
272 titleLegend.setPointSize( _params->legendTitleFontRelSize() );
273
274 textLegend=_params->legendFont();
275 textLegendIsRelative = _params->legendFontUseRelSize()
276 ? TQButton::On
277 : TQButton::Off;
278 if( TQButton::On == textLegendIsRelative )
279 textLegend.setPointSize(_params->legendFontRelSize());
280}
281
282void KChartLegendConfigPage::changeTitleLegendFont()
283{
284 TQButton::ToggleState state = titleLegendIsRelative;
285 if ( TDEFontDialog::getFont( titleLegend,false,this, true,&state ) != TQDialog::Rejected
286 && TQButton::NoChange != state )
287 titleLegendIsRelative = state;
288}
289
290void KChartLegendConfigPage::changeTextLegendFont()
291{
292 TQButton::ToggleState state = textLegendIsRelative;
293 if ( TDEFontDialog::getFont( textLegend,false,this, true,&state ) != TQDialog::Rejected
294 && TQButton::NoChange != state )
295 textLegendIsRelative = state;
296}
297
298void KChartLegendConfigPage::apply()
299{
300 if( noLegend->isOn() )
301 _params->setLegendPosition( KDChartParams::NoLegend );
302 else if( lTop->isOn() )
303 _params->setLegendPosition( KDChartParams::LegendTop );
304 else if( lBottom->isOn() )
305 _params->setLegendPosition( KDChartParams::LegendBottom );
306 else if( lLeft->isOn() )
307 _params->setLegendPosition( KDChartParams::LegendLeft );
308 else if( lRight->isOn() )
309 _params->setLegendPosition( KDChartParams::LegendRight );
310 else if( lTopLeft->isOn() )
311 _params->setLegendPosition( KDChartParams::LegendTopLeft );
312 else if( lTopLeftTop->isOn() )
313 _params->setLegendPosition( KDChartParams::LegendTopLeftTop );
314 else if( lTopLeftLeft->isOn() )
315 _params->setLegendPosition( KDChartParams::LegendTopLeftLeft );
316 else if( lTopRight->isOn() )
317 _params->setLegendPosition( KDChartParams::LegendTopRight );
318 else if( lTopRightTop->isOn() )
319 _params->setLegendPosition( KDChartParams::LegendTopRightTop );
320 else if( lTopRightRight->isOn() )
321 _params->setLegendPosition( KDChartParams::LegendTopRightRight );
322 else if( lBottomRight->isOn() )
323 _params->setLegendPosition( KDChartParams::LegendBottomRight );
324 else if( lBottomRightBottom->isOn() )
325 _params->setLegendPosition( KDChartParams::LegendBottomRightBottom );
326 else if( lBottomRightRight->isOn() )
327 _params->setLegendPosition( KDChartParams::LegendBottomRightRight );
328 else if( lBottomLeft->isOn() )
329 _params->setLegendPosition( KDChartParams::LegendBottomLeft );
330 else if( lBottomLeftBottom->isOn() )
331 _params->setLegendPosition( KDChartParams::LegendBottomLeftBottom );
332 else if( lBottomLeftLeft->isOn() )
333 _params->setLegendPosition( KDChartParams::LegendBottomLeftLeft );
334 else
335 _params->setLegendPosition( KDChartParams::LegendRight );
336
337 if( orientationGroup->selectedId() == 0 )
338 _params->setLegendOrientation( TQt::Vertical );
339 else
340 _params->setLegendOrientation( TQt::Horizontal );
341
342 _params->setLegendTitleText(title->text());
343 _params->setLegendTitleTextColor(legendTitleColor->color());
344 _params->setLegendTextColor(legendTextColor->color());
345
346 const TQColor frameColor(legendFrameColor->color());
347 if( frameColor == TQt::black )
348 _params->removeFrame( KDChartEnums::AreaLegend );
349 else
350 _params->setSimpleFrame( KDChartEnums::AreaLegend,
351 0,0, 0,0,
352 true,
353 true,
354 KDFrame::FrameFlat,
355 1,
356 0,
357 frameColor );
358
359 _params->setLegendTitleFont(titleLegend, TQButton::Off == titleLegendIsRelative);
360 if( TQButton::On == titleLegendIsRelative )
361 _params->setLegendTitleFontRelSize(titleLegend.pointSize());
362 _params->setLegendFont(textLegend, TQButton::Off == textLegendIsRelative);
363 if( TQButton::On == textLegendIsRelative )
364 _params->setLegendFontRelSize(textLegend.pointSize());
365}
366
367TQPushButton* KChartLegendConfigPage::addButton( TQGridLayout* layout,
368 TQButtonGroup* gb,
369 const TQString &toolTipText,
370 const TQString &icon,
371 int posY,
372 int posX )
373{
374 TQPushButton* button = new TQPushButton( gb );
375 button->setToggleButton( true );
376 button->setPixmap( BarIcon( icon,
377 TDEIcon::SizeMedium,
378 TDEIcon::DefaultState,
379 KChartFactory::global() ) );
380 TQToolTip::add( button, toolTipText );
381 layout->addWidget( button, posY, posX );
382 return button;
383}
384
385} //KChart namespace
Stores the frame settings for one of the chart areas:
const KDFrame & frame() const
Return the KDFrame object used for drawing this areas frame.
Settings for one profile section of one side of the frame.