20#include "kchartLegendConfigPage.h"
21#include "kchartLegendConfigPage.moc"
23#include <tdeapplication.h>
25#include <kcolorbutton.h>
26#include <tdefontdialog.h>
27#include <kiconloader.h>
30#include <tqbuttongroup.h>
31#include <tqvbuttongroup.h>
32#include <tqradiobutton.h>
33#include <tqlineedit.h>
35#include <tqwhatsthis.h>
37#include "kchart_params.h"
38#include "kchart_factory.h"
40#include "KDFrameProfileSection.h"
47KChartLegendConfigPage::KChartLegendConfigPage( KChartParams* params,
49 TQWidget( parent ),_params( params )
52 TQGridLayout* layout =
new TQGridLayout(
this, 3, 2, KDialog::marginHint(), KDialog::spacingHint() );
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 );
60 TQGridLayout *grid2 =
new TQGridLayout( gb->layout(), 4, 2 );
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 );
66 title =
new TQLineEdit( gb );
67 grid2->addWidget( title, 0, 1 );
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 );
77 TQGridLayout *grid1 =
new TQGridLayout( gb->layout(), 5, 5 );
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 );
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 );
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 );
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 );
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 );
101 gb->setAlignment( TQt::AlignLeft );
102 layout->addMultiCellWidget( gb, 1,2, 0,0 );
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 );
111 TQGridLayout *grid4 =
new TQGridLayout( gb->layout(), 4, 2 );
112 titleLegendFontButton =
new TQPushButton( gb );
114 lab =
new TQLabel( i18n(
"Legend title font:"), gb );
115 grid4->addWidget( lab, 0 ,0 );
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 );
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 );
128 connect( titleLegendFontButton, TQ_SIGNAL(clicked()),
129 this, TQ_SLOT(changeTitleLegendFont()));
130 connect( textLegendFontButton, TQ_SIGNAL(clicked()),
131 this, TQ_SLOT(changeTextLegendFont()));
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 );
141 TQRadioButton* orientation =
new TQRadioButton( i18n(
"Vertically"), orientationGroup );
142 orientation =
new TQRadioButton( i18n(
"Horizontally"), orientationGroup );
143 Q_UNUSED(orientation);
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 );
152 TQGridLayout *grid3 =
new TQGridLayout( gb->layout(), 6, 2 );
154 lab =
new TQLabel( i18n(
"Legend title color:"), gb );
155 grid3->addWidget( lab, 0, 0 );
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 );
162 lab =
new TQLabel( i18n(
"Legend text color:"), gb );
163 grid3->addWidget( lab, 2, 0 );
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 );
170 lab =
new TQLabel( i18n(
"Legend frame color:"), gb );
171 grid3->addWidget( lab, 4, 0 );
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."));
176 grid3->addWidget( legendFrameColor, 5, 0 );
180 layout->addColSpacing( 1, 300 );
183void KChartLegendConfigPage::init()
185 switch( _params->legendPosition())
187 case KDChartParams::NoLegend:
188 noLegend->setOn(
true );
190 case KDChartParams::LegendTop:
193 case KDChartParams::LegendBottom:
194 lBottom->setOn(
true );
196 case KDChartParams::LegendLeft:
197 lLeft->setOn(
true );
199 case KDChartParams::LegendRight:
200 lRight->setOn(
true );
202 case KDChartParams::LegendTopLeft:
203 lTopLeft->setOn(
true );
205 case KDChartParams::LegendTopLeftTop:
206 lTopLeftTop->setOn(
true );
208 case KDChartParams::LegendTopLeftLeft:
209 lTopLeftLeft->setOn(
true );
211 case KDChartParams::LegendTopRight:
212 lTopRight->setOn(
true );
214 case KDChartParams::LegendTopRightTop:
215 lTopRightTop->setOn(
true );
217 case KDChartParams::LegendTopRightRight:
218 lTopRightRight->setOn(
true );
220 case KDChartParams::LegendBottomRight:
221 lBottomRight->setOn(
true );
223 case KDChartParams::LegendBottomRightBottom:
224 lBottomRightBottom->setOn(
true );
226 case KDChartParams::LegendBottomRightRight:
227 lBottomRightRight->setOn(
true );
229 case KDChartParams::LegendBottomLeft:
230 lBottomLeft->setOn(
true );
232 case KDChartParams::LegendBottomLeftBottom:
233 lBottomLeftBottom->setOn(
true );
235 case KDChartParams::LegendBottomLeftLeft:
236 lBottomLeftLeft->setOn(
true );
239 lRight->setOn(
true );
243 title->setText(_params->legendTitleText());
245 legendTitleColor->setColor(_params->legendTitleTextColor());
247 legendTextColor->setColor(_params->legendTextColor());
249 TQColor frameColor(TQt::black);
252 _params->frameSettings( KDChartEnums::AreaLegend, bFound );
256 const_cast<KDFrameProfile&
>(legendFrame->
frame().
profile( KDFrame::ProfileTop )).first();
258 frameColor = top->pen().color();
260 legendFrameColor->setColor(frameColor);
262 if( _params->legendOrientation() == TQt::Vertical )
263 orientationGroup->setButton(0);
265 orientationGroup->setButton(1);
267 titleLegend = _params->legendTitleFont();
268 titleLegendIsRelative = _params->legendTitleFontUseRelSize()
271 if( TQButton::On == titleLegendIsRelative )
272 titleLegend.setPointSize( _params->legendTitleFontRelSize() );
274 textLegend=_params->legendFont();
275 textLegendIsRelative = _params->legendFontUseRelSize()
278 if( TQButton::On == textLegendIsRelative )
279 textLegend.setPointSize(_params->legendFontRelSize());
282void KChartLegendConfigPage::changeTitleLegendFont()
284 TQButton::ToggleState state = titleLegendIsRelative;
285 if ( TDEFontDialog::getFont( titleLegend,
false,
this,
true,&state ) != TQDialog::Rejected
286 && TQButton::NoChange != state )
287 titleLegendIsRelative = state;
290void KChartLegendConfigPage::changeTextLegendFont()
292 TQButton::ToggleState state = textLegendIsRelative;
293 if ( TDEFontDialog::getFont( textLegend,
false,
this,
true,&state ) != TQDialog::Rejected
294 && TQButton::NoChange != state )
295 textLegendIsRelative = state;
298void KChartLegendConfigPage::apply()
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 );
335 _params->setLegendPosition( KDChartParams::LegendRight );
337 if( orientationGroup->selectedId() == 0 )
338 _params->setLegendOrientation( TQt::Vertical );
340 _params->setLegendOrientation( TQt::Horizontal );
342 _params->setLegendTitleText(title->text());
343 _params->setLegendTitleTextColor(legendTitleColor->color());
344 _params->setLegendTextColor(legendTextColor->color());
346 const TQColor frameColor(legendFrameColor->color());
347 if( frameColor == TQt::black )
348 _params->removeFrame( KDChartEnums::AreaLegend );
350 _params->setSimpleFrame( KDChartEnums::AreaLegend,
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());
367TQPushButton* KChartLegendConfigPage::addButton( TQGridLayout* layout,
369 const TQString &toolTipText,
370 const TQString &icon,
374 TQPushButton* button =
new TQPushButton( gb );
375 button->setToggleButton(
true );
376 button->setPixmap( BarIcon( icon,
378 TDEIcon::DefaultState,
379 KChartFactory::global() ) );
380 TQToolTip::add( button, toolTipText );
381 layout->addWidget( button, posY, posX );
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.
const KDFrameProfile & profile(ProfileName name) const