-
Notifications
You must be signed in to change notification settings - Fork 0
/
messagedialoghelper.cpp
86 lines (76 loc) · 3.12 KB
/
messagedialoghelper.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "messagedialoghelper.h"
MessageDialogHelper::MessageDialogHelper() : QPlatformMessageDialogHelper()
{
dialogWindow = new MessageDialog();
connect(dialogWindow, SIGNAL(clicked(QPlatformDialogHelper::StandardButton,QPlatformDialogHelper::ButtonRole)), this, SIGNAL(clicked(QPlatformDialogHelper::StandardButton,QPlatformDialogHelper::ButtonRole)));
}
void MessageDialogHelper::exec() {
updateWindowOptions();
switch (options().data()->icon()) {
case QMessageDialogOptions::Warning: {
QSoundEffect* sound = new QSoundEffect();
sound->setSource(QUrl("qrc:/sounds/warn.wav"));
sound->play();
connect(sound, SIGNAL(playingChanged()), sound, SLOT(deleteLater()));
break;
}
case QMessageDialogOptions::Critical: {
QSoundEffect* sound = new QSoundEffect();
sound->setSource(QUrl("qrc:/sounds/critical.wav"));
sound->play();
connect(sound, SIGNAL(playingChanged()), sound, SLOT(deleteLater()));
break;
}
}
dialogWindow->setParent(NULL);
dialogWindow->exec();
}
bool MessageDialogHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent) {
updateWindowOptions();
dialogWindow->setWindowFlags(windowFlags);
dialogWindow->setWindowModality(windowModality);
switch (options().data()->icon()) {
case QMessageDialogOptions::Warning: {
QSoundEffect* sound = new QSoundEffect();
sound->setSource(QUrl("qrc:/sounds/warn.wav"));
sound->play();
connect(sound, SIGNAL(playingChanged()), sound, SLOT(deleteLater()));
break;
}
case QMessageDialogOptions::Critical: {
QSoundEffect* sound = new QSoundEffect();
sound->setSource(QUrl("qrc:/sounds/critical.wav"));
sound->play();
connect(sound, SIGNAL(playingChanged()), sound, SLOT(deleteLater()));
break;
}
}
dialogWindow->setParent(parent);
dialogWindow->show();
return true;
}
void MessageDialogHelper::hide() {
dialogWindow->hide();
}
void MessageDialogHelper::updateWindowOptions() {
dialogWindow->setTitle(options().data()->windowTitle());
dialogWindow->setText(options().data()->text());
dialogWindow->setButtons(options().data()->standardButtons());
switch (options().data()->icon()) {
case QMessageDialogOptions::Warning:
dialogWindow->setIcon(QIcon::fromTheme("dialog-warning"));
dialogWindow->setSliceColor(QColor(150, 100, 0));
break;
case QMessageDialogOptions::Critical:
dialogWindow->setIcon(QIcon::fromTheme("dialog-error"));
dialogWindow->setSliceColor(QColor(150, 0, 0));
break;
case QMessageDialogOptions::Question:
dialogWindow->setIcon(QIcon::fromTheme("dialog-question"));
break;
case QMessageDialogOptions::Information:
dialogWindow->setIcon(QIcon::fromTheme("dialog-information"));
dialogWindow->setSliceColor(QColor(0, 100, 200));
break;
}
}