From 3a08d5d5801c7e902620e45305da838904bda1ab Mon Sep 17 00:00:00 2001 From: Keshav Bhatt Date: Thu, 16 Jun 2022 21:38:32 +0530 Subject: chore: improve window geo restore - show window on screen where the cursor is located - default window size if saved geometry is not valid --- src/mainwindow.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src/mainwindow.cpp') 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(); } } -- cgit v1.2.3