Browse Source

Remove group row icons and give titles the freed space

master
evgeny 3 days ago
parent
commit
61f2ca7a88
  1. 90
      tools/chatgui/src/channeldelegate.cpp
  2. 10
      tools/chatgui/src/channeldelegate.h

90
tools/chatgui/src/channeldelegate.cpp

@ -5,27 +5,6 @@
ChannelDelegate::ChannelDelegate(QObject *parent)
: QStyledItemDelegate(parent) {}
QRect ChannelDelegate::inviteButtonRect(const QRect &itemRect) {
const int margin = 6;
return QRect(itemRect.right() - margin - InviteBtnSize,
itemRect.top() + margin,
InviteBtnSize, InviteBtnSize);
}
QRect ChannelDelegate::inviteByLinkButtonRect(const QRect &itemRect) {
const int margin = 6;
return QRect(itemRect.right() - margin - InviteBtnSize * 2 - InviteBtnGap,
itemRect.top() + margin,
InviteBtnSize, InviteBtnSize);
}
QRect ChannelDelegate::settingsButtonRect(const QRect &itemRect) {
const int margin = 6;
return QRect(itemRect.right() - margin - InviteBtnSize * 3 - InviteBtnGap * 2,
itemRect.top() + margin,
InviteBtnSize, InviteBtnSize);
}
void ChannelDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const {
painter->save();
@ -115,7 +94,11 @@ void ChannelDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio
QRect nameRect = textRect;
nameRect.setHeight(QFontMetrics(nameFont).height());
nameRect.setRight(nameRect.right() - InviteBtnSize * 3 - InviteBtnGap * 2 - 4);
int unread = index.data(ChannelUnreadCountRole).toInt();
QString unreadText = unread > 99 ? QStringLiteral("99+") : QString::number(unread);
QFont unreadFont = option.font; unreadFont.setBold(true); unreadFont.setPixelSize(11);
int unreadWidth = qMax(18, QFontMetrics(unreadFont).horizontalAdvance(unreadText) + 8);
if (unread > 0) nameRect.setRight(nameRect.right() - unreadWidth - 6);
painter->drawText(nameRect, Qt::AlignLeft | Qt::AlignTop,
painter->fontMetrics().elidedText(name, Qt::ElideRight, nameRect.width()));
@ -159,77 +142,18 @@ 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);
QRect badgeRect(textRect.right() - unreadWidth, nameRect.top(), unreadWidth, badgeH);
painter->setRenderHint(QPainter::Antialiasing);
painter->setBrush(QColor("#E53935"));
painter->setPen(Qt::NoPen);
painter->drawRoundedRect(badgeRect, badgeH / 2, badgeH / 2);
painter->setFont(badgeFont);
painter->setFont(unreadFont);
painter->setPen(Qt::white);
painter->drawText(badgeRect, Qt::AlignCenter, unreadText);
}
/* ── invite plus button (top-right) ── */
QRect plusRect = inviteButtonRect(option.rect);
bool plusHovered = index.data(ChannelInviteBtnHoveredRole).toInt() != 0;
painter->setRenderHint(QPainter::Antialiasing);
QColor plusFill = plusHovered ? QColor(0x4A, 0xA4, 0xF0) : QColor(0x33, 0x90, 0xEC);
painter->setBrush(plusFill);
painter->setPen(Qt::NoPen);
painter->drawEllipse(plusRect);
painter->setPen(QPen(Qt::white, 2));
painter->drawLine(plusRect.center().x(), plusRect.top() + 5,
plusRect.center().x(), plusRect.bottom() - 5);
painter->drawLine(plusRect.left() + 5, plusRect.center().y(),
plusRect.right() - 5, plusRect.center().y());
/* ── invite-by-link button (left of plus, orange square with arrow) ── */
QRect invRect = inviteByLinkButtonRect(option.rect);
bool invHovered = index.data(ChannelInviteByLinkBtnHoveredRole).toInt() != 0;
painter->setRenderHint(QPainter::Antialiasing);
QColor invFill = invHovered ? QColor(0xF0, 0x90, 0x30) : QColor(0xE6, 0x7E, 0x22);
painter->setBrush(invFill);
painter->setPen(Qt::NoPen);
painter->drawRoundedRect(invRect, 3, 3);
painter->setPen(QPen(Qt::white, 1.5));
/* arrow: ← */
int cx = invRect.center().x(), cy = invRect.center().y();
int dx = 3;
painter->drawLine(cx + dx, cy - 3, cx - dx, cy);
painter->drawLine(cx + dx, cy + 3, cx - dx, cy);
painter->drawLine(cx + dx + 1, cy, cx + dx + 1, cy - 3 + 1);
painter->drawLine(cx + dx + 1, cy, cx + dx + 1, cy + 3 - 1);
/* ── settings gear (left of invite-by-link button) ── */
QRect gearRect = settingsButtonRect(option.rect);
bool gearHovered = index.data(ChannelSettingsBtnHoveredRole).toInt() != 0;
QColor gearColor = gearHovered ? QColor("#3390EC") : QColor("#555");
painter->setPen(QPen(gearColor, 2));
painter->setBrush(Qt::NoBrush);
int gr = 5;
painter->drawEllipse(gearRect.center(), gr, gr);
painter->drawEllipse(gearRect.center(), gr / 2, gr / 2);
int gcx = gearRect.center().x(), gcy = gearRect.center().y();
painter->drawLine(gcx, gcy - gr, gcx, gcy - gr + 1);
painter->drawLine(gcx, gcy + gr, gcx, gcy + gr - 1);
painter->drawLine(gcx - gr, gcy, gcx - gr + 1, gcy);
painter->drawLine(gcx + gr, gcy, gcx + gr - 1, gcy);
painter->drawLine(gcx - 3, gcy - 4, gcx - 3, gcy - 5);
painter->drawLine(gcx + 3, gcy + 4, gcx + 3, gcy + 5);
painter->drawLine(gcx - 4, gcy - 3, gcx - 5, gcy - 3);
painter->drawLine(gcx + 4, gcy + 3, gcx + 5, gcy + 3);
painter->restore();
}

10
tools/chatgui/src/channeldelegate.h

@ -1,4 +1,4 @@
/* Роли модели и отрисовка ChannelList: канал/PM, последнее сообщение, unread и кнопки действий. */
/* Роли модели и отрисовка ChannelList: канал/PM, последнее сообщение и unread. */
#pragma once
#include <QStyledItemDelegate>
@ -10,9 +10,6 @@ enum ChannelDataRole {
ChannelChannelIdRole = Qt::UserRole + 2,
ChannelPeersOnlineRole = Qt::UserRole + 3, /* int: count of online peers */
ChannelAutoConnectActiveRole = Qt::UserRole + 4, /* bool: 1 if auto-connect in progress */
ChannelInviteBtnHoveredRole = Qt::UserRole + 5, /* bool: 1 when mouse hovers invite button */
ChannelInviteByLinkBtnHoveredRole = Qt::UserRole + 8, /* bool: hover for invite-by-link button */
ChannelSettingsBtnHoveredRole = Qt::UserRole + 9, /* bool: hover for per-channel settings gear */
ChannelUnreadCountRole = Qt::UserRole + 6, /* int: unread message count, 0 if none */
ChannelLastMsgAtRole = Qt::UserRole + 7, /* qint64: last message timestamp for sorting */
ChannelDmOnlineRole = Qt::UserRole + 11, /* bool: живой BGP-путь PM */
@ -29,9 +26,4 @@ public:
QSize sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
static constexpr int InviteBtnSize = 18;
static constexpr int InviteBtnGap = 2;
static QRect inviteButtonRect(const QRect &itemRect);
static QRect inviteByLinkButtonRect(const QRect &itemRect);
static QRect settingsButtonRect(const QRect &itemRect);
};

Loading…
Cancel
Save