From 3639d5789259561c531a3481d7061a0cb492c644 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 9 Oct 2018 12:05:28 +0200 Subject: Unlink plugins from lib/ libraries --- plugins/ConfigurationEditor/CMakeLists.txt | 8 +-- .../configurationeditorplugin.cpp | 27 ++++++++- .../configurationeditorplugin.h | 12 +++- .../forms/configurationdialog.cpp | 65 ++++++++++++---------- .../forms/configurationdialog.h | 23 ++++++-- 5 files changed, 92 insertions(+), 43 deletions(-) (limited to 'plugins/ConfigurationEditor') diff --git a/plugins/ConfigurationEditor/CMakeLists.txt b/plugins/ConfigurationEditor/CMakeLists.txt index 22ef3d3..699366e 100644 --- a/plugins/ConfigurationEditor/CMakeLists.txt +++ b/plugins/ConfigurationEditor/CMakeLists.txt @@ -5,6 +5,9 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) add_library(ConfigurationEditorPlugin SHARED + ${CMAKE_SOURCE_DIR}/include/plugininterface.h + ${CMAKE_SOURCE_DIR}/include/browserinterface.h + configurationeditorplugin.cpp configurationeditorplugin.h forms/configurationdialog.cpp @@ -13,14 +16,11 @@ add_library(ConfigurationEditorPlugin SHARED ) target_include_directories(ConfigurationEditorPlugin - PRIVATE ${CMAKE_SOURCE_DIR}/plugins - PRIVATE ${CMAKE_SOURCE_DIR}/lib/configuration - PRIVATE ${Boost_INCLUDE_DIRS} + PRIVATE ${CMAKE_SOURCE_DIR}/include ) target_link_libraries(ConfigurationEditorPlugin PRIVATE Qt5::Widgets - PRIVATE configuration ) if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") diff --git a/plugins/ConfigurationEditor/configurationeditorplugin.cpp b/plugins/ConfigurationEditor/configurationeditorplugin.cpp index bf8a90d..1f60cc0 100644 --- a/plugins/ConfigurationEditor/configurationeditorplugin.cpp +++ b/plugins/ConfigurationEditor/configurationeditorplugin.cpp @@ -1,8 +1,15 @@ +/* + * This file is part of smolbote. It's copyrighted by the contributors recorded + * in the version control history of the file, available from its original + * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote + * + * SPDX-License-Identifier: GPL-3.0 + */ + #include "configurationeditorplugin.h" #include "forms/configurationdialog.h" #include #include -#include CommandHash_t ConfigurationEditorPlugin::commands() { @@ -16,9 +23,23 @@ CommandHash_t ConfigurationEditorPlugin::commands() return hash; } -QDialog *ConfigurationEditorPlugin::createWidget(QWidget *parent) +QDialog *ConfigurationEditorPlugin::createWidget(QWidget *parent) const { - auto *dlg = new ConfigurationDialog(browser->getConfiguration(), parent); + auto *app = browser(); + Q_CHECK_PTR(app); + + auto *dlg = new ConfigurationDialog(parent); dlg->setAttribute(Qt::WA_DeleteOnClose, true); + + for(const QString &key : app->configurationOptions()) { + dlg->addOption(key, app->configuration(key)); + } + dlg->ui->settings_treeWidget->resizeColumnToContents(0); + dlg->ui->shortcuts_treeWidget->resizeColumnToContents(0); + + connect(dlg, &ConfigurationDialog::configurationChanged, dlg, [app](const QString &key, const QString &value) { + app->setConfiguration(key, value); + }); + return dlg; } diff --git a/plugins/ConfigurationEditor/configurationeditorplugin.h b/plugins/ConfigurationEditor/configurationeditorplugin.h index 5e70ab7..7e7ebc6 100644 --- a/plugins/ConfigurationEditor/configurationeditorplugin.h +++ b/plugins/ConfigurationEditor/configurationeditorplugin.h @@ -1,8 +1,16 @@ +/* + * This file is part of smolbote. It's copyrighted by the contributors recorded + * in the version control history of the file, available from its original + * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote + * + * SPDX-License-Identifier: GPL-3.0 + */ + #ifndef CONFIGURATIONEDITOR_PLUGIN_H #define CONFIGURATIONEDITOR_PLUGIN_H #include -#include +#include class QDialog; class ConfigurationEditorPlugin : public QObject, public PluginInterface @@ -14,7 +22,7 @@ class ConfigurationEditorPlugin : public QObject, public PluginInterface public: // PluginInterface CommandHash_t commands() override; - QDialog *createWidget(QWidget *parent = nullptr) override; + QDialog *createWidget(QWidget *parent = nullptr) const override; }; #endif // CONFIGURATIONEDITOR_PLUGIN_H diff --git a/plugins/ConfigurationEditor/forms/configurationdialog.cpp b/plugins/ConfigurationEditor/forms/configurationdialog.cpp index ffe7f9c..f433d70 100644 --- a/plugins/ConfigurationEditor/forms/configurationdialog.cpp +++ b/plugins/ConfigurationEditor/forms/configurationdialog.cpp @@ -1,41 +1,50 @@ +/* + * This file is part of smolbote. It's copyrighted by the contributors recorded + * in the version control history of the file, available from its original + * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote + * + * SPDX-License-Identifier: GPL-3.0 + */ + #include "configurationdialog.h" -#include "ui_configurationdialog.h" -#include #include +#include -ConfigurationDialog::ConfigurationDialog(Configuration *conf, QWidget *parent) : +ConfigurationDialog::ConfigurationDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ConfigurationDialog) { ui->setupUi(this); - Q_CHECK_PTR(conf); - - for(const auto &option : conf->options()) { - auto path = QString::fromStdString(option->long_name()); - auto value = QString::fromStdString(conf->value(option->long_name().c_str()).value_or("")); - - QTreeWidgetItem *item = nullptr; - if(path.contains("shortcut")) { - item = new QTreeWidgetItem(ui->shortcuts_treeWidget); - auto *edit = new QKeySequenceEdit(value); - connect(edit, &QKeySequenceEdit::keySequenceChanged, this, [=](const QKeySequence &keySequqnce) { - conf->setValue(qUtf8Printable(path), keySequqnce.toString()); - }); - ui->shortcuts_treeWidget->setItemWidget(item, 1, edit); - } else { - item = new QTreeWidgetItem(ui->settings_treeWidget); - item->setText(1, value); - } - - item->setText(0, path); - - } - - ui->settings_treeWidget->resizeColumnToContents(0); - ui->shortcuts_treeWidget->resizeColumnToContents(0); } ConfigurationDialog::~ConfigurationDialog() { delete ui; } + +void ConfigurationDialog::addOption(const QString &key, const QString &value) +{ + QTreeWidgetItem *item = nullptr; + + if(key.contains(QLatin1Literal("shortcut"))) { + item = new QTreeWidgetItem(ui->shortcuts_treeWidget); + + auto *edit = new QKeySequenceEdit(value); + ui->shortcuts_treeWidget->setItemWidget(item, 1, edit); + + connect(edit, &QKeySequenceEdit::keySequenceChanged, this, [this, key](const QKeySequence &keySequence) { + emit configurationChanged(key, keySequence.toString()); + }); + + } else { + item = new QTreeWidgetItem(ui->settings_treeWidget); + + auto *edit = new QLineEdit(value); + ui->settings_treeWidget->setItemWidget(item, 1, edit); + + connect(edit, &QLineEdit::editingFinished, this, [this, key, edit]() { + emit configurationChanged(key, edit->text()); + }); + } + item->setText(0, key); +} diff --git a/plugins/ConfigurationEditor/forms/configurationdialog.h b/plugins/ConfigurationEditor/forms/configurationdialog.h index 9d86f2d..fd07aa8 100644 --- a/plugins/ConfigurationEditor/forms/configurationdialog.h +++ b/plugins/ConfigurationEditor/forms/configurationdialog.h @@ -1,21 +1,32 @@ +/* + * This file is part of smolbote. It's copyrighted by the contributors recorded + * in the version control history of the file, available from its original + * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote + * + * SPDX-License-Identifier: GPL-3.0 + */ + #ifndef CONFIGURATIONDIALOG_H #define CONFIGURATIONDIALOG_H #include +#include "ui_configurationdialog.h" -namespace Ui { -class ConfigurationDialog; -} - -class Configuration; class ConfigurationDialog : public QDialog { Q_OBJECT + friend class ConfigurationEditorPlugin; + public: - explicit ConfigurationDialog(Configuration *conf, QWidget *parent = nullptr); + explicit ConfigurationDialog(QWidget *parent = nullptr); ~ConfigurationDialog(); + void addOption(const QString &key, const QString &value); + +signals: + void configurationChanged(const QString &key, const QString &value); + private: Ui::ConfigurationDialog *ui; }; -- cgit v1.2.1