File indexing completed on 2024-11-10 04:57:11

0001 /*
0002     SPDX-FileCopyrightText: 2022 Marco Martin <mart@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #include "tileseditoreffectkcm.h"
0007 
0008 #include <config-kwin.h>
0009 
0010 #include <kwineffects_interface.h>
0011 
0012 #include <KActionCollection>
0013 #include <KGlobalAccel>
0014 #include <KLocalizedString>
0015 #include <KPluginFactory>
0016 
0017 #include <QAction>
0018 
0019 K_PLUGIN_CLASS(KWin::TilesEditorEffectConfig)
0020 
0021 namespace KWin
0022 {
0023 
0024 TilesEditorEffectConfig::TilesEditorEffectConfig(QObject *parent, const KPluginMetaData &data)
0025     : KCModule(parent, data)
0026 {
0027     ui.setupUi(widget());
0028 
0029     auto actionCollection = new KActionCollection(this, QStringLiteral("kwin"));
0030 
0031     actionCollection->setComponentDisplayName(i18n("KWin"));
0032     actionCollection->setConfigGroup(QStringLiteral("tileseditor"));
0033     actionCollection->setConfigGlobal(true);
0034 
0035     const QKeySequence defaultToggleShortcut = Qt::META | Qt::Key_T;
0036     QAction *toggleAction = actionCollection->addAction(QStringLiteral("Edit Tiles"));
0037     toggleAction->setText(i18n("Toggle Tiles Editor"));
0038     toggleAction->setProperty("isConfigurationAction", true);
0039     KGlobalAccel::self()->setDefaultShortcut(toggleAction, {defaultToggleShortcut});
0040     KGlobalAccel::self()->setShortcut(toggleAction, {defaultToggleShortcut});
0041 
0042     ui.shortcutsEditor->addCollection(actionCollection);
0043     connect(ui.shortcutsEditor, &KShortcutsEditor::keyChange, this, &KCModule::markAsChanged);
0044 }
0045 
0046 void TilesEditorEffectConfig::save()
0047 {
0048     KCModule::save();
0049     ui.shortcutsEditor->save();
0050 
0051     OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"),
0052                                          QStringLiteral("/Effects"),
0053                                          QDBusConnection::sessionBus());
0054     interface.reconfigureEffect(QStringLiteral("tileseditor"));
0055 }
0056 
0057 void TilesEditorEffectConfig::defaults()
0058 {
0059     ui.shortcutsEditor->allDefault();
0060     KCModule::defaults();
0061 }
0062 
0063 } // namespace KWin
0064 
0065 #include "tileseditoreffectkcm.moc"
0066 
0067 #include "moc_tileseditoreffectkcm.cpp"