diff --git a/kcms/colors/CMakeLists.txt b/kcms/colors/CMakeLists.txt --- a/kcms/colors/CMakeLists.txt +++ b/kcms/colors/CMakeLists.txt @@ -4,6 +4,7 @@ set(kcm_colors_SRCS ../krdb/krdb.cpp colors.cpp + colorsdata.cpp colorsmodel.cpp filterproxymodel.cpp ) diff --git a/kcms/colors/colors.h b/kcms/colors/colors.h --- a/kcms/colors/colors.h +++ b/kcms/colors/colors.h @@ -41,6 +41,7 @@ class ColorsModel; class FilterProxyModel; class ColorsSettings; +class ColorsData; class KCMColors : public KQuickAddons::ManagedConfigModule { @@ -94,7 +95,7 @@ ColorsModel *m_model; FilterProxyModel *m_filteredModel; - ColorsSettings *m_settings; + ColorsData *m_data; bool m_selectedSchemeDirty = false; bool m_activeSchemeEdited = false; diff --git a/kcms/colors/colors.cpp b/kcms/colors/colors.cpp --- a/kcms/colors/colors.cpp +++ b/kcms/colors/colors.cpp @@ -59,14 +59,15 @@ #include "colorsmodel.h" #include "filterproxymodel.h" #include "colorssettings.h" +#include "colorsdata.h" -K_PLUGIN_FACTORY_WITH_JSON(KCMColorsFactory, "kcm_colors.json", registerPlugin();) +K_PLUGIN_FACTORY_WITH_JSON(KCMColorsFactory, "kcm_colors.json", registerPlugin();registerPlugin();) KCMColors::KCMColors(QObject *parent, const QVariantList &args) : KQuickAddons::ManagedConfigModule(parent, args) , m_model(new ColorsModel(this)) , m_filteredModel(new FilterProxyModel(this)) - , m_settings(new ColorsSettings(this)) + , m_data(new ColorsData(this)) , m_config(KSharedConfig::openConfig(QStringLiteral("kdeglobals"))) { qmlRegisterUncreatableType("org.kde.private.kcms.colors", 1, 0, "KCM", QStringLiteral("Cannot create instances of KCM")); @@ -83,11 +84,11 @@ connect(m_model, &ColorsModel::selectedSchemeChanged, this, [this](const QString &scheme) { m_selectedSchemeDirty = true; - m_settings->setColorScheme(scheme); + colorsSettings()->setColorScheme(scheme); }); - connect(m_settings, &ColorsSettings::colorSchemeChanged, this, [this] { - m_model->setSelectedScheme(m_settings->colorScheme()); + connect(colorsSettings(), &ColorsSettings::colorSchemeChanged, this, [this] { + m_model->setSelectedScheme(colorsSettings()->colorScheme()); }); connect(m_model, &ColorsModel::selectedSchemeChanged, m_filteredModel, &FilterProxyModel::setSelectedScheme); @@ -111,7 +112,7 @@ ColorsSettings *KCMColors::colorsSettings() const { - return m_settings; + return m_data->settings(); } bool KCMColors::downloadingFile() const @@ -271,7 +272,7 @@ m_model->load(); // would be cool to just reload/add the changed/new ones // If the currently active scheme was edited, consider settings dirty even if the scheme itself didn't change - if (savedThemes.contains(m_settings->colorScheme())) { + if (savedThemes.contains(colorsSettings()->colorScheme())) { m_activeSchemeEdited = true; settingsChanged(); } @@ -319,14 +320,14 @@ m_config->markAsClean(); m_config->reparseConfiguration(); - const QString schemeName = m_settings->colorScheme(); + const QString schemeName = colorsSettings()->colorScheme(); // If the scheme named in kdeglobals doesn't exist, show a warning and use default scheme if (m_model->indexOfScheme(schemeName) == -1) { - m_model->setSelectedScheme(m_settings->defaultColorSchemeValue()); + m_model->setSelectedScheme(colorsSettings()->defaultColorSchemeValue()); // These are normally synced but initially the model doesn't emit a change to avoid the // Apply button from being enabled without any user interaction. Sync manually here. - m_filteredModel->setSelectedScheme(m_settings->defaultColorSchemeValue()); + m_filteredModel->setSelectedScheme(colorsSettings()->defaultColorSchemeValue()); emit showSchemeNotInstalledWarning(schemeName); } else { m_model->setSelectedScheme(schemeName); diff --git a/kcms/colors/colorsdata.h b/kcms/colors/colorsdata.h new file mode 100644 --- /dev/null +++ b/kcms/colors/colorsdata.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020 Benjamin Port + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + */ + +#ifndef COLORSDATA_H +#define COLORSDATA_H + +#include + +#include "kcmoduledata.h" + +class ColorsSettings; + +class ColorsData : public KCModuleData +{ + Q_OBJECT + +public: + explicit ColorsData(QObject *parent = nullptr, const QVariantList &args = QVariantList()); + ColorsSettings *settings() const; + +private: + ColorsSettings *m_settings; +}; + +#endif diff --git a/kcms/colors/colorsdata.cpp b/kcms/colors/colorsdata.cpp new file mode 100644 --- /dev/null +++ b/kcms/colors/colorsdata.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 Benjamin Port + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + */ + +#include "colorsdata.h" + +#include + +#include "colorssettings.h" + +ColorsData::ColorsData(QObject *parent, const QVariantList &args) + : KCModuleData(parent, args) + , m_settings(new ColorsSettings(this)) +{ + autoRegisterSkeletons(); +} + +ColorsSettings *ColorsData::settings() const +{ + return m_settings; +} + +#include "colorsdata.moc" diff --git a/kcms/cursortheme/CMakeLists.txt b/kcms/cursortheme/CMakeLists.txt --- a/kcms/cursortheme/CMakeLists.txt +++ b/kcms/cursortheme/CMakeLists.txt @@ -15,7 +15,7 @@ ########### next target ############### -set(kcm_cursortheme_PART_SRCS kcmcursortheme.cpp ${libnoinst_SRCS}) +set(kcm_cursortheme_PART_SRCS kcmcursortheme.cpp cursorthemedata.cpp ${libnoinst_SRCS}) kconfig_add_kcfg_files(kcm_cursortheme_PART_SRCS cursorthemesettings.kcfgc GENERATE_MOC) add_library(kcm_cursortheme MODULE ${kcm_cursortheme_PART_SRCS}) diff --git a/kcms/cursortheme/cursorthemedata.h b/kcms/cursortheme/cursorthemedata.h new file mode 100644 --- /dev/null +++ b/kcms/cursortheme/cursorthemedata.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2020 Benjamin Port + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + */ + +#ifndef CURSORTHEMEDATA_H +#define CURSORTHEMEDATA_H + +#include + +#include "kcmoduledata.h" + +class CursorThemeSettings; + +class CursorThemeData : public KCModuleData +{ + Q_OBJECT +// Q_PROPERTY(CursorThemeSettings *cursorThemeSettings READ cursorThemeSettings CONSTANT) + +public: + explicit CursorThemeData(QObject *parent = nullptr, const QVariantList &args = QVariantList()); + CursorThemeSettings *settings() const; + +private: + CursorThemeSettings *m_settings; +}; + +#endif diff --git a/kcms/cursortheme/cursorthemedata.cpp b/kcms/cursortheme/cursorthemedata.cpp new file mode 100644 --- /dev/null +++ b/kcms/cursortheme/cursorthemedata.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 Benjamin Port + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + */ + +#include "cursorthemedata.h" + +#include + +#include "cursorthemesettings.h" + +CursorThemeData::CursorThemeData(QObject *parent, const QVariantList &args) + : KCModuleData(parent, args) + , m_settings(new CursorThemeSettings(this)) +{ + autoRegisterSkeletons(); +} + +CursorThemeSettings *CursorThemeData::settings() const +{ + return m_settings; +} + + +#include "cursorthemedata.moc" diff --git a/kcms/cursortheme/kcmcursortheme.h b/kcms/cursortheme/kcmcursortheme.h --- a/kcms/cursortheme/kcmcursortheme.h +++ b/kcms/cursortheme/kcmcursortheme.h @@ -31,6 +31,7 @@ class SortProxyModel; class CursorTheme; class CursorThemeSettings; +class CursorThemeData; namespace KIO { @@ -126,7 +127,7 @@ CursorThemeModel *m_themeModel; SortProxyModel *m_themeProxyModel; QStandardItemModel *m_sizesModel; - CursorThemeSettings *m_settings; + CursorThemeData *m_data; /** Holds the last size that was chosen by the user. Example: The user chooses theme1 which provides the sizes 24 and 36. He chooses 36. preferredSize gets diff --git a/kcms/cursortheme/kcmcursortheme.cpp b/kcms/cursortheme/kcmcursortheme.cpp --- a/kcms/cursortheme/kcmcursortheme.cpp +++ b/kcms/cursortheme/kcmcursortheme.cpp @@ -20,6 +20,7 @@ #include #include "kcmcursortheme.h" +#include "cursorthemedata.h" #include "xcursor/thememodel.h" #include "xcursor/sortproxymodel.h" @@ -59,17 +60,17 @@ # include #endif -K_PLUGIN_FACTORY_WITH_JSON(CursorThemeConfigFactory, "kcm_cursortheme.json", registerPlugin();) +K_PLUGIN_FACTORY_WITH_JSON(CursorThemeConfigFactory, "kcm_cursortheme.json", registerPlugin();registerPlugin();) CursorThemeConfig::CursorThemeConfig(QObject *parent, const QVariantList &args) : KQuickAddons::ManagedConfigModule(parent, args), - m_settings(new CursorThemeSettings(this)), + m_data(new CursorThemeData(this)), m_canInstall(true), m_canResize(true), m_canConfigure(true) { - m_preferredSize = m_settings->cursorSize(); - connect(m_settings, &CursorThemeSettings::cursorThemeChanged, this, &CursorThemeConfig::updateSizeComboBox); + m_preferredSize = cursorThemeSettings()->cursorSize(); + connect(cursorThemeSettings(), &CursorThemeSettings::cursorThemeChanged, this, &CursorThemeConfig::updateSizeComboBox); qmlRegisterType("org.kde.private.kcm_cursortheme", 1, 0, "PreviewWidget"); qmlRegisterType(); qmlRegisterType(); @@ -102,7 +103,7 @@ CursorThemeSettings *CursorThemeConfig::cursorThemeSettings() const { - return m_settings; + return m_data->settings(); } void CursorThemeConfig::setCanInstall(bool can) @@ -195,7 +196,7 @@ m_sizesModel->clear(); // refill the combo box and adopt its icon size - int row = cursorThemeIndex(m_settings->cursorTheme()); + int row = cursorThemeIndex(cursorThemeSettings()->cursorTheme()); QModelIndex selected = m_themeProxyModel->index(row, 0); int maxIconWidth = 0; int maxIconHeight = 0; @@ -263,18 +264,18 @@ } } } - m_settings->setCursorSize(size); + cursorThemeSettings()->setCursorSize(size); } } // enable or disable the combobox - if (m_settings->isImmutable("cursorSize")) { + if (cursorThemeSettings()->isImmutable("cursorSize")) { setCanResize(false); } else { setCanResize(m_sizesModel->rowCount() > 0); } // We need to emit a cursorSizeChanged in all case to refresh UI - emit m_settings->cursorSizeChanged(); + emit cursorThemeSettings()->cursorSizeChanged(); } bool CursorThemeConfig::applyTheme(const CursorTheme *theme, const int size) @@ -365,13 +366,13 @@ void CursorThemeConfig::save() { ManagedConfigModule::save(); - setPreferredSize(m_settings->cursorSize()); + setPreferredSize(cursorThemeSettings()->cursorSize()); - int row = cursorThemeIndex(m_settings->cursorTheme()); + int row = cursorThemeIndex(cursorThemeSettings()->cursorTheme()); QModelIndex selected = m_themeProxyModel->index(row, 0); const CursorTheme *theme = selected.isValid() ? m_themeProxyModel->theme(selected) : nullptr; - if (!applyTheme(theme, m_settings->cursorSize())) { + if (!applyTheme(theme, cursorThemeSettings()->cursorSize())) { emit showInfoMessage(i18n("You have to restart the Plasma session for these changes to take effect.")); } @@ -382,12 +383,12 @@ void CursorThemeConfig::load() { ManagedConfigModule::load(); - setPreferredSize(m_settings->cursorSize()); + setPreferredSize(cursorThemeSettings()->cursorSize()); // Get the name of the theme KDE is configured to use - QString currentTheme = m_settings->cursorTheme(); + QString currentTheme = cursorThemeSettings()->cursorTheme(); // Disable the listview and the buttons if we're in kiosk mode - if (m_settings->isImmutable( QStringLiteral( "cursorTheme" ))) { + if (cursorThemeSettings()->isImmutable( QStringLiteral( "cursorTheme" ))) { setCanConfigure(false); setCanInstall(false); } @@ -401,7 +402,7 @@ void CursorThemeConfig::defaults() { ManagedConfigModule::defaults(); - m_preferredSize = m_settings->cursorSize(); + m_preferredSize = cursorThemeSettings()->cursorSize(); } void CursorThemeConfig::ghnsEntriesChanged(const QQmlListReference &changedEntries) @@ -558,7 +559,7 @@ const CursorTheme *theme = m_themeProxyModel->theme(idx); // Don't let the user delete the currently configured theme - if (theme->name() == m_settings->cursorTheme()) { + if (theme->name() == cursorThemeSettings()->cursorTheme()) { KMessageBox::sorry(nullptr, i18n("You cannot delete the theme you are currently " "using.
You have to switch to another theme first.
")); return; diff --git a/kcms/fonts/CMakeLists.txt b/kcms/fonts/CMakeLists.txt --- a/kcms/fonts/CMakeLists.txt +++ b/kcms/fonts/CMakeLists.txt @@ -10,7 +10,7 @@ include_directories(../kfontinst/lib) -set(kcm_fonts_PART_SRCS ../krdb/krdb.cpp previewrenderengine.cpp previewimageprovider.cpp fonts.cpp fontsaasettings.cpp ../kfontinst/lib/FcEngine.cpp) +set(kcm_fonts_PART_SRCS ../krdb/krdb.cpp previewrenderengine.cpp previewimageprovider.cpp fonts.cpp fontsaasettings.cpp fontsdata.cpp ../kfontinst/lib/FcEngine.cpp) if(X11_FOUND) set(kcm_fonts_PART_SRCS ${kcm_fonts_PART_SRCS} ${libkxftconfig_SRCS}) diff --git a/kcms/fonts/fonts.h b/kcms/fonts/fonts.h --- a/kcms/fonts/fonts.h +++ b/kcms/fonts/fonts.h @@ -33,15 +33,16 @@ #include +class FontsData; class FontsSettings; class FontsAASettings; /** * The Desktop/fonts tab in kcontrol. */ class KFonts : public KQuickAddons::ManagedConfigModule { - Q_OBJECT +Q_OBJECT Q_PROPERTY(FontsSettings *fontsSettings READ fontsSettings CONSTANT) Q_PROPERTY(FontsAASettings *fontsAASettings READ fontsAASettings CONSTANT) Q_PROPERTY(QAbstractItemModel *subPixelOptionsModel READ subPixelOptionsModel CONSTANT) @@ -79,8 +80,7 @@ QFont applyFontDiff(const QFont &fnt, const QFont &newFont, int fontDiffFlags); void setNearestExistingFonts(); - FontsSettings *m_settings; - FontsAASettings *m_settingsAA; + FontsData *m_data; QStandardItemModel *m_subPixelOptionsModel; QStandardItemModel *m_hintingOptionsModel; }; diff --git a/kcms/fonts/fonts.cpp b/kcms/fonts/fonts.cpp --- a/kcms/fonts/fonts.cpp +++ b/kcms/fonts/fonts.cpp @@ -51,8 +51,10 @@ #include "fontssettings.h" #include "fontsaasettings.h" +#include "fontsdata.h" + /**** DLL Interface ****/ -K_PLUGIN_FACTORY_WITH_JSON(KFontsFactory, "kcm_fonts.json", registerPlugin();) +K_PLUGIN_FACTORY_WITH_JSON(KFontsFactory, "kcm_fonts.json", registerPlugin();registerPlugin();) //from KFontRequester // Determine if the font with given properties is available on the system, @@ -111,8 +113,7 @@ KFonts::KFonts(QObject *parent, const QVariantList &args) : KQuickAddons::ManagedConfigModule(parent, args) - , m_settings(new FontsSettings(this)) - , m_settingsAA(new FontsAASettings(this)) + , m_data(new FontsData(this)) , m_subPixelOptionsModel(new QStandardItemModel(this)) , m_hintingOptionsModel(new QStandardItemModel(this)) { @@ -135,22 +136,22 @@ auto item = new QStandardItem(KXftConfig::description(s)); m_hintingOptionsModel->appendRow(item); } - connect(m_settingsAA, &FontsAASettings::hintingChanged, this, &KFonts::hintingCurrentIndexChanged); - connect(m_settingsAA, &FontsAASettings::subPixelChanged, this, &KFonts::subPixelCurrentIndexChanged); + connect(fontsAASettings(), &FontsAASettings::hintingChanged, this, &KFonts::hintingCurrentIndexChanged); + connect(fontsAASettings(), &FontsAASettings::subPixelChanged, this, &KFonts::subPixelCurrentIndexChanged); } KFonts::~KFonts() { } FontsSettings *KFonts::fontsSettings() const { - return m_settings; + return m_data->settings(); } FontsAASettings *KFonts::fontsAASettings() const { - return m_settingsAA; + return m_data->settingsAA(); } QAbstractItemModel *KFonts::subPixelOptionsModel() const @@ -165,12 +166,12 @@ void KFonts::setNearestExistingFonts() { - 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())); + fontsSettings()->setFont(nearestExistingFont(fontsSettings()->font())); + fontsSettings()->setFixed(nearestExistingFont(fontsSettings()->fixed())); + fontsSettings()->setSmallestReadableFont(nearestExistingFont(fontsSettings()->smallestReadableFont())); + fontsSettings()->setToolBarFont(nearestExistingFont(fontsSettings()->toolBarFont())); + fontsSettings()->setMenuFont(nearestExistingFont(fontsSettings()->menuFont())); + fontsSettings()->setActiveFont(nearestExistingFont(fontsSettings()->activeFont())); } void KFonts::load() @@ -185,17 +186,17 @@ // NOTE: This needs to be done AFTER AA settings is loaded // otherwise AA settings will be reset in process of loading // previews - engine()->addImageProvider("preview", new PreviewImageProvider(m_settings->font())); + engine()->addImageProvider("preview", new PreviewImageProvider(fontsSettings()->font())); // KCM expect save state to be false at this point (can be true because of setNearestExistingFonts setNeedsSave(false); } void KFonts::save() { - auto dpiItem = m_settingsAA->findItem("forceFontDPI"); - auto dpiWaylandItem = m_settingsAA->findItem("forceFontDPIWayland"); - auto antiAliasingItem = m_settingsAA->findItem("antiAliasing"); + auto dpiItem = fontsAASettings()->findItem("forceFontDPI"); + auto dpiWaylandItem = fontsAASettings()->findItem("forceFontDPIWayland"); + auto antiAliasingItem = fontsAASettings()->findItem("antiAliasing"); Q_ASSERT(dpiItem && dpiWaylandItem && antiAliasingItem); if (dpiItem->isSaveNeeded() || dpiWaylandItem->isSaveNeeded() || antiAliasingItem->isSaveNeeded()) { emit aliasingChangeApplied(); @@ -208,7 +209,7 @@ #if HAVE_X11 // if the setting is reset in the module, remove the dpi value, // otherwise don't explicitly remove it and leave any possible system-wide value - if (m_settingsAA->forceFontDPI() == 0 && forceFontDPIChanged && !KWindowSystem::isPlatformWayland()) { + if (fontsAASettings()->forceFontDPI() == 0 && forceFontDPIChanged && !KWindowSystem::isPlatformWayland()) { QProcess proc; proc.setProcessChannelMode(QProcess::ForwardedChannels); proc.start("xrdb", QStringList() << "-quiet" << "-remove" << "-nocpp"); @@ -236,37 +237,37 @@ if (ret == QDialog::Accepted) { if (category == QLatin1String("font")) { - m_settings->setFont(selFont); + fontsSettings()->setFont(selFont); } else if (category == QLatin1String("menuFont")) { - m_settings->setMenuFont(selFont); + fontsSettings()->setMenuFont(selFont); } else if (category == QLatin1String("toolBarFont")) { - m_settings->setToolBarFont(selFont); + fontsSettings()->setToolBarFont(selFont); } else if (category == QLatin1String("activeFont")) { - m_settings->setActiveFont(selFont); + fontsSettings()->setActiveFont(selFont); } else if (category == QLatin1String("smallestReadableFont")) { - m_settings->setSmallestReadableFont(selFont); + fontsSettings()->setSmallestReadableFont(selFont); } else if (category == QLatin1String("fixed")) { - m_settings->setFixed(selFont); + fontsSettings()->setFixed(selFont); } } } void KFonts::adjustAllFonts() { - QFont font = m_settings->font(); + QFont font = fontsSettings()->font(); KFontChooser::FontDiffFlags fontDiffFlags; 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)); + fontsSettings()->setFont(applyFontDiff(fontsSettings()->font(), font, fontDiffFlags)); + fontsSettings()->setMenuFont(applyFontDiff(fontsSettings()->menuFont(), font, fontDiffFlags)); + fontsSettings()->setToolBarFont(applyFontDiff(fontsSettings()->toolBarFont(), font, fontDiffFlags)); + fontsSettings()->setActiveFont(applyFontDiff(fontsSettings()->activeFont(), font, fontDiffFlags)); + fontsSettings()->setSmallestReadableFont(applyFontDiff(fontsSettings()->smallestReadableFont(), font, fontDiffFlags)); - const QFont adjustedFont = applyFontDiff(m_settings->fixed(), font, fontDiffFlags); + const QFont adjustedFont = applyFontDiff(fontsSettings()->fixed(), font, fontDiffFlags); if (QFontInfo(adjustedFont).fixedPitch()) { - m_settings->setFixed(adjustedFont); + fontsSettings()->setFixed(adjustedFont); } } } @@ -293,22 +294,22 @@ int KFonts::subPixelCurrentIndex() const { - return m_settingsAA->subPixel() - KXftConfig::SubPixel::None; + return fontsAASettings()->subPixel() - KXftConfig::SubPixel::None; } void KFonts::setSubPixelCurrentIndex(int idx) { - m_settingsAA->setSubPixel(static_cast(KXftConfig::SubPixel::None + idx)); + fontsAASettings()->setSubPixel(static_cast(KXftConfig::SubPixel::None + idx)); } int KFonts::hintingCurrentIndex() const { - return m_settingsAA->hinting() - KXftConfig::Hint::None; + return fontsAASettings()->hinting() - KXftConfig::Hint::None; } void KFonts::setHintingCurrentIndex(int idx) { - m_settingsAA->setHinting(static_cast(KXftConfig::Hint::None + idx)); + fontsAASettings()->setHinting(static_cast(KXftConfig::Hint::None + idx)); } #include "fonts.moc" diff --git a/kcms/fonts/fontsdata.h b/kcms/fonts/fontsdata.h new file mode 100644 --- /dev/null +++ b/kcms/fonts/fontsdata.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020 Benjamin Port + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + */ + +#ifndef FONTSDATA_H +#define FONTSDATA_H + +#include + +#include "kcmoduledata.h" + +class FontsSettings; +class FontsAASettings; + +class FontsData : public KCModuleData +{ + Q_OBJECT + +public: + explicit FontsData(QObject *parent = nullptr, const QVariantList &args = QVariantList()); + FontsSettings *settings() const; + FontsAASettings *settingsAA() const; + +private: + FontsSettings *m_settings; + FontsAASettings *m_settingsAA; +}; + +#endif diff --git a/kcms/fonts/fontsdata.cpp b/kcms/fonts/fontsdata.cpp new file mode 100644 --- /dev/null +++ b/kcms/fonts/fontsdata.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020 Benjamin Port + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + */ + +#include "fontsdata.h" + +#include + +#include "fontssettings.h" +#include "fontsaasettings.h" + +FontsData::FontsData(QObject *parent, const QVariantList &args) + : KCModuleData(parent, args) + , m_settings(new FontsSettings(this)) + , m_settingsAA(new FontsAASettings(this)) +{ + autoRegisterSkeletons(); +} + +FontsSettings *FontsData::settings() const +{ + return m_settings; +} + +FontsAASettings *FontsData::settingsAA() const +{ + return m_settingsAA; +} + +#include "fontsdata.moc" diff --git a/kcms/spellchecking/CMakeLists.txt b/kcms/spellchecking/CMakeLists.txt --- a/kcms/spellchecking/CMakeLists.txt +++ b/kcms/spellchecking/CMakeLists.txt @@ -1,12 +1,14 @@ set(kcm_spellchecking_SRCS spellcheckingskeleton.cpp spellchecking.cpp + spellcheckingdata.cpp ) add_library(kcmspellchecking MODULE ${kcm_spellchecking_SRCS}) target_link_libraries(kcmspellchecking KF5::ConfigWidgets + KF5::KCMUtils KF5::SonnetCore KF5::SonnetUi ) diff --git a/kcms/spellchecking/spellchecking.h b/kcms/spellchecking/spellchecking.h --- a/kcms/spellchecking/spellchecking.h +++ b/kcms/spellchecking/spellchecking.h @@ -25,13 +25,15 @@ #define SONNETSPELLCHECKINGMODULE_H #include "kcmodule.h" -#include "spellcheckingskeleton.h" class KConfigDialogManager; +class SpellCheckingData; +class SpellCheckingSkeleton; namespace Sonnet { class ConfigView; + class Settings; } class SonnetSpellCheckingModule : public KCModule @@ -46,12 +48,14 @@ void load() override; void defaults() override; + SpellCheckingSkeleton *skeleton() const; + private: void stateChanged(); Sonnet::Settings *m_settings; Sonnet::ConfigView *m_configWidget; - SpellCheckingSkeleton *m_skeleton; + SpellCheckingData *m_data; KConfigDialogManager *m_managedConfig; }; diff --git a/kcms/spellchecking/spellchecking.cpp b/kcms/spellchecking/spellchecking.cpp --- a/kcms/spellchecking/spellchecking.cpp +++ b/kcms/spellchecking/spellchecking.cpp @@ -31,28 +31,29 @@ #include #include #include "spellcheckingskeleton.h" +#include "spellcheckingdata.h" -K_PLUGIN_FACTORY(SpellFactory, registerPlugin();) +K_PLUGIN_FACTORY(SpellFactory, registerPlugin();registerPlugin();) SonnetSpellCheckingModule::SonnetSpellCheckingModule(QWidget *parent, const QVariantList &) : KCModule(parent) + , m_data(new SpellCheckingData(this)) { QBoxLayout *layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); - m_skeleton = new SpellCheckingSkeleton(this); m_configWidget = new Sonnet::ConfigView(this); - m_configWidget->setNoBackendFoundVisible(m_skeleton->clients().isEmpty()); + m_configWidget->setNoBackendFoundVisible(skeleton()->clients().isEmpty()); layout->addWidget(m_configWidget); - m_managedConfig = addConfig(m_skeleton, m_configWidget); + m_managedConfig = addConfig(skeleton(), m_configWidget); connect(m_configWidget, &Sonnet::ConfigView::configChanged, this, &SonnetSpellCheckingModule::stateChanged); } void SonnetSpellCheckingModule::stateChanged() { bool unmanagedChangeState = false; bool unmanagedDefaultState = true; - QStringList refIgnoreList(m_skeleton->ignoreList()); + QStringList refIgnoreList(skeleton()->ignoreList()); refIgnoreList.removeDuplicates(); refIgnoreList.sort(); @@ -67,7 +68,7 @@ unmanagedChangeState |= currentIgnoreList != refIgnoreList; unmanagedDefaultState &= currentIgnoreList == defaultIgnoreList; - QStringList refPreferredLanguagesList(m_skeleton->preferredLanguages()); + QStringList refPreferredLanguagesList(skeleton()->preferredLanguages()); refPreferredLanguagesList.removeDuplicates(); refPreferredLanguagesList.sort(); @@ -82,7 +83,7 @@ unmanagedChangeState |= currentPreferredLanguagesList != refPreferredLanguagesList; unmanagedDefaultState &= currentPreferredLanguagesList == defaultPreferredLanguagesList; - unmanagedChangeState |= m_skeleton->defaultLanguage() != m_configWidget->language(); + unmanagedChangeState |= skeleton()->defaultLanguage() != m_configWidget->language(); unmanagedDefaultState &= m_configWidget->language() == Sonnet::Settings::defaultDefaultLanguage(); unmanagedWidgetDefaultState(unmanagedDefaultState); @@ -97,20 +98,20 @@ { KCModule::load(); // Set unmanaged widget value - m_configWidget->setIgnoreList(m_skeleton->ignoreList()); - m_configWidget->setPreferredLanguages(m_skeleton->preferredLanguages()); - m_configWidget->setLanguage(m_skeleton->defaultLanguage()); + m_configWidget->setIgnoreList(skeleton()->ignoreList()); + m_configWidget->setPreferredLanguages(skeleton()->preferredLanguages()); + m_configWidget->setLanguage(skeleton()->defaultLanguage()); } void SonnetSpellCheckingModule::save() { - m_skeleton->setIgnoreList(m_configWidget->ignoreList()); - m_skeleton->setPreferredLanguages(m_configWidget->preferredLanguages()); - m_skeleton->setDefaultLanguage(m_configWidget->language()); + skeleton()->setIgnoreList(m_configWidget->ignoreList()); + skeleton()->setPreferredLanguages(m_configWidget->preferredLanguages()); + skeleton()->setDefaultLanguage(m_configWidget->language()); // with addConfig, save on skeleton will be trigger only if one managed widget changed if (!m_managedConfig->hasChanged()) { - m_skeleton->save(); + skeleton()->save(); } KCModule::save(); } @@ -124,4 +125,9 @@ m_configWidget->setLanguage(Sonnet::Settings::defaultDefaultLanguage()); } +SpellCheckingSkeleton *SonnetSpellCheckingModule::skeleton() const +{ + return m_data->settings(); +} + #include "spellchecking.moc" diff --git a/kcms/spellchecking/spellcheckingdata.h b/kcms/spellchecking/spellcheckingdata.h new file mode 100644 --- /dev/null +++ b/kcms/spellchecking/spellcheckingdata.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2020 Benjamin Port + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + */ + +#ifndef SPELLCHECKINGDATA_H +#define SPELLCHECKINGDATA_H + +#include + +#include "kcmoduledata.h" + +class SpellCheckingSkeleton; + +class SpellCheckingData : public KCModuleData +{ + Q_OBJECT + +public: + explicit SpellCheckingData(QObject *parent = nullptr, const QVariantList &args = QVariantList()); + SpellCheckingSkeleton *settings() const; + bool isDefaults() const override; + +private: + SpellCheckingSkeleton *m_settings; +}; + +#endif diff --git a/kcms/spellchecking/spellcheckingdata.cpp b/kcms/spellchecking/spellcheckingdata.cpp new file mode 100644 --- /dev/null +++ b/kcms/spellchecking/spellcheckingdata.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2020 Benjamin Port + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + */ + +#include "spellcheckingdata.h" + +#include + +#include + +#include "spellcheckingskeleton.h" + +SpellCheckingData::SpellCheckingData(QObject *parent, const QVariantList &args) + : KCModuleData(parent, args) + , m_settings(new SpellCheckingSkeleton(this)) +{ + autoRegisterSkeletons(); +} + +SpellCheckingSkeleton *SpellCheckingData::settings() const +{ + return m_settings; +} + +bool SpellCheckingData::isDefaults() const +{ + bool isDefaults = KCModuleData::isDefaults(); + + QStringList refIgnoreList(m_settings->ignoreList()); + refIgnoreList.removeDuplicates(); + refIgnoreList.sort(); + + QStringList defaultIgnoreList(Sonnet::Settings::defaultIgnoreList()); + defaultIgnoreList.removeDuplicates(); + defaultIgnoreList.sort(); + + QStringList refPreferredLanguagesList(m_settings->preferredLanguages()); + refPreferredLanguagesList.removeDuplicates(); + refPreferredLanguagesList.sort(); + + QStringList defaultPreferredLanguagesList(Sonnet::Settings::defaultPreferredLanguages()); + defaultPreferredLanguagesList.removeDuplicates(); + defaultPreferredLanguagesList.sort(); + + isDefaults &= refIgnoreList == defaultIgnoreList; + isDefaults &= refPreferredLanguagesList == defaultPreferredLanguagesList; + isDefaults &= m_settings->defaultLanguage() == Sonnet::Settings::defaultDefaultLanguage(); + + return isDefaults; +} + + +#include "spellcheckingdata.moc"