[Cards] Artist attribution (#7092)
Some checks are pending
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 26.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / macOS 15 (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 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker Image / amd64 & arm64 (push) Waiting to run

* [Cards] Artist attribution

Took 7 minutes

Took 4 minutes

* Nudge attribution pill on home screen to align

Took 3 minutes


Took 28 seconds

Took 38 seconds

* Lint.

Took 3 minutes

* Lint.

Took 2 minutes

* Fix rebase whoopsie

Took 5 minutes

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-08-21 02:54:36 +02:00 committed by GitHub
parent 18b4ffefa8
commit 74a454552a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 195 additions and 10 deletions

View file

@ -0,0 +1,61 @@
#include "art_crop_attribution.h"
#include <QFontMetrics>
#include <QObject>
#include <QPainter>
#include <libcockatrice/card/printing/exact_card.h>
QString buildArtAttribution(const ExactCard &card)
{
const QString artist = card.getPrinting().getArtist();
if (artist.isEmpty()) {
return QString();
}
return QObject::tr("Art: %1").arg(artist);
}
QRectF paintArtAttribution(QPainter &painter,
const QRectF &rect,
const QString &attribution,
Qt::Alignment anchor,
qreal scale)
{
if (attribution.isEmpty()) {
return QRectF();
}
painter.save();
QFont font = painter.font();
font.setPointSizeF(qMax(6.0, font.pointSizeF() * scale));
painter.setFont(font);
const QFontMetrics fm(font);
const qreal maxTextWidth = rect.width() * 0.45;
const QString elided = fm.elidedText(attribution, Qt::ElideRight, qMax(qreal(80.0) * scale, maxTextWidth));
const qreal pad = 6.0 * scale;
QRectF captionRect(QPointF(0, 0), QSizeF(fm.horizontalAdvance(elided) + pad * 2.0, fm.height() + pad * 2.0));
const qreal margin = 4.0 * scale;
if (anchor.testFlag(Qt::AlignLeft)) {
captionRect.moveLeft(rect.left() + margin);
} else {
captionRect.moveRight(rect.right() - margin);
}
if (anchor.testFlag(Qt::AlignTop)) {
captionRect.moveTop(rect.top() + margin);
} else {
captionRect.moveBottom(rect.bottom() - margin);
}
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(0, 0, 0, 120));
painter.drawRoundedRect(captionRect, 4, 4);
painter.setPen(QColor(255, 255, 255, 220));
painter.drawText(captionRect, Qt::AlignCenter, elided);
painter.restore();
return captionRect;
}

View file

@ -0,0 +1,41 @@
#ifndef COCKATRICE_ART_CROP_ATTRIBUTION_H
#define COCKATRICE_ART_CROP_ATTRIBUTION_H
#include <QStringView>
class ExactCard;
class QPainter;
class QRectF;
class QString;
/**
* @brief Builds an attribution caption for a cropped card art display.
*
* When a card image's art region is shown cropped (an "art crop"), the artist
* should be credited in the same interface. Returns an empty string when the
* database has no artist data for the card.
*
* @param card The card whose art is being displayed.
* @return Caption such as "Art: John Avon", or empty.
*/
QString buildArtAttribution(const ExactCard &card);
/**
* @brief Paints an attribution caption in a corner of a rect.
*
* Draws a subtle semi-transparent pill containing the caption, elided to fit.
*
* @param painter Painter to draw with.
* @param rect The area (e.g. the cropped art region) the caption belongs to.
* @param attribution Caption text (see buildArtAttribution()).
* @param anchor Corner of @p rect to pin the pill to (default bottom-right).
* @param scale Size multiplier for the pill (e.g. 0.8 for a smaller pill).
* @return The rect the pill was drawn in, or an empty rect if @p attribution is empty.
*/
QRectF paintArtAttribution(QPainter &painter,
const QRectF &rect,
const QString &attribution,
Qt::Alignment anchor = Qt::AlignRight | Qt::AlignBottom,
qreal scale = 1.0);
#endif // COCKATRICE_ART_CROP_ATTRIBUTION_H