diff --git a/kcms/fonts/fonts.cpp b/kcms/fonts/fonts.cpp index 401328b8c..7437ca4af 100644 --- a/kcms/fonts/fonts.cpp +++ b/kcms/fonts/fonts.cpp @@ -1,463 +1,543 @@ /* 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. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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. */ #include "fonts.h" #include #include #include #include #include #include #include #include #include #include #include #include #include "../krdb/krdb.h" /**** DLL Interface ****/ K_PLUGIN_FACTORY_WITH_JSON(KFontsFactory, "kcm_fonts.json", registerPlugin();) /**** FontAASettings ****/ #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) FontAASettings::FontAASettings(QObject *parent) : QObject(parent) , m_subPixelOptionsModel(new QStandardItemModel(this)) , m_hintingOptionsModel(new QStandardItemModel(this)) , m_subPixel(QString("System default")) , m_hinting(QString("System default")) { for (int t = KXftConfig::SubPixel::NotSet; t <= KXftConfig::SubPixel::Vbgr; ++t) { QStandardItem *item = new QStandardItem(i18n(KXftConfig::description((KXftConfig::SubPixel::Type)t).toUtf8())); m_subPixelOptionsModel->appendRow(item); } for (int s = KXftConfig::Hint::NotSet; s <= KXftConfig::Hint::Full; ++s) { QStandardItem * item = new QStandardItem(i18n(KXftConfig::description((KXftConfig::Hint::Style)s).toUtf8())); m_hintingOptionsModel->appendRow(item); } } void FontAASettings::load() { double from, to; KXftConfig xft; if (xft.getExcludeRange(from, to)) { m_excludeFrom = from; m_excludeTo = to; } else { m_excludeFrom = 8; m_excludeTo = 15; } KXftConfig::SubPixel::Type spType; xft.getSubPixelType(spType); m_subPixel = KXftConfig::description(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); } else { m_hinting = KXftConfig::description(hStyle); } KConfig _cfgfonts("kcmfonts"); KConfigGroup cfgfonts(&_cfgfonts, "General"); setDpi(cfgfonts.readEntry("forceFontDPI", 0)); if (cfgfonts.readEntry("dontChangeAASettings", true)) { setAntiAliasing(1); //AASystem } else if (xft.aliasingEnabled()) { setAntiAliasing(0); //AAEnabled } else { setAntiAliasing(2); //AADisabled } } bool FontAASettings::save(KXftConfig::AntiAliasing::State aaState) { KXftConfig xft; KConfig kglobals("kdeglobals", KConfig::NoGlobals); KConfigGroup grp(&kglobals, "General"); xft.setAntiAliasing(aaState); xft.setExcludeRange(m_excludeFrom, m_excludeTo); KXftConfig::SubPixel::Type spType(getSubPixelType()); xft.setSubPixelType(spType); grp.writeEntry("XftSubPixel", KXftConfig::toStr(spType)); if (KXftConfig::AntiAliasing::NotSet == aaState) { grp.revertToDefault("XftAntialias"); } else { grp.writeEntry("XftAntialias", aaState == KXftConfig::AntiAliasing::Enabled); } bool mod = false; KXftConfig::Hint::Style hStyle(getHintStyle()); xft.setHintStyle(hStyle); QString hs(KXftConfig::toStr(hStyle)); if (hs != grp.readEntry("XftHintStyle")) { if (KXftConfig::Hint::NotSet == hStyle) { grp.revertToDefault("XftHintStyle"); } else { grp.writeEntry("XftHintStyle", hs); } } mod = true; kglobals.sync(); if (!mod) { mod = xft.changed(); } xft.apply(); KConfig _cfgfonts("kcmfonts"); KConfigGroup cfgfonts(&_cfgfonts, "General"); cfgfonts.writeEntry("forceFontDPI", m_dpi); cfgfonts.sync(); return mod; } void FontAASettings::defaults() { setExcludeTo(15); setExcludeFrom(8); setAntiAliasing(1); setDpi(96); setSubPixel(KXftConfig::description(KXftConfig::SubPixel::NotSet)); setHinting(KXftConfig::description(KXftConfig::Hint::NotSet)); } int FontAASettings::getIndexSubPixel(KXftConfig::SubPixel::Type spType) const { int pos = -1; int index; for (index = 0; index < m_subPixelOptionsModel->rowCount(); ++index) { QStandardItem *item = m_subPixelOptionsModel->item(index); if (item->text() == i18n(KXftConfig::description(spType).toUtf8())) { pos = index; break; } } return pos; } KXftConfig::SubPixel::Type FontAASettings::getSubPixelType() { int t; for (t = KXftConfig::SubPixel::NotSet; t <= KXftConfig::SubPixel::Vbgr; ++t){ if (m_subPixel == i18n(KXftConfig::description((KXftConfig::SubPixel::Type)t).toUtf8())) { return (KXftConfig::SubPixel::Type)t; } } return KXftConfig::SubPixel::NotSet; } int FontAASettings::getIndexHint(KXftConfig::Hint::Style hStyle) const { int pos = -1; int index; for (index = 0; index < m_hintingOptionsModel->rowCount(); ++index) { QStandardItem *item = m_hintingOptionsModel->item(index); if (item->text() == i18n(KXftConfig::description(hStyle).toUtf8())) { pos = index; break; } } return pos; } KXftConfig::Hint::Style FontAASettings::getHintStyle() { int s; for (s = KXftConfig::Hint::NotSet; s <= KXftConfig::Hint::Full; ++s){ if (m_hinting == i18n(KXftConfig::description((KXftConfig::Hint::Style)s).toUtf8())) { return (KXftConfig::Hint::Style)s; } } return KXftConfig::Hint::Medium; } #endif void FontAASettings::setSubPixel(const QString &subPixel) { if (m_subPixel == subPixel) { return; } m_subPixel = subPixel; emit subPixelChanged(); } QString FontAASettings::subPixel() const { return m_subPixel; } void FontAASettings::setHinting(const QString &hinting) { if (m_hinting == hinting) { return; } m_hinting = hinting; emit hintingChanged(); } QString FontAASettings::hinting() const { return m_hinting; } void FontAASettings::setExcludeTo(const int &excludeTo) { if (m_excludeTo == excludeTo) { return; } m_excludeTo = excludeTo; emit excludeToChanged(); } int FontAASettings::excludeTo() const { return m_excludeTo; } void FontAASettings::setExcludeFrom(const int &excludeTo) { if (m_excludeFrom == excludeTo) { return; } m_excludeFrom = excludeTo; emit excludeToChanged(); } int FontAASettings::excludeFrom() const { return m_excludeFrom; } void FontAASettings::setAntiAliasing(const int &antiAliasing) { if (m_antiAliasing == antiAliasing) { return; } m_antiAliasing = antiAliasing; emit aliasingChanged(); } int FontAASettings::antiAliasing() const { return m_antiAliasing; } void FontAASettings::setDpi(const int &dpi) { if (m_dpi == dpi) { return; } m_dpi = dpi; emit dpiChanged(); } int FontAASettings::dpi() const { return m_dpi; } int FontAASettings::subPixelCurrentIndex() { return getSubPixelType(); } int FontAASettings::hintingCurrentIndex() { return getHintStyle(); } /**** KFonts ****/ KFonts::KFonts(QObject *parent, const QVariantList &args) : KQuickAddons::ConfigModule(parent, args) - , m_fontsModel(new QStandardItemModel(this)) , 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); - - QHash roles = m_fontsModel->roleNames(); - roles[CategoryRole] = "categoryName"; - roles[StatusRole] = "statusName"; - roles[FontRole] = "font"; - m_fontsModel->setItemRoleNames(roles); } KFonts::~KFonts() { } void KFonts::defaults() { - QList defaultFonts; #ifdef Q_OS_MAC - defaultFonts << QFont("Lucida Grande", 13) // general/menu/desktop - << QFont("Monaco", 10) - << QFont("Lucida Grande", 11); // toolbar -#elif defined(Q_WS_MAEMO_5) || defined(MEEGO_EDITION_HARMATTAN) - defaultFonts << QFont("Sans Serif", 16) // general/menu/desktop - << QFont("Monospace", 16) - << QFont("Sans Serif", 16); // toolbar + 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 - defaultFonts << QFont("Oxygen-Sans", 10) // general/menu/desktop - <defaults(); } void KFonts::load() { - QList fonts; - fonts << FontsType { "General:", "General", "font" } - << FontsType { "Fixed width:", "General", "fixed" } - << FontsType { "Small:", "General", "smallestReadableFont" } - << FontsType { "Toolbar:", "General", "toolBarFont" } - << FontsType { "Menu:", "General", "menuFont" } - << FontsType { "Window Title:", "WM", "activeFont" }; - KSharedConfig::Ptr config = KSharedConfig::openConfig("kdeglobals"); - for (auto it : fonts) { - KConfigGroup cg(config, it.category); - QStandardItem *item = new QStandardItem(it.name); - item->setData(it.category, CategoryRole); - item->setData(it.status, StatusRole); + KConfigGroup cg(config, "General"); + QFont font; + font.fromString(cg.readEntry("font")); + setGeneralFont(font); - QFont font; - font.fromString(cg.readEntry(it.status)); - item->setData(font, FontRole); + font.fromString(cg.readEntry("fixed")); + setFixedWidthFont(font); - m_fontsModel->appendRow(item); - } + font.fromString(cg.readEntry("smallestReadableFont")); + setFixedWidthFont(font); + + font.fromString(cg.readEntry("toolBarFont")); + setFixedWidthFont(font); + + font.fromString(cg.readEntry("menuFont")); + setFixedWidthFont(font); + + cg = KConfigGroup(config, "WM"); + font.fromString(cg.readEntry("activeFont")); + setFixedWidthFont(font); m_fontAASettings->load(); } void KFonts::save() { KSharedConfig::Ptr config = KSharedConfig::openConfig("kdeglobals"); - for (int i = 0; i < m_fontsModel->rowCount(); i++) { - QStandardItem *item = m_fontsModel->item(i); - KConfigGroup cg(config, item->data(CategoryRole).toString()); - cg.writeEntry(item->data(StatusRole).toString(), item->data(FontRole).toString()); - cg.sync(); - } + KConfigGroup cg(config, "General"); + cg.writeEntry("font", m_generalFont.toString()); + cg.writeEntry("fixed", m_generalFont.toString()); + cg.writeEntry("smallestReadableFont", m_generalFont.toString()); + cg.writeEntry("toolBarFont", m_generalFont.toString()); + cg.writeEntry("menuFont", m_generalFont.toString()); + cg.sync(); + cg = KConfigGroup(config, "WM"); + cg.writeEntry("activeFont", m_generalFont.toString()); + cg.sync(); KConfig _cfgfonts("kcmfonts"); KConfigGroup cfgfonts(&_cfgfonts, "General"); AASetting aaSetting = (AASetting)m_fontAASettings->antiAliasing(); cfgfonts.writeEntry("dontChangeAASettings", aaSetting == AASystem); if (aaSetting == AAEnabled) { m_fontAASettings->save(KXftConfig::AntiAliasing::Enabled); } else if (aaSetting == AADisabled) { m_fontAASettings->save(KXftConfig::AntiAliasing::Disabled); } else { m_fontAASettings->save(KXftConfig::AntiAliasing::NotSet); } runRdb(KRdbExportXftSettings | KRdbExportGtkTheme); KGlobalSettings::self()->emitChange(KGlobalSettings::FontChanged); emit fontsHaveChanged(); setNeedsSave(false); } -void KFonts::updateFont(int currentIndex, QFont font) +void KFonts::setGeneralFont(const QFont &font) { - QStandardItem *item = m_fontsModel->item(currentIndex); - item->setData(font, FontRole); + if (m_generalFont == font) { + return; + } + m_generalFont = font; + emit generalFontChanged(); setNeedsSave(true); } +QFont KFonts::generalFont() const +{ + return m_generalFont; +} -void KFonts::adjustAllFonts(QFont font) +void KFonts::setFixedWidthFont(const QFont &font) +{ + if (m_fixedWidthFont == font) { + return; + } + + m_fixedWidthFont = font; + emit fixedWidthFontChanged(); + setNeedsSave(true); +} + +QFont KFonts::fixedWidthFont() const { - for (int i = 0; i < m_fontsModel->rowCount(); i++) { - updateFont(i, font); + return m_fixedWidthFont; +} + +void KFonts::setSmallFont(const QFont &font) +{ + if (m_smallFont == font) { + return; } + + m_smallFont = font; + emit smallFontChanged(); + setNeedsSave(true); +} + +QFont KFonts::smallFont() const +{ + return m_smallFont; +} + +void KFonts::setToolbarFont(const QFont &font) +{ + if (m_toolbarFont == font) { + return; + } + + m_toolbarFont = font; + emit toolbarFontChanged(); + setNeedsSave(true); +} + +QFont KFonts::toolbarFont() const +{ + return m_toolbarFont; +} + +void KFonts::setMenuFont(const QFont &font) +{ + if (m_menuFont == font) { + return; + } + + m_menuFont = font; + emit menuFontChanged(); + setNeedsSave(true); +} + +QFont KFonts::menuFont() const +{ + return m_menuFont; +} + +void KFonts::setWindowTitleFont(const QFont &font) +{ + if (m_windowTitleFont == font) { + return; + } + + m_windowTitleFont = font; + emit windowTitleFontChanged(); + setNeedsSave(true); +} + +QFont KFonts::windowTitleFont() const +{ + return m_windowTitleFont; +} + +void KFonts::adjustAllFonts(QFont font) +{ + setGeneralFont(font); + setMenuFont(font); + setFixedWidthFont(font); + setToolbarFont(font); + setSmallFont(font); + setWindowTitleFont(font); } #include "fonts.moc" diff --git a/kcms/fonts/fonts.h b/kcms/fonts/fonts.h index ac83a3293..b79a7e379 100644 --- a/kcms/fonts/fonts.h +++ b/kcms/fonts/fonts.h @@ -1,160 +1,179 @@ /* 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. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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. */ #ifndef FONTS_H #define FONTS_H #include #include #include #include #include "kxftconfig.h" class FontAASettings : public QObject { Q_OBJECT Q_PROPERTY(QAbstractItemModel *subPixelOptionsModel READ subPixelOptionsModel CONSTANT) Q_PROPERTY(QAbstractItemModel *hintingOptionsModel READ hintingOptionsModel CONSTANT) Q_PROPERTY(QString subPixel READ subPixel WRITE setSubPixel NOTIFY subPixelChanged) Q_PROPERTY(QString hinting READ hinting WRITE setHinting NOTIFY hintingChanged) 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: #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) FontAASettings(QObject *parent); bool save(KXftConfig::AntiAliasing::State aaState); void load(); void defaults(); int getIndexSubPixel(KXftConfig::SubPixel::Type spType) const; KXftConfig::SubPixel::Type getSubPixelType(); int getIndexHint(KXftConfig::Hint::Style hStyle) const; KXftConfig::Hint::Style getHintStyle(); void setAntiAliasingState(KXftConfig::AntiAliasing::State aaState); QAbstractItemModel* subPixelOptionsModel() { return m_subPixelOptionsModel; } QAbstractItemModel* hintingOptionsModel() { return m_hintingOptionsModel; } void setSubPixel(const QString &subPixel); QString subPixel() const; void setHinting(const QString &hinting); QString hinting() const; void setExcludeTo(const int &excludeTo); int excludeTo() const; void setExcludeFrom(const int &excludeTo); int excludeFrom() const; void setAntiAliasing(const int& antiAliasing); int antiAliasing() const; void setDpi(const int &dpi); int dpi() const; Q_INVOKABLE int subPixelCurrentIndex(); Q_INVOKABLE int hintingCurrentIndex(); #endif Q_SIGNALS: void subPixelChanged(); void hintingChanged(); void excludeToChanged(); void excludeFromChanged(); void antiAliasingChanged(); void aliasingChanged(); void dpiChanged(); #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) private: QString m_subPixel; QString m_hinting; int m_excludeTo; int m_excludeFrom; int m_antiAliasing; int m_dpi; QStandardItemModel *m_subPixelOptionsModel; QStandardItemModel *m_hintingOptionsModel; #endif }; /** * The Desktop/fonts tab in kcontrol. */ - - -struct FontsType { - QString name; - QString category; - QString status; - QFont font; - QString fontName; -}; - class KFonts : public KQuickAddons::ConfigModule { Q_OBJECT - Q_PROPERTY(QAbstractItemModel *fontsModel READ fontsModel CONSTANT) + 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: - - enum Roles { - CategoryRole = Qt::UserRole + 1, - StatusRole, - FontRole - }; - KFonts(QObject *parent, const QVariantList &); ~KFonts(); + 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; - QStandardItemModel* fontsModel() { return m_fontsModel; } QObject* fontAASettings() { return m_fontAASettings; } public Q_SLOTS: void load(); void save(); void defaults(); - Q_INVOKABLE void updateFont(int currentIndex, QFont font); Q_INVOKABLE void adjustAllFonts(QFont); Q_SIGNALS: void fontsHaveChanged(); + void generalFontChanged(); + void fixedWidthFontChanged(); + void smallFontChanged(); + void toolbarFontChanged(); + void menuFontChanged(); + void windowTitleFontChanged(); + private: enum AASetting { AAEnabled, AASystem, AADisabled }; - QStandardItemModel *m_fontsModel; + + QFont m_generalFont; + QFont m_fixedWidthFont; + QFont m_smallFont; + QFont m_toolbarFont; + QFont m_menuFont; + QFont m_windowTitleFont; + FontAASettings *m_fontAASettings; }; #endif diff --git a/kcms/fonts/package/contents/ui/FontWidget.qml b/kcms/fonts/package/contents/ui/FontWidget.qml new file mode 100644 index 000000000..ec56dd48c --- /dev/null +++ b/kcms/fonts/package/contents/ui/FontWidget.qml @@ -0,0 +1,53 @@ +/* + 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 + + +RowLayout { + id: root + property string label + property string category + property font font + Kirigami.FormData.label: root.label + + 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 + onClicked: { + fontDialog.adjustAllFonts = false; + fontDialog.currentCategory = root.category + fontDialog.font = root.font; + fontDialog.open() + } + } +} + diff --git a/kcms/fonts/package/contents/ui/main.qml b/kcms/fonts/package/contents/ui/main.qml index 31ea00c73..cdb6ce11c 100644 --- a/kcms/fonts/package/contents/ui/main.qml +++ b/kcms/fonts/package/contents/ui/main.qml @@ -1,246 +1,248 @@ /* 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 QtQuick.Controls.Private 1.0 import org.kde.kirigami 2.3 as Kirigami import org.kde.kcm 1.0 Kirigami.ScrollablePage { id: root ConfigModule.quickHelp: i18n("Fonts") Kirigami.FormLayout { id: formLayout QtControls.Button { id: adjustAllFontsButton text: i18n("Adjust All Fonts...") onClicked: { fontDialog.adjustAllFonts = true; fontDialog.open() } } - Repeater { - model: kcm.fontsModel - - delegate: RowLayout { - id: row - parent: formLayout - - Kirigami.FormData.label: model.display - - QtControls.TextField { - enabled: false - text: model.font.family + " " + model.font.pointSize - font: model.font - Layout.preferredHeight: fontButton.height - } - - QtControls.Button { - id: fontButton - text: i18n("Choose...") - onClicked: { - fontDialog.adjustAllFonts = false; - fontDialog.currentIndex = index; - fontDialog.font = model.font; - fontDialog.open() - } - } - } + FontWidget { + 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 } RowLayout { Kirigami.FormData.label: i18n("Use anti-aliasing:") QtControls.ComboBox { id: antiAliasingComboBox model: [i18n("Enabled"), i18n("System Settings"), i18n("Disabled")] currentIndex: kcm.fontAASettings.antiAliasing onCurrentIndexChanged: kcm.fontAASettings.antiAliasing = antiAliasingComboBox.currentIndex } QtControls.Button { text: i18n("Configure...") enabled: antiAliasingComboBox.currentIndex == 0 onClicked: { advancedDialog.open() } } } 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.Dialog { id: advancedDialog title: i18n("Configure Anti-Alias Settings") standardButtons: QtDialogs.StandardButton.Ok | QtDialogs.StandardButton.Cancel onAccepted: { kcm.fontAASettings.subPixel = subPixelComboBox.currentText; kcm.fontAASettings.hinting = hintingComboBox.currentText; kcm.fontAASettings.excludeTo = excludeCheckBox.checked ? excludeToSpinBox.value : 0; kcm.fontAASettings.excludeFrom = excludeCheckBox.checked ? excludeFromSpinBox.value : 0; } onVisibleChanged: { //our dialog has open if (advancedDialog.visible) { subPixelComboBox.currentIndex = kcm.fontAASettings.subPixelCurrentIndex(); hintingComboBox.currentIndex = kcm.fontAASettings.hintingCurrentIndex(); excludeToSpinBox.value = kcm.fontAASettings.excludeTo; excludeFromSpinBox.value = kcm.fontAASettings.excludeFrom; } } ColumnLayout { RowLayout { QtControls.CheckBox { id: excludeCheckBox checked: excludeToSpinBox.value != 0 && excludeFromSpinBox.value != 0 text: i18n("Exclude Range") Layout.fillWidth: true } QtControls.SpinBox { id: excludeFromSpinBox stepSize: 1 textFromValue: function(value, locale) { return i18n("%1 pt", value)} enabled: excludeCheckBox.checked } QtControls.Label { text: i18n("to") } QtControls.SpinBox { id: excludeToSpinBox stepSize: 1 textFromValue: function(value, locale) { return i18n("%1 pt", value)} enabled: excludeCheckBox.checked } } RowLayout { QtControls.Label{ text: i18n("Sub-pixel rendering type:") Layout.fillWidth: true horizontalAlignment: Text.AlignRight } QtControls.ComboBox { id: subPixelComboBox currentIndex: kcm.fontAASettings.subPixelCurrentIndex() model: kcm.fontAASettings.subPixelOptionsModel textRole: "display" } } RowLayout { QtControls.Label { text: i18n("Hinting style:") Layout.fillWidth: true horizontalAlignment: Text.AlignRight } QtControls.ComboBox { id: hintingComboBox currentIndex: kcm.fontAASettings.hintingCurrentIndex() model: kcm.fontAASettings.hintingOptionsModel textRole: "display" } } } } Connections { target: kcm.fontAASettings onSubPixelChanged: kcm.needsSave = true onHintingChanged: kcm.needsSave = true onExcludeToChanged: kcm.needsSave = true onExcludeFromChanged: kcm.needsSave = true //FIXME Those two signals are being emitted but the kcm.needsSave doesn't change. //onDpiChanged: kcm.needsSave = true //onAliasingChanged: kcm.needsSave = true; } QtDialogs.FontDialog { id: fontDialog title: "Choose a font" - property int currentIndex + property string currentCategory property bool adjustAllFonts: false onAccepted: { if (adjustAllFonts) { - kcm.adjustAllFonts(font) + kcm.adjustAllFonts(font); } else { - kcm.updateFont(currentIndex, font) + kcm[currentCategory] = font; } } } QtDialogs.MessageDialog { id: messageDialog title: i18n("Settings Have Changed") text: i18n("Some changes such as anti-aliasing or DPI will only affect newly started applications.") } Connections { target: kcm onFontsHaveChanged: messageDialog.open() } }