mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
47 lines
1.2 KiB
C++
47 lines
1.2 KiB
C++
#include "TrayIcon.hpp"
|
|
|
|
#include <QPainter>
|
|
|
|
QIcon TrayIcon::GetIcon(TrayIcon::TrayIconStatus status) {
|
|
QPixmap pixmap;
|
|
|
|
// software embedded icon
|
|
auto pixmap_read = QPixmap(":/nekoray/nekoray.png");
|
|
if (!pixmap_read.isNull()) pixmap = pixmap_read;
|
|
|
|
// software pack icon
|
|
pixmap_read = QPixmap("../nekoray.png");
|
|
if (!pixmap_read.isNull()) pixmap = pixmap_read;
|
|
|
|
// user icon
|
|
pixmap_read = QPixmap("./nekoray.png");
|
|
if (!pixmap_read.isNull()) pixmap = pixmap_read;
|
|
|
|
if (status == TrayIconStatus::NONE) return pixmap;
|
|
|
|
auto p = QPainter(&pixmap);
|
|
|
|
auto side = pixmap.width();
|
|
auto radius = side * 0.4;
|
|
auto d = side * 0.3;
|
|
auto margin = side * 0.1;
|
|
|
|
if (status == TrayIconStatus::RUNNING) {
|
|
p.setBrush(QBrush(Qt::darkGreen));
|
|
} else if (status == TrayIconStatus::SYSTEM_PROXY) {
|
|
p.setBrush(QBrush(Qt::blue));
|
|
} else if (status == TrayIconStatus::VPN) {
|
|
p.setBrush(QBrush(Qt::red));
|
|
}
|
|
p.drawRoundedRect(
|
|
QRect(side - d - margin,
|
|
side - d - margin,
|
|
d,
|
|
d),
|
|
radius,
|
|
radius);
|
|
p.end();
|
|
|
|
return pixmap;
|
|
}
|