-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathdebug_functions.cpp
More file actions
113 lines (89 loc) · 2.95 KB
/
debug_functions.cpp
File metadata and controls
113 lines (89 loc) · 2.95 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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "debug_functions.h"
#include "aoapplication.h"
#include "networkmanager.h"
#include <QCoreApplication>
#include <QDialogButtonBox>
#include <QElapsedTimer>
#include <QMessageBox>
#include <QPushButton>
#include <QTimer>
#include <functional>
debug_functions::debug_functions(AOApplication *parent)
: QObject(parent)
{
ao_app = parent;
}
void call_error(QString p_message)
{
QMessageBox *msgBox = new QMessageBox;
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setText(QCoreApplication::translate("debug_functions", "Error: %1").arg(p_message));
msgBox->setWindowTitle(QCoreApplication::translate("debug_functions", "Error"));
// msgBox->setWindowModality(Qt::NonModal);
msgBox->exec();
}
void call_notice(QString p_message)
{
auto *msgBox = new QMessageBox;
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setText(p_message);
msgBox->setWindowTitle(QCoreApplication::translate("debug_functions", "Notice"));
msgBox->setStandardButtons(QMessageBox::Ok);
msgBox->setDefaultButton(QMessageBox::Ok);
msgBox->defaultButton()->setEnabled(false);
QTimer intervalTimer;
intervalTimer.setInterval(1000);
int counter = 3;
const auto updateCounter = [msgBox, &counter] {
if (counter <= 0)
{
return;
}
msgBox->defaultButton()->setText(QString("%1 (%2)").arg(QDialogButtonBox::tr("OK")).arg(counter));
counter--;
};
QObject::connect(&intervalTimer, &QTimer::timeout, msgBox, updateCounter);
intervalTimer.start();
updateCounter();
QTimer::singleShot(3000, msgBox, [msgBox, &intervalTimer] {
msgBox->defaultButton()->setEnabled(true);
msgBox->defaultButton()->setText(QDialogButtonBox::tr("OK"));
intervalTimer.stop();
});
msgBox->exec();
}
void debug_functions::call_notice_reconnect(QString p_message)
{
auto *msgBox = new QMessageBox;
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setText(p_message);
msgBox->setWindowTitle(QCoreApplication::translate("debug_functions", "Notice"));
msgBox->setStandardButtons(QMessageBox::Ok);
msgBox->setDefaultButton(QMessageBox::Ok);
msgBox->defaultButton()->setEnabled(false);
QPushButton *reconnectButton = msgBox->addButton(QObject::tr("Reconnect"), QMessageBox::ActionRole);
QTimer intervalTimer;
intervalTimer.setInterval(1000);
int counter = 3;
const auto updateCounter = [msgBox, &counter] {
if (counter <= 0)
{
return;
}
msgBox->defaultButton()->setText(QString("%1 (%2)").arg(QDialogButtonBox::tr("OK")).arg(counter));
counter--;
};
QObject::connect(&intervalTimer, &QTimer::timeout, msgBox, updateCounter);
intervalTimer.start();
updateCounter();
QTimer::singleShot(3000, msgBox, [msgBox, &intervalTimer] {
msgBox->defaultButton()->setEnabled(true);
msgBox->defaultButton()->setText(QDialogButtonBox::tr("OK"));
intervalTimer.stop();
});
msgBox->exec();
if (msgBox->clickedButton() == reconnectButton)
{
ao_app->net_manager->reconnect_to_last_server();
}
}