KCM KWin Decoration: Add module data

depends on https://invent.kde.org/frameworks/kcmutils/-/merge_requests/19
This commit is contained in:
Benjamin Port 2020-09-30 14:24:02 +02:00
parent 5290583f8a
commit 7546af6b4c
4 changed files with 33 additions and 21 deletions

View file

@ -414,6 +414,7 @@ include_directories(BEFORE
add_subdirectory(libkwineffects)
if (KWIN_BUILD_KCMS)
include(KCMUtilsGenerateModuleData)
add_subdirectory(kcmkwin)
endif()

View file

@ -10,6 +10,14 @@ set(kcmkwindecoration_SRCS
utils.cpp
)
kcmutils_generate_module_data(
kcmkwindecoration_SRCS
MODULE_DATA_HEADER kwindecorationdata.h
MODULE_DATA_CLASS_NAME KWinDecorationData
SETTINGS_HEADERS kwindecorationsettings.h
SETTINGS_CLASSES KWinDecorationSettings
)
kconfig_add_kcfg_files(kcmkwindecoration_SRCS kwindecorationsettings.kcfgc GENERATE_MOC)
add_library(kcm_kwindecoration MODULE ${kcmkwindecoration_SRCS})
@ -17,6 +25,7 @@ add_library(kcm_kwindecoration MODULE ${kcmkwindecoration_SRCS})
target_link_libraries(kcm_kwindecoration
KDecoration2::KDecoration
KF5::I18n
KF5::KCMUtils
KF5::NewStuff
KF5::QuickAddons
Qt5::Quick

View file

@ -25,9 +25,10 @@
#include <KNewStuff3/KNS3/DownloadDialog>
#include "kwindecorationdata.h"
#include "kwindecorationsettings.h"
K_PLUGIN_FACTORY_WITH_JSON(KCMKWinDecorationFactory, "kwindecoration.json", registerPlugin<KCMKWinDecoration>();)
K_PLUGIN_FACTORY_WITH_JSON(KCMKWinDecorationFactory, "kwindecoration.json", registerPlugin<KCMKWinDecoration>();registerPlugin<KWinDecorationData>();)
Q_DECLARE_METATYPE(KDecoration2::BorderSize)
@ -44,7 +45,7 @@ KCMKWinDecoration::KCMKWinDecoration(QObject *parent, const QVariantList &argume
, m_leftButtonsModel(new KDecoration2::Preview::ButtonsModel(DecorationButtonsList(), this))
, m_rightButtonsModel(new KDecoration2::Preview::ButtonsModel(DecorationButtonsList(), this))
, m_availableButtonsModel(new KDecoration2::Preview::ButtonsModel(this))
, m_settings(new KWinDecorationSettings(this))
, m_data(new KWinDecorationData(this))
{
auto about = new KAboutData(QStringLiteral("kcm_kwindecoration"),
i18n("Window Decorations"),
@ -64,8 +65,8 @@ KCMKWinDecoration::KCMKWinDecoration(QObject *parent, const QVariantList &argume
m_proxyThemesModel->setSortCaseSensitivity(Qt::CaseInsensitive);
m_proxyThemesModel->sort(0);
connect(m_settings, &KWinDecorationSettings::themeChanged, this, &KCMKWinDecoration::themeChanged);
connect(m_settings, &KWinDecorationSettings::borderSizeChanged, this, &KCMKWinDecoration::borderSizeChanged);
connect(m_data->settings(), &KWinDecorationSettings::themeChanged, this, &KCMKWinDecoration::themeChanged);
connect(m_data->settings(), &KWinDecorationSettings::borderSizeChanged, this, &KCMKWinDecoration::borderSizeChanged);
connect(m_leftButtonsModel, &QAbstractItemModel::rowsInserted, this, &KCMKWinDecoration::onLeftButtonsChanged);
connect(m_leftButtonsModel, &QAbstractItemModel::rowsMoved, this, &KCMKWinDecoration::onLeftButtonsChanged);
@ -89,7 +90,7 @@ KCMKWinDecoration::KCMKWinDecoration(QObject *parent, const QVariantList &argume
KWinDecorationSettings *KCMKWinDecoration::settings() const
{
return m_settings;
return m_data->settings();
}
void KCMKWinDecoration::reloadKWinSettings()
@ -120,20 +121,20 @@ void KCMKWinDecoration::load()
{
ManagedConfigModule::load();
m_leftButtonsModel->replace(Utils::buttonsFromString(m_settings->buttonsOnLeft()));
m_rightButtonsModel->replace(Utils::buttonsFromString(m_settings->buttonsOnRight()));
m_leftButtonsModel->replace(Utils::buttonsFromString(settings()->buttonsOnLeft()));
m_rightButtonsModel->replace(Utils::buttonsFromString(settings()->buttonsOnRight()));
setBorderSize(borderSizeIndexFromString(m_settings->borderSize()));
setBorderSize(borderSizeIndexFromString(settings()->borderSize()));
emit themeChanged();
}
void KCMKWinDecoration::save()
{
if (!m_settings->borderSizeAuto()) {
m_settings->setBorderSize(borderSizeIndexToString(m_borderSizeIndex));
if (!settings()->borderSizeAuto()) {
settings()->setBorderSize(borderSizeIndexToString(m_borderSizeIndex));
} else {
m_settings->setBorderSize(m_settings->defaultBorderSizeValue());
settings()->setBorderSize(settings()->defaultBorderSizeValue());
}
ManagedConfigModule::save();
@ -151,18 +152,18 @@ void KCMKWinDecoration::defaults()
setBorderSize(recommendedBorderSize());
m_leftButtonsModel->replace(Utils::buttonsFromString(m_settings->buttonsOnLeft()));
m_rightButtonsModel->replace(Utils::buttonsFromString(m_settings->buttonsOnRight()));
m_leftButtonsModel->replace(Utils::buttonsFromString(settings()->buttonsOnLeft()));
m_rightButtonsModel->replace(Utils::buttonsFromString(settings()->buttonsOnRight()));
}
void KCMKWinDecoration::onLeftButtonsChanged()
{
m_settings->setButtonsOnLeft(Utils::buttonsToString(m_leftButtonsModel->buttons()));
settings()->setButtonsOnLeft(Utils::buttonsToString(m_leftButtonsModel->buttons()));
}
void KCMKWinDecoration::onRightButtonsChanged()
{
m_settings->setButtonsOnRight(Utils::buttonsToString(m_rightButtonsModel->buttons()));
settings()->setButtonsOnRight(Utils::buttonsToString(m_rightButtonsModel->buttons()));
}
QSortFilterProxyModel *KCMKWinDecoration::themesModel() const
@ -211,7 +212,7 @@ int KCMKWinDecoration::recommendedBorderSize() const
int KCMKWinDecoration::theme() const
{
return m_proxyThemesModel->mapFromSource(m_themesModel->findDecoration(m_settings->pluginName(), m_settings->theme())).row();
return m_proxyThemesModel->mapFromSource(m_themesModel->findDecoration(settings()->pluginName(), settings()->theme())).row();
}
void KCMKWinDecoration::setBorderSize(int index)
@ -224,22 +225,22 @@ void KCMKWinDecoration::setBorderSize(int index)
void KCMKWinDecoration::setBorderSize(KDecoration2::BorderSize size)
{
m_settings->setBorderSize(Utils::borderSizeToString(size));
settings()->setBorderSize(Utils::borderSizeToString(size));
}
void KCMKWinDecoration::setTheme(int index)
{
QModelIndex dataIndex = m_proxyThemesModel->index(index, 0);
if (dataIndex.isValid()) {
m_settings->setTheme(m_proxyThemesModel->data(dataIndex, KDecoration2::Configuration::DecorationsModel::ThemeNameRole).toString());
m_settings->setPluginName(m_proxyThemesModel->data(dataIndex, KDecoration2::Configuration::DecorationsModel::PluginNameRole).toString());
settings()->setTheme(m_proxyThemesModel->data(dataIndex, KDecoration2::Configuration::DecorationsModel::ThemeNameRole).toString());
settings()->setPluginName(m_proxyThemesModel->data(dataIndex, KDecoration2::Configuration::DecorationsModel::PluginNameRole).toString());
emit themeChanged();
}
}
bool KCMKWinDecoration::isSaveNeeded() const
{
return !m_settings->borderSizeAuto() && borderSizeIndexFromString(m_settings->borderSize()) != m_borderSizeIndex;
return !settings()->borderSizeAuto() && borderSizeIndexFromString(settings()->borderSize()) != m_borderSizeIndex;
}
int KCMKWinDecoration::borderSizeIndexFromString(const QString &size) const

View file

@ -36,6 +36,7 @@ class DecorationsModel;
}
class KWinDecorationSettings;
class KWinDecorationData;
class KCMKWinDecoration : public KQuickAddons::ManagedConfigModule
{
@ -100,5 +101,5 @@ private:
QPointer<KNS3::DownloadDialog> m_newStuffDialog;
int m_borderSizeIndex = -1;
KWinDecorationSettings *m_settings;
KWinDecorationData *m_data;
};