mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 01:23:24 -08:00
[Client] Alt badges, breadcrumb trail, investigate button
AltTableDelegate paints palette-tinted match badges with paint-through selection, style warning/critical icons on nonzero counts, and font/elision handling. TabAlts gains a clickable breadcrumb trail, an Investigate-this-user button, and bold usernames. Async alts responses are guarded against stale investigations.
This commit is contained in:
parent
4d645e7513
commit
803e1e9ec3
5 changed files with 234 additions and 0 deletions
|
|
@ -378,6 +378,7 @@ set(cockatrice_SOURCES
|
|||
src/interface/widgets/tabs/api/edhrec/display/top_tags/edhrec_top_tags_api_response_display_widget.cpp
|
||||
src/interface/widgets/tabs/api/edhrec/tab_edhrec.cpp
|
||||
src/interface/widgets/tabs/api/edhrec/tab_edhrec_main.cpp
|
||||
src/interface/widgets/tabs/alt_table_delegate.cpp
|
||||
src/interface/widgets/tabs/report_status_delegate.cpp
|
||||
src/interface/widgets/tabs/tab.cpp
|
||||
src/interface/widgets/tabs/tab_account.cpp
|
||||
|
|
|
|||
132
cockatrice/src/interface/widgets/tabs/alt_table_delegate.cpp
Normal file
132
cockatrice/src/interface/widgets/tabs/alt_table_delegate.cpp
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
#include "alt_table_delegate.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QModelIndex>
|
||||
#include <QPainter>
|
||||
#include <QPalette>
|
||||
#include <QStyle>
|
||||
#include <QStyleOptionViewItem>
|
||||
|
||||
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
|
||||
|
||||
AltTableDelegate::AltTableDelegate(int viaColumn, int warnsColumn, int bansColumn, int sharedColumn, QObject *parent)
|
||||
: QStyledItemDelegate(parent), viaColumn(viaColumn), warnsColumn(warnsColumn), bansColumn(bansColumn),
|
||||
sharedColumn(sharedColumn)
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
QStyleOptionViewItem opt(option);
|
||||
initStyleOption(&opt, index);
|
||||
painter->setFont(opt.font);
|
||||
QStyle *style = opt.widget != nullptr ? opt.widget->style() : QApplication::style();
|
||||
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 QPalette::ColorRole textRole = (dimmed && !selected) ? QPalette::PlaceholderText : emphasisRole;
|
||||
if (text == QStringLiteral("email")) {
|
||||
paintPill(QPalette::Link, emphasisRole, QIcon(), text);
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
paintPill(QPalette::PlaceholderText, textRole, QIcon(), text);
|
||||
return;
|
||||
}
|
||||
QStyledItemDelegate::paint(painter, opt, index);
|
||||
return;
|
||||
}
|
||||
|
||||
if (index.column() == warnsColumn || index.column() == bansColumn) {
|
||||
bool countOk = false;
|
||||
const int count = text.toInt(&countOk);
|
||||
if (countOk && count > 0 && !selected) {
|
||||
const QIcon icon = style->standardIcon(index.column() == bansColumn ? QStyle::SP_MessageBoxCritical
|
||||
: QStyle::SP_MessageBoxWarning);
|
||||
const int iconSize = qMax(0, opt.rect.height() - 2 * ICON_TEXT_GAP);
|
||||
QRect textRect = opt.rect;
|
||||
if (!icon.isNull() && iconSize > 0) {
|
||||
const QRect iconRect(opt.rect.left() + ICON_TEXT_GAP, opt.rect.top() + ICON_TEXT_GAP, iconSize,
|
||||
iconSize);
|
||||
icon.paint(painter, iconRect);
|
||||
textRect.setLeft(iconRect.right() + ICON_TEXT_GAP);
|
||||
}
|
||||
const QString elided = opt.fontMetrics.elidedText(text, opt.textElideMode, textRect.width());
|
||||
style->drawItemText(painter, textRect, Qt::AlignLeft | Qt::AlignVCenter, opt.palette, true, elided,
|
||||
emphasisRole);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QStyledItemDelegate::paint(painter, opt, index);
|
||||
}
|
||||
|
||||
QSize AltTableDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
const QSize hint = QStyledItemDelegate::sizeHint(option, index);
|
||||
if (index.column() == viaColumn) {
|
||||
return hint + QSize(PILL_PAD_X + 2 * ICON_TEXT_GAP, PILL_PAD_Y);
|
||||
}
|
||||
if (index.column() == warnsColumn || index.column() == bansColumn) {
|
||||
return hint + QSize(2 * ICON_TEXT_GAP, 0);
|
||||
}
|
||||
return hint;
|
||||
}
|
||||
35
cockatrice/src/interface/widgets/tabs/alt_table_delegate.h
Normal file
35
cockatrice/src/interface/widgets/tabs/alt_table_delegate.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef ALT_TABLE_DELEGATE_H
|
||||
#define ALT_TABLE_DELEGATE_H
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
/**
|
||||
* Badge + icon painting for the User Alts table. The match-evidence column
|
||||
* renders as a palette-tinted pill per match type (email / client id / IP),
|
||||
* with the style's warning icon once an IP is shared by more than the VPN
|
||||
* threshold. Warn/ban counts gain the style's warning/critical icons when
|
||||
* nonzero. Selected rows and unknown content fall back to default painting.
|
||||
*/
|
||||
class AltTableDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AltTableDelegate(int viaColumn,
|
||||
int warnsColumn,
|
||||
int bansColumn,
|
||||
int sharedColumn,
|
||||
QObject *parent = nullptr);
|
||||
void setVpnThreshold(int threshold);
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
[[nodiscard]] QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
|
||||
private:
|
||||
int viaColumn;
|
||||
int warnsColumn;
|
||||
int bansColumn;
|
||||
int sharedColumn;
|
||||
int vpnThreshold = 10;
|
||||
};
|
||||
|
||||
#endif // ALT_TABLE_DELEGATE_H
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
#include "../utility/epoch_format.h"
|
||||
#include "../utility/table_activation.h"
|
||||
#include "abstract_client.h"
|
||||
#include "alt_table_delegate.h"
|
||||
#include "libcockatrice/protocol/pb/response.pb.h"
|
||||
#include "libcockatrice/protocol/pb/response_user_alts.pb.h"
|
||||
|
||||
|
|
@ -102,6 +103,15 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
|
|||
connect(backButton, &QPushButton::clicked, this, &TabAlts::goBack);
|
||||
|
||||
statusLabel = new QLabel;
|
||||
trailLabel = new QLabel;
|
||||
trailLabel->setTextFormat(Qt::RichText);
|
||||
trailLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||
trailLabel->setOpenExternalLinks(false);
|
||||
connect(trailLabel, &QLabel::linkActivated, this, [this](const QString &userName) {
|
||||
if (!userName.isEmpty() && userName != currentUser) {
|
||||
investigate(userName);
|
||||
}
|
||||
});
|
||||
|
||||
auto *topBar = new QHBoxLayout;
|
||||
topBar->addWidget(backButton);
|
||||
|
|
@ -136,6 +146,12 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
|
|||
|
||||
altsTable = new QTableWidget(0, COL_ALTS_COUNT);
|
||||
configureAltTable(altsTable);
|
||||
altsDelegate = new AltTableDelegate(COL_ALTS_VIA, COL_ALTS_WARNS, COL_ALTS_BANS, COL_ALTS_SHARED, altsTable);
|
||||
altsDelegate->setVpnThreshold(vpnSpin->value());
|
||||
connect(vpnSpin, &QSpinBox::valueChanged, altsDelegate, &AltTableDelegate::setVpnThreshold);
|
||||
altsTable->setItemDelegateForColumn(COL_ALTS_VIA, altsDelegate);
|
||||
altsTable->setItemDelegateForColumn(COL_ALTS_WARNS, altsDelegate);
|
||||
altsTable->setItemDelegateForColumn(COL_ALTS_BANS, altsDelegate);
|
||||
connectTableActivation(altsTable, this, [this](const QModelIndex &index) {
|
||||
if (!index.isValid()) {
|
||||
return;
|
||||
|
|
@ -174,6 +190,10 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
|
|||
detailsLayout->addLayout(detailGrid);
|
||||
detailsLayout->addWidget(warnsTable, 1);
|
||||
detailsLayout->addWidget(bansTable, 1);
|
||||
investigateSelectedButton = new QPushButton;
|
||||
investigateSelectedButton->setEnabled(false);
|
||||
connect(investigateSelectedButton, &QPushButton::clicked, this, &TabAlts::investigateSelected);
|
||||
detailsLayout->addWidget(investigateSelectedButton);
|
||||
|
||||
auto *contentSplitter = new QSplitter(Qt::Horizontal);
|
||||
contentSplitter->addWidget(altsTable);
|
||||
|
|
@ -186,6 +206,7 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
|
|||
mainLayout->addLayout(topBar);
|
||||
mainLayout->addLayout(filterBar);
|
||||
mainLayout->addWidget(statusLabel);
|
||||
mainLayout->addWidget(trailLabel);
|
||||
mainLayout->addWidget(contentSplitter, 1);
|
||||
|
||||
retranslateUi();
|
||||
|
|
@ -225,6 +246,8 @@ void TabAlts::retranslateUi()
|
|||
detailNameLabel->setText(tr("Name:"));
|
||||
detailCountsLabel->setText(tr("Counts:"));
|
||||
detailNotesLabel->setText(tr("Admin notes:"));
|
||||
investigateSelectedButton->setText(tr("Investigate this user"));
|
||||
investigateSelectedButton->setToolTip(tr("Open the selected account as a new investigation"));
|
||||
|
||||
if (!lastAlts.isEmpty()) {
|
||||
renderTable();
|
||||
|
|
@ -262,16 +285,41 @@ void TabAlts::loadUser(const QString &userName)
|
|||
{
|
||||
currentUser = userName;
|
||||
searchEdit->setText(userName);
|
||||
updateTrail();
|
||||
investigateUser();
|
||||
}
|
||||
|
||||
void TabAlts::updateTrail()
|
||||
{
|
||||
QStringList trail = backStack;
|
||||
trail << currentUser;
|
||||
trail.removeAll(QString());
|
||||
QStringList links;
|
||||
for (const QString &name : trail) {
|
||||
const QString safeName = name.toHtmlEscaped();
|
||||
if (name == currentUser) {
|
||||
links << QStringLiteral("<b>") + safeName + QStringLiteral("</b>");
|
||||
} else {
|
||||
links << QStringLiteral("<a href=\"") + safeName + QStringLiteral("\">") + safeName +
|
||||
QStringLiteral("</a>");
|
||||
}
|
||||
}
|
||||
trailLabel->setText(links.join(QStringLiteral(" › ")));
|
||||
trailLabel->setVisible(!links.isEmpty());
|
||||
}
|
||||
|
||||
void TabAlts::investigateUser()
|
||||
{
|
||||
const QString userName = searchEdit->text().simplified();
|
||||
if (userName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (userName != currentUser && !currentUser.isEmpty()) {
|
||||
backStack << currentUser;
|
||||
backButton->setEnabled(true);
|
||||
}
|
||||
currentUser = userName;
|
||||
updateTrail();
|
||||
lastAlts.clear();
|
||||
selectedUser.clear();
|
||||
clearDetails();
|
||||
|
|
@ -396,6 +444,9 @@ void TabAlts::renderTable()
|
|||
if (QString::fromStdString(alt.match_reason()).startsWith(QStringLiteral("ip:")) && alt.has_shared_count() &&
|
||||
alt.shared_count() > 2) {
|
||||
for (int col = 0; col < COL_ALTS_COUNT; ++col) {
|
||||
if (col == COL_ALTS_VIA) {
|
||||
continue;
|
||||
}
|
||||
if (auto *item = altsTable->item(row, col)) {
|
||||
item->setForeground(dimColor);
|
||||
}
|
||||
|
|
@ -446,6 +497,13 @@ void TabAlts::onFilterChanged()
|
|||
renderTable();
|
||||
}
|
||||
|
||||
void TabAlts::investigateSelected()
|
||||
{
|
||||
if (!selectedUser.isEmpty() && selectedUser != currentUser) {
|
||||
investigate(selectedUser);
|
||||
}
|
||||
}
|
||||
|
||||
void TabAlts::onAltSelected()
|
||||
{
|
||||
const auto selected = altsTable->selectedItems();
|
||||
|
|
@ -469,6 +527,7 @@ void TabAlts::requestDetails(const QString &userName)
|
|||
detailNotesEdit->clear();
|
||||
warnsTable->setRowCount(0);
|
||||
bansTable->setRowCount(0);
|
||||
investigateSelectedButton->setEnabled(userName != currentUser);
|
||||
|
||||
Command_ReportUserInfo infoCmd;
|
||||
infoCmd.set_user_name(userName.toStdString());
|
||||
|
|
@ -508,6 +567,7 @@ void TabAlts::clearDetails()
|
|||
detailNotesEdit->clear();
|
||||
warnsTable->setRowCount(0);
|
||||
bansTable->setRowCount(0);
|
||||
investigateSelectedButton->setEnabled(false);
|
||||
}
|
||||
|
||||
void TabAlts::userDetailsResponse(const Response &response)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <qtmetamacros.h>
|
||||
|
||||
class AbstractClient;
|
||||
class AltTableDelegate;
|
||||
class QGroupBox;
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
|
|
@ -41,6 +42,7 @@ public:
|
|||
private slots:
|
||||
void investigateUser();
|
||||
void goBack();
|
||||
void investigateSelected();
|
||||
void altsResponse(const Response &response);
|
||||
void onFilterChanged();
|
||||
void onAltSelected();
|
||||
|
|
@ -50,6 +52,7 @@ private slots:
|
|||
|
||||
private:
|
||||
void loadUser(const QString &userName);
|
||||
void updateTrail();
|
||||
void requestAlts(const QString &userName, int depth);
|
||||
void requestDetails(const QString &userName);
|
||||
void clearDetails();
|
||||
|
|
@ -67,8 +70,11 @@ private:
|
|||
QSpinBox *depthSpin;
|
||||
QPushButton *investigateButton;
|
||||
QPushButton *backButton;
|
||||
QPushButton *investigateSelectedButton;
|
||||
QLabel *trailLabel;
|
||||
QLabel *statusLabel;
|
||||
QTableWidget *altsTable;
|
||||
AltTableDelegate *altsDelegate;
|
||||
|
||||
QPushButton *emailChip;
|
||||
QPushButton *clientIdChip;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue