mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-23 02:00:20 +07:00
ref code sort files
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
#include "wintrayiconbackend.h"
|
||||
|
||||
#include "ui/utils/trayIconCommon.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
WinTrayIconBackend::WinTrayIconBackend(QObject *parent) : m_trayIcon(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void WinTrayIconBackend::setMenu(QMenu *menu)
|
||||
{
|
||||
m_trayIcon.setContextMenu(menu);
|
||||
}
|
||||
|
||||
void WinTrayIconBackend::setToolTip(const QString &tooltip)
|
||||
{
|
||||
m_trayIcon.setToolTip(tooltip);
|
||||
}
|
||||
|
||||
void WinTrayIconBackend::show()
|
||||
{
|
||||
m_trayIcon.show();
|
||||
}
|
||||
|
||||
void WinTrayIconBackend::applyVisual(const TrayIconVisual &visual)
|
||||
{
|
||||
const qreal opacity = TrayIconCommon::opacityForState(visual.connectionState);
|
||||
const QColor indicatorColor = TrayIconCommon::indicatorColorForState(visual.connectionState);
|
||||
m_trayIcon.setIcon(buildTrayIcon(opacity, visual.darkTheme, indicatorColor));
|
||||
}
|
||||
|
||||
void WinTrayIconBackend::showMessage(const QString &title, const QString &message, const TrayIconVisual &visual,
|
||||
int timerMsec)
|
||||
{
|
||||
m_trayIcon.showMessage(title, message,
|
||||
buildTrayIcon(TrayIconCommon::kConnectedOpacity, visual.darkTheme,
|
||||
TrayIconCommon::indicatorColorForState(Vpn::ConnectionState::Connected)),
|
||||
timerMsec);
|
||||
}
|
||||
|
||||
void WinTrayIconBackend::rebuildMenu()
|
||||
{
|
||||
}
|
||||
|
||||
void WinTrayIconBackend::setActivatedHandler(std::function<void(QSystemTrayIcon::ActivationReason)> handler)
|
||||
{
|
||||
if (!handler) {
|
||||
return;
|
||||
}
|
||||
|
||||
QObject::connect(&m_trayIcon, &QSystemTrayIcon::activated, m_trayIcon.parent(),
|
||||
[handler](QSystemTrayIcon::ActivationReason reason) { handler(reason); });
|
||||
}
|
||||
|
||||
QIcon WinTrayIconBackend::buildTrayIcon(qreal opacity, bool darkTheme, const QColor &indicatorColor) const
|
||||
{
|
||||
return TrayIconCommon::buildIcon(opacity, darkTheme, indicatorColor);
|
||||
}
|
||||
|
||||
std::unique_ptr<TrayIconBackend> createTrayIconBackend(QObject *parent)
|
||||
{
|
||||
return std::make_unique<WinTrayIconBackend>(parent);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef WINTRAYICONBACKEND_H
|
||||
#define WINTRAYICONBACKEND_H
|
||||
|
||||
#include "ui/utils/trayIconBackend.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QIcon>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
class WinTrayIconBackend final : public TrayIconBackend
|
||||
{
|
||||
public:
|
||||
explicit WinTrayIconBackend(QObject *parent);
|
||||
|
||||
void setMenu(QMenu *menu) override;
|
||||
void setToolTip(const QString &tooltip) override;
|
||||
void show() override;
|
||||
void applyVisual(const TrayIconVisual &visual) override;
|
||||
void showMessage(const QString &title, const QString &message, const TrayIconVisual &visual, int timerMsec) override;
|
||||
void rebuildMenu() override;
|
||||
void setActivatedHandler(std::function<void(QSystemTrayIcon::ActivationReason)> handler) override;
|
||||
|
||||
private:
|
||||
QIcon buildTrayIcon(qreal opacity, bool darkTheme, const QColor &indicatorColor) const;
|
||||
|
||||
QSystemTrayIcon m_trayIcon;
|
||||
};
|
||||
|
||||
#endif // WINTRAYICONBACKEND_H
|
||||
@@ -0,0 +1,26 @@
|
||||
#include "wintraytheme.h"
|
||||
|
||||
#include "platforms/windows/windowsutils.h"
|
||||
#include "ui/utils/trayThemeChangeFilter.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QGuiApplication>
|
||||
#include <QObject>
|
||||
#include <QStyleHints>
|
||||
|
||||
void WinTrayTheme::installThemeObserver(const std::function<void()> &onThemeChanged, QObject *parent)
|
||||
{
|
||||
if (!onThemeChanged || !parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (QStyleHints *styleHints = QGuiApplication::styleHints()) {
|
||||
QObject::connect(styleHints, &QStyleHints::colorSchemeChanged, parent, [onThemeChanged]() { onThemeChanged(); });
|
||||
}
|
||||
|
||||
qApp->installEventFilter(new TrayThemeChangeFilter(onThemeChanged, parent));
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
WindowsUtils::installThemeChangeObserver(onThemeChanged);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef WINTRAYTHEME_H
|
||||
#define WINTRAYTHEME_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
class QObject;
|
||||
|
||||
namespace WinTrayTheme
|
||||
{
|
||||
|
||||
void installThemeObserver(const std::function<void()> &onThemeChanged, QObject *parent);
|
||||
|
||||
} // namespace WinTrayTheme
|
||||
|
||||
#endif // WINTRAYTHEME_H
|
||||
Reference in New Issue
Block a user