Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,20 @@ GlobalSettings::GlobalSettings()
"Window Size:",
"Set the size of the window. Takes effect immediately.<br>"
"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.<br>",
600, 1200,
0, 0
)
, LOG_WINDOW_STARTUP(
"<b>Open Output Window at startup:</b>",
LockMode::UNLOCK_WHILE_RUNNING,
false
)
, STREAM_HISTORY(CONSTRUCT_TOKEN)
, SLEEP_SUPPRESS(CONSTRUCT_TOKEN)
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class GlobalSettings : public BatchOption, private ConfigOption::Listener{

Pimpl<ThemeSelectorOption> THEME;
Pimpl<ResolutionOption> WINDOW_SIZE;
Pimpl<ResolutionOption> LOG_WINDOW_SIZE;
BooleanCheckBoxOption LOG_WINDOW_STARTUP;

Pimpl<StreamHistoryOption> STREAM_HISTORY;
Pimpl<SleepSuppressOptions> SLEEP_SUPPRESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
#include <QMenuBar>
#include <QDir>
#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 <iostream>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}





Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -88,6 +89,7 @@ class FileWindowLoggerWindow : public QMainWindow{
FileWindowLogger& m_logger;
QMenuBar* m_menubar;
QTextEdit* m_text;
bool m_pending_resize = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this get used? I see it set, but it's never read.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I just copy pasted it without understanding its purpose.
I now understand what it's for and I don't need it at this time.

};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
*/

#include "CommonFramework/GlobalSettingsPanel.h"
#include "CommonFramework/Windows/DpiScaler.h"
#include "ResolutionOption.h"

Expand All @@ -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("<b>Width:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(default_width))
, HEIGHT("<b>Height:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_height(default_height))
, INITIAL_X_POS("<b>Initial X position:</b>", LockMode::LOCK_WHILE_RUNNING, scale_dpi_width(initial_x_pos))
, INITIAL_Y_POS("<b>Initial Y position:</b>", 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);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t> WIDTH;
SimpleIntegerOption<uint32_t> HEIGHT;
SimpleIntegerOption<uint32_t> INITIAL_X_POS;
SimpleIntegerOption<uint32_t> INITIAL_Y_POS;
};


Expand Down
33 changes: 29 additions & 4 deletions SerialPrograms/Source/CommonFramework/Windows/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -46,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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this goes negative? screen_width-100 < 0

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed that PA would be run on screens bigger than 100 pixels. But fair enough, I'll change it to screen_width*0.97.

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);
Expand Down Expand Up @@ -201,14 +212,28 @@ 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_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);
Expand Down