| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #ifndef CHATMESSAGE_H
- #define CHATMESSAGE_H
- #include <QDateTime>
- #include <QObject>
- #include <QString>
- #include <QSize>
- namespace ChatConstants {
- static constexpr int AVATAR_SIZE = 40;
- static constexpr int BUBBLE_PADDING = 12;
- static constexpr int BUBBLE_SPACING = 8;
- static constexpr int BUBBLE_RADIUS = 8;
- static constexpr int TIMESTAMP_HEIGHT = 20;
- // static constexpr int MAX_WIDTH = 600;
- } // namespace ChatConstants
- // 添加消息类型枚举
- enum class MessageType {
- Left, // 接收到的消息
- Right, // 发送的消息
- System, // 系统消息
- Private // 私聊消息
- };
- // 添加内容类型枚举
- enum class ContentType {
- Text, // 纯文本消息
- Image, // 图片消息
- Mixed // 混合内容(文本+图片)
- };
- class ChatMessage
- {
- public:
- QString id;
- QString text;
- QString senderId;
- QString senderName;
- QString roomId;
- QString avatar;
- MessageType type = MessageType::Left;
- ContentType contentType = ContentType::Text; // 内容类型
- QString imagePath; // 图片路径
- QSize imageSize; // 图片尺寸
- QString thumbnailPath; // 缩略图路径
- QDateTime timestamp = QDateTime::currentDateTime();
- bool isRead = false;
- ChatMessage(const QString &text = QString(),
- MessageType type = MessageType::Left,
- const QDateTime ×tamp = QDateTime::currentDateTime())
- : text(text)
- , type(type)
- , timestamp(timestamp)
- {}
-
- // 图片消息构造函数
- ChatMessage(const QString &imagePath,
- const QSize &imageSize,
- MessageType type = MessageType::Left,
- const QString &text = QString())
- : text(text)
- , type(type)
- , contentType(text.isEmpty() ? ContentType::Image : ContentType::Mixed)
- , imagePath(imagePath)
- , imageSize(imageSize)
- {}
- bool isLeft() const { return type == MessageType::Left; }
- bool isRight() const { return type == MessageType::Right; }
- bool isSystem() const { return type == MessageType::System; }
- bool hasImage() const { return contentType == ContentType::Image || contentType == ContentType::Mixed; }
- bool hasText() const { return contentType == ContentType::Text || contentType == ContentType::Mixed; }
- bool isImageOnly() const { return contentType == ContentType::Image; }
- };
- Q_DECLARE_METATYPE(ChatMessage)
- #endif // CHATMESSAGE_H
|