forked from Public-Mirror/Textractor
fix some geometry issues
This commit is contained in:
parent
6247a4ed35
commit
a9249111c0
@ -37,7 +37,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
connect(ui->ttCombo, (void(QComboBox::*)(int))&QComboBox::activated, this, &MainWindow::ViewThread);
|
connect(ui->ttCombo, (void(QComboBox::*)(int))&QComboBox::activated, this, &MainWindow::ViewThread);
|
||||||
|
|
||||||
QSettings settings(CONFIG_FILE, QSettings::IniFormat);
|
QSettings settings(CONFIG_FILE, QSettings::IniFormat);
|
||||||
setGeometry(settings.value(WINDOW, geometry()).toRect());
|
if (settings.contains(WINDOW)) setGeometry(settings.value(WINDOW).toRect());
|
||||||
TextThread::flushDelay = settings.value(FLUSH_DELAY, TextThread::flushDelay).toInt();
|
TextThread::flushDelay = settings.value(FLUSH_DELAY, TextThread::flushDelay).toInt();
|
||||||
TextThread::maxBufferSize = settings.value(MAX_BUFFER_SIZE, TextThread::maxBufferSize).toInt();
|
TextThread::maxBufferSize = settings.value(MAX_BUFFER_SIZE, TextThread::maxBufferSize).toInt();
|
||||||
Host::defaultCodepage = settings.value(DEFAULT_CODEPAGE, Host::defaultCodepage).toInt();
|
Host::defaultCodepage = settings.value(DEFAULT_CODEPAGE, Host::defaultCodepage).toInt();
|
||||||
|
@ -21,11 +21,15 @@ public:
|
|||||||
{
|
{
|
||||||
settings->beginGroup("Extra Window");
|
settings->beginGroup("Extra Window");
|
||||||
(new QHBoxLayout(this))->addWidget(display = new QLabel(EXTRA_WINDOW_INFO, this));
|
(new QHBoxLayout(this))->addWidget(display = new QLabel(EXTRA_WINDOW_INFO, this));
|
||||||
|
display->setTextFormat(Qt::PlainText);
|
||||||
|
display->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
||||||
display->setAlignment(Qt::AlignTop);
|
display->setAlignment(Qt::AlignTop);
|
||||||
display->setWordWrap(true);
|
display->setWordWrap(true);
|
||||||
|
display->setMaximumHeight(600);
|
||||||
setWindowFlags(Qt::FramelessWindowHint);
|
setWindowFlags(Qt::FramelessWindowHint);
|
||||||
setAttribute(Qt::WA_TranslucentBackground);
|
setAttribute(Qt::WA_TranslucentBackground);
|
||||||
setSizeGripEnabled(true);
|
setSizeGripEnabled(true);
|
||||||
|
resize(400, 1);
|
||||||
show();
|
show();
|
||||||
|
|
||||||
auto setBackgroundColor = [=](QColor color)
|
auto setBackgroundColor = [=](QColor color)
|
||||||
@ -62,15 +66,15 @@ public:
|
|||||||
setBackgroundColor(settings->value(BG_COLOR, palette().window().color()).value<QColor>());
|
setBackgroundColor(settings->value(BG_COLOR, palette().window().color()).value<QColor>());
|
||||||
setTextColor(settings->value(TEXT_COLOR, display->palette().windowText().color()).value<QColor>());
|
setTextColor(settings->value(TEXT_COLOR, display->palette().windowText().color()).value<QColor>());
|
||||||
|
|
||||||
auto menu = new QMenu(this);
|
auto menu = new QMenu(display);
|
||||||
auto topmost = menu->addAction(TOPMOST, setTopmost);
|
auto topmost = menu->addAction(TOPMOST, setTopmost);
|
||||||
topmost->setCheckable(true);
|
topmost->setCheckable(true);
|
||||||
topmost->setChecked(settings->value(TOPMOST).toBool());
|
topmost->setChecked(settings->value(TOPMOST, false).toBool());
|
||||||
menu->addAction(BG_COLOR, [=] { setBackgroundColor(QColorDialog::getColor(bgColor, this, BG_COLOR, QColorDialog::ShowAlphaChannel)); });
|
menu->addAction(BG_COLOR, [=] { setBackgroundColor(QColorDialog::getColor(bgColor, this, BG_COLOR, QColorDialog::ShowAlphaChannel)); });
|
||||||
menu->addAction(TEXT_COLOR, [=] { setTextColor(QColorDialog::getColor(display->palette().windowText().color(), this, TEXT_COLOR, QColorDialog::ShowAlphaChannel)); });
|
menu->addAction(TEXT_COLOR, [=] { setTextColor(QColorDialog::getColor(display->palette().windowText().color(), this, TEXT_COLOR, QColorDialog::ShowAlphaChannel)); });
|
||||||
menu->addAction(FONT_SIZE, [=] { setFontSize(QInputDialog::getInt(this, FONT_SIZE, "", display->font().pointSize(), 0, INT_MAX, 1, nullptr, Qt::WindowCloseButtonHint)); });
|
menu->addAction(FONT_SIZE, [=] { setFontSize(QInputDialog::getInt(this, FONT_SIZE, "", display->font().pointSize(), 0, INT_MAX, 1, nullptr, Qt::WindowCloseButtonHint)); });
|
||||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
display->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(this, &QDialog::customContextMenuRequested, menu, [=](QPoint point) { menu->exec(mapToGlobal(point)); });
|
connect(display, &QLabel::customContextMenuRequested, [=](QPoint point) { menu->exec(mapToGlobal(point)); });
|
||||||
connect(this, &QDialog::destroyed, [=] { settings->setValue(WINDOW, geometry()); });
|
connect(this, &QDialog::destroyed, [=] { settings->setValue(WINDOW, geometry()); });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,6 +87,12 @@ private:
|
|||||||
QPainter(this).fillRect(rect(), bgColor);
|
QPainter(this).fillRect(rect(), bgColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void resizeEvent(QResizeEvent* event) override
|
||||||
|
{
|
||||||
|
display->setMaximumWidth(event->size().width());
|
||||||
|
QDialog::resizeEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
void mousePressEvent(QMouseEvent* event)
|
void mousePressEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
oldPos = event->globalPos();
|
oldPos = event->globalPos();
|
||||||
@ -115,7 +125,11 @@ BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved
|
|||||||
case DLL_PROCESS_DETACH:
|
case DLL_PROCESS_DETACH:
|
||||||
{
|
{
|
||||||
std::lock_guard l(m);
|
std::lock_guard l(m);
|
||||||
if (window != nullptr) window->settings->setValue(WINDOW, window->geometry());
|
if (window != nullptr)
|
||||||
|
{
|
||||||
|
window->settings->setValue(WINDOW, window->geometry());
|
||||||
|
window->settings->sync();
|
||||||
|
}
|
||||||
if (lpReserved == NULL) // https://blogs.msdn.microsoft.com/oldnewthing/20120105-00/?p=8683
|
if (lpReserved == NULL) // https://blogs.msdn.microsoft.com/oldnewthing/20120105-00/?p=8683
|
||||||
{
|
{
|
||||||
delete window;
|
delete window;
|
||||||
|
@ -67,7 +67,8 @@ constexpr auto BING_PROMPT = u8"What language should Bing translate to?";
|
|||||||
constexpr auto GOOGLE_PROMPT = u8"What language should Google translate to?";
|
constexpr auto GOOGLE_PROMPT = u8"What language should Google translate to?";
|
||||||
constexpr auto TOO_MANY_TRANS_REQUESTS = L"\r\nToo many translation requests: refuse to make more";
|
constexpr auto TOO_MANY_TRANS_REQUESTS = L"\r\nToo many translation requests: refuse to make more";
|
||||||
constexpr auto TRANSLATION_ERROR = L"Error while translating";
|
constexpr auto TRANSLATION_ERROR = L"Error while translating";
|
||||||
constexpr auto EXTRA_WINDOW_INFO = u8"Right click to change settings";
|
constexpr auto EXTRA_WINDOW_INFO = u8"Right click to change settings\r\n"
|
||||||
|
u8"Click and drag on window edges to move, or the bottom right corner to resize";
|
||||||
constexpr auto BG_COLOR = u8"Background Color";
|
constexpr auto BG_COLOR = u8"Background Color";
|
||||||
constexpr auto TEXT_COLOR = u8"Text Color";
|
constexpr auto TEXT_COLOR = u8"Text Color";
|
||||||
constexpr auto FONT_SIZE = u8"Font Size";
|
constexpr auto FONT_SIZE = u8"Font Size";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user