blob: d3ff2f7d513b9b7470ad0d0ea20721c5689b31c3 (
plain)
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
90
91
|
#pragma once
#include <QMainWindow>
class LockWidget
{
public:
// reason to show the widget
//
enum Reasons
{
NoReason = 0,
// lock the ui
LockUI,
// because the output is required
OutputRequired,
// to prevent exiting until all processes are completed
PreventExit
};
// returned by result()
//
enum Results
{
NoResult = 0,
// the widget is still up
StillLocked,
// force unlock was clicked
ForceUnlocked,
// cancel was clicked
Cancelled
};
// if `reason` is not NoReason, lock() is called with it
//
LockWidget(QWidget* parent, Reasons reason=NoReason);
~LockWidget();
void lock(Reasons reason);
void unlock();
void setInfo(DWORD pid, const QString& name);
Results result() const;
private:
class Filter : public QObject
{
public:
std::function<void ()> resized;
std::function<void ()> closed;
protected:
bool eventFilter(QObject* o, QEvent* e) override
{
if (e->type() == QEvent::Resize) {
if (resized) {
resized();
}
} else if (e->type() == QEvent::Close) {
if (closed) {
closed();
}
}
return QObject::eventFilter(o, e);
}
};
QWidget* m_parent;
std::unique_ptr<QWidget> m_overlay;
QLabel* m_info;
Results m_result;
std::unique_ptr<Filter> m_filter;
std::vector<QPointer<QWidget>> m_disabled;
void createUi(Reasons reason);
void onForceUnlock();
void onCancel();
void disableAll();
void enableAll();
void disable(QWidget* w);
};
|