forked from MatsuriDayo/nekoray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIcon.cpp
53 lines (41 loc) · 1.37 KB
/
Icon.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#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.3;
auto margin = side * 0.05;
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;
}
QPixmap Icon::GetMaterialIcon(const QString &name) {
QPixmap pixmap(":/icon/material/" + name + ".svg");
return pixmap;
}