not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kcontrol / fonts / fonts.cpp
blob511e5f17f082673f901fc2622feed337fb372667
1 // KDE Display fonts setup tab
2 //
3 // Copyright (c) Mark Donohoe 1997
4 // lars Knoll 1999
5 // Rik Hemsley 2000
6 //
7 // Ported to kcontrol2 by Geert Jansen.
9 #include <config-workspace.h>
11 #include <QCheckBox>
12 #include <QComboBox>
13 #include <QDir>
14 #include <QLabel>
15 #include <QPushButton>
16 #include <QtCore/QSettings>
19 //Added by qt3to4:
20 #include <QPixmap>
21 #include <QByteArray>
22 #include <QGridLayout>
23 #include <QHBoxLayout>
24 #include <QVBoxLayout>
27 #include <kacceleratormanager.h>
28 #include <kapplication.h>
29 #include <kglobalsettings.h>
30 #include <kgenericfactory.h>
31 #include <kmessagebox.h>
32 #include <knuminput.h>
33 #include <kprocess.h>
34 #include <kconfig.h>
35 #include <kstandarddirs.h>
36 #include <stdlib.h>
38 #include "../krdb/krdb.h"
39 #include "fonts.h"
40 #include "fonts.moc"
42 #include <kdebug.h>
44 #ifdef HAVE_FREETYPE
45 #include <ft2build.h>
46 #ifdef FT_LCD_FILTER_H
47 #include FT_FREETYPE_H
48 #include FT_LCD_FILTER_H
49 #endif
50 #endif
52 #include <X11/Xlib.h>
53 #include <QX11Info>
55 #include <KPluginFactory>
57 // X11 headers
58 #undef Bool
59 #undef Unsorted
60 #undef None
62 static const char *aa_rgb_xpm[]={
63 "12 12 3 1",
64 "a c #0000ff",
65 "# c #00ff00",
66 ". c #ff0000",
67 "....####aaaa",
68 "....####aaaa",
69 "....####aaaa",
70 "....####aaaa",
71 "....####aaaa",
72 "....####aaaa",
73 "....####aaaa",
74 "....####aaaa",
75 "....####aaaa",
76 "....####aaaa",
77 "....####aaaa",
78 "....####aaaa"};
79 static const char *aa_bgr_xpm[]={
80 "12 12 3 1",
81 ". c #0000ff",
82 "# c #00ff00",
83 "a c #ff0000",
84 "....####aaaa",
85 "....####aaaa",
86 "....####aaaa",
87 "....####aaaa",
88 "....####aaaa",
89 "....####aaaa",
90 "....####aaaa",
91 "....####aaaa",
92 "....####aaaa",
93 "....####aaaa",
94 "....####aaaa",
95 "....####aaaa"};
96 static const char *aa_vrgb_xpm[]={
97 "12 12 3 1",
98 "a c #0000ff",
99 "# c #00ff00",
100 ". c #ff0000",
101 "............",
102 "............",
103 "............",
104 "............",
105 "############",
106 "############",
107 "############",
108 "############",
109 "aaaaaaaaaaaa",
110 "aaaaaaaaaaaa",
111 "aaaaaaaaaaaa",
112 "aaaaaaaaaaaa"};
113 static const char *aa_vbgr_xpm[]={
114 "12 12 3 1",
115 ". c #0000ff",
116 "# c #00ff00",
117 "a c #ff0000",
118 "............",
119 "............",
120 "............",
121 "............",
122 "############",
123 "############",
124 "############",
125 "############",
126 "aaaaaaaaaaaa",
127 "aaaaaaaaaaaa",
128 "aaaaaaaaaaaa",
129 "aaaaaaaaaaaa"};
131 static const char** aaPixmaps[]={ aa_rgb_xpm, aa_bgr_xpm, aa_vrgb_xpm, aa_vbgr_xpm };
133 /**** DLL Interface ****/
134 K_PLUGIN_FACTORY(FontFactory, registerPlugin<KFonts>(); )
135 K_EXPORT_PLUGIN(FontFactory("kcmfonts"))
137 /**** FontUseItem ****/
139 FontUseItem::FontUseItem(
140 QWidget * parent,
141 const QString &name,
142 const QString &grp,
143 const QString &key,
144 const QString &rc,
145 const QFont &default_fnt,
146 bool f
148 : KFontRequester(parent, f),
149 _rcfile(rc),
150 _rcgroup(grp),
151 _rckey(key),
152 _default(default_fnt)
154 KAcceleratorManager::setNoAccel( this );
155 setTitle( name );
156 readFont();
159 void FontUseItem::setDefault()
161 setFont( _default, isFixedOnly() );
164 void FontUseItem::readFont()
166 KConfig *config;
168 bool deleteme = false;
169 if (_rcfile.isEmpty())
170 config = KGlobal::config().data();
171 else
173 config = new KConfig(_rcfile);
174 deleteme = true;
177 KConfigGroup group(config, _rcgroup);
178 QFont tmpFnt(_default);
179 setFont( group.readEntry(_rckey, tmpFnt), isFixedOnly() );
180 if (deleteme) delete config;
183 void FontUseItem::writeFont()
185 KConfig *config;
187 if (_rcfile.isEmpty()) {
188 config = KGlobal::config().data();
189 KConfigGroup(config, _rcgroup).writeEntry(_rckey, font(), KConfig::Normal|KConfig::Global);
190 } else {
191 config = new KConfig(KStandardDirs::locateLocal("config", _rcfile));
192 KConfigGroup(config, _rcgroup).writeEntry(_rckey, font());
193 config->sync();
194 delete config;
198 void FontUseItem::applyFontDiff( const QFont &fnt, int fontDiffFlags )
200 QFont _font( font() );
202 if (fontDiffFlags & KFontChooser::FontDiffSize) {
203 _font.setPointSize( fnt.pointSize() );
205 if (fontDiffFlags & KFontChooser::FontDiffFamily) {
206 if (!isFixedOnly()) _font.setFamily( fnt.family() );
208 if (fontDiffFlags & KFontChooser::FontDiffStyle) {
209 _font.setBold( fnt.bold() );
210 _font.setItalic( fnt.italic() );
211 _font.setUnderline( fnt.underline() );
214 setFont( _font, isFixedOnly() );
217 /**** FontAASettings ****/
218 #ifdef HAVE_FONTCONFIG
219 FontAASettings::FontAASettings(QWidget *parent)
220 : KDialog( parent ),
221 changesMade(false)
223 setObjectName( "FontAASettings" );
224 setModal( true );
225 setCaption( i18n("Configure Anti-Alias Settings") );
226 setButtons( Ok|Cancel );
227 showButtonSeparator( true );
229 QWidget *mw=new QWidget(this);
230 QGridLayout *layout=new QGridLayout(mw);
231 layout->setSpacing(KDialog::spacingHint());
232 layout->setMargin(0);
234 excludeRange=new QCheckBox(i18n("E&xclude range:"), mw),
235 layout->addWidget(excludeRange, 0, 0);
236 excludeFrom=new KDoubleNumInput(0, 72, 8.0, mw,1, 1),
237 excludeFrom->setSuffix(i18n(" pt"));
238 layout->addWidget(excludeFrom, 0, 1);
239 excludeToLabel=new QLabel(i18n(" to "), mw);
240 layout->addWidget(excludeToLabel, 0, 2);
241 excludeTo=new KDoubleNumInput(0, 72, 15.0, mw, 1, 1);
242 excludeTo->setSuffix(i18n(" pt"));
243 layout->addWidget(excludeTo, 0, 3);
245 QString subPixelWhatsThis = i18n("<p>If you have a TFT or LCD screen you"
246 " can further improve the quality of displayed fonts by selecting"
247 " this option.<br />Sub-pixel rendering is also known as ClearType(tm).<br />"
248 " In order for sub-pixel rendering to"
249 " work correctly you need to know how the sub-pixels of your display"
250 " are aligned.</p>"
251 " <p>On TFT or LCD displays a single pixel is actually composed of"
252 " three sub-pixels, red, green and blue. Most displays"
253 " have a linear ordering of RGB sub-pixel, some have BGR.<br />"
254 " This feature does not work with CRT monitors.</p>" );
256 useSubPixel=new QCheckBox(i18n("&Use sub-pixel rendering:"), mw);
257 layout->addWidget(useSubPixel, 1, 0);
258 useSubPixel->setWhatsThis( subPixelWhatsThis );
260 subPixelType=new QComboBox(mw);
261 layout->addWidget(subPixelType, 1, 1, 1, 3);
263 subPixelType->setEditable(false);
264 subPixelType->setWhatsThis( subPixelWhatsThis );
266 for(int t=KXftConfig::SubPixel::None+1; t<=KXftConfig::SubPixel::Vbgr; ++t)
267 subPixelType->addItem(QPixmap(aaPixmaps[t-1]), i18n(KXftConfig::description((KXftConfig::SubPixel::Type)t).toUtf8()));
269 QLabel *hintingLabel=new QLabel(i18n("Hinting style: "), mw);
270 layout->addWidget(hintingLabel, 2, 0);
271 hintingStyle=new QComboBox(mw);
272 hintingStyle->setEditable(false);
273 layout->addWidget(hintingStyle, 2, 1, 1, 3);
274 for(int s=KXftConfig::Hint::NotSet+1; s<=KXftConfig::Hint::Full; ++s)
275 hintingStyle->addItem(i18n(KXftConfig::description((KXftConfig::Hint::Style)s).toUtf8()));
277 QString hintingText(i18n("Hinting is a process used to enhance the quality of fonts at small sizes."));
278 hintingStyle->setWhatsThis( hintingText);
279 hintingLabel->setWhatsThis( hintingText);
280 load();
281 enableWidgets();
282 setMainWidget(mw);
284 connect(excludeRange, SIGNAL(toggled(bool)), SLOT(changed()));
285 connect(useSubPixel, SIGNAL(toggled(bool)), SLOT(changed()));
286 connect(excludeFrom, SIGNAL(valueChanged(double)), SLOT(changed()));
287 connect(excludeTo, SIGNAL(valueChanged(double)), SLOT(changed()));
288 connect(subPixelType, SIGNAL(activated(const QString &)), SLOT(changed()));
289 connect(hintingStyle, SIGNAL(activated(const QString &)), SLOT(changed()));
292 bool FontAASettings::load()
294 double from, to;
295 KXftConfig xft(KXftConfig::constStyleSettings);
297 if(xft.getExcludeRange(from, to))
298 excludeRange->setChecked(true);
299 else
301 excludeRange->setChecked(false);
302 from=8.0;
303 to=15.0;
306 excludeFrom->setValue(from);
307 excludeTo->setValue(to);
309 KXftConfig::SubPixel::Type spType;
311 if(!xft.getSubPixelType(spType) || KXftConfig::SubPixel::None==spType)
312 useSubPixel->setChecked(false);
313 else
315 int idx=getIndex(spType);
317 if(idx>-1)
319 useSubPixel->setChecked(true);
320 subPixelType->setCurrentIndex(idx);
322 else
323 useSubPixel->setChecked(false);
326 KXftConfig::Hint::Style hStyle;
328 if(!xft.getHintStyle(hStyle) || KXftConfig::Hint::NotSet==hStyle)
330 KConfig kglobals("kdeglobals", KConfig::NoGlobals);
332 hStyle=KXftConfig::Hint::Medium;
333 xft.setHintStyle(hStyle);
334 xft.apply(); // Save this setting
335 KConfigGroup(&kglobals, "General").writeEntry("XftHintStyle", KXftConfig::toStr(hStyle));
336 kglobals.sync();
337 runRdb(KRdbExportXftSettings);
340 hintingStyle->setCurrentIndex(getIndex(hStyle));
342 enableWidgets();
344 return xft.getAntiAliasing();
347 bool FontAASettings::save( bool useAA )
349 KXftConfig xft(KXftConfig::constStyleSettings);
350 KConfig kglobals("kdeglobals", KConfig::NoGlobals);
351 KConfigGroup grp(&kglobals, "General");
353 xft.setAntiAliasing( useAA );
355 if(excludeRange->isChecked())
356 xft.setExcludeRange(excludeFrom->value(), excludeTo->value());
357 else
358 xft.setExcludeRange(0, 0);
360 KXftConfig::SubPixel::Type spType(useSubPixel->isChecked()
361 ? getSubPixelType()
362 : KXftConfig::SubPixel::None);
364 xft.setSubPixelType(spType);
365 grp.writeEntry("XftSubPixel", KXftConfig::toStr(spType));
366 grp.writeEntry("XftAntialias", useAA);
368 bool mod=false;
369 KXftConfig::Hint::Style hStyle(getHintStyle());
371 xft.setHintStyle(hStyle);
373 QString hs(KXftConfig::toStr(hStyle));
375 if(!hs.isEmpty() && hs!=grp.readEntry("XftHintStyle"))
377 grp.writeEntry("XftHintStyle", hs);
378 mod=true;
380 kglobals.sync();
382 if(!mod)
383 mod=xft.changed();
385 xft.apply();
387 return mod;
390 void FontAASettings::defaults()
392 excludeRange->setChecked(true);
393 excludeFrom->setValue(8.0);
394 excludeTo->setValue(15.0);
395 useSubPixel->setChecked(false);
396 hintingStyle->setCurrentIndex(getIndex(KXftConfig::Hint::Medium));
397 enableWidgets();
400 int FontAASettings::getIndex(KXftConfig::SubPixel::Type spType)
402 int pos=-1;
403 int index;
405 for(index=0; index<subPixelType->count(); ++index)
406 if(subPixelType->itemText(index)==i18n(KXftConfig::description(spType).toUtf8()))
408 pos=index;
409 break;
412 return pos;
415 KXftConfig::SubPixel::Type FontAASettings::getSubPixelType()
417 int t;
419 for(t=KXftConfig::SubPixel::None; t<=KXftConfig::SubPixel::Vbgr; ++t)
420 if(subPixelType->currentText()==i18n(KXftConfig::description((KXftConfig::SubPixel::Type)t).toUtf8()))
421 return (KXftConfig::SubPixel::Type)t;
423 return KXftConfig::SubPixel::None;
426 int FontAASettings::getIndex(KXftConfig::Hint::Style hStyle)
428 int pos=-1;
429 int index;
431 for(index=0; index<hintingStyle->count(); ++index)
432 if(hintingStyle->itemText(index)==i18n(KXftConfig::description(hStyle).toUtf8()))
434 pos=index;
435 break;
438 return pos;
442 KXftConfig::Hint::Style FontAASettings::getHintStyle()
444 int s;
446 for(s=KXftConfig::Hint::NotSet; s<=KXftConfig::Hint::Full; ++s)
447 if(hintingStyle->currentText()==i18n(KXftConfig::description((KXftConfig::Hint::Style)s).toUtf8()))
448 return (KXftConfig::Hint::Style)s;
450 return KXftConfig::Hint::Medium;
453 void FontAASettings::enableWidgets()
455 excludeFrom->setEnabled(excludeRange->isChecked());
456 excludeTo->setEnabled(excludeRange->isChecked());
457 excludeToLabel->setEnabled(excludeRange->isChecked());
458 subPixelType->setEnabled(useSubPixel->isChecked());
459 #ifdef FT_LCD_FILTER_H
460 static int ft_has_subpixel = -1;
461 if( ft_has_subpixel == -1 ) {
462 FT_Library ftLibrary;
463 if(FT_Init_FreeType(&ftLibrary) == 0) {
464 ft_has_subpixel = ( FT_Library_SetLcdFilter(ftLibrary, FT_LCD_FILTER_DEFAULT )
465 == FT_Err_Unimplemented_Feature ) ? 0 : 1;
466 FT_Done_FreeType(ftLibrary);
469 useSubPixel->setEnabled(ft_has_subpixel);
470 subPixelType->setEnabled(ft_has_subpixel);
471 #endif
473 #endif
475 void FontAASettings::changed()
477 #ifdef HAVE_FONTCONFIG
478 changesMade=true;
479 enableWidgets();
480 #endif
483 #ifdef HAVE_FONTCONFIG
484 int FontAASettings::exec()
486 int i=KDialog::exec();
488 if(!i)
489 load(); // Reset settings...
491 return i && changesMade;
493 #endif
495 /**** KFonts ****/
497 KFonts::KFonts(QWidget *parent, const QVariantList &args)
498 : KCModule(FontFactory::componentData(), parent, args)
500 QStringList nameGroupKeyRc;
502 nameGroupKeyRc
503 << i18n("General") << "General" << "font" << ""
504 << i18n("Fixed width") << "General" << "fixed" << ""
505 << i18n("Small") << "General" << "smallestReadableFont" << ""
506 << i18n("Toolbar") << "General" << "toolBarFont" << ""
507 << i18n("Menu") << "General" << "menuFont" << ""
508 << i18n("Window title") << "WM" << "activeFont" << ""
509 << i18n("Taskbar") << "General" << "taskbarFont" << ""
510 << i18n("Desktop") << "General" << "desktopFont" << "";
512 QList<QFont> defaultFontList;
514 // NOTE: keep in sync with kdelibs/kdeui/kernel/kglobalsettings.cpp
516 QFont f0("Sans Serif", 10);
517 QFont f1("Monospace", 10);
518 QFont f2("Sans Serif", 8);
519 QFont f3("Sans Serif", 9, QFont::Bold);
520 QFont f4("Sans Serif", 10);
521 QFont f5("Sans Serif", 8); // smallestReadableFont
523 defaultFontList << f0 << f1 << f5 << f2 << f0 << f3 << f4 << f0;
525 QList<bool> fixedList;
527 fixedList
528 << false
529 << true
530 << false
531 << false
532 << false
533 << false
534 << false
535 << false;
537 QStringList quickHelpList;
539 quickHelpList
540 << i18n("Used for normal text (e.g. button labels, list items).")
541 << i18n("A non-proportional font (i.e. typewriter font).")
542 << i18n("Smallest font that is still readable well.")
543 << i18n("Used to display text beside toolbar icons.")
544 << i18n("Used by menu bars and popup menus.")
545 << i18n("Used by the window titlebar.")
546 << i18n("Used by the taskbar.")
547 << i18n("Used for desktop icons.");
549 QVBoxLayout * layout = new QVBoxLayout(this );
550 layout->setSpacing( KDialog::spacingHint() );
551 layout->setMargin(0);
553 QGridLayout * fontUseLayout = new QGridLayout( );
554 layout->addItem( fontUseLayout );
555 fontUseLayout->setColumnStretch(0, 0);
556 fontUseLayout->setColumnStretch(1, 1);
557 fontUseLayout->setColumnStretch(2, 0);
559 QList<QFont>::ConstIterator defaultFontIt(defaultFontList.begin());
560 QList<bool>::ConstIterator fixedListIt(fixedList.begin());
561 QStringList::ConstIterator quickHelpIt(quickHelpList.begin());
562 QStringList::ConstIterator it(nameGroupKeyRc.begin());
564 unsigned int count = 0;
566 while (it != nameGroupKeyRc.constEnd()) {
568 QString name = *it; it++;
569 QString group = *it; it++;
570 QString key = *it; it++;
571 QString file = *it; it++;
573 FontUseItem * i =
574 new FontUseItem(
575 this,
576 name,
577 group,
578 key,
579 file,
580 *defaultFontIt++,
581 *fixedListIt++
584 fontUseList.append(i);
585 connect(i, SIGNAL(fontSelected(const QFont &)), SLOT(fontSelected()));
587 QLabel * fontUse = new QLabel(i18nc("Font role", "%1: ", name), this);
588 fontUse->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
589 fontUse->setWhatsThis( *quickHelpIt++);
591 fontUseLayout->addWidget(fontUse, count, 0);
592 fontUseLayout->addWidget(i, count, 1);
594 ++count;
597 QHBoxLayout *hblay = new QHBoxLayout();
598 layout->addItem(hblay);
599 hblay->setSpacing(KDialog::spacingHint());
600 hblay->addStretch();
601 QPushButton * fontAdjustButton = new QPushButton(i18n("Ad&just All Fonts..."), this);
602 fontAdjustButton->setWhatsThis( i18n("Click to change all fonts"));
603 hblay->addWidget( fontAdjustButton );
604 connect(fontAdjustButton, SIGNAL(clicked()), SLOT(slotApplyFontDiff()));
606 layout->addSpacing(KDialog::spacingHint());
608 QGridLayout* lay = new QGridLayout();
609 layout->addItem(lay);
610 lay->setColumnStretch( 3, 10 );
611 lay->setSpacing(KDialog::spacingHint());
612 QLabel* label=0L;
613 #ifdef HAVE_FONTCONFIG
614 label = new QLabel( i18n( "Use a&nti-aliasing:" ), this );
615 label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
616 lay->addWidget( label, 0, 0 );
617 cbAA = new QComboBox( this );
618 cbAA->insertItem( AAEnabled, i18nc( "Use anti-aliasing", "Enabled" )); // change AASetting type if order changes
619 cbAA->insertItem( AASystem, i18nc( "Use anti-aliasing", "System Settings" ));
620 cbAA->insertItem( AADisabled, i18nc( "Use anti-aliasing", "Disabled" ));
621 cbAA->setWhatsThis( i18n("If this option is selected, KDE will smooth the edges of curves in "
622 "fonts."));
623 aaSettingsButton = new QPushButton( i18n( "Configure..." ), this);
624 connect(aaSettingsButton, SIGNAL(clicked()), SLOT(slotCfgAa()));
625 label->setBuddy( cbAA );
626 lay->addWidget( cbAA, 0, 1 );
627 lay->addWidget( aaSettingsButton, 0, 2 );
628 connect(cbAA, SIGNAL(activated(int)), SLOT(slotUseAntiAliasing()));
629 #endif
630 label = new QLabel( i18n( "Force fonts DPI:" ), this );
631 label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
632 lay->addWidget( label, 1, 0 );
633 comboForceDpi = new QComboBox( this );
634 label->setBuddy( comboForceDpi );
635 comboForceDpi->insertItem( DPINone, i18nc("Force fonts DPI", "Disabled" )); // change DPISetti ng type if order changes
636 comboForceDpi->insertItem( DPI96, i18n( "96 DPI" ));
637 comboForceDpi->insertItem( DPI120, i18n( "120 DPI" ));
638 QString whatsthis = i18n(
639 "<p>This option forces a specific DPI value for fonts. It may be useful"
640 " when the real DPI of the hardware is not detected properly and it"
641 " is also often misused when poor quality fonts are used that do not"
642 " look well with DPI values other than 96 or 120 DPI.</p>"
643 "<p>The use of this option is generally discouraged. For selecting proper DPI"
644 " value a better option is explicitly configuring it for the whole X server if"
645 " possible (e.g. DisplaySize in xorg.conf or adding <i>-dpi value</i> to"
646 " ServerLocalArgs= in $KDEDIR/share/config/kdm/kdmrc). When fonts do not render"
647 " properly with real DPI value better fonts should be used or configuration"
648 " of font hinting should be checked.</p>" );
649 comboForceDpi->setWhatsThis(whatsthis);
650 connect( comboForceDpi, SIGNAL( activated( int )), SLOT( changed()));
651 lay->addWidget( comboForceDpi, 1, 1 );
653 layout->addStretch(1);
655 #ifdef HAVE_FONTCONFIG
656 aaSettings=new FontAASettings(this);
657 #endif
661 KFonts::~KFonts()
663 QList<FontUseItem *>::Iterator it(fontUseList.begin()),
664 end(fontUseList.end());
666 for(; it!=end; ++it)
667 delete (*it);
668 fontUseList.clear();
671 void KFonts::fontSelected()
673 emit changed(true);
676 void KFonts::defaults()
678 for ( int i = 0; i < (int) fontUseList.count(); i++ )
679 fontUseList.at( i )->setDefault();
681 #ifdef HAVE_FONTCONFIG
682 useAA = AASystem;
683 cbAA->setCurrentIndex( useAA );
684 aaSettings->defaults();
685 #endif
686 comboForceDpi->setCurrentIndex( DPINone );
687 emit changed(true);
690 void KFonts::load()
692 QList<FontUseItem *>::Iterator it(fontUseList.begin()),
693 end(fontUseList.end());
695 for(; it!=end; ++it)
696 (*it)->readFont();
698 #ifdef HAVE_FONTCONFIG
699 useAA_original = useAA = aaSettings->load() ? AAEnabled : AADisabled;
700 cbAA->setCurrentIndex( useAA );
701 #endif
703 KConfig _cfgfonts( "kcmfonts" );
704 KConfigGroup cfgfonts(&_cfgfonts, "General");
705 int dpicfg = cfgfonts.readEntry( "forceFontDPI", 0 );
706 DPISetting dpi = dpicfg == 120 ? DPI120 : dpicfg == 96 ? DPI96 : DPINone;
707 comboForceDpi->setCurrentIndex( dpi );
708 dpi_original = dpi;
709 #ifdef HAVE_FONTCONFIG
710 if( cfgfonts.readEntry( "dontChangeAASettings", true )) {
711 useAA_original = useAA = AASystem;
712 cbAA->setCurrentIndex( useAA );
714 aaSettingsButton->setEnabled( cbAA->currentIndex() == AAEnabled );
715 #endif
717 emit changed(false);
720 void KFonts::save()
722 QList<FontUseItem *>::Iterator it(fontUseList.begin()),
723 end(fontUseList.end());
725 for(; it!=end; ++it)
726 (*it)->writeFont();
728 KGlobal::config()->sync();
730 KConfig _cfgfonts( "kcmfonts" );
731 KConfigGroup cfgfonts(&_cfgfonts, "General");
732 DPISetting dpi = static_cast< DPISetting >( comboForceDpi->currentIndex());
733 const int dpi2value[] = { 0, 96, 120 };
734 cfgfonts.writeEntry( "forceFontDPI", dpi2value[ dpi ] );
735 #ifdef HAVE_FONTCONFIG
736 cfgfonts.writeEntry( "dontChangeAASettings", cbAA->currentIndex() == AASystem );
737 #endif
738 cfgfonts.sync();
739 // if the setting is reset in the module, remove the dpi value,
740 // otherwise don't explicitly remove it and leave any possible system-wide value
741 if( dpi == DPINone && dpi_original != DPINone ) {
742 KProcess proc;
743 proc << "xrdb" << "-quiet" << "-remove" << "-nocpp";
744 proc.start();
745 if (proc.waitForStarted()) {
746 proc.write( QByteArray( "Xft.dpi\n" ) );
747 proc.closeWriteChannel();
748 proc.waitForFinished();
752 // KDE-1.x support
754 KConfig config( QDir::homePath() + "/.kderc", KConfig::SimpleConfig);
755 KConfigGroup grp(&config, "General");
757 for(it=fontUseList.begin(); it!=end; ++it) {
758 if("font"==(*it)->rcKey())
759 QSettings().setValue("/qt/font", (*it)->font().toString());
760 kDebug(1208) << "write entry " << (*it)->rcKey();
761 grp.writeEntry( (*it)->rcKey(), (*it)->font() );
763 config.sync();
766 KGlobalSettings::self()->emitChange(KGlobalSettings::FontChanged);
768 kapp->processEvents(); // Process font change ourselves
771 // Don't overwrite global settings unless explicitly asked for - e.g. the system
772 // fontconfig setup may be much more complex than this module can provide.
773 // TODO: With AASystem the changes already made by this module should be reverted somehow.
774 #ifdef HAVE_FONTCONFIG
775 bool aaSave = false;
776 if( cbAA->currentIndex() != AASystem )
777 aaSave = aaSettings->save( useAA == AAEnabled );
779 if( aaSave || (useAA != useAA_original) || dpi != dpi_original) {
780 KMessageBox::information(this,
781 i18n(
782 "<p>Some changes such as anti-aliasing will only affect newly started applications.</p>"
783 ), i18n("Font Settings Changed"), "FontSettingsChanged", false);
784 useAA_original = useAA;
785 dpi_original = dpi;
787 #else
788 if(dpi != dpi_original) {
789 KMessageBox::information(this,
790 i18n(
791 "<p>Some changes such as DPI will only affect newly started applications.</p>"
792 ), i18n("Font Settings Changed"), "FontSettingsChanged", false);
793 dpi_original = dpi;
795 #endif
796 runRdb(KRdbExportXftSettings);
798 emit changed(false);
802 void KFonts::slotApplyFontDiff()
804 QFont font = QFont(fontUseList.first()->font());
805 KFontChooser::FontDiffFlags fontDiffFlags = 0;
806 int ret = KFontDialog::getFontDiff(font,fontDiffFlags,KFontChooser::NoDisplayFlags,this);
808 if (ret == KDialog::Accepted && fontDiffFlags)
810 for ( int i = 0; i < (int) fontUseList.count(); i++ )
811 fontUseList.at( i )->applyFontDiff( font,fontDiffFlags );
812 emit changed(true);
816 void KFonts::slotUseAntiAliasing()
818 #ifdef HAVE_FONTCONFIG
819 useAA = static_cast< AASetting >( cbAA->currentIndex());
820 aaSettingsButton->setEnabled( cbAA->currentIndex() == AAEnabled );
821 emit changed(true);
822 #endif
825 void KFonts::slotCfgAa()
827 #ifdef HAVE_FONTCONFIG
828 if(aaSettings->exec())
830 emit changed(true);
832 #endif
835 // vim:ts=2:sw=2:tw=78