Repository navigation
Expand file tree
/
Copy pathalertwindow.cpp
More file actions
76 lines (62 loc) · 1.9 KB
/
Copy pathalertwindow.cpp
File metadata and controls
76 lines (62 loc) · 1.9 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
#include "alertwindow.h"
#include <QResizeEvent>
#include <QTimer>
#include "ui_alertwindow.h"
AlertWindow::AlertWindow(QWidget *parent, bool hideOnClose,
int autoCloseSeconds)
: QWidget(parent), ui(new Ui::AlertWindow) {
ui->setupUi(this);
this->hideOnClose = hideOnClose;
this->autoCloseSeconds = autoCloseSeconds;
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
setAttribute(Qt::WA_DeleteOnClose);
if (parent) {
resize(parent->size());
}
if (autoCloseSeconds > 0) {
cancelButtonHide();
confirmButtonHide();
QTimer::singleShot(autoCloseSeconds * 1000, [=]() { this->close(); });
}
}
AlertWindow::~AlertWindow() { delete ui; }
void AlertWindow::setTitleText(QString title) {
ui->titleLabel->setText(title);
}
void AlertWindow::setContentText(QString contentText) {
ui->contentLabel->setText(contentText);
}
void AlertWindow::setConfirmButtonText(QString buttonText) {
ui->confirmPushButton->setText(buttonText);
}
void AlertWindow::setCancelButtonText(QString buttonText) {
ui->cancelPushButton->setText(buttonText);
}
void AlertWindow::confirmButtonHide() { ui->confirmPushButton->hide(); }
void AlertWindow::cancelButtonHide() { ui->cancelPushButton->hide(); }
void AlertWindow::confirmButtonShow() { ui->confirmPushButton->show(); }
void AlertWindow::cancelButtonShow() { ui->cancelPushButton->show(); }
bool AlertWindow::eventFilter(QObject *watched, QEvent *event) {
if (event->type() == QEvent::Resize) {
QResizeEvent *resizeEvent = static_cast<QResizeEvent *>(event);
resize(resizeEvent->size());
return false;
}
return true;
}
void AlertWindow::on_confirmPushButton_clicked() {
if (hideOnClose) {
this->close();
} else {
this->hide();
}
emit confirmEvent();
}
void AlertWindow::on_cancelPushButton_clicked() {
if (hideOnClose) {
this->close();
} else {
this->hide();
}
emit cancelEvent();
}