00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kchartFontConfigPage.h"
00022
00023 #include "kchartFontConfigPage.moc"
00024
00025 #include <kapplication.h>
00026 #include <klocale.h>
00027 #include <kcolorbutton.h>
00028 #include <kdebug.h>
00029
00030 #include <qlayout.h>
00031 #include <qlabel.h>
00032 #include <qlineedit.h>
00033 #include <qlistbox.h>
00034 #include <qpushbutton.h>
00035 #include <qpainter.h>
00036 #include <qwhatsthis.h>
00037
00038 #include <kfontdialog.h>
00039
00040
00041 namespace std {}
00042
00043 using namespace std;
00044
00045 #include "kchart_params.h"
00046
00047
00048 class KChartFontListBoxItem : public QListBoxText
00049 {
00050 public:
00051 KChartFontListBoxItem( QListBox* lb, const QString& text = QString::null ) :
00052 QListBoxText( lb, text ) {}
00053 KChartFontListBoxItem( const QString& text = QString::null ) :
00054 QListBoxText( text ) {}
00055
00056 void setFont( const QFont& font ) {
00057 _font = font;
00058 listBox()->repaint();
00059 }
00060 QFont font() const {
00061 return _font;
00062 }
00063
00064 protected:
00065 void paint( QPainter* painter )
00066 {
00067 painter->save();
00068 painter->setFont( _font );
00069 QListBoxText::paint( painter );
00070 painter->restore();
00071 }
00072
00073 private:
00074 QFont _font;
00075 };
00076
00077
00078
00079
00080
00081 namespace KChart
00082 {
00083
00084 KChartFontConfigPage::KChartFontConfigPage( KChartParams* params,
00085 QWidget* parent,
00086 KDChartTableData *dat) :
00087 QWidget( parent ), m_params( params ), data(dat)
00088 {
00089 QGridLayout *grid = new QGridLayout(this,4,3,KDialog::marginHint(), KDialog::spacingHint());
00090
00091
00092 m_list = new QListBox(this);
00093 m_list->resize( m_list->sizeHint() );
00094 grid->addWidget(m_list, 0, 0);
00095
00096
00097 m_fontButton = new QPushButton( this);
00098 m_fontButton->setText(i18n("Font..."));
00099 QWhatsThis::add(m_fontButton, i18n("Select an item in the list above and click on this button to display the KDE font dialog in order to choose a new font for this item."));
00100 m_fontButton->resize( m_fontButton->sizeHint() );
00101 grid->addWidget( m_fontButton, 1, 0);
00102
00103 #if 0
00104
00105 KFontChooser *fontChooser = new KFontChooser(this, "fontChooser");
00106 grid->addMultiCellWidget(fontChooser, 0, 2, 1, 1);
00107 #endif
00108
00109 grid->setColStretch(2, 1);
00110 grid->setRowStretch(3, 1);
00111
00112 connect( m_fontButton, SIGNAL(clicked()),
00113 this, SLOT(changeLabelFont()));
00114 connect( m_list, SIGNAL(doubleClicked ( QListBoxItem * )),
00115 this, SLOT(changeLabelFont()));
00116
00117
00118 initList();
00119 }
00120
00121
00122 void KChartFontConfigPage::initList()
00123 {
00124 if ( m_params->chartType() != KChartParams::Pie
00125 && m_params->chartType() != KChartParams::Ring ) {
00126 m_list->insertItem(new KChartFontListBoxItem( i18n("X-Title")));
00127 m_list->insertItem(new KChartFontListBoxItem( i18n("Y-Title")));
00128 m_list->insertItem(new KChartFontListBoxItem( i18n("X-Axis")));
00129 m_list->insertItem(new KChartFontListBoxItem( i18n("Y-Axis")));
00130 m_list->insertItem(new KChartFontListBoxItem( i18n("All Axes")));
00131 }
00132
00133 m_list->insertItem(i18n("Label"));
00134 m_list->setCurrentItem(0);
00135 }
00136
00137
00138
00139 void KChartFontConfigPage::changeLabelFont()
00140 {
00141 QFont *font = 0;
00142 QButton::ToggleState *state = 0;
00143 bool diffAxes = false;
00144
00145 if (m_list->currentText()==i18n("X-Title")) {
00146 font = &xTitle;
00147 state = &xTitleIsRelative;
00148 } else if(m_list->currentText()==i18n("Y-Title")) {
00149 font = &yTitle;
00150 state = &yTitleIsRelative;
00151 } else if(m_list->currentText()==i18n("X-Axis")) {
00152 font = &xAxis;
00153 state = &xAxisIsRelative;
00154 } else if(m_list->currentText()==i18n("Y-Axis")) {
00155 font = &yAxis;
00156 state = &yAxisIsRelative;
00157 } else if(m_list->currentText()==i18n("All Axes")) {
00158 diffAxes = true;
00159 } else if(m_list->currentText()==i18n("Label")) {
00160 font = &label;
00161 state = &labelIsRelative;
00162 }
00163 else
00164 kdDebug( 35001 ) << "Pb in listBox" << endl;
00165
00166 if ( diffAxes ) {
00167 QFont newFont;
00168 int flags = 0;
00169 QButton::ToggleState newState
00170 = (xAxisIsRelative == yAxisIsRelative)
00171 ? (xAxisIsRelative ? QButton::On : QButton::Off)
00172 : QButton::NoChange;
00173 if (KFontDialog::getFontDiff( newFont,
00174 flags,
00175 false,
00176 this,
00177 true,
00178 &newState ) != QDialog::Rejected) {
00179 if ( KFontChooser::FamilyList & flags ) {
00180 xAxis.setFamily( newFont.family() );
00181 yAxis.setFamily( newFont.family() );
00182 }
00183
00184 if ( KFontChooser::StyleList & flags ) {
00185 xAxis.setWeight( newFont.weight() );
00186 xAxis.setItalic( newFont.italic() );
00187 xAxis.setUnderline( newFont.underline() );
00188 xAxis.setStrikeOut( newFont.strikeOut() );
00189
00190 yAxis.setWeight( newFont.weight() );
00191 yAxis.setItalic( newFont.italic() );
00192 yAxis.setUnderline( newFont.underline() );
00193 yAxis.setStrikeOut( newFont.strikeOut() );
00194 }
00195
00196 if ( KFontChooser::SizeList & flags ) {
00197 xAxis.setPointSize( newFont.pointSize() );
00198 yAxis.setPointSize( newFont.pointSize() );
00199 }
00200
00201
00202
00203
00204
00205 if ( QButton::NoChange != newState ) {
00206 xAxisIsRelative = newState;
00207 yAxisIsRelative = newState;
00208 }
00209 }
00210 }
00211 else if ( font && state ) {
00212 QFont newFont( *font );
00213 QButton::ToggleState newState = *state;
00214 if (KFontDialog::getFont( newFont,
00215 false,
00216 this,
00217 true,
00218 &newState ) != QDialog::Rejected) {
00219 *font = newFont;
00220 if ( QButton::NoChange != newState )
00221 *state = newState;
00222 }
00223 }
00224 }
00225
00226
00227 void KChartFontConfigPage::init()
00228 {
00229 KDChartAxisParams leftparms;
00230 leftparms = m_params->axisParams( KDChartAxisParams::AxisPosLeft );
00231 KDChartAxisParams rightparms;
00232 rightparms = m_params->axisParams( KDChartAxisParams::AxisPosRight );
00233 KDChartAxisParams bottomparms;
00234 bottomparms = m_params->axisParams( KDChartAxisParams::AxisPosBottom );
00235
00236 xAxis = bottomparms.axisLabelsFont();
00237 xAxisIsRelative = bottomparms.axisLabelsFontUseRelSize()
00238 ? QButton::On : QButton::Off;
00239
00240 if ( QButton::On == xAxisIsRelative )
00241 xAxis.setPointSize( bottomparms.axisLabelsFontRelSize() );
00242
00243 yAxis = leftparms.axisLabelsFont();
00244 yAxisIsRelative = leftparms.axisLabelsFontUseRelSize()
00245 ? QButton::On : QButton::Off;
00246
00247 if ( QButton::On == yAxisIsRelative )
00248 yAxis.setPointSize( leftparms.axisLabelsFontRelSize() );
00249
00250
00251
00252
00253
00254 xTitle = m_params->axisTitleFont( KDChartAxisParams::AxisPosBottom );
00255 yTitle = m_params->axisTitleFont( KDChartAxisParams::AxisPosLeft );
00256 xTitle.setPointSize( m_params->axisTitleFontRelSize( KDChartAxisParams::AxisPosBottom ) );
00257 yTitle.setPointSize( m_params->axisTitleFontRelSize( KDChartAxisParams::AxisPosLeft ) );
00258
00259
00260
00261
00262
00263
00264
00265 }
00266
00267
00268 void KChartFontConfigPage::apply()
00269 {
00270
00271 KDChartAxisParams leftparms;
00272 leftparms = m_params->axisParams( KDChartAxisParams::AxisPosLeft );
00273 KDChartAxisParams rightparms;
00274 rightparms = m_params->axisParams( KDChartAxisParams::AxisPosRight );
00275 KDChartAxisParams bottomparms;
00276 bottomparms = m_params->axisParams( KDChartAxisParams::AxisPosBottom );
00277
00278 leftparms.setAxisLabelsFont( yAxis, QButton::Off == yAxisIsRelative );
00279 if ( QButton::On == yAxisIsRelative )
00280 leftparms.setAxisLabelsFontRelSize( yAxis.pointSize() );
00281
00282
00283
00284
00285 rightparms.setAxisLabelsFont( yAxis, QButton::Off == yAxisIsRelative );
00286 if ( QButton::On == yAxisIsRelative )
00287 rightparms.setAxisLabelsFontRelSize( yAxis.pointSize() );
00288
00289 bottomparms.setAxisLabelsFont( xAxis, QButton::Off == xAxisIsRelative );
00290 if ( QButton::On == xAxisIsRelative )
00291 bottomparms.setAxisLabelsFontRelSize( xAxis.pointSize() );
00292
00293
00294 m_params->setAxisParams( KDChartAxisParams::AxisPosLeft, leftparms );
00295 m_params->setAxisParams( KDChartAxisParams::AxisPosRight, rightparms );
00296 m_params->setAxisParams( KDChartAxisParams::AxisPosBottom, bottomparms );
00297
00298
00299
00300
00301
00302 m_params->setAxisTitleFont( KDChartAxisParams::AxisPosLeft, yTitle );
00303 m_params->setAxisTitleFont( KDChartAxisParams::AxisPosBottom, xTitle );
00304 m_params->setAxisTitleFontRelSize( KDChartAxisParams::AxisPosLeft, yTitle.pointSize() );
00305 m_params->setAxisTitleFontRelSize( KDChartAxisParams::AxisPosBottom, xTitle.pointSize() );
00306 }
00307
00308 }