diff --git a/kcms/fonts/fonts.cpp b/kcms/fonts/fonts.cpp index 7d9001251..543e20655 100644 --- a/kcms/fonts/fonts.cpp +++ b/kcms/fonts/fonts.cpp @@ -1,892 +1,892 @@ /* Copyright 1997 Mark Donohoe Copyright 1999 Lars Knoll Copyright 2000 Rik Hemsley Ported to kcontrol2 by Geert Jansen. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include "fonts.h" #include #include #include #include #include #include #include #include #include #include #include //Added by qt3to4: #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "../krdb/krdb.h" #ifdef HAVE_FREETYPE #include #ifdef FT_LCD_FILTER_H #include FT_FREETYPE_H #include FT_LCD_FILTER_H #endif #endif #if HAVE_X11 #include #endif #if HAVE_X11 // X11 headers #undef Bool #undef Unsorted #undef None #endif static const char *const aa_rgb_xpm[] = { "12 12 3 1", "a c #0000ff", "# c #00ff00", ". c #ff0000", "....####aaaa", "....####aaaa", "....####aaaa", "....####aaaa", "....####aaaa", "....####aaaa", "....####aaaa", "....####aaaa", "....####aaaa", "....####aaaa", "....####aaaa", "....####aaaa" }; static const char *const aa_bgr_xpm[] = { "12 12 3 1", ". c #0000ff", "# c #00ff00", "a c #ff0000", "....####aaaa", "....####aaaa", "....####aaaa", "....####aaaa", "....####aaaa", "....####aaaa", "....####aaaa", "....####aaaa", "....####aaaa", "....####aaaa", "....####aaaa", "....####aaaa" }; static const char *const aa_vrgb_xpm[] = { "12 12 3 1", "a c #0000ff", "# c #00ff00", ". c #ff0000", "............", "............", "............", "............", "############", "############", "############", "############", "aaaaaaaaaaaa", "aaaaaaaaaaaa", "aaaaaaaaaaaa", "aaaaaaaaaaaa" }; static const char *const aa_vbgr_xpm[] = { "12 12 3 1", ". c #0000ff", "# c #00ff00", "a c #ff0000", "............", "............", "............", "............", "############", "############", "############", "############", "aaaaaaaaaaaa", "aaaaaaaaaaaa", "aaaaaaaaaaaa", "aaaaaaaaaaaa" }; static const char *const *const aaPixmaps[] = { 0, 0, aa_rgb_xpm, aa_bgr_xpm, aa_vrgb_xpm, aa_vbgr_xpm }; /**** DLL Interface ****/ K_PLUGIN_FACTORY(FontFactory, registerPlugin();) /**** FontUseItem ****/ FontUseItem::FontUseItem( QWidget *parent, const QString &name, const QString &grp, const QString &key, const QString &rc, const QFont &default_fnt, bool f ) : KFontRequester(parent, f), _rcfile(rc), _rcgroup(grp), _rckey(key), _default(default_fnt) { KAcceleratorManager::setNoAccel(this); setTitle(name); readFont(); } void FontUseItem::setDefault() { setFont(_default, isFixedOnly()); } void FontUseItem::readFont() { const KConfig *config = KSharedConfig::openConfig(_rcfile).data(); const KConfigGroup group(config, _rcgroup); QFont tmpFnt(_default); setFont(group.readEntry(_rckey, tmpFnt), isFixedOnly()); } void FontUseItem::writeFont() { KConfig *config = KSharedConfig::openConfig(_rcfile).data(); if (_rcfile.isEmpty()) { KConfigGroup(config, _rcgroup).writeEntry(_rckey, font(), KConfig::Normal | KConfig::Global); } else { KConfigGroup(config, _rcgroup).writeEntry(_rckey, font()); config->sync(); } } void FontUseItem::applyFontDiff(const QFont &fnt, int fontDiffFlags) { QFont _font(font()); if (fontDiffFlags & KFontChooser::FontDiffSize) { _font.setPointSizeF(fnt.pointSizeF()); } if (fontDiffFlags & KFontChooser::FontDiffFamily) { if (!isFixedOnly() || QFontInfo(fnt).fixedPitch()) { _font.setFamily(fnt.family()); } } if (fontDiffFlags & KFontChooser::FontDiffStyle) { _font.setWeight(fnt.weight()); _font.setStyle(fnt.style()); _font.setUnderline(fnt.underline()); #if QT_VERSION >= 0x040800 _font.setStyleName(fnt.styleName()); #endif } setFont(_font, isFixedOnly()); } /**** FontAASettings ****/ #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) FontAASettings::FontAASettings(QWidget *parent) : QDialog(parent), changesMade(false) { setObjectName("FontAASettings"); setModal(true); setWindowTitle(i18n("Configure Anti-Alias Settings")); QVBoxLayout *mainLayout = new QVBoxLayout(this); QFormLayout *layout = new QFormLayout(); layout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow); excludeRange = new QCheckBox(i18n("E&xclude range:"), this); QHBoxLayout *rangeLayout = new QHBoxLayout(); excludeFrom = new QDoubleSpinBox(this); excludeFrom->setRange(0.0, 72.0); excludeFrom->setValue(8.0); excludeFrom->setSingleStep(1.0); excludeFrom->setDecimals(1); excludeFrom->setSuffix(i18nc("abbreviation for unit of points", " pt")); rangeLayout->addWidget(excludeFrom); excludeToLabel = new QLabel(i18n(" to "), this); rangeLayout->addWidget(excludeToLabel); excludeTo = new QDoubleSpinBox(this); excludeTo->setRange(0.0, 72.0); excludeTo->setValue(15.0); excludeTo->setSingleStep(1.0); excludeTo->setDecimals(1); excludeTo->setSuffix(i18nc("abbreviation for unit of points", " pt")); rangeLayout->addWidget(excludeTo); layout->addRow(excludeRange, rangeLayout); QString subPixelWhatsThis = i18n("

If you have a TFT or LCD screen you" " can further improve the quality of displayed fonts by selecting" " this option.
Sub-pixel rendering is also known as ClearType(tm).
" " In order for sub-pixel rendering to" " work correctly you need to know how the sub-pixels of your display" " are aligned.

" "

On TFT or LCD displays a single pixel is actually composed of" " three sub-pixels, red, green and blue. Most displays" " have a linear ordering of RGB sub-pixel, some have BGR.
" " This feature does not work with CRT monitors.

"); subPixelLabel = new QLabel(i18n("Sub-pixel rendering type:"), this); subPixelLabel->setWhatsThis(subPixelWhatsThis); subPixelType = new QComboBox(this); layout->addRow(subPixelLabel, subPixelType); subPixelType->setEditable(false); subPixelType->setWhatsThis(subPixelWhatsThis); for (int t = KXftConfig::SubPixel::NotSet; t <= KXftConfig::SubPixel::Vbgr; ++t) { subPixelType->addItem(QPixmap(aaPixmaps[t]), i18n(KXftConfig::description((KXftConfig::SubPixel::Type)t).toUtf8())); } QLabel *hintingLabel = new QLabel(i18n("Hinting style:"), this); hintingStyle = new QComboBox(this); hintingStyle->setEditable(false); layout->addRow(hintingLabel, hintingStyle); for (int s = KXftConfig::Hint::NotSet; s <= KXftConfig::Hint::Full; ++s) { hintingStyle->addItem(i18n(KXftConfig::description((KXftConfig::Hint::Style)s).toUtf8())); } QString hintingText(i18n("Hinting is a process used to enhance the quality of fonts at small sizes.")); hintingStyle->setWhatsThis(hintingText); hintingLabel->setWhatsThis(hintingText); load(); enableWidgets(); QHBoxLayout *outerLayout = new QHBoxLayout(); outerLayout->addLayout(layout); outerLayout->addStretch(1); mainLayout->addLayout(outerLayout); mainLayout->addStretch(1); mainLayout->addSpacing(style()->pixelMetric(QStyle::PM_LayoutBottomMargin)); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, this); buttonBox->button(QDialogButtonBox::Ok)->setShortcut(Qt::CTRL|Qt::Key_Return); connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); mainLayout->addWidget(buttonBox); connect(excludeRange, &QAbstractButton::toggled, this, &FontAASettings::changed); connect(excludeFrom, static_cast(&QDoubleSpinBox::valueChanged), this, &FontAASettings::changed); connect(excludeTo, static_cast(&QDoubleSpinBox::valueChanged), this, &FontAASettings::changed); connect(subPixelType, static_cast(&QComboBox::activated), this, &FontAASettings::changed); connect(hintingStyle, static_cast(&QComboBox::activated), this, &FontAASettings::changed); } bool FontAASettings::load() { double from, to; KXftConfig xft; if (xft.getExcludeRange(from, to)) { excludeRange->setChecked(true); } else { excludeRange->setChecked(false); from = 8.0; to = 15.0; } excludeFrom->setValue(from); excludeTo->setValue(to); KXftConfig::SubPixel::Type spType; xft.getSubPixelType(spType); int idx = getIndex(spType); subPixelType->setCurrentIndex(idx); KXftConfig::Hint::Style hStyle; if (!xft.getHintStyle(hStyle) || KXftConfig::Hint::NotSet == hStyle) { hStyle = KXftConfig::Hint::NotSet; xft.setHintStyle(hStyle); runRdb(KRdbExportXftSettings | KRdbExportGtkTheme); } hintingStyle->setCurrentIndex(getIndex(hStyle)); enableWidgets(); return xft.aliasingEnabled(); } bool FontAASettings::save(KXftConfig::AntiAliasing::State aaState) { KXftConfig xft; KConfig kglobals("kdeglobals", KConfig::NoGlobals); KConfigGroup grp(&kglobals, "General"); xft.setAntiAliasing(aaState); if (excludeRange->isChecked()) { xft.setExcludeRange(excludeFrom->value(), excludeTo->value()); } else { xft.setExcludeRange(0, 0); } KXftConfig::SubPixel::Type spType(getSubPixelType()); xft.setSubPixelType(spType); if (KXftConfig::SubPixel::NotSet == spType) { grp.revertToDefault("XftSubPixel"); } else { grp.writeEntry("XftSubPixel", KXftConfig::toStr(spType)); } if (KXftConfig::AntiAliasing::NotSet == aaState) { grp.revertToDefault("XftAntialias"); } else { grp.writeEntry("XftAntialias", aaState == KXftConfig::AntiAliasing::Enabled); } bool mod = false; KXftConfig::Hint::Style hStyle(getHintStyle()); xft.setHintStyle(hStyle); QString hs(KXftConfig::toStr(hStyle)); if (hs != grp.readEntry("XftHintStyle")) { if (KXftConfig::Hint::NotSet == hStyle) { grp.revertToDefault("XftHintStyle"); } else { grp.writeEntry("XftHintStyle", hs); } } mod = true; kglobals.sync(); if (!mod) { mod = xft.changed(); } xft.apply(); return mod; } void FontAASettings::defaults() { excludeRange->setChecked(false); excludeFrom->setValue(8.0); excludeTo->setValue(15.0); subPixelType->setCurrentIndex(getIndex(KXftConfig::SubPixel::NotSet)); hintingStyle->setCurrentIndex(getIndex(KXftConfig::Hint::NotSet)); enableWidgets(); } int FontAASettings::getIndex(KXftConfig::SubPixel::Type spType) { int pos = -1; int index; for (index = 0; index < subPixelType->count(); ++index) if (subPixelType->itemText(index) == i18n(KXftConfig::description(spType).toUtf8())) { pos = index; break; } return pos; } KXftConfig::SubPixel::Type FontAASettings::getSubPixelType() { int t; for (t = KXftConfig::SubPixel::NotSet; t <= KXftConfig::SubPixel::Vbgr; ++t) if (subPixelType->currentText() == i18n(KXftConfig::description((KXftConfig::SubPixel::Type)t).toUtf8())) { return (KXftConfig::SubPixel::Type)t; } return KXftConfig::SubPixel::NotSet; } int FontAASettings::getIndex(KXftConfig::Hint::Style hStyle) { int pos = -1; int index; for (index = 0; index < hintingStyle->count(); ++index) if (hintingStyle->itemText(index) == i18n(KXftConfig::description(hStyle).toUtf8())) { pos = index; break; } return pos; } KXftConfig::Hint::Style FontAASettings::getHintStyle() { int s; for (s = KXftConfig::Hint::NotSet; s <= KXftConfig::Hint::Full; ++s) if (hintingStyle->currentText() == i18n(KXftConfig::description((KXftConfig::Hint::Style)s).toUtf8())) { return (KXftConfig::Hint::Style)s; } return KXftConfig::Hint::Medium; } void FontAASettings::enableWidgets() { excludeFrom->setEnabled(excludeRange->isChecked()); excludeTo->setEnabled(excludeRange->isChecked()); excludeToLabel->setEnabled(excludeRange->isChecked()); #ifdef FT_LCD_FILTER_H static int ft_has_subpixel = -1; if (ft_has_subpixel == -1) { FT_Library ftLibrary; if (FT_Init_FreeType(&ftLibrary) == 0) { ft_has_subpixel = (FT_Library_SetLcdFilter(ftLibrary, FT_LCD_FILTER_DEFAULT) == FT_Err_Unimplemented_Feature) ? 0 : 1; FT_Done_FreeType(ftLibrary); } } subPixelType->setEnabled(ft_has_subpixel); #endif } #endif void FontAASettings::changed() { #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) changesMade = true; enableWidgets(); #endif } #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) int FontAASettings::exec() { const int i = QDialog::exec(); if (!i) { load(); // Reset settings... } return i && changesMade; } #endif /**** KFonts ****/ KFonts::KFonts(QWidget *parent, const QVariantList &args) : KCModule(parent, args) { QStringList nameGroupKeyRc; nameGroupKeyRc << i18nc("font usage", "General") << "General" << "font" << "" << i18nc("font usage", "Fixed width") << "General" << "fixed" << "" << i18nc("font usage", "Small") << "General" << "smallestReadableFont" << "" << i18nc("font usage", "Toolbar") << "General" << "toolBarFont" << "" << i18nc("font usage", "Menu") << "General" << "menuFont" << "" << i18nc("font usage", "Window title") << "WM" << "activeFont" << ""; QList defaultFontList; // NOTE: keep in sync with plasma-integration/src/platformtheme/kfontsettingsdata.cpp #ifdef Q_OS_MACOS QFont f0("Lucida Grande", 13); // general/menu/desktop QFont f1("Monaco", 10); QFont f2("Lucida Grande", 11); // toolbar #elif defined(Q_WS_MAEMO_5) || defined(MEEGO_EDITION_HARMATTAN) QFont f0("Sans Serif", 16); // general/menu/desktop QFont f1("Monospace", 16; QFont f2("Sans Serif", 16); // toolbar #else QFont f0("Noto Sans", 10); // general/menu/desktop QFont f1("Hack", 9); // fixed font QFont f2("Noto Sans", 10); // toolbar #endif #ifdef Q_OS_MACOS QFont f3("Lucida Grande", 14); // window title QFont f5("Lucida Grande", 9); // smallestReadableFont #else QFont f3("Noto Sans", 10); // window title QFont f5("Noto Sans", 8); // smallestReadableFont #endif defaultFontList << f0 << f1 << f5 << f2 << f0 << f3; QList fixedList; fixedList << false << true << false << false << false << false; QStringList quickHelpList; quickHelpList << i18n("Used for normal text (e.g. button labels, list items).") << i18n("A non-proportional font (i.e. typewriter font).") << i18n("Smallest font that is still readable well.") << i18n("Used to display text beside toolbar icons.") << i18n("Used by menu bars and popup menus.") << i18n("Used by the window titlebar."); QVBoxLayout *layout = new QVBoxLayout(this); layout->setMargin(0); QGridLayout *fontUseLayout = new QGridLayout(); layout->addLayout(fontUseLayout); fontUseLayout->setColumnStretch(0, 0); fontUseLayout->setColumnStretch(1, 1); fontUseLayout->setColumnStretch(2, 0); QList::ConstIterator defaultFontIt(defaultFontList.begin()); QList::ConstIterator fixedListIt(fixedList.begin()); QStringList::ConstIterator quickHelpIt(quickHelpList.begin()); QStringList::ConstIterator it(nameGroupKeyRc.begin()); unsigned int count = 0; while (it != nameGroupKeyRc.constEnd()) { QString name = *it; it++; QString group = *it; it++; QString key = *it; it++; QString file = *it; it++; FontUseItem *i = new FontUseItem( this, name, group, key, file, *defaultFontIt++, *fixedListIt++ ); fontUseList.append(i); connect(i, &KFontRequester::fontSelected, this, &KFonts::fontSelected); QLabel *fontUse = new QLabel(i18nc("Font role", "%1: ", name), this); fontUse->setAlignment(Qt::AlignRight | Qt::AlignVCenter); fontUse->setWhatsThis(*quickHelpIt++); fontUse->setBuddy(i); fontUseLayout->addWidget(fontUse, count, 0); fontUseLayout->addWidget(i, count, 1); ++count; } QHBoxLayout *hblay = new QHBoxLayout(); layout->addLayout(hblay); hblay->addStretch(); QPushButton *fontAdjustButton = new QPushButton(i18n("Ad&just All Fonts..."), this); fontAdjustButton->setWhatsThis(i18n("Click to change all fonts")); hblay->addWidget(fontAdjustButton); connect(fontAdjustButton, &QAbstractButton::clicked, this, &KFonts::slotApplyFontDiff); layout->addSpacing(style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)); QGridLayout *lay = new QGridLayout(); layout->addLayout(lay); lay->setColumnStretch(3, 10); #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) QLabel *label = 0L; label = new QLabel(i18n("Use a&nti-aliasing:"), this); label->setAlignment(Qt::AlignRight | Qt::AlignVCenter); lay->addWidget(label, 0, 0); cbAA = new QComboBox(this); cbAA->insertItem(AAEnabled, i18nc("Use anti-aliasing", "Enabled")); // change AASetting type if order changes cbAA->insertItem(AASystem, i18nc("Use anti-aliasing", "System Settings")); cbAA->insertItem(AADisabled, i18nc("Use anti-aliasing", "Disabled")); cbAA->setWhatsThis(i18n("Select this option to smooth the edges of curves in fonts.")); aaSettingsButton = new QPushButton(i18n("Configure..."), this); connect(aaSettingsButton, &QAbstractButton::clicked, this, &KFonts::slotCfgAa); label->setBuddy(cbAA); lay->addWidget(cbAA, 0, 1); lay->addWidget(aaSettingsButton, 0, 2); // Initialize aaSettingsButton state based on the current cbAA->currentIndex value, will be eventually updated at load() slotUseAntiAliasing(); connect(cbAA, SIGNAL(currentIndexChanged(int)), SLOT(slotUseAntiAliasing())); #endif checkboxForceDpi = new QCheckBox(i18n("Force fonts DPI:"), this); lay->addWidget(checkboxForceDpi, 1, 0); spinboxDpi = new QSpinBox(this); spinboxDpi->setRange(1, 1000); spinboxDpi->setSingleStep(24); // The common DPI values 72, 96 and 120 are multiples of 24 QString whatsthis = i18n( "

This option forces a specific DPI value for fonts. It may be useful" " when the real DPI of the hardware is not detected properly and it" " is also often misused when poor quality fonts are used that do not" " look well with DPI values other than 96 or 120 DPI.

" "

The use of this option is generally discouraged. For selecting proper DPI" " value a better option is explicitly configuring it for the whole X server if" " possible (e.g. DisplaySize in xorg.conf). When fonts do not render" " properly with real DPI value better fonts should be used or configuration" " of font hinting should be checked.

"); spinboxDpi->setWhatsThis(whatsthis); #if !defined(HAVE_X11) || !HAVE_X11 QString nothere = i18n("This property has no effect on this platform"); spinboxDpi->setToolTip(nothere); checkboxForceDpi->setToolTip(nothere); #endif checkboxForceDpi->setChecked(false); spinboxDpi->setEnabled(false); connect(spinboxDpi, SIGNAL(valueChanged(int)), SLOT(changed())); connect(checkboxForceDpi, SIGNAL(toggled(bool)), SLOT(changed())); connect(checkboxForceDpi, &QAbstractButton::toggled, spinboxDpi, &QWidget::setEnabled); lay->addWidget(spinboxDpi, 1, 1); layout->addStretch(1); #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) aaSettings = new FontAASettings(this); #endif } KFonts::~KFonts() { QList::Iterator it(fontUseList.begin()), end(fontUseList.end()); for (; it != end; ++it) { delete(*it); } fontUseList.clear(); } void KFonts::fontSelected() { emit changed(true); } void KFonts::defaults() { for (int i = 0; i < (int) fontUseList.count(); i++) { fontUseList.at(i)->setDefault(); } #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) useAA = AASystem; cbAA->setCurrentIndex(useAA); aaSettings->defaults(); #endif checkboxForceDpi->setChecked(false); spinboxDpi->setValue(96); emit changed(true); } void KFonts::load() { QList::Iterator it(fontUseList.begin()), end(fontUseList.end()); for (; it != end; ++it) { (*it)->readFont(); } #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) useAA_original = useAA = aaSettings->load() ? AAEnabled : AADisabled; cbAA->setCurrentIndex(useAA); #endif KConfig _cfgfonts("kcmfonts"); KConfigGroup cfgfonts(&_cfgfonts, "General"); int dpicfg; if (KWindowSystem::isPlatformWayland()) { dpicfg = cfgfonts.readEntry("forceFontDPIWayland", 0); } else { dpicfg = cfgfonts.readEntry("forceFontDPI", 0); } if (dpicfg <= 0) { checkboxForceDpi->setChecked(false); spinboxDpi->setValue(96); dpi_original = 0; } else { checkboxForceDpi->setChecked(true); spinboxDpi->setValue(dpicfg); dpi_original = dpicfg; }; #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) if (cfgfonts.readEntry("dontChangeAASettings", true)) { useAA_original = useAA = AASystem; cbAA->setCurrentIndex(useAA); } #endif emit changed(false); } void KFonts::save() { QList::Iterator it(fontUseList.begin()), end(fontUseList.end()); for (; it != end; ++it) { (*it)->writeFont(); } KSharedConfig::openConfig()->sync(); KConfig _cfgfonts("kcmfonts"); KConfigGroup cfgfonts(&_cfgfonts, "General"); int dpi = (checkboxForceDpi->isChecked() ? spinboxDpi->value() : 0); if (KWindowSystem::isPlatformWayland()) { cfgfonts.writeEntry("forceFontDPIWayland", dpi); } else { cfgfonts.writeEntry("forceFontDPI", dpi); } #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) cfgfonts.writeEntry("dontChangeAASettings", cbAA->currentIndex() == AASystem); #endif cfgfonts.sync(); #if HAVE_X11 // if the setting is reset in the module, remove the dpi value, // otherwise don't explicitly remove it and leave any possible system-wide value - if (dpi == 0 && dpi_original != 0) { + if (dpi == 0 && dpi_original != 0 && !KWindowSystem::isPlatformWayland()) { QProcess proc; proc.setProcessChannelMode(QProcess::ForwardedChannels); proc.start("xrdb", QStringList() << "-quiet" << "-remove" << "-nocpp"); if (proc.waitForStarted()) { proc.write(QByteArray("Xft.dpi\n")); proc.closeWriteChannel(); proc.waitForFinished(); } } #endif KGlobalSettings::self()->emitChange(KGlobalSettings::FontChanged); QApplication::processEvents(); // Process font change ourselves // Don't overwrite global settings unless explicitly asked for - e.g. the system // fontconfig setup may be much more complex than this module can provide. // TODO: With AASystem the changes already made by this module should be reverted somehow. #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) bool aaSave = false; if (cbAA->currentIndex() == AAEnabled ) { aaSave = aaSettings->save(KXftConfig::AntiAliasing::Enabled); } else if (cbAA->currentIndex() == AADisabled) { aaSave = aaSettings->save(KXftConfig::AntiAliasing::Disabled); } else { // If AASystem is selected, this removes all fontconfig settings made by // this module. aaSettings->defaults(); aaSave = aaSettings->save(KXftConfig::AntiAliasing::NotSet); } if (aaSave || (useAA != useAA_original) || dpi != dpi_original) { KMessageBox::information(this, i18n( "

Some changes such as anti-aliasing or DPI will only affect newly started applications.

" ), i18n("Font Settings Changed"), "FontSettingsChanged"); useAA_original = useAA; dpi_original = dpi; } #else #if HAVE_X11 if (dpi != dpi_original) { KMessageBox::information(this, i18n( "

Some changes such as DPI will only affect newly started applications.

" ), i18n("Font Settings Changed"), "FontSettingsChanged"); dpi_original = dpi; } #endif #endif runRdb(KRdbExportXftSettings | KRdbExportGtkTheme); emit changed(false); } void KFonts::slotApplyFontDiff() { QFont font = QFont(fontUseList.first()->font()); KFontChooser::FontDiffFlags fontDiffFlags = 0; int ret = KFontDialog::getFontDiff(font, fontDiffFlags, KFontChooser::NoDisplayFlags, this); if (ret == KDialog::Accepted && fontDiffFlags) { for (int i = 0; i < (int) fontUseList.count(); i++) { fontUseList.at(i)->applyFontDiff(font, fontDiffFlags); } emit changed(true); } } void KFonts::slotUseAntiAliasing() { #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) useAA = static_cast< AASetting >(cbAA->currentIndex()); aaSettingsButton->setEnabled(useAA == AAEnabled); emit changed(true); #endif } void KFonts::slotCfgAa() { #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) if (aaSettings->exec()) { emit changed(true); } #endif } #include "fonts.moc" diff --git a/kcms/krdb/krdb.cpp b/kcms/krdb/krdb.cpp index dd517d438..6d9e81beb 100644 --- a/kcms/krdb/krdb.cpp +++ b/kcms/krdb/krdb.cpp @@ -1,727 +1,730 @@ /**************************************************************************** ** ** ** KRDB - puts current KDE color scheme into preprocessor statements ** cats specially written application default files and uses xrdb -merge to ** write to RESOURCE_MANAGER. Thus it gives a simple way to make non-KDE ** applications fit in with the desktop ** ** Copyright (C) 1998 by Mark Donohoe ** Copyright (C) 1999 by Dirk A. Mueller (reworked for KDE 2.0) ** Copyright (C) 2001 by Matthias Ettrich (add support for GTK applications ) ** Copyright (C) 2001 by Waldo Bastian ** Copyright (C) 2002 by Karol Szwed ** This application is freely distributable under the GNU Public License. ** *****************************************************************************/ #include #include #include #include #include #include #undef Unsorted #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "krdb.h" #if HAVE_X11 #include #include #endif inline const char * gtkEnvVar(int version) { return 2==version ? "GTK2_RC_FILES" : "GTK_RC_FILES"; } inline const char * sysGtkrc(int version) { if(2==version) { if(access("/etc/opt/gnome/gtk-2.0", F_OK) == 0) return "/etc/opt/gnome/gtk-2.0/gtkrc"; else return "/etc/gtk-2.0/gtkrc"; } else { if(access("/etc/opt/gnome/gtk", F_OK) == 0) return "/etc/opt/gnome/gtk/gtkrc"; else return "/etc/gtk/gtkrc"; } } inline const char * userGtkrc(int version) { return 2==version ? "/.gtkrc-2.0" : "/.gtkrc"; } // ----------------------------------------------------------------------------- static QString writableGtkrc(int version) { QString gtkrc = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); QDir dir; dir.mkpath(gtkrc); gtkrc += 2==version?"/gtkrc-2.0":"/gtkrc"; return gtkrc; } // ----------------------------------------------------------------------------- static void applyGtkStyles(bool active, int version) { QString gtkkde = writableGtkrc(version); QByteArray gtkrc = getenv(gtkEnvVar(version)); QStringList list = QFile::decodeName(gtkrc).split( ':'); QString userHomeGtkrc = QDir::homePath()+userGtkrc(version); if (!list.contains(userHomeGtkrc)) list.prepend(userHomeGtkrc); QLatin1String systemGtkrc = QLatin1String(sysGtkrc(version)); if (!list.contains(systemGtkrc)) list.prepend(systemGtkrc); list.removeAll(QLatin1String("")); list.removeAll(gtkkde); list.append(gtkkde); // Pass env. var to kdeinit. QString name = gtkEnvVar(version); QString value = list.join(QStringLiteral(":")); org::kde::KLauncher klauncher(QStringLiteral("org.kde.klauncher5"), QStringLiteral("/KLauncher"), QDBusConnection::sessionBus()); klauncher.setLaunchEnv(name, value); } // ----------------------------------------------------------------------------- static void applyQtColors( KSharedConfigPtr kglobalcfg, QSettings& settings, QPalette& newPal ) { QStringList actcg, inactcg, discg; /* export kde color settings */ int i; for (i = 0; i < QPalette::NColorRoles; i++) actcg << newPal.color(QPalette::Active, (QPalette::ColorRole) i).name(); for (i = 0; i < QPalette::NColorRoles; i++) inactcg << newPal.color(QPalette::Inactive, (QPalette::ColorRole) i).name(); for (i = 0; i < QPalette::NColorRoles; i++) discg << newPal.color(QPalette::Disabled, (QPalette::ColorRole) i).name(); settings.setValue(QStringLiteral("/qt/Palette/active"), actcg); settings.setValue(QStringLiteral("/qt/Palette/inactive"), inactcg); settings.setValue(QStringLiteral("/qt/Palette/disabled"), discg); // export kwin's colors to qtrc for kstyle to use KConfigGroup wmCfgGroup(kglobalcfg, "WM"); // active colors QColor clr = newPal.color( QPalette::Active, QPalette::Background ); clr = wmCfgGroup.readEntry("activeBackground", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/activeBackground"), clr.name()); if (QPixmap::defaultDepth() > 8) clr = clr.dark(110); clr = wmCfgGroup.readEntry("activeBlend", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/activeBlend"), clr.name()); clr = newPal.color( QPalette::Active, QPalette::HighlightedText ); clr = wmCfgGroup.readEntry("activeForeground", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/activeForeground"), clr.name()); clr = newPal.color( QPalette::Active,QPalette::Background ); clr = wmCfgGroup.readEntry("frame", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/frame"), clr.name()); clr = wmCfgGroup.readEntry("activeTitleBtnBg", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/activeTitleBtnBg"), clr.name()); // inactive colors clr = newPal.color(QPalette::Inactive, QPalette::Background); clr = wmCfgGroup.readEntry("inactiveBackground", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/inactiveBackground"), clr.name()); if (QPixmap::defaultDepth() > 8) clr = clr.dark(110); clr = wmCfgGroup.readEntry("inactiveBlend", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/inactiveBlend"), clr.name()); clr = newPal.color(QPalette::Inactive, QPalette::Background).dark(); clr = wmCfgGroup.readEntry("inactiveForeground", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/inactiveForeground"), clr.name()); clr = newPal.color(QPalette::Inactive, QPalette::Background); clr = wmCfgGroup.readEntry("inactiveFrame", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/inactiveFrame"), clr.name()); clr = wmCfgGroup.readEntry("inactiveTitleBtnBg", clr); settings.setValue(QStringLiteral("/qt/KWinPalette/inactiveTitleBtnBg"), clr.name()); KConfigGroup kdeCfgGroup(kglobalcfg, "KDE"); settings.setValue(QStringLiteral("/qt/KDE/contrast"), kdeCfgGroup.readEntry("contrast", 7)); } // ----------------------------------------------------------------------------- static void applyQtSettings( KSharedConfigPtr kglobalcfg, QSettings& settings ) { /* export font settings */ // NOTE keep this in sync with kfontsettingsdata in plasma-integration (cf. also Bug 378262) QFont defaultFont(QStringLiteral("Noto Sans"), 10, -1); defaultFont.setStyleHint(QFont::SansSerif); const KConfigGroup configGroup(KSharedConfig::openConfig(), QStringLiteral("General")); const QString fontInfo = configGroup.readEntry(QStringLiteral("font"), QString()); if (!fontInfo.isEmpty()) { defaultFont.fromString(fontInfo); } settings.setValue(QStringLiteral("/qt/font"), defaultFont.toString()); /* export effects settings */ KConfigGroup kdeCfgGroup(kglobalcfg, "General"); bool effectsEnabled = kdeCfgGroup.readEntry("EffectsEnabled", false); bool fadeMenus = kdeCfgGroup.readEntry("EffectFadeMenu", false); bool fadeTooltips = kdeCfgGroup.readEntry("EffectFadeTooltip", false); bool animateCombobox = kdeCfgGroup.readEntry("EffectAnimateCombo", false); QStringList guieffects; if (effectsEnabled) { guieffects << QStringLiteral("general"); if (fadeMenus) guieffects << QStringLiteral("fademenu"); if (animateCombobox) guieffects << QStringLiteral("animatecombo"); if (fadeTooltips) guieffects << QStringLiteral("fadetooltip"); } else guieffects << QStringLiteral("none"); settings.setValue(QStringLiteral("/qt/GUIEffects"), guieffects); } // ----------------------------------------------------------------------------- static void addColorDef(QString& s, const char* n, const QColor& col) { QString tmp; tmp.sprintf("#define %s #%02x%02x%02x\n", n, col.red(), col.green(), col.blue()); s += tmp; } // ----------------------------------------------------------------------------- static void copyFile(QFile& tmp, QString const& filename, bool ) { QFile f( filename ); if ( f.open(QIODevice::ReadOnly) ) { QByteArray buf( 8192, ' ' ); while ( !f.atEnd() ) { int read = f.read( buf.data(), buf.size() ); if ( read > 0 ) tmp.write( buf.data(), read ); } } } // ----------------------------------------------------------------------------- static QString item( int i ) { return QString::number( i / 255.0, 'f', 3 ); } static QString color( const QColor& col ) { return QStringLiteral( "{ %1, %2, %3 }" ).arg( item( col.red() ) ).arg( item( col.green() ) ).arg( item( col.blue() ) ); } static void createGtkrc( bool exportColors, const QPalette& cg, bool exportGtkTheme, const QString& gtkTheme, int version ) { // lukas: why does it create in ~/.kde/share/config ??? // pfeiffer: so that we don't overwrite the user's gtkrc. // it is found via the GTK_RC_FILES environment variable. QSaveFile saveFile( writableGtkrc(version) ); if ( !saveFile.open(QIODevice::WriteOnly) ) return; QTextStream t ( &saveFile ); t.setCodec( QTextCodec::codecForLocale () ); t << i18n( "# created by KDE Plasma, %1\n" "#\n" "# If you do not want Plasma to override your GTK settings, select\n" "# Colors in the System Settings and disable the checkbox\n" "# \"Apply colors to non-Qt applications\"\n" "#\n" "#\n", QDateTime::currentDateTime().toString()); if ( 2==version ) { // we should maybe check for MacOS settings here t << endl; t << "gtk-alternative-button-order = 1" << endl; t << endl; } if (exportGtkTheme) { QString gtkStyle; if (gtkTheme.toLower() == QLatin1String("oxygen")) gtkStyle = QStringLiteral("oxygen-gtk"); else gtkStyle = gtkTheme; bool exist_gtkrc = false; QByteArray gtkrc = getenv(gtkEnvVar(version)); QStringList listGtkrc = QFile::decodeName(gtkrc).split(QStringLiteral(":")); if (listGtkrc.contains(saveFile.fileName())) listGtkrc.removeAll(saveFile.fileName()); listGtkrc.append(QDir::homePath() + userGtkrc(version)); listGtkrc.append(QDir::homePath() + "/.gtkrc-2.0-kde"); listGtkrc.append(QDir::homePath() + "/.gtkrc-2.0-kde4"); listGtkrc.removeAll(QLatin1String("")); listGtkrc.removeDuplicates(); for (int i = 0; i < listGtkrc.size(); ++i) { if ((exist_gtkrc = QFile::exists(listGtkrc.at(i)))) break; } if (!exist_gtkrc) { QString gtk2ThemeFilename; gtk2ThemeFilename = QStringLiteral("%1/.themes/%2/gtk-2.0/gtkrc").arg(QDir::homePath()).arg(gtkStyle); if (!QFile::exists(gtk2ThemeFilename)) { QStringList gtk2ThemePath; gtk2ThemeFilename.clear(); QByteArray xdgDataDirs = getenv("XDG_DATA_DIRS"); gtk2ThemePath.append(QDir::homePath() + "/.local"); gtk2ThemePath.append(QFile::decodeName(xdgDataDirs).split(QStringLiteral(":"))); gtk2ThemePath.removeDuplicates(); for (int i = 0; i < gtk2ThemePath.size(); ++i) { gtk2ThemeFilename = QStringLiteral("%1/themes/%2/gtk-2.0/gtkrc").arg(gtk2ThemePath.at(i)).arg(gtkStyle); if (QFile::exists(gtk2ThemeFilename)) break; else gtk2ThemeFilename.clear(); } } if (!gtk2ThemeFilename.isEmpty()) { t << "include \"" << gtk2ThemeFilename << "\"" << endl; t << endl; t << "gtk-theme-name=\"" << gtkStyle << "\"" << endl; t << endl; if (gtkStyle == QLatin1String("oxygen-gtk")) exportColors = false; } } } if (exportColors) { t << "style \"default\"" << endl; t << "{" << endl; t << " bg[NORMAL] = " << color( cg.color( QPalette::Active, QPalette::Background ) ) << endl; t << " bg[SELECTED] = " << color( cg.color(QPalette::Active, QPalette::Highlight) ) << endl; t << " bg[INSENSITIVE] = " << color( cg.color( QPalette::Active, QPalette::Background ) ) << endl; t << " bg[ACTIVE] = " << color( cg.color( QPalette::Active, QPalette::Mid ) ) << endl; t << " bg[PRELIGHT] = " << color( cg.color( QPalette::Active, QPalette::Background ) ) << endl; t << endl; t << " base[NORMAL] = " << color( cg.color( QPalette::Active, QPalette::Base ) ) << endl; t << " base[SELECTED] = " << color( cg.color(QPalette::Active, QPalette::Highlight) ) << endl; t << " base[INSENSITIVE] = " << color( cg.color( QPalette::Active, QPalette::Background ) ) << endl; t << " base[ACTIVE] = " << color( cg.color(QPalette::Active, QPalette::Highlight) ) << endl; t << " base[PRELIGHT] = " << color( cg.color(QPalette::Active, QPalette::Highlight) ) << endl; t << endl; t << " text[NORMAL] = " << color( cg.color(QPalette::Active, QPalette::Text) ) << endl; t << " text[SELECTED] = " << color( cg.color(QPalette::Active, QPalette::HighlightedText) ) << endl; t << " text[INSENSITIVE] = " << color( cg.color( QPalette::Active, QPalette::Mid ) ) << endl; t << " text[ACTIVE] = " << color( cg.color(QPalette::Active, QPalette::HighlightedText) ) << endl; t << " text[PRELIGHT] = " << color( cg.color(QPalette::Active, QPalette::HighlightedText) ) << endl; t << endl; t << " fg[NORMAL] = " << color ( cg.color( QPalette::Active, QPalette::Foreground ) ) << endl; t << " fg[SELECTED] = " << color( cg.color(QPalette::Active, QPalette::HighlightedText) ) << endl; t << " fg[INSENSITIVE] = " << color( cg.color( QPalette::Active, QPalette::Mid ) ) << endl; t << " fg[ACTIVE] = " << color( cg.color( QPalette::Active, QPalette::Foreground ) ) << endl; t << " fg[PRELIGHT] = " << color( cg.color( QPalette::Active, QPalette::Foreground ) ) << endl; t << "}" << endl; t << endl; t << "class \"*\" style \"default\"" << endl; t << endl; // tooltips don't have the standard background color t << "style \"ToolTip\"" << endl; t << "{" << endl; QPalette group = QToolTip::palette(); t << " bg[NORMAL] = " << color( group.color( QPalette::Active, QPalette::Background ) ) << endl; t << " base[NORMAL] = " << color( group.color( QPalette::Active, QPalette::Base ) ) << endl; t << " text[NORMAL] = " << color( group.color( QPalette::Active, QPalette::Text ) ) << endl; t << " fg[NORMAL] = " << color( group.color( QPalette::Active, QPalette::Foreground ) ) << endl; t << "}" << endl; t << endl; t << "widget \"gtk-tooltip\" style \"ToolTip\"" << endl; t << "widget \"gtk-tooltips\" style \"ToolTip\"" << endl; t << endl; // highlight the current (mouse-hovered) menu-item // not every button, checkbox, etc. t << "style \"MenuItem\"" << endl; t << "{" << endl; t << " bg[PRELIGHT] = " << color( cg.color(QPalette::Highlight) ) << endl; t << " fg[PRELIGHT] = " << color( cg.color(QPalette::HighlightedText) ) << endl; t << "}" << endl; t << endl; t << "class \"*MenuItem\" style \"MenuItem\"" << endl; t << endl; } saveFile.commit(); } // ----------------------------------------------------------------------------- void runRdb( uint flags ) { // Obtain the application palette that is about to be set. bool exportColors = flags & KRdbExportColors; bool exportQtColors = flags & KRdbExportQtColors; bool exportQtSettings = flags & KRdbExportQtSettings; bool exportXftSettings = flags & KRdbExportXftSettings; bool exportGtkTheme = flags & KRdbExportGtkTheme; KSharedConfigPtr kglobalcfg = KSharedConfig::openConfig( QStringLiteral("kdeglobals") ); KConfigGroup kglobals(kglobalcfg, "KDE"); QPalette newPal = KColorScheme::createApplicationPalette(kglobalcfg); QTemporaryFile tmpFile; if (!tmpFile.open()) { qDebug() << "Couldn't open temp file"; exit(0); } KConfigGroup generalCfgGroup(kglobalcfg, "General"); QString gtkTheme; if (kglobals.hasKey("widgetStyle")) gtkTheme = kglobals.readEntry("widgetStyle"); else gtkTheme = QStringLiteral("oxygen"); createGtkrc( exportColors, newPal, exportGtkTheme, gtkTheme, 1 ); createGtkrc( exportColors, newPal, exportGtkTheme, gtkTheme, 2 ); // Export colors to non-(KDE/Qt) apps (e.g. Motif, GTK+ apps) if (exportColors) { KConfigGroup g(KSharedConfig::openConfig(), "WM"); QString preproc; QColor backCol = newPal.color( QPalette::Active, QPalette::Background ); addColorDef(preproc, "FOREGROUND" , newPal.color( QPalette::Active, QPalette::Foreground ) ); addColorDef(preproc, "BACKGROUND" , backCol); addColorDef(preproc, "HIGHLIGHT" , backCol.light(100+(2*KColorScheme::contrast()+4)*16/1)); addColorDef(preproc, "LOWLIGHT" , backCol.dark(100+(2*KColorScheme::contrast()+4)*10)); addColorDef(preproc, "SELECT_BACKGROUND" , newPal.color( QPalette::Active, QPalette::Highlight)); addColorDef(preproc, "SELECT_FOREGROUND" , newPal.color( QPalette::Active, QPalette::HighlightedText)); addColorDef(preproc, "WINDOW_BACKGROUND" , newPal.color( QPalette::Active, QPalette::Base ) ); addColorDef(preproc, "WINDOW_FOREGROUND" , newPal.color( QPalette::Active, QPalette::Text ) ); addColorDef(preproc, "INACTIVE_BACKGROUND", g.readEntry("inactiveBackground", QColor(224, 223, 222))); addColorDef(preproc, "INACTIVE_FOREGROUND", g.readEntry("inactiveBackground", QColor(224, 223, 222))); addColorDef(preproc, "ACTIVE_BACKGROUND" , g.readEntry("activeBackground", QColor(48, 174, 232))); addColorDef(preproc, "ACTIVE_FOREGROUND" , g.readEntry("activeBackground", QColor(48, 174, 232))); //--------------------------------------------------------------- tmpFile.write( preproc.toLatin1(), preproc.length() ); QStringList list; const QStringList adPaths = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kdisplay/app-defaults/"), QStandardPaths::LocateDirectory); for (QStringList::ConstIterator it = adPaths.constBegin(); it != adPaths.constEnd(); ++it) { QDir dSys( *it ); if ( dSys.exists() ) { dSys.setFilter( QDir::Files ); dSys.setSorting( QDir::Name ); dSys.setNameFilters(QStringList(QStringLiteral("*.ad"))); list += dSys.entryList(); } } for (QStringList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it) copyFile(tmpFile, QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kdisplay/app-defaults/"+(*it)), true); } // Merge ~/.Xresources or fallback to ~/.Xdefaults QString homeDir = QDir::homePath(); QString xResources = homeDir + "/.Xresources"; // very primitive support for ~/.Xresources by appending it if ( QFile::exists( xResources ) ) copyFile(tmpFile, xResources, true); else copyFile(tmpFile, homeDir + "/.Xdefaults", true); // Export the Xcursor theme & size settings KConfigGroup mousecfg(KSharedConfig::openConfig( QStringLiteral("kcminputrc") ), "Mouse" ); QString theme = mousecfg.readEntry("cursorTheme", QString()); QString size = mousecfg.readEntry("cursorSize", QString()); QString contents; if (!theme.isNull()) contents = "Xcursor.theme: " + theme + '\n'; if (!size.isNull()) contents += "Xcursor.size: " + size + '\n'; if (exportXftSettings) { if (generalCfgGroup.hasKey("XftAntialias")) { contents += QLatin1String("Xft.antialias: "); if(generalCfgGroup.readEntry("XftAntialias", true)) contents += QLatin1String("1\n"); else contents += QLatin1String("0\n"); } if (generalCfgGroup.hasKey("XftHintStyle")) { QString hintStyle = generalCfgGroup.readEntry("XftHintStyle", "hintmedium"); contents += QLatin1String("Xft.hinting: "); if(hintStyle.isEmpty()) contents += QLatin1String("-1\n"); else { if(hintStyle!=QLatin1String("hintnone")) contents += QLatin1String("1\n"); else contents += QLatin1String("0\n"); contents += "Xft.hintstyle: " + hintStyle + '\n'; } } if (generalCfgGroup.hasKey("XftSubPixel")) { QString subPixel = generalCfgGroup.readEntry("XftSubPixel"); if(!subPixel.isEmpty()) contents += "Xft.rgba: " + subPixel + '\n'; } KConfig _cfgfonts( QStringLiteral("kcmfonts") ); KConfigGroup cfgfonts(&_cfgfonts, "General"); int dpi; //even though this sets up the X rdb, we want to use the value the //user has set to use when under wayland - as X apps will be scaled by the compositor if (KWindowSystem::isPlatformWayland()) { dpi = cfgfonts.readEntry( "forceFontDPIWayland", 0); + if (dpi == 0) { //with wayland we want xwayland to run at 96 dpi (unless set otherwise) as we have wayland scaling on top + dpi = 96; + } } else { dpi = cfgfonts.readEntry( "forceFontDPI", 0); } if( dpi != 0 ) contents += "Xft.dpi: " + QString::number(dpi) + '\n'; else { KProcess proc; proc << QStringLiteral("xrdb") << QStringLiteral("-quiet") << QStringLiteral("-remove") << QStringLiteral("-nocpp"); proc.start(); if (proc.waitForStarted()) { proc.write( QByteArray( "Xft.dpi\n" ) ); proc.closeWriteChannel(); proc.waitForFinished(); } } } if (contents.length() > 0) tmpFile.write( contents.toLatin1(), contents.length() ); tmpFile.flush(); KProcess proc; #ifndef NDEBUG proc << QStringLiteral("xrdb") << QStringLiteral("-merge") << tmpFile.fileName(); #else proc << "xrdb" << "-quiet" << "-merge" << tmpFile.fileName(); #endif proc.execute(); applyGtkStyles(exportColors, 1); applyGtkStyles(exportColors, 2); /* Qt exports */ if ( exportQtColors || exportQtSettings ) { QSettings* settings = new QSettings(QStringLiteral("Trolltech")); if ( exportQtColors ) applyQtColors( kglobalcfg, *settings, newPal ); // For kcmcolors if ( exportQtSettings ) applyQtSettings( kglobalcfg, *settings ); // For kcmstyle delete settings; QApplication::flush(); #if HAVE_X11 if (qApp->platformName() == QStringLiteral("xcb")) { // We let KIPC take care of ourselves, as we are in a KDE app with // QApp::setDesktopSettingsAware(false); // Instead of calling QApp::x11_apply_settings() directly, we instead // modify the timestamp which propagates the settings changes onto // Qt-only apps without adversely affecting ourselves. // Cheat and use the current timestamp, since we just saved to qtrc. QDateTime settingsstamp = QDateTime::currentDateTime(); static Atom qt_settings_timestamp = 0; if (!qt_settings_timestamp) { QString atomname(QStringLiteral("_QT_SETTINGS_TIMESTAMP_")); atomname += XDisplayName( 0 ); // Use the $DISPLAY envvar. qt_settings_timestamp = XInternAtom( QX11Info::display(), atomname.toLatin1(), False); } QBuffer stamp; QDataStream s(&stamp.buffer(), QIODevice::WriteOnly); s << settingsstamp; XChangeProperty( QX11Info::display(), QX11Info::appRootWindow(), qt_settings_timestamp, qt_settings_timestamp, 8, PropModeReplace, (unsigned char*) stamp.buffer().data(), stamp.buffer().size() ); QApplication::flush(); } #endif } //Legacy support: //Try to sync kde4 settings with ours Kdelibs4Migration migration; //kf5 congig groups for general and icons KConfigGroup generalGroup(kglobalcfg, "General"); KConfigGroup iconsGroup(kglobalcfg, "Icons"); const QString colorSchemeName = generalGroup.readEntry("ColorScheme", QString()); //if no valid color scheme saved, something weird is going on, abort if (colorSchemeName.isEmpty()) { return; } QString colorSchemeSrcFile; if (colorSchemeName != QLatin1String("Default")) { //fix filename, copied from ColorsCM::saveScheme() QString colorSchemeFilename = colorSchemeName; colorSchemeFilename.remove('\''); // So Foo's does not become FooS QRegExp fixer(QStringLiteral("[\\W,.-]+(.?)")); int offset; while ((offset = fixer.indexIn(colorSchemeFilename)) >= 0) colorSchemeFilename.replace(offset, fixer.matchedLength(), fixer.cap(1).toUpper()); colorSchemeFilename.replace(0, 1, colorSchemeFilename.at(0).toUpper()); //clone the color scheme colorSchemeSrcFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "color-schemes/" + colorSchemeFilename + ".colors"); const QString dest = migration.saveLocation("data", QStringLiteral("color-schemes")) + colorSchemeName + ".colors"; QFile::remove(dest); QFile::copy(colorSchemeSrcFile, dest); } //Apply the color scheme QString configFilePath = migration.saveLocation("config") + "kdeglobals"; if (configFilePath.isEmpty()) { return; } KConfig kde4config(configFilePath, KConfig::SimpleConfig); KConfigGroup kde4generalGroup(&kde4config, "General"); kde4generalGroup.writeEntry("ColorScheme", colorSchemeName); //fonts QString font = generalGroup.readEntry("font", QString()); if (!font.isEmpty()) { kde4generalGroup.writeEntry("font", font); } font = generalGroup.readEntry("desktopFont", QString()); if (!font.isEmpty()) { kde4generalGroup.writeEntry("desktopFont", font); } font = generalGroup.readEntry("menuFont", QString()); if (!font.isEmpty()) { kde4generalGroup.writeEntry("menuFont", font); } font = generalGroup.readEntry("smallestReadableFont", QString()); if (!font.isEmpty()) { kde4generalGroup.writeEntry("smallestReadableFont", font); } font = generalGroup.readEntry("taskbarFont", QString()); if (!font.isEmpty()) { kde4generalGroup.writeEntry("taskbarFont", font); } font = generalGroup.readEntry("toolBarFont", QString()); if (!font.isEmpty()) { kde4generalGroup.writeEntry("toolBarFont", font); } //TODO: does exist any way to check if a qt4 widget style is present from a qt5 app? //kde4generalGroup.writeEntry("widgetStyle", "qtcurve"); kde4generalGroup.sync(); KConfigGroup kde4IconGroup(&kde4config, "Icons"); QString iconTheme = iconsGroup.readEntry("Theme", QString()); if (!iconTheme.isEmpty()) { kde4IconGroup.writeEntry("Theme", iconTheme); } kde4IconGroup.sync(); if (!colorSchemeSrcFile.isEmpty()) { //copy all the groups in the color scheme in kdeglobals KSharedConfigPtr kde4ColorConfig = KSharedConfig::openConfig(colorSchemeSrcFile, KConfig::SimpleConfig); foreach (const QString &grp, kde4ColorConfig->groupList()) { KConfigGroup cg(kde4ColorConfig, grp); KConfigGroup cg2(&kde4config, grp); cg.copyTo(&cg2); } } //widgets settings KConfigGroup kglobals4(&kde4config, "KDE"); kglobals4.writeEntry("ShowIconsInMenuItems", kglobals.readEntry("ShowIconsInMenuItems", true)); kglobals4.writeEntry("ShowIconsOnPushButtons", kglobals.readEntry("ShowIconsOnPushButtons", true)); kglobals4.writeEntry("contrast", kglobals.readEntry("contrast", 4)); //FIXME: this should somehow check if the kde4 version of the style is installed kde4generalGroup.writeEntry("widgetStyle", kglobals.readEntry("widgetStyle", "breeze")); //toolbar style KConfigGroup toolbars4(&kde4config, "Toolbar style"); KConfigGroup toolbars5(kglobalcfg, "Toolbar style"); toolbars4.writeEntry("ToolButtonStyle", toolbars5.readEntry("ToolButtonStyle", "TextBesideIcon")); toolbars4.writeEntry("ToolButtonStyleOtherToolbars", toolbars5.readEntry("ToolButtonStyleOtherToolbars", "TextBesideIcon")); }