File indexing completed on 2024-11-10 04:56:59
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2007 Rivo Laks <rivolaks@hot.ee> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include "invert_config.h" 0011 #include <kwineffects_interface.h> 0012 0013 #include <QAction> 0014 0015 #include <KActionCollection> 0016 #include <KGlobalAccel> 0017 #include <KLocalizedString> 0018 #include <KPluginFactory> 0019 #include <KShortcutsEditor> 0020 0021 #include <QVBoxLayout> 0022 0023 K_PLUGIN_CLASS(KWin::InvertEffectConfig) 0024 0025 namespace KWin 0026 { 0027 0028 InvertEffectConfig::InvertEffectConfig(QObject *parent, const KPluginMetaData &data) 0029 : KCModule(parent, data) 0030 { 0031 QVBoxLayout *layout = new QVBoxLayout(widget()); 0032 0033 // Shortcut config. The shortcut belongs to the component "kwin"! 0034 KActionCollection *actionCollection = new KActionCollection(widget(), QStringLiteral("kwin")); 0035 actionCollection->setComponentDisplayName(i18n("KWin")); 0036 0037 QAction *a = actionCollection->addAction(QStringLiteral("Invert")); 0038 a->setText(i18n("Toggle Invert Effect")); 0039 a->setProperty("isConfigurationAction", true); 0040 KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << (Qt::CTRL | Qt::META | Qt::Key_I)); 0041 KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << (Qt::CTRL | Qt::META | Qt::Key_I)); 0042 0043 QAction *b = actionCollection->addAction(QStringLiteral("InvertWindow")); 0044 b->setText(i18n("Toggle Invert Effect on Window")); 0045 b->setProperty("isConfigurationAction", true); 0046 KGlobalAccel::self()->setDefaultShortcut(b, QList<QKeySequence>() << (Qt::CTRL | Qt::META | Qt::Key_U)); 0047 KGlobalAccel::self()->setShortcut(b, QList<QKeySequence>() << (Qt::CTRL | Qt::META | Qt::Key_U)); 0048 0049 mShortcutEditor = new KShortcutsEditor(actionCollection, widget(), 0050 KShortcutsEditor::GlobalAction, KShortcutsEditor::LetterShortcutsDisallowed); 0051 connect(mShortcutEditor, &KShortcutsEditor::keyChange, this, &KCModule::markAsChanged); 0052 layout->addWidget(mShortcutEditor); 0053 } 0054 0055 void InvertEffectConfig::load() 0056 { 0057 KCModule::load(); 0058 0059 setNeedsSave(false); 0060 } 0061 0062 void InvertEffectConfig::save() 0063 { 0064 KCModule::save(); 0065 0066 mShortcutEditor->save(); // undo() will restore to this state from now on 0067 0068 setNeedsSave(false); 0069 OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), 0070 QStringLiteral("/Effects"), 0071 QDBusConnection::sessionBus()); 0072 interface.reconfigureEffect(QStringLiteral("invert")); 0073 } 0074 0075 void InvertEffectConfig::defaults() 0076 { 0077 mShortcutEditor->allDefault(); 0078 0079 setNeedsSave(true); 0080 } 0081 0082 } // namespace 0083 0084 #include "invert_config.moc" 0085 0086 #include "moc_invert_config.cpp"