diff options
| author | Leifa <26681464+TrickyLeifa@users.noreply.github.com> | 2024-07-12 14:06:27 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-12 14:06:27 +0200 |
| commit | d05636571e234bf28dd49830af52675e6bb20068 (patch) | |
| tree | 5c20f972419f4efc58e5f23e35f25467b5e3aa43 /src/aoapplication.cpp | |
| parent | fb64ca386c51cc3942e1f38cfd76132b1b50e9db (diff) | |
| parent | 712269b4503989736b8b9b64eeeb69cab938b7f8 (diff) | |
Merge pull request #1016 from AttorneyOnline/restore-window-position
[Feature] Add support for windows position restore
Diffstat (limited to 'src/aoapplication.cpp')
| -rw-r--r-- | src/aoapplication.cpp | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/aoapplication.cpp b/src/aoapplication.cpp index 20eaaa30..bcc1ad59 100644 --- a/src/aoapplication.cpp +++ b/src/aoapplication.cpp @@ -51,10 +51,7 @@ void AOApplication::construct_lobby() w_lobby = new Lobby(this, net_manager); - QRect geometry = QGuiApplication::primaryScreen()->geometry(); - int x = (geometry.width() - w_lobby->width()) / 2; - int y = (geometry.height() - w_lobby->height()) / 2; - w_lobby->move(x, y); + centerOrMoveWidgetOnPrimaryScreen(w_lobby); if (Options::getInstance().discordEnabled()) { @@ -96,10 +93,7 @@ void AOApplication::construct_courtroom() w_courtroom = new Courtroom(this); - QRect geometry = QGuiApplication::primaryScreen()->geometry(); - int x = (geometry.width() - w_courtroom->width()) / 2; - int y = (geometry.height() - w_courtroom->height()) / 2; - w_courtroom->move(x, y); + centerOrMoveWidgetOnPrimaryScreen(w_courtroom); if (demo_server != nullptr) { @@ -235,6 +229,34 @@ void AOApplication::initBASS() } } +bool AOApplication::pointExistsOnScreen(QPoint point) +{ + for (QScreen *screen : QApplication::screens()) + { + if (screen->availableGeometry().contains(point)) + { + return true; + } + } + return false; +} + +void AOApplication::centerOrMoveWidgetOnPrimaryScreen(QWidget *widget) +{ + auto point = Options::getInstance().windowPosition(widget->objectName()); + if (!Options::getInstance().restoreWindowPositionEnabled() || !point.has_value() || !pointExistsOnScreen(point.value())) + { + QRect geometry = QGuiApplication::primaryScreen()->geometry(); + int x = (geometry.width() - widget->width()) / 2; + int y = (geometry.height() - widget->height()) / 2; + widget->move(x, y); + } + else + { + widget->move(point->x(), point->y()); + } +} + #if (defined(_WIN32) || defined(_WIN64)) void AOApplication::load_bass_plugins() { |
