-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnotification.cpp
More file actions
80 lines (71 loc) · 2.91 KB
/
notification.cpp
File metadata and controls
80 lines (71 loc) · 2.91 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
#include "notification.h"
#include "ui_notification.h"
#include <QPropertyAnimation>
#include <QGraphicsOpacityEffect>
Notification::Notification(const QString &title, const QString &message, const QString ¬i_type, QWidget *parent)
: QWidget(parent)
, ui(new Ui::Notification)
{
ui->setupUi(this);
ui->title->setText(title);
ui->message->setText(message);
if (noti_type == "info") {
setStyleSheet("QFrame {"
"background-color: rgb(80, 70, 229);"
"color: white;"
"border-radius: 10px;"
"}"
"QPushButton {"
"background-color: rgb(237, 240, 247);"
"color: rgb(80, 70, 229);"
"border: none;"
"border-radius: 10px;"
"padding: 10px;"
"}"
"QPushButton:hover {"
"background-color: #919ae5;"
"}");
} else if (noti_type == "risk") {
setStyleSheet("QFrame {"
"background-color: #F43F5E;"
"color: white;"
"border-radius: 10px;"
"}"
"QPushButton {"
"background-color: rgb(237, 240, 247);"
"color: #F43F5E;"
"border: none;"
"border-radius: 10px;"
"padding: 10px;"
"}"
"QPushButton:hover {"
"background-color: #f4b1b4;"
"}");
}
// Set the initial position of the widget (off-screen to the right)
this->move(this->x() + 500, this->y());
}
Notification::~Notification()
{
delete ui;
}
void Notification::on_dismiss_btn_clicked()
{
// Create an animation for the sliding effect
QPropertyAnimation *slideOutAnimation = new QPropertyAnimation(this, "pos");
slideOutAnimation->setDuration(500); // Duration in milliseconds
slideOutAnimation->setStartValue(this->pos()); // Current position
slideOutAnimation->setEndValue(QPoint(this->x() + 500, this->y())); // Slide to the right off-screen
// Optionally, you can also add a fade-out effect using QGraphicsOpacityEffect
QGraphicsOpacityEffect *opacityEffect = new QGraphicsOpacityEffect(this);
this->setGraphicsEffect(opacityEffect);
QPropertyAnimation *fadeOutAnimation = new QPropertyAnimation(opacityEffect, "opacity");
fadeOutAnimation->setDuration(500);
fadeOutAnimation->setStartValue(1.0); // Fully visible
fadeOutAnimation->setEndValue(0.0); // Fully transparent
// Start the animations
slideOutAnimation->start();
fadeOutAnimation->start();
// After the animation finishes, close the widget
connect(slideOutAnimation, &QPropertyAnimation::finished, this, &QWidget::close);
}