~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to kcontrol/konqhtml/appearance.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-27 12:09:48 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080527120948-dottsyd5rcwhzd36
Tags: 4:4.0.80-1ubuntu1
* Merge with Debian
 - remove 97_fix_target_link_libraries.diff
 - Add replaces/conflicts on -kde4 packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
#include <qfontdatabase.h>
3
 
#include <qlabel.h>
4
 
#include <qlayout.h>
5
 
#include <qvgroupbox.h>
6
 
#include <qwhatsthis.h>
7
 
 
8
 
#include <dcopclient.h>
9
 
 
10
 
#include <kapplication.h>
11
 
#include <kcharsets.h>
12
 
#include <kconfig.h>
13
 
#include <kdebug.h>
14
 
#include <kdialog.h>
15
 
#include <kfontcombo.h>
16
 
#include <kglobal.h>
17
 
#include <khtmldefaults.h>
18
 
#include <klocale.h>
19
 
#include <knuminput.h>
20
 
 
21
 
#if defined Q_WS_X11 && !defined K_WS_QTONLY
22
 
#include <X11/Xlib.h>
23
 
#endif
24
 
 
25
 
 
26
 
#include "appearance.moc"
27
 
 
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 )
31
 
 
32
 
{
33
 
  setQuickHelp( i18n("<h1>Konqueror Fonts</h1>On this page, you can configure "
34
 
              "which fonts Konqueror should use to display the web "
35
 
              "pages you view."));
36
 
 
37
 
  QString wtstr;
38
 
 
39
 
  QGridLayout *lay = new QGridLayout(this, 1 ,1 , 0, KDialog::spacingHint());
40
 
  int r = 0;
41
 
  int E = 0, M = 1, W = 3; //CT 3 (instead 2) allows smaller color buttons
42
 
 
43
 
  QGroupBox* gb = new QGroupBox( 1, QGroupBox::Horizontal, i18n("Font Si&ze"), this );
44
 
  lay->addMultiCellWidget(gb, r, r, E, W);
45
 
 
46
 
  QWhatsThis::add( gb, i18n("This is the relative font size Konqueror uses to display web sites.") );
47
 
 
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" ) );
55
 
 
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.") );
64
 
 
65
 
  QStringList emptyList;
66
 
 
67
 
  QLabel* label = new QLabel( i18n("S&tandard font:"), this );
68
 
  lay->addWidget( label , ++r, E);
69
 
 
70
 
  m_pFonts[0] = new KFontCombo( emptyList, this );
71
 
 
72
 
  label->setBuddy( m_pFonts[0] );
73
 
  lay->addMultiCellWidget(m_pFonts[0], r, r, M, W);
74
 
 
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 );
78
 
 
79
 
  connect( m_pFonts[0], SIGNAL( activated(const QString&) ),
80
 
           SLOT( slotStandardFont(const QString&) ) );
81
 
  connect( m_pFonts[0], SIGNAL( activated(const QString&) ),
82
 
           SLOT(changed() ) );
83
 
  connect( m_pFonts[0]->lineEdit(), SIGNAL( textChanged(const QString&) ),
84
 
           SLOT( slotStandardFont(const QString&) ) );
85
 
  connect( m_pFonts[0], SIGNAL( textChanged(const QString&) ),
86
 
           SLOT(changed() ) );
87
 
 
88
 
  label = new QLabel( i18n( "&Fixed font:"), this );
89
 
  lay->addWidget( label, ++r, E );
90
 
 
91
 
  m_pFonts[1] = new KFontCombo( emptyList, this );
92
 
 
93
 
  label->setBuddy( m_pFonts[1] );
94
 
  lay->addMultiCellWidget(m_pFonts[1], r, r, M, W);
95
 
 
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 );
99
 
 
100
 
  connect( m_pFonts[1], SIGNAL( activated(const QString&) ),
101
 
           SLOT( slotFixedFont(const QString&) ) );
102
 
  connect( m_pFonts[1], SIGNAL( activated(const QString&) ),
103
 
           SLOT(changed() ) );
104
 
  connect( m_pFonts[1]->lineEdit(), SIGNAL( textChanged(const QString&) ),
105
 
           SLOT( slotFixedFont(const QString&) ) );
106
 
  connect( m_pFonts[1], SIGNAL( textChanged(const QString&) ),
107
 
           SLOT(changed() ) );
108
 
 
109
 
  label = new QLabel( i18n( "S&erif font:" ), this );
110
 
  lay->addWidget( label, ++r, E );
111
 
 
112
 
  m_pFonts[2] = new KFontCombo( emptyList, this );
113
 
 
114
 
  label->setBuddy( m_pFonts[2] );
115
 
  lay->addMultiCellWidget( m_pFonts[2], r, r, M, W );
116
 
 
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 );
120
 
 
121
 
  connect( m_pFonts[2], SIGNAL( activated( const QString& ) ),
122
 
           SLOT( slotSerifFont( const QString& ) ) );
123
 
  connect( m_pFonts[2], SIGNAL( activated( const QString& ) ),
124
 
           SLOT( changed() ) );
125
 
  connect( m_pFonts[2]->lineEdit(), SIGNAL( textChanged(const QString&) ),
126
 
           SLOT( slotSerifFont(const QString&) ) );
127
 
  connect( m_pFonts[2], SIGNAL( textChanged(const QString&) ),
128
 
           SLOT(changed() ) );
129
 
 
130
 
  label = new QLabel( i18n( "Sa&ns serif font:" ), this );
131
 
  lay->addWidget( label, ++r, E );
132
 
 
133
 
  m_pFonts[3] = new KFontCombo( emptyList, this );
134
 
 
135
 
  label->setBuddy( m_pFonts[3] );
136
 
  lay->addMultiCellWidget( m_pFonts[3], r, r, M, W );
137
 
 
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 );
141
 
 
142
 
  connect( m_pFonts[3], SIGNAL( activated( const QString& ) ),
143
 
           SLOT( slotSansSerifFont( const QString& ) ) );
144
 
  connect( m_pFonts[3], SIGNAL( activated( const QString& ) ),
145
 
           SLOT( changed() ) );
146
 
  connect( m_pFonts[3]->lineEdit(), SIGNAL( textChanged(const QString&) ),
147
 
           SLOT( slotSansSerifFont(const QString&) ) );
148
 
  connect( m_pFonts[3], SIGNAL( textChanged(const QString&) ),
149
 
           SLOT(changed() ) );
150
 
 
151
 
 
152
 
  label = new QLabel( i18n( "C&ursive font:" ), this );
153
 
  lay->addWidget( label, ++r, E );
154
 
 
155
 
  m_pFonts[4] = new KFontCombo( emptyList, this );
156
 
 
157
 
  label->setBuddy( m_pFonts[4] );
158
 
  lay->addMultiCellWidget( m_pFonts[4], r, r, M, W );
159
 
 
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 );
163
 
 
164
 
  connect( m_pFonts[4], SIGNAL( activated( const QString& ) ),
165
 
           SLOT( slotCursiveFont( const QString& ) ) );
166
 
  connect( m_pFonts[4], SIGNAL( activated( const QString& ) ),
167
 
           SLOT( changed() ) );
168
 
  connect( m_pFonts[4]->lineEdit(), SIGNAL( textChanged(const QString&) ),
169
 
           SLOT( slotCursiveFont(const QString&) ) );
170
 
  connect( m_pFonts[4], SIGNAL( textChanged(const QString&) ),
171
 
           SLOT(changed() ) );
172
 
 
173
 
 
174
 
  label = new QLabel( i18n( "Fantas&y font:" ), this );
175
 
  lay->addWidget( label, ++r, E );
176
 
 
177
 
  m_pFonts[5] = new KFontCombo( emptyList, this );
178
 
 
179
 
  label->setBuddy( m_pFonts[5] );
180
 
  lay->addMultiCellWidget( m_pFonts[5], r, r, M, W );
181
 
 
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 );
185
 
 
186
 
  connect( m_pFonts[5], SIGNAL( activated( const QString& ) ),
187
 
           SLOT( slotFantasyFont( const QString& ) ) );
188
 
  connect( m_pFonts[5], SIGNAL( activated( const QString& ) ),
189
 
           SLOT( changed() ) );
190
 
  connect( m_pFonts[5]->lineEdit(), SIGNAL( textChanged(const QString&) ),
191
 
           SLOT( slotFantasyFont(const QString&) ) );
192
 
  connect( m_pFonts[5], SIGNAL( textChanged(const QString&) ),
193
 
           SLOT(changed() ) );
194
 
 
195
 
 
196
 
  label = new QLabel( i18n( "Font &size adjustment for this encoding:" ), this );
197
 
  lay->addWidget( label, ++r, M );
198
 
 
199
 
  m_pFontSizeAdjust = new QSpinBox( -5, 5, 1, this );
200
 
  label->setBuddy( m_pFontSizeAdjust );
201
 
  lay->addMultiCellWidget( m_pFontSizeAdjust, r, r, M+1, W );
202
 
 
203
 
  connect( m_pFontSizeAdjust, SIGNAL( valueChanged( int ) ),
204
 
           SLOT( slotFontSizeAdjust( int ) ) );
205
 
  connect( m_pFontSizeAdjust, SIGNAL( valueChanged( int ) ),
206
 
           SLOT( changed() ) );
207
 
 
208
 
  label = new QLabel( i18n( "Default encoding:"), this );
209
 
  //++r;
210
 
  //lay->addMultiCellWidget( label, r, r, E, E+1);
211
 
  lay->addWidget( label, ++r, E);
212
 
 
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);
219
 
 
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 );
224
 
 
225
 
  connect( m_pEncoding, SIGNAL( activated(const QString& ) ),
226
 
           SLOT( slotEncoding(const QString&) ) );
227
 
  connect( m_pEncoding, SIGNAL( activated(const QString& ) ),
228
 
           SLOT( changed() ) );
229
 
 
230
 
  ++r; lay->setRowStretch(r, 8);
231
 
 
232
 
  QFontDatabase db;
233
 
 
234
 
  m_families = db.families();
235
 
 
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 );
242
 
 
243
 
  load();
244
 
}
245
 
 
246
 
KAppearanceOptions::~KAppearanceOptions()
247
 
{
248
 
delete m_pConfig;
249
 
}
250
 
 
251
 
void KAppearanceOptions::slotFontSize( int i )
252
 
{
253
 
    fSize = i;
254
 
    if ( fSize < fMinSize ) {
255
 
        m_minSize->setValue( fSize );
256
 
        fMinSize = fSize;
257
 
    }
258
 
}
259
 
 
260
 
 
261
 
void KAppearanceOptions::slotMinimumFontSize( int i )
262
 
{
263
 
    fMinSize = i;
264
 
    if ( fMinSize > fSize ) {
265
 
        m_MedSize->setValue( fMinSize );
266
 
        fSize = fMinSize;
267
 
    }
268
 
}
269
 
 
270
 
 
271
 
void KAppearanceOptions::slotStandardFont(const QString& n )
272
 
{
273
 
    fonts[0] = n;
274
 
}
275
 
 
276
 
 
277
 
void KAppearanceOptions::slotFixedFont(const QString& n )
278
 
{
279
 
    fonts[1] = n;
280
 
}
281
 
 
282
 
 
283
 
void KAppearanceOptions::slotSerifFont( const QString& n )
284
 
{
285
 
    fonts[2] = n;
286
 
}
287
 
 
288
 
 
289
 
void KAppearanceOptions::slotSansSerifFont( const QString& n )
290
 
{
291
 
    fonts[3] = n;
292
 
}
293
 
 
294
 
 
295
 
void KAppearanceOptions::slotCursiveFont( const QString& n )
296
 
{
297
 
    fonts[4] = n;
298
 
}
299
 
 
300
 
 
301
 
void KAppearanceOptions::slotFantasyFont( const QString& n )
302
 
{
303
 
    fonts[5] = n;
304
 
}
305
 
 
306
 
void KAppearanceOptions::slotFontSizeAdjust( int value )
307
 
{
308
 
    fonts[6] = QString::number( value );
309
 
}
310
 
 
311
 
void KAppearanceOptions::slotEncoding(const QString& n)
312
 
{
313
 
    encodingName = n;
314
 
}
315
 
 
316
 
void KAppearanceOptions::load()
317
 
{
318
 
        load( false );
319
 
}
320
 
 
321
 
void KAppearanceOptions::load( bool useDefaults )
322
 
{
323
 
    KConfig khtmlrc("khtmlrc", true, false);
324
 
         m_pConfig->setReadDefaults( useDefaults );
325
 
 
326
 
         khtmlrc.setReadDefaults( useDefaults );
327
 
 
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))
332
 
 
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)
337
 
      fSize = fMinSize;
338
 
 
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
347
 
 
348
 
    if (m_pConfig->hasKey("Fonts"))
349
 
       fonts = m_pConfig->readListEntry( "Fonts" );
350
 
    else
351
 
       fonts = khtmlrc.readListEntry( "Fonts" );
352
 
    while (fonts.count() < 7)
353
 
       fonts.append(QString::null);
354
 
 
355
 
    encodingName = READ_ENTRY( "DefaultEncoding", QString::null );
356
 
    //kdDebug(0) << "encoding = " << encodingName << endl;
357
 
 
358
 
    updateGUI();
359
 
    emit changed( useDefaults );
360
 
 
361
 
#undef SET_GROUP
362
 
#undef READ_NUM
363
 
#undef READ_ENTRY
364
 
#undef READ_LIST
365
 
}
366
 
 
367
 
void KAppearanceOptions::defaults()
368
 
{
369
 
        load( true );
370
 
}
371
 
 
372
 
void KAppearanceOptions::updateGUI()
373
 
{
374
 
    //kdDebug() << "KAppearanceOptions::updateGUI " << charset << endl;
375
 
    for ( int f = 0; f < 6; f++ ) {
376
 
        QString ff = fonts[f];
377
 
        if (ff.isEmpty())
378
 
           ff = defaultFonts[f];
379
 
        m_pFonts[f]->setCurrentFont(ff);
380
 
    }
381
 
 
382
 
    int i = 0;
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);
395
 
}
396
 
 
397
 
void KAppearanceOptions::save()
398
 
{
399
 
    m_pConfig->setGroup(m_groupname);
400
 
    m_pConfig->writeEntry( "MediumFontSize", fSize );
401
 
    m_pConfig->writeEntry( "MinimumFontSize", fMinSize );
402
 
    m_pConfig->writeEntry( "Fonts", fonts );
403
 
 
404
 
    // If the user chose "Use language encoding", write an empty string
405
 
    if (encodingName == i18n("Use Language Encoding"))
406
 
        encodingName = "";
407
 
    m_pConfig->writeEntry( "DefaultEncoding", encodingName );
408
 
    m_pConfig->sync();
409
 
 
410
 
  QByteArray data;
411
 
  if ( !kapp->dcopClient()->isAttached() )
412
 
    kapp->dcopClient()->attach();
413
 
  kapp->dcopClient()->send( "konqueror*", "KonquerorIface", "reparseConfiguration()", data );
414
 
 
415
 
  emit changed(false);
416
 
}
417