chatgui: remember last read message, restore scroll position, show unread count badge
Store read/scroll positions per channel via ui_state table (key-value). Draw red +N badge on channel list items for unread messages. Fix getMessages() to fetch last N messages (was fetching first N).
This commit is contained in:
1 parent
de14f82048
commit
86d227bffe
10 files changed
+158
-12
No files matched your search
@@ -125,6 +125,28 @@ void ChannelDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio
|
||||
}
|
||||
}
|
||||
|
||||
/* ── unread count badge (right of channel name) ── */
|
||||
int unread = index.data(ChannelUnreadCountRole).toInt();
|
||||
if (unread > 0) {
|
||||
QString unreadText = unread > 99 ? QStringLiteral("99+") : QString::number(unread);
|
||||
QFont badgeFont = option.font;
|
||||
badgeFont.setBold(true);
|
||||
badgeFont.setPixelSize(11);
|
||||
QFontMetrics badgeFm(badgeFont);
|
||||
int textW = badgeFm.horizontalAdvance(unreadText) + 8;
|
||||
int badgeH = 18;
|
||||
if (textW < badgeH) textW = badgeH;
|
||||
QRect badgeRect(textRect.right() - textW, nameRect.top(),
|
||||
textW, badgeH);
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
painter->setBrush(QColor("#E53935"));
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->drawRoundedRect(badgeRect, badgeH / 2, badgeH / 2);
|
||||
painter->setFont(badgeFont);
|
||||
painter->setPen(Qt::white);
|
||||
painter->drawText(badgeRect, Qt::AlignCenter, unreadText);
|
||||
}
|
||||
|
||||
/* ── invite plus button (bottom-right) ── */
|
||||
QRect plusRect = inviteButtonRect(option.rect);
|
||||
bool plusHovered = index.data(ChannelInviteBtnHoveredRole).toInt() != 0;
|
||||
|
||||
Reference in new issue
Block a user