nekoray_Mahdi-zarei/ui/Icon.cpp
Nova e6149a8d28 feat: Add customized geo asset download &&
Add font size customization &&
Fix an issue with underlying dns detection &&
Improve Tray Icon &&
Fix a crash when Core crashed while running a profile
2024-10-18 00:47:36 +03:30

56 lines
1.5 KiB
C++

#include "Icon.hpp"
#include "main/NekoGui.hpp"
#include <QPainter>
QPixmap Icon::GetTrayIcon(Icon::TrayIconStatus status) {
QPixmap pixmap;
// software embedded icon
auto pixmap_read = QPixmap(":/neko/" + software_name.toLower() + ".png");
if (!pixmap_read.isNull()) pixmap = pixmap_read;
// software pack icon
pixmap_read = QPixmap("../" + software_name.toLower() + ".png");
if (!pixmap_read.isNull()) pixmap = pixmap_read;
// user icon
pixmap_read = QPixmap("./" + software_name.toLower() + ".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.4;
auto margin = side * 0.04;
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));
} else if (status == TrayIconStatus::DNS) {
p.setBrush(QBrush(Qt::darkMagenta));
}
p.drawRoundedRect(
QRect(side - d - margin,
side - d - margin,
d,
d),
radius,
radius);
p.end();
return pixmap;
}
QPixmap Icon::GetMaterialIcon(const QString &name) {
QPixmap pixmap(":/icon/material/" + name + ".svg");
return pixmap;
}