-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventloop.cpp
66 lines (56 loc) · 2.13 KB
/
eventloop.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
#include "eventloop.h"
#include "staticutils.h"
#include <QEvent>
#include <QApplication>
#include <QMainWindow>
EventLoop::EventLoop(QObject *parent) : QEventLoop(parent) {
QMainWindow * wnd = StaticUtils::findMainWindow();
if (wnd != NULL) {
wnd->installEventFilter(this);
QObjectList childs = wnd->children();
for (int i=0;i<childs.count();i++) {
if (childs.at(i)->inherits("QWidget")) childs.at(i)->installEventFilter(this);
}
}
}
EventLoop::~EventLoop() {
QMainWindow * wnd = StaticUtils::findMainWindow();
if (wnd != NULL) {
wnd->removeEventFilter(this);
QObjectList childs = wnd->children();
for (int i=0;i<childs.count();i++) {
if (childs.at(i)->inherits("QWidget")) childs.at(i)->removeEventFilter(this);
}
}
}
void EventLoop::cancel() {
exit(1);
}
bool EventLoop::eventFilter(QObject *obj, QEvent *event) {
if ((event->type() == QEvent::KeyPress) ||
(event->type() == QEvent::KeyRelease) ||
(event->type() == QEvent::MouseButtonDblClick) ||
(event->type() == QEvent::MouseButtonPress) ||
(event->type() == QEvent::MouseButtonRelease) ||
(event->type() == QEvent::MouseMove)) {
if (!obj->inherits("QLineEdit") &&
!obj->inherits("QPushButton") &&
!obj->inherits("QScrollBar") &&
!obj->inherits("QScrollArea")) return true;
}
if ((event->type() == QEvent::Show) && obj->inherits("QDialog")) {
if (QApplication::overrideCursor() != NULL) QApplication::changeOverrideCursor(Qt::ArrowCursor);
}
if ((event->type() == QEvent::Hide) && obj->inherits("QDialog")) {
if (QApplication::overrideCursor() != NULL) QApplication::changeOverrideCursor(Qt::WaitCursor);
}
if (event->type() == QEvent::ChildAdded) {
QChildEvent* ce = static_cast<QChildEvent*>(event);
ce->child()->installEventFilter(this);
}
if (event->type() == QEvent::ChildRemoved) {
QChildEvent* ce = static_cast<QChildEvent*>(event);
ce->child()->removeEventFilter(this);
}
return QEventLoop::eventFilter(obj, event);
}