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