#include "notifywnd.h"
#include "notifymanager.h"
#include <QBoxLayout>
#include <QGraphicsDropShadowEffect>
NotifyWnd::NotifyWnd (NotifyManager *manager, QWidget *parent)
: ArrangedWnd(manager, parent)
{
background = new QFrame(this);
background->setGeometry(3, 3, width()-6, height()-6);
background->setObjectName("notify-background");
QHBoxLayout *mainLayout = new QHBoxLayout(background);
QVBoxLayout *contentLayout = new QVBoxLayout();
iconLabel = new QLabel(background);
iconLabel->setFixedSize(40, 40);
iconLabel->setAlignment(Qt::AlignCenter);
iconLabel->setWordWrap(true);
titleLabel = new QLabel(background);
titleLabel->setObjectName("notify-title");
bodyLabel = new QLabel(background);
bodyLabel->setObjectName("notify-body");
bodyLabel->setAlignment(Qt::AlignLeft|Qt::AlignTop);
bodyLabel->setWordWrap(true);
contentLayout->addWidget(titleLabel);
contentLayout->addWidget(bodyLabel);
contentLayout->setStretch(1,1);
mainLayout->addWidget(iconLabel);
mainLayout->addLayout(contentLayout);
mainLayout->setAlignment(iconLabel, Qt::AlignTop);
closeBtn = new QPushButton("×", background);
closeBtn->setObjectName("notify-close-btn");
closeBtn->setFixedSize(24, 24);
closeBtn->move(background->width() - closeBtn->width(), 0);
connect(closeBtn, &QPushButton::clicked, this, &QObject::deleteLater);
setStyleSheet(m_manager->styleSheet());
// 边框阴影
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
shadow->setOffset(0, 0);
shadow->setBlurRadius(5);
background->setGraphicsEffect(shadow);
connect(this, &ArrangedWnd::visibleChanged, [this](bool visible){
if (visible)
{
int displayTime = m_data.value("displayTime", m_manager->displayTime()).toInt();
QTimer::singleShot(displayTime, this, [this](){
showArranged(0);
});
}
else deleteLater();
});
}
QVariantMap NotifyWnd::data() const
{
return m_data;
}
// 需显示后调用
void NotifyWnd::setData(const QVariantMap &data)
{
m_data = data;
QPixmap icon;
QVariant iconv = data.value("icon");
if (iconv.type() == QVariant::Pixmap) icon = iconv.value<QPixmap>();
if (iconv.type() == QVariant::String) icon = QPixmap(iconv.toString());
else icon = QPixmap(m_manager->defaultIcon());
icon = icon.scaled(QSize(32, 32), Qt::KeepAspectRatio);
iconLabel->setPixmap(icon);
QString title = data.value("title").toString();
titleLabel->setText(title);
// 计算可显示行数及长度
QString body = m_data.value("body").toString();
QSize s1 = bodyLabel->size();
QSize s2 = bodyLabel->fontMetrics().size(Qt::TextSingleLine, body);
int linecount = s1.height()/s2.height();
int charcount = qFloor(1.0*body.size()*s1.width()/s2.width()) * linecount;
QString bodyElid = charcount > body.size() ? body : (body.left(charcount-1)+"…");
bodyLabel->setText(bodyElid);
if (data.contains("styleSheet"))
setStyleSheet(data.value("styleSheet").toString());
else if (data.contains("theme"))
setStyleSheet(m_manager->styleSheet(data.value("theme").toString()));
}
NotifyCountWnd::NotifyCountWnd(NotifyManager *manager, QWidget *parent)
: ArrangedWnd(manager, parent)
{
setAttribute(Qt::WA_TransparentForMouseEvents, true);
iconLabel = new QLabel(this);
iconLabel->setFixedSize(40, 40);
iconLabel->setAlignment(Qt::AlignCenter);
countLabel = new QLabel(this);
countLabel->setObjectName("notify-count");
countLabel->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
QHBoxLayout *mainLayout = new QHBoxLayout(this);
mainLayout->addWidget(iconLabel);
mainLayout->addWidget(countLabel);
// 文字阴影
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
shadow->setOffset(2, 2);
shadow->setBlurRadius(5);
setGraphicsEffect(shadow);
setStyleSheet("#notify-count {"
"font: 20px Verdana;"
"color: #dd424d;"
"}");
QPixmap icon = QPixmap(m_manager->defaultIcon());
icon = icon.scaled(QSize(32, 32), Qt::KeepAspectRatio);
iconLabel->setPixmap(icon);
flickerAnim = new QPropertyAnimation(this, "windowOpacity", this);
flickerAnim->setStartValue(1);
flickerAnim->setKeyValueAt(0.25, 0.1);
flickerAnim->setKeyValueAt(0.5, 1);
flickerAnim->setEndValue(1);
flickerAnim->setDuration(2000);
flickerAnim->setLoopCount(-1);
connect(this, &ArrangedWnd::visibleChanged, [this](bool visible){
if (visible) flickerAnim->start();
else flickerAnim->stop();
});
}
void NotifyCountWnd::setCount(int count)
{
countLabel->setNum(count);
}
路过的大熊
- 粉丝: 1w+
- 资源: 91
最新资源
- transformer-6layer.hbm
- 中小型制造企业质量管理系统--论文pf-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 高校危化试剂仓储系统--论文pf-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 驾校预约学习系统--论文pf-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 基于下垂控制,引入电感,两台单相逆变器非同步并机 默认发2018b 控制方式为下垂控制且引入电感(图2),使用二阶广义积分器(SOGI)实现有功和无功解耦 引入电感前后有功无功对比如图4和图5 功能
- 西南交通大学车辆工程专业大四上车辆综合实训ame仿真模型
- 同城上门喂遛宠物系统--论文pf-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 基于javaweb的在线远程考试系统.zip
- 招生宣传管理系统pf-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- comsol相控阵检测 16阵元放在有机玻璃斜楔上检测工件内部缺陷,都是固体力学,图1红圈?位置的波为横孔缺陷的反射接收波 工件里的波看起来好像没怎么折射,其实那是斜楔纵波声速接近工件横波声速造成的
- 高校疫情防控web系统pf-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 高校汉服租赁网站--论文pf-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 高校物品捐赠管理系统--论文pf-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 小米音箱 MiGPT源码包
- 高校竞赛管理系统--论文pf-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 智慧社区居家养老健康管理系统pf-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈