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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
static MessageBox::StandardButton showNewMessageBox(QWidget *parent,
MessageBox::Icon icon,
const QString& title, const QString& text,
MessageBox::StandardButtons buttons,
MessageBox::StandardButton defaultButton)
{
QMessageBox msgBox(icon, title, text, MessageBox::NoButton, parent);
QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(&msgBox);
Q_ASSERT(buttonBox != 0);
uint mask = MessageBox::FirstButton;
while(mask <= MessageBox::LastButton) {
uint sb = buttons & mask;
mask <<= 1;
if(!sb) continue;
QPushButton *button = msgBox.addButton((MessageBox::StandardButton)sb);
switch(sb) {
case MessageBox::Ok:
button->setText(QObject::tr("Ok"));
break;
case MessageBox::Open:
button->setText(QObject::tr("Open"));
break;
case MessageBox::Save:
button->setText(QObject::tr("Save"));
break;
case MessageBox::Cancel:
button->setText(QObject::tr("Cancel"));
break;
case MessageBox::Close:
button->setText(QObject::tr("Close"));
break;
case MessageBox::Discard:
button->setText(QObject::tr("Discard"));
break;
case MessageBox::Apply:
button->setText(QObject::tr("Apply"));
break;
case MessageBox::Reset:
button->setText(QObject::tr("Reset"));
break;
case MessageBox::RestoreDefaults:
button->setText(QObject::tr("Restore Defaults"));
break;
case MessageBox::Help:
button->setText(QObject::tr("Help"));
break;
case MessageBox::SaveAll:
button->setText(QObject::tr("Save All"));
break;
case MessageBox::Yes:
button->setText(QObject::tr("Yes"));
break;
case MessageBox::YesToAll:
button->setText(QObject::tr("Yes To All"));
break;
case MessageBox::No:
button->setText(QObject::tr("No"));
break;
case MessageBox::NoToAll:
button->setText(QObject::tr("No To All"));
break;
case MessageBox::Abort:
button->setText(QObject::tr("Abort"));
break;
case MessageBox::Retry:
button->setText(QObject::tr("Retry"));
break;
case MessageBox::Ignore:
button->setText(QObject::tr("Ignore"));
break;
case MessageBox::NoButton:
break;
}
if(msgBox.defaultButton()) continue;
if((defaultButton == MessageBox::NoButton
&& buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole)
|| (defaultButton != MessageBox::NoButton && sb == uint(defaultButton)))
msgBox.setDefaultButton(button);
}
if (msgBox.exec() == -1) return MessageBox::Cancel;
return msgBox.standardButton(msgBox.clickedButton());
}
MessageBox::StandardButton MessageBox::information(QWidget *parent, const QString &title,
const QString& text, StandardButtons buttons,
StandardButton defaultButton)
{
return showNewMessageBox(parent, Information, title, text, buttons, defaultButton);
}
MessageBox::StandardButton MessageBox::question(QWidget *parent, const QString &title,
const QString& text, StandardButtons buttons,
StandardButton defaultButton)
{
return showNewMessageBox(parent, Question, title, text, buttons, defaultButton);
}
MessageBox::StandardButton MessageBox::warning(QWidget *parent, const QString &title,
const QString& text, StandardButtons buttons,
StandardButton defaultButton)
{
return showNewMessageBox(parent, Warning, title, text, buttons, defaultButton);
}
MessageBox::StandardButton MessageBox::critical(QWidget *parent, const QString &title,
const QString& text, StandardButtons buttons,
StandardButton defaultButton)
{
return showNewMessageBox(parent, Critical, title, text, buttons, defaultButton);
}
|