summaryrefslogtreecommitdiffstats
path: root/kcontrol/konqhtml/appearance.cpp
blob: 30272c3f6e3ea0a7564aaed8348d1e519e0aa493 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417

#include <tqfontdatabase.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqvgroupbox.h>
#include <tqwhatsthis.h>

#include <dcopclient.h>

#include <tdeapplication.h>
#include <kcharsets.h>
#include <tdeconfig.h>
#include <kdebug.h>
#include <kdialog.h>
#include <tdefontcombo.h>
#include <tdeglobal.h>
#include <tdehtmldefaults.h>
#include <tdelocale.h>
#include <knuminput.h>

#if defined Q_WS_X11 && !defined K_WS_QTONLY
#include <X11/Xlib.h>
#endif


#include "appearance.moc"

KAppearanceOptions::KAppearanceOptions(TDEConfig *config, TQString group, TQWidget *parent, const char *)
    : TDECModule( parent, "kcmkonqhtml" ), m_pConfig(config), m_groupname(group),
      fSize( 10 ), fMinSize( HTML_DEFAULT_MIN_FONT_SIZE )

{
  setQuickHelp( i18n("<h1>Konqueror Fonts</h1>On this page, you can configure "
              "which fonts Konqueror should use to display the web "
              "pages you view."));

  TQString wtstr;

  TQGridLayout *lay = new TQGridLayout(this, 1 ,1 , 0, KDialog::spacingHint());
  int r = 0;
  int E = 0, M = 1, W = 3; //CT 3 (instead 2) allows smaller color buttons

  TQGroupBox* gb = new TQGroupBox( 1, Qt::Horizontal, i18n("Font Si&ze"), this );
  lay->addMultiCellWidget(gb, r, r, E, W);

  TQWhatsThis::add( gb, i18n("This is the relative font size Konqueror uses to display web sites.") );

  m_minSize = new KIntNumInput( fMinSize, gb );
  m_minSize->setLabel( i18n( "M&inimum font size:" ) );
  m_minSize->setRange( 2, 30 );
  connect( m_minSize, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( slotMinimumFontSize( int ) ) );
  connect( m_minSize, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( changed() ) );
  TQWhatsThis::add( m_minSize, i18n( "Konqueror will never display text smaller than "
                                    "this size,<br>overriding any other settings" ) );

  m_MedSize = new KIntNumInput( m_minSize, fSize, gb );
  m_MedSize->setLabel( i18n( "&Medium font size:" ) );
  m_MedSize->setRange( 2, 30 );
  connect( m_MedSize, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( slotFontSize( int ) ) );
  connect( m_MedSize, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( changed() ) );
  TQWhatsThis::add( m_MedSize,
                   i18n("This is the relative font size Konqueror uses "
                        "to display web sites.") );

  TQStringList emptyList;

  TQLabel* label = new TQLabel( i18n("S&tandard font:"), this );
  lay->addWidget( label , ++r, E);

  m_pFonts[0] = new TDEFontCombo( emptyList, this );

  label->setBuddy( m_pFonts[0] );
  lay->addMultiCellWidget(m_pFonts[0], r, r, M, W);

  wtstr = i18n("This is the font used to display normal text in a web page.");
  TQWhatsThis::add( label, wtstr );
  TQWhatsThis::add( m_pFonts[0], wtstr );

  connect( m_pFonts[0], TQT_SIGNAL( activated(const TQString&) ),
	   TQT_SLOT( slotStandardFont(const TQString&) ) );
  connect( m_pFonts[0], TQT_SIGNAL( activated(const TQString&) ),
	   TQT_SLOT(changed() ) );
  connect( m_pFonts[0]->lineEdit(), TQT_SIGNAL( textChanged(const TQString&) ),
	   TQT_SLOT( slotStandardFont(const TQString&) ) );
  connect( m_pFonts[0], TQT_SIGNAL( textChanged(const TQString&) ),
	   TQT_SLOT(changed() ) );

  label = new TQLabel( i18n( "&Fixed font:"), this );
  lay->addWidget( label, ++r, E );

  m_pFonts[1] = new TDEFontCombo( emptyList, this );

  label->setBuddy( m_pFonts[1] );
  lay->addMultiCellWidget(m_pFonts[1], r, r, M, W);

  wtstr = i18n("This is the font used to display fixed-width (i.e. non-proportional) text.");
  TQWhatsThis::add( label, wtstr );
  TQWhatsThis::add( m_pFonts[1], wtstr );

  connect( m_pFonts[1], TQT_SIGNAL( activated(const TQString&) ),
	   TQT_SLOT( slotFixedFont(const TQString&) ) );
  connect( m_pFonts[1], TQT_SIGNAL( activated(const TQString&) ),
	   TQT_SLOT(changed() ) );
  connect( m_pFonts[1]->lineEdit(), TQT_SIGNAL( textChanged(const TQString&) ),
	   TQT_SLOT( slotFixedFont(const TQString&) ) );
  connect( m_pFonts[1], TQT_SIGNAL( textChanged(const TQString&) ),
	   TQT_SLOT(changed() ) );

  label = new TQLabel( i18n( "S&erif font:" ), this );
  lay->addWidget( label, ++r, E );

  m_pFonts[2] = new TDEFontCombo( emptyList, this );

  label->setBuddy( m_pFonts[2] );
  lay->addMultiCellWidget( m_pFonts[2], r, r, M, W );

  wtstr= i18n( "This is the font used to display text that is marked up as serif." );
  TQWhatsThis::add( label, wtstr );
  TQWhatsThis::add( m_pFonts[2], wtstr );

  connect( m_pFonts[2], TQT_SIGNAL( activated( const TQString& ) ),
	   TQT_SLOT( slotSerifFont( const TQString& ) ) );
  connect( m_pFonts[2], TQT_SIGNAL( activated( const TQString& ) ),
	   TQT_SLOT( changed() ) );
  connect( m_pFonts[2]->lineEdit(), TQT_SIGNAL( textChanged(const TQString&) ),
	   TQT_SLOT( slotSerifFont(const TQString&) ) );
  connect( m_pFonts[2], TQT_SIGNAL( textChanged(const TQString&) ),
	   TQT_SLOT(changed() ) );

  label = new TQLabel( i18n( "Sa&ns serif font:" ), this );
  lay->addWidget( label, ++r, E );

  m_pFonts[3] = new TDEFontCombo( emptyList, this );

  label->setBuddy( m_pFonts[3] );
  lay->addMultiCellWidget( m_pFonts[3], r, r, M, W );

  wtstr= i18n( "This is the font used to display text that is marked up as sans-serif." );
  TQWhatsThis::add( label, wtstr );
  TQWhatsThis::add( m_pFonts[3], wtstr );

  connect( m_pFonts[3], TQT_SIGNAL( activated( const TQString& ) ),
	   TQT_SLOT( slotSansSerifFont( const TQString& ) ) );
  connect( m_pFonts[3], TQT_SIGNAL( activated( const TQString& ) ),
	   TQT_SLOT( changed() ) );
  connect( m_pFonts[3]->lineEdit(), TQT_SIGNAL( textChanged(const TQString&) ),
	   TQT_SLOT( slotSansSerifFont(const TQString&) ) );
  connect( m_pFonts[3], TQT_SIGNAL( textChanged(const TQString&) ),
	   TQT_SLOT(changed() ) );


  label = new TQLabel( i18n( "C&ursive font:" ), this );
  lay->addWidget( label, ++r, E );

  m_pFonts[4] = new TDEFontCombo( emptyList, this );

  label->setBuddy( m_pFonts[4] );
  lay->addMultiCellWidget( m_pFonts[4], r, r, M, W );

  wtstr= i18n( "This is the font used to display text that is marked up as italic." );
  TQWhatsThis::add( label, wtstr );
  TQWhatsThis::add( m_pFonts[4], wtstr );

  connect( m_pFonts[4], TQT_SIGNAL( activated( const TQString& ) ),
	   TQT_SLOT( slotCursiveFont( const TQString& ) ) );
  connect( m_pFonts[4], TQT_SIGNAL( activated( const TQString& ) ),
	   TQT_SLOT( changed() ) );
  connect( m_pFonts[4]->lineEdit(), TQT_SIGNAL( textChanged(const TQString&) ),
	   TQT_SLOT( slotCursiveFont(const TQString&) ) );
  connect( m_pFonts[4], TQT_SIGNAL( textChanged(const TQString&) ),
	   TQT_SLOT(changed() ) );


  label = new TQLabel( i18n( "Fantas&y font:" ), this );
  lay->addWidget( label, ++r, E );

  m_pFonts[5] = new TDEFontCombo( emptyList, this );

  label->setBuddy( m_pFonts[5] );
  lay->addMultiCellWidget( m_pFonts[5], r, r, M, W );

  wtstr= i18n( "This is the font used to display text that is marked up as a fantasy font." );
  TQWhatsThis::add( label, wtstr );
  TQWhatsThis::add( m_pFonts[5], wtstr );

  connect( m_pFonts[5], TQT_SIGNAL( activated( const TQString& ) ),
	   TQT_SLOT( slotFantasyFont( const TQString& ) ) );
  connect( m_pFonts[5], TQT_SIGNAL( activated( const TQString& ) ),
	   TQT_SLOT( changed() ) );
  connect( m_pFonts[5]->lineEdit(), TQT_SIGNAL( textChanged(const TQString&) ),
	   TQT_SLOT( slotFantasyFont(const TQString&) ) );
  connect( m_pFonts[5], TQT_SIGNAL( textChanged(const TQString&) ),
	   TQT_SLOT(changed() ) );


  label = new TQLabel( i18n( "Font &size adjustment for this encoding:" ), this );
  lay->addWidget( label, ++r, M );

  m_pFontSizeAdjust = new TQSpinBox( -5, 5, 1, this );
  label->setBuddy( m_pFontSizeAdjust );
  lay->addMultiCellWidget( m_pFontSizeAdjust, r, r, M+1, W );

  connect( m_pFontSizeAdjust, TQT_SIGNAL( valueChanged( int ) ),
	   TQT_SLOT( slotFontSizeAdjust( int ) ) );
  connect( m_pFontSizeAdjust, TQT_SIGNAL( valueChanged( int ) ),
	   TQT_SLOT( changed() ) );

  label = new TQLabel( i18n( "Default encoding:"), this );
  //++r;
  //lay->addMultiCellWidget( label, r, r, E, E+1);
  lay->addWidget( label, ++r, E);

  m_pEncoding = new TQComboBox( false, this );
  label->setBuddy( m_pEncoding );
  encodings = TDEGlobal::charsets()->availableEncodingNames();
  encodings.prepend(i18n("Use Language Encoding"));
  m_pEncoding->insertStringList( encodings );
  lay->addMultiCellWidget(m_pEncoding,r, r, M, W);

  wtstr = i18n( "Select the default encoding to be used; normally, you will be fine with 'Use language encoding' "
	       "and should not have to change this.");
  TQWhatsThis::add( label, wtstr );
  TQWhatsThis::add( m_pEncoding, wtstr );

  connect( m_pEncoding, TQT_SIGNAL( activated(const TQString& ) ),
	   TQT_SLOT( slotEncoding(const TQString&) ) );
  connect( m_pEncoding, TQT_SIGNAL( activated(const TQString& ) ),
	   TQT_SLOT( changed() ) );

  ++r; lay->setRowStretch(r, 8);

  TQFontDatabase db;

  m_families = db.families();

  m_pFonts[0]->setFonts( m_families );
  m_pFonts[1]->setFonts( m_families );
  m_pFonts[2]->setFonts( m_families );
  m_pFonts[3]->setFonts( m_families );
  m_pFonts[4]->setFonts( m_families );
  m_pFonts[5]->setFonts( m_families );

  load();
}

KAppearanceOptions::~KAppearanceOptions()
{
delete m_pConfig;
}

void KAppearanceOptions::slotFontSize( int i )
{
    fSize = i;
    if ( fSize < fMinSize ) {
        m_minSize->setValue( fSize );
        fMinSize = fSize;
    }
}


void KAppearanceOptions::slotMinimumFontSize( int i )
{
    fMinSize = i;
    if ( fMinSize > fSize ) {
        m_MedSize->setValue( fMinSize );
        fSize = fMinSize;
    }
}


void KAppearanceOptions::slotStandardFont(const TQString& n )
{
    fonts[0] = n;
}


void KAppearanceOptions::slotFixedFont(const TQString& n )
{
    fonts[1] = n;
}


void KAppearanceOptions::slotSerifFont( const TQString& n )
{
    fonts[2] = n;
}


void KAppearanceOptions::slotSansSerifFont( const TQString& n )
{
    fonts[3] = n;
}


void KAppearanceOptions::slotCursiveFont( const TQString& n )
{
    fonts[4] = n;
}


void KAppearanceOptions::slotFantasyFont( const TQString& n )
{
    fonts[5] = n;
}

void KAppearanceOptions::slotFontSizeAdjust( int value )
{
    fonts[6] = TQString::number( value );
}

void KAppearanceOptions::slotEncoding(const TQString& n)
{
    encodingName = n;
}

void KAppearanceOptions::load()
{
	load( false );
}

void KAppearanceOptions::load( bool useDefaults )
{
    TDEConfig tdehtmlrc("tdehtmlrc", true, false);
	 m_pConfig->setReadDefaults( useDefaults );

	 tdehtmlrc.setReadDefaults( useDefaults );

#define SET_GROUP(x) m_pConfig->setGroup(x); tdehtmlrc.setGroup(x)
#define READ_NUM(x,y) m_pConfig->readNumEntry(x, tdehtmlrc.readNumEntry(x, y))
#define READ_ENTRY(x,y) m_pConfig->readEntry(x, tdehtmlrc.readEntry(x, y))
#define READ_LIST(x) m_pConfig->readListEntry(x, tdehtmlrc.readListEntry(x))

    SET_GROUP(m_groupname);
    fSize = READ_NUM( "MediumFontSize", 12 );
    fMinSize = READ_NUM( "MinimumFontSize", HTML_DEFAULT_MIN_FONT_SIZE );
    if (fSize < fMinSize)
      fSize = fMinSize;

    defaultFonts = TQStringList();
    defaultFonts.append( READ_ENTRY( "StandardFont", TDEGlobalSettings::generalFont().family() ) );
    defaultFonts.append( READ_ENTRY( "FixedFont", TDEGlobalSettings::fixedFont().family() ) );
    defaultFonts.append( READ_ENTRY( "SerifFont", HTML_DEFAULT_VIEW_SERIF_FONT ) );
    defaultFonts.append( READ_ENTRY( "SansSerifFont", HTML_DEFAULT_VIEW_SANSSERIF_FONT ) );
    defaultFonts.append( READ_ENTRY( "CursiveFont", HTML_DEFAULT_VIEW_CURSIVE_FONT ) );
    defaultFonts.append( READ_ENTRY( "FantasyFont", HTML_DEFAULT_VIEW_FANTASY_FONT ) );
    defaultFonts.append( TQString("0") ); // default font size adjustment

    if (m_pConfig->hasKey("Fonts"))
       fonts = m_pConfig->readListEntry( "Fonts" );
    else
       fonts = tdehtmlrc.readListEntry( "Fonts" );
    while (fonts.count() < 7)
       fonts.append(TQString::null);

    encodingName = READ_ENTRY( "DefaultEncoding", TQString::null );
    //kdDebug(0) << "encoding = " << encodingName << endl;

    updateGUI();
    emit changed( useDefaults );

#undef SET_GROUP
#undef READ_NUM
#undef READ_ENTRY
#undef READ_LIST
}

void KAppearanceOptions::defaults()
{
	load( true );
}

void KAppearanceOptions::updateGUI()
{
    //kdDebug() << "KAppearanceOptions::updateGUI " << charset << endl;
    for ( int f = 0; f < 6; f++ ) {
        TQString ff = fonts[f];
        if (ff.isEmpty())
           ff = defaultFonts[f];
        m_pFonts[f]->setCurrentFont(ff);
    }

    int i = 0;
    for ( TQStringList::Iterator it = encodings.begin(); it != encodings.end(); ++it, ++i )
        if ( encodingName == *it )
            m_pEncoding->setCurrentItem( i );
    if(encodingName.isEmpty())
        m_pEncoding->setCurrentItem( 0 );
    m_pFontSizeAdjust->setValue( fonts[6].toInt() );
    m_MedSize->blockSignals(true);
    m_MedSize->setValue( fSize );
    m_MedSize->blockSignals(false);
    m_minSize->blockSignals(true);
    m_minSize->setValue( fMinSize );
    m_minSize->blockSignals(false);
}

void KAppearanceOptions::save()
{
    m_pConfig->setGroup(m_groupname);
    m_pConfig->writeEntry( "MediumFontSize", fSize );
    m_pConfig->writeEntry( "MinimumFontSize", fMinSize );
    m_pConfig->writeEntry( "Fonts", fonts );

    // If the user chose "Use language encoding", write an empty string
    if (encodingName == i18n("Use Language Encoding"))
        encodingName = "";
    m_pConfig->writeEntry( "DefaultEncoding", encodingName );
    m_pConfig->sync();

  TQByteArray data;
  if ( !kapp->dcopClient()->isAttached() )
    kapp->dcopClient()->attach();
  kapp->dcopClient()->send( "konqueror*", "KonquerorIface", "reparseConfiguration()", data );

  emit changed(false);
}