2 * This file is part of the KDE Help Center
4 * Copyright (C) 2003 Frerich Raabe <raabe@kde.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "fontdialog.h"
22 #include <kapplication.h>
23 #include <kcharsets.h>
24 #include <kcombobox.h>
27 #include <khtmldefaults.h>
29 #include <knuminput.h>
31 #include <kfontcombobox.h>
37 #include <kconfiggroup.h>
41 FontDialog::FontDialog( QWidget
*parent
)
45 setCaption( i18n( "Font Configuration" ) );
46 setButtons( Ok
| Cancel
);
48 m_mainWidget
= new KVBox( this );
49 setMainWidget( m_mainWidget
);
53 setupFontEncodingBox();
57 connect( this, SIGNAL( okClicked() ), SLOT( slotOk() ) );
60 void FontDialog::slotOk()
66 void FontDialog::setupFontSizesBox()
68 QGroupBox
*gb
= new QGroupBox( i18n( "Sizes" ), m_mainWidget
);
70 QGridLayout
*layout
= new QGridLayout( gb
);
71 layout
->setSpacing( KDialog::spacingHint() );
72 layout
->setMargin( KDialog::marginHint() * 2 );
74 QLabel
*lMinFontSize
= new QLabel( i18nc( "The smallest size a will have", "M&inimum font size:" ), gb
);
75 layout
->addWidget( lMinFontSize
, 0, 0 );
76 m_minFontSize
= new KIntNumInput( gb
);
77 layout
->addWidget( m_minFontSize
, 0, 1 );
78 m_minFontSize
->setRange( 1, 20 );
79 lMinFontSize
->setBuddy( m_minFontSize
);
81 QLabel
*lMedFontSize
= new QLabel( i18nc( "The normal size a font will have", "M&edium font size:" ), gb
);
82 layout
->addWidget( lMedFontSize
, 1, 0 );
83 m_medFontSize
= new KIntNumInput( gb
);
84 layout
->addWidget( m_medFontSize
, 1, 1 );
85 m_medFontSize
->setRange( 4, 28 );
86 lMedFontSize
->setBuddy( m_medFontSize
);
89 void FontDialog::setupFontTypesBox()
91 QGroupBox
*gb
= new QGroupBox( i18n( "Fonts" ), m_mainWidget
);
93 QGridLayout
*layout
= new QGridLayout( gb
);
94 layout
->setSpacing( KDialog::spacingHint() );
95 layout
->setMargin( KDialog::marginHint() * 2 );
97 QLabel
*lStandardFont
= new QLabel( i18n( "S&tandard font:" ), gb
);
98 layout
->addWidget( lStandardFont
, 0, 0 );
99 m_standardFontCombo
= new KFontComboBox( gb
);
100 layout
->addWidget( m_standardFontCombo
, 0, 1 );
101 lStandardFont
->setBuddy( m_standardFontCombo
);
103 QLabel
*lFixedFont
= new QLabel( i18n( "F&ixed font:" ), gb
);
104 layout
->addWidget( lFixedFont
, 1, 0 );
105 m_fixedFontCombo
= new KFontComboBox( gb
);
106 layout
->addWidget( m_fixedFontCombo
, 1, 1 );
107 lFixedFont
->setBuddy( m_fixedFontCombo
);
109 QLabel
*lSerifFont
= new QLabel( i18n( "S&erif font:" ), gb
);
110 layout
->addWidget( lSerifFont
, 2, 0 );
111 m_serifFontCombo
= new KFontComboBox( gb
);
112 layout
->addWidget( m_serifFontCombo
, 2, 1 );
113 lSerifFont
->setBuddy( m_serifFontCombo
);
115 QLabel
*lSansSerifFont
= new QLabel( i18n( "S&ans serif font:" ), gb
);
116 layout
->addWidget( lSansSerifFont
, 3, 0 );
117 m_sansSerifFontCombo
= new KFontComboBox( gb
);
118 layout
->addWidget( m_sansSerifFontCombo
, 3, 1 );
119 lSansSerifFont
->setBuddy( m_sansSerifFontCombo
);
121 QLabel
*lItalicFont
= new QLabel( i18n( "&Italic font:" ), gb
);
122 layout
->addWidget( lItalicFont
, 4, 0 );
123 m_italicFontCombo
= new KFontComboBox( gb
);
124 layout
->addWidget( m_italicFontCombo
, 4, 1 );
125 lItalicFont
->setBuddy( m_italicFontCombo
);
127 QLabel
*lFantasyFont
= new QLabel( i18n( "&Fantasy font:" ), gb
);
128 layout
->addWidget( lFantasyFont
, 5, 0 );
129 m_fantasyFontCombo
= new KFontComboBox( gb
);
130 layout
->addWidget( m_fantasyFontCombo
, 5, 1 );
131 lFantasyFont
->setBuddy( m_fantasyFontCombo
);
134 void FontDialog::setupFontEncodingBox()
136 QGroupBox
*gb
= new QGroupBox( i18n( "Encoding" ), m_mainWidget
);
138 QGridLayout
*layout
= new QGridLayout( gb
);
139 layout
->setSpacing( KDialog::spacingHint() );
140 layout
->setMargin( KDialog::marginHint() * 2 );
142 QLabel
*lDefaultEncoding
= new QLabel( i18n( "&Default encoding:" ), gb
);
143 layout
->addWidget( lDefaultEncoding
, 0, 0 );
144 m_defaultEncoding
= new KComboBox( false, gb
);
145 layout
->addWidget( m_defaultEncoding
, 0, 1 );
146 QStringList encodings
= KGlobal::charsets()->availableEncodingNames();
147 encodings
.prepend( i18n( "Use Language Encoding" ) );
148 m_defaultEncoding
->addItems( encodings
);
149 lDefaultEncoding
->setBuddy( m_defaultEncoding
);
151 QLabel
*lFontSizeAdjustement
= new QLabel( i18n( "&Font size adjustment:" ), gb
);
152 layout
->addWidget( lFontSizeAdjustement
, 1, 0 );
153 m_fontSizeAdjustement
= new QSpinBox( gb
);
154 m_fontSizeAdjustement
->setRange( -5, 5 );
155 m_fontSizeAdjustement
->setSingleStep( 1 );
156 layout
->addWidget( m_fontSizeAdjustement
, 1, 1 );
157 lFontSizeAdjustement
->setBuddy( m_fontSizeAdjustement
);
160 void FontDialog::load()
162 KSharedConfig::Ptr cfg
= KGlobal::config();
164 KConfigGroup
configGroup( cfg
, "HTML Settings" );
166 m_minFontSize
->setValue( configGroup
.readEntry( "MinimumFontSize", (int)HTML_DEFAULT_MIN_FONT_SIZE
) );
167 m_medFontSize
->setValue( configGroup
.readEntry( "MediumFontSize", 10 ) );
169 QStringList fonts
= configGroup
.readEntry( "Fonts" , QStringList() );
170 if ( fonts
.isEmpty() )
171 fonts
<< KGlobalSettings::generalFont().family()
172 << KGlobalSettings::fixedFont().family()
173 << QLatin1String(HTML_DEFAULT_VIEW_SERIF_FONT
)
174 << QLatin1String(HTML_DEFAULT_VIEW_SANSSERIF_FONT
)
175 << QLatin1String(HTML_DEFAULT_VIEW_CURSIVE_FONT
)
176 << QLatin1String(HTML_DEFAULT_VIEW_FANTASY_FONT
)
179 m_standardFontCombo
->setCurrentFont( fonts
[ 0 ] );
180 m_fixedFontCombo
->setCurrentFont( fonts
[ 1 ] );
181 m_serifFontCombo
->setCurrentFont( fonts
[ 2 ] );
182 m_sansSerifFontCombo
->setCurrentFont( fonts
[ 3 ] );
183 m_italicFontCombo
->setCurrentFont( fonts
[ 4 ] );
184 m_fantasyFontCombo
->setCurrentFont( fonts
[ 5 ] );
186 QString encoding
= configGroup
.readEntry( "DefaultEncoding" );
187 if (encoding
.isEmpty()) m_defaultEncoding
->setCurrentIndex( 0 );
188 else m_defaultEncoding
->setCurrentItem( encoding
);
189 m_fontSizeAdjustement
->setValue( fonts
[ 6 ].toInt() );
193 void FontDialog::save()
195 KSharedConfig::Ptr cfg
= KGlobal::config();
197 KConfigGroup
configGroup( cfg
, "General" );
198 configGroup
.writeEntry( "UseKonqSettings", false );
201 KConfigGroup
configGroup( cfg
, "HTML Settings" );
203 configGroup
.writeEntry( "MinimumFontSize", m_minFontSize
->value() );
204 configGroup
.writeEntry( "MediumFontSize", m_medFontSize
->value() );
207 fonts
<< m_standardFontCombo
->currentFont().family()
208 << m_fixedFontCombo
->currentFont().family()
209 << m_serifFontCombo
->currentFont().family()
210 << m_sansSerifFontCombo
->currentFont().family()
211 << m_italicFontCombo
->currentFont().family()
212 << m_fantasyFontCombo
->currentFont().family()
213 << QString::number( m_fontSizeAdjustement
->value() );
215 configGroup
.writeEntry( "Fonts", fonts
);
217 if ( m_defaultEncoding
->currentText() == i18n( "Use Language Encoding" ) )
218 configGroup
.writeEntry( "DefaultEncoding", QString() );
220 configGroup
.writeEntry( "DefaultEncoding", m_defaultEncoding
->currentText() );
225 #include "fontdialog.moc"
226 // vim:ts=4:sw=4:noet