-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
63 lines (47 loc) · 1.54 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
#include "widget.h"
#include "configeditordialog.h"
#include <QApplication>
#include <QWindow>
#include <QGuiApplication>
#include <QScreen>
#include <QDebug>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QAction>
#include <QFile>
#include <QProcess>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.setWindowFlags(Qt::FramelessWindowHint | Qt::WindowTransparentForInput | Qt::WindowStaysOnBottomHint | Qt::Tool); //
w.setAttribute(Qt::WA_TranslucentBackground);
w.show();
QSystemTrayIcon *trayIcon = new QSystemTrayIcon;
trayIcon->setIcon(QIcon(":/ico/logo.ico"));
QMenu *trayIconMenu = new QMenu;
QAction *openConfigurator = new QAction("打开设置",&a);
QObject::connect(openConfigurator, &QAction::triggered, [&]() {
ConfigEditorDialog dialog;
dialog.exec();
});
trayIconMenu->addAction(openConfigurator);
trayIconMenu->addSeparator();
QAction *restart = new QAction("重启程序",&a);
QObject::connect(restart, &QAction::triggered, [&]() {
w.restart();
});
trayIconMenu->addAction(restart);
QAction *exitAction = new QAction("退出程序", &a);
QObject::connect(exitAction, &QAction::triggered, &a, &QApplication::quit);
trayIconMenu->addAction(exitAction);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->show();
a.setQuitOnLastWindowClosed(false);
int code = a.exec();
if(code == 312){
QProcess::startDetached(qApp->applicationFilePath());
return 0;
}
return code;
}