Skip to content

Commit 0ee4e7e

Browse files
committed
Default size, position for Output Window
1 parent e6f9318 commit 0ee4e7e

File tree

7 files changed

+68
-8
lines changed

7 files changed

+68
-8
lines changed

SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,20 @@ GlobalSettings::GlobalSettings()
133133
"Window Size:",
134134
"Set the size of the window. Takes effect immediately.<br>"
135135
"Use this to easily set the window to a specific resolution for streaming alignment.",
136-
1280, 1000
136+
1280, 1000,
137+
0, 0
138+
)
139+
, LOG_WINDOW_SIZE(
140+
CONSTRUCT_TOKEN,
141+
"Output Window Size:",
142+
"Set the initial size of the output window. Takes effect after restart.<br>",
143+
600, 1200,
144+
0, 0
145+
)
146+
, LOG_WINDOW_STARTUP(
147+
"<b>Open Output Window at startup:</b>",
148+
LockMode::UNLOCK_WHILE_RUNNING,
149+
false
137150
)
138151
, STREAM_HISTORY(CONSTRUCT_TOKEN)
139152
, SLEEP_SUPPRESS(CONSTRUCT_TOKEN)
@@ -196,6 +209,8 @@ GlobalSettings::GlobalSettings()
196209
PA_ADD_OPTION(TEMP_FOLDER);
197210
PA_ADD_OPTION(THEME);
198211
PA_ADD_OPTION(WINDOW_SIZE);
212+
PA_ADD_OPTION(LOG_WINDOW_SIZE);
213+
PA_ADD_OPTION(LOG_WINDOW_STARTUP);
199214
#if (QT_VERSION_MAJOR == 6) && (QT_VERSION_MINOR >= 8)
200215
if (IS_BETA_VERSION || PreloadSettings::instance().DEVELOPER_MODE){
201216
PA_ADD_OPTION(STREAM_HISTORY);

SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class GlobalSettings : public BatchOption, private ConfigOption::Listener{
9696

9797
Pimpl<ThemeSelectorOption> THEME;
9898
Pimpl<ResolutionOption> WINDOW_SIZE;
99+
Pimpl<ResolutionOption> LOG_WINDOW_SIZE;
100+
BooleanCheckBoxOption LOG_WINDOW_STARTUP;
99101

100102
Pimpl<StreamHistoryOption> STREAM_HISTORY;
101103
Pimpl<SleepSuppressOptions> SLEEP_SUPPRESS;

SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
#include <QMenuBar>
99
#include <QDir>
1010
#include "CommonFramework/Globals.h"
11+
#include "CommonFramework/GlobalSettingsPanel.h"
1112
#include "CommonFramework/Windows/DpiScaler.h"
1213
#include "CommonFramework/Windows/WindowTracker.h"
14+
#include "CommonFramework/Options/ResolutionOption.h"
1315
#include "FileWindowLogger.h"
1416

1517
//#include <iostream>
@@ -212,7 +214,9 @@ FileWindowLoggerWindow::FileWindowLoggerWindow(FileWindowLogger& logger, QWidget
212214
if (objectName().isEmpty()){
213215
setObjectName(QString::fromUtf8("TextWindow"));
214216
}
215-
resize(scale_dpi_width(1200), scale_dpi_height(600));
217+
uint32_t width = GlobalSettings::instance().LOG_WINDOW_SIZE->WIDTH;
218+
uint32_t height = GlobalSettings::instance().LOG_WINDOW_SIZE->HEIGHT;
219+
resize(scale_dpi_width(width), scale_dpi_height(height));
216220
m_text = new QTextEdit(this);
217221
m_text->setObjectName(QString::fromUtf8("centralwidget"));
218222
setCentralWidget(m_text);
@@ -255,6 +259,14 @@ void FileWindowLoggerWindow::log(QString msg){
255259
emit signal_log(msg);
256260
}
257261

262+
void FileWindowLoggerWindow::resizeEvent(QResizeEvent* event){
263+
m_pending_resize = true;
264+
GlobalSettings::instance().LOG_WINDOW_SIZE->WIDTH.set(width());
265+
GlobalSettings::instance().LOG_WINDOW_SIZE->HEIGHT.set(height());
266+
m_pending_resize = false;
267+
}
268+
269+
258270

259271

260272

SerialPrograms/Source/CommonFramework/Logging/FileWindowLogger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class FileWindowLoggerWindow : public QMainWindow{
8080
virtual ~FileWindowLoggerWindow();
8181

8282
void log(QString msg);
83+
virtual void resizeEvent(QResizeEvent* event) override;
8384

8485
signals:
8586
void signal_log(QString msg);
@@ -88,6 +89,7 @@ class FileWindowLoggerWindow : public QMainWindow{
8889
FileWindowLogger& m_logger;
8990
QMenuBar* m_menubar;
9091
QTextEdit* m_text;
92+
bool m_pending_resize = false;
9193
};
9294

9395

SerialPrograms/Source/CommonFramework/Options/ResolutionOption.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
*/
66

7+
#include "CommonFramework/GlobalSettingsPanel.h"
78
#include "CommonFramework/Windows/DpiScaler.h"
89
#include "ResolutionOption.h"
910

@@ -12,16 +13,23 @@ namespace PokemonAutomation{
1213

1314
ResolutionOption::ResolutionOption(
1415
std::string label, std::string description,
15-
int default_width, int default_height
16+
int default_width, int default_height,
17+
int initial_x_pos, int initial_y_pos
1618
)
1719
: GroupOption(std::move(label), LockMode::LOCK_WHILE_RUNNING)
1820
, DESCRIPTION(std::move(description))
1921
, WIDTH("<b>Width:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(default_width))
2022
, HEIGHT("<b>Height:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_height(default_height))
23+
, INITIAL_X_POS("<b>Initial X position:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(initial_x_pos))
24+
, INITIAL_Y_POS("<b>Initial Y position:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_height(initial_y_pos))
2125
{
2226
PA_ADD_STATIC(DESCRIPTION);
2327
PA_ADD_OPTION(WIDTH);
2428
PA_ADD_OPTION(HEIGHT);
29+
if (PreloadSettings::instance().DEVELOPER_MODE){
30+
PA_ADD_OPTION(INITIAL_X_POS);
31+
PA_ADD_OPTION(INITIAL_Y_POS);
32+
}
2533
}
2634

2735

SerialPrograms/Source/CommonFramework/Options/ResolutionOption.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ class ResolutionOption : public GroupOption{
1818
public:
1919
ResolutionOption(
2020
std::string label, std::string description,
21-
int default_width, int default_height
21+
int default_width, int default_height,
22+
int initial_x_pos, int initial_y_pos
2223
);
2324

2425
StaticTextOption DESCRIPTION;
2526
SimpleIntegerOption<uint32_t> WIDTH;
2627
SimpleIntegerOption<uint32_t> HEIGHT;
28+
SimpleIntegerOption<uint32_t> INITIAL_X_POS;
29+
SimpleIntegerOption<uint32_t> INITIAL_Y_POS;
2730
};
2831

2932

SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "CommonFramework/Startup/NewVersionCheck.h"
2121
#include "CommonFramework/Options/ResolutionOption.h"
2222
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
23+
#include "CommonFramework/Windows/DpiScaler.h"
2324
#include "PanelLists.h"
2425
#include "WindowTracker.h"
2526
#include "ButtonDiagram.h"
@@ -201,14 +202,31 @@ MainWindow::MainWindow(QWidget* parent)
201202
m_output_window.reset(new FileWindowLoggerWindow((FileWindowLogger&)global_logger_raw()));
202203
QPushButton* output = new QPushButton("Output Window", support_box);
203204
buttons->addWidget(output);
205+
auto show_output_window = [&](){
206+
m_output_window->show();
207+
m_output_window->raise(); // bring the window to front on macOS
208+
m_output_window->activateWindow(); // bring the window to front on Windows
209+
};
204210
connect(
205211
output, &QPushButton::clicked,
206-
this, [this](bool){
207-
m_output_window->show();
208-
m_output_window->raise(); // bring the window to front on macOS
209-
m_output_window->activateWindow(); // bring the window to front on Windows
212+
this, [&](bool){
213+
show_output_window();
210214
}
211215
);
216+
217+
if (GlobalSettings::instance().LOG_WINDOW_STARTUP){ // show the Output Window on startup
218+
show_output_window();
219+
}
220+
221+
// move the output window to desired position on startup
222+
uint32_t initial_x_pos = GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_X_POS;
223+
uint32_t initial_y_pos = GlobalSettings::instance().LOG_WINDOW_SIZE->INITIAL_Y_POS;
224+
auto const screen_geometry = QGuiApplication::primaryScreen()->availableGeometry();
225+
uint32_t const screen_width = (uint32_t)screen_geometry.width();
226+
uint32_t const screen_height = (uint32_t)screen_geometry.height();
227+
uint32_t move_x = std::min(initial_x_pos, screen_width-100);
228+
uint32_t move_y = std::min(initial_y_pos, screen_height-100);
229+
m_output_window->move(scale_dpi_width(move_x), scale_dpi_height(move_y));
212230
}
213231
{
214232
QPushButton* settings = new QPushButton("Settings", support_box);

0 commit comments

Comments
 (0)