mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-06 10:03:26 -08:00
[Client] Fix alt badge and trail review findings
- Drop the dead VPN warning branch: rowVisible() already hides IP rows above the threshold, so setVpnThreshold(), its member and the spin-box connect never took effect. - Dim IP rows at shared_count > 2 instead of > 1: the count already includes the investigated account, so every IP row was dimmed. - Truncate backStack when a breadcrumb is clicked instead of pushing the current user again, so the trail keeps a single path and Back works. - Word-wrap the trail label so a long chain cannot widen the tab. - Extract the status/match pill painting into widgets/utility/pill_painter and use it from both delegates instead of duplicating it.
This commit is contained in:
parent
d7b2786184
commit
d09f4c5356
8 changed files with 120 additions and 92 deletions
|
|
@ -1,5 +1,7 @@
|
|||
#include "alt_table_delegate.h"
|
||||
|
||||
#include "../utility/pill_painter.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QModelIndex>
|
||||
#include <QPainter>
|
||||
|
|
@ -9,9 +11,6 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
constexpr qreal PILL_ALPHA = 0.30;
|
||||
constexpr int PILL_PAD_X = 10;
|
||||
constexpr int PILL_PAD_Y = 4;
|
||||
constexpr int ICON_TEXT_GAP = 4;
|
||||
} // namespace
|
||||
|
||||
|
|
@ -21,11 +20,6 @@ AltTableDelegate::AltTableDelegate(int viaColumn, int warnsColumn, int bansColum
|
|||
{
|
||||
}
|
||||
|
||||
void AltTableDelegate::setVpnThreshold(int threshold)
|
||||
{
|
||||
vpnThreshold = threshold;
|
||||
}
|
||||
|
||||
void AltTableDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
const bool selected = (option.state & QStyle::State_Selected) != 0;
|
||||
|
|
@ -37,58 +31,27 @@ void AltTableDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
|||
const QString text = index.data(Qt::DisplayRole).toString();
|
||||
const QPalette::ColorRole emphasisRole = selected ? QPalette::HighlightedText : QPalette::WindowText;
|
||||
|
||||
auto paintPill = [&](QPalette::ColorRole tintRole, QPalette::ColorRole textRole, const QIcon &icon,
|
||||
const QString &pillText) {
|
||||
const QRect pillRect = opt.rect.adjusted(PILL_PAD_X / 2, PILL_PAD_Y / 2, -PILL_PAD_X / 2, -PILL_PAD_Y / 2);
|
||||
if (pillRect.width() <= 0 || pillRect.height() <= 0) {
|
||||
QStyledItemDelegate::paint(painter, opt, index);
|
||||
return;
|
||||
}
|
||||
if (!selected) {
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
QColor pill = opt.palette.color(tintRole);
|
||||
pill.setAlphaF(PILL_ALPHA);
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(pill);
|
||||
painter->drawRoundedRect(pillRect, pillRect.height() / 2.0, pillRect.height() / 2.0);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
QRect textRect = pillRect;
|
||||
if (!icon.isNull()) {
|
||||
const int iconSize = qMin(pillRect.height(), pillRect.width());
|
||||
if (iconSize > 0) {
|
||||
const QRect iconRect(pillRect.left() + ICON_TEXT_GAP, pillRect.top(), iconSize, iconSize);
|
||||
icon.paint(painter, iconRect);
|
||||
textRect.setLeft(iconRect.right() + ICON_TEXT_GAP);
|
||||
}
|
||||
}
|
||||
const QString elided = opt.fontMetrics.elidedText(pillText, opt.textElideMode, textRect.width());
|
||||
style->drawItemText(painter, textRect, Qt::AlignCenter, opt.palette, true, elided, textRole);
|
||||
};
|
||||
|
||||
if (index.column() == viaColumn) {
|
||||
bool sharedOk = false;
|
||||
const unsigned shared = index.sibling(index.row(), sharedColumn).data(Qt::DisplayRole).toUInt(&sharedOk);
|
||||
const bool dimmed = sharedOk && text.startsWith(QStringLiteral("ip:")) && shared > 1;
|
||||
const bool vpn =
|
||||
sharedOk && text.startsWith(QStringLiteral("ip:")) && shared > static_cast<unsigned>(vpnThreshold);
|
||||
const bool ipMatch = text.startsWith(QStringLiteral("ip:"));
|
||||
// shared_count for an IP match already includes the investigated account,
|
||||
// so anything above 2 means the address is shared beyond that pair.
|
||||
const bool dimmed = sharedOk && ipMatch && shared > 2;
|
||||
const QPalette::ColorRole textRole = (dimmed && !selected) ? QPalette::PlaceholderText : emphasisRole;
|
||||
|
||||
QPalette::ColorRole tintRole = QPalette::NoRole;
|
||||
if (text == QStringLiteral("email")) {
|
||||
paintPill(QPalette::Link, emphasisRole, QIcon(), text);
|
||||
return;
|
||||
tintRole = QPalette::Link;
|
||||
} else if (text.startsWith(QStringLiteral("clientid:"))) {
|
||||
tintRole = QPalette::Highlight;
|
||||
} else if (ipMatch) {
|
||||
tintRole = QPalette::PlaceholderText;
|
||||
}
|
||||
if (text.startsWith(QStringLiteral("clientid:"))) {
|
||||
paintPill(QPalette::Highlight, emphasisRole, QIcon(), text);
|
||||
return;
|
||||
}
|
||||
if (text.startsWith(QStringLiteral("ip:"))) {
|
||||
if (vpn) {
|
||||
paintPill(QPalette::Highlight, textRole, style->standardIcon(QStyle::SP_MessageBoxWarning), text);
|
||||
return;
|
||||
if (tintRole != QPalette::NoRole) {
|
||||
if (!pill_painter::paint(painter, opt, tintRole, textRole, text)) {
|
||||
QStyledItemDelegate::paint(painter, opt, index);
|
||||
}
|
||||
paintPill(QPalette::PlaceholderText, textRole, QIcon(), text);
|
||||
return;
|
||||
}
|
||||
QStyledItemDelegate::paint(painter, opt, index);
|
||||
|
|
@ -123,7 +86,7 @@ QSize AltTableDelegate::sizeHint(const QStyleOptionViewItem &option, const QMode
|
|||
{
|
||||
const QSize hint = QStyledItemDelegate::sizeHint(option, index);
|
||||
if (index.column() == viaColumn) {
|
||||
return hint + QSize(PILL_PAD_X + 2 * ICON_TEXT_GAP, PILL_PAD_Y);
|
||||
return hint + QSize(pill_painter::PAD_X + 2 * ICON_TEXT_GAP, pill_painter::PAD_Y);
|
||||
}
|
||||
if (index.column() == warnsColumn || index.column() == bansColumn) {
|
||||
return hint + QSize(2 * ICON_TEXT_GAP, 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue