1 Star 0 Fork 5

kimihuang001/message

forked from 屁股大象/message 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
message.h 1.86 KB
一键复制 编辑 原始数据 按行查看 历史
屁股大象 提交于 2022-08-10 22:30 . 刷新
#ifndef MESSAGE_H
#define MESSAGE_H
#include <QWidget>
#include <QLabel>
#include <QTimer>
#include <QPropertyAnimation>
#include <mutex>
enum MessageType {
MESSAGE_TYPE_SUCCESS = 0x20,
MESSAGE_TYPE_ERROR,
MESSAGE_TYPE_WARNING,
MESSAGE_TYPE_INFORMATION
};
class MessageItem;
class Message : public QObject
{
Q_OBJECT
public:
explicit Message(QObject *parent = nullptr);
~Message() override;
/**
* @brief Push 推入消息
* @param type 消息类型
* @param content 消息内容
*/
void Push(MessageType type, QString content);
/**
* @brief SetDuration 设置消息显示的时间
* @param nDuration 显示时间,必须大于等于0,若等于0则不消失
*/
void SetDuration(int nDuration);
private:
std::vector<MessageItem*> m_vecMessage;
std::mutex m_qMtx;
int m_nWidth;
int m_nDuration;
private slots:
void adjustItemPos(MessageItem* pItem);
void removeItem(MessageItem* pItem);
};
class MessageItem : public QWidget
{
Q_OBJECT
public:
explicit MessageItem(QWidget* parent = nullptr,
MessageType type = MessageType::MESSAGE_TYPE_INFORMATION,
QString content = "");
~MessageItem() override;
void Show();
void Close();
void SetDuration(int nDuration);
protected:
void paintEvent(QPaintEvent *event) override;
private:
void AppearAnimation();
void DisappearAnimation();
private:
const int nIconMargin = 12;
const int nLeftMargin = 64;
const int nTopMargin = 10;
const int nMinWidth = 400;
const int nMinHeight = 70;
QLabel* m_pLabelIcon;
QLabel* m_pLabelContent;
QTimer m_lifeTimer;
int m_nWidth;
int m_nHeight;
int m_nDuration;
signals:
void itemReadyRemoved(MessageItem* pItem);
void itemRemoved(MessageItem* pItem);
};
#endif // MESSAGE_H
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/kimihuang001/message.git
git@gitee.com:kimihuang001/message.git
kimihuang001
message
message
master

搜索帮助