From 6a015f04bcb87055462a7545d27f798d843968b8 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sat, 13 Jul 2019 19:15:43 +0530 Subject: [PATCH] use qfontdialog for extra and main window and massive perf improvement when loading large threads --- GUI/main.cpp | 1 + GUI/mainwindow.cpp | 25 +++++++++++++++++++++++-- GUI/mainwindow.h | 2 ++ GUI/mainwindow.ui | 23 ++++++++++++----------- extensions/extrawindow.cpp | 31 ++++++++----------------------- 5 files changed, 46 insertions(+), 36 deletions(-) diff --git a/GUI/main.cpp b/GUI/main.cpp index 07e8c62..7a9a092 100644 --- a/GUI/main.cpp +++ b/GUI/main.cpp @@ -26,5 +26,6 @@ int main(int argc, char *argv[]) QDir::setCurrent(QFileInfo(S(Util::GetModuleFilename().value())).absolutePath()); QApplication app(argc, argv); + app.setFont(QFont("MS Shell Dlg 2", 10)); return MainWindow().show(), app.exec(); } diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index b0bd1df..492335f 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -3,8 +3,10 @@ #include "defs.h" #include "host/util.h" #include +#include #include #include +#include extern const char* ATTACH; extern const char* LAUNCH; @@ -16,6 +18,7 @@ extern const char* SAVE_HOOKS; extern const char* SEARCH_FOR_HOOKS; extern const char* SETTINGS; extern const char* EXTENSIONS; +extern const char* FONT; extern const char* SELECT_PROCESS; extern const char* ATTACH_INFO; extern const char* SELECT_PROCESS_INFO; @@ -75,9 +78,11 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->ttCombo, qOverload(&QComboBox::activated), this, &MainWindow::ViewThread); connect(ui->textOutput, &QPlainTextEdit::selectionChanged, [this] { if (!(QApplication::mouseButtons() & Qt::LeftButton)) ui->textOutput->copy(); }); + connect(ui->textOutput, &QPlainTextEdit::customContextMenuRequested, this, &MainWindow::OutputContextMenu); QSettings settings(CONFIG_FILE, QSettings::IniFormat); if (settings.contains(WINDOW)) setGeometry(settings.value(WINDOW).toRect()); + if (settings.contains(FONT)) SetOutputFont(settings.value(FONT).toString()); TextThread::filterRepetition = settings.value(FILTER_REPETITION, TextThread::filterRepetition).toBool(); autoAttach = settings.value(AUTO_ATTACH, autoAttach).toBool(); autoAttachSavedOnly = settings.value(ATTACH_SAVED_ONLY, autoAttachSavedOnly).toBool(); @@ -172,7 +177,7 @@ void MainWindow::ProcessDisconnected(DWORD processId) void MainWindow::ThreadAdded(TextThread& thread) { std::wstring threadCode = Util::GenerateCode(thread.hp, thread.tp.processId); - QString ttString = TextThreadString(thread) + S(FormatString(L"(%s)", threadCode)); + QString ttString = TextThreadString(thread) + S(FormatString(L" (%s)", threadCode)); bool savedMatch = savedThreadCtx == thread.tp.ctx && savedThreadCtx2 == thread.tp.ctx2 && savedThreadCode == threadCode; if (savedMatch) savedThreadCtx = savedThreadCtx2 = savedThreadCode[0] = 0; QMetaObject::invokeMethod(this, [this, ttString, savedMatch] @@ -206,9 +211,16 @@ bool MainWindow::SentenceReceived(TextThread& thread, std::wstring& sentence) return true; } +void MainWindow::OutputContextMenu(QPoint point) +{ + std::unique_ptr menu(ui->textOutput->createStandardContextMenu()); + menu->addAction(FONT, [this] { if (QString font = QFontDialog::getFont(&ok, ui->textOutput->font(), this, FONT).toString(); ok) SetOutputFont(font); }); + menu->exec(ui->textOutput->mapToGlobal(point)); +} + QString MainWindow::TextThreadString(TextThread& thread) { - return QString("%1:%2:%3:%4:%5: %6 ").arg( + return QString("%1:%2:%3:%4:%5: %6").arg( QString::number(thread.handle, 16), QString::number(thread.tp.processId, 16), QString::number(thread.tp.addr, 16), @@ -521,3 +533,12 @@ void MainWindow::ViewThread(int index) ui->textOutput->setPlainText(S((current = &Host::GetThread(ParseTextThreadString(ui->ttCombo->itemText(index))))->storage->c_str())); ui->textOutput->moveCursor(QTextCursor::End); } + +void MainWindow::SetOutputFont(QString fontString) +{ + QFont font = ui->textOutput->font(); + font.fromString(fontString); + font.setStyleStrategy(QFont::NoFontMerging); + ui->textOutput->setFont(font); + QSettings(CONFIG_FILE, QSettings::IniFormat).setValue(FONT, font.toString()); +} diff --git a/GUI/mainwindow.h b/GUI/mainwindow.h index d72fbcd..7d2bcb9 100644 --- a/GUI/mainwindow.h +++ b/GUI/mainwindow.h @@ -27,6 +27,7 @@ private: void ThreadAdded(TextThread& thread); void ThreadRemoved(TextThread& thread); bool SentenceReceived(TextThread& thread, std::wstring& sentence); + void OutputContextMenu(QPoint point); QString TextThreadString(TextThread& thread); ThreadParam ParseTextThreadString(QString ttString); DWORD GetSelectedProcessId(); @@ -43,6 +44,7 @@ private: void Settings(); void Extensions(); void ViewThread(int index); + void SetOutputFont(QString font); Ui::MainWindow* ui; ExtenWindow* extenWindow; diff --git a/GUI/mainwindow.ui b/GUI/mainwindow.ui index 6cf2e48..e5e16d2 100644 --- a/GUI/mainwindow.ui +++ b/GUI/mainwindow.ui @@ -13,16 +13,8 @@ Textractor - - - QObject - { - font: 10pt "MS Shell Dlg 2"; - } - #textOutput - { - font: 13pt "MS Shell Dlg 2"; - } + + QPushButton, QComboBox { padding-top: 3px; @@ -32,7 +24,7 @@ text-align: left; } - + @@ -83,6 +75,15 @@ + + Qt::CustomContextMenu + + + + Meiryo + 12 + + true diff --git a/extensions/extrawindow.cpp b/extensions/extrawindow.cpp index 36d36eb..5cd89e5 100644 --- a/extensions/extrawindow.cpp +++ b/extensions/extrawindow.cpp @@ -3,6 +3,7 @@ #include "ui_extrawindow.h" #include "defs.h" #include +#include #include #include #include @@ -15,9 +16,6 @@ extern const char* SIZE_LOCK; extern const char* BG_COLOR; extern const char* TEXT_COLOR; extern const char* FONT; -extern const char* FONT_SIZE; -extern const char* FONT_FAMILY; -extern const char* FONT_WEIGHT; extern const char* SAVE_SETTINGS; struct Window : QDialog @@ -73,25 +71,12 @@ public: private: void RequestFont() { - QFont font = ui.display->font(); - QDialog fontDialog(this, Qt::WindowCloseButtonHint); - fontDialog.setWindowTitle(FONT); - QFormLayout layout(&fontDialog); - QLineEdit fontFamily(font.family(), &fontDialog); - layout.addRow(FONT_FAMILY, &fontFamily); - QSpinBox fontSize(&fontDialog); - fontSize.setValue(font.pointSize()); - layout.addRow(FONT_SIZE, &fontSize); - QSpinBox fontWeight(&fontDialog); - fontWeight.setValue(font.weight()); - layout.addRow(FONT_WEIGHT, &fontWeight); - QPushButton save(SAVE_SETTINGS, &fontDialog); - layout.addWidget(&save); - connect(&save, &QPushButton::clicked, &fontDialog, &QDialog::accept); - if (!fontDialog.exec()) return; - font = QFont(fontFamily.text(), fontSize.value(), fontWeight.value()); - settings.setValue(FONT, font.toString()); - ui.display->setFont(font); + bool ok; + if (QFont font = QFontDialog::getFont(&ok, ui.display->font(), this, FONT); ok) + { + settings.setValue(FONT, font.toString()); + ui.display->setFont(font); + } }; void setBackgroundColor(QColor color) @@ -159,7 +144,7 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) if (!sentenceInfo["current select"]) return false; QString qSentence = S(sentence); - if (!window.settings.value(SHOW_ORIGINAL).toBool()) qSentence = qSentence.section('\n', qSentence.count('\n') / 2 + 1); + if (!window.settings.value(SHOW_ORIGINAL, true).toBool()) qSentence = qSentence.section('\n', qSentence.count('\n') / 2 + 1); QMetaObject::invokeMethod(&window, [=] { window.ui.display->setText(qSentence); }); return false;