aboutsummaryrefslogtreecommitdiff
path: root/plugins/ConfigurationEditor/forms
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-06-23 16:24:24 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-06-23 16:24:24 +0200
commitdd3115fee8fbc20c8d9ac71eb3a13198d29d7f53 (patch)
tree516ed976f2463504c46ffc2f1eb28d61acfee9f2 /plugins/ConfigurationEditor/forms
parentSort commands alphabetically (diff)
downloadsmolbote-dd3115fee8fbc20c8d9ac71eb3a13198d29d7f53.tar.xz
Split shortcuts into new tab
Diffstat (limited to 'plugins/ConfigurationEditor/forms')
-rw-r--r--plugins/ConfigurationEditor/forms/configurationdialog.cpp41
-rw-r--r--plugins/ConfigurationEditor/forms/configurationdialog.h23
-rw-r--r--plugins/ConfigurationEditor/forms/configurationdialog.ui119
-rw-r--r--plugins/ConfigurationEditor/forms/settingsdialog.cpp101
-rw-r--r--plugins/ConfigurationEditor/forms/settingsdialog.h35
5 files changed, 183 insertions, 136 deletions
diff --git a/plugins/ConfigurationEditor/forms/configurationdialog.cpp b/plugins/ConfigurationEditor/forms/configurationdialog.cpp
new file mode 100644
index 0000000..ffe7f9c
--- /dev/null
+++ b/plugins/ConfigurationEditor/forms/configurationdialog.cpp
@@ -0,0 +1,41 @@
+#include "configurationdialog.h"
+#include "ui_configurationdialog.h"
+#include <configuration.h>
+#include <QKeySequenceEdit>
+
+ConfigurationDialog::ConfigurationDialog(Configuration *conf, 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<std::string>(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;
+}
diff --git a/plugins/ConfigurationEditor/forms/configurationdialog.h b/plugins/ConfigurationEditor/forms/configurationdialog.h
new file mode 100644
index 0000000..9d86f2d
--- /dev/null
+++ b/plugins/ConfigurationEditor/forms/configurationdialog.h
@@ -0,0 +1,23 @@
+#ifndef CONFIGURATIONDIALOG_H
+#define CONFIGURATIONDIALOG_H
+
+#include <QDialog>
+
+namespace Ui {
+class ConfigurationDialog;
+}
+
+class Configuration;
+class ConfigurationDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit ConfigurationDialog(Configuration *conf, QWidget *parent = nullptr);
+ ~ConfigurationDialog();
+
+private:
+ Ui::ConfigurationDialog *ui;
+};
+
+#endif // CONFIGURATIONDIALOG_H
diff --git a/plugins/ConfigurationEditor/forms/configurationdialog.ui b/plugins/ConfigurationEditor/forms/configurationdialog.ui
new file mode 100644
index 0000000..738d4a1
--- /dev/null
+++ b/plugins/ConfigurationEditor/forms/configurationdialog.ui
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ConfigurationDialog</class>
+ <widget class="QDialog" name="ConfigurationDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>600</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Configuration</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="settings_tab">
+ <attribute name="title">
+ <string>Settings</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <widget class="QTreeWidget" name="settings_treeWidget">
+ <property name="editTriggers">
+ <set>QAbstractItemView::NoEditTriggers</set>
+ </property>
+ <column>
+ <property name="text">
+ <string>Name</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Value</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="shortcuts_tab">
+ <attribute name="title">
+ <string>Shortcuts</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QTreeWidget" name="shortcuts_treeWidget">
+ <property name="editTriggers">
+ <set>QAbstractItemView::NoEditTriggers</set>
+ </property>
+ <column>
+ <property name="text">
+ <string notr="true">Name</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Value</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Close</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>ConfigurationDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>ConfigurationDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/plugins/ConfigurationEditor/forms/settingsdialog.cpp b/plugins/ConfigurationEditor/forms/settingsdialog.cpp
deleted file mode 100644
index ebc054e..0000000
--- a/plugins/ConfigurationEditor/forms/settingsdialog.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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/smolbote.hg
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#include "settingsdialog.h"
-#include <QApplication>
-#include <QFile>
-#include <QMenuBar>
-#include <QStatusBar>
-#include <QToolButton>
-#include <QVBoxLayout>
-#include <QFileDialog>
-#include <configuration.h>
-
-SettingsDialog::SettingsDialog(Configuration *config, QWidget *parent)
- : QDialog(parent)
-{
- resize(800, 600);
- Q_CHECK_PTR(config);
-
- // main menu
-// settingsMenu.setTitle(tr("Settings"));
-
-// auto *saveAction = settingsMenu.addAction(tr("Save"));
-// saveAction->setShortcut(QKeySequence::Save);
-
-// auto *saveAsAction = settingsMenu.addAction(tr("Save As"));
-// saveAsAction->setShortcut(QKeySequence::SaveAs);
-
-// settingsMenu.addAction(tr("Quit"), qApp, &QApplication::quit, QKeySequence::Quit);
-
-// menuBar()->addMenu(&settingsMenu);
-
- auto *layout = new QVBoxLayout(this);
- layout->addWidget(&treeWidget);
- treeWidget.setColumnCount(2);
- treeWidget.setHeaderLabels({ tr("setting"), tr("value") });
- treeWidget.setEditTriggers(QTreeWidget::NoEditTriggers);
- //connect(&treeWidget, &QTreeWidget::itemDoubleClicked, this, &SettingsDialog::editItem);
-
- for(const auto &option : config->options()) {
- auto *item = new QTreeWidgetItem(&treeWidget);
- item->setText(0, QString::fromStdString(option->long_name()));
- item->setText(1, QString::fromStdString(config->value<std::string>(option->long_name().c_str()).value_or(std::string())));
- item->setFlags(item->flags() | Qt::ItemIsEditable);
- }
-
- treeWidget.resizeColumnToContents(0);
-
- // connect signals
-// connect(saveAction, &QAction::triggered, this, [this]() {
-// write(configPath);
-// statusBar()->showMessage(tr("Configuration saved to: ") + configPath, 3000);
-// });
-
-// connect(saveAsAction, &QAction::triggered, this, [this]() {
-// QString path = QFileDialog::getSaveFileName(this, tr("Save Configuration"), configPath, tr("smolbote config (smolbote.cfg)"));
-// if(!path.isEmpty()) {
-// write(path);
-// statusBar()->showMessage(tr("Configuration saved to: ") + path, 3000);
-// }
-// });
-}
-
-SettingsDialog::~SettingsDialog()
-{
-// if(unsavedChanges)
-// write(configPath);
-}
-
-//void SettingsDialog::editItem(QTreeWidgetItem *item, int column)
-//{
-// if(column == 1) {
-// treeWidget.editItem(item, column);
-// unsavedChanges = true;
-
-// if(!windowTitle().endsWith('*')) {
-// setWindowTitle(windowTitle() + '*');
-// }
-// }
-//}
-
-//void SettingsDialog::write(const QString &path)
-//{
-// QFile output(path);
-// output.open(QIODevice::WriteOnly);
-
-// for(int i = 0; i < treeWidget.topLevelItemCount(); ++i) {
-// auto *item = treeWidget.topLevelItem(i);
-// output.write(QString(item->text(0) + " = " + item->text(1) + "\n").toUtf8());
-// }
-
-// output.close();
-
-// unsavedChanges = false;
-// setWindowTitle(configPath);
-//}
diff --git a/plugins/ConfigurationEditor/forms/settingsdialog.h b/plugins/ConfigurationEditor/forms/settingsdialog.h
deleted file mode 100644
index ed9e02d..0000000
--- a/plugins/ConfigurationEditor/forms/settingsdialog.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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/smolbote.hg
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#ifndef SMOLBOTE_SETTINGSDIALOG_H
-#define SMOLBOTE_SETTINGSDIALOG_H
-
-#include <QDialog>
-#include <QTreeWidget>
-
-class Configuration;
-class SettingsDialog : public QDialog
-{
- Q_OBJECT
-
-public:
- explicit SettingsDialog(Configuration *config, QWidget *parent = nullptr);
- ~SettingsDialog() override;
-
- QString configPath;
-
-public slots:
-// void editItem(QTreeWidgetItem *item, int column);
-// void write(const QString &path);
-
-private:
- QTreeWidget treeWidget;
- bool unsavedChanges = false;
-};
-
-#endif // SMOLBOTE_SETTINGSDIALOG_H