1 | |
2 | /* |
3 | * This file is part of the KDE Help Center |
4 | * |
5 | * Copyright (C) 2003 Frerich Raabe <raabe@kde.org> |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. |
11 | * |
12 | * This program is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU General Public License |
18 | * along with this program; if not, write to the Free Software |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | */ |
21 | |
22 | #include "fontdialog.h" |
23 | |
24 | #include <KApplication> |
25 | #include <KCharsets> |
26 | #include <KComboBox> |
27 | #include <KConfig> |
28 | #include <KGlobal> |
29 | #include <KLocale> |
30 | #include <KNumInput> |
31 | #include <KVBox> |
32 | #include <KFontComboBox> |
33 | #include <KConfigGroup> |
34 | |
35 | #include <khtmldefaults.h> |
36 | |
37 | #include <QGroupBox> |
38 | #include <QLabel> |
39 | #include <QLayout> |
40 | |
41 | using namespace KHC; |
42 | |
43 | FontDialog::FontDialog( QWidget *parent ) |
44 | : KDialog( parent ) |
45 | { |
46 | setModal( true ); |
47 | setCaption( i18n( "Font Configuration" ) ); |
48 | setButtons( Ok | Cancel ); |
49 | |
50 | m_mainWidget = new KVBox( this ); |
51 | setMainWidget( m_mainWidget ); |
52 | |
53 | setupFontSizesBox(); |
54 | setupFontTypesBox(); |
55 | setupFontEncodingBox(); |
56 | |
57 | load(); |
58 | |
59 | connect( this, SIGNAL( okClicked() ), SLOT( slotOk() ) ); |
60 | } |
61 | |
62 | void FontDialog::slotOk() |
63 | { |
64 | save(); |
65 | accept(); |
66 | } |
67 | |
68 | void FontDialog::setupFontSizesBox() |
69 | { |
70 | QGroupBox *gb = new QGroupBox( i18n( "Sizes" ), m_mainWidget ); |
71 | |
72 | QGridLayout *layout = new QGridLayout( gb ); |
73 | layout->setSpacing( KDialog::spacingHint() ); |
74 | layout->setMargin( KDialog::marginHint() * 2 ); |
75 | |
76 | QLabel *lMinFontSize = new QLabel( i18nc( "The smallest size a will have" , "M&inimum font size:" ), gb ); |
77 | layout->addWidget( lMinFontSize, 0, 0 ); |
78 | m_minFontSize = new KIntNumInput( gb ); |
79 | layout->addWidget( m_minFontSize, 0, 1 ); |
80 | m_minFontSize->setRange( 1, 20 ); |
81 | lMinFontSize->setBuddy( m_minFontSize ); |
82 | |
83 | QLabel *lMedFontSize = new QLabel( i18nc( "The normal size a font will have" , "M&edium font size:" ), gb ); |
84 | layout->addWidget( lMedFontSize, 1, 0 ); |
85 | m_medFontSize = new KIntNumInput( gb ); |
86 | layout->addWidget( m_medFontSize, 1, 1 ); |
87 | m_medFontSize->setRange( 4, 28 ); |
88 | lMedFontSize->setBuddy( m_medFontSize ); |
89 | } |
90 | |
91 | void FontDialog::setupFontTypesBox() |
92 | { |
93 | QGroupBox *gb = new QGroupBox( i18n( "Fonts" ), m_mainWidget ); |
94 | |
95 | QGridLayout *layout = new QGridLayout( gb ); |
96 | layout->setSpacing( KDialog::spacingHint() ); |
97 | layout->setMargin( KDialog::marginHint() * 2 ); |
98 | |
99 | QLabel *lStandardFont = new QLabel( i18n( "S&tandard font:" ), gb ); |
100 | layout->addWidget( lStandardFont, 0, 0 ); |
101 | m_standardFontCombo = new KFontComboBox( gb ); |
102 | layout->addWidget( m_standardFontCombo, 0, 1 ); |
103 | lStandardFont->setBuddy( m_standardFontCombo ); |
104 | |
105 | QLabel *lFixedFont = new QLabel( i18n( "F&ixed font:" ), gb ); |
106 | layout->addWidget( lFixedFont, 1, 0 ); |
107 | m_fixedFontCombo = new KFontComboBox( gb ); |
108 | layout->addWidget( m_fixedFontCombo, 1, 1 ); |
109 | lFixedFont->setBuddy( m_fixedFontCombo ); |
110 | |
111 | QLabel *lSerifFont = new QLabel( i18n( "S&erif font:" ), gb ); |
112 | layout->addWidget( lSerifFont, 2, 0 ); |
113 | m_serifFontCombo = new KFontComboBox( gb ); |
114 | layout->addWidget( m_serifFontCombo, 2, 1 ); |
115 | lSerifFont->setBuddy( m_serifFontCombo ); |
116 | |
117 | QLabel *lSansSerifFont = new QLabel( i18n( "S&ans serif font:" ), gb ); |
118 | layout->addWidget( lSansSerifFont, 3, 0 ); |
119 | m_sansSerifFontCombo = new KFontComboBox( gb ); |
120 | layout->addWidget( m_sansSerifFontCombo, 3, 1 ); |
121 | lSansSerifFont->setBuddy( m_sansSerifFontCombo ); |
122 | |
123 | QLabel *lItalicFont = new QLabel( i18n( "&Italic font:" ), gb ); |
124 | layout->addWidget( lItalicFont, 4, 0 ); |
125 | m_italicFontCombo = new KFontComboBox( gb ); |
126 | layout->addWidget( m_italicFontCombo, 4, 1 ); |
127 | lItalicFont->setBuddy( m_italicFontCombo ); |
128 | |
129 | QLabel *lFantasyFont = new QLabel( i18n( "&Fantasy font:" ), gb ); |
130 | layout->addWidget( lFantasyFont, 5, 0 ); |
131 | m_fantasyFontCombo = new KFontComboBox( gb ); |
132 | layout->addWidget( m_fantasyFontCombo, 5, 1 ); |
133 | lFantasyFont->setBuddy( m_fantasyFontCombo ); |
134 | } |
135 | |
136 | void FontDialog::setupFontEncodingBox() |
137 | { |
138 | QGroupBox *gb = new QGroupBox( i18n( "Encoding" ), m_mainWidget ); |
139 | |
140 | QGridLayout *layout = new QGridLayout( gb ); |
141 | layout->setSpacing( KDialog::spacingHint() ); |
142 | layout->setMargin( KDialog::marginHint() * 2 ); |
143 | |
144 | QLabel *lDefaultEncoding = new QLabel( i18n( "&Default encoding:" ), gb ); |
145 | layout->addWidget( lDefaultEncoding, 0, 0 ); |
146 | m_defaultEncoding = new KComboBox( false, gb ); |
147 | layout->addWidget( m_defaultEncoding, 0, 1 ); |
148 | QStringList encodings = KGlobal::charsets()->availableEncodingNames(); |
149 | encodings.prepend( i18n( "Use Language Encoding" ) ); |
150 | m_defaultEncoding->addItems( encodings ); |
151 | lDefaultEncoding->setBuddy( m_defaultEncoding ); |
152 | |
153 | QLabel *lFontSizeAdjustement = new QLabel( i18n( "&Font size adjustment:" ), gb ); |
154 | layout->addWidget( lFontSizeAdjustement, 1, 0 ); |
155 | m_fontSizeAdjustement = new KIntSpinBox( gb ); |
156 | m_fontSizeAdjustement->setRange( -5, 5 ); |
157 | m_fontSizeAdjustement->setSingleStep( 1 ); |
158 | layout->addWidget( m_fontSizeAdjustement, 1, 1 ); |
159 | lFontSizeAdjustement->setBuddy( m_fontSizeAdjustement ); |
160 | } |
161 | |
162 | void FontDialog::load() |
163 | { |
164 | KSharedConfig::Ptr cfg = KGlobal::config(); |
165 | { |
166 | KConfigGroup configGroup( cfg, "HTML Settings" ); |
167 | |
168 | m_minFontSize->setValue( configGroup.readEntry( "MinimumFontSize" , (int)HTML_DEFAULT_MIN_FONT_SIZE ) ); |
169 | m_medFontSize->setValue( configGroup.readEntry( "MediumFontSize" , 10 ) ); |
170 | |
171 | QStringList fonts = configGroup.readEntry( "Fonts" , QStringList() ); |
172 | if ( fonts.isEmpty() ) |
173 | fonts << KGlobalSettings::generalFont().family() |
174 | << KGlobalSettings::fixedFont().family() |
175 | << QLatin1String(HTML_DEFAULT_VIEW_SERIF_FONT) |
176 | << QLatin1String(HTML_DEFAULT_VIEW_SANSSERIF_FONT) |
177 | << QLatin1String(HTML_DEFAULT_VIEW_CURSIVE_FONT) |
178 | << QLatin1String(HTML_DEFAULT_VIEW_FANTASY_FONT) |
179 | << QString(); |
180 | |
181 | m_standardFontCombo->setCurrentFont( fonts[ 0 ] ); |
182 | m_fixedFontCombo->setCurrentFont( fonts[ 1 ] ); |
183 | m_serifFontCombo->setCurrentFont( fonts[ 2 ] ); |
184 | m_sansSerifFontCombo->setCurrentFont( fonts[ 3 ] ); |
185 | m_italicFontCombo->setCurrentFont( fonts[ 4 ] ); |
186 | m_fantasyFontCombo->setCurrentFont( fonts[ 5 ] ); |
187 | |
188 | QString encoding = configGroup.readEntry( "DefaultEncoding" ); |
189 | if (encoding.isEmpty()) m_defaultEncoding->setCurrentIndex( 0 ); |
190 | else m_defaultEncoding->setCurrentItem( encoding ); |
191 | m_fontSizeAdjustement->setValue( fonts[ 6 ].toInt() ); |
192 | } |
193 | } |
194 | |
195 | void FontDialog::save() |
196 | { |
197 | KSharedConfig::Ptr cfg = KGlobal::config(); |
198 | { |
199 | KConfigGroup configGroup( cfg, "General" ); |
200 | configGroup.writeEntry( "UseKonqSettings" , false ); |
201 | } |
202 | { |
203 | KConfigGroup configGroup( cfg, "HTML Settings" ); |
204 | |
205 | configGroup.writeEntry( "MinimumFontSize" , m_minFontSize->value() ); |
206 | configGroup.writeEntry( "MediumFontSize" , m_medFontSize->value() ); |
207 | |
208 | QStringList fonts; |
209 | fonts << m_standardFontCombo->currentFont().family() |
210 | << m_fixedFontCombo->currentFont().family() |
211 | << m_serifFontCombo->currentFont().family() |
212 | << m_sansSerifFontCombo->currentFont().family() |
213 | << m_italicFontCombo->currentFont().family() |
214 | << m_fantasyFontCombo->currentFont().family() |
215 | << QString::number( m_fontSizeAdjustement->value() ); |
216 | |
217 | configGroup.writeEntry( "Fonts" , fonts ); |
218 | |
219 | if ( m_defaultEncoding->currentText() == i18n( "Use Language Encoding" ) ) |
220 | configGroup.writeEntry( "DefaultEncoding" , QString() ); |
221 | else |
222 | configGroup.writeEntry( "DefaultEncoding" , m_defaultEncoding->currentText() ); |
223 | } |
224 | cfg->sync(); |
225 | } |
226 | |
227 | #include "fontdialog.moc" |
228 | // vim:ts=4:sw=4:noet |
229 | |