-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.cpp
executable file
·89 lines (76 loc) · 2.88 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <QApplication>
#include <QQmlApplicationEngine>
#include "file.h"
#include <QSystemTrayIcon>
#include <QAction>
#include <QMenu>
#include <QQmlContext>
#include <QDebug>
#include <QQuickWindow>
#include <QTranslator>
#include <QLocale>
void addQMLApis() {
qmlRegisterType<File>("org.eminfedar.file", 1, 0, "File");
qputenv("QML_DISABLE_DISTANCEFIELD", "1");
}
void addSysTrayIcon(QQmlApplicationEngine* engine) {
QObject *root = 0;
if (engine->rootObjects().size() > 0)
{
root = engine->rootObjects().at(0);
QAction *restoreAction = new QAction(QObject::tr("Show / Hide"), root);
root->connect(restoreAction, &QAction::triggered, [=](){
root->setProperty("visible", !root->property("visible").toBool());
});
QAction *quitAction = new QAction(QObject::tr("Exit"), root);
root->connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
QMenu *trayIconMenu = new QMenu();
trayIconMenu->addAction(restoreAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
QSystemTrayIcon *trayIcon = new QSystemTrayIcon(root);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->setIcon(QIcon(":/icons/vaktisalah.png"));
trayIcon->show();
trayIcon->connect(trayIcon, &QSystemTrayIcon::activated, [=](QSystemTrayIcon::ActivationReason reason){
if ( reason == QSystemTrayIcon::Trigger || reason == QSystemTrayIcon::DoubleClick){
root->setProperty("visible", !root->property("visible").toBool());
}
});
}
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// Get Translations
QTranslator t;
if (t.load(":/translations/vaktisalah_" + QLocale::system().name())) {
app.installTranslator(&t);
} else {
qDebug() << "Could not load the translation";
}
// Add QML Apis
addQMLApis();
// Little Styling
app.setStyleSheet("QMenu{"
"background: #292929;"
"color: #FFFFFF;"
"}"
""
"QMenu::item:selected{"
"background-color: rgb(0, 150, 0);"
"}"
""
"QMenu::item:disabled{"
"color: #BBBBBB;"
"background-color: #393939;"
"}");
app.setWindowIcon(QIcon(":/icons/vaktisalah.png"));
// QML Engine
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("iconTray", QIcon(":/icons/vaktisalah.png"));
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QQuickWindow::setTextRenderType(QQuickWindow::NativeTextRendering);
addSysTrayIcon(&engine);
return app.exec();
}