kchart

kchartHeaderFooterConfigPage.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#include "kchartHeaderFooterConfigPage.h"
21#include "kchartHeaderFooterConfigPage.moc"
22
23#include <tdeapplication.h>
24#include <kdialog.h>
25#include <tdelocale.h>
26#include <tqlayout.h>
27#include <tqlabel.h>
28#include <tqlineedit.h>
29#include <tqbuttongroup.h>
30#include <tqwhatsthis.h>
31#include <tdefontdialog.h>
32
33#include "kchart_params.h"
34
35namespace KChart
36{
37
38KChartHeaderFooterConfigPage::KChartHeaderFooterConfigPage( KChartParams* params,
39 TQWidget* parent ) :
40 TQWidget( parent ),_params( params )
41{
42 TQGridLayout* layout = new TQGridLayout( this, 4, 3 );
43 layout->setSpacing( KDialog::spacingHint() );
44 layout->setMargin( KDialog::marginHint() );
45
46 TQLabel *lab=new TQLabel(i18n("Title:"), this);
47 TQWhatsThis::add(lab, i18n("Write here the title of your chart if you want one. The title will be centered on top above your chart."));
48 layout->addWidget(lab,0,0);
49
50 titleEdit=new TQLineEdit(this);
51 TQWhatsThis::add(titleEdit, i18n("Write here the title of your chart if you want one. The title will be centered on top above your chart."));
52 layout->addWidget(titleEdit,0,1);
53
54 titleColorButton=new KColorButton(this);
55 TQWhatsThis::add(titleColorButton, i18n("Click on this button to choose the color for the title font."));
56 layout->addWidget(titleColorButton,0,2);
57
58 titleFontButton=new TQPushButton(i18n("Font..."),this);
59 TQWhatsThis::add(titleFontButton, i18n("Click on this button to choose the font family, style and size for the title."));
60 layout->addWidget(titleFontButton,0,3);
61 connect( titleFontButton, TQ_SIGNAL(clicked()), this, TQ_SLOT(changeTitleFont()));
62
63 lab=new TQLabel(i18n("Subtitle:"),this);
64 TQWhatsThis::add(lab, i18n("Write here the subtitle of your chart if you want one. The subtitle will be centered on top just below the title."));
65 layout->addWidget(lab,1,0);
66
67 subtitleEdit=new TQLineEdit(this);
68 TQWhatsThis::add(subtitleEdit, i18n("Write here the subtitle of your chart if you want one. The subtitle will be centered on top just below the title."));
69 layout->addWidget(subtitleEdit,1,1);
70
71 subtitleColorButton=new KColorButton(this);
72 TQWhatsThis::add(subtitleColorButton, i18n("Click on this button to choose the color for the subtitle font."));
73 layout->addWidget(subtitleColorButton,1,2);
74
75 subtitleFontButton=new TQPushButton(i18n("Font..."),this);
76 TQWhatsThis::add(subtitleFontButton, i18n("Click on this button to choose the font family, style and size for the subtitle."));
77 layout->addWidget(subtitleFontButton,1,3);
78 connect( subtitleFontButton, TQ_SIGNAL(clicked()), this, TQ_SLOT(changeSubtitleFont()));
79
80 lab=new TQLabel(i18n("Footer:"),this);
81 TQWhatsThis::add(lab, i18n("Write here the footer of your chart if you want one. The footer will be centered at the bottom just below your chart."));
82 layout->addWidget(lab,2,0);
83
84 footerEdit=new TQLineEdit(this);
85 TQWhatsThis::add(footerEdit, i18n("Write here the subtitle of your chart if you want one. The subtitle will be centered on top just below the title."));
86 layout->addWidget(footerEdit,2,1);
87
88 footerColorButton=new KColorButton(this);
89 TQWhatsThis::add(footerColorButton, i18n("Click on this button to choose the color for the footer font."));
90 layout->addWidget(footerColorButton,2,2);
91
92 footerFontButton=new TQPushButton(i18n("Font..."),this);
93 TQWhatsThis::add(footerFontButton, i18n("Click on this button to choose the font family, style and size for the footer."));
94 connect( footerFontButton, TQ_SIGNAL(clicked()), this, TQ_SLOT(changeFooterFont()));
95 layout->addWidget(footerFontButton,2,3);
96
97 layout->addItem( new TQSpacerItem( 5, 5, TQSizePolicy::Minimum, TQSizePolicy::Expanding ), 3, 0 );
98
99 layout->activate();
100}
101
102void KChartHeaderFooterConfigPage::init()
103{
104 titleColorButton->setColor(_params->headerFooterColor( KDChartParams::HdFtPosHeader ) );
105 subtitleColorButton->setColor(_params->headerFooterColor( KDChartParams::HdFtPosHeader2 ));
106 footerColorButton->setColor(_params->headerFooterColor( KDChartParams::HdFtPosFooter ) );
107 titleEdit->setText(_params->header1Text());
108 subtitleEdit->setText(_params->header2Text());
109 footerEdit->setText(_params->footerText());
110
111
112 titleFont = _params->header1Font();
113 titleFontIsRelative = _params->headerFooterFontUseRelSize(KDChartParams::HdFtPosHeader)
114 ? TQButton::On
115 : TQButton::Off;
116 if( TQButton::On == titleFontIsRelative )
117 titleFont.setPointSize( _params->headerFooterFontRelSize(KDChartParams::HdFtPosHeader) );
118
119 subtitleFont = _params->header2Font();
120 subtitleFontIsRelative = _params->headerFooterFontUseRelSize(KDChartParams::HdFtPosHeader2)
121 ? TQButton::On
122 : TQButton::Off;
123 if( TQButton::On == subtitleFontIsRelative )
124 subtitleFont.setPointSize( _params->headerFooterFontRelSize(KDChartParams::HdFtPosHeader2) );
125
126 footerFont = _params->footerFont();
127 footerFontIsRelative = _params->headerFooterFontUseRelSize(KDChartParams::HdFtPosFooter)
128 ? TQButton::On
129 : TQButton::Off;
130 if( TQButton::On == footerFontIsRelative )
131 footerFont.setPointSize( _params->headerFooterFontRelSize(KDChartParams::HdFtPosFooter) );
132}
133
134
135void KChartHeaderFooterConfigPage::apply()
136{
137 _params->setHeaderFooterColor( KDChartParams::HdFtPosHeader,titleColorButton->color() );
138 _params->setHeaderFooterColor( KDChartParams::HdFtPosHeader2,subtitleColorButton->color() );
139 _params->setHeaderFooterColor( KDChartParams::HdFtPosFooter, footerColorButton->color() );
140
141
142 _params->setHeader1Text(titleEdit->text());
143 _params->setHeader2Text(subtitleEdit->text());
144 _params->setFooterText(footerEdit->text());
145
146
147 _params->setHeaderFooterFont( KDChartParams::HdFtPosHeader, titleFont,
148 titleFontIsRelative,
149 titleFont.pointSize() );
150 _params->setHeaderFooterFont( KDChartParams::HdFtPosHeader2, subtitleFont,
151 subtitleFontIsRelative,
152 subtitleFont.pointSize() );
153 _params->setHeaderFooterFont( KDChartParams::HdFtPosFooter, footerFont,
154 footerFontIsRelative,
155 footerFont.pointSize() );
156}
157
158void KChartHeaderFooterConfigPage::changeTitleFont()
159{
160 TQButton::ToggleState state = titleFontIsRelative;
161 if ( TDEFontDialog::getFont( titleFont,false,this, true,&state ) != TQDialog::Rejected
162 && TQButton::NoChange != state )
163 titleFontIsRelative = state;
164}
165
166void KChartHeaderFooterConfigPage::changeSubtitleFont()
167{
168 TQButton::ToggleState state = subtitleFontIsRelative;
169 if ( TDEFontDialog::getFont( subtitleFont,false,this, true,&state ) != TQDialog::Rejected
170 && TQButton::NoChange != state )
171 subtitleFontIsRelative = state;
172}
173
174void KChartHeaderFooterConfigPage::changeFooterFont()
175{
176 TQButton::ToggleState state = footerFontIsRelative;
177 if ( TDEFontDialog::getFont( footerFont,false,this, true,&state ) != TQDialog::Rejected
178 && TQButton::NoChange != state )
179 footerFontIsRelative = state;
180}
181
182} //KChart namespace