kchart

kchartFontConfigPage.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
21#include "kchartFontConfigPage.h"
22
23#include "kchartFontConfigPage.moc"
24
25#include <tdeapplication.h>
26#include <tdelocale.h>
27#include <kcolorbutton.h>
28#include <kdebug.h>
29
30#include <tqlayout.h>
31#include <tqlabel.h>
32#include <tqlineedit.h>
33#include <tqlistbox.h>
34#include <tqpushbutton.h>
35#include <tqpainter.h>
36#include <tqwhatsthis.h>
37
38#include <tdefontdialog.h>
39
40// For IRIX
41namespace std {}
42
43using namespace std;
44
45#include "kchart_params.h"
46
47
48class KChartFontListBoxItem : public TQListBoxText
49{
50public:
51 KChartFontListBoxItem( TQListBox* lb, const TQString& text = TQString() ) :
52 TQListBoxText( lb, text ) {}
53 KChartFontListBoxItem( const TQString& text = TQString() ) :
54 TQListBoxText( text ) {}
55
56 void setFont( const TQFont& font ) {
57 _font = font;
58 listBox()->repaint();
59 }
60 TQFont font() const {
61 return _font;
62 }
63
64protected:
65 void paint( TQPainter* painter )
66 {
67 painter->save();
68 painter->setFont( _font );
69 TQListBoxText::paint( painter );
70 painter->restore();
71 }
72
73private:
74 TQFont _font;
75};
76
77
78// ----------------------------------------------------------------
79
80
81namespace KChart
82{
83
84KChartFontConfigPage::KChartFontConfigPage( KChartParams* params,
85 TQWidget* parent,
86 KDChartTableData *dat) :
87 TQWidget( parent ), m_params( params ), data(dat)
88{
89 TQGridLayout *grid = new TQGridLayout(this,4,3,KDialog::marginHint(), KDialog::spacingHint());
90
91 // The listbox
92 m_list = new TQListBox(this);
93 m_list->resize( m_list->sizeHint() );
94 grid->addWidget(m_list, 0, 0); // Row 0-0, col 0-1
95
96 // The font button.
97 m_fontButton = new TQPushButton( this);
98 m_fontButton->setText(i18n("Font..."));
99 TQWhatsThis::add(m_fontButton, i18n("Select an item in the list above and click on this button to display the TDE font dialog in order to choose a new font for this item."));
100 m_fontButton->resize( m_fontButton->sizeHint() );
101 grid->addWidget( m_fontButton, 1, 0);
102
103#if 0
104 // FIXME: Integrate the font chooser instead? Well, maybe later.
105 TDEFontChooser *fontChooser = new TDEFontChooser(this, "fontChooser");
106 grid->addMultiCellWidget(fontChooser, 0, 2, 1, 1);
107#endif
108
109 grid->setColStretch(2, 1);
110 grid->setRowStretch(3, 1);
111
112 connect( m_fontButton, TQ_SIGNAL(clicked()),
113 this, TQ_SLOT(changeLabelFont()));
114 connect( m_list, TQ_SIGNAL(doubleClicked ( TQListBoxItem * )),
115 this, TQ_SLOT(changeLabelFont()));
116
117 // Enter the items into the list.
118 initList();
119}
120
121
122void KChartFontConfigPage::initList()
123{
124 if ( m_params->chartType() != KChartParams::Pie
125 && m_params->chartType() != KChartParams::Ring ) {
126 m_list->insertItem(new KChartFontListBoxItem( i18n("X-Title")));
127 m_list->insertItem(new KChartFontListBoxItem( i18n("Y-Title")));
128 m_list->insertItem(new KChartFontListBoxItem( i18n("X-Axis")));
129 m_list->insertItem(new KChartFontListBoxItem( i18n("Y-Axis")));
130 m_list->insertItem(new KChartFontListBoxItem( i18n("All Axes")));
131 }
132
133 m_list->insertItem(i18n("Label"));
134 m_list->setCurrentItem(0);
135}
136
137
138
139void KChartFontConfigPage::changeLabelFont()
140{
141 TQFont *font = 0;
142 TQButton::ToggleState *state = 0;
143 bool diffAxes = false;
144
145 if (m_list->currentText()==i18n("X-Title")) {
146 font = &xTitle;
147 state = &xTitleIsRelative;
148 } else if(m_list->currentText()==i18n("Y-Title")) {
149 font = &yTitle;
150 state = &yTitleIsRelative;
151 } else if(m_list->currentText()==i18n("X-Axis")) {
152 font = &xAxis;
153 state = &xAxisIsRelative;
154 } else if(m_list->currentText()==i18n("Y-Axis")) {
155 font = &yAxis;
156 state = &yAxisIsRelative;
157 } else if(m_list->currentText()==i18n("All Axes")) {
158 diffAxes = true;
159 } else if(m_list->currentText()==i18n("Label")) {
160 font = &label;
161 state = &labelIsRelative;
162 }
163 else
164 kdDebug( 35001 ) << "Pb in listBox" << endl;
165
166 if ( diffAxes ) {
167 TQFont newFont;
168 int flags = 0;
169 TQButton::ToggleState newState
170 = (xAxisIsRelative == yAxisIsRelative)
171 ? (xAxisIsRelative ? TQButton::On : TQButton::Off)
172 : TQButton::NoChange;
173 if (TDEFontDialog::getFontDiff( newFont,
174 flags,
175 false,
176 this,
177 true,
178 &newState ) != TQDialog::Rejected) {
179 if ( TDEFontChooser::FamilyList & flags ) {
180 xAxis.setFamily( newFont.family() );
181 yAxis.setFamily( newFont.family() );
182 }
183
184 if ( TDEFontChooser::StyleList & flags ) {
185 xAxis.setWeight( newFont.weight() );
186 xAxis.setItalic( newFont.italic() );
187 xAxis.setUnderline( newFont.underline() );
188 xAxis.setStrikeOut( newFont.strikeOut() );
189
190 yAxis.setWeight( newFont.weight() );
191 yAxis.setItalic( newFont.italic() );
192 yAxis.setUnderline( newFont.underline() );
193 yAxis.setStrikeOut( newFont.strikeOut() );
194 }
195
196 if ( TDEFontChooser::SizeList & flags ) {
197 xAxis.setPointSize( newFont.pointSize() );
198 yAxis.setPointSize( newFont.pointSize() );
199 }
200
201 // CharSet settings are ignored since we are not TQt 2.x compatible
202 // if( TDEFontChooser::CharsetList & flags ) {
203 // }
204
205 if ( TQButton::NoChange != newState ) {
206 xAxisIsRelative = newState;
207 yAxisIsRelative = newState;
208 }
209 }
210 }
211 else if ( font && state ) {
212 TQFont newFont( *font );
213 TQButton::ToggleState newState = *state;
214 if (TDEFontDialog::getFont( newFont,
215 false,
216 this,
217 true,
218 &newState ) != TQDialog::Rejected) {
219 *font = newFont;
220 if ( TQButton::NoChange != newState )
221 *state = newState;
222 }
223 }
224}
225
226
227void KChartFontConfigPage::init()
228{
229 KDChartAxisParams leftparms;
230 leftparms = m_params->axisParams( KDChartAxisParams::AxisPosLeft );
231 KDChartAxisParams rightparms;
232 rightparms = m_params->axisParams( KDChartAxisParams::AxisPosRight );
233 KDChartAxisParams bottomparms;
234 bottomparms = m_params->axisParams( KDChartAxisParams::AxisPosBottom );
235
236 xAxis = bottomparms.axisLabelsFont();
237 xAxisIsRelative = bottomparms.axisLabelsFontUseRelSize()
238 ? TQButton::On : TQButton::Off;
239
240 if ( TQButton::On == xAxisIsRelative )
241 xAxis.setPointSize( bottomparms.axisLabelsFontRelSize() );
242
243 yAxis = leftparms.axisLabelsFont();
244 yAxisIsRelative = leftparms.axisLabelsFontUseRelSize()
245 ? TQButton::On : TQButton::Off;
246
247 if ( TQButton::On == yAxisIsRelative )
248 yAxis.setPointSize( leftparms.axisLabelsFontRelSize() );
249 // PENDING(khz) Add support for the other 6 possible axes
250
251 // PENDING(khz) Add support for the other 16 possible hd/ft areas
252
253
254 xTitle = m_params->axisTitleFont( KDChartAxisParams::AxisPosBottom );
255 yTitle = m_params->axisTitleFont( KDChartAxisParams::AxisPosLeft );
256 xTitle.setPointSize( m_params->axisTitleFontRelSize( KDChartAxisParams::AxisPosBottom ) );
257 yTitle.setPointSize( m_params->axisTitleFontRelSize( KDChartAxisParams::AxisPosLeft ) );
258// label = _params->labelFont();
259
260 // PENDING(kalle) Adapt
261// for(int i=0;i<12;i++)
262// extColor.setColor(i,_params->ExtColor.color(i));
263// index = 0;
264// colorButton->setColor(extColor.color(index));
265}
266
267
268void KChartFontConfigPage::apply()
269{
270 // PENDING(kalle) Adapt
271 KDChartAxisParams leftparms;
272 leftparms = m_params->axisParams( KDChartAxisParams::AxisPosLeft );
273 KDChartAxisParams rightparms;
274 rightparms = m_params->axisParams( KDChartAxisParams::AxisPosRight );
275 KDChartAxisParams bottomparms;
276 bottomparms = m_params->axisParams( KDChartAxisParams::AxisPosBottom );
277
278 leftparms.setAxisLabelsFont( yAxis, TQButton::Off == yAxisIsRelative );
279 if ( TQButton::On == yAxisIsRelative )
280 leftparms.setAxisLabelsFontRelSize( yAxis.pointSize() );
281
282 // PENDING(khz) change right axis handling
283 // use left axis settings for the right axis as well
284 // (this must be changed, khz 14.12.2001)
285 rightparms.setAxisLabelsFont( yAxis, TQButton::Off == yAxisIsRelative );
286 if ( TQButton::On == yAxisIsRelative )
287 rightparms.setAxisLabelsFontRelSize( yAxis.pointSize() );
288
289 bottomparms.setAxisLabelsFont( xAxis, TQButton::Off == xAxisIsRelative );
290 if ( TQButton::On == xAxisIsRelative )
291 bottomparms.setAxisLabelsFontRelSize( xAxis.pointSize() );
292 // PENDING(khz) Add support for the other 6 possible axes
293
294 m_params->setAxisParams( KDChartAxisParams::AxisPosLeft, leftparms );
295 m_params->setAxisParams( KDChartAxisParams::AxisPosRight, rightparms );
296 m_params->setAxisParams( KDChartAxisParams::AxisPosBottom, bottomparms );
297 // PENDING(khz) change hd2 and ft handling
298 // use header settings for header 2 and footer as well
299 // (this must be changed, khz 14.12.2001)
300 // PENDING(khz) Add support for the other 16 possible hd/ft areas
301
302 m_params->setAxisTitleFont( KDChartAxisParams::AxisPosLeft, yTitle );
303 m_params->setAxisTitleFont( KDChartAxisParams::AxisPosBottom, xTitle );
304 m_params->setAxisTitleFontRelSize( KDChartAxisParams::AxisPosLeft, yTitle.pointSize() );
305 m_params->setAxisTitleFontRelSize( KDChartAxisParams::AxisPosBottom, xTitle.pointSize() );
306}
307
308} //KChart namespace
access the chart axis parameters.
void setAxisLabelsFont(TQFont axisLabelsFont, bool useFontSize)
Specifies the axis labels font.
TQFont axisLabelsFont() const
Returns the axis labels font.
int axisLabelsFontRelSize() const
Returns the axis labels relative font size.
bool axisLabelsFontUseRelSize() const
Returns whether the fix axis font size is used.
void setAxisLabelsFontRelSize(int axisLabelsFontRelSize)
Specifies the axis labels relative font size.