-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotificationBar.cpp
More file actions
130 lines (107 loc) · 3.02 KB
/
NotificationBar.cpp
File metadata and controls
130 lines (107 loc) · 3.02 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
#include "NotificationBar.h"
#include "ui_NotificationBar.h"
NotificationBar::NotificationBar(QWidget *parent) :
QFrame(parent),
ui(new Ui::NotificationBar)
{
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(this);
QPalette palette = this->palette();
palette.setColor(QPalette::Window, QColor(255,255,225));
setPalette(palette);
setModality(false);
setVisible(false);
setFocusPolicy(Qt::StrongFocus);
}
NotificationBar::~NotificationBar()
{
delete ui;
}
QString NotificationBar::text() const
{
return ui->lblText->text();
}
void NotificationBar::setText(const QString &text)
{
ui->lblText->setText(text);
}
QIcon NotificationBar::icon() const
{
//TODO:
return QIcon();
}
void NotificationBar::setIcon(const QIcon icon)
{
Q_UNUSED(icon);
//TODO:
}
QDialogButtonBox::StandardButtons NotificationBar::standardButtons() const
{
return ui->btnBox->standardButtons();
}
void NotificationBar::setStandardButtons(const QDialogButtonBox::StandardButtons standardButtons)
{
ui->btnBox->setStandardButtons(standardButtons);
}
bool NotificationBar::modality() const
{
return _modality;
}
void NotificationBar::setModality(const bool modality)
{
_modality = modality;
}
void NotificationBar::on_btnBox_clicked(QAbstractButton *button)
{
this->hide();
emit buttonClicked(ui->btnBox->standardButton(button));
emit closing();
this->close();
}
void NotificationBar::on_btnClose_clicked()
{
this->hide();
emit buttonClicked(QDialogButtonBox::NoButton);
emit closing();
this->close();
}
void NotificationBar::keyReleaseEvent(QKeyEvent *event)
{
/* Why I can't just send the freakin' key event to the QDialogButtonBox is beyond me. I Googled the crap out of the
subject and it seems that there really isn't a good solution to the problem. The only thing I could do was the
following hack. o_O
*/
if(event->count() != 1) {
QFrame::keyReleaseEvent(event);
return;
}
QDialogButtonBox::ButtonRole keyRole;
switch(event->key()) {
case Qt::Key_Escape:
keyRole = QDialogButtonBox::RejectRole;
break;
case Qt::Key_Return:
case Qt::Key_Enter:
keyRole = QDialogButtonBox::AcceptRole;
break;
default:
QFrame::keyReleaseEvent(event);
return;
}
foreach(QAbstractButton *button, ui->btnBox->buttons()) {
QDialogButtonBox::ButtonRole buttonRole = ui->btnBox->buttonRole(button);
if(keyRole == QDialogButtonBox::AcceptRole) {
if(buttonRole == QDialogButtonBox::AcceptRole || buttonRole == QDialogButtonBox::YesRole ||
buttonRole == QDialogButtonBox::ApplyRole) {
button->click();
return;
}
} else if(keyRole == QDialogButtonBox::RejectRole) {
if(buttonRole == QDialogButtonBox::RejectRole || buttonRole == QDialogButtonBox::NoRole) {
button->click();
return;
}
}
}
on_btnClose_clicked();
}