Repository navigation
Expand file tree
/
Copy pathUniversalDialogQtBinding.cpp
More file actions
137 lines (132 loc) · 4.45 KB
/
Copy pathUniversalDialogQtBinding.cpp
File metadata and controls
137 lines (132 loc) · 4.45 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <QMessageBox>
#include <QString>
#include <QObject>
#include <QApplication>
enum class DialogButton
{
AbortRetryIgnore = 0x00000002L,
Ok = 0x00000000L,
OkCancel = 0x00000001L,
RetryCancel = 0x00000005L,
YesNo = 0x00000004L,
YesNoCancel = 0x00000003L,
CancelTryContinue = 0x00000006L,
};
enum class DialogIcon
{
Exclamation = 0x00000030L,
Information = 0x00000040L,
Error = 0x00000010L,
None = 0
};
enum class DialogResult
{
Abort = 3,
Cancel = 2,
Continue = 11,
Ignore = 5,
No = 7,
Ok = 1,
Retry = 4,
TryAgain = 10,
Yes = 6,
Failed = 0
};
extern "C"
{
DialogResult ShowMessageDialog(char *caption, char *text, DialogButton button, DialogIcon icon);
}
//Constructs a QApplication to make QMessageBox useable.
static int argc = 0;
static QApplication app(argc, nullptr);
DialogResult ShowMessageDialog(char *caption, char *text, DialogButton button, DialogIcon icon)
{
QMessageBox msgBox;
msgBox.setText(QString(text));
msgBox.setInformativeText(QString(caption));
switch (icon)
{
case DialogIcon::Error:
msgBox.setIcon(QMessageBox::Critical);
break;
case DialogIcon::Information:
msgBox.setIcon(QMessageBox::Information);
break;
case DialogIcon::Exclamation:
msgBox.setIcon(QMessageBox::Warning);
break;
default:
break;
}
QPushButton *abort = nullptr, *retry = nullptr, *ignore = nullptr,
*cancel = nullptr, *tryBtn = nullptr, *continueBtn = nullptr,
*ok = nullptr, *yes = nullptr, *no = nullptr;
switch (button)
{
case DialogButton::AbortRetryIgnore:
abort = msgBox.addButton(QMessageBox::Abort);
retry = msgBox.addButton(QMessageBox::Retry);
ignore = msgBox.addButton(QMessageBox::Ignore);
msgBox.exec();
if ((QPushButton *)msgBox.clickedButton() == abort)
return DialogResult::Abort;
if ((QPushButton *)msgBox.clickedButton() == retry)
return DialogResult::Retry;
if ((QPushButton *)msgBox.clickedButton() == ignore)
return DialogResult::Ignore;
return DialogResult::Failed;
case DialogButton::CancelTryContinue:
cancel = msgBox.addButton(QMessageBox::Cancel);
tryBtn = msgBox.addButton(QObject::tr("Try Again"), QMessageBox::ActionRole);
continueBtn = msgBox.addButton(QObject::tr("Continue"), QMessageBox::ActionRole);
msgBox.exec();
if ((QPushButton *)msgBox.clickedButton() == cancel)
return DialogResult::Cancel;
if ((QPushButton *)msgBox.clickedButton() == tryBtn)
return DialogResult::TryAgain;
if ((QPushButton *)msgBox.clickedButton() == continueBtn)
return DialogResult::Continue;
return DialogResult::Failed;
case DialogButton::Ok:
ok = msgBox.addButton(QMessageBox::Ok);
msgBox.exec();
if ((QPushButton *)msgBox.clickedButton() == ok)
return DialogResult::Ok;
return DialogResult::Failed;
case DialogButton::YesNo:
yes = msgBox.addButton(QMessageBox::Yes);
no = msgBox.addButton(QMessageBox::No);
msgBox.exec();
if ((QPushButton *)msgBox.clickedButton() == yes)
return DialogResult::Yes;
if ((QPushButton *)msgBox.clickedButton() == no)
return DialogResult::No;
return DialogResult::Failed;
case DialogButton::OkCancel:
ok = msgBox.addButton(QMessageBox::Ok);
goto addCancel;
case DialogButton::RetryCancel:
retry = msgBox.addButton(QMessageBox::Retry);
goto addCancel;
case DialogButton::YesNoCancel:
yes = msgBox.addButton(QMessageBox::Yes);
no = msgBox.addButton(QMessageBox::No);
addCancel:
cancel = msgBox.addButton(QMessageBox::Cancel);
msgBox.exec();
if (msgBox.clickedButton() == nullptr)
return DialogResult::Failed;
if ((QPushButton *)msgBox.clickedButton() == yes)
return DialogResult::Yes;
if ((QPushButton *)msgBox.clickedButton() == no)
return DialogResult::No;
if ((QPushButton *)msgBox.clickedButton() == retry)
return DialogResult::Retry;
if ((QPushButton *)msgBox.clickedButton() == cancel)
return DialogResult::Cancel;
if ((QPushButton *)msgBox.clickedButton() == ok)
return DialogResult::Ok;
default:
return DialogResult::Failed;
}
}