forked from AngryFender/Remini
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
41 lines (32 loc) · 1.31 KB
/
Copy pathmain.cpp
File metadata and controls
41 lines (32 loc) · 1.31 KB
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
#include <QApplication>
#include <QKeyEvent>
#include "appeventfilter.h"
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QIcon icon(QStringLiteral(":/icons/mainIcon"));
a.setWindowIcon(icon);
AppEventFilter filter;
a.installEventFilter(&filter);
MainWindow w;
QObject::connect(&filter, &AppEventFilter::openRecentFiles, &w,
&MainWindow::recentFilesHandler);
// When the application loses focus, release any pending Alt state in
// the event filter. Using applicationStateChanged is more accurate than
// QApplication::focusChanged, which also fires for intra-window widget
// focus changes and would incorrectly synthesise an Alt release.
//
// The event is created on the stack so sendEvent() does not leak it.
QObject::connect(&a, &QGuiApplication::applicationStateChanged,
[&a](Qt::ApplicationState state)
{
if (state != Qt::ApplicationInactive)
return;
QKeyEvent event(QEvent::KeyRelease, Qt::Key_Alt,
Qt::AltModifier);
QCoreApplication::sendEvent(&a, &event);
});
w.show();
return a.exec();
}