Files
utun2/tools/chatgui/src/accountdelegate.cpp
T
evgeny b2e4aadbf0 e2e: AES-128-CCM encryption via BGP router (ROUTER_FLAG_ENCRYPTED), ECDH key per peer-pair from NODEINFO pubkeys, cache 8 entries
- etcp_router.h/c: new flag ROUTER_FLAG_ENCRYPTED (0x04), etcp_route_send_encrypted(), inflight/retrans/send_q support
- utun_instance.h: e2e_ctx_cache[8] — per-peer sc_context_t cache with derived session key
- topo_node.c: topo_node_sign_self() — single point for Ed25519 self-signing of NODEINFO
- topo_node.c: fix stale x25519_self_sig after address update (topo_node_sign_self call)
- nat_detection.c: fix stale x25519_self_sig after in-place socket meta modification
- test_etcp_router_unit: 5 E2E tests (basic round-trip, no NODEINFO drop, tampered, cache reuse, ENCRYPTED+SIGNED combined)
- builds clean, 70/70 tests pass
2026-08-09 08:19:20 +03:00

73 lines
2.8 KiB
C++

#include "accountdelegate.h"
#include "flagpainter.h"
#include "memberlistmodel.h"
#include <QPainter>
#include <QFont>
AccountDelegate::AccountDelegate(QObject *parent)
: QStyledItemDelegate(parent) {}
void AccountDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const {
painter->save();
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.highlight());
else if (option.state & QStyle::State_MouseOver)
painter->fillRect(option.rect, option.palette.light());
else
painter->fillRect(option.rect, option.palette.alternateBase());
const int margin = 4;
const int iconSz = 24;
QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
if (!icon.isNull())
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 int yMid = option.rect.top() + option.rect.height() / 2;
QFont nameFont = painter->font();
nameFont.setBold(true);
nameFont.setPixelSize(13);
painter->setFont(nameFont);
QColor textColor = option.palette.color(QPalette::Text);
if (option.state & QStyle::State_Selected) textColor = option.palette.color(QPalette::HighlightedText);
if (index.data(Qt::UserRole + 2).toBool()) textColor = QColor("#4CAF50");
painter->setPen(textColor);
uint8_t flags = (uint8_t)(index.data(Qt::UserRole + 3).toInt() & 0xFF);
int flagX = x;
if (flags) {
FlagPainter::draw(painter, flags, flagX, option.rect.top() + (option.rect.height() - nameFont.pixelSize()) / 2, nameFont.pixelSize());
flagX += nameFont.pixelSize() * ((flags & 0x01 ? 1 : 0) + (flags & 0x02 ? 1 : 0) + (flags & 0x04 ? 1 : 0))
+ ((__builtin_popcount(flags) - 1) * 2);
}
QString name = index.data(Qt::DisplayRole).toString();
painter->drawText(QRect(flagX, option.rect.top() + 2, w - (flagX - x), yMid - option.rect.top() - 2),
Qt::AlignLeft | Qt::AlignBottom, name);
QFont subFont = painter->font();
subFont.setBold(false);
subFont.setPixelSize(10);
painter->setFont(subFont);
painter->setPen(QColor(130, 130, 130));
QString sub = index.data(Qt::UserRole + 1).toString();
if (!sub.isEmpty())
painter->drawText(QRect(x, yMid + 2, w, option.rect.bottom() - yMid - 2),
Qt::AlignLeft | Qt::AlignTop, sub);
painter->restore();
}
QSize AccountDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const {
(void)option; (void)index;
return QSize(160, 36);
}