mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 17:43:23 -08:00
[Completer] Minimum size popup, fall back to compact design if not possible. (#7111)
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
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>
This commit is contained in:
parent
96b0888a73
commit
213ce691dd
4 changed files with 89 additions and 14 deletions
|
|
@ -46,6 +46,22 @@ template <class T> class QSharedPointer;
|
|||
namespace
|
||||
{
|
||||
|
||||
// Below this row width the delegate switches to a compact layout so the card
|
||||
// name stays readable when the popup cannot be as wide as PopupRowWidth.
|
||||
constexpr int CompactRowWidth = 380;
|
||||
constexpr int CompactSymbolRadius = 6;
|
||||
constexpr int CompactSymbolSpacing = 1;
|
||||
constexpr int CompactRightPad = 8;
|
||||
constexpr int ManaZoneWidth = 110;
|
||||
constexpr int CompactManaZoneWidth = 70;
|
||||
constexpr int RightPad = 14;
|
||||
constexpr int TextLeftPad = 12;
|
||||
constexpr int TextRightGap = 8;
|
||||
|
||||
// Below this text width the type-line band is dropped so the name can use the
|
||||
// whole row height instead of being elided to a single readable character.
|
||||
constexpr int MinNameWidth = 120;
|
||||
|
||||
struct ManaColor
|
||||
{
|
||||
QColor fill;
|
||||
|
|
@ -125,7 +141,7 @@ QSize CardCompleterDelegate::sizeHint(const QStyleOptionViewItem &option, const
|
|||
}
|
||||
|
||||
// Fixed wide rows so the popup has room for name, type line, set and mana
|
||||
return {480, CardRowHeight};
|
||||
return {PopupRowWidth, CardRowHeight};
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
@ -176,7 +192,12 @@ void CardCompleterDelegate::drawManaSymbol(QPainter *p, QPoint centre, const QSt
|
|||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
int CardCompleterDelegate::drawManaCost(QPainter *p, const QRect &row, const QString &manaCost, int radius) const
|
||||
int CardCompleterDelegate::drawManaCost(QPainter *p,
|
||||
const QRect &row,
|
||||
const QString &manaCost,
|
||||
int radius,
|
||||
int spacing,
|
||||
int rightPad) const
|
||||
{
|
||||
if (manaCost.isEmpty()) {
|
||||
return row.right();
|
||||
|
|
@ -205,11 +226,9 @@ int CardCompleterDelegate::drawManaCost(QPainter *p, const QRect &row, const QSt
|
|||
totalW += PartGap;
|
||||
}
|
||||
|
||||
totalW += parts.at(i).size() * diam + qMax(0, parts.at(i).size() - 1) * SymbolSpacing;
|
||||
totalW += parts.at(i).size() * diam + qMax(0, parts.at(i).size() - 1) * spacing;
|
||||
}
|
||||
|
||||
const int rightPad = 14;
|
||||
|
||||
int x = row.right() - rightPad - totalW + radius;
|
||||
|
||||
const int cy = row.center().y();
|
||||
|
|
@ -219,11 +238,11 @@ int CardCompleterDelegate::drawManaCost(QPainter *p, const QRect &row, const QSt
|
|||
|
||||
for (const QString &sym : symbols) {
|
||||
drawManaSymbol(p, {x, cy}, sym, radius);
|
||||
x += diam + SymbolSpacing;
|
||||
x += diam + spacing;
|
||||
}
|
||||
|
||||
if (i < parts.size() - 1) {
|
||||
x += PartGap - SymbolSpacing;
|
||||
x += PartGap - spacing;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -290,6 +309,14 @@ void CardCompleterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
|||
const QString typeLine = card->getCardType();
|
||||
const QString setCode = setCodeForCard(card);
|
||||
|
||||
// When the row is too narrow for the full layout, use smaller mana pips and
|
||||
// a slimmer mana zone so the card name keeps as much room as possible.
|
||||
const bool compact = rect.width() < CompactRowWidth;
|
||||
const int symbolRadius = compact ? CompactSymbolRadius : SymbolRadius;
|
||||
const int symbolSpacing = compact ? CompactSymbolSpacing : SymbolSpacing;
|
||||
const int rightPad = compact ? CompactRightPad : RightPad;
|
||||
const int manaZoneWidth = compact ? CompactManaZoneWidth : ManaZoneWidth;
|
||||
|
||||
const QColor accent = accentForColors(card->getColors());
|
||||
|
||||
const QColor base = pal.color(QPalette::Base);
|
||||
|
|
@ -338,7 +365,7 @@ void CardCompleterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
|||
// Right mana zone
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
const QRectF manaZone(cardRect.right() - 110, cardRect.top(), 110, cardRect.height());
|
||||
const QRectF manaZone(cardRect.right() - manaZoneWidth, cardRect.top(), manaZoneWidth, cardRect.height());
|
||||
|
||||
QLinearGradient manaGrad(manaZone.topLeft(), manaZone.bottomLeft());
|
||||
|
||||
|
|
@ -380,22 +407,27 @@ void CardCompleterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
|||
// Mana cost
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
const int costLeft = drawManaCost(painter, cardRect.toRect(), manaCost, SymbolRadius);
|
||||
const int costLeft = drawManaCost(painter, cardRect.toRect(), manaCost, symbolRadius, symbolSpacing, rightPad);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Card name + type line + set code
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
const int textLeft = cardRect.left() + AccentBarWidth + 12;
|
||||
const int textRight = costLeft - 8;
|
||||
const int textLeft = cardRect.left() + AccentBarWidth + TextLeftPad;
|
||||
const int textRight = costLeft - TextRightGap;
|
||||
const int textWidth = qMax(0, textRight - textLeft);
|
||||
|
||||
// If even the compact layout leaves too little room for a readable name,
|
||||
// drop the type-line band and let the name use the full row height.
|
||||
const bool showInfoBand = textWidth >= MinNameWidth;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Card name (top band)
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
{
|
||||
const QRect nameRect(textLeft, rect.top() + 2, textWidth, 20);
|
||||
const QRect nameRect = showInfoBand ? QRect(textLeft, rect.top() + 2, textWidth, 20)
|
||||
: QRect(textLeft, rect.top() + 2, textWidth, rect.height() - 4);
|
||||
|
||||
QFont f = option.font;
|
||||
f.setPixelSize(13);
|
||||
|
|
@ -416,7 +448,7 @@ void CardCompleterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
|||
// Type line + set code (bottom band)
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
{
|
||||
if (showInfoBand) {
|
||||
const QRect infoRect(textLeft, rect.top() + 22, textWidth, rect.height() - 24);
|
||||
|
||||
QFont f = option.font;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue