diff --git a/src/debug_console.cpp b/src/debug_console.cpp index 5b82d45968..fdd686a78d 100644 --- a/src/debug_console.cpp +++ b/src/debug_console.cpp @@ -619,6 +619,8 @@ DebugConsole::DebugConsole() setWindowFlags(Qt::X11BypassWindowManagerHint); } + m_ui->tabWidget->addTab(new DebugConsoleEffectsTab(), i18nc("@label", "Effects")); + connect(m_ui->quitButton, &QAbstractButton::clicked, this, &DebugConsole::deleteLater); connect(m_ui->tabWidget, &QTabWidget::currentChanged, this, [this](int index) { // delay creation of input event filter until the tab is selected @@ -1565,6 +1567,62 @@ void DataSourceModel::setSource(AbstractDataSource *source) } endResetModel(); } + +DebugConsoleEffectItem::DebugConsoleEffectItem(const QString &name, bool loaded, QWidget *parent) + : QWidget(parent) + , m_name(name) + , m_loaded(loaded) +{ + QHBoxLayout *layout = new QHBoxLayout(this); + + QLabel *label = new QLabel(name, this); + layout->addWidget(label); + + QPushButton *toggleButton = new QPushButton(this); + layout->addWidget(toggleButton); + + if (loaded) { + toggleButton->setText(i18nc("@action:button unload an effect", "Unload")); + } else { + toggleButton->setText(i18nc("@action:button load an effect", "Load")); + } + + connect(toggleButton, &QPushButton::clicked, this, [this, toggleButton]() { + if (m_loaded) { + m_loaded = false; + effects->unloadEffect(m_name); + } else { + m_loaded = effects->loadEffect(m_name); + } + + if (m_loaded) { + toggleButton->setText(i18nc("@action:button unload an effect", "Unload")); + } else { + toggleButton->setText(i18nc("@action:button load an effect", "Load")); + } + }); } +DebugConsoleEffectsTab::DebugConsoleEffectsTab(QWidget *parent) + : QListWidget(parent) +{ + if (!effects) { + return; + } + + const QStringList availableEffects = effects->listOfEffects(); + const QStringList loadedEffects = effects->loadedEffects(); + + for (const QString &effectName : availableEffects) { + QListWidgetItem *item = new QListWidgetItem(this); + DebugConsoleEffectItem *effectItem = new DebugConsoleEffectItem(effectName, loadedEffects.contains(effectName)); + + addItem(item); + setItemWidget(item, effectItem); + item->setSizeHint(effectItem->sizeHint()); + } +} + +} // namespace KWin + #include "moc_debug_console.cpp" diff --git a/src/debug_console.h b/src/debug_console.h index 3cf9615ba2..0b7d72d4ed 100644 --- a/src/debug_console.h +++ b/src/debug_console.h @@ -16,10 +16,14 @@ #include #include +#include #include + #include #include +class QLabel; +class QPushButton; class QTextEdit; namespace Ui @@ -185,4 +189,25 @@ private: AbstractDataSource *m_source = nullptr; QList m_data; }; -} + +class DebugConsoleEffectItem : public QWidget +{ + Q_OBJECT + +public: + explicit DebugConsoleEffectItem(const QString &name, bool loaded, QWidget *parent = nullptr); + +private: + QString m_name; + bool m_loaded = false; +}; + +class DebugConsoleEffectsTab : public QListWidget +{ + Q_OBJECT + +public: + explicit DebugConsoleEffectsTab(QWidget *parent = nullptr); +}; + +} // namespace KWin