From a9249111c08b760571a71bb0d5eed06495b03cfd Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sun, 6 Jan 2019 00:07:20 -0500 Subject: [PATCH] fix some geometry issues --- GUI/mainwindow.cpp | 2 +- extensions/extrawindow.cpp | 24 +++++++++++++++++++----- include/text.h | 3 ++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index c0423d1..b03595e 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -37,7 +37,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->ttCombo, (void(QComboBox::*)(int))&QComboBox::activated, this, &MainWindow::ViewThread); 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::maxBufferSize = settings.value(MAX_BUFFER_SIZE, TextThread::maxBufferSize).toInt(); Host::defaultCodepage = settings.value(DEFAULT_CODEPAGE, Host::defaultCodepage).toInt(); diff --git a/extensions/extrawindow.cpp b/extensions/extrawindow.cpp index 7f26eeb..de696bd 100644 --- a/extensions/extrawindow.cpp +++ b/extensions/extrawindow.cpp @@ -21,11 +21,15 @@ public: { settings->beginGroup("Extra Window"); (new QHBoxLayout(this))->addWidget(display = new QLabel(EXTRA_WINDOW_INFO, this)); + display->setTextFormat(Qt::PlainText); + display->setTextInteractionFlags(Qt::TextSelectableByMouse); display->setAlignment(Qt::AlignTop); display->setWordWrap(true); + display->setMaximumHeight(600); setWindowFlags(Qt::FramelessWindowHint); setAttribute(Qt::WA_TranslucentBackground); setSizeGripEnabled(true); + resize(400, 1); show(); auto setBackgroundColor = [=](QColor color) @@ -62,15 +66,15 @@ public: setBackgroundColor(settings->value(BG_COLOR, palette().window().color()).value()); setTextColor(settings->value(TEXT_COLOR, display->palette().windowText().color()).value()); - auto menu = new QMenu(this); + auto menu = new QMenu(display); auto topmost = menu->addAction(TOPMOST, setTopmost); 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(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)); }); - setContextMenuPolicy(Qt::CustomContextMenu); - connect(this, &QDialog::customContextMenuRequested, menu, [=](QPoint point) { menu->exec(mapToGlobal(point)); }); + display->setContextMenuPolicy(Qt::CustomContextMenu); + connect(display, &QLabel::customContextMenuRequested, [=](QPoint point) { menu->exec(mapToGlobal(point)); }); connect(this, &QDialog::destroyed, [=] { settings->setValue(WINDOW, geometry()); }); } @@ -83,6 +87,12 @@ private: QPainter(this).fillRect(rect(), bgColor); } + void resizeEvent(QResizeEvent* event) override + { + display->setMaximumWidth(event->size().width()); + QDialog::resizeEvent(event); + } + void mousePressEvent(QMouseEvent* event) { oldPos = event->globalPos(); @@ -115,7 +125,11 @@ BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved case DLL_PROCESS_DETACH: { 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 { delete window; diff --git a/include/text.h b/include/text.h index 5adab6e..b520126 100644 --- a/include/text.h +++ b/include/text.h @@ -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 TOO_MANY_TRANS_REQUESTS = L"\r\nToo many translation requests: refuse to make more"; 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 TEXT_COLOR = u8"Text Color"; constexpr auto FONT_SIZE = u8"Font Size";