diff --git a/GUI/CMakeLists.txt b/GUI/CMakeLists.txt index d164cce..fb5d05b 100644 --- a/GUI/CMakeLists.txt +++ b/GUI/CMakeLists.txt @@ -10,7 +10,6 @@ set(gui_SRCS mainwindow.cpp misc.cpp extenwindow.cpp - setdialog.cpp tests.cpp host/host.cpp host/textthread.cpp diff --git a/GUI/extenwindow.cpp b/GUI/extenwindow.cpp index b60be4f..bea793e 100644 --- a/GUI/extenwindow.cpp +++ b/GUI/extenwindow.cpp @@ -5,9 +5,12 @@ #include "types.h" #include "misc.h" #include +#include +#include #include #include #include +#include namespace { @@ -76,16 +79,15 @@ bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_mapsetupUi(this); + ui->vboxLayout->addWidget(new QLabel(EXTEN_WINDOW_INSTRUCTIONS, this)); + setWindowTitle(EXTENSIONS); ui->extenList->installEventFilter(this); - connect(ui->addButton, &QPushButton::clicked, [this] { Add(QFileDialog::getOpenFileName(this, SELECT_EXTENSION, "C:\\", EXTENSION_FILES)); }); - connect(ui->rmvButton, &QPushButton::clicked, [this] { if (auto extenName = ui->extenList->currentItem()) Unload(extenName->text()); Sync(); }); - for (auto extenName : QString(QAutoFile(EXTEN_SAVE_FILE, QIODevice::ReadOnly)->readAll()).split(">")) Load(extenName); Sync(); } @@ -128,6 +130,15 @@ bool ExtenWindow::eventFilter(QObject* target, QEvent* event) return false; } +void ExtenWindow::keyPressEvent(QKeyEvent* event) +{ + if (event->key() == Qt::Key_Delete) if (auto extenName = ui->extenList->currentItem()) + { + Unload(extenName->text()); + Sync(); + } +} + void ExtenWindow::dragEnterEvent(QDragEnterEvent* event) { event->acceptProposedAction(); diff --git a/GUI/extenwindow.h b/GUI/extenwindow.h index 921dc52..bc06ca6 100644 --- a/GUI/extenwindow.h +++ b/GUI/extenwindow.h @@ -1,8 +1,6 @@ #pragma once #include "qtcommon.h" -#include -#include namespace Ui { @@ -21,6 +19,7 @@ private: void Add(QFileInfo extenFile); void Sync(); bool eventFilter(QObject* target, QEvent* event) override; + void keyPressEvent(QKeyEvent* event) override; void dragEnterEvent(QDragEnterEvent* event) override; void dropEvent(QDropEvent* event) override; diff --git a/GUI/extenwindow.ui b/GUI/extenwindow.ui index b1ae569..a28e5c5 100644 --- a/GUI/extenwindow.ui +++ b/GUI/extenwindow.ui @@ -13,11 +13,8 @@ true - - Extensions - - - + + @@ -28,42 +25,9 @@ - - - - - - Qt::Vertical - - - - - - - Add - - - - - - - Remove - - - - - - - Qt::Vertical - - - - - - diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 8372f31..7de0950 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -3,12 +3,13 @@ #include "defs.h" #include "text.h" #include "extenwindow.h" -#include "setdialog.h" #include "misc.h" #include "host/util.h" #include #include +#include #include +#include #include MainWindow::MainWindow(QWidget *parent) : @@ -231,7 +232,34 @@ void MainWindow::SaveHooks() void MainWindow::Settings() { - SetDialog(this).exec(); + struct : QDialog + { + using QDialog::QDialog; + void launch() + { + auto settings = new QSettings(CONFIG_FILE, QSettings::IniFormat, this); + auto layout = new QFormLayout(this); + auto save = new QPushButton(this); + save->setText(SAVE_SETTINGS); + layout->addWidget(save); + for (auto[value, label] : Array>{ + { TextThread::defaultCodepage, DEFAULT_CODEPAGE }, + { TextThread::maxBufferSize, MAX_BUFFER_SIZE }, + { TextThread::flushDelay, FLUSH_DELAY }, + }) + { + auto spinBox = new QSpinBox(this); + spinBox->setMaximum(INT_MAX); + spinBox->setValue(value); + layout->insertRow(0, label, spinBox); + connect(save, &QPushButton::clicked, [=, &value] { settings->setValue(label, value = spinBox->value()); settings->sync(); }); + } + connect(save, &QPushButton::clicked, this, &QDialog::accept); + setWindowTitle(SETTINGS); + exec(); + } + } settingsDialog(this, Qt::WindowCloseButtonHint); + settingsDialog.launch(); } void MainWindow::Extensions() diff --git a/GUI/setdialog.cpp b/GUI/setdialog.cpp deleted file mode 100644 index 01d9688..0000000 --- a/GUI/setdialog.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "setdialog.h" -#include "ui_setdialog.h" -#include "defs.h" -#include "text.h" -#include "host/host.h" - -SetDialog::SetDialog(QWidget* parent) : - QDialog(parent, Qt::WindowCloseButtonHint), - ui(new Ui::SetDialog) -{ - ui->setupUi(this); - for (auto[spinBox, value, label] : Array>{ - { flushDelay, TextThread::flushDelay, FLUSH_DELAY }, - { maxBufferSize, TextThread::maxBufferSize, MAX_BUFFER_SIZE }, - { defaultCodepage, TextThread::defaultCodepage, DEFAULT_CODEPAGE } - }) - { - spinBox = new QSpinBox(this); - spinBox->setMaximum(INT_MAX); - spinBox->setValue(value); - ui->layout->insertRow(0, label, spinBox); - } - - connect(ui->buttonBox, &QDialogButtonBox::accepted, [this] { edited = true; }); -} - -SetDialog::~SetDialog() -{ - if (edited) - { - QSettings settings(CONFIG_FILE, QSettings::IniFormat); - settings.setValue(FLUSH_DELAY, TextThread::flushDelay = flushDelay->value()); - settings.setValue(MAX_BUFFER_SIZE, TextThread::maxBufferSize = maxBufferSize->value()); - settings.setValue(DEFAULT_CODEPAGE, TextThread::defaultCodepage = defaultCodepage->value()); - settings.sync(); - } - delete ui; -} diff --git a/GUI/setdialog.h b/GUI/setdialog.h deleted file mode 100644 index 4f56c22..0000000 --- a/GUI/setdialog.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "qtcommon.h" -#include - -namespace Ui -{ - class SetDialog; -} - -class SetDialog : public QDialog -{ -public: - explicit SetDialog(QWidget* parent = nullptr); - ~SetDialog(); - -private: - Ui::SetDialog* ui; - QSpinBox* flushDelay; - QSpinBox* maxBufferSize; - QSpinBox* defaultCodepage; - bool edited = false; -}; diff --git a/GUI/setdialog.ui b/GUI/setdialog.ui deleted file mode 100644 index f7cd03f..0000000 --- a/GUI/setdialog.ui +++ /dev/null @@ -1,44 +0,0 @@ - - - SetDialog - - - - 0 - 0 - 300 - 120 - - - - Settings - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - SetDialog - accept() - - - buttonBox - rejected() - SetDialog - reject() - - - diff --git a/extensions/regexfilter.cpp b/extensions/regexfilter.cpp index e467f1f..370bf6e 100644 --- a/extensions/regexfilter.cpp +++ b/extensions/regexfilter.cpp @@ -9,7 +9,8 @@ std::wregex regex; std::mutex m; -struct : QMainWindow { +struct : QMainWindow +{ void Initialize() { auto centralWidget = new QWidget(this); @@ -26,10 +27,10 @@ struct : QMainWindow { catch (...) { return output->setText(INVALID_REGEX); } output->setText(CURRENT_FILTER + newRegex); }); - QMainWindow::resize(350, 60); - QMainWindow::setCentralWidget(centralWidget); - QMainWindow::setWindowTitle(REGEX_FILTER); - QMainWindow::show(); + resize(350, 60); + setCentralWidget(centralWidget); + setWindowTitle(REGEX_FILTER); + show(); } }*window = nullptr; diff --git a/include/text.h b/include/text.h index dfc1e0e..b064e31 100644 --- a/include/text.h +++ b/include/text.h @@ -25,10 +25,10 @@ u8"S/Q/V: Shift-JIS/UTF-16/UTF-8 string\r\n" u8"Negatives for data_offset/sub_offset refer to registers\r\n" u8"-4 for EAX, -8 for ECX, -C for EDX, -10 for EBX, -14 for ESP, -18 for EBP, -1C for ESI, -20 for EDI\r\n" u8"* means dereference pointer+deref_offset"; -constexpr auto UNHOOK = u8"Unhook"; -constexpr auto REMOVE_HOOK = u8"Which hook to remove?"; -constexpr auto SELECT_EXTENSION = u8"Select Extension"; -constexpr auto EXTENSION_FILES = u8"Extensions (*.dll)"; +constexpr auto SAVE_SETTINGS = u8"Save settings"; +constexpr auto EXTEN_WINDOW_INSTRUCTIONS = u8"Drag and drop extensions (.dll files) here to add them\r\n" +u8"Press delete with an extension selected to remove it\r\n" +u8"Drag and drop extensions to rearrange them"; constexpr auto WINDOW = u8"Window"; constexpr auto DEFAULT_CODEPAGE = u8"Default Codepage"; constexpr auto FLUSH_DELAY = u8"Flush Delay";