2
#include <qfontdatabase.h>
5
#include <qvgroupbox.h>
6
#include <qwhatsthis.h>
8
#include <dcopclient.h>
10
#include <kapplication.h>
11
#include <kcharsets.h>
15
#include <kfontcombo.h>
17
#include <khtmldefaults.h>
19
#include <knuminput.h>
21
#if defined Q_WS_X11 && !defined K_WS_QTONLY
26
#include "appearance.moc"
28
KAppearanceOptions::KAppearanceOptions(KConfig *config, QString group, QWidget *parent, const char *)
29
: KCModule( parent, "kcmkonqhtml" ), m_pConfig(config), m_groupname(group),
30
fSize( 10 ), fMinSize( HTML_DEFAULT_MIN_FONT_SIZE )
33
setQuickHelp( i18n("<h1>Konqueror Fonts</h1>On this page, you can configure "
34
"which fonts Konqueror should use to display the web "
39
QGridLayout *lay = new QGridLayout(this, 1 ,1 , 0, KDialog::spacingHint());
41
int E = 0, M = 1, W = 3; //CT 3 (instead 2) allows smaller color buttons
43
QGroupBox* gb = new QGroupBox( 1, QGroupBox::Horizontal, i18n("Font Si&ze"), this );
44
lay->addMultiCellWidget(gb, r, r, E, W);
46
QWhatsThis::add( gb, i18n("This is the relative font size Konqueror uses to display web sites.") );
48
m_minSize = new KIntNumInput( fMinSize, gb );
49
m_minSize->setLabel( i18n( "M&inimum font size:" ) );
50
m_minSize->setRange( 2, 30 );
51
connect( m_minSize, SIGNAL( valueChanged( int ) ), this, SLOT( slotMinimumFontSize( int ) ) );
52
connect( m_minSize, SIGNAL( valueChanged( int ) ), this, SLOT( changed() ) );
53
QWhatsThis::add( m_minSize, i18n( "Konqueror will never display text smaller than "
54
"this size,<br>overriding any other settings" ) );
56
m_MedSize = new KIntNumInput( m_minSize, fSize, gb );
57
m_MedSize->setLabel( i18n( "&Medium font size:" ) );
58
m_MedSize->setRange( 2, 30 );
59
connect( m_MedSize, SIGNAL( valueChanged( int ) ), this, SLOT( slotFontSize( int ) ) );
60
connect( m_MedSize, SIGNAL( valueChanged( int ) ), this, SLOT( changed() ) );
61
QWhatsThis::add( m_MedSize,
62
i18n("This is the relative font size Konqueror uses "
63
"to display web sites.") );
65
QStringList emptyList;
67
QLabel* label = new QLabel( i18n("S&tandard font:"), this );
68
lay->addWidget( label , ++r, E);
70
m_pFonts[0] = new KFontCombo( emptyList, this );
72
label->setBuddy( m_pFonts[0] );
73
lay->addMultiCellWidget(m_pFonts[0], r, r, M, W);
75
wtstr = i18n("This is the font used to display normal text in a web page.");
76
QWhatsThis::add( label, wtstr );
77
QWhatsThis::add( m_pFonts[0], wtstr );
79
connect( m_pFonts[0], SIGNAL( activated(const QString&) ),
80
SLOT( slotStandardFont(const QString&) ) );
81
connect( m_pFonts[0], SIGNAL( activated(const QString&) ),
83
connect( m_pFonts[0]->lineEdit(), SIGNAL( textChanged(const QString&) ),
84
SLOT( slotStandardFont(const QString&) ) );
85
connect( m_pFonts[0], SIGNAL( textChanged(const QString&) ),
88
label = new QLabel( i18n( "&Fixed font:"), this );
89
lay->addWidget( label, ++r, E );
91
m_pFonts[1] = new KFontCombo( emptyList, this );
93
label->setBuddy( m_pFonts[1] );
94
lay->addMultiCellWidget(m_pFonts[1], r, r, M, W);
96
wtstr = i18n("This is the font used to display fixed-width (i.e. non-proportional) text.");
97
QWhatsThis::add( label, wtstr );
98
QWhatsThis::add( m_pFonts[1], wtstr );
100
connect( m_pFonts[1], SIGNAL( activated(const QString&) ),
101
SLOT( slotFixedFont(const QString&) ) );
102
connect( m_pFonts[1], SIGNAL( activated(const QString&) ),
104
connect( m_pFonts[1]->lineEdit(), SIGNAL( textChanged(const QString&) ),
105
SLOT( slotFixedFont(const QString&) ) );
106
connect( m_pFonts[1], SIGNAL( textChanged(const QString&) ),
109
label = new QLabel( i18n( "S&erif font:" ), this );
110
lay->addWidget( label, ++r, E );
112
m_pFonts[2] = new KFontCombo( emptyList, this );
114
label->setBuddy( m_pFonts[2] );
115
lay->addMultiCellWidget( m_pFonts[2], r, r, M, W );
117
wtstr= i18n( "This is the font used to display text that is marked up as serif." );
118
QWhatsThis::add( label, wtstr );
119
QWhatsThis::add( m_pFonts[2], wtstr );
121
connect( m_pFonts[2], SIGNAL( activated( const QString& ) ),
122
SLOT( slotSerifFont( const QString& ) ) );
123
connect( m_pFonts[2], SIGNAL( activated( const QString& ) ),
125
connect( m_pFonts[2]->lineEdit(), SIGNAL( textChanged(const QString&) ),
126
SLOT( slotSerifFont(const QString&) ) );
127
connect( m_pFonts[2], SIGNAL( textChanged(const QString&) ),
130
label = new QLabel( i18n( "Sa&ns serif font:" ), this );
131
lay->addWidget( label, ++r, E );
133
m_pFonts[3] = new KFontCombo( emptyList, this );
135
label->setBuddy( m_pFonts[3] );
136
lay->addMultiCellWidget( m_pFonts[3], r, r, M, W );
138
wtstr= i18n( "This is the font used to display text that is marked up as sans-serif." );
139
QWhatsThis::add( label, wtstr );
140
QWhatsThis::add( m_pFonts[3], wtstr );
142
connect( m_pFonts[3], SIGNAL( activated( const QString& ) ),
143
SLOT( slotSansSerifFont( const QString& ) ) );
144
connect( m_pFonts[3], SIGNAL( activated( const QString& ) ),
146
connect( m_pFonts[3]->lineEdit(), SIGNAL( textChanged(const QString&) ),
147
SLOT( slotSansSerifFont(const QString&) ) );
148
connect( m_pFonts[3], SIGNAL( textChanged(const QString&) ),
152
label = new QLabel( i18n( "C&ursive font:" ), this );
153
lay->addWidget( label, ++r, E );
155
m_pFonts[4] = new KFontCombo( emptyList, this );
157
label->setBuddy( m_pFonts[4] );
158
lay->addMultiCellWidget( m_pFonts[4], r, r, M, W );
160
wtstr= i18n( "This is the font used to display text that is marked up as italic." );
161
QWhatsThis::add( label, wtstr );
162
QWhatsThis::add( m_pFonts[4], wtstr );
164
connect( m_pFonts[4], SIGNAL( activated( const QString& ) ),
165
SLOT( slotCursiveFont( const QString& ) ) );
166
connect( m_pFonts[4], SIGNAL( activated( const QString& ) ),
168
connect( m_pFonts[4]->lineEdit(), SIGNAL( textChanged(const QString&) ),
169
SLOT( slotCursiveFont(const QString&) ) );
170
connect( m_pFonts[4], SIGNAL( textChanged(const QString&) ),
174
label = new QLabel( i18n( "Fantas&y font:" ), this );
175
lay->addWidget( label, ++r, E );
177
m_pFonts[5] = new KFontCombo( emptyList, this );
179
label->setBuddy( m_pFonts[5] );
180
lay->addMultiCellWidget( m_pFonts[5], r, r, M, W );
182
wtstr= i18n( "This is the font used to display text that is marked up as a fantasy font." );
183
QWhatsThis::add( label, wtstr );
184
QWhatsThis::add( m_pFonts[5], wtstr );
186
connect( m_pFonts[5], SIGNAL( activated( const QString& ) ),
187
SLOT( slotFantasyFont( const QString& ) ) );
188
connect( m_pFonts[5], SIGNAL( activated( const QString& ) ),
190
connect( m_pFonts[5]->lineEdit(), SIGNAL( textChanged(const QString&) ),
191
SLOT( slotFantasyFont(const QString&) ) );
192
connect( m_pFonts[5], SIGNAL( textChanged(const QString&) ),
196
label = new QLabel( i18n( "Font &size adjustment for this encoding:" ), this );
197
lay->addWidget( label, ++r, M );
199
m_pFontSizeAdjust = new QSpinBox( -5, 5, 1, this );
200
label->setBuddy( m_pFontSizeAdjust );
201
lay->addMultiCellWidget( m_pFontSizeAdjust, r, r, M+1, W );
203
connect( m_pFontSizeAdjust, SIGNAL( valueChanged( int ) ),
204
SLOT( slotFontSizeAdjust( int ) ) );
205
connect( m_pFontSizeAdjust, SIGNAL( valueChanged( int ) ),
208
label = new QLabel( i18n( "Default encoding:"), this );
210
//lay->addMultiCellWidget( label, r, r, E, E+1);
211
lay->addWidget( label, ++r, E);
213
m_pEncoding = new QComboBox( false, this );
214
label->setBuddy( m_pEncoding );
215
encodings = KGlobal::charsets()->availableEncodingNames();
216
encodings.prepend(i18n("Use Language Encoding"));
217
m_pEncoding->insertStringList( encodings );
218
lay->addMultiCellWidget(m_pEncoding,r, r, M, W);
220
wtstr = i18n( "Select the default encoding to be used; normally, you will be fine with 'Use language encoding' "
221
"and should not have to change this.");
222
QWhatsThis::add( label, wtstr );
223
QWhatsThis::add( m_pEncoding, wtstr );
225
connect( m_pEncoding, SIGNAL( activated(const QString& ) ),
226
SLOT( slotEncoding(const QString&) ) );
227
connect( m_pEncoding, SIGNAL( activated(const QString& ) ),
230
++r; lay->setRowStretch(r, 8);
234
m_families = db.families();
236
m_pFonts[0]->setFonts( m_families );
237
m_pFonts[1]->setFonts( m_families );
238
m_pFonts[2]->setFonts( m_families );
239
m_pFonts[3]->setFonts( m_families );
240
m_pFonts[4]->setFonts( m_families );
241
m_pFonts[5]->setFonts( m_families );
246
KAppearanceOptions::~KAppearanceOptions()
251
void KAppearanceOptions::slotFontSize( int i )
254
if ( fSize < fMinSize ) {
255
m_minSize->setValue( fSize );
261
void KAppearanceOptions::slotMinimumFontSize( int i )
264
if ( fMinSize > fSize ) {
265
m_MedSize->setValue( fMinSize );
271
void KAppearanceOptions::slotStandardFont(const QString& n )
277
void KAppearanceOptions::slotFixedFont(const QString& n )
283
void KAppearanceOptions::slotSerifFont( const QString& n )
289
void KAppearanceOptions::slotSansSerifFont( const QString& n )
295
void KAppearanceOptions::slotCursiveFont( const QString& n )
301
void KAppearanceOptions::slotFantasyFont( const QString& n )
306
void KAppearanceOptions::slotFontSizeAdjust( int value )
308
fonts[6] = QString::number( value );
311
void KAppearanceOptions::slotEncoding(const QString& n)
316
void KAppearanceOptions::load()
321
void KAppearanceOptions::load( bool useDefaults )
323
KConfig khtmlrc("khtmlrc", true, false);
324
m_pConfig->setReadDefaults( useDefaults );
326
khtmlrc.setReadDefaults( useDefaults );
328
#define SET_GROUP(x) m_pConfig->setGroup(x); khtmlrc.setGroup(x)
329
#define READ_NUM(x,y) m_pConfig->readNumEntry(x, khtmlrc.readNumEntry(x, y))
330
#define READ_ENTRY(x,y) m_pConfig->readEntry(x, khtmlrc.readEntry(x, y))
331
#define READ_LIST(x) m_pConfig->readListEntry(x, khtmlrc.readListEntry(x))
333
SET_GROUP(m_groupname);
334
fSize = READ_NUM( "MediumFontSize", 12 );
335
fMinSize = READ_NUM( "MinimumFontSize", HTML_DEFAULT_MIN_FONT_SIZE );
336
if (fSize < fMinSize)
339
defaultFonts = QStringList();
340
defaultFonts.append( READ_ENTRY( "StandardFont", KGlobalSettings::generalFont().family() ) );
341
defaultFonts.append( READ_ENTRY( "FixedFont", KGlobalSettings::fixedFont().family() ) );
342
defaultFonts.append( READ_ENTRY( "SerifFont", HTML_DEFAULT_VIEW_SERIF_FONT ) );
343
defaultFonts.append( READ_ENTRY( "SansSerifFont", HTML_DEFAULT_VIEW_SANSSERIF_FONT ) );
344
defaultFonts.append( READ_ENTRY( "CursiveFont", HTML_DEFAULT_VIEW_CURSIVE_FONT ) );
345
defaultFonts.append( READ_ENTRY( "FantasyFont", HTML_DEFAULT_VIEW_FANTASY_FONT ) );
346
defaultFonts.append( QString("0") ); // default font size adjustment
348
if (m_pConfig->hasKey("Fonts"))
349
fonts = m_pConfig->readListEntry( "Fonts" );
351
fonts = khtmlrc.readListEntry( "Fonts" );
352
while (fonts.count() < 7)
353
fonts.append(QString::null);
355
encodingName = READ_ENTRY( "DefaultEncoding", QString::null );
356
//kdDebug(0) << "encoding = " << encodingName << endl;
359
emit changed( useDefaults );
367
void KAppearanceOptions::defaults()
372
void KAppearanceOptions::updateGUI()
374
//kdDebug() << "KAppearanceOptions::updateGUI " << charset << endl;
375
for ( int f = 0; f < 6; f++ ) {
376
QString ff = fonts[f];
378
ff = defaultFonts[f];
379
m_pFonts[f]->setCurrentFont(ff);
383
for ( QStringList::Iterator it = encodings.begin(); it != encodings.end(); ++it, ++i )
384
if ( encodingName == *it )
385
m_pEncoding->setCurrentItem( i );
386
if(encodingName.isEmpty())
387
m_pEncoding->setCurrentItem( 0 );
388
m_pFontSizeAdjust->setValue( fonts[6].toInt() );
389
m_MedSize->blockSignals(true);
390
m_MedSize->setValue( fSize );
391
m_MedSize->blockSignals(false);
392
m_minSize->blockSignals(true);
393
m_minSize->setValue( fMinSize );
394
m_minSize->blockSignals(false);
397
void KAppearanceOptions::save()
399
m_pConfig->setGroup(m_groupname);
400
m_pConfig->writeEntry( "MediumFontSize", fSize );
401
m_pConfig->writeEntry( "MinimumFontSize", fMinSize );
402
m_pConfig->writeEntry( "Fonts", fonts );
404
// If the user chose "Use language encoding", write an empty string
405
if (encodingName == i18n("Use Language Encoding"))
407
m_pConfig->writeEntry( "DefaultEncoding", encodingName );
411
if ( !kapp->dcopClient()->isAttached() )
412
kapp->dcopClient()->attach();
413
kapp->dcopClient()->send( "konqueror*", "KonquerorIface", "reparseConfiguration()", data );