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

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net>
0006     SPDX-FileCopyrightText: 2023 Andrew Shark <ashark at linuxcomp.ru>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 #include "mousemark_config.h"
0011 
0012 #include <config-kwin.h>
0013 
0014 // KConfigSkeleton
0015 #include "mousemarkconfig.h"
0016 #include <kwineffects_interface.h>
0017 
0018 #include <QAction>
0019 
0020 #include <KActionCollection>
0021 #include <KGlobalAccel>
0022 #include <KLocalizedString>
0023 #include <KPluginFactory>
0024 
0025 #include <QDebug>
0026 #include <QWidget>
0027 
0028 K_PLUGIN_CLASS(KWin::MouseMarkEffectConfig)
0029 
0030 namespace KWin
0031 {
0032 
0033 MouseMarkEffectConfig::MouseMarkEffectConfig(QObject *parent, const KPluginMetaData &data)
0034     : KCModule(parent, data)
0035 {
0036     m_ui.setupUi(widget());
0037 
0038     MouseMarkConfig::instance(KWIN_CONFIG);
0039     addConfig(MouseMarkConfig::self(), widget());
0040 
0041     // Shortcut config. The shortcut belongs to the component "kwin"!
0042     m_actionCollection = new KActionCollection(this, QStringLiteral("kwin"));
0043     m_actionCollection->setComponentDisplayName(i18n("KWin"));
0044 
0045     QAction *a = m_actionCollection->addAction(QStringLiteral("ClearMouseMarks"));
0046     a->setText(i18n("Clear Mouse Marks"));
0047     a->setProperty("isConfigurationAction", true);
0048     KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << (Qt::SHIFT | Qt::META | Qt::Key_F11));
0049     KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << (Qt::SHIFT | Qt::META | Qt::Key_F11));
0050 
0051     a = m_actionCollection->addAction(QStringLiteral("ClearLastMouseMark"));
0052     a->setText(i18n("Clear Last Mouse Mark"));
0053     a->setProperty("isConfigurationAction", true);
0054     KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << (Qt::SHIFT | Qt::META | Qt::Key_F12));
0055     KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << (Qt::SHIFT | Qt::META | Qt::Key_F12));
0056 
0057     m_ui.editor->addCollection(m_actionCollection);
0058 
0059     connect(m_ui.kcfg_LineWidth, qOverload<int>(&QSpinBox::valueChanged), this, [this]() {
0060         updateSpinBoxSuffix();
0061     });
0062 }
0063 
0064 void MouseMarkEffectConfig::load()
0065 {
0066     KCModule::load();
0067 
0068     updateSpinBoxSuffix();
0069 }
0070 
0071 void MouseMarkEffectConfig::save()
0072 {
0073     qDebug() << "Saving config of MouseMark";
0074     KCModule::save();
0075 
0076     m_actionCollection->writeSettings();
0077     m_ui.editor->save(); // undo() will restore to this state from now on
0078 
0079     OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"),
0080                                          QStringLiteral("/Effects"),
0081                                          QDBusConnection::sessionBus());
0082     interface.reconfigureEffect(QStringLiteral("mousemark"));
0083 }
0084 
0085 void MouseMarkEffectConfig::updateSpinBoxSuffix()
0086 {
0087     m_ui.kcfg_LineWidth->setSuffix(i18ncp("Suffix", " pixel", " pixels", m_ui.kcfg_LineWidth->value()));
0088 }
0089 
0090 } // namespace
0091 
0092 #include "mousemark_config.moc"
0093 
0094 #include "moc_mousemark_config.cpp"