00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kchartLegendConfigPage.h"
00021 #include "kchartLegendConfigPage.moc"
00022
00023 #include <kapplication.h>
00024 #include <klocale.h>
00025 #include <kcolorbutton.h>
00026 #include <kfontdialog.h>
00027 #include <kiconloader.h>
00028
00029 #include <qlabel.h>
00030 #include <qbuttongroup.h>
00031 #include <qradiobutton.h>
00032 #include <qlineedit.h>
00033 #include <qtooltip.h>
00034 #include <qwhatsthis.h>
00035
00036 #include "kchart_params.h"
00037 #include "kchart_factory.h"
00038
00039 namespace KChart
00040 {
00041
00042
00043 KChartLegendConfigPage::KChartLegendConfigPage( KChartParams* params,
00044 QWidget* parent ) :
00045 QWidget( parent ),_params( params )
00046 {
00047
00048 QGridLayout* layout = new QGridLayout( this, 2, 2, KDialog::marginHint(), KDialog::spacingHint() );
00049
00050
00051 QButtonGroup* gb = new QButtonGroup( 0, Qt::Vertical, i18n("General"), this );
00052 gb->layout()->setSpacing(KDialog::spacingHint());
00053 gb->layout()->setMargin(KDialog::marginHint());
00054 layout->addWidget( gb, 0, 0 );
00055
00056 QGridLayout *grid2 = new QGridLayout( gb->layout(), 4, 2 );
00057
00058 QLabel* lab = new QLabel( i18n("Title:"), gb );
00059 QWhatsThis::add(lab, i18n("Write here the title of the legend, which is displayed at the top of the legend box."));
00060 grid2->addWidget( lab, 0, 0 );
00061
00062 title = new QLineEdit( gb );
00063 grid2->addWidget( title, 1, 0 );
00064
00065
00066 gb = new QButtonGroup( 0, Qt::Vertical, i18n("Legend Position"), this );
00067 QWhatsThis::add(gb, i18n("<qt>Choose the location of the legend on the chart by clicking a location button.\nUse the central button to <b>hide</b> the legend.</qt>"));
00068 gb->layout()->setSpacing(KDialog::spacingHint());
00069 gb->layout()->setMargin(KDialog::marginHint());
00070 gb->setExclusive( true );
00071
00072 QGridLayout *grid1 = new QGridLayout( gb->layout(), 3, 3 );
00073
00074 lTopLeft = addButton( grid1, gb, i18n("Top-Left"), "chart_legend_topleft", 0, 0 );
00075 lTop = addButton( grid1, gb, i18n("Top"), "chart_legend_top", 0, 1 );
00076 lTopRight = addButton( grid1, gb, i18n("Top-Right"), "chart_legend_topright", 0, 2 );
00077
00078 lLeft = addButton( grid1, gb, i18n("Left"), "chart_legend_left", 1, 0 );
00079 noLegend = addButton( grid1, gb, i18n("No Legend"), "chart_legend_nolegend", 1, 1 );
00080 lRight = addButton( grid1, gb, i18n("Right"), "chart_legend_right", 1, 2 );
00081
00082 lBottomLeft = addButton( grid1, gb, i18n("Bottom-Left"), "chart_legend_bottomleft", 2, 0 );
00083 lBottom = addButton( grid1, gb, i18n("Bottom"), "chart_legend_bottom", 2, 1 );
00084 lBottomRight = addButton( grid1, gb, i18n("Bottom-Right"), "chart_legend_bottomright", 2, 2 );
00085
00086 gb->setAlignment( Qt::AlignLeft );
00087 layout->addWidget( gb, 1, 0 );
00088
00089
00090 gb = new QButtonGroup( 0, Qt::Vertical, i18n("Font"), this );
00091 QWhatsThis::add(gb, i18n("This Font box can be used to set different fonts for the legend title and the individual entries."));
00092 gb->layout()->setSpacing(KDialog::spacingHint());
00093 gb->layout()->setMargin(KDialog::marginHint());
00094 layout->addWidget( gb, 0, 1 );
00095
00096 QGridLayout *grid4 = new QGridLayout( gb->layout(), 4, 2 );
00097 titleLegendFontButton = new QPushButton( gb );
00098
00099 lab = new QLabel( i18n("Legend title font:"), gb );
00100 grid4->addWidget( lab, 0 ,0 );
00101
00102 titleLegendFontButton->setText( i18n("Select Font...") );
00103 QWhatsThis::add(titleLegendFontButton, i18n("Click here to display the KDE font chooser dialog. You will be able to change the font family, style and size for the legend title."));
00104 grid4->addWidget( titleLegendFontButton, 1, 0 );
00105
00106 lab = new QLabel( i18n("Legend text font:"), gb );
00107 grid4->addWidget( lab, 2, 0 );
00108 textLegendFontButton = new QPushButton( gb );
00109 textLegendFontButton->setText( i18n("Select Font...") );
00110 QWhatsThis::add(textLegendFontButton, i18n("Click here to display the KDE font chooser dialog. You will be able to change the font family, style and size for the legend text."));
00111 grid4->addWidget( textLegendFontButton, 3, 0 );
00112
00113 connect( titleLegendFontButton, SIGNAL(clicked()),
00114 this, SLOT(changeTitleLegendFont()));
00115 connect( textLegendFontButton, SIGNAL(clicked()),
00116 this, SLOT(changeTextLegendFont()));
00117
00118
00119 gb = new QButtonGroup( 0, Qt::Vertical, i18n("Color"), this );
00120 QWhatsThis::add(gb, i18n("This Color box can be used to set different colors for the legend title and text."));
00121 gb->layout()->setSpacing(KDialog::spacingHint());
00122 gb->layout()->setMargin(KDialog::marginHint());
00123 layout->addWidget( gb, 1, 1 );
00124
00125 QGridLayout *grid3 = new QGridLayout( gb->layout(), 4, 2 );
00126
00127 lab = new QLabel( i18n("Legend title color:"), gb );
00128 grid3->addWidget( lab, 0, 0 );
00129
00130 legendTitleColor = new KColorButton( gb );
00131 QWhatsThis::add(legendTitleColor, i18n("Click here to display the KDE Select Color dialog. You will be able to change the color for the legend title."));
00132 grid3->addWidget( legendTitleColor, 1, 0 );
00133
00134
00135 lab = new QLabel( i18n("Legend text color:"), gb );
00136 grid3->addWidget( lab, 2, 0 );
00137
00138 legendTextColor = new KColorButton( gb );
00139 QWhatsThis::add(legendTextColor, i18n("Click here to display the KDE Select Color dialog. You will be able to change the color for the legend text."));
00140
00141 grid3->addWidget( legendTextColor, 3, 0 );
00142
00143
00144
00145 layout->addColSpacing( 1, 300 );
00146 }
00147
00148 void KChartLegendConfigPage::init()
00149 {
00150 switch( _params->legendPosition())
00151 {
00152 case KDChartParams::NoLegend:
00153 noLegend->setOn( true );
00154 break;
00155 case KDChartParams::LegendTop:
00156 lTop->setOn( true );
00157 break;
00158 case KDChartParams::LegendBottom:
00159 lBottom->setOn( true );
00160 break;
00161 case KDChartParams::LegendLeft:
00162 lLeft->setOn( true );
00163 break;
00164 case KDChartParams::LegendRight:
00165 lRight->setOn( true );
00166 break;
00167 case KDChartParams::LegendTopLeft:
00168 lTopLeft->setOn( true );
00169 break;
00170 case KDChartParams::LegendTopRight:
00171 lTopRight->setOn( true );
00172 break;
00173 case KDChartParams::LegendBottomRight:
00174 lBottomRight->setOn( true );
00175 break;
00176 case KDChartParams::LegendBottomLeft:
00177 lBottomLeft->setOn( true );
00178 break;
00179 default:
00180 lRight->setOn( true );
00181 break;
00182 }
00183 title->setText(_params->legendTitleText());
00184 legendTitleColor->setColor(_params->legendTitleTextColor());
00185 legendTextColor->setColor(_params->legendTextColor());
00186
00187 titleLegend = _params->legendTitleFont();
00188 titleLegendIsRelative = _params->legendTitleFontUseRelSize()
00189 ? QButton::On
00190 : QButton::Off;
00191 if( QButton::On == titleLegendIsRelative )
00192 titleLegend.setPointSize( _params->legendTitleFontRelSize() );
00193
00194 textLegend=_params->legendFont();
00195 textLegendIsRelative = _params->legendFontUseRelSize()
00196 ? QButton::On
00197 : QButton::Off;
00198 if( QButton::On == textLegendIsRelative )
00199 textLegend.setPointSize(_params->legendFontRelSize());
00200 }
00201
00202 void KChartLegendConfigPage::changeTitleLegendFont()
00203 {
00204 QButton::ToggleState state = titleLegendIsRelative;
00205 if ( KFontDialog::getFont( titleLegend,false,this, true,&state ) != QDialog::Rejected
00206 && QButton::NoChange != state )
00207 titleLegendIsRelative = state;
00208 }
00209
00210 void KChartLegendConfigPage::changeTextLegendFont()
00211 {
00212 QButton::ToggleState state = textLegendIsRelative;
00213 if ( KFontDialog::getFont( textLegend,false,this, true,&state ) != QDialog::Rejected
00214 && QButton::NoChange != state )
00215 textLegendIsRelative = state;
00216 }
00217
00218 void KChartLegendConfigPage::apply()
00219 {
00220 if( noLegend->isOn() )
00221 _params->setLegendPosition( KDChartParams::NoLegend );
00222 else if( lTop->isOn() )
00223 _params->setLegendPosition( KDChartParams::LegendTop );
00224 else if( lBottom->isOn() )
00225 _params->setLegendPosition( KDChartParams::LegendBottom );
00226 else if( lLeft->isOn() )
00227 _params->setLegendPosition( KDChartParams::LegendLeft );
00228 else if( lRight->isOn() )
00229 _params->setLegendPosition( KDChartParams::LegendRight );
00230 else if( lTopLeft->isOn() )
00231 _params->setLegendPosition( KDChartParams::LegendTopLeft );
00232 else if( lTopRight->isOn() )
00233 _params->setLegendPosition( KDChartParams::LegendTopRight );
00234 else if( lBottomRight->isOn() )
00235 _params->setLegendPosition( KDChartParams::LegendBottomRight );
00236 else if( lBottomLeft->isOn() )
00237 _params->setLegendPosition( KDChartParams::LegendBottomLeft );
00238 else
00239 _params->setLegendPosition( KDChartParams::LegendRight );
00240
00241 _params->setLegendTitleText(title->text());
00242 _params->setLegendTitleTextColor(legendTitleColor->color());
00243 _params->setLegendTextColor(legendTextColor->color());
00244
00245 _params->setLegendTitleFont(titleLegend, QButton::Off == titleLegendIsRelative);
00246 if( QButton::On == titleLegendIsRelative )
00247 _params->setLegendTitleFontRelSize(titleLegend.pointSize());
00248 _params->setLegendFont(textLegend, QButton::Off == textLegendIsRelative);
00249 if( QButton::On == textLegendIsRelative )
00250 _params->setLegendFontRelSize(textLegend.pointSize());
00251 }
00252
00253 QPushButton* KChartLegendConfigPage::addButton( QGridLayout* layout,
00254 QButtonGroup* gb,
00255 const QString &toolTipText,
00256 const QString &icon,
00257 int posY,
00258 int posX )
00259 {
00260 QPushButton* button = new QPushButton( gb );
00261 button->setToggleButton( true );
00262 button->setPixmap( BarIcon( icon,
00263 KIcon::SizeMedium,
00264 KIcon::DefaultState,
00265 KChartFactory::global() ) );
00266 QToolTip::add( button, toolTipText );
00267 layout->addWidget( button, posY, posX );
00268 return button;
00269 }
00270
00271 }