199 lines
5.4 KiB
C++
Executable File
199 lines
5.4 KiB
C++
Executable File
#include "lts_notification_box.h"
|
|
#include "ui_lts_notification_box.h"
|
|
|
|
#include <QPainter>
|
|
#include <QLinearGradient>
|
|
#include <QColor>
|
|
#include <QGraphicsDropShadowEffect>
|
|
#include <QStyleOption>
|
|
#include <QStyle>
|
|
#ifdef NOTIBOX_DEBUG
|
|
#include <QDebug>
|
|
#endif
|
|
|
|
|
|
namespace LtsWidgets
|
|
{
|
|
const int LtsNotificationBox::margin = 14;
|
|
|
|
LtsNotificationBox::LtsNotificationBox(QWidget *parent)
|
|
: QWidget(parent)
|
|
, m_ui(new Ui::NotiBox)
|
|
{
|
|
m_ui->setupUi(this);
|
|
m_ui->lblText->setText({});
|
|
|
|
connect(m_ui->lblText, &QLabel::linkActivated,
|
|
this, [this](const QString &link)
|
|
{
|
|
emit signalLinkClicked(link);
|
|
});
|
|
|
|
connect(m_ui->tbClose, &QToolButton::clicked,
|
|
this, &LtsNotificationBox::signalClose);
|
|
connect(m_ui->tbAck, &QToolButton::clicked,
|
|
this, &LtsNotificationBox::signalAck);
|
|
|
|
setObjectName(QStringLiteral("NotiBox"));
|
|
|
|
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
|
|
shadow->setOffset(0, 0);
|
|
shadow->setBlurRadius(margin*2);
|
|
shadow->setColor(QColor(25, 25, 25));
|
|
|
|
setGraphicsEffect(shadow);
|
|
}
|
|
|
|
|
|
void LtsNotificationBox::message(const QString &title, const QString &text, MessageType type)
|
|
{
|
|
static QString rgbBaseString(QStringLiteral("%1, %2, %3"));
|
|
static QString closeDefault(QStringLiteral("close.svg"));
|
|
static QString closeDark(QStringLiteral("close_dark.svg"));
|
|
static QString ackDefault(QStringLiteral("ack.svg"));
|
|
static QString ackDark(QStringLiteral("ack_dark.svg"));
|
|
static QString lightTextColor(QStringLiteral("fbfbfb"));
|
|
static QString darkTextColor(QStringLiteral("2c3642"));
|
|
|
|
static QColor errorStart(254, 45, 102);
|
|
static QColor errorEnd(255, 92, 61);
|
|
|
|
static QColor successStart(43, 167, 70);
|
|
static QColor successEnd(130, 180, 45);
|
|
|
|
static QColor infoStart(74, 74, 74);
|
|
static QColor infoEnd(43, 43, 43);
|
|
|
|
static QColor warningStart(253, 151, 4);
|
|
static QColor warningEnd(253, 202, 0);
|
|
|
|
|
|
QColor start;
|
|
QColor end;
|
|
QString close;
|
|
QString closeHover;
|
|
QString ack;
|
|
QString ackHover;
|
|
QString textColor;
|
|
|
|
switch (type)
|
|
{
|
|
case MessageType::Error:
|
|
{
|
|
start = errorStart;
|
|
end = errorEnd;
|
|
close = closeDefault;
|
|
closeHover = closeDark;
|
|
ack = ackDefault;
|
|
ackHover = ackDark;
|
|
textColor = lightTextColor;
|
|
m_ui->lblImage->setPixmap(QPixmap(QStringLiteral(":/error.svg")));
|
|
|
|
break;
|
|
}
|
|
|
|
case MessageType::Success:
|
|
{
|
|
start = successStart;
|
|
end = successEnd;
|
|
close = closeDefault;
|
|
closeHover = closeDark;
|
|
ack = ackDefault;
|
|
ackHover = ackDark;
|
|
textColor = lightTextColor;
|
|
m_ui->lblImage->setPixmap(QPixmap(QStringLiteral(":/success.svg")));
|
|
|
|
break;
|
|
}
|
|
|
|
case MessageType::Info:
|
|
{
|
|
start = infoStart;
|
|
end = infoEnd;
|
|
close = closeDefault;
|
|
closeHover = closeDark;
|
|
ack = ackDefault;
|
|
ackHover = ackDark;
|
|
textColor = lightTextColor;
|
|
m_ui->lblImage->setPixmap(QPixmap(QStringLiteral(":/info.svg")));
|
|
|
|
break;
|
|
}
|
|
|
|
case MessageType::Warning:
|
|
{
|
|
start = warningStart;
|
|
end = warningEnd;
|
|
close = closeDark;
|
|
closeHover = closeDefault;
|
|
ack = ackDark;
|
|
ackHover = ackDefault;
|
|
textColor = darkTextColor;
|
|
m_ui->lblImage->setPixmap(QPixmap(QStringLiteral(":/warning.svg")));
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
QStringList css;
|
|
|
|
css << QStringLiteral("#NotiBox { background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop: 0 rgb(%1), stop: 1 rgb(%2)); border: 1px solid rgb(%3); border-radius: 8px; margin: %4px }").
|
|
arg(rgbBaseString.arg(start.red()).arg(start.green()).arg(start.blue()),
|
|
rgbBaseString.arg(end.red()).arg(end.green()).arg(end.blue()),
|
|
rgbBaseString.arg(end.red()).arg(end.green()).arg(end.blue())).
|
|
arg(margin);
|
|
|
|
css << QStringLiteral("QToolButton#tbClose { border-image: url(:/%1) 0 0 0 0 stretch stretch; border-width: 0px; background-color: transparent; }").arg(close);
|
|
css << QStringLiteral("QToolButton#tbClose:hover { border-image: url(:/%1) 0 0 0 0 stretch stretch; border-width: 0px; background-color: transparent; }").arg(closeHover);
|
|
|
|
css << QStringLiteral("QToolButton#tbAck { border-image: url(:/%1) 0 0 0 0 stretch stretch; border-width: 0px; background-color: transparent; }").arg(ack);
|
|
css << QStringLiteral("QToolButton#tbAck:hover { border-image: url(:/%1) 0 0 0 0 stretch stretch; border-width: 0px; background-color: transparent; }").arg(ackHover);
|
|
|
|
#ifdef NOTIBOX_DEBUG
|
|
qWarning() << "css" << css;
|
|
|
|
qWarning() << "exists?" << QFile::exists(QStringLiteral(":/close.svg"));
|
|
qWarning() << "exists?" << QFile::exists(QStringLiteral(":/close_dark.svg"));
|
|
qWarning() << "exists?" << QFile::exists(QStringLiteral(":/error.svg"));
|
|
qWarning() << "exists?" << QFile::exists(QStringLiteral(":/info.svg"));
|
|
qWarning() << "exists?" << QFile::exists(QStringLiteral(":/warning.svg"));
|
|
qWarning() << "exists?" << QFile::exists(QStringLiteral(":/success.svg"));
|
|
#endif
|
|
|
|
m_ui->lblImage->setStyleSheet(QString());
|
|
setStyleSheet(css.join(QStringLiteral(" ")));
|
|
|
|
m_ui->lblText->setText(QStringLiteral("<p><span style='font-size:14pt; font-weight:600; color:#%1;'>%2</span></p><p><span style='font-size:14pt; color:#%3;'>%4</span></p>").arg(textColor, title, textColor, text));
|
|
|
|
show();
|
|
}
|
|
|
|
|
|
void LtsNotificationBox::paintEvent(QPaintEvent *)
|
|
{
|
|
QStyleOption opt;
|
|
opt.init(this);
|
|
QPainter p(this);
|
|
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|