UI: Tray: Make Options menu clickable

This commit is contained in:
Nodir Temirkhodjaev 2023-01-19 13:52:36 +03:00
parent 8e9e2e7657
commit ead247505f
5 changed files with 43 additions and 2 deletions

View File

@ -32,6 +32,7 @@ SOURCES += \
form/controls/appinforow.cpp \
form/controls/checkspincombo.cpp \
form/controls/checktimeperiod.cpp \
form/controls/clickablemenu.cpp \
form/controls/controlutil.cpp \
form/controls/labelcolor.cpp \
form/controls/labeldoublespin.cpp \
@ -193,6 +194,7 @@ HEADERS += \
form/controls/appinforow.h \
form/controls/checkspincombo.h \
form/controls/checktimeperiod.h \
form/controls/clickablemenu.h \
form/controls/controlutil.h \
form/controls/labelcolor.h \
form/controls/labeldoublespin.h \

View File

@ -0,0 +1,15 @@
#include "clickablemenu.h"
#include <QMouseEvent>
ClickableMenu::ClickableMenu(QWidget *parent) : QMenu(parent)
{
setAttribute(Qt::WA_WindowPropagation); // to inherit default font
}
void ClickableMenu::mousePressEvent(QMouseEvent *event)
{
QMenu::mousePressEvent(event);
emit clicked();
}

View File

@ -0,0 +1,20 @@
#ifndef CLICKABLEMENU_H
#define CLICKABLEMENU_H
#include <QMenu>
class ClickableMenu : public QMenu
{
Q_OBJECT
public:
explicit ClickableMenu(QWidget *parent = nullptr);
signals:
void clicked();
protected:
void mousePressEvent(QMouseEvent *event) override;
};
#endif // CLICKABLEMENU_H

View File

@ -10,6 +10,7 @@
#include <conf/confmanager.h>
#include <conf/firewallconf.h>
#include <driver/drivermanager.h>
#include <form/controls/clickablemenu.h>
#include <form/controls/controlutil.h>
#include <form/controls/mainwindow.h>
#include <fortsettings.h>
@ -372,13 +373,15 @@ void TrayIcon::setupTrayMenu()
void TrayIcon::setupTrayMenuOptions()
{
m_optionsMenu = ControlUtil::createMenu(m_menu);
m_optionsMenu = new ClickableMenu(m_menu);
m_optionsMenu->setIcon(IconCache::icon(":/icons/cog.png"));
m_optionsAction = addAction(m_optionsMenu, IconCache::icon(":/icons/cog.png"), QString(),
windowManager(), SLOT(showOptionsWindow()));
addHotKey(m_optionsAction, iniUser()->hotKeyOptions());
connect(m_optionsMenu, &ClickableMenu::clicked, m_optionsAction, &QAction::trigger);
m_zonesAction = addAction(m_optionsMenu, IconCache::icon(":/icons/ip_class.png"), QString(),
windowManager(), SLOT(showZonesWindow()));
addHotKey(m_zonesAction, iniUser()->hotKeyZones());

View File

@ -7,6 +7,7 @@ QT_FORWARD_DECLARE_CLASS(QAction)
QT_FORWARD_DECLARE_CLASS(QActionGroup)
QT_FORWARD_DECLARE_CLASS(QTimer)
class ClickableMenu;
class ConfManager;
class DriverManager;
class FirewallConf;
@ -119,7 +120,7 @@ private:
QMenu *m_menu = nullptr;
QAction *m_programsAction = nullptr;
QMenu *m_optionsMenu = nullptr;
ClickableMenu *m_optionsMenu = nullptr;
QAction *m_optionsAction = nullptr;
QAction *m_statisticsAction = nullptr;
QAction *m_graphAction = nullptr;