forked from Public-Mirror/Textractor
use qfontdialog for extra and main window and massive perf improvement when loading large threads
This commit is contained in:
parent
f56e9ff07c
commit
6a015f04bc
@ -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();
|
||||
}
|
||||
|
@ -3,8 +3,10 @@
|
||||
#include "defs.h"
|
||||
#include "host/util.h"
|
||||
#include <shellapi.h>
|
||||
#include <QMenu>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QFileDialog>
|
||||
#include <QFontDialog>
|
||||
|
||||
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<int>(&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();
|
||||
@ -206,6 +211,13 @@ bool MainWindow::SentenceReceived(TextThread& thread, std::wstring& sentence)
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainWindow::OutputContextMenu(QPoint point)
|
||||
{
|
||||
std::unique_ptr<QMenu> 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(
|
||||
@ -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());
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -15,14 +15,6 @@
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">
|
||||
QObject
|
||||
{
|
||||
font: 10pt "MS Shell Dlg 2";
|
||||
}
|
||||
#textOutput
|
||||
{
|
||||
font: 13pt "MS Shell Dlg 2";
|
||||
}
|
||||
QPushButton, QComboBox
|
||||
{
|
||||
padding-top: 3px;
|
||||
@ -83,6 +75,15 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="textOutput">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Meiryo</family>
|
||||
<pointsize>12</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "ui_extrawindow.h"
|
||||
#include "defs.h"
|
||||
#include <QColorDialog>
|
||||
#include <QFontDialog>
|
||||
#include <QMenu>
|
||||
#include <QPainter>
|
||||
#include <QMouseEvent>
|
||||
@ -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());
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user