-
Notifications
You must be signed in to change notification settings - Fork 0
/
warningpopup.cpp
57 lines (48 loc) · 1.94 KB
/
warningpopup.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
#include "warningpopup.h"
#include "ui_warningpopup.h"
#include <QApplication>
#include <QDesktopWidget>
#include <QFontDatabase>
WarningPopup::WarningPopup(QWidget *parent) : QWidget(parent), ui(new Ui::WarningPopup)
{
ui->setupUi(this);
setWindowFlags(Qt::Window | // Add if popup doesn't show up
Qt::FramelessWindowHint | // No window border
Qt::WindowDoesNotAcceptFocus | // No focus
Qt::WindowStaysOnTopHint // Always on top
);
setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_ShowWithoutActivating);
setAttribute(Qt::WA_DeleteOnClose);
_timer.setSingleShot(true);
connect(ui->closeButton, &QPushButton::clicked, this, &WarningPopup::close);
connect(&_timer, &QTimer::timeout, this, &WarningPopup::close);
ui->warningTextlabel->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
hide();
}
WarningPopup::~WarningPopup() { delete ui; }
int WarningPopup::showPeriod() const { return _showPeriod; }
void WarningPopup::setShowPeriod(int showPeriod) { _showPeriod = showPeriod; }
void WarningPopup::showPopup(const QString &text)
{
auto activeWindow = qApp->activeWindow();
QRect popupRect;
if(activeWindow == nullptr)
{
popupRect = QStyle::alignedRect(Qt::RightToLeft, Qt::AlignBottom, size(),
qApp->desktop()->screenGeometry(QCursor::pos()));
popupRect.translate(-20, -30);
}
else
{
popupRect = QStyle::alignedRect(Qt::RightToLeft, Qt::AlignBottom, size(),
activeWindow->geometry());
// do not overlap with scrollbar and bottom panel of main Qt Creator window
popupRect.translate(-20, -43);
}
setGeometry(popupRect);
ui->warningTextlabel->setText(text);
_timer.setInterval(_showPeriod);
show();
_timer.start();
}