Skip to content

Commit 10477d2

Browse files
committed
changing config value will change the size/position of the output window
1 parent 04509a8 commit 10477d2

File tree

4 files changed

+49
-14
lines changed

4 files changed

+49
-14
lines changed

SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,16 @@ GlobalSettings::GlobalSettings()
130130
, THEME(CONSTRUCT_TOKEN)
131131
, WINDOW_SIZE(
132132
CONSTRUCT_TOKEN,
133-
"Window Size:",
134-
"Set the size of the window. Takes effect immediately.<br>"
133+
"Window Size/Position:",
134+
"Set the size/position of the window. Takes effect immediately.<br>"
135135
"Use this to easily set the window to a specific resolution for streaming alignment.",
136136
1280, 1000,
137137
0, 0
138138
)
139139
, LOG_WINDOW_SIZE(
140140
CONSTRUCT_TOKEN,
141-
"Output Window Size:",
142-
"Set the initial size of the output window. Takes effect after restart.<br>",
141+
"Output Window Size/Position:",
142+
"Set the size/position of the output window. Takes effect immediately.<br>",
143143
600, 1200,
144144
0, 0
145145
)

SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "CommonFramework/GlobalSettingsPanel.h"
1212
#include "CommonFramework/Windows/DpiScaler.h"
1313
#include "CommonFramework/Windows/WindowTracker.h"
14+
#include "CommonFramework/Windows/MainWindow.h"
1415
#include "CommonFramework/Options/ResolutionOption.h"
1516
#include "FileWindowLogger.h"
1617

@@ -240,6 +241,11 @@ FileWindowLoggerWindow::FileWindowLoggerWindow(FileWindowLogger& logger, QWidget
240241
}
241242
);
242243

244+
GlobalSettings::instance().LOG_WINDOW_SIZE->WIDTH.add_listener(*this);
245+
GlobalSettings::instance().LOG_WINDOW_SIZE->HEIGHT.add_listener(*this);
246+
GlobalSettings::instance().LOG_WINDOW_SIZE->X_POS.add_listener(*this);
247+
GlobalSettings::instance().LOG_WINDOW_SIZE->Y_POS.add_listener(*this);
248+
243249
m_logger += *this;
244250
log("================================================================================");
245251
log("<b>Window Startup...</b>");
@@ -252,6 +258,10 @@ FileWindowLoggerWindow::FileWindowLoggerWindow(FileWindowLogger& logger, QWidget
252258
FileWindowLoggerWindow::~FileWindowLoggerWindow(){
253259
remove_window(*this);
254260
m_logger -= *this;
261+
GlobalSettings::instance().LOG_WINDOW_SIZE->WIDTH.remove_listener(*this);
262+
GlobalSettings::instance().LOG_WINDOW_SIZE->HEIGHT.remove_listener(*this);
263+
GlobalSettings::instance().LOG_WINDOW_SIZE->X_POS.remove_listener(*this);
264+
GlobalSettings::instance().LOG_WINDOW_SIZE->Y_POS.remove_listener(*this);
255265
}
256266

257267
void FileWindowLoggerWindow::log(QString msg){
@@ -260,15 +270,39 @@ void FileWindowLoggerWindow::log(QString msg){
260270
}
261271

262272
void FileWindowLoggerWindow::resizeEvent(QResizeEvent* event){
263-
// m_pending_resize = true;
273+
m_pending_resize = true;
264274
GlobalSettings::instance().LOG_WINDOW_SIZE->WIDTH.set(width());
265275
GlobalSettings::instance().LOG_WINDOW_SIZE->HEIGHT.set(height());
266-
// m_pending_resize = false;
276+
m_pending_resize = false;
267277
}
268278

269279
void FileWindowLoggerWindow::moveEvent(QMoveEvent* event){
280+
m_pending_move = true;
270281
GlobalSettings::instance().LOG_WINDOW_SIZE->X_POS.set(x());
271282
GlobalSettings::instance().LOG_WINDOW_SIZE->Y_POS.set(y());
283+
m_pending_move = false;
284+
}
285+
286+
void FileWindowLoggerWindow::on_config_value_changed(void* object){
287+
if (object == &GlobalSettings::instance().LOG_WINDOW_SIZE->WIDTH || object == &GlobalSettings::instance().LOG_WINDOW_SIZE->HEIGHT){
288+
QMetaObject::invokeMethod(this, [this]{
289+
if (!m_pending_resize){
290+
resize(
291+
GlobalSettings::instance().LOG_WINDOW_SIZE->WIDTH,
292+
GlobalSettings::instance().LOG_WINDOW_SIZE->HEIGHT
293+
);
294+
}
295+
});
296+
}else if (object == &GlobalSettings::instance().LOG_WINDOW_SIZE->X_POS || object == &GlobalSettings::instance().LOG_WINDOW_SIZE->Y_POS){
297+
QMetaObject::invokeMethod(this, [this]{
298+
if (!m_pending_move){
299+
move(
300+
move_x_within_screen_bounds(GlobalSettings::instance().LOG_WINDOW_SIZE->X_POS),
301+
move_y_within_screen_bounds(GlobalSettings::instance().LOG_WINDOW_SIZE->Y_POS)
302+
);
303+
}
304+
});
305+
}
272306
}
273307

274308

SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <QTextEdit>
1717
#include <QMainWindow>
1818
#include "Common/Cpp/AbstractLogger.h"
19+
#include "Common/Cpp/Options/ConfigOption.h"
1920
//#include "Common/Cpp/LifetimeSanitizer.h"
2021

2122
namespace PokemonAutomation{
@@ -72,7 +73,7 @@ class FileWindowLogger : public Logger{
7273
};
7374

7475

75-
class FileWindowLoggerWindow : public QMainWindow{
76+
class FileWindowLoggerWindow : public QMainWindow, public ConfigOption::Listener{
7677
Q_OBJECT
7778

7879
public:
@@ -87,10 +88,12 @@ class FileWindowLoggerWindow : public QMainWindow{
8788
void signal_log(QString msg);
8889

8990
private:
91+
virtual void on_config_value_changed(void* object) override;
9092
FileWindowLogger& m_logger;
9193
QMenuBar* m_menubar;
9294
QTextEdit* m_text;
93-
// bool m_pending_resize = false;
95+
bool m_pending_resize = false;
96+
bool m_pending_move = false;
9497
};
9598

9699

SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@ ResolutionOption::ResolutionOption(
2020
, DESCRIPTION(std::move(description))
2121
, WIDTH("<b>Width:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(default_width))
2222
, HEIGHT("<b>Height:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_height(default_height))
23-
, X_POS("<b>X position:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(initial_x_pos))
24-
, Y_POS("<b>Y position:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_height(initial_y_pos))
23+
, X_POS("<b>X-position:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(initial_x_pos))
24+
, Y_POS("<b>Y-position:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_height(initial_y_pos))
2525
{
2626
PA_ADD_STATIC(DESCRIPTION);
2727
PA_ADD_OPTION(WIDTH);
2828
PA_ADD_OPTION(HEIGHT);
29-
if (PreloadSettings::instance().DEVELOPER_MODE){
30-
PA_ADD_OPTION(X_POS);
31-
PA_ADD_OPTION(Y_POS);
32-
}
29+
PA_ADD_OPTION(X_POS);
30+
PA_ADD_OPTION(Y_POS);
3331
}
3432

3533

0 commit comments

Comments
 (0)