diff --git a/kcms/fonts/CMakeLists.txt b/kcms/fonts/CMakeLists.txt --- a/kcms/fonts/CMakeLists.txt +++ b/kcms/fonts/CMakeLists.txt @@ -23,17 +23,23 @@ target_link_libraries(kcm_fonts Qt5::DBus Qt5::Xml KF5::KCMUtils KF5::I18n KF5::KDELibs4Support ${FREETYPE_LIBRARIES}) if(X11_FOUND) - target_link_libraries(kcm_fonts Qt5::X11Extras) + target_link_libraries(kcm_fonts + Qt5::X11Extras + KF5::I18n + KF5::Plasma + KF5::PlasmaQuick + KF5::Declarative + KF5::QuickAddons) if(FONTCONFIG_FOUND) target_link_libraries(kcm_fonts ${FONTCONFIG_LIBRARIES}) endif() target_link_libraries(kcm_fonts ${X11_LIBRARIES}) endif() -install(TARGETS kcm_fonts DESTINATION ${PLUGIN_INSTALL_DIR} ) - +kcoreaddons_desktop_to_json(kcm_fonts "kcm_fonts.desktop") ########### install files ############### - -install( FILES fonts.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) +install(TARGETS kcm_fonts DESTINATION ${PLUGIN_INSTALL_DIR}/kcms) +install(FILES kcm_fonts.desktop DESTINATION ${SERVICES_INSTALL_DIR}) +kpackage_install_package(package kcm_fonts kcms) diff --git a/kcms/fonts/fonts.h b/kcms/fonts/fonts.h --- a/kcms/fonts/fonts.h +++ b/kcms/fonts/fonts.h @@ -2,6 +2,8 @@ Copyright 1997 Mark Donohoe Copyright 1999 Lars Knoll Copyright 2000 Rik Hemsley + Copyright 2015 Antonis Tsiapaliokas + Copyright 2017 Marco Martin Ported to kcontrol2 by Geert Jansen. @@ -24,128 +26,168 @@ #ifndef FONTS_H #define FONTS_H -#include -#include -#include #include +#include +#include -#include -#include +#include #include "kxftconfig.h" -class QCheckBox; -class QComboBox; -class QDoubleSpinBox; -class QSpinBox; -class FontAASettings; - -class FontUseItem : public KFontRequester +class FontAASettings : public QObject { Q_OBJECT -public: - FontUseItem(QWidget *parent, const QString &name, const QString &grp, - const QString &key, const QString &rc, const QFont &default_fnt, - bool fixed = false); - - void readFont(); - void writeFont(); - void setDefault(); - void applyFontDiff(const QFont &fnt, int fontDiffFlags); - - const QString &rcFile() - { - return _rcfile; - } - const QString &rcGroup() - { - return _rcgroup; - } - const QString &rcKey() - { - return _rckey; - } - -private: - QString _rcfile; - QString _rcgroup; - QString _rckey; - QFont _default; -}; + Q_PROPERTY(QAbstractItemModel *subPixelOptionsModel READ subPixelOptionsModel CONSTANT) + Q_PROPERTY(int subPixelCurrentIndex READ subPixelCurrentIndex WRITE setSubPixelCurrentIndex NOTIFY subPixelCurrentIndexChanged); + Q_PROPERTY(QAbstractItemModel *hintingOptionsModel READ hintingOptionsModel CONSTANT) + Q_PROPERTY(int hintingCurrentIndex READ hintingCurrentIndex WRITE setHintingCurrentIndex NOTIFY hintingCurrentIndexChanged); -class FontAASettings : public QDialog -{ - Q_OBJECT + Q_PROPERTY(bool exclude READ exclude WRITE setExclude NOTIFY excludeChanged) + Q_PROPERTY(int excludeTo READ excludeTo WRITE setExcludeTo NOTIFY excludeToChanged) + Q_PROPERTY(int excludeFrom READ excludeFrom WRITE setExcludeFrom NOTIFY excludeFromChanged) + Q_PROPERTY(int antiAliasing READ antiAliasing WRITE setAntiAliasing NOTIFY aliasingChanged) + Q_PROPERTY(int dpi READ dpi WRITE setDpi NOTIFY dpiChanged) public: - + enum AASetting { AAEnabled, AASystem, AADisabled }; #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) - FontAASettings(QWidget *parent); + FontAASettings(QObject *parent); bool save(KXftConfig::AntiAliasing::State aaState); - bool load(); + void load(); void defaults(); - int getIndex(KXftConfig::SubPixel::Type spType); - KXftConfig::SubPixel::Type getSubPixelType(); - int getIndex(KXftConfig::Hint::Style hStyle); - KXftConfig::Hint::Style getHintStyle(); void setAntiAliasingState(KXftConfig::AntiAliasing::State aaState); - void enableWidgets(); - int exec() Q_DECL_OVERRIDE; -#endif + QAbstractItemModel* subPixelOptionsModel() { return m_subPixelOptionsModel; } + QAbstractItemModel* hintingOptionsModel() { return m_hintingOptionsModel; } + + void setExclude(bool exclude); + bool exclude() const; + + void setExcludeTo(const int &excludeTo); + int excludeTo() const; -protected Q_SLOTS: + void setExcludeFrom(const int &excludeTo); + int excludeFrom() const; - void changed(); + void setAntiAliasing(const int& antiAliasing); + int antiAliasing() const; + + void setDpi(const int &dpi); + int dpi() const; + + int subPixelCurrentIndex(); + void setSubPixelCurrentIndex(int idx); + int hintingCurrentIndex(); + void setHintingCurrentIndex(int idx); + + bool needsSave() const; + +#endif + +Q_SIGNALS: + void excludeChanged(); + void excludeToChanged(); + void excludeFromChanged(); + void antiAliasingChanged(); + void aliasingChanged(); + void dpiChanged(); + void subPixelCurrentIndexChanged(); + void hintingCurrentIndexChanged(); #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) private: - - QCheckBox *excludeRange; - QDoubleSpinBox *excludeFrom; - QDoubleSpinBox *excludeTo; - QComboBox *subPixelType; - QComboBox *hintingStyle; - QLabel *subPixelLabel; - QLabel *excludeToLabel; - bool changesMade; + int m_excludeTo; + int m_excludeToOriginal; + int m_excludeFrom; + int m_excludeFromOriginal; + int m_antiAliasing; + int m_antiAliasingOriginal; + int m_dpi; + int m_dpiOriginal; + int m_subPixelCurrentIndex = 0; + int m_hintingCurrentIndex = 0; + QStandardItemModel *m_subPixelOptionsModel; + QStandardItemModel *m_hintingOptionsModel; + bool m_exclude = false; #endif }; /** * The Desktop/fonts tab in kcontrol. */ -class KFonts : public KCModule +class KFonts : public KQuickAddons::ConfigModule { Q_OBJECT + Q_PROPERTY(QFont generalFont READ generalFont WRITE setGeneralFont NOTIFY generalFontChanged) + Q_PROPERTY(QFont fixedWidthFont READ fixedWidthFont WRITE setFixedWidthFont NOTIFY fixedWidthFontChanged) + Q_PROPERTY(QFont smallFont READ smallFont WRITE setSmallFont NOTIFY smallFontChanged) + Q_PROPERTY(QFont toolbarFont READ toolbarFont WRITE setToolbarFont NOTIFY toolbarFontChanged) + Q_PROPERTY(QFont menuFont READ menuFont WRITE setMenuFont NOTIFY menuFontChanged) + Q_PROPERTY(QFont windowTitleFont READ windowTitleFont WRITE setWindowTitleFont NOTIFY windowTitleFontChanged) + Q_PROPERTY(QObject *fontAASettings READ fontAASettings CONSTANT) public: - KFonts(QWidget *parent, const QVariantList &); + KFonts(QObject *parent, const QVariantList &); ~KFonts(); - void load() Q_DECL_OVERRIDE; - void save() Q_DECL_OVERRIDE; - void defaults() Q_DECL_OVERRIDE; + void setGeneralFont(const QFont &font); + QFont generalFont() const; + + void setFixedWidthFont(const QFont &font); + QFont fixedWidthFont() const; + + void setSmallFont(const QFont &font); + QFont smallFont() const; + + void setToolbarFont(const QFont &font); + QFont toolbarFont() const; + + void setMenuFont(const QFont &font); + QFont menuFont() const; + + void setWindowTitleFont(const QFont &font); + QFont windowTitleFont() const; -protected Q_SLOTS: - void fontSelected(); - void slotApplyFontDiff(); - void slotUseAntiAliasing(); - void slotCfgAa(); + QObject* fontAASettings() { return m_fontAASettings; } + +public Q_SLOTS: + void load(); + void save(); + void defaults(); + Q_INVOKABLE void adjustAllFonts(); + +Q_SIGNALS: + void fontsHaveChanged(); + + void generalFontChanged(); + void fixedWidthFontChanged(); + void smallFontChanged(); + void toolbarFontChanged(); + void menuFontChanged(); + void windowTitleFontChanged(); private: -#if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) - enum AASetting { AAEnabled, AASystem, AADisabled }; - AASetting useAA, useAA_original; - QComboBox *cbAA; - QPushButton *aaSettingsButton; - FontAASettings *aaSettings; -#endif - int dpi_original; - QCheckBox *checkboxForceDpi; - QSpinBox *spinboxDpi; - QList fontUseList; + void updateNeedsSave(); + QFont applyFontDiff(const QFont &fnt, const QFont &newFont, int fontDiffFlags); + + QFont m_defaultFont; + QFont m_generalFont; + QFont m_fixedWidthFont; + QFont m_smallFont; + QFont m_toolbarFont; + QFont m_menuFont; + QFont m_windowTitleFont; + + QFont m_defaultFontOriginal; + QFont m_generalFontOriginal; + QFont m_fixedWidthFontOriginal; + QFont m_smallFontOriginal; + QFont m_toolbarFontOriginal; + QFont m_menuFontOriginal; + QFont m_windowTitleFontOriginal; + + FontAASettings *m_fontAASettings; }; #endif diff --git a/kcms/fonts/fonts.cpp b/kcms/fonts/fonts.cpp --- a/kcms/fonts/fonts.cpp +++ b/kcms/fonts/fonts.cpp @@ -2,6 +2,8 @@ Copyright 1997 Mark Donohoe Copyright 1999 Lars Knoll Copyright 2000 Rik Hemsley + Copyright 2015 Antonis Tsiapaliokas + Copyright 2017 Marco Martin Ported to kcontrol2 by Geert Jansen. @@ -21,348 +23,172 @@ Boston, MA 02110-1301, USA. */ -#include #include "fonts.h" -#include - +#include +#include +#include +#include +#include +#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 #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 ****/ +K_PLUGIN_FACTORY_WITH_JSON(KFontsFactory, "kcm_fonts.json", registerPlugin();) -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) +//from KFontRequester +// Determine if the font with given properties is available on the system, +// otherwise find and return the best fitting combination. +static QFont nearestExistingFont(const QFont &font) { - 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(); + QFontDatabase dbase; + + // Initialize font data accoring to given font object. + QString family = font.family(); + QString style = dbase.styleString(font); + qreal size = font.pointSizeF(); + + // Check if the family exists. + const QStringList families = dbase.families(); + if (!families.contains(family)) { + // Chose another family. + family = QFontInfo(font).family(); // the nearest match + if (!families.contains(family)) { + family = families.count() ? families.at(0) : QStringLiteral("fixed"); + } } -} - -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()); + // Check if the family has the requested style. + // Easiest by piping it through font selection in the database. + QString retStyle = dbase.styleString(dbase.font(family, style, 10)); + style = retStyle; + + // Check if the family has the requested size. + // Only for bitmap fonts. + if (!dbase.isSmoothlyScalable(family, style)) { + QList sizes = dbase.smoothSizes(family, style); + if (!sizes.contains(size)) { + // Find nearest available size. + int mindiff = 1000; + int refsize = size; + Q_FOREACH (int lsize, sizes) { + int diff = qAbs(refsize - lsize); + if (mindiff > diff) { + mindiff = diff; + size = lsize; + } + } } } - 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()); + // Select the font with confirmed properties. + QFont result = dbase.font(family, style, int(size)); + if (dbase.isSmoothlyScalable(family, style) && result.pointSize() == floor(size)) { + result.setPointSizeF(size); + } + return result; } /**** 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); - +FontAASettings::FontAASettings(QObject *parent) + : QObject(parent) + , m_subPixelOptionsModel(new QStandardItemModel(this)) + , m_hintingOptionsModel(new QStandardItemModel(this)) +{ for (int t = KXftConfig::SubPixel::NotSet; t <= KXftConfig::SubPixel::Vbgr; ++t) { - subPixelType->addItem(QPixmap(aaPixmaps[t]), i18n(KXftConfig::description((KXftConfig::SubPixel::Type)t).toUtf8())); + QStandardItem *item = new QStandardItem(KXftConfig::description((KXftConfig::SubPixel::Type)t)); + m_subPixelOptionsModel->appendRow(item); } - 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())); + QStandardItem * item = new QStandardItem(KXftConfig::description((KXftConfig::Hint::Style)s)); + m_hintingOptionsModel->appendRow(item); } - - 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() +void FontAASettings::load() { double from, to; KXftConfig xft; if (xft.getExcludeRange(from, to)) { - excludeRange->setChecked(true); + m_excludeFrom = from; + m_excludeTo = to; + setExclude(true); } else { - excludeRange->setChecked(false); - from = 8.0; - to = 15.0; + m_excludeFrom = 8; + m_excludeTo = 15; + setExclude(false); } - - excludeFrom->setValue(from); - excludeTo->setValue(to); + m_excludeFromOriginal = m_excludeFrom; + m_excludeToOriginal = m_excludeTo; + excludeToChanged(); + excludeFromChanged(); KXftConfig::SubPixel::Type spType; - xft.getSubPixelType(spType); - int idx = getIndex(spType); - subPixelType->setCurrentIndex(idx); + setSubPixelCurrentIndex(spType); KXftConfig::Hint::Style hStyle; if (!xft.getHintStyle(hStyle) || KXftConfig::Hint::NotSet == hStyle) { + KConfig kglobals("kdeglobals", KConfig::NoGlobals); + hStyle = KXftConfig::Hint::NotSet; xft.setHintStyle(hStyle); + KConfigGroup(&kglobals, "General").writeEntry("XftHintStyle", KXftConfig::toStr(hStyle)); + kglobals.sync(); runRdb(KRdbExportXftSettings | KRdbExportGtkTheme); } - hintingStyle->setCurrentIndex(getIndex(hStyle)); + setHintingCurrentIndex(hStyle); - enableWidgets(); + KConfig _cfgfonts("kcmfonts"); + KConfigGroup cfgfonts(&_cfgfonts, "General"); - return xft.aliasingEnabled(); + int dpicfg; + if (KWindowSystem::isPlatformWayland()) { + dpicfg = cfgfonts.readEntry("forceFontDPIWayland", 0); + } else { + dpicfg = cfgfonts.readEntry("forceFontDPI", 0); + } + + if (dpicfg <= 0) { + m_dpiOriginal = 0; + } else { + m_dpiOriginal = dpicfg; + }; + + setDpi(dpicfg); + + KSharedConfig::Ptr config = KSharedConfig::openConfig("kdeglobals"); + KConfigGroup cg(config, "General"); + + if (cfgfonts.readEntry("dontChangeAASettings", true)) { + setAntiAliasing(1); //AASystem + } else if (cg.readEntry("XftAntialias", true)) { + setAntiAliasing(0); //AAEnabled + } else { + setAntiAliasing(2); //AADisabled + } + m_antiAliasingOriginal = m_antiAliasing; } bool FontAASettings::save(KXftConfig::AntiAliasing::State aaState) @@ -372,34 +198,29 @@ KConfigGroup grp(&kglobals, "General"); xft.setAntiAliasing(aaState); - - if (excludeRange->isChecked()) { - xft.setExcludeRange(excludeFrom->value(), excludeTo->value()); + if (m_exclude) { + xft.setExcludeRange(m_excludeFrom, m_excludeTo); } else { xft.setExcludeRange(0, 0); } - KXftConfig::SubPixel::Type spType(getSubPixelType()); + KXftConfig::SubPixel::Type spType = (KXftConfig::SubPixel::Type)m_subPixelCurrentIndex; xft.setSubPixelType(spType); - if (KXftConfig::SubPixel::NotSet == spType) { - grp.revertToDefault("XftSubPixel"); - } else { - grp.writeEntry("XftSubPixel", KXftConfig::toStr(spType)); - } - - if (KXftConfig::AntiAliasing::NotSet == aaState) { + grp.writeEntry("XftSubPixel", KXftConfig::toStr(spType)); + if (aaState == KXftConfig::AntiAliasing::NotSet) { grp.revertToDefault("XftAntialias"); } else { grp.writeEntry("XftAntialias", aaState == KXftConfig::AntiAliasing::Enabled); } bool mod = false; - KXftConfig::Hint::Style hStyle(getHintStyle()); + KXftConfig::Hint::Style hStyle = (KXftConfig::Hint::Style)m_hintingCurrentIndex; xft.setHintStyle(hStyle); QString hs(KXftConfig::toStr(hStyle)); + if (hs != grp.readEntry("XftHintStyle")) { if (KXftConfig::Hint::NotSet == hStyle) { grp.revertToDefault("XftHintStyle"); @@ -416,476 +237,461 @@ xft.apply(); + KConfig _cfgfonts("kcmfonts"); + KConfigGroup cfgfonts(&_cfgfonts, "General"); + + if (KWindowSystem::isPlatformWayland()) { + cfgfonts.writeEntry("forceFontDPIWayland", m_dpi); + } else { + cfgfonts.writeEntry("forceFontDPI", m_dpi); + } + + 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 (m_dpi == 0 && m_dpiOriginal != 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 + + 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) + if (mod || (m_antiAliasing != m_antiAliasingOriginal) || m_dpi != m_dpiOriginal) { + KMessageBox::information(0, + i18n( + "

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

" + ), i18n("Font Settings Changed"), "FontSettingsChanged"); + m_antiAliasingOriginal = m_antiAliasing; + m_dpiOriginal = m_dpi; + } +#else +#if HAVE_X11 + if (m_dpi != m_dpiOriginal) { + KMessageBox::information(0, + i18n( + "

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

" + ), i18n("Font Settings Changed"), "FontSettingsChanged"); + m_dpiOriginal = m_dpi; + } +#endif +#endif + + m_excludeToOriginal = m_excludeTo; + m_excludeFromOriginal = m_excludeFrom; + 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(); + setExcludeTo(15); + setExcludeFrom(8); + setAntiAliasing(1); + m_antiAliasingOriginal = m_antiAliasing; + setDpi(96); + setSubPixelCurrentIndex(KXftConfig::SubPixel::NotSet); + setHintingCurrentIndex(KXftConfig::Hint::NotSet); } -int FontAASettings::getIndex(KXftConfig::SubPixel::Type spType) +#endif + +void FontAASettings::setExclude(bool exclude) { - int pos = -1; - int index; + if (exclude == m_exclude) { + return; + } - for (index = 0; index < subPixelType->count(); ++index) - if (subPixelType->itemText(index) == i18n(KXftConfig::description(spType).toUtf8())) { - pos = index; - break; - } + m_exclude = exclude; + emit excludeChanged(); +} - return pos; +bool FontAASettings::exclude() const +{ + return m_exclude; } -KXftConfig::SubPixel::Type FontAASettings::getSubPixelType() +void FontAASettings::setExcludeTo(const int &excludeTo) { - int t; + if (m_excludeTo == excludeTo) { + return; + } - 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; - } + m_excludeTo = excludeTo; + emit excludeToChanged(); +} - return KXftConfig::SubPixel::NotSet; +int FontAASettings::excludeTo() const +{ + return m_excludeTo; } -int FontAASettings::getIndex(KXftConfig::Hint::Style hStyle) +void FontAASettings::setExcludeFrom(const int &excludeTo) { - int pos = -1; - int index; + if (m_excludeFrom == excludeTo) { + return; + } - for (index = 0; index < hintingStyle->count(); ++index) - if (hintingStyle->itemText(index) == i18n(KXftConfig::description(hStyle).toUtf8())) { - pos = index; - break; - } + m_excludeFrom = excludeTo; + emit excludeToChanged(); +} - return pos; +int FontAASettings::excludeFrom() const +{ + return m_excludeFrom; } -KXftConfig::Hint::Style FontAASettings::getHintStyle() +void FontAASettings::setAntiAliasing(const int &antiAliasing) { - int s; + if (m_antiAliasing == antiAliasing) { + return; + } - 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; - } + m_antiAliasing = antiAliasing; + emit aliasingChanged(); +} - return KXftConfig::Hint::Medium; +int FontAASettings::antiAliasing() const +{ + return m_antiAliasing; } -void FontAASettings::enableWidgets() +void FontAASettings::setDpi(const int &dpi) { - 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); - } + if (m_dpi == dpi) { + return; } - subPixelType->setEnabled(ft_has_subpixel); -#endif + + m_dpi = dpi; + emit dpiChanged(); } -#endif -void FontAASettings::changed() +int FontAASettings::dpi() const { -#if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) - changesMade = true; - enableWidgets(); -#endif + return m_dpi; } -#if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) -int FontAASettings::exec() +void FontAASettings::setSubPixelCurrentIndex(int idx) { - const int i = QDialog::exec(); + if (m_subPixelCurrentIndex == idx) { + return; + } + + m_subPixelCurrentIndex = idx; + emit subPixelCurrentIndexChanged(); +} - if (!i) { - load(); // Reset settings... +int FontAASettings::subPixelCurrentIndex() +{ + return m_subPixelCurrentIndex; +} + +void FontAASettings::setHintingCurrentIndex(int idx) +{ + if (m_hintingCurrentIndex == idx) { + return; } - return i && changesMade; + m_hintingCurrentIndex = idx; + emit hintingCurrentIndexChanged(); } -#endif -/**** KFonts ****/ +int FontAASettings::hintingCurrentIndex() +{ + return m_hintingCurrentIndex; +} -KFonts::KFonts(QWidget *parent, const QVariantList &args) - : KCModule(parent, args) +bool FontAASettings::needsSave() const { - QStringList nameGroupKeyRc; + return m_excludeTo != m_excludeToOriginal || m_excludeFrom != m_excludeFromOriginal || m_antiAliasing != m_antiAliasingOriginal || m_dpi != m_dpiOriginal; +} - 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; +/**** KFonts ****/ - // NOTE: keep in sync with plasma-integration/src/platformtheme/kfontsettingsdata.cpp +KFonts::KFonts(QObject *parent, const QVariantList &args) + : KQuickAddons::ConfigModule(parent, args) + , m_fontAASettings(new FontAASettings(this)) +{ + qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); + KAboutData* about = new KAboutData("kcm_fonts", i18n("Configure Fonts"), + "0.1", QString(), KAboutLicense::LGPL); + about->addAuthor(i18n("Antonis Tsiapaliokas"), QString(), "antonis.tsiapaliokas@kde.org"); + setAboutData(about); + qmlRegisterType(); + setButtons(Apply | Default); + + auto updateState = [this]() { + setNeedsSave(m_fontAASettings->needsSave()); + }; -#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 + connect(m_fontAASettings, &FontAASettings::subPixelCurrentIndexChanged, this, updateState); + connect(m_fontAASettings, &FontAASettings::hintingCurrentIndexChanged, this, updateState); + connect(m_fontAASettings, &FontAASettings::excludeToChanged, this, updateState); + connect(m_fontAASettings, &FontAASettings::antiAliasingChanged, this, updateState); + connect(m_fontAASettings, &FontAASettings::aliasingChanged, this, updateState); + connect(m_fontAASettings, &FontAASettings::dpiChanged, this, updateState); +} + +KFonts::~KFonts() +{ +} + +void KFonts::defaults() +{ +#ifdef Q_OS_MAC + setGeneralFont(QFont("Lucida Grande", 13)); + setMenuFont(QFont("Lucida Grande", 13)); + setFixedWidthFont(QFont("Monaco", 10)); + setToolbarFont(QFont("Lucida Grande", 11)); + setSmallFont(QFont("Lucida Grande", 9)); + setWindowTitleFont(QFont("Lucida Grande", 14)); #else - QFont f3("Noto Sans", 10); // window title - QFont f5("Noto Sans", 8); // smallestReadableFont + setGeneralFont(QFont("Noto Sans", 10)); + setMenuFont(QFont("Noto Sans", 10)); + setFixedWidthFont(QFont("Hack", 9)); + setToolbarFont(QFont("Noto Sans", 10)); + setSmallFont(QFont("Noto Sans", 8)); + setWindowTitleFont(QFont("Noto Sans", 10)); #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); + m_fontAASettings->defaults(); +} -#if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) - aaSettings = new FontAASettings(this); -#endif +void KFonts::load() +{ + KSharedConfig::Ptr config = KSharedConfig::openConfig("kdeglobals"); + + KConfigGroup cg(config, "General"); + m_generalFont = m_generalFontOriginal = nearestExistingFont(cg.readEntry("font", m_defaultFont)); + + + m_fixedWidthFont = m_fixedWidthFontOriginal = nearestExistingFont(cg.readEntry("fixed", m_defaultFont)); + + m_smallFont = m_smallFontOriginal = nearestExistingFont(cg.readEntry("smallestReadableFont", m_defaultFont)); + + m_toolbarFont = m_toolbarFontOriginal = nearestExistingFont(cg.readEntry("toolBarFont", m_defaultFont)); + + m_menuFont = m_menuFontOriginal = nearestExistingFont(cg.readEntry("menuFont", m_defaultFont)); + cg = KConfigGroup(config, "WM"); + m_windowTitleFont = m_windowTitleFontOriginal = nearestExistingFont(cg.readEntry("activeFont", m_defaultFont)); + + emit generalFontChanged(); + emit fixedWidthFontChanged(); + emit smallFontChanged(); + emit toolbarFontChanged(); + emit menuFontChanged(); + emit windowTitleFontChanged(); + + m_fontAASettings->load(); + setNeedsSave(false); } -KFonts::~KFonts() +void KFonts::save() { - QList::Iterator it(fontUseList.begin()), - end(fontUseList.end()); + KSharedConfig::Ptr config = KSharedConfig::openConfig("kdeglobals"); + + KConfigGroup cg(config, "General"); + cg.writeEntry("font", m_generalFont.toString()); + cg.writeEntry("fixed", m_fixedWidthFont.toString()); + cg.writeEntry("smallestReadableFont", m_smallFont.toString()); + cg.writeEntry("toolBarFont", m_toolbarFont.toString()); + cg.writeEntry("menuFont", m_menuFont.toString()); + cg.sync(); + cg = KConfigGroup(config, "WM"); + cg.writeEntry("activeFont", m_windowTitleFont.toString()); + cg.sync(); + + m_defaultFontOriginal = m_defaultFont; + m_generalFontOriginal = m_generalFont; + m_fixedWidthFontOriginal = m_fixedWidthFont; + m_smallFontOriginal = m_smallFont; + m_toolbarFontOriginal = m_toolbarFont; + m_menuFontOriginal = m_menuFont; + m_windowTitleFontOriginal = m_windowTitleFont; - for (; it != end; ++it) { - delete(*it); + KConfig _cfgfonts("kcmfonts"); + KConfigGroup cfgfonts(&_cfgfonts, "General"); + + FontAASettings::AASetting aaSetting = (FontAASettings::AASetting)m_fontAASettings->antiAliasing(); + cfgfonts.writeEntry("dontChangeAASettings", aaSetting == FontAASettings::AASystem); + + if (aaSetting == FontAASettings::AAEnabled) { + m_fontAASettings->save(KXftConfig::AntiAliasing::Enabled); + } else if (aaSetting == FontAASettings::AADisabled) { + m_fontAASettings->save(KXftConfig::AntiAliasing::Disabled); + } else { + m_fontAASettings->save(KXftConfig::AntiAliasing::NotSet); } - fontUseList.clear(); + + KGlobalSettings::self()->emitChange(KGlobalSettings::FontChanged); + + runRdb(KRdbExportXftSettings | KRdbExportGtkTheme); + + emit fontsHaveChanged(); + setNeedsSave(false); } -void KFonts::fontSelected() +void KFonts::updateNeedsSave() { - emit changed(true); + setNeedsSave(m_defaultFontOriginal != m_defaultFont || + m_generalFontOriginal != m_generalFont || + m_fixedWidthFontOriginal != m_fixedWidthFont || + m_smallFontOriginal != m_smallFont || + m_toolbarFontOriginal != m_toolbarFont || + m_menuFontOriginal != m_menuFont || + m_windowTitleFontOriginal != m_windowTitleFont || + m_fontAASettings->needsSave()); } -void KFonts::defaults() +void KFonts::setGeneralFont(const QFont &font) { - for (int i = 0; i < (int) fontUseList.count(); i++) { - fontUseList.at(i)->setDefault(); + if (m_generalFont == font) { + return; } -#if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) - useAA = AASystem; - cbAA->setCurrentIndex(useAA); - aaSettings->defaults(); -#endif - checkboxForceDpi->setChecked(false); - spinboxDpi->setValue(96); - emit changed(true); + m_generalFont = font; + emit generalFontChanged(); + updateNeedsSave(); } -void KFonts::load() +QFont KFonts::generalFont() const { - QList::Iterator it(fontUseList.begin()), - end(fontUseList.end()); + return m_generalFont; +} - for (; it != end; ++it) { - (*it)->readFont(); +void KFonts::setFixedWidthFont(const QFont &font) +{ + if (m_fixedWidthFont == font) { + return; } -#if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) - useAA_original = useAA = aaSettings->load() ? AAEnabled : AADisabled; - cbAA->setCurrentIndex(useAA); -#endif + m_fixedWidthFont = font; + emit fixedWidthFontChanged(); + updateNeedsSave(); +} - KConfig _cfgfonts("kcmfonts"); - KConfigGroup cfgfonts(&_cfgfonts, "General"); - int dpicfg; - if (KWindowSystem::isPlatformWayland()) { - dpicfg = cfgfonts.readEntry("forceFontDPIWayland", 0); - } else { - dpicfg = cfgfonts.readEntry("forceFontDPI", 0); - } +QFont KFonts::fixedWidthFont() const +{ + return m_fixedWidthFont; +} - 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); +void KFonts::setSmallFont(const QFont &font) +{ + if (m_smallFont == font) { + return; } -#endif - emit changed(false); + m_smallFont = font; + emit smallFontChanged(); + updateNeedsSave(); } -void KFonts::save() +QFont KFonts::smallFont() const { - QList::Iterator it(fontUseList.begin()), - end(fontUseList.end()); + return m_smallFont; +} - for (; it != end; ++it) { - (*it)->writeFont(); +void KFonts::setToolbarFont(const QFont &font) +{ + if (m_toolbarFont == font) { + return; } - KSharedConfig::openConfig()->sync(); + m_toolbarFont = font; + emit toolbarFontChanged(); + updateNeedsSave(); +} - 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 && !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(); - } +QFont KFonts::toolbarFont() const +{ + return m_toolbarFont; +} + +void KFonts::setMenuFont(const QFont &font) +{ + if (m_menuFont == font) { + return; } -#endif - KGlobalSettings::self()->emitChange(KGlobalSettings::FontChanged); + m_menuFont = font; + emit menuFontChanged(); + updateNeedsSave(); +} - QApplication::processEvents(); // Process font change ourselves +QFont KFonts::menuFont() const +{ + return m_menuFont; +} - // 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); +void KFonts::setWindowTitleFont(const QFont &font) +{ + if (m_windowTitleFont == font) { + return; } - 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); + m_windowTitleFont = font; + emit windowTitleFontChanged(); + updateNeedsSave(); +} - emit changed(false); +QFont KFonts::windowTitleFont() const +{ + return m_windowTitleFont; } -void KFonts::slotApplyFontDiff() +void KFonts::adjustAllFonts() { - QFont font = QFont(fontUseList.first()->font()); + QFont font = m_generalFont; KFontChooser::FontDiffFlags fontDiffFlags = 0; - int ret = KFontDialog::getFontDiff(font, fontDiffFlags, KFontChooser::NoDisplayFlags, this); + int ret = KFontDialog::getFontDiff(font, fontDiffFlags, KFontChooser::NoDisplayFlags); if (ret == KDialog::Accepted && fontDiffFlags) { - for (int i = 0; i < (int) fontUseList.count(); i++) { - fontUseList.at(i)->applyFontDiff(font, fontDiffFlags); + setGeneralFont(applyFontDiff(m_generalFont, font, fontDiffFlags)); + setMenuFont(applyFontDiff(m_menuFont, font, fontDiffFlags)); + { + const QFont adjustedFont = applyFontDiff(m_fixedWidthFont, font, fontDiffFlags); + if (QFontInfo(adjustedFont).fixedPitch()) { + setFixedWidthFont(adjustedFont); + } } - emit changed(true); + setToolbarFont(applyFontDiff(m_toolbarFont, font, fontDiffFlags)); + setSmallFont(applyFontDiff(m_smallFont, font, fontDiffFlags)); + setWindowTitleFont(applyFontDiff(m_windowTitleFont, font, fontDiffFlags)); } } -void KFonts::slotUseAntiAliasing() +QFont KFonts::applyFontDiff(const QFont &fnt, const QFont &newFont, int fontDiffFlags) { -#if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) - useAA = static_cast< AASetting >(cbAA->currentIndex()); - aaSettingsButton->setEnabled(useAA == AAEnabled); - emit changed(true); -#endif -} + QFont font(fnt); -void KFonts::slotCfgAa() -{ -#if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) - if (aaSettings->exec()) { - emit changed(true); + if (fontDiffFlags & KFontChooser::FontDiffSize) { + font.setPointSizeF(newFont.pointSizeF()); } -#endif + if ((fontDiffFlags & KFontChooser::FontDiffFamily)) { + font.setFamily(newFont.family()); + } + if (fontDiffFlags & KFontChooser::FontDiffStyle) { + font.setWeight(newFont.weight()); + font.setStyle(newFont.style()); + font.setUnderline(newFont.underline()); + font.setStyleName(newFont.styleName()); + } + + return font; } #include "fonts.moc" diff --git a/kcms/fonts/fonts.desktop b/kcms/fonts/kcm_fonts.desktop rename from kcms/fonts/fonts.desktop rename to kcms/fonts/kcm_fonts.desktop --- a/kcms/fonts/fonts.desktop +++ b/kcms/fonts/kcm_fonts.desktop @@ -107,32 +107,24 @@ Comment[ar]=الخطوط Comment[bs]=Fontovi Comment[ca]=Tipus de lletra -Comment[ca@valencia]=Tipus de lletra Comment[cs]=Písma Comment[da]=Skrifttyper Comment[de]=Schriftarten Comment[el]=Γραμματοσειρές Comment[en_GB]=Fonts -Comment[eo]=Tiparoj Comment[es]=Tipos de letra -Comment[et]=Fondid -Comment[eu]=Letra-tipoak Comment[fi]=Fontit Comment[fr]=Polices de caractères Comment[gl]=Tipos de letra -Comment[he]=גופנים Comment[hu]=Betűtípusok Comment[id]=Fonta -Comment[is]=Letur Comment[it]=Caratteri -Comment[ja]=フォント Comment[ko]=글꼴 Comment[lt]=Šriftai Comment[mr]=फॉन्ट Comment[nb]=Skrifttype Comment[nds]=Schriftoorden Comment[nl]=Lettertypen -Comment[nn]=Skrifter Comment[pa]=ਫੋਂਟ Comment[pl]=Czcionki Comment[pt]=Tipos de Letra @@ -154,8 +146,8 @@ X-KDE-Keywords=fonts,font size,styles,charsets,character sets,panel,control panel,desktops,FileManager,Toolbars,Menu,Window Title,Title,DPI,anti-aliasing,desktop fonts,toolbar fonts,character,general fonts X-KDE-Keywords[ar]=خطوط,حجم الخط,أنماط,طقم محارف,طقوم محارف,لوحة,لوحة تحكّم,أسطح المكتب,مدير ملفات,أشرطة أدوات,قائمة,عنوان نافذة,عنوان,نقطة/بوصة,DPI,إزالة التسنّن,خطوط سطح المكتب,خطوط شريط الأدوات,محرف,خطوط عامة X-KDE-Keywords[bs]=slova,veličina slova,stil,znakovi,postaviti znakove,ploča,kontrolna ploča,pozadina,upravitelj datoteka,alatne trake,meni,naslov prozora,naslov,DPI,niskopropusni,slova pozadine,slova na alatnoj traci,obilježja,opći fontovi -X-KDE-Keywords[ca]=tipus de lletres,mida de tipus de lletra,estils,joc de caràcters,jocs de caràcters,plafó,plafó de control,escriptoris,Gestor de fitxers,Barres d'eines,Menú,Títol de la finestra,Títol,DPI,antialiàsing,tipus de lletra d'escriptori,tipus de lletra de barra d'eines,caràcter,tipus de lletra general -X-KDE-Keywords[ca@valencia]=tipus de lletres,mida de tipus de lletra,estils,joc de caràcters,jocs de caràcters,plafó,plafó de control,escriptoris,Gestor de fitxers,Barres d'eines,Menú,Títol de la finestra,Títol,DPI,antialiàsing,tipus de lletra d'escriptori,tipus de lletra de barra d'eines,caràcter,tipus de lletra general +X-KDE-Keywords[ca]=tipus de lletres,mida de tipus de lletra,estils,joc de caràcters,jocs de caràcters,plafó,plafó de control,escriptoris,Gestor de fitxers,Barres d'eines,Menú,Títol de finestra,Títol,DPI,antialiàsing,tipus de lletra d'escriptori,tipus de lletra de barra d'eines,caràcter,tipus de lletra general +X-KDE-Keywords[ca@valencia]=tipus de lletres,mida de tipus de lletra,estils,joc de caràcters,jocs de caràcters,plafó,plafó de control,escriptoris,Gestor de fitxers,Barres d'eines,Menú,Títol de finestra,Títol,DPI,antialiàsing,tipus de lletra d'escriptori,tipus de lletra de barra d'eines,caràcter,tipus de lletra general X-KDE-Keywords[da]=skrifttyper,skriftstørrelse,stile,tegnsæt,panel,kontrolpanel,skriveborde,filhåndtering,værktøjslinjer,menu,vinduestitel,titel,DPI,anti-aliasing,værktøjslinjer,tegn X-KDE-Keywords[de]=Schriftarten,Schriftgrößen,Stile,Zeichensätze,Kontrollleiste,Stile,Dateiverwaltung,Arbeitsflächen,Werkzeugleisten,Menüs,Fenstertitel,Titel,DPI,Antialiasing,Arbeitsflächenschriften,Werkzeugleistenschriften,Zeichen,Allgemeine Schriftarten X-KDE-Keywords[el]=γραμματοσειρές,μέγεθος γραμματοσειράς,στιλ,σύνολα χαρακτήρων,πίνακας,πίνακας ελέγχου,επιφάνειες εργασίας,διαχειριστής αρχείων,γραμμές εργαλείων,μενού,τίτλος παραθύρου,τίτλος,DPI,εξομάλυνση,γραμματοσειρές επιφάνειας εργασίας,γραμματοσειρές γραμμής εργαλείων,χαρακτήρας,γενικές γραμματοσειρές @@ -166,7 +158,7 @@ X-KDE-Keywords[fi]=kirjasimet,fontit,kirjasinkoko,fonttikoko,tyylit,merkistöt,paneeli,ohjauskeskus,työpöydät,Tiedostonhallinta,Työkalurivit,Työkalupalkit,Valikko,Ikkunan otsikko,Otsikko,DPI,antialiasointi,työpöytäkirjasimet,työpöytäfontit,työkalurivikirjasimet, työkalurivien kirjasimet, työkalurivifontit, työkalurivien fontit,merkki,yleiskirjasimet,yleiset kirjasimet,yleisfontit,yleiset fontit X-KDE-Keywords[fr]=polices, taille de police, styles, tables de caractères, jeux de caractères, tableau de bord, bureaux, Gestionnaire de Fichiers, Barre d'outils, Menu, Titre de fenêtre, Titre, DPI, anti crénelage, polices du bureau, police de barre d'outils, caractère, polices générales X-KDE-Keywords[ga]=clónna,clófhoirne,clómhéid,stíleanna,tacair charachtar,painéal,painéal rialaithe,deasca,Bainisteoir Comhad,Barraí Uirlisí,Roghchlár,Teideal Fuinneoige,Teideal,PSO,frithailiasáil,clónna deisce,clófhoirne deisce,clónna barra uirlisí,carachtar,clónna ginearálta,clófhoirne ginearálta -X-KDE-Keywords[gl]=tipo de letra,letra,tamaño de letra,tamaño da letra,codificacións de caracteres,conxuntos de caracteres,panel,control,panel de control,escritorios,xestor de ficheiros,barras de ferramentas,menú,título de xanela,título,DPI,PPP,antialiasing,suavizado,tipos de letra do escritorio,tipos de letra das barras de ferramentas,carácter,tipos de letra xerais +X-KDE-Keywords[gl]=tipo de letra, letra, tamaño da letra, carácter, caracteres, conxunto de caracteres, glifo, panel, control, panel de control, antialiasing, suavizado X-KDE-Keywords[hu]=betűkészletek,betűméret,stílusok,karakterkészletek,karakterkészletek,panel,beállítópanel,asztalok,Fájlkezelő,Eszköztárak,Menü,Ablakcím,Cím,DPI,élsimítás,asztal betűkészletek,eszköztár betűkészletek,karakter,általános betűkészletek X-KDE-Keywords[ia]=fonts,grandor de font,stilos,insimules de characteres,insimules de characteres,pannello,pannello de controlo,scriptorios,Gerente de File,Barra de instrumentos,menu,Titulo de Fenestra,Titulo,DPI,anti-aliasing,fonts de scriptorio, fonts de barra de titulo, character,fonts general X-KDE-Keywords[id]=fonta,ukuran fonta,gaya,charset,set karakter,panel,panel kendali,desktop,ManajerBerkas,Bilah Alat,Menu,Judul Jendela,Judul,DPI,anti-alias,fonta desktop,fonta bilah alat,karakter,fonta umum @@ -178,7 +170,6 @@ X-KDE-Keywords[nb]=skrifter,skriftstørrelse,stiler,tegnsett,panel,kontrollpanel,skrivebord,filbehandler,Verktøylinje,Meny,Vindiustittel,tittel,DPI,kantutjevning,skrivebordsskrifter,verktøylinjeskrifter,generelle skrifter X-KDE-Keywords[nds]=Schriftoorden,Schrift,Stilen,Tekensetten,Paneel,Stüerpaneel,Schriefdisch,Dateipleger,Warktüüchbalkens,Menü,Finstertitel,Titel,DPI,Kantstreken,anti-aliasing,Schriefdisch,Teken X-KDE-Keywords[nl]=lettertypes,lettertype,tekengrootte,stijlen,tekensets,paneel,besturingspaneel,bureaubladen,bestandsbeheerder,werkbalken,menu,venstertitel,titel,DPI,anti-aliasing,lettertypen van bureaublad,lettertypen van werkbalk,teken,algemene lettertypes -X-KDE-Keywords[nn]=skrifter,skriftstorleik,stilar,teiknsett,teiknkodingar,panel,kontrollpanel,skrivebord,filhandsamar,verktøylinje,meny,vindaugstittel,tittel,DPI,PPT,kantutjamning,skrivebordsskrifter,verktøylinjeskrifter,generelle skriftar X-KDE-Keywords[pl]=czcionki,rozmiar czcionki,style,zestaw znaków,panel,panel sterowania,pulpity,Menadżer plików,Paski narzędzi,Menu,Tytuł okna,Tytuł,DPI,wygładzanie,czcionki pulpitu,czcionki pasków narzędzi,znak,czcionki ogólne X-KDE-Keywords[pt]=tipos de letra,tamanho de letra,estilos,codificações,codificações de caracteres,painel,painel de controlo,ecrãs,gestor de ficheiros,barras de ferramentas,menu,título da janela,título,PPP,suavização,tipos de letra do ecrã,tipos de letra da barra de ferramentas,carácter,tipos de letra gerais X-KDE-Keywords[pt_BR]=fontes,tamanho da fonte,estilos,codificações,codificações de caracteres,painel,painel de controle,áreas de trabalho,gerenciador de arquivos,barras de ferramentas,Menu,Título da janela,Título,PPP,anti-aliasing,fontes da área de trabalho,fontes da barra de ferramentas,caractere,fontes gerais @@ -190,7 +181,7 @@ X-KDE-Keywords[sr@ijekavianlatin]=fonts,font size,styles,charsets,character sets,panel,control panel,desktops,FileManager,Toolbars,Menu,Window Title,Title,DPI,anti-aliasing,desktop fonts,toolbar fonts,character,general fonts,font,veličina fonta,stil,kodiranje,panel,kontrolni panel,površ,menadžer fajlova,trake alatki,meni,naslov prozora,tpi,omekšavanje,font površi,font trake alatki,znakovi,opšti font X-KDE-Keywords[sr@latin]=fonts,font size,styles,charsets,character sets,panel,control panel,desktops,FileManager,Toolbars,Menu,Window Title,Title,DPI,anti-aliasing,desktop fonts,toolbar fonts,character,general fonts,font,veličina fonta,stil,kodiranje,panel,kontrolni panel,površ,menadžer fajlova,trake alatki,meni,naslov prozora,tpi,omekšavanje,font površi,font trake alatki,znakovi,opšti font X-KDE-Keywords[sv]=teckensnitt,teckenstorlek,stil,teckenuppsättningar,panel,kontrollpanel,skrivbord,Filhanterare,Verktygsrader,Meny,Fönsternamn,Namn,Punkter/tum,kantutjämning,skrivbordsteckensnitt,verktygsradsteckensnitt,tecken,allmänna teckensnitt -X-KDE-Keywords[tr]=yazı tipi,yazı tipi boyutu,karakterler,karakter setleri,panel,denetim paneli,masaüstleri,Dosya Yöneticisi,Araç Çubukları,Menü,Pencere Başlığı,Başlık,DPI,yumuşatma,anti-aliasing,masaüstü yazı tipleri,araç çubuğu yazı tipleri,karakter,genel yazı tipleri,biçemler +X-KDE-Keywords[tr]=yazı tipi,yazı tipi boyutu,karakterler,karakter setleri,panel,denetim paneli,masaüstleri,Dosya Yöneticisi,Araç Çubukları,Menü,Pencere Başlığı,Başlık,DPI,yumuşatma,anti-aliasing,masaüstü yazı tipleri,araç çubuğu yazı tipleri,karakter,genel yazı tipleri X-KDE-Keywords[uk]=fonts,font size,styles,charsets,character sets,panel,control panel,desktops,FileManager,Toolbars,Menu,Window Title,Title,DPI,anti-aliasing,desktop fonts,toolbar fonts,character,general fonts,шрифт,шрифти,розмір,розмір шрифту,стиль,стилі,гарнітура,гарнітури,кодування,набір,символ,символи,набір символів,панель,панель керування,стільниця,стільниці,файл,керування,керування файлами,менеджер,панель інструментів,меню,заголовок,заголовок вікна,роздільність,згладжування,шрифти стільниці,шрифти панелі,символ,загальні шрифти X-KDE-Keywords[x-test]=xxfontsxx,xxfont sizexx,xxstylesxx,xxcharsetsxx,xxcharacter setsxx,xxpanelxx,xxcontrol panelxx,xxdesktopsxx,xxFileManagerxx,xxToolbarsxx,xxMenuxx,xxWindow Titlexx,xxTitlexx,xxDPIxx,xxanti-aliasingxx,xxdesktop fontsxx,xxtoolbar fontsxx,xxcharacterxx,xxgeneral fontsxx X-KDE-Keywords[zh_CN]=fonts,font size,styles,charsets,character sets,panel,control panel,desktops,FileManager,Toolbars,Menu,Window Title,Title,DPI,anti-aliasing,desktop fonts,toolbar fonts,character,general fonts,字体字体大小,样式,字符集,面板,控制面板,桌面,文件管理器,工具栏,菜单,窗口标题,标题,反锯齿,桌面字体,工具栏字体,字符,常规字体 diff --git a/kcms/fonts/kxftconfig.h b/kcms/fonts/kxftconfig.h --- a/kcms/fonts/kxftconfig.h +++ b/kcms/fonts/kxftconfig.h @@ -64,7 +64,7 @@ SubPixel(Type t, QDomNode &n) : Item(n), type(t) {} SubPixel(Type t = NotSet) : type(t) {} - void reset() Q_DECL_OVERRIDE + void reset() { Item::reset(); type = NotSet; @@ -77,7 +77,7 @@ Exclude(double f, double t, QDomNode &n) : Item(n), from(f), to(t) {} Exclude(double f = 0, double t = 0) : from(f), to(t) {} - void reset() Q_DECL_OVERRIDE + void reset() { Item::reset(); from = to = 0; @@ -99,7 +99,7 @@ Hint(Style s, QDomNode &n) : Item(n), style(s) {} Hint(Style s = NotSet) : style(s) {} - void reset() Q_DECL_OVERRIDE + void reset() { Item::reset(); style = NotSet; @@ -112,7 +112,7 @@ Hinting(bool s, QDomNode &n) : Item(n), set(s) {} Hinting(bool s = true) : set(s) {} - void reset() Q_DECL_OVERRIDE + void reset() { Item::reset(); set = true; @@ -131,7 +131,7 @@ AntiAliasing(State s, QDomNode &n) : Item(n), state(s) {} AntiAliasing(State s = NotSet) : state(s) {} - void reset() Q_DECL_OVERRIDE + void reset() { Item::reset(); state = NotSet; diff --git a/kcms/fonts/kxftconfig.cpp b/kcms/fonts/kxftconfig.cpp --- a/kcms/fonts/kxftconfig.cpp +++ b/kcms/fonts/kxftconfig.cpp @@ -451,7 +451,7 @@ switch (t) { default: case SubPixel::NotSet: - return i18nc("use system subpixel setting", "System default"); + return i18nc("use system subpixel setting", "Vendor Default"); case SubPixel::None: return i18nc("no subpixel rendering", "None"); case SubPixel::Rgb: @@ -469,6 +469,8 @@ { switch (t) { default: + case SubPixel::NotSet: + return ""; case SubPixel::None: return "none"; case SubPixel::Rgb: @@ -487,7 +489,7 @@ switch (s) { default: case Hint::NotSet: - return i18nc("use system hinting settings", "System default"); + return i18nc("use system hinting settings", "Vendor Default"); case Hint::Medium: return i18nc("medium hinting", "Medium"); case Hint::None: diff --git a/kcms/fonts/package/contents/ui/FontWidget.qml b/kcms/fonts/package/contents/ui/FontWidget.qml new file mode 100644 --- /dev/null +++ b/kcms/fonts/package/contents/ui/FontWidget.qml @@ -0,0 +1,68 @@ +/* + Copyright (c) 2015 Antonis Tsiapaliokas + Copyright (c) 2017 Marco Martin + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + 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. +*/ + +import QtQuick 2.1 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 2.0 as QtControls +import QtQuick.Dialogs 1.2 as QtDialogs +import org.kde.kirigami 2.3 as Kirigami +import org.kde.kcm 1.0 + + +FocusScope { + id: root + property string label + property string category + property font font + Kirigami.FormData.label: root.label + activeFocusOnTab: true + + Layout.minimumWidth: layout.Layout.minimumWidth + Layout.preferredWidth: layout.Layout.preferredWidth + Layout.minimumHeight: layout.Layout.minimumHeight + Layout.preferredHeight: layout.Layout.preferredHeight + implicitWidth: layout.implicitWidth + implicitHeight: layout.implicitHeight + + RowLayout { + id: layout + + QtControls.TextField { + enabled: false + text: root.font.family + " " + root.font.pointSize + font: root.font + Layout.fillHeight: true + } + + QtControls.Button { + text: i18n("Choose...") + Layout.fillHeight: true + Kirigami.MnemonicData.enabled: false + focus: true + onClicked: { + fontDialog.adjustAllFonts = false; + fontDialog.currentCategory = root.category + fontDialog.font = root.font; + fontDialog.currentFont = root.font; + fontDialog.open() + } + } + } +} + diff --git a/kcms/fonts/package/contents/ui/main.qml b/kcms/fonts/package/contents/ui/main.qml new file mode 100644 --- /dev/null +++ b/kcms/fonts/package/contents/ui/main.qml @@ -0,0 +1,195 @@ +/* + Copyright (c) 2015 Antonis Tsiapaliokas + Copyright (c) 2017 Marco Martin + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + 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. +*/ + +import QtQuick 2.1 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 2.0 as QtControls +import QtQuick.Dialogs 1.2 as QtDialogs +import org.kde.kirigami 2.3 as Kirigami +import org.kde.kcm 1.1 as KCM + +KCM.SimpleKCM { + id: root + + KCM.ConfigModule.quickHelp: i18n("Fonts") + + Kirigami.FormLayout { + id: formLayout + readonly property int maxImplicitWidth: Math.max(adjustAllFontsButton.implicitWidth, Math.max(antiAliasingComboBox.implicitWidth, Math.max(excludeField.implicitWidth, Math.max(subPixelCombo.implicitWidth, hintingCombo.implicitWidth)))) + + QtControls.Button { + id: adjustAllFontsButton + Layout.preferredWidth: formLayout.maxImplicitWidth + text: i18n("&Adjust All Fonts...") + + onClicked: kcm.adjustAllFonts(); + } + + FontWidget { + id: generalFontWidget + label: i18n("General:") + category: "generalFont" + font: kcm.generalFont + } + FontWidget { + label: i18n("Fixed width:") + category: "fixedWidthFont" + font: kcm.fixedWidthFont + } + FontWidget { + label: i18n("Small:") + category: "smallFont" + font: kcm.smallFont + } + FontWidget { + label: i18n("Toolbar:") + category: "toolbarFont" + font: kcm.toolbarFont + } + FontWidget { + label: i18n("Menu:") + category: "menuFont" + font: kcm.menuFont + } + FontWidget { + label: i18n("Window title:") + category: "windowTitleFont" + font: kcm.windowTitleFont + } + + Kirigami.Separator { + Kirigami.FormData.isSection: true + } + + QtControls.ComboBox { + id: antiAliasingComboBox + Layout.preferredWidth: formLayout.maxImplicitWidth + Kirigami.FormData.label: i18n("Use anti-aliasing:") + + model: [i18n("Enabled"), i18n("Vendor Default"), i18n("Disabled")] + + currentIndex: kcm.fontAASettings.antiAliasing + onCurrentIndexChanged: kcm.fontAASettings.antiAliasing = antiAliasingComboBox.currentIndex + } + + QtControls.CheckBox { + id: excludeCheckBox + checked: kcm.fontAASettings.exclude + onCheckedChanged: kcm.fontAASettings.exclude = checked; + text: i18n("Exclude range from anti-aliasing") + Layout.fillWidth: true + enabled: antiAliasingComboBox.currentIndex == 0 + } + + RowLayout { + id: excludeField + Layout.preferredWidth: formLayout.maxImplicitWidth + enabled: antiAliasingComboBox.currentIndex == 0 + QtControls.SpinBox { + id: excludeFromSpinBox + stepSize: 1 + onValueChanged: kcm.fontAASettings.excludeFrom = value + textFromValue: function(value, locale) { return i18n("%1 pt", value)} + enabled: excludeCheckBox.checked + } + + QtControls.Label { + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + text: i18n("to") + } + + QtControls.SpinBox { + id: excludeToSpinBox + stepSize: 1 + onValueChanged: kcm.fontAASettings.excludeTo = value + textFromValue: function(value, locale) { return i18n("%1 pt", value)} + enabled: excludeCheckBox.checked + } + Connections { + target: kcm.fontAASettings + onExcludeFromChanged: excludeFromSpinBox.value = kcm.fontAASettings.excludeFrom; + onExcludeToChanged: excludeToSpinBox.value = kcm.fontAASettings.excludeTo; + } + } + + QtControls.ComboBox { + id: subPixelCombo + Layout.preferredWidth: formLayout.maxImplicitWidth + Kirigami.FormData.label: i18n("Sub-pixel rendering type:") + currentIndex: kcm.fontAASettings.subPixelCurrentIndex + onCurrentIndexChanged: kcm.fontAASettings.subPixelCurrentIndex = currentIndex; + model: kcm.fontAASettings.subPixelOptionsModel + textRole: "display" + enabled: antiAliasingComboBox.currentIndex == 0 + } + + QtControls.ComboBox { + id: hintingCombo + Layout.preferredWidth: formLayout.maxImplicitWidth + Kirigami.FormData.label: i18n("Hinting style:") + currentIndex: kcm.fontAASettings.hintingCurrentIndex + onCurrentTextChanged: kcm.fontAASettings.hintingCurrentIndex = currentIndex; + model: kcm.fontAASettings.hintingOptionsModel + textRole: "display" + enabled: antiAliasingComboBox.currentIndex == 0 + } + + RowLayout { + QtControls.CheckBox { + id: dpiCheckBox + checked: dpiSpinBox.value != 96 + text: i18n("Force Fonts DPI:") + onCheckedChanged: { + if (!dpiCheckBox.checked) { + dpiSpinBox.enabled = false; + kcm.fontAASettings.dpi = 0; + } else { + dpiSpinBox.enabled = true; + } + } + } + + QtControls.SpinBox { + id: dpiSpinBox + stepSize: 24 + enabled: dpiCheckBox.checked + value: kcm.fontAASettings.dpi + onValueChanged: kcm.fontAASettings.dpi = dpiSpinBox.value + to: 1000 + from: 96 + } + } + + QtDialogs.FontDialog { + id: fontDialog + title: "Choose a font" + property string currentCategory + property bool adjustAllFonts: false + onAccepted: { + if (adjustAllFonts) { + kcm.adjustAllFonts(font); + } else { + kcm[currentCategory] = font; + } + } + } + } +} + diff --git a/kcms/fonts/package/metadata.desktop b/kcms/fonts/package/metadata.desktop new file mode 100644 --- /dev/null +++ b/kcms/fonts/package/metadata.desktop @@ -0,0 +1,149 @@ +[Desktop Entry] +Name=Fonts +Name[af]=Skriftipes +Name[ar]=الخطوط +Name[be]=Шрыфты +Name[be@latin]=Šryfty +Name[bg]=Шрифтове +Name[bn]=ফন্ট +Name[bn_IN]=ফন্ট +Name[br]=Fontoù +Name[bs]=Fontovi +Name[ca]=Tipus de lletra +Name[ca@valencia]=Tipus de lletra +Name[cs]=Písma +Name[csb]=Fòntë +Name[cy]=Ffontiau +Name[da]=Skrifttyper +Name[de]=Schriftarten +Name[el]=Γραμματοσειρές +Name[en_GB]=Fonts +Name[eo]=Tiparoj +Name[es]=Tipos de letra +Name[et]=Fondid +Name[eu]=Letra-tipoak +Name[fa]=قلمها +Name[fi]=Fontit +Name[fr]=Polices de caractères +Name[fy]=Lettertypen +Name[ga]=Clónna +Name[gl]=Tipos de letra +Name[gu]=ફોન્ટ્સ +Name[he]=גופנים +Name[hi]=फ़ॉन्ट्स +Name[hne]=फोंट +Name[hr]=Fontovi +Name[hsb]=Pisma +Name[hu]=Betűtípusok +Name[ia]=Fontes +Name[id]=Fonta +Name[is]=Letur +Name[it]=Caratteri +Name[ja]=フォント +Name[ka]=ფონტები +Name[kk]=Қаріптер +Name[km]=ពុម្ព​អក្សរ +Name[kn]=ಅಕ್ಷರಶೈಲಿಗಳು +Name[ko]=글꼴 +Name[ku]=Curenivîs +Name[lt]=Šriftai +Name[lv]=Fonti +Name[mai]=फान्ट +Name[mk]=Фонтови +Name[ml]=അക്ഷരസഞ്ചയങ്ങള്‍ +Name[mr]=फॉन्ट +Name[ms]=Fon +Name[nb]=Skrifttyper +Name[nds]=Schriftoorden +Name[ne]=फन्ट +Name[nl]=Lettertypen +Name[nn]=Skrifter +Name[oc]=Poliças +Name[or]=ଅକ୍ଷର ରୂପ +Name[pa]=ਫੋਂਟ +Name[pl]=Czcionki +Name[pt]=Tipos de Letra +Name[pt_BR]=Fontes +Name[ro]=Fonturi +Name[ru]=Шрифты +Name[se]=Fonttat +Name[si]=අකුරු +Name[sk]=Písma +Name[sl]=Pisave +Name[sr]=Фонтови +Name[sr@ijekavian]=Фонтови +Name[sr@ijekavianlatin]=Fontovi +Name[sr@latin]=Fontovi +Name[sv]=Teckensnitt +Name[ta]=எழுத்துருக்கள் +Name[te]=ఫాంట్‍స్ +Name[tg]=Ҳарфҳо +Name[th]=แบบอักษรต่างๆ +Name[tr]=Yazı Tipleri +Name[ug]=خەت نۇسخىلىرى +Name[uk]=Шрифти +Name[uz]=Shriftlar +Name[uz@cyrillic]=Шрифтлар +Name[vi]=Phông chữ +Name[wa]=Fontes +Name[xh]=Uhlobo lwamagama +Name[x-test]=xxFontsxx +Name[zh_CN]=字体 +Name[zh_TW]=字型 + +Comment=Fonts +Comment[ar]=الخطوط +Comment[bs]=Fontovi +Comment[ca]=Tipus de lletra +Comment[cs]=Písma +Comment[da]=Skrifttyper +Comment[de]=Schriftarten +Comment[el]=Γραμματοσειρές +Comment[en_GB]=Fonts +Comment[es]=Tipos de letra +Comment[fi]=Fontit +Comment[fr]=Polices de caractères +Comment[gl]=Tipos de letra +Comment[hu]=Betűtípusok +Comment[id]=Fonta +Comment[it]=Caratteri +Comment[ko]=글꼴 +Comment[lt]=Šriftai +Comment[mr]=फॉन्ट +Comment[nb]=Skrifttype +Comment[nds]=Schriftoorden +Comment[nl]=Lettertypen +Comment[pa]=ਫੋਂਟ +Comment[pl]=Czcionki +Comment[pt]=Tipos de Letra +Comment[pt_BR]=Fontes +Comment[ru]=Шрифты +Comment[sk]=Písma +Comment[sl]=Pisave +Comment[sr]=Фонтови +Comment[sr@ijekavian]=Фонтови +Comment[sr@ijekavianlatin]=Fontovi +Comment[sr@latin]=Fontovi +Comment[sv]=Teckensnitt +Comment[tr]=Yazı Tipleri +Comment[uk]=Шрифти +Comment[x-test]=xxFontsxx +Comment[zh_CN]=字体 +Comment[zh_TW]=字型 + +Icon=preferences-desktop-font +Encoding=UTF-8 +Keywords= +Type=Service +X-KDE-ParentApp= +X-KDE-PluginInfo-Author=Antonis Tsiapaliokas +X-KDE-PluginInfo-Email=antonis.tsiapaliokas@kde.org +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-Name=kcm_fonts +X-KDE-PluginInfo-Version= +X-KDE-PluginInfo-Website= +X-KDE-ServiceTypes=Plasma/Generic +X-Plasma-API=declarativeappletscript + +X-Plasma-MainScript=ui/main.qml +X-Plasma-RemoteLocation=