UI: Options: Tray: Add "Show Icon" flag

This commit is contained in:
Nodir Temirkhodjaev 2023-05-06 13:34:38 +03:00
parent ec51aaff34
commit 5577922117
10 changed files with 83 additions and 30 deletions

View File

@ -1,9 +1,11 @@
#include "homewindow.h" #include "homewindow.h"
#include <QPushButton>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <conf/confmanager.h> #include <conf/confmanager.h>
#include <form/controls/controlutil.h> #include <form/controls/controlutil.h>
#include <form/tray/trayicon.h>
#include <manager/windowmanager.h> #include <manager/windowmanager.h>
#include <user/iniuser.h> #include <user/iniuser.h>
#include <util/guiutil.h> #include <util/guiutil.h>
@ -56,6 +58,8 @@ void HomeWindow::retranslateUi()
{ {
this->unsetLocale(); this->unsetLocale();
m_btMenu->setText(tr("Menu"));
this->setWindowTitle(tr("My Fort")); this->setWindowTitle(tr("My Fort"));
} }
@ -76,6 +80,14 @@ void HomeWindow::setupUi()
auto layout = new QVBoxLayout(); auto layout = new QVBoxLayout();
layout->setContentsMargins(6, 6, 6, 6); layout->setContentsMargins(6, 6, 6, 6);
// Header
auto header = setupHeader();
layout->addLayout(header);
// Frame
auto frame = new QHBoxLayout();
layout->addLayout(frame, 1);
this->setLayout(layout); this->setLayout(layout);
// Font // Font
@ -84,3 +96,16 @@ void HomeWindow::setupUi()
// Size // Size
this->setMinimumSize(500, 400); this->setMinimumSize(500, 400);
} }
QLayout *HomeWindow::setupHeader()
{
auto layout = new QHBoxLayout();
m_btMenu = ControlUtil::createButton(":/icons/sheild-96.png");
m_btMenu->setMenu(windowManager()->trayIcon()->menu());
layout->addWidget(m_btMenu);
layout->addStretch();
return layout;
}

View File

@ -33,10 +33,13 @@ private:
void retranslateUi(); void retranslateUi();
void setupUi(); void setupUi();
QLayout *setupHeader();
private: private:
HomeController *m_ctrl = nullptr; HomeController *m_ctrl = nullptr;
WidgetWindowStateWatcher *m_stateWatcher = nullptr; WidgetWindowStateWatcher *m_stateWatcher = nullptr;
QPushButton *m_btMenu = nullptr;
}; };
#endif // HOMEWINDOW_H #endif // HOMEWINDOW_H

View File

@ -189,6 +189,7 @@ void OptionsPage::onRetranslateUi()
tr("Lock the password (unlocked till \"%1\")") tr("Lock the password (unlocked till \"%1\")")
.arg(PasswordDialog::unlockTypeStrings().at(settings()->passwordUnlockType()))); .arg(PasswordDialog::unlockTypeStrings().at(settings()->passwordUnlockType())));
m_cbTrayShowIcon->setText(tr("Show Icon"));
m_cbTrayAnimateAlert->setText(tr("Animate Alert Icon")); m_cbTrayAnimateAlert->setText(tr("Animate Alert Icon"));
m_labelTrayEvent->setText(tr("Event:")); m_labelTrayEvent->setText(tr("Event:"));
m_labelTrayAction->setText(tr("Action:")); m_labelTrayAction->setText(tr("Action:"));
@ -611,6 +612,11 @@ void OptionsPage::setupPasswordLock()
void OptionsPage::setupTrayBox() void OptionsPage::setupTrayBox()
{ {
m_cbTrayShowIcon = ControlUtil::createCheckBox(iniUser()->trayShowIcon(), [&](bool checked) {
iniUser()->setTrayShowIcon(checked);
ctrl()->setIniUserEdited();
});
m_cbTrayAnimateAlert = m_cbTrayAnimateAlert =
ControlUtil::createCheckBox(iniUser()->trayAnimateAlert(), [&](bool checked) { ControlUtil::createCheckBox(iniUser()->trayAnimateAlert(), [&](bool checked) {
iniUser()->setTrayAnimateAlert(checked); iniUser()->setTrayAnimateAlert(checked);
@ -622,6 +628,7 @@ void OptionsPage::setupTrayBox()
auto actionLayout = setupTrayActionLayout(); auto actionLayout = setupTrayActionLayout();
auto layout = new QVBoxLayout(); auto layout = new QVBoxLayout();
layout->addWidget(m_cbTrayShowIcon);
layout->addWidget(m_cbTrayAnimateAlert); layout->addWidget(m_cbTrayAnimateAlert);
layout->addWidget(ControlUtil::createSeparator()); layout->addWidget(ControlUtil::createSeparator());
layout->addLayout(eventLayout); layout->addLayout(eventLayout);

View File

@ -94,6 +94,7 @@ private:
QCheckBox *m_cbPassword = nullptr; QCheckBox *m_cbPassword = nullptr;
QLineEdit *m_editPassword = nullptr; QLineEdit *m_editPassword = nullptr;
QToolButton *m_btPasswordLock = nullptr; QToolButton *m_btPasswordLock = nullptr;
QCheckBox *m_cbTrayShowIcon = nullptr;
QCheckBox *m_cbTrayAnimateAlert = nullptr; QCheckBox *m_cbTrayAnimateAlert = nullptr;
QLabel *m_labelTrayEvent = nullptr; QLabel *m_labelTrayEvent = nullptr;
QComboBox *m_comboTrayEvent = nullptr; QComboBox *m_comboTrayEvent = nullptr;

View File

@ -265,6 +265,16 @@ void TrayIcon::updateTrayMenu(bool onlyFlags)
updateClickActions(); updateClickActions();
} }
void TrayIcon::quitProgram()
{
if (iniUser()->confirmQuit()) {
windowManager()->showConfirmBox(
[&] { windowManager()->quit(); }, tr("Are you sure you want to quit the program?"));
} else {
windowManager()->quit();
}
}
void TrayIcon::switchTrayMenu(bool /*checked*/) void TrayIcon::switchTrayMenu(bool /*checked*/)
{ {
showTrayMenu(QCursor::pos()); showTrayMenu(QCursor::pos());
@ -615,16 +625,6 @@ void TrayIcon::switchFilterMode(QAction *action)
} }
} }
void TrayIcon::quitProgram()
{
if (iniUser()->confirmQuit()) {
windowManager()->showConfirmBox(
[&] { windowManager()->quit(); }, tr("Are you sure you want to quit the program?"));
} else {
windowManager()->quit();
}
}
void TrayIcon::addHotKey(QAction *action, const QString &shortcutText) void TrayIcon::addHotKey(QAction *action, const QString &shortcutText)
{ {
if (shortcutText.isEmpty()) if (shortcutText.isEmpty())

View File

@ -60,6 +60,8 @@ public:
DriverManager *driverManager() const; DriverManager *driverManager() const;
WindowManager *windowManager() const; WindowManager *windowManager() const;
QMenu *menu() const { return m_menu; }
static ActionType clickEventActionType(IniUser *iniUser, ClickType clickType); static ActionType clickEventActionType(IniUser *iniUser, ClickType clickType);
static void setClickEventActionType( static void setClickEventActionType(
IniUser *iniUser, ClickType clickType, ActionType actionType); IniUser *iniUser, ClickType clickType, ActionType actionType);
@ -70,6 +72,8 @@ public slots:
void showTrayMenu(const QPoint &pos); void showTrayMenu(const QPoint &pos);
void updateTrayMenu(bool onlyFlags = false); void updateTrayMenu(bool onlyFlags = false);
void quitProgram();
protected slots: protected slots:
void switchTrayMenu(bool checked); void switchTrayMenu(bool checked);
void switchFilterModeMenu(bool checked); void switchFilterModeMenu(bool checked);
@ -80,7 +84,6 @@ protected slots:
void switchTrayFlag(bool checked); void switchTrayFlag(bool checked);
void switchFilterMode(QAction *action); void switchFilterMode(QAction *action);
void quitProgram();
private: private:
void setupController(); void setupController();

View File

@ -318,12 +318,19 @@ void FortManager::setupTranslationManager()
void FortManager::show() void FortManager::show()
{ {
auto windowManager = IoC<WindowManager>(); auto windowManager = IoC<WindowManager>();
const IniUser &iniUser = IoC<UserSettings>()->iniUser();
setupTranslationManager(); setupTranslationManager();
windowManager->showTrayIcon(); windowManager->setupTrayIcon();
if (IoC<UserSettings>()->iniUser().graphWindowVisible()) { if (iniUser.trayShowIcon()) {
windowManager->showTrayIcon();
} else {
windowManager->showHomeWindow();
}
if (iniUser.graphWindowVisible()) {
windowManager->showGraphWindow(); windowManager->showGraphWindow();
} }
} }

View File

@ -146,18 +146,6 @@ void WindowManager::closeMainWindow()
m_mainWindow = nullptr; m_mainWindow = nullptr;
} }
void WindowManager::setupTrayIcon()
{
m_trayIcon = new TrayIcon(this);
connect(m_trayIcon, &QSystemTrayIcon::messageClicked, this,
&WindowManager::onTrayMessageClicked);
auto confManager = IoC<ConfManager>();
connect(confManager, &ConfManager::appAlerted, m_trayIcon,
[&] { m_trayIcon->updateTrayIcon(/*alerted=*/true); });
}
void WindowManager::setupHomeWindow() void WindowManager::setupHomeWindow()
{ {
m_homeWindow = new HomeWindow(); m_homeWindow = new HomeWindow();
@ -245,11 +233,24 @@ void WindowManager::closeAll()
closeMainWindow(); closeMainWindow();
} }
void WindowManager::setupTrayIcon()
{
if (m_trayIcon)
return;
m_trayIcon = new TrayIcon(this);
connect(m_trayIcon, &QSystemTrayIcon::messageClicked, this,
&WindowManager::onTrayMessageClicked);
auto confManager = IoC<ConfManager>();
connect(confManager, &ConfManager::appAlerted, m_trayIcon,
[&] { m_trayIcon->updateTrayIcon(/*alerted=*/true); });
}
void WindowManager::showTrayIcon() void WindowManager::showTrayIcon()
{ {
if (!m_trayIcon) { setupTrayIcon();
setupTrayIcon();
}
m_trayIcon->show(); m_trayIcon->show();
} }
@ -290,6 +291,10 @@ void WindowManager::closeHomeWindow()
m_homeWindow->deleteLater(); m_homeWindow->deleteLater();
m_homeWindow = nullptr; m_homeWindow = nullptr;
if (!trayIcon()->isVisible()) {
trayIcon()->quitProgram();
}
} }
void WindowManager::showProgramsWindow() void WindowManager::showProgramsWindow()

View File

@ -51,6 +51,7 @@ signals:
public slots: public slots:
void setupAppPalette(); void setupAppPalette();
void setupTrayIcon();
void showTrayIcon(); void showTrayIcon();
void closeTrayIcon(); void closeTrayIcon();
void showTrayMessage( void showTrayMessage(
@ -106,8 +107,6 @@ private:
void setupMainWindow(); void setupMainWindow();
void closeMainWindow(); void closeMainWindow();
void setupTrayIcon();
void setupHomeWindow(); void setupHomeWindow();
void setupProgramsWindow(); void setupProgramsWindow();
void setupOptionsWindow(); void setupOptionsWindow();

View File

@ -41,6 +41,9 @@ public:
"filterModeAllow", "filterModeIgnore" }; "filterModeAllow", "filterModeIgnore" };
} }
bool trayShowIcon() const { return valueBool("tray/showIcon", true); }
void setTrayShowIcon(bool v) { setValue("tray/showIcon", v, true); }
bool trayAnimateAlert() const { return valueBool("tray/animateAlert"); } bool trayAnimateAlert() const { return valueBool("tray/animateAlert"); }
void setTrayAnimateAlert(bool v) { setValue("tray/animateAlert", v); } void setTrayAnimateAlert(bool v) { setValue("tray/animateAlert", v); }