// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL #pragma once #include "koutnetsettings.h" #include #include #include #include namespace koutnet { // The font the window is drawn in, and the one it sets code and quoted text in. // // This is the application's own font, not the desktop's: it is put on the // QApplication and nowhere else, so setting it does not reach into kdeglobals // and change every other program the user has open. Empty family and a zero // size both mean "leave it to the desktop", which is what the window opens // with, and the same is true of the fixed family - an empty one keeps the // desktop's own monospaced face. // // It does not apply itself on construction the way ColorSchemeSelector does: // startup asks it to once, before the window exists, so that the first frame // is already in the chosen font rather than repainting into it a moment later. class FontSelector : public QObject { Q_OBJECT Q_PROPERTY(QString family READ family WRITE setFamily NOTIFY familyChanged) Q_PROPERTY(int pointSize READ pointSize WRITE setPointSize NOTIFY pointSizeChanged) Q_PROPERTY(QString fixedFamily READ fixedFamily WRITE setFixedFamily NOTIFY fixedFamilyChanged) Q_PROPERTY(bool customised READ customised NOTIFY customisedChanged) public: explicit FontSelector(KOutNetSettings *settings, QObject *parent = nullptr); QString family() const; void setFamily(const QString &family); int pointSize() const; void setPointSize(int pointSize); QString fixedFamily() const; void setFixedFamily(const QString &family); // Whether anything but the desktop's own font is in force, which is what // the settings page shows its "reset" row against: with nothing set there // is nothing to reset. bool customised() const; Q_INVOKABLE QStringList families() const; Q_INVOKABLE QStringList fixedFamilies() const; Q_INVOKABLE void resetToSystem(); // What apply() would put on the application, worked out without touching // it: the base font with the stored family and size laid over it. Public // and static so the arithmetic can be checked without a window. static QFont resolvedFont(const QFont &base, const QString &family, int pointSize); // Puts the stored font on the QGuiApplication. Called once from app startup // before the window is made, and again on every setter, so that a change // lands on the open window rather than on the next launch. void apply() const; Q_SIGNALS: void familyChanged(); void pointSizeChanged(); void fixedFamilyChanged(); void customisedChanged(); private: KOutNetSettings *m_settings; // The application's font as it was before this selector touched it, which // is the desktop's own. Every apply() builds on this rather than on the // current font, so that clearing a setting really does go back instead of // leaving the last family in place with only the size removed. QFont m_baseFont; // Enumerating the fonts on the machine is a disk scan, and the settings // page asks for both lists every time it opens. Keep the answer for the // life of the process: fonts installed while the window is up are picked // up at the next launch, like the theme list. mutable QStringList m_families; mutable QStringList m_fixedFamilies; mutable bool m_familiesCached = false; mutable bool m_fixedFamiliesCached = false; }; } // namespace koutnet