Commit 90ac7c21 authored by Ahmad Samir's avatar Ahmad Samir

[Fonts KCM] Use KFontChooserDialog instead of QFontDialog

Summary:
Now all font selection dialogs use KFontChooserDialog (from KWidgetAddons),
bump KF5 minimum required version to 5.69.0.

KFontChooserDialog has some pros over QFontDialog:
 - If the font to pre-select in KFontChooser doesn't have the styleName
   property set, the dialog will try and select the correct style (usually
   that works); this is useful since we want to save/load fonts with
   "Regular"-like styles without setting that property so that setBold(true)
   can work properly
- Fractional font sizes, e.g. 10.5 pt (QFontDialog only supports int)
- KFontChooserDialog will discard "Regular"-like styleName prop. after
  the user has selected a font, which means less workarounds in the fonts
  KCM code.

Do not check for immutability:
 - The setters generated by KConfig already do that
 - The QML FontWidget check for immutability and disable the relevant
   font widget

adjustAllFonts() doesn't take any args, change the qml code accrodingly.

Test Plan: The fonts KCM still works.

Reviewers: #plasma, davidedmundson, broulik, meven, cfeck, bport

Reviewed By: bport

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D27808
parent 3e8c7dad
......@@ -54,6 +54,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
Activities
ActivitiesStats
Config
WidgetsAddons
)
find_package(KF5Kirigami2 ${KF5_MIN_VERSION} CONFIG)
......
......@@ -30,6 +30,7 @@ if(X11_FOUND)
KF5::PlasmaQuick
KF5::Declarative
KF5::QuickAddons
KF5::WidgetsAddons
PW::KWorkspace)
if(FONTCONFIG_FOUND)
target_link_libraries(kcm_fonts ${FONTCONFIG_LIBRARIES})
......
......@@ -31,7 +31,6 @@
#include <QWindow>
#include <QQmlEngine>
#include <QQuickView>
#include <QFontDialog>
#include <QApplication>
#include <QFontDatabase>
......@@ -42,7 +41,7 @@
#include <KAboutData>
#include <KLocalizedString>
#include <KPluginFactory>
#include <KFontDialog>
#include <KFontChooserDialog>
#include <KWindowSystem>
#include "../krdb/krdb.h"
......@@ -230,30 +229,43 @@ void KFonts::save()
emit fontsHaveChanged();
}
void KFonts::adjustFont(const QFont &font, const QString &category)
{
QFont selFont = font;
int ret = KFontChooserDialog::getFont(selFont, KFontChooser::NoDisplayFlags);
if (ret == QDialog::Accepted) {
if (category == QLatin1String("font")) {
m_settings->setFont(selFont);
} else if (category == QLatin1String("menuFont")) {
m_settings->setMenuFont(selFont);
} else if (category == QLatin1String("toolBarFont")) {
m_settings->setToolBarFont(selFont);
} else if (category == QLatin1String("activeFont")) {
m_settings->setActiveFont(selFont);
} else if (category == QLatin1String("smallestReadableFont")) {
m_settings->setSmallestReadableFont(selFont);
} else if (category == QLatin1String("fixed")) {
m_settings->setFixed(selFont);
}
}
}
void KFonts::adjustAllFonts()
{
QFont font = m_settings->font();
KFontChooser::FontDiffFlags fontDiffFlags;
int ret = KFontDialog::getFontDiff(font, fontDiffFlags, KFontChooser::NoDisplayFlags);
int ret = KFontChooserDialog::getFontDiff(font, fontDiffFlags, KFontChooser::NoDisplayFlags);
if (ret == QDialog::Accepted && fontDiffFlags) {
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));
if (ret == KDialog::Accepted && fontDiffFlags) {
if (!m_settings->isImmutable("font")) {
m_settings->setFont(applyFontDiff(m_settings->font(), font, fontDiffFlags));
}
if (!m_settings->isImmutable("menuFont")) {
m_settings->setMenuFont(applyFontDiff(m_settings->menuFont(), font, fontDiffFlags));
}
if (!m_settings->isImmutable("toolBarFont")) {
m_settings->setToolBarFont(applyFontDiff(m_settings->toolBarFont(), font, fontDiffFlags));
}
if (!m_settings->isImmutable("activeFont")) {
m_settings->setActiveFont(applyFontDiff(m_settings->activeFont(), font, fontDiffFlags));
}
if (!m_settings->isImmutable("smallestReadableFont")) {
m_settings->setSmallestReadableFont(applyFontDiff(m_settings->smallestReadableFont(), font, fontDiffFlags));
}
const QFont adjustedFont = applyFontDiff(m_settings->fixed(), font, fontDiffFlags);
if (QFontInfo(adjustedFont).fixedPitch() && !m_settings->isImmutable("fixed")) {
if (QFontInfo(adjustedFont).fixedPitch()) {
m_settings->setFixed(adjustedFont);
}
}
......
......@@ -67,6 +67,7 @@ public Q_SLOTS:
void load() override;
void save() override;
Q_INVOKABLE void adjustAllFonts();
Q_INVOKABLE void adjustFont(const QFont &font, const QString &category);
Q_SIGNALS:
void fontsHaveChanged();
......
......@@ -57,11 +57,8 @@ FocusScope {
Kirigami.MnemonicData.enabled: false
focus: true
onClicked: {
fontDialog.adjustAllFonts = false;
fontDialog.currentCategory = root.category
fontDialog.font = root.font;
fontDialog.currentFont = root.font;
fontDialog.open()
fontDialog.adjustAllFonts = false
kcm.adjustFont(root.font, root.category)
}
QtControls.ToolTip {
visible: parent.hovered
......
......@@ -266,9 +266,9 @@ KCM.SimpleKCM {
property bool adjustAllFonts: false
onAccepted: {
if (adjustAllFonts) {
kcm.adjustAllFonts(font);
kcm.adjustAllFonts()
} else {
kcm.fontsSettings[currentCategory] = font;
kcm.adjustFont(font, currentCategory)
}
}
}
......
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