mirror of
https://github.com/tnodir/fort
synced 2024-11-15 05:25:56 +00:00
UI: Tray: Change icon color on some states
This commit is contained in:
parent
538d7dc752
commit
b5bcbac542
@ -73,10 +73,10 @@ bool DriverManager::openDevice()
|
||||
{
|
||||
const bool res = device()->open(DriverCommon::deviceName());
|
||||
|
||||
emit isDeviceOpenedChanged();
|
||||
|
||||
updateErrorCode(res);
|
||||
|
||||
emit isDeviceOpenedChanged();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -84,10 +84,10 @@ bool DriverManager::closeDevice()
|
||||
{
|
||||
const bool res = device()->close();
|
||||
|
||||
emit isDeviceOpenedChanged();
|
||||
|
||||
updateErrorCode(true);
|
||||
|
||||
emit isDeviceOpenedChanged();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <conf/confmanager.h>
|
||||
#include <conf/firewallconf.h>
|
||||
#include <driver/drivermanager.h>
|
||||
#include <fortmanager.h>
|
||||
#include <fortsettings.h>
|
||||
#include <manager/hotkeymanager.h>
|
||||
@ -50,6 +51,11 @@ HotKeyManager *TrayController::hotKeyManager() const
|
||||
return IoC<HotKeyManager>();
|
||||
}
|
||||
|
||||
DriverManager *TrayController::driverManager() const
|
||||
{
|
||||
return IoC<DriverManager>();
|
||||
}
|
||||
|
||||
TranslationManager *TrayController::translationManager() const
|
||||
{
|
||||
return IoC<TranslationManager>();
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <QObject>
|
||||
|
||||
class ConfManager;
|
||||
class DriverManager;
|
||||
class FirewallConf;
|
||||
class FortManager;
|
||||
class FortSettings;
|
||||
@ -27,6 +28,7 @@ public:
|
||||
IniOptions *ini() const;
|
||||
IniUser *iniUser() const;
|
||||
HotKeyManager *hotKeyManager() const;
|
||||
DriverManager *driverManager() const;
|
||||
TranslationManager *translationManager() const;
|
||||
WindowManager *windowManager() const;
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <conf/appgroup.h>
|
||||
#include <conf/confmanager.h>
|
||||
#include <conf/firewallconf.h>
|
||||
#include <driver/drivermanager.h>
|
||||
#include <form/controls/controlutil.h>
|
||||
#include <form/controls/mainwindow.h>
|
||||
#include <fortsettings.h>
|
||||
@ -145,6 +146,7 @@ QAction *addAction(QWidget *widget, const QIcon &icon, const QString &text,
|
||||
TrayIcon::TrayIcon(QObject *parent) :
|
||||
QSystemTrayIcon(parent),
|
||||
m_trayTriggered(false),
|
||||
m_alerted(false),
|
||||
m_animatedAlert(false),
|
||||
m_ctrl(new TrayController(this))
|
||||
{
|
||||
@ -152,6 +154,11 @@ TrayIcon::TrayIcon(QObject *parent) :
|
||||
setupController();
|
||||
|
||||
connect(this, &QSystemTrayIcon::activated, this, &TrayIcon::onTrayActivated);
|
||||
|
||||
connect(confManager(), &ConfManager::confChanged, this, &TrayIcon::updateTrayMenu);
|
||||
connect(confManager(), &ConfManager::iniUserChanged, this, &TrayIcon::updateTrayMenu);
|
||||
connect(driverManager(), &DriverManager::isDeviceOpenedChanged, this,
|
||||
&TrayIcon::updateTrayIconShape);
|
||||
}
|
||||
|
||||
FortSettings *TrayIcon::settings() const
|
||||
@ -184,6 +191,11 @@ HotKeyManager *TrayIcon::hotKeyManager() const
|
||||
return ctrl()->hotKeyManager();
|
||||
}
|
||||
|
||||
DriverManager *TrayIcon::driverManager() const
|
||||
{
|
||||
return ctrl()->driverManager();
|
||||
}
|
||||
|
||||
WindowManager *TrayIcon::windowManager() const
|
||||
{
|
||||
return ctrl()->windowManager();
|
||||
@ -211,9 +223,12 @@ void TrayIcon::onTrayActivated(QSystemTrayIcon::ActivationReason reason)
|
||||
|
||||
void TrayIcon::updateTrayIcon(bool alerted)
|
||||
{
|
||||
updateAnimatedTrayIcon(alerted);
|
||||
m_alerted = alerted;
|
||||
m_animatedAlert = false;
|
||||
|
||||
updateAlertTimer(alerted);
|
||||
updateAlertTimer();
|
||||
|
||||
updateTrayIconShape();
|
||||
}
|
||||
|
||||
void TrayIcon::showTrayMenu(const QPoint &pos)
|
||||
@ -227,6 +242,7 @@ void TrayIcon::updateTrayMenu(bool onlyFlags)
|
||||
updateAppGroupActions();
|
||||
}
|
||||
|
||||
updateTrayIconShape();
|
||||
updateTrayMenuFlags();
|
||||
updateHotKeys();
|
||||
}
|
||||
@ -286,8 +302,6 @@ void TrayIcon::setupUi()
|
||||
setupTrayMenu();
|
||||
updateTrayMenu();
|
||||
|
||||
updateTrayIcon();
|
||||
|
||||
updateClickActions();
|
||||
}
|
||||
|
||||
@ -441,7 +455,7 @@ void TrayIcon::updateAppGroupActions()
|
||||
}
|
||||
}
|
||||
|
||||
void TrayIcon::updateAlertTimer(bool alerted)
|
||||
void TrayIcon::updateAlertTimer()
|
||||
{
|
||||
if (!iniUser()->trayAnimateAlert())
|
||||
return;
|
||||
@ -452,25 +466,35 @@ void TrayIcon::updateAlertTimer(bool alerted)
|
||||
|
||||
connect(m_alertTimer, &QTimer::timeout, this, [&] {
|
||||
m_animatedAlert = !m_animatedAlert;
|
||||
updateAnimatedTrayIcon(/*alerted=*/true, m_animatedAlert);
|
||||
updateTrayIconShape();
|
||||
});
|
||||
}
|
||||
|
||||
m_animatedAlert = alerted;
|
||||
m_animatedAlert = m_alerted;
|
||||
|
||||
if (alerted) {
|
||||
if (m_alerted) {
|
||||
m_alertTimer->start();
|
||||
} else {
|
||||
m_alertTimer->stop();
|
||||
}
|
||||
}
|
||||
|
||||
void TrayIcon::updateAnimatedTrayIcon(bool alerted, bool animated)
|
||||
void TrayIcon::updateTrayIconShape()
|
||||
{
|
||||
const auto icon = alerted
|
||||
? (animated ? IconCache::icon(":/icons/error.png")
|
||||
: GuiUtil::overlayIcon(":/icons/sheild-96.png", ":/icons/error.png"))
|
||||
: IconCache::icon(":/icons/sheild-96.png");
|
||||
QString mainIconPath;
|
||||
|
||||
if (!conf()->filterEnabled() || !driverManager()->isDeviceOpened()) {
|
||||
mainIconPath = ":/icons/sheild-96_gray.png";
|
||||
} else if (conf()->stopTraffic() || conf()->stopInetTraffic()) {
|
||||
mainIconPath = ":/icons/sheild-96_red.png";
|
||||
} else {
|
||||
mainIconPath = ":/icons/sheild-96.png";
|
||||
}
|
||||
|
||||
const auto icon = m_alerted
|
||||
? (m_animatedAlert ? IconCache::icon(":/icons/error.png")
|
||||
: GuiUtil::overlayIcon(mainIconPath, ":/icons/error.png"))
|
||||
: IconCache::icon(mainIconPath);
|
||||
|
||||
this->setIcon(icon);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ QT_FORWARD_DECLARE_CLASS(QActionGroup)
|
||||
QT_FORWARD_DECLARE_CLASS(QTimer)
|
||||
|
||||
class ConfManager;
|
||||
class DriverManager;
|
||||
class FirewallConf;
|
||||
class FortSettings;
|
||||
class HotKeyManager;
|
||||
@ -52,6 +53,7 @@ public:
|
||||
IniOptions *ini() const;
|
||||
IniUser *iniUser() const;
|
||||
HotKeyManager *hotKeyManager() const;
|
||||
DriverManager *driverManager() const;
|
||||
WindowManager *windowManager() const;
|
||||
|
||||
ActionType clickEventActionType(ClickType clickType) const;
|
||||
@ -87,8 +89,8 @@ private:
|
||||
void updateTrayMenuFlags();
|
||||
void updateAppGroupActions();
|
||||
|
||||
void updateAlertTimer(bool alerted);
|
||||
void updateAnimatedTrayIcon(bool alerted, bool animated = false);
|
||||
void updateAlertTimer();
|
||||
void updateTrayIconShape();
|
||||
|
||||
void addHotKey(QAction *action, const QString &shortcutText);
|
||||
void updateHotKeys();
|
||||
@ -108,6 +110,7 @@ private:
|
||||
|
||||
private:
|
||||
bool m_trayTriggered : 1;
|
||||
bool m_alerted : 1;
|
||||
bool m_animatedAlert : 1;
|
||||
|
||||
TrayController *m_ctrl = nullptr;
|
||||
|
@ -38,6 +38,8 @@
|
||||
<file>icons/pencil.png</file>
|
||||
<file>icons/play.png</file>
|
||||
<file>icons/sheild-96.png</file>
|
||||
<file>icons/sheild-96_gray.png</file>
|
||||
<file>icons/sheild-96_red.png</file>
|
||||
<file>icons/save_as.png</file>
|
||||
<file>icons/server_components.png</file>
|
||||
<file>icons/time.png</file>
|
||||
|
BIN
src/ui/icons/sheild-96_gray.png
Normal file
BIN
src/ui/icons/sheild-96_gray.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.2 KiB |
BIN
src/ui/icons/sheild-96_red.png
Normal file
BIN
src/ui/icons/sheild-96_red.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.9 KiB |
@ -132,10 +132,8 @@ void WindowManager::setupTrayIcon()
|
||||
&WindowManager::onTrayMessageClicked);
|
||||
|
||||
auto confManager = IoC<ConfManager>();
|
||||
connect(confManager, &ConfManager::confChanged, m_trayIcon, &TrayIcon::updateTrayMenu);
|
||||
connect(confManager, &ConfManager::iniUserChanged, m_trayIcon, &TrayIcon::updateTrayMenu);
|
||||
connect(confManager, &ConfManager::appAlerted, m_trayIcon,
|
||||
[&] { m_trayIcon->updateTrayIcon(true); });
|
||||
[&] { m_trayIcon->updateTrayIcon(/*alerted=*/true); });
|
||||
}
|
||||
|
||||
void WindowManager::setupProgramsWindow()
|
||||
@ -145,7 +143,7 @@ void WindowManager::setupProgramsWindow()
|
||||
|
||||
connect(m_progWindow, &ProgramsWindow::aboutToClose, this, &WindowManager::closeProgramsWindow);
|
||||
connect(m_progWindow, &ProgramsWindow::activationChanged, m_trayIcon,
|
||||
[&] { m_trayIcon->updateTrayIcon(false); });
|
||||
[&] { m_trayIcon->updateTrayIcon(/*alerted=*/false); });
|
||||
}
|
||||
|
||||
void WindowManager::setupOptionsWindow()
|
||||
|
Loading…
Reference in New Issue
Block a user