From 2806813f48765a81a16ed3abbd98e4a7ac4e4118 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Mon, 8 May 2023 16:01:15 +0300 Subject: [PATCH] UI: HomeWindow: Show menu on activation --- src/ui/form/home/homewindow.cpp | 6 ++++++ src/ui/form/tray/trayicon.cpp | 3 +++ src/ui/fortmanager.cpp | 1 + src/ui/manager/windowmanager.cpp | 31 ++++++++++++++++--------------- src/ui/manager/windowmanager.h | 2 +- 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/ui/form/home/homewindow.cpp b/src/ui/form/home/homewindow.cpp index 1f986ca4..7512000b 100644 --- a/src/ui/form/home/homewindow.cpp +++ b/src/ui/form/home/homewindow.cpp @@ -23,6 +23,12 @@ HomeWindow::HomeWindow(QWidget *parent) : setupUi(); setupController(); setupStateWatcher(); + + connect(this, &HomeWindow::activationChanged, this, [&] { + if (isActiveWindow()) { + m_btMenu->showMenu(); + } + }); } ConfManager *HomeWindow::confManager() const diff --git a/src/ui/form/tray/trayicon.cpp b/src/ui/form/tray/trayicon.cpp index c34f56cb..d47e248f 100644 --- a/src/ui/form/tray/trayicon.cpp +++ b/src/ui/form/tray/trayicon.cpp @@ -240,6 +240,9 @@ void TrayIcon::onTrayActivated(QSystemTrayIcon::ActivationReason reason) void TrayIcon::updateTrayIcon(bool alerted) { + if (m_alerted == alerted) + return; + m_alerted = alerted; m_animatedAlert = false; diff --git a/src/ui/fortmanager.cpp b/src/ui/fortmanager.cpp index b954ef26..7c8d75c7 100644 --- a/src/ui/fortmanager.cpp +++ b/src/ui/fortmanager.cpp @@ -327,6 +327,7 @@ void FortManager::show() if (iniUser.trayShowIcon()) { windowManager->showTrayIcon(); } else { + windowManager->setupHomeWindow(/*quitOnClose=*/true); windowManager->showHomeWindow(); } diff --git a/src/ui/manager/windowmanager.cpp b/src/ui/manager/windowmanager.cpp index 020ea2ea..c848af3b 100644 --- a/src/ui/manager/windowmanager.cpp +++ b/src/ui/manager/windowmanager.cpp @@ -146,14 +146,6 @@ void WindowManager::closeMainWindow() m_mainWindow = nullptr; } -void WindowManager::setupHomeWindow() -{ - m_homeWindow = new HomeWindow(); - m_homeWindow->restoreWindowState(); - - connect(m_homeWindow, &HomeWindow::aboutToClose, this, &WindowManager::closeHomeWindow); -} - void WindowManager::setupProgramsWindow() { m_progWindow = new ProgramsWindow(); @@ -269,14 +261,27 @@ void WindowManager::showTrayMessage(const QString &message, WindowManager::TrayM m_trayIcon->showMessage(QGuiApplication::applicationDisplayName(), message); } +void WindowManager::setupHomeWindow(bool quitOnClose) +{ + if (m_homeWindow) + return; + + m_homeWindow = new HomeWindow(); + m_homeWindow->restoreWindowState(); + + if (quitOnClose) { + connect(m_homeWindow, &HomeWindow::aboutToClose, trayIcon(), &TrayIcon::quitProgram); + } else { + connect(m_homeWindow, &HomeWindow::aboutToClose, this, &WindowManager::closeHomeWindow); + } +} + void WindowManager::showHomeWindow() { if (!widgetVisibleByCheckPassword(m_homeWindow)) return; - if (!m_homeWindow) { - setupHomeWindow(); - } + setupHomeWindow(); showWidget(m_homeWindow); } @@ -291,10 +296,6 @@ void WindowManager::closeHomeWindow() m_homeWindow->deleteLater(); m_homeWindow = nullptr; - - if (!trayIcon()->isVisible()) { - trayIcon()->quitProgram(); - } } void WindowManager::showProgramsWindow() diff --git a/src/ui/manager/windowmanager.h b/src/ui/manager/windowmanager.h index 3226ac24..749e1218 100644 --- a/src/ui/manager/windowmanager.h +++ b/src/ui/manager/windowmanager.h @@ -57,6 +57,7 @@ public slots: void showTrayMessage( const QString &message, WindowManager::TrayMessageType type = MessageOptions); + void setupHomeWindow(bool quitOnClose = false); void showHomeWindow(); void closeHomeWindow(); @@ -107,7 +108,6 @@ private: void setupMainWindow(); void closeMainWindow(); - void setupHomeWindow(); void setupProgramsWindow(); void setupOptionsWindow(); void setupPoliciesWindow();