move more text into include/text.h and make a better ux for extenwindow and misc refactors

This commit is contained in:
Akash Mozumdar 2018-12-21 14:18:43 -05:00
parent afea96e9d5
commit 7015ef0c53
10 changed files with 58 additions and 161 deletions

View File

@ -10,7 +10,6 @@ set(gui_SRCS
mainwindow.cpp mainwindow.cpp
misc.cpp misc.cpp
extenwindow.cpp extenwindow.cpp
setdialog.cpp
tests.cpp tests.cpp
host/host.cpp host/host.cpp
host/textthread.cpp host/textthread.cpp

View File

@ -5,9 +5,12 @@
#include "types.h" #include "types.h"
#include "misc.h" #include "misc.h"
#include <shared_mutex> #include <shared_mutex>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QFileDialog> #include <QFileDialog>
#include <QMimeData> #include <QMimeData>
#include <QUrl> #include <QUrl>
#include <QLabel>
namespace namespace
{ {
@ -76,16 +79,15 @@ bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map<std
} }
ExtenWindow::ExtenWindow(QWidget* parent) : ExtenWindow::ExtenWindow(QWidget* parent) :
QMainWindow(parent), QMainWindow(parent, Qt::WindowCloseButtonHint),
ui(new Ui::ExtenWindow) ui(new Ui::ExtenWindow)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->vboxLayout->addWidget(new QLabel(EXTEN_WINDOW_INSTRUCTIONS, this));
setWindowTitle(EXTENSIONS);
ui->extenList->installEventFilter(this); 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); for (auto extenName : QString(QAutoFile(EXTEN_SAVE_FILE, QIODevice::ReadOnly)->readAll()).split(">")) Load(extenName);
Sync(); Sync();
} }
@ -128,6 +130,15 @@ bool ExtenWindow::eventFilter(QObject* target, QEvent* event)
return false; 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) void ExtenWindow::dragEnterEvent(QDragEnterEvent* event)
{ {
event->acceptProposedAction(); event->acceptProposedAction();

View File

@ -1,8 +1,6 @@
#pragma once #pragma once
#include "qtcommon.h" #include "qtcommon.h"
#include <QDragEnterEvent>
#include <QDropEvent>
namespace Ui namespace Ui
{ {
@ -21,6 +19,7 @@ private:
void Add(QFileInfo extenFile); void Add(QFileInfo extenFile);
void Sync(); void Sync();
bool eventFilter(QObject* target, QEvent* event) override; bool eventFilter(QObject* target, QEvent* event) override;
void keyPressEvent(QKeyEvent* event) override;
void dragEnterEvent(QDragEnterEvent* event) override; void dragEnterEvent(QDragEnterEvent* event) override;
void dropEvent(QDropEvent* event) override; void dropEvent(QDropEvent* event) override;

View File

@ -13,11 +13,8 @@
<property name="acceptDrops"> <property name="acceptDrops">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="windowTitle"> <widget class="QWidget">
<string>Extensions</string> <layout class="QVBoxLayout">
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QListWidget" name="extenList"> <widget class="QListWidget" name="extenList">
<property name="dragDropMode"> <property name="dragDropMode">
@ -28,42 +25,9 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<layout class="QVBoxLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="addButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="rmvButton">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</spacer>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
<layoutdefault spacing="6" margin="6"/>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -3,12 +3,13 @@
#include "defs.h" #include "defs.h"
#include "text.h" #include "text.h"
#include "extenwindow.h" #include "extenwindow.h"
#include "setdialog.h"
#include "misc.h" #include "misc.h"
#include "host/util.h" #include "host/util.h"
#include <Psapi.h> #include <Psapi.h>
#include <winhttp.h> #include <winhttp.h>
#include <QFormLayout>
#include <QPushButton> #include <QPushButton>
#include <QSpinBox>
#include <QInputDialog> #include <QInputDialog>
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :
@ -231,7 +232,34 @@ void MainWindow::SaveHooks()
void MainWindow::Settings() 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<std::tuple<int&, const char*>>{
{ 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() void MainWindow::Extensions()

View File

@ -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<std::tuple<QSpinBox*&, int, const char*>>{
{ 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;
}

View File

@ -1,23 +0,0 @@
#pragma once
#include "qtcommon.h"
#include <QSpinBox>
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;
};

View File

@ -1,44 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SetDialog</class>
<widget class="QDialog" name="SetDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>120</height>
</rect>
</property>
<property name="windowTitle">
<string>Settings</string>
</property>
<layout class="QFormLayout" name="layout">
<item row="0" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>SetDialog</receiver>
<slot>accept()</slot>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>SetDialog</receiver>
<slot>reject()</slot>
</connection>
</connections>
</ui>

View File

@ -9,7 +9,8 @@
std::wregex regex; std::wregex regex;
std::mutex m; std::mutex m;
struct : QMainWindow { struct : QMainWindow
{
void Initialize() void Initialize()
{ {
auto centralWidget = new QWidget(this); auto centralWidget = new QWidget(this);
@ -26,10 +27,10 @@ struct : QMainWindow {
catch (...) { return output->setText(INVALID_REGEX); } catch (...) { return output->setText(INVALID_REGEX); }
output->setText(CURRENT_FILTER + newRegex); output->setText(CURRENT_FILTER + newRegex);
}); });
QMainWindow::resize(350, 60); resize(350, 60);
QMainWindow::setCentralWidget(centralWidget); setCentralWidget(centralWidget);
QMainWindow::setWindowTitle(REGEX_FILTER); setWindowTitle(REGEX_FILTER);
QMainWindow::show(); show();
} }
}*window = nullptr; }*window = nullptr;

View File

@ -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"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"-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"; u8"* means dereference pointer+deref_offset";
constexpr auto UNHOOK = u8"Unhook"; constexpr auto SAVE_SETTINGS = u8"Save settings";
constexpr auto REMOVE_HOOK = u8"Which hook to remove?"; constexpr auto EXTEN_WINDOW_INSTRUCTIONS = u8"Drag and drop extensions (.dll files) here to add them\r\n"
constexpr auto SELECT_EXTENSION = u8"Select Extension"; u8"Press delete with an extension selected to remove it\r\n"
constexpr auto EXTENSION_FILES = u8"Extensions (*.dll)"; u8"Drag and drop extensions to rearrange them";
constexpr auto WINDOW = u8"Window"; constexpr auto WINDOW = u8"Window";
constexpr auto DEFAULT_CODEPAGE = u8"Default Codepage"; constexpr auto DEFAULT_CODEPAGE = u8"Default Codepage";
constexpr auto FLUSH_DELAY = u8"Flush Delay"; constexpr auto FLUSH_DELAY = u8"Flush Delay";