From 0ee4e7e444074833dc3f092391f8362e0c392289 Mon Sep 17 00:00:00 2001 From: jw098 Date: Thu, 26 Jun 2025 22:40:07 -0700 Subject: [PATCH 1/6] Default size, position for Output Window --- .../CommonFramework/GlobalSettingsPanel.cpp | 17 +++++++++++- .../CommonFramework/GlobalSettingsPanel.h | 2 ++ .../Logging/FileWindowLogger.cpp | 14 +++++++++- .../Logging/FileWindowLogger.h | 2 ++ .../Options/ResolutionOption.cpp | 10 ++++++- .../Options/ResolutionOption.h | 5 +++- .../CommonFramework/Windows/MainWindow.cpp | 26 ++++++++++++++++--- 7 files changed, 68 insertions(+), 8 deletions(-) diff --git a/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp b/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp index 1a26fe6cfd..f89603a855 100644 --- a/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp +++ b/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp @@ -133,7 +133,20 @@ GlobalSettings::GlobalSettings() "Window Size:", "Set the size of the window. Takes effect immediately.
" "Use this to easily set the window to a specific resolution for streaming alignment.", - 1280, 1000 + 1280, 1000, + 0, 0 + ) + , LOG_WINDOW_SIZE( + CONSTRUCT_TOKEN, + "Output Window Size:", + "Set the initial size of the output window. Takes effect after restart.
", + 600, 1200, + 0, 0 + ) + , LOG_WINDOW_STARTUP( + "Open Output Window at startup:", + LockMode::UNLOCK_WHILE_RUNNING, + false ) , STREAM_HISTORY(CONSTRUCT_TOKEN) , SLEEP_SUPPRESS(CONSTRUCT_TOKEN) @@ -196,6 +209,8 @@ GlobalSettings::GlobalSettings() PA_ADD_OPTION(TEMP_FOLDER); PA_ADD_OPTION(THEME); PA_ADD_OPTION(WINDOW_SIZE); + PA_ADD_OPTION(LOG_WINDOW_SIZE); + PA_ADD_OPTION(LOG_WINDOW_STARTUP); #if (QT_VERSION_MAJOR == 6) && (QT_VERSION_MINOR >= 8) if (IS_BETA_VERSION || PreloadSettings::instance().DEVELOPER_MODE){ PA_ADD_OPTION(STREAM_HISTORY); diff --git a/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h b/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h index 28330ff3c8..fcec0f2a9d 100644 --- a/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h +++ b/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h @@ -96,6 +96,8 @@ class GlobalSettings : public BatchOption, private ConfigOption::Listener{ Pimpl THEME; Pimpl WINDOW_SIZE; + Pimpl LOG_WINDOW_SIZE; + BooleanCheckBoxOption LOG_WINDOW_STARTUP; Pimpl STREAM_HISTORY; Pimpl SLEEP_SUPPRESS; diff --git a/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp b/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp index 47600c9b46..b8e1be5f6a 100644 --- a/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp +++ b/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp @@ -8,8 +8,10 @@ #include #include #include "CommonFramework/Globals.h" +#include "CommonFramework/GlobalSettingsPanel.h" #include "CommonFramework/Windows/DpiScaler.h" #include "CommonFramework/Windows/WindowTracker.h" +#include "CommonFramework/Options/ResolutionOption.h" #include "FileWindowLogger.h" //#include @@ -212,7 +214,9 @@ FileWindowLoggerWindow::FileWindowLoggerWindow(FileWindowLogger& logger, QWidget if (objectName().isEmpty()){ setObjectName(QString::fromUtf8("TextWindow")); } - resize(scale_dpi_width(1200), scale_dpi_height(600)); + uint32_t width = GlobalSettings::instance().LOG_WINDOW_SIZE->WIDTH; + uint32_t height = GlobalSettings::instance().LOG_WINDOW_SIZE->HEIGHT; + resize(scale_dpi_width(width), scale_dpi_height(height)); m_text = new QTextEdit(this); m_text->setObjectName(QString::fromUtf8("centralwidget")); setCentralWidget(m_text); @@ -255,6 +259,14 @@ void FileWindowLoggerWindow::log(QString msg){ emit signal_log(msg); } +void FileWindowLoggerWindow::resizeEvent(QResizeEvent* event){ + m_pending_resize = true; + GlobalSettings::instance().LOG_WINDOW_SIZE->WIDTH.set(width()); + GlobalSettings::instance().LOG_WINDOW_SIZE->HEIGHT.set(height()); + m_pending_resize = false; +} + + diff --git a/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.h b/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.h index cc9e38ba6d..2ce1ed9219 100644 --- a/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.h +++ b/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.h @@ -80,6 +80,7 @@ class FileWindowLoggerWindow : public QMainWindow{ virtual ~FileWindowLoggerWindow(); void log(QString msg); + virtual void resizeEvent(QResizeEvent* event) override; signals: void signal_log(QString msg); @@ -88,6 +89,7 @@ class FileWindowLoggerWindow : public QMainWindow{ FileWindowLogger& m_logger; QMenuBar* m_menubar; QTextEdit* m_text; + bool m_pending_resize = false; }; diff --git a/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp b/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp index f0c94428fa..7e03ddd044 100644 --- a/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp +++ b/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp @@ -4,6 +4,7 @@ * */ +#include "CommonFramework/GlobalSettingsPanel.h" #include "CommonFramework/Windows/DpiScaler.h" #include "ResolutionOption.h" @@ -12,16 +13,23 @@ namespace PokemonAutomation{ ResolutionOption::ResolutionOption( std::string label, std::string description, - int default_width, int default_height + int default_width, int default_height, + int initial_x_pos, int initial_y_pos ) : GroupOption(std::move(label), LockMode::LOCK_WHILE_RUNNING) , DESCRIPTION(std::move(description)) , WIDTH("Width:", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(default_width)) , HEIGHT("Height:", LockMode::LOCK_WHILE_RUNNING, scale_dpi_height(default_height)) + , INITIAL_X_POS("Initial X position:", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(initial_x_pos)) + , INITIAL_Y_POS("Initial Y position:", LockMode::LOCK_WHILE_RUNNING, scale_dpi_height(initial_y_pos)) { PA_ADD_STATIC(DESCRIPTION); PA_ADD_OPTION(WIDTH); PA_ADD_OPTION(HEIGHT); + if (PreloadSettings::instance().DEVELOPER_MODE){ + PA_ADD_OPTION(INITIAL_X_POS); + PA_ADD_OPTION(INITIAL_Y_POS); + } } diff --git a/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.h b/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.h index 4de2ee091a..2c41fc2c30 100644 --- a/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.h +++ b/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.h @@ -18,12 +18,15 @@ class ResolutionOption : public GroupOption{ public: ResolutionOption( std::string label, std::string description, - int default_width, int default_height + int default_width, int default_height, + int initial_x_pos, int initial_y_pos ); StaticTextOption DESCRIPTION; SimpleIntegerOption WIDTH; SimpleIntegerOption HEIGHT; + SimpleIntegerOption INITIAL_X_POS; + SimpleIntegerOption INITIAL_Y_POS; }; diff --git a/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp b/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp index fd61620534..3d573ae0f2 100644 --- a/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp +++ b/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp @@ -20,6 +20,7 @@ #include "CommonFramework/Startup/NewVersionCheck.h" #include "CommonFramework/Options/ResolutionOption.h" #include "CommonFramework/Options/Environment/ThemeSelectorOption.h" +#include "CommonFramework/Windows/DpiScaler.h" #include "PanelLists.h" #include "WindowTracker.h" #include "ButtonDiagram.h" @@ -201,14 +202,31 @@ MainWindow::MainWindow(QWidget* parent) m_output_window.reset(new FileWindowLoggerWindow((FileWindowLogger&)global_logger_raw())); QPushButton* output = new QPushButton("Output Window", support_box); buttons->addWidget(output); + auto show_output_window = [&](){ + m_output_window->show(); + m_output_window->raise(); // bring the window to front on macOS + m_output_window->activateWindow(); // bring the window to front on Windows + }; connect( output, &QPushButton::clicked, - this, [this](bool){ - m_output_window->show(); - m_output_window->raise(); // bring the window to front on macOS - m_output_window->activateWindow(); // bring the window to front on Windows + this, [&](bool){ + show_output_window(); } ); + + if (GlobalSettings::instance().LOG_WINDOW_STARTUP){ // show the Output Window on startup + show_output_window(); + } + + // move the output window to desired position on startup + uint32_t initial_x_pos = GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_X_POS; + uint32_t initial_y_pos = GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_Y_POS; + auto const screen_geometry = QGuiApplication::primaryScreen()->availableGeometry(); + uint32_t const screen_width = (uint32_t)screen_geometry.width(); + uint32_t const screen_height = (uint32_t)screen_geometry.height(); + uint32_t move_x = std::min(initial_x_pos, screen_width-100); + uint32_t move_y = std::min(initial_y_pos, screen_height-100); + m_output_window->move(scale_dpi_width(move_x), scale_dpi_height(move_y)); } { QPushButton* settings = new QPushButton("Settings", support_box); From 1fabc4c50aee14760b05b5b74204a0d4e70c57e3 Mon Sep 17 00:00:00 2001 From: jw098 Date: Thu, 26 Jun 2025 23:19:56 -0700 Subject: [PATCH 2/6] set startup position for main window --- .../CommonFramework/Windows/MainWindow.cpp | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp b/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp index 3d573ae0f2..e4143d2868 100644 --- a/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp +++ b/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp @@ -47,6 +47,16 @@ MainWindow::MainWindow(QWidget* parent) GlobalSettings::instance().WINDOW_SIZE->WIDTH, GlobalSettings::instance().WINDOW_SIZE->HEIGHT ); + // move main window to desired position on startup + auto const screen_geometry = QGuiApplication::primaryScreen()->availableGeometry(); + uint32_t const screen_width = (uint32_t)screen_geometry.width(); + uint32_t const screen_height = (uint32_t)screen_geometry.height(); + uint32_t initial_x_pos_main = GlobalSettings::instance().WINDOW_SIZE->INITIAL_X_POS; + uint32_t initial_y_pos_main = GlobalSettings::instance().WINDOW_SIZE->INITIAL_Y_POS; + uint32_t move_x_main = std::min(initial_x_pos_main, screen_width-100); + uint32_t move_y_main = std::min(initial_y_pos_main, screen_height-100); + move(scale_dpi_width(move_x_main), scale_dpi_height(move_y_main)); + centralwidget = new QWidget(this); centralwidget->setObjectName(QString::fromUtf8("centralwidget")); setCentralWidget(centralwidget); @@ -219,14 +229,11 @@ MainWindow::MainWindow(QWidget* parent) } // move the output window to desired position on startup - uint32_t initial_x_pos = GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_X_POS; - uint32_t initial_y_pos = GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_Y_POS; - auto const screen_geometry = QGuiApplication::primaryScreen()->availableGeometry(); - uint32_t const screen_width = (uint32_t)screen_geometry.width(); - uint32_t const screen_height = (uint32_t)screen_geometry.height(); - uint32_t move_x = std::min(initial_x_pos, screen_width-100); - uint32_t move_y = std::min(initial_y_pos, screen_height-100); - m_output_window->move(scale_dpi_width(move_x), scale_dpi_height(move_y)); + uint32_t initial_x_pos_log = GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_X_POS; + uint32_t initial_y_pos_log = GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_Y_POS; + uint32_t move_x_log = std::min(initial_x_pos_log, screen_width-100); + uint32_t move_y_log = std::min(initial_y_pos_log, screen_height-100); + m_output_window->move(scale_dpi_width(move_x_log), scale_dpi_height(move_y_log)); } { QPushButton* settings = new QPushButton("Settings", support_box); From 08d1dc5a5ca3fc79b08cfab397bb85372092b6ea Mon Sep 17 00:00:00 2001 From: jw098 Date: Thu, 26 Jun 2025 23:57:13 -0700 Subject: [PATCH 3/6] Save X/Y position of window, so that it will re-open at that position. Fix bug with re-opening the Output window. --- .../Logging/FileWindowLogger.cpp | 8 +++-- .../Logging/FileWindowLogger.h | 3 +- .../Options/ResolutionOption.cpp | 2 +- .../Options/ResolutionOption.h | 4 +-- .../CommonFramework/Windows/MainWindow.cpp | 30 +++++++++++-------- .../CommonFramework/Windows/MainWindow.h | 1 + 6 files changed, 30 insertions(+), 18 deletions(-) diff --git a/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp b/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp index b8e1be5f6a..54d8f71788 100644 --- a/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp +++ b/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp @@ -260,12 +260,16 @@ void FileWindowLoggerWindow::log(QString msg){ } void FileWindowLoggerWindow::resizeEvent(QResizeEvent* event){ - m_pending_resize = true; + // m_pending_resize = true; GlobalSettings::instance().LOG_WINDOW_SIZE->WIDTH.set(width()); GlobalSettings::instance().LOG_WINDOW_SIZE->HEIGHT.set(height()); - m_pending_resize = false; + // m_pending_resize = false; } +void FileWindowLoggerWindow::moveEvent(QMoveEvent* event){ + GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_X_POS.set(x()); + GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_Y_POS.set(y()); +} diff --git a/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.h b/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.h index 2ce1ed9219..03eae3f92d 100644 --- a/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.h +++ b/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.h @@ -81,6 +81,7 @@ class FileWindowLoggerWindow : public QMainWindow{ void log(QString msg); virtual void resizeEvent(QResizeEvent* event) override; + virtual void moveEvent(QMoveEvent* event) override; signals: void signal_log(QString msg); @@ -89,7 +90,7 @@ class FileWindowLoggerWindow : public QMainWindow{ FileWindowLogger& m_logger; QMenuBar* m_menubar; QTextEdit* m_text; - bool m_pending_resize = false; + // bool m_pending_resize = false; }; diff --git a/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp b/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp index 7e03ddd044..b259fe8e39 100644 --- a/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp +++ b/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp @@ -26,7 +26,7 @@ ResolutionOption::ResolutionOption( PA_ADD_STATIC(DESCRIPTION); PA_ADD_OPTION(WIDTH); PA_ADD_OPTION(HEIGHT); - if (PreloadSettings::instance().DEVELOPER_MODE){ + if (PreloadSettings::instance().DEVELOPER_MODE){ PA_ADD_OPTION(INITIAL_X_POS); PA_ADD_OPTION(INITIAL_Y_POS); } diff --git a/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.h b/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.h index 2c41fc2c30..a3cf0f8f20 100644 --- a/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.h +++ b/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.h @@ -25,8 +25,8 @@ class ResolutionOption : public GroupOption{ StaticTextOption DESCRIPTION; SimpleIntegerOption WIDTH; SimpleIntegerOption HEIGHT; - SimpleIntegerOption INITIAL_X_POS; - SimpleIntegerOption INITIAL_Y_POS; + SimpleIntegerOption INITIAL_X_POS; + SimpleIntegerOption INITIAL_Y_POS; }; diff --git a/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp b/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp index e4143d2868..8e1732c159 100644 --- a/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp +++ b/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp @@ -27,9 +27,9 @@ #include "MainWindow.h" -//#include -//using std::cout; -//using std::endl; +#include +using std::cout; +using std::endl; namespace PokemonAutomation{ @@ -212,25 +212,26 @@ MainWindow::MainWindow(QWidget* parent) m_output_window.reset(new FileWindowLoggerWindow((FileWindowLogger&)global_logger_raw())); QPushButton* output = new QPushButton("Output Window", support_box); buttons->addWidget(output); - auto show_output_window = [&](){ - m_output_window->show(); - m_output_window->raise(); // bring the window to front on macOS - m_output_window->activateWindow(); // bring the window to front on Windows - }; connect( output, &QPushButton::clicked, this, [&](bool){ - show_output_window(); + m_output_window->show(); + m_output_window->raise(); // bring the window to front on macOS + m_output_window->activateWindow(); // bring the window to front on Windows } ); + // get snapshot of the saved initial x/y position, since activating the window seems to change the window coordinates, + // which then causes initial x/y position to change, due to triggering moveEvent(). + uint32_t initial_x_pos_log = GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_X_POS; + uint32_t initial_y_pos_log = GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_Y_POS; if (GlobalSettings::instance().LOG_WINDOW_STARTUP){ // show the Output Window on startup - show_output_window(); + m_output_window->show(); + m_output_window->raise(); // bring the window to front on macOS + m_output_window->activateWindow(); // bring the window to front on Windows } // move the output window to desired position on startup - uint32_t initial_x_pos_log = GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_X_POS; - uint32_t initial_y_pos_log = GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_Y_POS; uint32_t move_x_log = std::min(initial_x_pos_log, screen_width-100); uint32_t move_y_log = std::min(initial_y_pos_log, screen_height-100); m_output_window->move(scale_dpi_width(move_x_log), scale_dpi_height(move_y_log)); @@ -281,6 +282,11 @@ void MainWindow::resizeEvent(QResizeEvent* event){ m_pending_resize = false; } +void MainWindow::moveEvent(QMoveEvent* event){ + GlobalSettings::instance().WINDOW_SIZE->INITIAL_X_POS.set(x()); + GlobalSettings::instance().WINDOW_SIZE->INITIAL_Y_POS.set(y()); +} + void MainWindow::close_panel() noexcept{ // cout << "close_panel(): enter: " << m_current_panel_widget << endl; // Must destroy the widget first since it references the instance. diff --git a/SerialPrograms/Source/CommonFramework/Windows/MainWindow.h b/SerialPrograms/Source/CommonFramework/Windows/MainWindow.h index 71f67cd466..708a5949c3 100644 --- a/SerialPrograms/Source/CommonFramework/Windows/MainWindow.h +++ b/SerialPrograms/Source/CommonFramework/Windows/MainWindow.h @@ -37,6 +37,7 @@ class MainWindow : private: virtual void closeEvent(QCloseEvent* event) override; virtual void resizeEvent(QResizeEvent* event) override; + virtual void moveEvent(QMoveEvent* event) override; void close_panel() noexcept; From 6d2f732385d935ac51ccebe18fa0daf51afc32c1 Mon Sep 17 00:00:00 2001 From: jw098 Date: Fri, 27 Jun 2025 12:07:26 -0700 Subject: [PATCH 4/6] fix bounds for move_x/move_y. --- .../CommonFramework/Windows/MainWindow.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp b/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp index 8e1732c159..f3dad52f07 100644 --- a/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp +++ b/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp @@ -51,10 +51,10 @@ MainWindow::MainWindow(QWidget* parent) auto const screen_geometry = QGuiApplication::primaryScreen()->availableGeometry(); uint32_t const screen_width = (uint32_t)screen_geometry.width(); uint32_t const screen_height = (uint32_t)screen_geometry.height(); - uint32_t initial_x_pos_main = GlobalSettings::instance().WINDOW_SIZE->INITIAL_X_POS; - uint32_t initial_y_pos_main = GlobalSettings::instance().WINDOW_SIZE->INITIAL_Y_POS; - uint32_t move_x_main = std::min(initial_x_pos_main, screen_width-100); - uint32_t move_y_main = std::min(initial_y_pos_main, screen_height-100); + int32_t initial_x_pos_main = GlobalSettings::instance().WINDOW_SIZE->INITIAL_X_POS; + int32_t initial_y_pos_main = GlobalSettings::instance().WINDOW_SIZE->INITIAL_Y_POS; + int32_t move_x_main = std::max(0, std::min(initial_x_pos_main, (int32_t)(screen_width*0.97))); + int32_t move_y_main = std::max(0, std::min(initial_y_pos_main, (int32_t)(screen_height*0.97))); move(scale_dpi_width(move_x_main), scale_dpi_height(move_y_main)); centralwidget = new QWidget(this); @@ -222,8 +222,8 @@ MainWindow::MainWindow(QWidget* parent) ); // get snapshot of the saved initial x/y position, since activating the window seems to change the window coordinates, // which then causes initial x/y position to change, due to triggering moveEvent(). - uint32_t initial_x_pos_log = GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_X_POS; - uint32_t initial_y_pos_log = GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_Y_POS; + int32_t initial_x_pos_log = GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_X_POS; + int32_t initial_y_pos_log = GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_Y_POS; if (GlobalSettings::instance().LOG_WINDOW_STARTUP){ // show the Output Window on startup m_output_window->show(); @@ -232,8 +232,8 @@ MainWindow::MainWindow(QWidget* parent) } // move the output window to desired position on startup - uint32_t move_x_log = std::min(initial_x_pos_log, screen_width-100); - uint32_t move_y_log = std::min(initial_y_pos_log, screen_height-100); + int32_t move_x_log = std::max(0, std::min(initial_x_pos_log, (int32_t)(screen_width*0.97))); // ensure move_x is greater than 0, but less than screen_width + int32_t move_y_log = std::max(0, std::min(initial_y_pos_log, (int32_t)(screen_height*0.97))); m_output_window->move(scale_dpi_width(move_x_log), scale_dpi_height(move_y_log)); } { From 04509a8fa5a173e081de4913784ed2ab44fe71b5 Mon Sep 17 00:00:00 2001 From: jw098 Date: Fri, 27 Jun 2025 12:40:01 -0700 Subject: [PATCH 5/6] changing Config value will change position of main window --- .../Logging/FileWindowLogger.cpp | 4 +- .../Options/ResolutionOption.cpp | 8 +- .../Options/ResolutionOption.h | 4 +- .../CommonFramework/Windows/MainWindow.cpp | 79 +++++++++++++------ .../CommonFramework/Windows/MainWindow.h | 7 +- 5 files changed, 70 insertions(+), 32 deletions(-) diff --git a/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp b/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp index 54d8f71788..9bbf207c16 100644 --- a/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp +++ b/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp @@ -267,8 +267,8 @@ void FileWindowLoggerWindow::resizeEvent(QResizeEvent* event){ } void FileWindowLoggerWindow::moveEvent(QMoveEvent* event){ - GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_X_POS.set(x()); - GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_Y_POS.set(y()); + GlobalSettings::instance().LOG_WINDOW_SIZE->X_POS.set(x()); + GlobalSettings::instance().LOG_WINDOW_SIZE->Y_POS.set(y()); } diff --git a/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp b/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp index b259fe8e39..dd82693ff3 100644 --- a/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp +++ b/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp @@ -20,15 +20,15 @@ ResolutionOption::ResolutionOption( , DESCRIPTION(std::move(description)) , WIDTH("Width:", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(default_width)) , HEIGHT("Height:", LockMode::LOCK_WHILE_RUNNING, scale_dpi_height(default_height)) - , INITIAL_X_POS("Initial X position:", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(initial_x_pos)) - , INITIAL_Y_POS("Initial Y position:", LockMode::LOCK_WHILE_RUNNING, scale_dpi_height(initial_y_pos)) + , X_POS("X position:", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(initial_x_pos)) + , Y_POS("Y position:", LockMode::LOCK_WHILE_RUNNING, scale_dpi_height(initial_y_pos)) { PA_ADD_STATIC(DESCRIPTION); PA_ADD_OPTION(WIDTH); PA_ADD_OPTION(HEIGHT); if (PreloadSettings::instance().DEVELOPER_MODE){ - PA_ADD_OPTION(INITIAL_X_POS); - PA_ADD_OPTION(INITIAL_Y_POS); + PA_ADD_OPTION(X_POS); + PA_ADD_OPTION(Y_POS); } } diff --git a/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.h b/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.h index a3cf0f8f20..ba06ab107f 100644 --- a/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.h +++ b/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.h @@ -25,8 +25,8 @@ class ResolutionOption : public GroupOption{ StaticTextOption DESCRIPTION; SimpleIntegerOption WIDTH; SimpleIntegerOption HEIGHT; - SimpleIntegerOption INITIAL_X_POS; - SimpleIntegerOption INITIAL_Y_POS; + SimpleIntegerOption X_POS; + SimpleIntegerOption Y_POS; }; diff --git a/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp b/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp index f3dad52f07..9fcf1027df 100644 --- a/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp +++ b/SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp @@ -48,14 +48,14 @@ MainWindow::MainWindow(QWidget* parent) GlobalSettings::instance().WINDOW_SIZE->HEIGHT ); // move main window to desired position on startup - auto const screen_geometry = QGuiApplication::primaryScreen()->availableGeometry(); - uint32_t const screen_width = (uint32_t)screen_geometry.width(); - uint32_t const screen_height = (uint32_t)screen_geometry.height(); - int32_t initial_x_pos_main = GlobalSettings::instance().WINDOW_SIZE->INITIAL_X_POS; - int32_t initial_y_pos_main = GlobalSettings::instance().WINDOW_SIZE->INITIAL_Y_POS; - int32_t move_x_main = std::max(0, std::min(initial_x_pos_main, (int32_t)(screen_width*0.97))); - int32_t move_y_main = std::max(0, std::min(initial_y_pos_main, (int32_t)(screen_height*0.97))); - move(scale_dpi_width(move_x_main), scale_dpi_height(move_y_main)); + // auto const screen_geometry = QGuiApplication::primaryScreen()->availableGeometry(); + // uint32_t const screen_width = (uint32_t)screen_geometry.width(); + // uint32_t const screen_height = (uint32_t)screen_geometry.height(); + int32_t x_pos_main = GlobalSettings::instance().WINDOW_SIZE->X_POS; + int32_t y_pos_main = GlobalSettings::instance().WINDOW_SIZE->Y_POS; + int32_t move_x_main = move_x_within_screen_bounds(x_pos_main); + int32_t move_y_main = move_y_within_screen_bounds(y_pos_main); + move(move_x_main, move_y_main); centralwidget = new QWidget(this); centralwidget->setObjectName(QString::fromUtf8("centralwidget")); @@ -222,8 +222,8 @@ MainWindow::MainWindow(QWidget* parent) ); // get snapshot of the saved initial x/y position, since activating the window seems to change the window coordinates, // which then causes initial x/y position to change, due to triggering moveEvent(). - int32_t initial_x_pos_log = GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_X_POS; - int32_t initial_y_pos_log = GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_Y_POS; + int32_t x_pos_log = GlobalSettings::instance().LOG_WINDOW_SIZE->X_POS; + int32_t y_pos_log = GlobalSettings::instance().LOG_WINDOW_SIZE->Y_POS; if (GlobalSettings::instance().LOG_WINDOW_STARTUP){ // show the Output Window on startup m_output_window->show(); @@ -232,9 +232,9 @@ MainWindow::MainWindow(QWidget* parent) } // move the output window to desired position on startup - int32_t move_x_log = std::max(0, std::min(initial_x_pos_log, (int32_t)(screen_width*0.97))); // ensure move_x is greater than 0, but less than screen_width - int32_t move_y_log = std::max(0, std::min(initial_y_pos_log, (int32_t)(screen_height*0.97))); - m_output_window->move(scale_dpi_width(move_x_log), scale_dpi_height(move_y_log)); + int32_t move_x_log = move_x_within_screen_bounds(x_pos_log); + int32_t move_y_log = move_y_within_screen_bounds(y_pos_log); + m_output_window->move(move_x_log, move_y_log); } { QPushButton* settings = new QPushButton("Settings", support_box); @@ -260,6 +260,8 @@ MainWindow::MainWindow(QWidget* parent) GlobalSettings::instance().WINDOW_SIZE->WIDTH.add_listener(*this); GlobalSettings::instance().WINDOW_SIZE->HEIGHT.add_listener(*this); + GlobalSettings::instance().WINDOW_SIZE->X_POS.add_listener(*this); + GlobalSettings::instance().WINDOW_SIZE->Y_POS.add_listener(*this); SystemSleepController::instance().add_listener(*this); // cout << "Done constructing" << endl; } @@ -268,6 +270,24 @@ MainWindow::~MainWindow(){ SystemSleepController::instance().remove_listener(*this); GlobalSettings::instance().WINDOW_SIZE->WIDTH.remove_listener(*this); GlobalSettings::instance().WINDOW_SIZE->HEIGHT.remove_listener(*this); + GlobalSettings::instance().WINDOW_SIZE->X_POS.remove_listener(*this); + GlobalSettings::instance().WINDOW_SIZE->Y_POS.remove_listener(*this); +} + +int32_t move_x_within_screen_bounds(int32_t x_pos){ + auto static const screen_geometry = QGuiApplication::primaryScreen()->availableGeometry(); + uint32_t static const screen_width = (uint32_t)screen_geometry.width(); + // ensure move_x is greater than 0, but less than screen_width + return scale_dpi_width(std::max(0, std::min(x_pos, (int32_t)(screen_width*0.97)))); + +} + +int32_t move_y_within_screen_bounds(int32_t y_pos){ + auto static const screen_geometry = QGuiApplication::primaryScreen()->availableGeometry(); + uint32_t const screen_height = (uint32_t)screen_geometry.height(); + // ensure move_y is greater than 0, but less than screen_height + return scale_dpi_width(std::max(0, std::min(y_pos, (int32_t)(screen_height*0.97)))); + } @@ -283,8 +303,10 @@ void MainWindow::resizeEvent(QResizeEvent* event){ } void MainWindow::moveEvent(QMoveEvent* event){ - GlobalSettings::instance().WINDOW_SIZE->INITIAL_X_POS.set(x()); - GlobalSettings::instance().WINDOW_SIZE->INITIAL_Y_POS.set(y()); + m_pending_move = true; + GlobalSettings::instance().WINDOW_SIZE->X_POS.set(x()); + GlobalSettings::instance().WINDOW_SIZE->Y_POS.set(y()); + m_pending_move = false; } void MainWindow::close_panel() noexcept{ @@ -373,14 +395,25 @@ void MainWindow::on_idle(){ void MainWindow::on_config_value_changed(void* object){ - QMetaObject::invokeMethod(this, [this]{ - if (!m_pending_resize){ - resize( - GlobalSettings::instance().WINDOW_SIZE->WIDTH, - GlobalSettings::instance().WINDOW_SIZE->HEIGHT - ); - } - }); + if (object == &GlobalSettings::instance().WINDOW_SIZE->WIDTH || object == &GlobalSettings::instance().WINDOW_SIZE->HEIGHT){ + QMetaObject::invokeMethod(this, [this]{ + if (!m_pending_resize){ + resize( + GlobalSettings::instance().WINDOW_SIZE->WIDTH, + GlobalSettings::instance().WINDOW_SIZE->HEIGHT + ); + } + }); + }else if (object == &GlobalSettings::instance().WINDOW_SIZE->X_POS || object == &GlobalSettings::instance().WINDOW_SIZE->Y_POS){ + QMetaObject::invokeMethod(this, [this]{ + if (!m_pending_move){ + move( + move_x_within_screen_bounds(GlobalSettings::instance().WINDOW_SIZE->X_POS), + move_y_within_screen_bounds(GlobalSettings::instance().WINDOW_SIZE->Y_POS) + ); + } + }); + } } void MainWindow::sleep_suppress_state_changed(SleepSuppress new_state){ QMetaObject::invokeMethod(this, [=, this]{ diff --git a/SerialPrograms/Source/CommonFramework/Windows/MainWindow.h b/SerialPrograms/Source/CommonFramework/Windows/MainWindow.h index 708a5949c3..cb08eea269 100644 --- a/SerialPrograms/Source/CommonFramework/Windows/MainWindow.h +++ b/SerialPrograms/Source/CommonFramework/Windows/MainWindow.h @@ -34,6 +34,7 @@ class MainWindow : MainWindow(QWidget* parent = nullptr); ~MainWindow(); + private: virtual void closeEvent(QCloseEvent* event) override; virtual void resizeEvent(QResizeEvent* event) override; @@ -86,10 +87,14 @@ class MainWindow : std::unique_ptr m_sleep_scope; bool m_pending_resize = false; + bool m_pending_move = false; bool m_panel_transition = false; }; - +// returns given X value, but bounded by 0 and screen_width +int32_t move_x_within_screen_bounds(int32_t x_pos); +// returns given y value, but bounded by 0 and screen_height +int32_t move_y_within_screen_bounds(int32_t y_pos); } From 10477d26fd170951317363ea823ef6eee373df25 Mon Sep 17 00:00:00 2001 From: jw098 Date: Fri, 27 Jun 2025 13:01:35 -0700 Subject: [PATCH 6/6] changing config value will change the size/position of the output window --- .../CommonFramework/GlobalSettingsPanel.cpp | 8 ++-- .../Logging/FileWindowLogger.cpp | 38 ++++++++++++++++++- .../Logging/FileWindowLogger.h | 7 +++- .../Options/ResolutionOption.cpp | 10 ++--- 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp b/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp index f89603a855..2aeed75bcc 100644 --- a/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp +++ b/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp @@ -130,16 +130,16 @@ GlobalSettings::GlobalSettings() , THEME(CONSTRUCT_TOKEN) , WINDOW_SIZE( CONSTRUCT_TOKEN, - "Window Size:", - "Set the size of the window. Takes effect immediately.
" + "Window Size/Position:", + "Set the size/position of the window. Takes effect immediately.
" "Use this to easily set the window to a specific resolution for streaming alignment.", 1280, 1000, 0, 0 ) , LOG_WINDOW_SIZE( CONSTRUCT_TOKEN, - "Output Window Size:", - "Set the initial size of the output window. Takes effect after restart.
", + "Output Window Size/Position:", + "Set the size/position of the output window. Takes effect immediately.
", 600, 1200, 0, 0 ) diff --git a/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp b/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp index 9bbf207c16..e06b05e919 100644 --- a/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp +++ b/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp @@ -11,6 +11,7 @@ #include "CommonFramework/GlobalSettingsPanel.h" #include "CommonFramework/Windows/DpiScaler.h" #include "CommonFramework/Windows/WindowTracker.h" +#include "CommonFramework/Windows/MainWindow.h" #include "CommonFramework/Options/ResolutionOption.h" #include "FileWindowLogger.h" @@ -240,6 +241,11 @@ FileWindowLoggerWindow::FileWindowLoggerWindow(FileWindowLogger& logger, QWidget } ); + GlobalSettings::instance().LOG_WINDOW_SIZE->WIDTH.add_listener(*this); + GlobalSettings::instance().LOG_WINDOW_SIZE->HEIGHT.add_listener(*this); + GlobalSettings::instance().LOG_WINDOW_SIZE->X_POS.add_listener(*this); + GlobalSettings::instance().LOG_WINDOW_SIZE->Y_POS.add_listener(*this); + m_logger += *this; log("================================================================================"); log("Window Startup..."); @@ -252,6 +258,10 @@ FileWindowLoggerWindow::FileWindowLoggerWindow(FileWindowLogger& logger, QWidget FileWindowLoggerWindow::~FileWindowLoggerWindow(){ remove_window(*this); m_logger -= *this; + GlobalSettings::instance().LOG_WINDOW_SIZE->WIDTH.remove_listener(*this); + GlobalSettings::instance().LOG_WINDOW_SIZE->HEIGHT.remove_listener(*this); + GlobalSettings::instance().LOG_WINDOW_SIZE->X_POS.remove_listener(*this); + GlobalSettings::instance().LOG_WINDOW_SIZE->Y_POS.remove_listener(*this); } void FileWindowLoggerWindow::log(QString msg){ @@ -260,15 +270,39 @@ void FileWindowLoggerWindow::log(QString msg){ } void FileWindowLoggerWindow::resizeEvent(QResizeEvent* event){ - // m_pending_resize = true; + m_pending_resize = true; GlobalSettings::instance().LOG_WINDOW_SIZE->WIDTH.set(width()); GlobalSettings::instance().LOG_WINDOW_SIZE->HEIGHT.set(height()); - // m_pending_resize = false; + m_pending_resize = false; } void FileWindowLoggerWindow::moveEvent(QMoveEvent* event){ + m_pending_move = true; GlobalSettings::instance().LOG_WINDOW_SIZE->X_POS.set(x()); GlobalSettings::instance().LOG_WINDOW_SIZE->Y_POS.set(y()); + m_pending_move = false; +} + +void FileWindowLoggerWindow::on_config_value_changed(void* object){ + if (object == &GlobalSettings::instance().LOG_WINDOW_SIZE->WIDTH || object == &GlobalSettings::instance().LOG_WINDOW_SIZE->HEIGHT){ + QMetaObject::invokeMethod(this, [this]{ + if (!m_pending_resize){ + resize( + GlobalSettings::instance().LOG_WINDOW_SIZE->WIDTH, + GlobalSettings::instance().LOG_WINDOW_SIZE->HEIGHT + ); + } + }); + }else if (object == &GlobalSettings::instance().LOG_WINDOW_SIZE->X_POS || object == &GlobalSettings::instance().LOG_WINDOW_SIZE->Y_POS){ + QMetaObject::invokeMethod(this, [this]{ + if (!m_pending_move){ + move( + move_x_within_screen_bounds(GlobalSettings::instance().LOG_WINDOW_SIZE->X_POS), + move_y_within_screen_bounds(GlobalSettings::instance().LOG_WINDOW_SIZE->Y_POS) + ); + } + }); + } } diff --git a/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.h b/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.h index 03eae3f92d..a24bc4002d 100644 --- a/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.h +++ b/SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.h @@ -16,6 +16,7 @@ #include #include #include "Common/Cpp/AbstractLogger.h" +#include "Common/Cpp/Options/ConfigOption.h" //#include "Common/Cpp/LifetimeSanitizer.h" namespace PokemonAutomation{ @@ -72,7 +73,7 @@ class FileWindowLogger : public Logger{ }; -class FileWindowLoggerWindow : public QMainWindow{ +class FileWindowLoggerWindow : public QMainWindow, public ConfigOption::Listener{ Q_OBJECT public: @@ -87,10 +88,12 @@ class FileWindowLoggerWindow : public QMainWindow{ void signal_log(QString msg); private: + virtual void on_config_value_changed(void* object) override; FileWindowLogger& m_logger; QMenuBar* m_menubar; QTextEdit* m_text; - // bool m_pending_resize = false; + bool m_pending_resize = false; + bool m_pending_move = false; }; diff --git a/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp b/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp index dd82693ff3..5167dfd340 100644 --- a/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp +++ b/SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp @@ -20,16 +20,14 @@ ResolutionOption::ResolutionOption( , DESCRIPTION(std::move(description)) , WIDTH("Width:", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(default_width)) , HEIGHT("Height:", LockMode::LOCK_WHILE_RUNNING, scale_dpi_height(default_height)) - , X_POS("X position:", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(initial_x_pos)) - , Y_POS("Y position:", LockMode::LOCK_WHILE_RUNNING, scale_dpi_height(initial_y_pos)) + , X_POS("X-position:", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(initial_x_pos)) + , Y_POS("Y-position:", LockMode::LOCK_WHILE_RUNNING, scale_dpi_height(initial_y_pos)) { PA_ADD_STATIC(DESCRIPTION); PA_ADD_OPTION(WIDTH); PA_ADD_OPTION(HEIGHT); - if (PreloadSettings::instance().DEVELOPER_MODE){ - PA_ADD_OPTION(X_POS); - PA_ADD_OPTION(Y_POS); - } + PA_ADD_OPTION(X_POS); + PA_ADD_OPTION(Y_POS); }