diff options
author | 2022-06-16 21:38:32 +0530 | |
---|---|---|
committer | 2022-06-16 21:38:32 +0530 | |
commit | 3a08d5d5801c7e902620e45305da838904bda1ab (patch) | |
tree | 4b23b7e3087ecbc2fe0f34c542eaaa09164c4f2e /src | |
parent | 5c2764f71ba3ee51305ff6129bdea0650f10ba21 (diff) | |
download | whatsie-3a08d5d5801c7e902620e45305da838904bda1ab.tar.gz whatsie-3a08d5d5801c7e902620e45305da838904bda1ab.zip |
chore: improve window geo restore
- show window on screen where the cursor is located
- default window size if saved geometry is not valid
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow.cpp | 28 | ||||
-rw-r--r-- | src/mainwindow.h | 1 |
2 files changed, 26 insertions, 3 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 13b01eb..7ab2216 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -23,7 +23,7 @@ MainWindow::MainWindow(QWidget *parent) setWindowIcon(QIcon(":/icons/app/icon-128.png")); setMinimumWidth(525); setMinimumHeight(448); - restoreGeometry(settings.value("geometry").toByteArray()); + restoreMainWindow(); initThemes(); createActions(); createTrayIcon(); @@ -35,6 +35,21 @@ MainWindow::MainWindow(QWidget *parent) initAutoLock(); } +void MainWindow::restoreMainWindow() { + if (settings.value("geometry").isValid()) { + restoreGeometry(settings.value("geometry").toByteArray()); + QPoint pos = QCursor::pos(); + for (QScreen *screen : QGuiApplication::screens()) { + QRect screenRect = screen->geometry(); + if (screenRect.contains(pos)) { + this->move(screenRect.center() - this->rect().center()); + } + } + }else{ + this->resize(636, 760); + } +} + void MainWindow::initAutoLock() { autoLockEventFilter = new AutoLockEventFilter( settings.value("autoLockDuration", defaultAppAutoLockDuration).toInt() * @@ -252,9 +267,10 @@ void MainWindow::tryLogOut() { } void MainWindow::init_settingWidget() { + int screenNumber = qApp->desktop()->screenNumber(this); if (settingsWidget == nullptr) { settingsWidget = new SettingsWidget( - this, webEngine->page()->profile()->cachePath(), + this, screenNumber, webEngine->page()->profile()->cachePath(), webEngine->page()->profile()->persistentStoragePath()); settingsWidget->setWindowTitle(QApplication::applicationName() + " | Settings"); @@ -414,12 +430,18 @@ void MainWindow::showSettings() { if (webEngine == nullptr) { QMessageBox::critical( this, QApplication::applicationName() + "| Error", - "Unable to initialize settings module.\nIs webengine initialized?"); + "Unable to initialize settings module.\nWebengine is not initialized."); return; } if (!settingsWidget->isVisible()) { this->updateSettingsUserAgentWidget(); settingsWidget->refresh(); + int screenNumber = qApp->desktop()->screenNumber(this); + QRect screenRect = QGuiApplication::screens().at(screenNumber)->geometry(); + if (!screenRect.contains(settingsWidget->pos())) { + settingsWidget->move(screenRect.center() - + settingsWidget->rect().center()); + } settingsWidget->show(); } } diff --git a/src/mainwindow.h b/src/mainwindow.h index 2c580b6..43b02f5 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -128,6 +128,7 @@ private slots: void appAutoLockChanged(); void injectNewChatJavaScript(); void triggerNewChat(QString phone, QString text); + void restoreMainWindow(); }; #endif // MAINWINDOW_H |