mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 02:53:25 -08:00
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 cover (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 26 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Desktop / Prune caches (push) Waiting to run
Build Docker / Servatrice (arm) (push) Waiting to run
Build Docker / Servatrice (x86) (push) Waiting to run
Build Docker / Publish multi-platform Servatrice image (push) Blocked by required conditions
* [Completer] Minimum size popup, fall back to compact design if not possible. Took 15 minutes Took 6 seconds Took 5 minutes * [Completer] Fix popup going offscreen by clamping in screen coordinates The position clamping in applyPopupWidth() was comparing popup->pos() (parent coordinates) against screen->availableGeometry() (screen coordinates). When the parent widget is not at the screen origin the clamping computed a position in the wrong coordinate space, placing the popup offscreen. Convert to global coordinates first, clamp, then map back to parent coordinates. * [Completer] Clamp popup from geometry() in screen coordinates setMinimumWidth() already widens the popup synchronously, so the old width() < minWidth guard never ran and the popup grew past the right screen edge. The popup is also a top-level Qt::Popup window, so move() takes global coordinates and the mapFromGlobal round-trip moved it to the top-left of the screen. Clamp x from geometry() after setMinimumWidth() and move(QPoint(clampedX, popup->y())) directly. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
67 lines
2.2 KiB
C++
67 lines
2.2 KiB
C++
/**
|
|
* @file card_completer_delegate.h
|
|
* @ingroup UtilityWidgets
|
|
*/
|
|
//! \todo Document this file.
|
|
|
|
#ifndef CARD_COMPLETER_DELEGATE_H
|
|
#define CARD_COMPLETER_DELEGATE_H
|
|
|
|
#include <QCache>
|
|
#include <QColor>
|
|
#include <QString>
|
|
#include <QStyledItemDelegate>
|
|
#include <qtmetamacros.h>
|
|
|
|
class CardInfo;
|
|
class QObject;
|
|
class QPainter;
|
|
class QPoint;
|
|
class QRect;
|
|
template <class T> class QSharedPointer;
|
|
|
|
/**
|
|
* @brief Paints styled card completer popup rows.
|
|
*
|
|
* Each row shows the card name, type line, set code and mana cost pips,
|
|
* color-coded by the card's color identity. Card data is read directly from
|
|
* the CardSearchModel::CardInfoRole so no extra database lookups are needed.
|
|
*/
|
|
class CardCompleterDelegate : public QStyledItemDelegate
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit CardCompleterDelegate(QObject *parent = nullptr);
|
|
|
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
|
|
|
// Content width of one popup row; the completer popup is sized to fit it.
|
|
static constexpr int PopupRowWidth = 480;
|
|
|
|
private:
|
|
// Set short codes, resolved once per card name and cached
|
|
mutable QCache<QString, QString> setCodeCache;
|
|
|
|
// Resolve the card's color string ("RG", "W", "", ...) → accent QColor
|
|
static QColor accentForColors(const QString &colors);
|
|
|
|
// Draw a single mana symbol pip at centre point
|
|
void drawManaSymbol(QPainter *p, QPoint centre, const QString &symbol, int radius) const;
|
|
|
|
// Draw all mana pips for a cost string like "2RG" or "{2}{R}{G}"; split and
|
|
// adventure costs ("1W // W") are drawn as separate groups. Returns the left-most x used
|
|
int
|
|
drawManaCost(QPainter *p, const QRect &row, const QString &manaCost, int radius, int spacing, int rightPad) const;
|
|
|
|
// Resolve the preferred printing's set short code for a card
|
|
QString setCodeForCard(const QSharedPointer<CardInfo> &card) const;
|
|
|
|
static constexpr int CardRowHeight = 40;
|
|
static constexpr int AccentBarWidth = 5;
|
|
static constexpr int SymbolRadius = 9;
|
|
static constexpr int SymbolSpacing = 2;
|
|
static constexpr int PartGap = 14;
|
|
};
|
|
|
|
#endif // CARD_COMPLETER_DELEGATE_H
|