代码拉取完成,页面将自动刷新
同步操作将从 终端组/qt-notify 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include <QPropertyAnimation>
#include <QTimer>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QDebug>
#include <QPixmap>
#include <QFontMetrics>
#include <QDesktopServices>
#include "notify.h"
Notify::Notify (int displayTime, QWidget *parent) : QWidget(parent),
displayTime(displayTime)
{
this->setWindowFlags(Qt::FramelessWindowHint|Qt::WindowSystemMenuHint| Qt::Tool | Qt::WindowStaysOnTopHint);
this->setAttribute(Qt::WA_NoSystemBackground, true);
this->setAttribute(Qt::WA_TranslucentBackground,true);
backgroundLabel = new QLabel(this);
backgroundLabel->move(0, 0);
backgroundLabel->setObjectName("notify-background");
QHBoxLayout *mainLayout = new QHBoxLayout(backgroundLabel);
QVBoxLayout *contentLayout = new QVBoxLayout();
iconLabel = new QLabel(backgroundLabel);
iconLabel->setFixedWidth(40);
iconLabel->setAlignment(Qt::AlignCenter);
titleLabel = new QLabel(backgroundLabel);
titleLabel->setObjectName("notify-title");
bodyLabel = new QLabel(backgroundLabel);
bodyLabel->setObjectName("notify-body");
QFont font = bodyLabel->font();
font.setPixelSize(12);
bodyLabel->setFont(font);
contentLayout->addWidget(titleLabel);
contentLayout->addWidget(bodyLabel);
mainLayout->addWidget(iconLabel);
mainLayout->addSpacing(5);
mainLayout->addLayout(contentLayout);
closeBtn = new QPushButton("×", backgroundLabel);
closeBtn->setObjectName("notify-close-btn");
closeBtn->setFixedSize(24, 24);
connect(closeBtn, &QPushButton::clicked, this, [this]{
Q_EMIT disappeared();
});
this->setStyleSheet("#notify-background {"
"border: 1px solid #ccc;"
"background:white;"
"border-radius: 4px;"
"} "
"#notify-title{"
"font-weight: bold;"
"color: #333;"
"font-size: 14px;"
"}"
"#notify-body{"
"color: #444;"
"}"
"#notify-close-btn{ "
"border: 0;"
"color: #999;"
"}"
"#notify-close-btn:hover{ "
"background: #ccc;"
"}");
}
void Notify::showGriant()
{
this->show();
titleLabel->setText(title);
QPixmap tempPix = QPixmap(this->icon);
tempPix = tempPix.scaled(QSize(30, 30), Qt::KeepAspectRatio);
iconLabel->setPixmap(tempPix);
backgroundLabel->setFixedSize(this->size());
closeBtn->move(backgroundLabel->width() - closeBtn->width(), 0);
// 超过长度省略号
QFontMetrics elidfont(bodyLabel->font());
QString text = elidfont.elidedText(this->body, Qt::ElideRight, bodyLabel->width() - 5);
bodyLabel->setText(text);
QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity", this);
animation->setStartValue(0);
animation->setEndValue(1);
animation->setDuration(200);
animation->start();
connect(animation, &QPropertyAnimation::finished, this, [animation, this](){
animation->deleteLater();
QTimer::singleShot(displayTime, this, [this](){
this->hideGriant();
});
});
}
void Notify::hideGriant()
{
QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity", this);
animation->setStartValue(this->windowOpacity());
animation->setEndValue(0);
animation->setDuration(200);
animation->start();
connect(animation, &QPropertyAnimation::finished, this, [animation, this](){
this->hide();
animation->deleteLater();
Q_EMIT disappeared();
});
}
void Notify::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton) {
if(!url.isEmpty()){
QDesktopServices::openUrl(url);
}
hideGriant();
}
}
void Notify::setUrl(const QString &value)
{
url = value;
}
void Notify::setBody(const QString &value)
{
body = value;
}
void Notify::setTitle(const QString &value)
{
title = value;
}
void Notify::setIcon(const QString &value)
{
icon = value;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。