Commit d28337b6 authored by Benjamin Port's avatar Benjamin Port

KCM Fonts port anti aliasing part to KPropertySkeletonItem

Reviewers: #plasma, ervin, crossi, meven

Reviewed By: ervin, crossi, meven

Subscribers: usta, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D27156
parent d6731530
......@@ -10,13 +10,14 @@ include_directories(${FREETYPE_INCLUDE_DIRS})
include_directories(../kfontinst/lib)
set(kcm_fonts_PART_SRCS ../krdb/krdb.cpp previewrenderengine.cpp previewimageprovider.cpp fonts.cpp ../kfontinst/lib/FcEngine.cpp)
set(kcm_fonts_PART_SRCS ../krdb/krdb.cpp previewrenderengine.cpp previewimageprovider.cpp fonts.cpp fontsaasettings.cpp ../kfontinst/lib/FcEngine.cpp)
if(X11_FOUND)
set(kcm_fonts_PART_SRCS ${kcm_fonts_PART_SRCS} ${libkxftconfig_SRCS})
endif()
kconfig_add_kcfg_files(kcm_fonts_PART_SRCS fontssettings.kcfgc GENERATE_MOC)
kconfig_add_kcfg_files(kcm_fonts_PART_SRCS fontssettings.kcfgc fontsaasettingsbase.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)
......
This diff is collapsed.
......@@ -33,103 +33,8 @@
#include <KQuickAddons/ManagedConfigModule>
#include "kxftconfig.h"
class FontsSettings;
class FontAASettings : public QObject
{
Q_OBJECT
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)
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(bool antiAliasing READ antiAliasing WRITE setAntiAliasing NOTIFY aliasingChanged)
Q_PROPERTY(int dpi READ dpi WRITE setDpi NOTIFY dpiChanged)
struct State
{
bool exclude;
int excludeFrom;
int excludeTo;
int antiAliasing;
bool antiAliasingHasLocalConfig;
bool subPixelHasLocalConfig;
bool hintingHasLocalConfig;
int dpi;
int subPixel;
int hinting;
bool operator==(const State& other) const;
bool operator!=(const State& other) const;
};
public:
enum AASetting { AAEnabled, AASystem, AADisabled };
#if defined(HAVE_FONTCONFIG) && HAVE_X11
FontAASettings(QObject *parent);
bool save(KXftConfig::AntiAliasing::State aaState);
void load();
void defaults();
QAbstractItemModel* subPixelOptionsModel() { return m_subPixelOptionsModel; }
QAbstractItemModel* hintingOptionsModel() { return m_hintingOptionsModel; }
void setExclude(bool exclude);
bool exclude() const;
void setExcludeTo(int excludeTo);
int excludeTo() const;
void setExcludeFrom(int excludeFrom);
int excludeFrom() const;
void setAntiAliasing(bool antiAliasing);
bool antiAliasing() const;
bool antiAliasingNeedsSave() const;
bool subPixelNeedsSave() const;
bool hintingNeedsSave() const;
void setDpi(const int &dpi);
int dpi() const;
int subPixelCurrentIndex();
void setSubPixelCurrentIndex(int idx);
void setSubPixel(int idx);
int hintingCurrentIndex();
void setHintingCurrentIndex(int idx);
void setHinting(int idx);
bool needsSave() const;
bool isDefaults() const;
#endif
Q_SIGNALS:
void excludeChanged();
void excludeToChanged();
void excludeFromChanged();
void antiAliasingChanged();
void aliasingChangeApplied();
void aliasingChanged();
void dpiChanged();
void subPixelCurrentIndexChanged();
void hintingCurrentIndexChanged();
#if defined(HAVE_FONTCONFIG) && HAVE_X11
private:
State m_state;
State m_originalState;
QStandardItemModel *m_subPixelOptionsModel;
QStandardItemModel *m_hintingOptionsModel;
#endif
};
class FontsAASettings;
/**
* The Desktop/fonts tab in kcontrol.
......@@ -138,34 +43,45 @@ class KFonts : public KQuickAddons::ManagedConfigModule
{
Q_OBJECT
Q_PROPERTY(FontsSettings *fontsSettings READ fontsSettings CONSTANT)
Q_PROPERTY(QObject *fontAASettings READ fontAASettings CONSTANT)
Q_PROPERTY(FontsAASettings *fontsAASettings READ fontsAASettings CONSTANT)
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)
public:
KFonts(QObject *parent, const QVariantList &);
~KFonts() override;
FontsSettings *fontsSettings() const;
FontsAASettings *fontsAASettings() const;
QObject* fontAASettings() { return m_fontAASettings; }
int subPixelCurrentIndex() const;
void setHintingCurrentIndex(int idx);
int hintingCurrentIndex() const;
void setSubPixelCurrentIndex(int idx);
QAbstractItemModel *subPixelOptionsModel() const;
QAbstractItemModel *hintingOptionsModel() const;
public Q_SLOTS:
void load() override;
void save() override;
void defaults() override;
Q_INVOKABLE void adjustAllFonts();
Q_SIGNALS:
void fontsHaveChanged();
void hintingCurrentIndexChanged();
void subPixelCurrentIndexChanged();
void aliasingChangeApplied();
private:
bool isSaveNeeded() const override;
bool isDefaults() const override;
QFont applyFontDiff(const QFont &fnt, const QFont &newFont, int fontDiffFlags);
void setNearestExistingFonts();
FontsSettings *m_settings;
FontAASettings *m_fontAASettings;
FontsAASettings *m_settingsAA;
QStandardItemModel *m_subPixelOptionsModel;
QStandardItemModel *m_hintingOptionsModel;
};
#endif
......
This diff is collapsed.
/**
* Copyright 2020 Benjamin Port <benjamin.port@enioka.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef FONTSAASETTINGS_H
#define FONTSAASETTINGS_H
#include "fontsaasettingsbase.h"
#include "kxftconfig.h"
class FontAASettingsStore;
class FontsAASettings : public FontsAASettingsBase
{
Q_OBJECT
Q_PROPERTY(bool exclude READ exclude WRITE setExclude NOTIFY excludeChanged)
Q_PROPERTY(int excludeFrom READ excludeFrom WRITE setExcludeFrom NOTIFY excludeFromChanged)
Q_PROPERTY(int excludeTo READ excludeTo WRITE setExcludeTo NOTIFY excludeToChanged)
Q_PROPERTY(bool antiAliasing READ antiAliasing WRITE setAntiAliasing NOTIFY antiAliasingChanged)
Q_PROPERTY(int dpi READ dpi WRITE setDpi NOTIFY dpiChanged)
Q_PROPERTY(KXftConfig::SubPixel::Type subPixel READ subPixel WRITE setSubPixel NOTIFY subPixelChanged)
Q_PROPERTY(KXftConfig::Hint::Style hinting READ hinting WRITE setHinting NOTIFY hintingChanged)
public:
FontsAASettings(QObject *parent = nullptr);
bool exclude() const;
int excludeFrom() const;
int excludeTo() const;
bool antiAliasing() const;
int dpi() const;
KXftConfig::SubPixel::Type subPixel() const;
KXftConfig::Hint::Style hinting() const;
void setExclude(bool exclude);
void setExcludeFrom(int excludeFrom);
void setExcludeTo(int excludeTo);
void setAntiAliasing(bool antiAliasing);
void setDpi(int dpi);
void setSubPixel(KXftConfig::SubPixel::Type subPixel);
void setHinting(KXftConfig::Hint::Style hinting);
signals:
void excludeChanged();
void excludeFromChanged();
void excludeToChanged();
void antiAliasingChanged();
void dpiChanged();
void subPixelChanged();
void hintingChanged();
void aliasingChangeApplied();
private:
FontAASettingsStore *m_fontAASettingsStore;
bool usrSave() override;
using NotifySignalType = void (FontsAASettings::*)();
void addItemInternal(const QByteArray &propertyName, const QVariant &defaultValue, NotifySignalType notifySignal);
};
#endif
<?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="kcmfonts" />
<group name="General">
<entry name="forceFontDPIWayland" type="UInt">
<label>Force font DPI Wayland</label>
<default>0</default>
</entry>
<entry name="forceFontDPI" type="UInt">
<label>Force font DPI X11</label>
<default>0</default>
</entry>
</group>
</kcfg>
File=fontsaasettingsbase.kcfg
ClassName=FontsAASettingsBase
Mutators=true
DefaultValueGetters=true
GenerateProperties=true
ParentInConstructor=true
......@@ -27,6 +27,7 @@
#include <QDateTime>
#include <QDomDocument>
#include <QStringList>
#include <QtCore/QMetaType>
class KXftConfig
{
......@@ -200,6 +201,8 @@ private:
QDateTime m_time;
};
Q_DECLARE_METATYPE(KXftConfig::Hint::Style)
Q_DECLARE_METATYPE(KXftConfig::SubPixel::Type)
#endif
#endif
......@@ -39,7 +39,7 @@ KCM.SimpleKCM {
text: i18n("Some changes such as anti-aliasing or DPI will only affect newly started applications.")
Connections {
target: kcm.fontAASettings
target: kcm
onAliasingChangeApplied: antiAliasingMessage.visible = true
}
}
......@@ -107,8 +107,8 @@ KCM.SimpleKCM {
QtControls.CheckBox {
id: antiAliasingCheckBox
checked: kcm.fontAASettings.antiAliasing
onCheckedChanged: kcm.fontAASettings.antiAliasing = checked
checked: kcm.fontsAASettings.antiAliasing
onCheckedChanged: kcm.fontsAASettings.antiAliasing = checked
Kirigami.FormData.label: i18n("Anti-Aliasing:")
text: i18n("Enable")
Layout.fillWidth: true
......@@ -116,8 +116,8 @@ KCM.SimpleKCM {
QtControls.CheckBox {
id: excludeCheckBox
checked: kcm.fontAASettings.exclude
onCheckedChanged: kcm.fontAASettings.exclude = checked;
checked: kcm.fontsAASettings.exclude
onCheckedChanged: kcm.fontsAASettings.exclude = checked;
text: i18n("Exclude range from anti-aliasing")
Layout.fillWidth: true
enabled: antiAliasingCheckBox.checked
......@@ -130,11 +130,12 @@ KCM.SimpleKCM {
QtControls.SpinBox {
id: excludeFromSpinBox
stepSize: 1
onValueChanged: kcm.fontAASettings.excludeFrom = value
onValueChanged: kcm.fontsAASettings.excludeFrom = value
textFromValue: function(value, locale) { return i18n("%1 pt", value)}
valueFromText: function(text, locale) { return parseInt(text) }
editable: true
enabled: excludeCheckBox.checked
value: kcm.fontsAASettings.excludeFrom
}
QtControls.Label {
......@@ -147,16 +148,17 @@ KCM.SimpleKCM {
QtControls.SpinBox {
id: excludeToSpinBox
stepSize: 1
onValueChanged: kcm.fontAASettings.excludeTo = value
onValueChanged: kcm.fontsAASettings.excludeTo = value
textFromValue: function(value, locale) { return i18n("%1 pt", value)}
valueFromText: function(text, locale) { return parseInt(text) }
editable: true
enabled: excludeCheckBox.checked
value: kcm.fontsAASettings.excludeTo
}
Connections {
target: kcm.fontAASettings
onExcludeFromChanged: excludeFromSpinBox.value = kcm.fontAASettings.excludeFrom;
onExcludeToChanged: excludeToSpinBox.value = kcm.fontAASettings.excludeTo;
target: kcm.fontsAASettings
onExcludeFromChanged: excludeFromSpinBox.value = kcm.fontsAASettings.excludeFrom;
onExcludeToChanged: excludeToSpinBox.value = kcm.fontsAASettings.excludeTo;
}
}
......@@ -164,9 +166,9 @@ KCM.SimpleKCM {
id: subPixelCombo
Layout.preferredWidth: formLayout.maxImplicitWidth
Kirigami.FormData.label: i18nc("Used as a noun, and precedes a combobox full of options", "Sub-pixel rendering:")
currentIndex: kcm.fontAASettings.subPixelCurrentIndex
onCurrentIndexChanged: kcm.fontAASettings.subPixelCurrentIndex = currentIndex;
model: kcm.fontAASettings.subPixelOptionsModel
currentIndex: kcm.subPixelCurrentIndex
onCurrentIndexChanged: kcm.subPixelCurrentIndex = currentIndex;
model: kcm.subPixelOptionsModel
textRole: "display"
enabled: antiAliasingCheckBox.checked
popup.height: popup.implicitHeight
......@@ -184,7 +186,7 @@ KCM.SimpleKCM {
}
Image {
id: subPixelComboImage
source: "image://preview/" + model.index + "_" + kcm.fontAASettings.hintingCurrentIndex + ".png"
source: "image://preview/" + model.index + "_" + kcm.hintingCurrentIndex + ".png"
// Setting sourceSize here is necessary as a workaround for QTBUG-38127
//
// With this bug, images requested from a QQuickImageProvider have an incorrect scale with devicePixelRatio != 1 when sourceSize is not set.
......@@ -201,9 +203,9 @@ KCM.SimpleKCM {
id: hintingCombo
Layout.preferredWidth: formLayout.maxImplicitWidth
Kirigami.FormData.label: i18nc("Used as a noun, and precedes a combobox full of options", "Hinting:")
currentIndex: kcm.fontAASettings.hintingCurrentIndex
onCurrentTextChanged: kcm.fontAASettings.hintingCurrentIndex = currentIndex;
model: kcm.fontAASettings.hintingOptionsModel
currentIndex: kcm.hintingCurrentIndex
onCurrentTextChanged: kcm.hintingCurrentIndex = currentIndex;
model: kcm.hintingOptionsModel
textRole: "display"
enabled: antiAliasingCheckBox.checked
popup.height: popup.implicitHeight
......@@ -221,7 +223,7 @@ KCM.SimpleKCM {
}
Image {
id: hintingComboImage
source: "image://preview/" + kcm.fontAASettings.subPixelCurrentIndex + "_" + model.index + ".png"
source: "image://preview/" + kcm.subPixelCurrentIndex + "_" + model.index + ".png"
// Setting sourceSize here is necessary as a workaround for QTBUG-38127
//
// With this bug, images requested from a QQuickImageProvider have an incorrect scale with devicePixelRatio != 1 when sourceSize is not set.
......@@ -237,9 +239,9 @@ KCM.SimpleKCM {
RowLayout {
QtControls.CheckBox {
id: dpiCheckBox
checked: kcm.fontAASettings.dpi !== 0
checked: kcm.fontsAASettings.dpi !== 0
text: i18n("Force font DPI:")
onClicked: kcm.fontAASettings.dpi = (checked ? dpiSpinBox.value : 0)
onClicked: kcm.fontsAASettings.dpi = (checked ? dpiSpinBox.value : 0)
}
QtControls.SpinBox {
......@@ -247,8 +249,8 @@ KCM.SimpleKCM {
stepSize: 24
editable: true
enabled: dpiCheckBox.checked
value: kcm.fontAASettings.dpi !== 0 ? kcm.fontAASettings.dpi : 96
onValueModified: kcm.fontAASettings.dpi = value
value: kcm.fontsAASettings.dpi !== 0 ? kcm.fontsAASettings.dpi : 96
onValueModified: kcm.fontsAASettings.dpi = value
// to: need to divide to stepSize
to: 1008
// lowest vaue here can be == stepSize, that is because 0 means off
......
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