You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

69 lines
2.4 KiB

#pragma once
#include <QStyledItemDelegate>
enum MessageDataRole {
MsgAuthorRole = Qt::UserRole + 1,
MsgTextRole = Qt::UserRole + 2,
MsgTimeRole = Qt::UserRole + 3,
MsgEditedRole = Qt::UserRole + 4,
MsgAvatarRole = Qt::UserRole + 5,
MsgHasQuoteRole = Qt::UserRole + 6,
MsgQuoteAuthorRole = Qt::UserRole + 7,
MsgQuoteTextRole = Qt::UserRole + 8,
MsgReactionsRole = Qt::UserRole + 9,
};
class MessageDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
explicit MessageDelegate(QObject *parent = nullptr);
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
QSize sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
private:
struct Layout {
int viewWidth;
int bubbleWidth;
QRect authorRect;
QRect avatarRect;
QRect bubbleRect;
QRect quoteRect;
QRect quoteBarRect;
QRect quoteAuthorRect;
QRect quoteTextRect;
QRect textRect;
QRect statusRect;
int totalHeight;
bool narrow = false;
};
Layout calcLayout(const QStyleOptionViewItem &option,
const QModelIndex &index) const;
void drawQuote(QPainter *p, const Layout &L,
const QModelIndex &index, const QStyleOptionViewItem &opt) const;
void drawBubble(QPainter *p, const Layout &L, const QStyleOptionViewItem &opt) const;
void drawStatusBar(QPainter *p, const Layout &L,
const QModelIndex &index, const QStyleOptionViewItem &opt) const;
void drawAvatar(QPainter *p, const Layout &L,
const QModelIndex &index) const;
static constexpr int kAvatar = 36;
static constexpr int kGap = 8;
static constexpr int kRadius = 10;
static constexpr int kPadH = 12;
static constexpr int kPadTop = 8;
static constexpr int kPadBot = 6;
static constexpr int kTail = 6;
static constexpr int kMarginH = 8;
static constexpr int kItemGap = 3;
static constexpr int kQuoteGap = 4;
static constexpr int kQuotePadH = 6;
static constexpr int kQuotePadV = 6;
static constexpr int kQuoteBarW = 2;
static constexpr int kQuoteAv = 16;
static constexpr int kStatusH = 18;
};