mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 11:03:25 -08:00
[Client] Alt badges, breadcrumb trail, investigate button (#7516)
* [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. * [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. * [Client] Route investigate() through the trail helper --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
18f9b26a3d
commit
2fba13753b
8 changed files with 298 additions and 29 deletions
|
|
@ -293,6 +293,8 @@ set(cockatrice_SOURCES
|
||||||
src/interface/widgets/utility/custom_line_edit.cpp
|
src/interface/widgets/utility/custom_line_edit.cpp
|
||||||
src/interface/widgets/utility/epoch_format.h
|
src/interface/widgets/utility/epoch_format.h
|
||||||
src/interface/widgets/utility/get_text_with_max.cpp
|
src/interface/widgets/utility/get_text_with_max.cpp
|
||||||
|
src/interface/widgets/utility/pill_painter.cpp
|
||||||
|
src/interface/widgets/utility/pill_painter.h
|
||||||
src/interface/widgets/utility/report_utils.cpp
|
src/interface/widgets/utility/report_utils.cpp
|
||||||
src/interface/widgets/utility/report_utils.h
|
src/interface/widgets/utility/report_utils.h
|
||||||
src/interface/widgets/utility/table_activation.cpp
|
src/interface/widgets/utility/table_activation.cpp
|
||||||
|
|
@ -384,6 +386,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/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.cpp
|
||||||
src/interface/widgets/tabs/api/edhrec/tab_edhrec_main.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/report_status_delegate.cpp
|
||||||
src/interface/widgets/tabs/tab.cpp
|
src/interface/widgets/tabs/tab.cpp
|
||||||
src/interface/widgets/tabs/tab_account.cpp
|
src/interface/widgets/tabs/tab_account.cpp
|
||||||
|
|
|
||||||
95
cockatrice/src/interface/widgets/tabs/alt_table_delegate.cpp
Normal file
95
cockatrice/src/interface/widgets/tabs/alt_table_delegate.cpp
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
#include "alt_table_delegate.h"
|
||||||
|
|
||||||
|
#include "../utility/pill_painter.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QModelIndex>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPalette>
|
||||||
|
#include <QStyle>
|
||||||
|
#include <QStyleOptionViewItem>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
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::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;
|
||||||
|
|
||||||
|
if (index.column() == viaColumn) {
|
||||||
|
bool sharedOk = false;
|
||||||
|
const unsigned shared = index.sibling(index.row(), sharedColumn).data(Qt::DisplayRole).toUInt(&sharedOk);
|
||||||
|
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")) {
|
||||||
|
tintRole = QPalette::Link;
|
||||||
|
} else if (text.startsWith(QStringLiteral("clientid:"))) {
|
||||||
|
tintRole = QPalette::Highlight;
|
||||||
|
} else if (ipMatch) {
|
||||||
|
tintRole = QPalette::PlaceholderText;
|
||||||
|
}
|
||||||
|
if (tintRole != QPalette::NoRole) {
|
||||||
|
if (!pill_painter::paint(painter, opt, tintRole, textRole, text)) {
|
||||||
|
QStyledItemDelegate::paint(painter, opt, index);
|
||||||
|
}
|
||||||
|
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_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);
|
||||||
|
}
|
||||||
|
return hint;
|
||||||
|
}
|
||||||
33
cockatrice/src/interface/widgets/tabs/alt_table_delegate.h
Normal file
33
cockatrice/src/interface/widgets/tabs/alt_table_delegate.h
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
#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), and
|
||||||
|
* an IP shared by more than one other account is dimmed. 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 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;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ALT_TABLE_DELEGATE_H
|
||||||
|
|
@ -1,18 +1,13 @@
|
||||||
#include "report_status_delegate.h"
|
#include "report_status_delegate.h"
|
||||||
|
|
||||||
|
#include "../utility/pill_painter.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QStyleOptionViewItem>
|
#include <QStyleOptionViewItem>
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
constexpr qreal PILL_ALPHA = 0.30;
|
|
||||||
constexpr int PILL_PAD_X = 10;
|
|
||||||
constexpr int PILL_PAD_Y = 4;
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
ReportStatusDelegate::ReportStatusDelegate(QObject *parent) : QStyledItemDelegate(parent)
|
ReportStatusDelegate::ReportStatusDelegate(QObject *parent) : QStyledItemDelegate(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -46,32 +41,14 @@ void ReportStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString elided =
|
|
||||||
opt.fontMetrics.elidedText(opt.text.isEmpty() ? status : opt.text, opt.textElideMode, pillRect.width());
|
|
||||||
const QPalette::ColorRole textRole = selected ? QPalette::HighlightedText : QPalette::WindowText;
|
const QPalette::ColorRole textRole = selected ? QPalette::HighlightedText : QPalette::WindowText;
|
||||||
QStyle *style = opt.widget != nullptr ? opt.widget->style() : QApplication::style();
|
if (!pill_painter::paint(painter, opt, tintRole, textRole, opt.text.isEmpty() ? status : opt.text)) {
|
||||||
style->drawItemText(painter, pillRect, Qt::AlignCenter, opt.palette, true, elided, textRole);
|
QStyledItemDelegate::paint(painter, opt, index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize ReportStatusDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
QSize ReportStatusDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
const QSize hint = QStyledItemDelegate::sizeHint(option, index);
|
const QSize hint = QStyledItemDelegate::sizeHint(option, index);
|
||||||
return hint + QSize(PILL_PAD_X, PILL_PAD_Y);
|
return hint + QSize(pill_painter::PAD_X, pill_painter::PAD_Y);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include "../utility/epoch_format.h"
|
#include "../utility/epoch_format.h"
|
||||||
#include "../utility/table_activation.h"
|
#include "../utility/table_activation.h"
|
||||||
#include "abstract_client.h"
|
#include "abstract_client.h"
|
||||||
|
#include "alt_table_delegate.h"
|
||||||
#include "libcockatrice/protocol/pb/response.pb.h"
|
#include "libcockatrice/protocol/pb/response.pb.h"
|
||||||
#include "libcockatrice/protocol/pb/response_user_alts.pb.h"
|
#include "libcockatrice/protocol/pb/response_user_alts.pb.h"
|
||||||
|
|
||||||
|
|
@ -102,6 +103,18 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
|
||||||
connect(backButton, &QPushButton::clicked, this, &TabAlts::goBack);
|
connect(backButton, &QPushButton::clicked, this, &TabAlts::goBack);
|
||||||
|
|
||||||
statusLabel = new QLabel;
|
statusLabel = new QLabel;
|
||||||
|
trailLabel = new QLabel;
|
||||||
|
trailLabel->setTextFormat(Qt::RichText);
|
||||||
|
trailLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||||
|
trailLabel->setOpenExternalLinks(false);
|
||||||
|
// The trail grows with every hop, so let it wrap instead of forcing the tab
|
||||||
|
// wider than the window.
|
||||||
|
trailLabel->setWordWrap(true);
|
||||||
|
connect(trailLabel, &QLabel::linkActivated, this, [this](const QString &userName) {
|
||||||
|
if (!userName.isEmpty() && userName != currentUser) {
|
||||||
|
goToTrailEntry(userName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
auto *topBar = new QHBoxLayout;
|
auto *topBar = new QHBoxLayout;
|
||||||
topBar->addWidget(backButton);
|
topBar->addWidget(backButton);
|
||||||
|
|
@ -136,6 +149,10 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
|
||||||
|
|
||||||
altsTable = new QTableWidget(0, COL_ALTS_COUNT);
|
altsTable = new QTableWidget(0, COL_ALTS_COUNT);
|
||||||
configureAltTable(altsTable);
|
configureAltTable(altsTable);
|
||||||
|
altsDelegate = new AltTableDelegate(COL_ALTS_VIA, COL_ALTS_WARNS, COL_ALTS_BANS, COL_ALTS_SHARED, altsTable);
|
||||||
|
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) {
|
connectTableActivation(altsTable, this, [this](const QModelIndex &index) {
|
||||||
if (!index.isValid()) {
|
if (!index.isValid()) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -174,6 +191,10 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
|
||||||
detailsLayout->addLayout(detailGrid);
|
detailsLayout->addLayout(detailGrid);
|
||||||
detailsLayout->addWidget(warnsTable, 1);
|
detailsLayout->addWidget(warnsTable, 1);
|
||||||
detailsLayout->addWidget(bansTable, 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);
|
auto *contentSplitter = new QSplitter(Qt::Horizontal);
|
||||||
contentSplitter->addWidget(altsTable);
|
contentSplitter->addWidget(altsTable);
|
||||||
|
|
@ -186,6 +207,7 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
|
||||||
mainLayout->addLayout(topBar);
|
mainLayout->addLayout(topBar);
|
||||||
mainLayout->addLayout(filterBar);
|
mainLayout->addLayout(filterBar);
|
||||||
mainLayout->addWidget(statusLabel);
|
mainLayout->addWidget(statusLabel);
|
||||||
|
mainLayout->addWidget(trailLabel);
|
||||||
mainLayout->addWidget(contentSplitter, 1);
|
mainLayout->addWidget(contentSplitter, 1);
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
|
|
@ -225,6 +247,8 @@ void TabAlts::retranslateUi()
|
||||||
detailNameLabel->setText(tr("Name:"));
|
detailNameLabel->setText(tr("Name:"));
|
||||||
detailCountsLabel->setText(tr("Counts:"));
|
detailCountsLabel->setText(tr("Counts:"));
|
||||||
detailNotesLabel->setText(tr("Admin notes:"));
|
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()) {
|
if (!lastAlts.isEmpty()) {
|
||||||
renderTable();
|
renderTable();
|
||||||
|
|
@ -241,6 +265,13 @@ void TabAlts::investigate(const QString &userName)
|
||||||
if (userName.isEmpty() || userName == currentUser) {
|
if (userName.isEmpty() || userName == currentUser) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Alt matches are symmetric, so revisiting an earlier account is a normal
|
||||||
|
// double-click. Truncate there instead of pushing it again, so the trail
|
||||||
|
// stays a single path.
|
||||||
|
if (backStack.contains(userName)) {
|
||||||
|
goToTrailEntry(userName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!currentUser.isEmpty()) {
|
if (!currentUser.isEmpty()) {
|
||||||
backStack << currentUser;
|
backStack << currentUser;
|
||||||
backButton->setEnabled(true);
|
backButton->setEnabled(true);
|
||||||
|
|
@ -248,6 +279,20 @@ void TabAlts::investigate(const QString &userName)
|
||||||
loadUser(userName);
|
loadUser(userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabAlts::goToTrailEntry(const QString &userName)
|
||||||
|
{
|
||||||
|
const int index = backStack.indexOf(userName);
|
||||||
|
if (index < 0) {
|
||||||
|
investigate(userName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Clicking an earlier crumb truncates the history there instead of pushing
|
||||||
|
// another entry, so the trail keeps a single path and Back still works.
|
||||||
|
backStack.erase(backStack.begin() + index, backStack.end());
|
||||||
|
backButton->setEnabled(!backStack.isEmpty());
|
||||||
|
loadUser(userName);
|
||||||
|
}
|
||||||
|
|
||||||
void TabAlts::goBack()
|
void TabAlts::goBack()
|
||||||
{
|
{
|
||||||
if (backStack.isEmpty()) {
|
if (backStack.isEmpty()) {
|
||||||
|
|
@ -262,16 +307,41 @@ void TabAlts::loadUser(const QString &userName)
|
||||||
{
|
{
|
||||||
currentUser = userName;
|
currentUser = userName;
|
||||||
searchEdit->setText(userName);
|
searchEdit->setText(userName);
|
||||||
|
updateTrail();
|
||||||
investigateUser();
|
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()
|
void TabAlts::investigateUser()
|
||||||
{
|
{
|
||||||
const QString userName = searchEdit->text().simplified();
|
const QString userName = searchEdit->text().simplified();
|
||||||
if (userName.isEmpty()) {
|
if (userName.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (userName != currentUser && !currentUser.isEmpty()) {
|
||||||
|
backStack << currentUser;
|
||||||
|
backButton->setEnabled(true);
|
||||||
|
}
|
||||||
currentUser = userName;
|
currentUser = userName;
|
||||||
|
updateTrail();
|
||||||
lastAlts.clear();
|
lastAlts.clear();
|
||||||
selectedUser.clear();
|
selectedUser.clear();
|
||||||
clearDetails();
|
clearDetails();
|
||||||
|
|
@ -393,9 +463,14 @@ void TabAlts::renderTable()
|
||||||
altsTable->setItem(row, COL_ALTS_WARNS, new QTableWidgetItem(QString::number(alt.warn_count())));
|
altsTable->setItem(row, COL_ALTS_WARNS, new QTableWidgetItem(QString::number(alt.warn_count())));
|
||||||
altsTable->setItem(row, COL_ALTS_BANS, new QTableWidgetItem(QString::number(alt.ban_count())));
|
altsTable->setItem(row, COL_ALTS_BANS, new QTableWidgetItem(QString::number(alt.ban_count())));
|
||||||
altsTable->setItem(row, COL_ALTS_ACTIVE, new QTableWidgetItem(alt.is_active() ? tr("yes") : tr("no")));
|
altsTable->setItem(row, COL_ALTS_ACTIVE, new QTableWidgetItem(alt.is_active() ? tr("yes") : tr("no")));
|
||||||
|
// shared_count already includes the investigated account, so anything
|
||||||
|
// above 2 means the address is shared beyond that pair.
|
||||||
if (QString::fromStdString(alt.match_reason()).startsWith(QStringLiteral("ip:")) && alt.has_shared_count() &&
|
if (QString::fromStdString(alt.match_reason()).startsWith(QStringLiteral("ip:")) && alt.has_shared_count() &&
|
||||||
alt.shared_count() > 2) {
|
alt.shared_count() > 2) {
|
||||||
for (int col = 0; col < COL_ALTS_COUNT; ++col) {
|
for (int col = 0; col < COL_ALTS_COUNT; ++col) {
|
||||||
|
if (col == COL_ALTS_VIA) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (auto *item = altsTable->item(row, col)) {
|
if (auto *item = altsTable->item(row, col)) {
|
||||||
item->setForeground(dimColor);
|
item->setForeground(dimColor);
|
||||||
}
|
}
|
||||||
|
|
@ -446,6 +521,13 @@ void TabAlts::onFilterChanged()
|
||||||
renderTable();
|
renderTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabAlts::investigateSelected()
|
||||||
|
{
|
||||||
|
if (!selectedUser.isEmpty() && selectedUser != currentUser) {
|
||||||
|
investigate(selectedUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TabAlts::onAltSelected()
|
void TabAlts::onAltSelected()
|
||||||
{
|
{
|
||||||
const auto selected = altsTable->selectedItems();
|
const auto selected = altsTable->selectedItems();
|
||||||
|
|
@ -469,6 +551,7 @@ void TabAlts::requestDetails(const QString &userName)
|
||||||
detailNotesEdit->clear();
|
detailNotesEdit->clear();
|
||||||
warnsTable->setRowCount(0);
|
warnsTable->setRowCount(0);
|
||||||
bansTable->setRowCount(0);
|
bansTable->setRowCount(0);
|
||||||
|
investigateSelectedButton->setEnabled(userName != currentUser);
|
||||||
|
|
||||||
Command_ReportUserInfo infoCmd;
|
Command_ReportUserInfo infoCmd;
|
||||||
infoCmd.set_user_name(userName.toStdString());
|
infoCmd.set_user_name(userName.toStdString());
|
||||||
|
|
@ -508,6 +591,7 @@ void TabAlts::clearDetails()
|
||||||
detailNotesEdit->clear();
|
detailNotesEdit->clear();
|
||||||
warnsTable->setRowCount(0);
|
warnsTable->setRowCount(0);
|
||||||
bansTable->setRowCount(0);
|
bansTable->setRowCount(0);
|
||||||
|
investigateSelectedButton->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabAlts::userDetailsResponse(const Response &response)
|
void TabAlts::userDetailsResponse(const Response &response)
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include <qtmetamacros.h>
|
#include <qtmetamacros.h>
|
||||||
|
|
||||||
class AbstractClient;
|
class AbstractClient;
|
||||||
|
class AltTableDelegate;
|
||||||
class QGroupBox;
|
class QGroupBox;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
|
|
@ -41,6 +42,7 @@ public:
|
||||||
private slots:
|
private slots:
|
||||||
void investigateUser();
|
void investigateUser();
|
||||||
void goBack();
|
void goBack();
|
||||||
|
void investigateSelected();
|
||||||
void altsResponse(const Response &response);
|
void altsResponse(const Response &response);
|
||||||
void onFilterChanged();
|
void onFilterChanged();
|
||||||
void onAltSelected();
|
void onAltSelected();
|
||||||
|
|
@ -50,6 +52,8 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadUser(const QString &userName);
|
void loadUser(const QString &userName);
|
||||||
|
void goToTrailEntry(const QString &userName);
|
||||||
|
void updateTrail();
|
||||||
void requestAlts(const QString &userName, int depth);
|
void requestAlts(const QString &userName, int depth);
|
||||||
void requestDetails(const QString &userName);
|
void requestDetails(const QString &userName);
|
||||||
void clearDetails();
|
void clearDetails();
|
||||||
|
|
@ -67,8 +71,11 @@ private:
|
||||||
QSpinBox *depthSpin;
|
QSpinBox *depthSpin;
|
||||||
QPushButton *investigateButton;
|
QPushButton *investigateButton;
|
||||||
QPushButton *backButton;
|
QPushButton *backButton;
|
||||||
|
QPushButton *investigateSelectedButton;
|
||||||
|
QLabel *trailLabel;
|
||||||
QLabel *statusLabel;
|
QLabel *statusLabel;
|
||||||
QTableWidget *altsTable;
|
QTableWidget *altsTable;
|
||||||
|
AltTableDelegate *altsDelegate;
|
||||||
|
|
||||||
QPushButton *emailChip;
|
QPushButton *emailChip;
|
||||||
QPushButton *clientIdChip;
|
QPushButton *clientIdChip;
|
||||||
|
|
|
||||||
41
cockatrice/src/interface/widgets/utility/pill_painter.cpp
Normal file
41
cockatrice/src/interface/widgets/utility/pill_painter.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
#include "pill_painter.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QFontMetrics>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QRect>
|
||||||
|
#include <QStyle>
|
||||||
|
#include <QStyleOptionViewItem>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
constexpr qreal PILL_ALPHA = 0.30;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
bool pill_painter::paint(QPainter *painter,
|
||||||
|
const QStyleOptionViewItem &option,
|
||||||
|
QPalette::ColorRole tintRole,
|
||||||
|
QPalette::ColorRole textRole,
|
||||||
|
const QString &text)
|
||||||
|
{
|
||||||
|
const QRect pillRect = option.rect.adjusted(PAD_X / 2, PAD_Y / 2, -PAD_X / 2, -PAD_Y / 2);
|
||||||
|
if (pillRect.width() <= 0 || pillRect.height() <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((option.state & QStyle::State_Selected) == 0) {
|
||||||
|
painter->save();
|
||||||
|
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
QColor pill = option.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();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStyle *style = option.widget != nullptr ? option.widget->style() : QApplication::style();
|
||||||
|
const QString elided = option.fontMetrics.elidedText(text, option.textElideMode, pillRect.width());
|
||||||
|
style->drawItemText(painter, pillRect, Qt::AlignCenter, option.palette, true, elided, textRole);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
29
cockatrice/src/interface/widgets/utility/pill_painter.h
Normal file
29
cockatrice/src/interface/widgets/utility/pill_painter.h
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef PILL_PAINTER_H
|
||||||
|
#define PILL_PAINTER_H
|
||||||
|
|
||||||
|
#include <QPalette>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class QPainter;
|
||||||
|
class QStyleOptionViewItem;
|
||||||
|
|
||||||
|
namespace pill_painter
|
||||||
|
{
|
||||||
|
constexpr int PAD_X = 10;
|
||||||
|
constexpr int PAD_Y = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws a translucent, palette-tinted rounded pill inside the option's rect and
|
||||||
|
* paints the text elided and centred on it, so badges follow the active theme.
|
||||||
|
* Returns false when the cell is too small to hold a pill, leaving the caller to
|
||||||
|
* fall back to default painting.
|
||||||
|
*/
|
||||||
|
bool paint(QPainter *painter,
|
||||||
|
const QStyleOptionViewItem &option,
|
||||||
|
QPalette::ColorRole tintRole,
|
||||||
|
QPalette::ColorRole textRole,
|
||||||
|
const QString &text);
|
||||||
|
|
||||||
|
} // namespace pill_painter
|
||||||
|
|
||||||
|
#endif // PILL_PAINTER_H
|
||||||
Loading…
Add table
Add a link
Reference in a new issue