refactor: simplify windows size/pos saving
This commit is contained in:
parent
3875e41154
commit
9a3a89efab
2 changed files with 4 additions and 52 deletions
|
|
@ -80,7 +80,6 @@ MainWindow::MainWindow(ConfigScopes &configScopes, AppConfig &appConfig)
|
||||||
m_ServerConnection(this, appConfig, m_ServerConfig, m_ServerConfigDialogState),
|
m_ServerConnection(this, appConfig, m_ServerConfig, m_ServerConfigDialogState),
|
||||||
m_ClientConnection(this, appConfig),
|
m_ClientConnection(this, appConfig),
|
||||||
m_TlsUtility(appConfig),
|
m_TlsUtility(appConfig),
|
||||||
m_WindowSaveTimer(this),
|
|
||||||
m_trayIcon{new QSystemTrayIcon(this)},
|
m_trayIcon{new QSystemTrayIcon(this)},
|
||||||
m_guiDupeChecker{new QLocalServer(this)},
|
m_guiDupeChecker{new QLocalServer(this)},
|
||||||
m_actionAbout{new QAction(this)},
|
m_actionAbout{new QAction(this)},
|
||||||
|
|
@ -186,24 +185,6 @@ void MainWindow::restoreWindow()
|
||||||
QRect screenGeometry = screen->geometry();
|
QRect screenGeometry = screen->geometry();
|
||||||
move(screenGeometry.center() - rect().center());
|
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()
|
void MainWindow::setupControls()
|
||||||
|
|
@ -288,8 +269,6 @@ void MainWindow::connectSlots()
|
||||||
|
|
||||||
connect(&m_VersionChecker, &VersionChecker::updateFound, this, &MainWindow::onVersionCheckerUpdateFound);
|
connect(&m_VersionChecker, &VersionChecker::updateFound, this, &MainWindow::onVersionCheckerUpdateFound);
|
||||||
|
|
||||||
connect(&m_WindowSaveTimer, &QTimer::timeout, this, &MainWindow::onWindowSaveTimerTimeout);
|
|
||||||
|
|
||||||
// Mac os tray will only show a menu
|
// Mac os tray will only show a menu
|
||||||
#ifndef Q_OS_MAC
|
#ifndef Q_OS_MAC
|
||||||
connect(m_trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::onTrayIconActivated);
|
connect(m_trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::onTrayIconActivated);
|
||||||
|
|
@ -527,11 +506,6 @@ void MainWindow::setModeClient()
|
||||||
m_ConfigScopes.save();
|
m_ConfigScopes.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onWindowSaveTimerTimeout()
|
|
||||||
{
|
|
||||||
saveWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onServerConnectionConfigureClient(const QString &clientName)
|
void MainWindow::onServerConnectionConfigureClient(const QString &clientName)
|
||||||
{
|
{
|
||||||
m_ServerConfigDialogState.setVisible(true);
|
m_ServerConfigDialogState.setVisible(true);
|
||||||
|
|
@ -546,24 +520,6 @@ void MainWindow::onServerConnectionConfigureClient(const QString &clientName)
|
||||||
// End slots
|
// 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()
|
void MainWindow::open()
|
||||||
{
|
{
|
||||||
if (!m_AppConfig.enableUpdateCheck().has_value()) {
|
if (!m_AppConfig.enableUpdateCheck().has_value()) {
|
||||||
|
|
@ -805,9 +761,11 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_SaveOnExit)
|
if (m_SaveOnExit) {
|
||||||
|
m_AppConfig.setMainWindowPosition(pos());
|
||||||
|
m_AppConfig.setMainWindowSize(size());
|
||||||
m_ConfigScopes.save();
|
m_ConfigScopes.save();
|
||||||
|
}
|
||||||
qDebug() << "quitting application";
|
qDebug() << "quitting application";
|
||||||
event->accept();
|
event->accept();
|
||||||
QApplication::quit();
|
QApplication::quit();
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,6 @@ private slots:
|
||||||
void onCoreProcessSecureSocket(bool enabled);
|
void onCoreProcessSecureSocket(bool enabled);
|
||||||
void onVersionCheckerUpdateFound(const QString &version);
|
void onVersionCheckerUpdateFound(const QString &version);
|
||||||
void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason);
|
void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason);
|
||||||
void onWindowSaveTimerTimeout();
|
|
||||||
void onServerConnectionConfigureClient(const QString &clientName);
|
void onServerConnectionConfigureClient(const QString &clientName);
|
||||||
|
|
||||||
void clearSettings();
|
void clearSettings();
|
||||||
|
|
@ -182,10 +181,7 @@ private:
|
||||||
QString configFilename();
|
QString configFilename();
|
||||||
void showConfigureServer(const QString &message);
|
void showConfigureServer(const QString &message);
|
||||||
void restoreWindow();
|
void restoreWindow();
|
||||||
void saveWindow();
|
|
||||||
void setupControls();
|
void setupControls();
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
|
||||||
void moveEvent(QMoveEvent *event) override;
|
|
||||||
void showFirstConnectedMessage();
|
void showFirstConnectedMessage();
|
||||||
void updateStatus();
|
void updateStatus();
|
||||||
void showAndActivate();
|
void showAndActivate();
|
||||||
|
|
@ -194,7 +190,6 @@ private:
|
||||||
QSystemTrayIcon *m_trayIcon = nullptr;
|
QSystemTrayIcon *m_trayIcon = nullptr;
|
||||||
QAbstractButton *m_pCancelButton = nullptr;
|
QAbstractButton *m_pCancelButton = nullptr;
|
||||||
bool m_SecureSocket = false;
|
bool m_SecureSocket = false;
|
||||||
bool m_SaveWindow = false;
|
|
||||||
deskflow::gui::config::ServerConfigDialogState m_ServerConfigDialogState;
|
deskflow::gui::config::ServerConfigDialogState m_ServerConfigDialogState;
|
||||||
bool m_SaveOnExit = true;
|
bool m_SaveOnExit = true;
|
||||||
deskflow::gui::core::WaylandWarnings m_WaylandWarnings;
|
deskflow::gui::core::WaylandWarnings m_WaylandWarnings;
|
||||||
|
|
@ -206,7 +201,6 @@ private:
|
||||||
deskflow::gui::ServerConnection m_ServerConnection;
|
deskflow::gui::ServerConnection m_ServerConnection;
|
||||||
deskflow::gui::ClientConnection m_ClientConnection;
|
deskflow::gui::ClientConnection m_ClientConnection;
|
||||||
deskflow::gui::TlsUtility m_TlsUtility;
|
deskflow::gui::TlsUtility m_TlsUtility;
|
||||||
QTimer m_WindowSaveTimer;
|
|
||||||
QSize m_expandedSize = QSize();
|
QSize m_expandedSize = QSize();
|
||||||
|
|
||||||
QLocalServer *m_guiDupeChecker = nullptr;
|
QLocalServer *m_guiDupeChecker = nullptr;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue