Add invitation action to desktop member rows

This commit is contained in:
evgeny committed 2026-10-04 14:54:58 +02:00
1 parent 6bc6d28e9e
commit fe23f4ca56
2 files changed
+37 -1

No files matched your search

+30 -1
View File
@@ -3,6 +3,11 @@
#include "memberlistmodel.h"
#include <QPainter>
#include <QFont>
#include <QMouseEvent>
static QRect inviteButtonRect(const QRect& row) {
return QRect(row.right() - 31, row.center().y() - 14, 28, 28);
}
AccountDelegate::AccountDelegate(QObject *parent)
: QStyledItemDelegate(parent) {}
@@ -26,7 +31,8 @@ void AccountDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio
icon.paint(painter, option.rect.left() + margin, option.rect.top() + (option.rect.height() - iconSz) / 2, iconSz, iconSz);
const int x = option.rect.left() + iconSz + margin * 3;
const int w = option.rect.right() - x - margin;
const bool canInvite = !index.data(Qt::UserRole + 2).toBool();
const int w = option.rect.right() - x - margin - (canInvite ? 32 : 0);
const int yMid = option.rect.top() + option.rect.height() / 2;
uint8_t flags = (uint8_t)(index.data(Qt::UserRole + 3).toInt() & 0xFF);
@@ -69,9 +75,32 @@ void AccountDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio
painter->drawText(QRect(flagX, yMid + 2, w - (flagX - x), option.rect.bottom() - yMid - 2),
Qt::AlignLeft | Qt::AlignTop, sub);
if (canInvite) {
QFont plusFont = nameFont; plusFont.setPixelSize(22); plusFont.setStrikeOut(false);
painter->setFont(plusFont);
painter->setPen(option.palette.color(QPalette::Link));
painter->drawText(inviteButtonRect(option.rect), Qt::AlignCenter, QStringLiteral("+"));
}
painter->restore();
}
bool AccountDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option,
const QModelIndex& index) {
Q_UNUSED(model);
if (index.data(Qt::UserRole + 2).toBool()) return false;
if (event->type() != QEvent::MouseButtonPress && event->type() != QEvent::MouseButtonRelease &&
event->type() != QEvent::MouseButtonDblClick) return false;
auto* mouse = static_cast<QMouseEvent*>(event);
if (mouse->button() != Qt::LeftButton) return false;
const bool inside = inviteButtonRect(option.rect).contains(mouse->pos());
if (event->type() == QEvent::MouseButtonPress) { m_invitePress = inside ? index : QModelIndex(); return inside; }
if (event->type() == QEvent::MouseButtonDblClick) return inside;
const bool activate = inside && m_invitePress == index;
m_invitePress = QPersistentModelIndex();
if (activate) emit inviteRequested(index);
return activate;
}
QSize AccountDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const {
(void)option; (void)index;