Commit a4d23764 authored by Benjamin Port's avatar Benjamin Port
Browse files

Port fonts KCM to KConfigXT

Reviewers: #plasma, ervin, mart

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D24669
parent c72a1d5c
......@@ -19,6 +19,7 @@ endif()
set(klauncher_xml ${KINIT_DBUS_INTERFACES_DIR}/kf5_org.kde.KLauncher.xml)
qt5_add_dbus_interface(kcm_fonts_PART_SRCS ${klauncher_xml} klauncher_iface)
kconfig_add_kcfg_files(kcm_fonts_PART_SRCS fontssettings.kcfgc GENERATE_MOC)
add_library(kcm_fonts MODULE ${kcm_fonts_PART_SRCS})
target_link_libraries(kcm_fonts Qt5::DBus Qt5::Xml KF5::KCMUtils KF5::I18n KF5::KDELibs4Support ${FREETYPE_LIBRARIES} kfontinst)
......@@ -41,6 +42,7 @@ endif()
kcoreaddons_desktop_to_json(kcm_fonts "kcm_fonts.desktop")
########### install files ###############
install(FILES fontssettings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
install(TARGETS kcm_fonts DESTINATION ${KDE_INSTALL_PLUGINDIR}/kcms)
install(FILES kcm_fonts.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
kpackage_install_package(package kcm_fonts kcms)
......@@ -4,6 +4,7 @@
Copyright 2000 Rik Hemsley
Copyright 2015 Antonis Tsiapaliokas <antonis.tsiapaliokas@kde.org>
Copyright 2017 Marco Martin <mart@kde.org>
Copyright 2019 Benjamin Port <benjamin.port@enioka.com>
Ported to kcontrol2 by Geert Jansen.
......@@ -49,6 +50,8 @@
#include "../krdb/krdb.h"
#include "previewimageprovider.h"
#include "fontssettings.h"
/**** DLL Interface ****/
K_PLUGIN_FACTORY_WITH_JSON(KFontsFactory, "kcm_fonts.json", registerPlugin<KFonts>();)
......@@ -467,6 +470,7 @@ bool FontAASettings::needsSave() const
KFonts::KFonts(QObject *parent, const QVariantList &args)
: KQuickAddons::ConfigModule(parent, args)
, m_settings(new FontsSettings(this))
, m_fontAASettings(new FontAASettings(this))
{
KAboutData* about = new KAboutData("kcm_fonts", i18n("Fonts"),
......@@ -474,12 +478,22 @@ KFonts::KFonts(QObject *parent, const QVariantList &args)
about->addAuthor(i18n("Antonis Tsiapaliokas"), QString(), "antonis.tsiapaliokas@kde.org");
setAboutData(about);
qmlRegisterType<QStandardItemModel>();
qmlRegisterType<FontsSettings>();
setButtons(Apply | Default | Help);
auto updateState = [this]() {
setNeedsSave(m_fontAASettings->needsSave());
};
connect(m_settings, &FontsSettings::configChanged, this, &KFonts::updateNeedsSave);
connect(m_settings, &FontsSettings::fontChanged, this, &KFonts::updateNeedsSave);
connect(m_settings, &FontsSettings::fixedChanged, this, &KFonts::updateNeedsSave);
connect(m_settings, &FontsSettings::smallestReadableFont, this, &KFonts::updateNeedsSave);
connect(m_settings, &FontsSettings::toolBarFont, this, &KFonts::updateNeedsSave);
connect(m_settings, &FontsSettings::menuFont, this, &KFonts::updateNeedsSave);
connect(m_settings, &FontsSettings::activeFont, this, &KFonts::updateNeedsSave);
connect(m_fontAASettings, &FontAASettings::subPixelCurrentIndexChanged, this, updateState);
connect(m_fontAASettings, &FontAASettings::hintingCurrentIndexChanged, this, updateState);
connect(m_fontAASettings, &FontAASettings::excludeChanged, this, updateState);
......@@ -494,54 +508,32 @@ KFonts::~KFonts()
{
}
void KFonts::defaults()
FontsSettings *KFonts::fontsSettings() const
{
#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
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
return m_settings;
}
void KFonts::defaults()
{
m_settings->setDefaults();
m_fontAASettings->defaults();
}
void KFonts::load()
void KFonts::setNearestExistingFonts()
{
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", QFont("Hack", 9)));
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));
engine()->addImageProvider("preview", new PreviewImageProvider(generalFont()));
m_settings->setFont(nearestExistingFont(m_settings->font()));
m_settings->setFixed(nearestExistingFont(m_settings->fixed()));
m_settings->setSmallestReadableFont(nearestExistingFont(m_settings->smallestReadableFont()));
m_settings->setToolBarFont(nearestExistingFont(m_settings->toolBarFont()));
m_settings->setMenuFont(nearestExistingFont(m_settings->menuFont()));
m_settings->setActiveFont(nearestExistingFont(m_settings->activeFont()));
}
emit generalFontChanged();
emit fixedWidthFontChanged();
emit smallFontChanged();
emit toolbarFontChanged();
emit menuFontChanged();
emit windowTitleFontChanged();
void KFonts::load()
{
m_settings->load();
setNearestExistingFonts();
engine()->addImageProvider("preview", new PreviewImageProvider(m_settings->font()));
m_fontAASettings->load();
setNeedsSave(false);
......@@ -549,26 +541,7 @@ void KFonts::load()
void KFonts::save()
{
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;
m_settings->save();
KConfig _cfgfonts("kcmfonts");
KConfigGroup cfgfonts(&_cfgfonts, "General");
......@@ -597,130 +570,25 @@ void KFonts::save()
void KFonts::updateNeedsSave()
{
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::setGeneralFont(const QFont &font)
{
if (m_generalFont == font) {
return;
}
m_generalFont = font;
emit generalFontChanged();
updateNeedsSave();
}
QFont KFonts::generalFont() const
{
return m_generalFont;
}
void KFonts::setFixedWidthFont(const QFont &font)
{
if (m_fixedWidthFont == font) {
return;
}
m_fixedWidthFont = font;
emit fixedWidthFontChanged();
updateNeedsSave();
}
QFont KFonts::fixedWidthFont() const
{
return m_fixedWidthFont;
}
void KFonts::setSmallFont(const QFont &font)
{
if (m_smallFont == font) {
return;
}
m_smallFont = font;
emit smallFontChanged();
updateNeedsSave();
}
QFont KFonts::smallFont() const
{
return m_smallFont;
}
void KFonts::setToolbarFont(const QFont &font)
{
if (m_toolbarFont == font) {
return;
}
m_toolbarFont = font;
emit toolbarFontChanged();
updateNeedsSave();
}
QFont KFonts::toolbarFont() const
{
return m_toolbarFont;
}
void KFonts::setMenuFont(const QFont &font)
{
if (m_menuFont == font) {
return;
}
m_menuFont = font;
emit menuFontChanged();
updateNeedsSave();
}
QFont KFonts::menuFont() const
{
return m_menuFont;
}
void KFonts::setWindowTitleFont(const QFont &font)
{
if (m_windowTitleFont == font) {
return;
}
m_windowTitleFont = font;
emit windowTitleFontChanged();
updateNeedsSave();
}
QFont KFonts::windowTitleFont() const
{
return m_windowTitleFont;
setNeedsSave(m_settings->isSaveNeeded() || m_fontAASettings->needsSave());
}
void KFonts::adjustAllFonts()
{
QFont font = m_generalFont;
QFont font = m_settings->font();
KFontChooser::FontDiffFlags fontDiffFlags;
int ret = KFontDialog::getFontDiff(font, fontDiffFlags, KFontChooser::NoDisplayFlags);
if (ret == KDialog::Accepted && 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);
}
m_settings->setFont(applyFontDiff(m_settings->font(), font, fontDiffFlags));
m_settings->setMenuFont(applyFontDiff(m_settings->menuFont(), font, fontDiffFlags));
m_settings->setToolBarFont(applyFontDiff(m_settings->toolBarFont(), font, fontDiffFlags));
m_settings->setActiveFont(applyFontDiff(m_settings->activeFont(), font, fontDiffFlags));
m_settings->setSmallestReadableFont(applyFontDiff(m_settings->smallestReadableFont(), font, fontDiffFlags));
const QFont adjustedFont = applyFontDiff(m_settings->fixed(), font, fontDiffFlags);
if (QFontInfo(adjustedFont).fixedPitch()) {
m_settings->setFixed(adjustedFont);
}
setToolbarFont(applyFontDiff(m_toolbarFont, font, fontDiffFlags));
setSmallFont(applyFontDiff(m_smallFont, font, fontDiffFlags));
setWindowTitleFont(applyFontDiff(m_windowTitleFont, font, fontDiffFlags));
}
}
......
......@@ -4,6 +4,7 @@
Copyright 2000 Rik Hemsley
Copyright 2015 Antonis Tsiapaliokas <antonis.tsiapaliokas@kde.org>
Copyright 2017 Marco Martin <mart@kde.org>
Copyright 2019 Benjamin Port <benjamin.port@enioka.com>
Ported to kcontrol2 by Geert Jansen.
......@@ -34,6 +35,8 @@
#include "kxftconfig.h"
class FontsSettings;
class FontAASettings : public QObject
{
Q_OBJECT
......@@ -134,35 +137,14 @@ private:
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(FontsSettings *fontsSettings READ fontsSettings CONSTANT)
Q_PROPERTY(QObject *fontAASettings READ fontAASettings CONSTANT)
public:
KFonts(QObject *parent, const QVariantList &);
~KFonts() 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;
FontsSettings *fontsSettings() const;
QObject* fontAASettings() { return m_fontAASettings; }
......@@ -175,32 +157,12 @@ public Q_SLOTS:
Q_SIGNALS:
void fontsHaveChanged();
void generalFontChanged();
void fixedWidthFontChanged();
void smallFontChanged();
void toolbarFontChanged();
void menuFontChanged();
void windowTitleFontChanged();
private:
void updateNeedsSave();
QFont applyFontDiff(const QFont &fnt, const QFont &newFont, int fontDiffFlags);
void setNearestExistingFonts();
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;
FontsSettings *m_settings;
FontAASettings *m_fontAASettings;
};
......
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="kdeglobals" />
<group name="General">
<entry name="font" type="Font">
<label>General font</label>
<code>
#ifdef Q_OS_MAC
QFont generalFont = QFont("Lucida Grande", 13);
#else
QFont generalFont = QFont("Noto Sans", 10);
#endif
</code>
<default code="true">generalFont</default>
</entry>
<entry name="fixed" type="Font">
<label>Fixed width font</label>
<code>
#ifdef Q_OS_MAC
QFont fixedWidthFont = QFont("Monaco", 10);
#else
QFont fixedWidthFont = QFont("Hack", 9);
#endif
</code>
<default code="true">fixedWidthFont</default>
</entry>
<entry name="smallestReadableFont" type="Font">
<label>Small font</label>
<code>
#ifdef Q_OS_MAC
QFont smallFont = QFont("Lucida Grande", 9);
#else
QFont smallFont = QFont("Noto Sans", 8);
#endif
</code>
<default code="true">smallFont</default>
</entry>
<entry name="toolBarFont" type="Font">
<label>Tool bar font</label>
<code>
#ifdef Q_OS_MAC
QFont toolBarFont = QFont("Lucida Grande", 11);
#else
QFont toolBarFont = QFont("Noto Sans", 10);
#endif
</code>
<default code="true">toolBarFont</default>
</entry>
<entry name="menuFont" type="Font">
<label>Menu font</label>
<code>
#ifdef Q_OS_MAC
QFont menuFont = QFont("Lucida Grande", 13);
#else
QFont menuFont = QFont("Noto Sans", 10);
#endif
</code>
<default code="true">menuFont</default>
</entry>
</group>
<group name="WM">
<entry name="activeFont" type="Font">
<label>Window title font</label>
<code>
#ifdef Q_OS_MAC
QFont windowTitleFont = QFont("Lucida Grande", 14);
#else
QFont windowTitleFont = QFont("Noto Sans", 10);
#endif
</code>
<default code="true">windowTitleFont</default>
</entry>
</group>
</kcfg>
File=fontssettings.kcfg
ClassName=FontsSettings
Mutators=true
DefaultValueGetters=true
GenerateProperties=true
ParentInConstructor=true
/*
Copyright (c) 2015 Antonis Tsiapaliokas <antonis.tsiapaliokas@kde.org>
Copyright (c) 2017 Marco Martin <mart@kde.org>
Copyright (c) 2019 Benjamin Port <benjamin.port@enioka.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -59,33 +60,33 @@ KCM.SimpleKCM {
FontWidget {
id: generalFontWidget
label: i18n("General:")
category: "generalFont"
font: kcm.generalFont
category: "font"
font: kcm.fontsSettings.font
}
FontWidget {
label: i18n("Fixed width:")
category: "fixedWidthFont"
font: kcm.fixedWidthFont
category: "fixed"
font: kcm.fontsSettings.fixed
}
FontWidget {
label: i18n("Small:")
category: "smallFont"
font: kcm.smallFont
category: "smallestReadableFont"
font: kcm.fontsSettings.smallestReadableFont
}
FontWidget {
label: i18n("Toolbar:")
category: "toolbarFont"
font: kcm.toolbarFont
category: "toolBarFont"
font: kcm.fontsSettings.toolBarFont
}
FontWidget {
label: i18n("Menu:")
category: "menuFont"
font: kcm.menuFont
font: kcm.fontsSettings.menuFont
}
FontWidget {
label: i18n("Window title:")
category: "windowTitleFont"
font: kcm.windowTitleFont
category: "activeFont"
font: kcm.fontsSettings.activeFont
}
Kirigami.Separator {
......@@ -247,7 +248,7 @@ KCM.SimpleKCM {
if (adjustAllFonts) {
kcm.adjustAllFonts(font);
} else {
kcm[currentCategory] = font;
kcm.fontsSettings[currentCategory] = font;
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment