refactor: simplify windows size/pos saving
This commit is contained in:
@ -80,7 +80,6 @@ MainWindow::MainWindow(ConfigScopes &configScopes, AppConfig &appConfig)
|
||||
m_ServerConnection(this, appConfig, m_ServerConfig, m_ServerConfigDialogState),
|
||||
m_ClientConnection(this, appConfig),
|
||||
m_TlsUtility(appConfig),
|
||||
m_WindowSaveTimer(this),
|
||||
m_trayIcon{new QSystemTrayIcon(this)},
|
||||
m_guiDupeChecker{new QLocalServer(this)},
|
||||
m_actionAbout{new QAction(this)},
|
||||
@ -186,24 +185,6 @@ void MainWindow::restoreWindow()
|
||||
QRect screenGeometry = screen->geometry();
|
||||
move(screenGeometry.center() - rect().center());
|
||||
}
|
||||
|
||||
// give the window chance to restore its size and position before the window
|
||||
// size and position are saved. this prevents the window from being saved
|
||||
// with the wrong size and position.
|
||||
m_SaveWindow = true;
|
||||
}
|
||||
|
||||
void MainWindow::saveWindow()
|
||||
{
|
||||
if (!m_SaveWindow) {
|
||||
qDebug() << "not yet ready to save window size and position, skipping";
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "saving window size and position";
|
||||
m_AppConfig.setMainWindowSize(size());
|
||||
m_AppConfig.setMainWindowPosition(pos());
|
||||
m_ConfigScopes.save();
|
||||
}
|
||||
|
||||
void MainWindow::setupControls()
|
||||
@ -288,8 +269,6 @@ void MainWindow::connectSlots()
|
||||
|
||||
connect(&m_VersionChecker, &VersionChecker::updateFound, this, &MainWindow::onVersionCheckerUpdateFound);
|
||||
|
||||
connect(&m_WindowSaveTimer, &QTimer::timeout, this, &MainWindow::onWindowSaveTimerTimeout);
|
||||
|
||||
// Mac os tray will only show a menu
|
||||
#ifndef Q_OS_MAC
|
||||
connect(m_trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::onTrayIconActivated);
|
||||
@ -527,11 +506,6 @@ void MainWindow::setModeClient()
|
||||
m_ConfigScopes.save();
|
||||
}
|
||||
|
||||
void MainWindow::onWindowSaveTimerTimeout()
|
||||
{
|
||||
saveWindow();
|
||||
}
|
||||
|
||||
void MainWindow::onServerConnectionConfigureClient(const QString &clientName)
|
||||
{
|
||||
m_ServerConfigDialogState.setVisible(true);
|
||||
@ -546,24 +520,6 @@ void MainWindow::onServerConnectionConfigureClient(const QString &clientName)
|
||||
// End slots
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void MainWindow::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QMainWindow::resizeEvent(event);
|
||||
|
||||
// postpone save so that settings are not written every delta change.
|
||||
m_WindowSaveTimer.setSingleShot(true);
|
||||
m_WindowSaveTimer.start(1000);
|
||||
}
|
||||
|
||||
void MainWindow::moveEvent(QMoveEvent *event)
|
||||
{
|
||||
QMainWindow::moveEvent(event);
|
||||
|
||||
// postpone save so that settings are not written every delta change.
|
||||
m_WindowSaveTimer.setSingleShot(true);
|
||||
m_WindowSaveTimer.start(1000);
|
||||
}
|
||||
|
||||
void MainWindow::open()
|
||||
{
|
||||
if (!m_AppConfig.enableUpdateCheck().has_value()) {
|
||||
@ -805,9 +761,11 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_SaveOnExit)
|
||||
if (m_SaveOnExit) {
|
||||
m_AppConfig.setMainWindowPosition(pos());
|
||||
m_AppConfig.setMainWindowSize(size());
|
||||
m_ConfigScopes.save();
|
||||
|
||||
}
|
||||
qDebug() << "quitting application";
|
||||
event->accept();
|
||||
QApplication::quit();
|
||||
|
||||
@ -125,7 +125,6 @@ private slots:
|
||||
void onCoreProcessSecureSocket(bool enabled);
|
||||
void onVersionCheckerUpdateFound(const QString &version);
|
||||
void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
void onWindowSaveTimerTimeout();
|
||||
void onServerConnectionConfigureClient(const QString &clientName);
|
||||
|
||||
void clearSettings();
|
||||
@ -182,10 +181,7 @@ private:
|
||||
QString configFilename();
|
||||
void showConfigureServer(const QString &message);
|
||||
void restoreWindow();
|
||||
void saveWindow();
|
||||
void setupControls();
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
void moveEvent(QMoveEvent *event) override;
|
||||
void showFirstConnectedMessage();
|
||||
void updateStatus();
|
||||
void showAndActivate();
|
||||
@ -194,7 +190,6 @@ private:
|
||||
QSystemTrayIcon *m_trayIcon = nullptr;
|
||||
QAbstractButton *m_pCancelButton = nullptr;
|
||||
bool m_SecureSocket = false;
|
||||
bool m_SaveWindow = false;
|
||||
deskflow::gui::config::ServerConfigDialogState m_ServerConfigDialogState;
|
||||
bool m_SaveOnExit = true;
|
||||
deskflow::gui::core::WaylandWarnings m_WaylandWarnings;
|
||||
@ -206,7 +201,6 @@ private:
|
||||
deskflow::gui::ServerConnection m_ServerConnection;
|
||||
deskflow::gui::ClientConnection m_ClientConnection;
|
||||
deskflow::gui::TlsUtility m_TlsUtility;
|
||||
QTimer m_WindowSaveTimer;
|
||||
QSize m_expandedSize = QSize();
|
||||
|
||||
QLocalServer *m_guiDupeChecker = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user