mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
* [Fonts] Migrate CardText surfaces to theme font role * [Fonts] Keep CardText call sites on the app font and fix px sizes - CardText's unset fallback is qApp->font() again: only the three counter painters (paintNumberEllipse, GeneralCounter, PlayerCounter) were Serif before the role existed, and they now ask for it through ThemeManager::cardTextFont(). Card names, player names, counters, the overlay, the Archidekt and EDHREC labels and the completer delegate keep the app font they used before. - Use setPixelSize for the EDHREC card name (20px) and commander name (28px) and details (16px) sizes: the stylesheets said px, and setPointSize made them about a third larger. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
72 lines
2.2 KiB
C++
72 lines
2.2 KiB
C++
#include "abstract_graphics_item.h"
|
|
|
|
#include "../../interface/theme_manager.h"
|
|
|
|
#include <QBrush>
|
|
#include <QFont>
|
|
#include <QFontMetrics>
|
|
#include <QPainter>
|
|
#include <QRectF>
|
|
#include <QString>
|
|
#include <QTransform>
|
|
#include <QtGlobal>
|
|
#include <qnamespace.h>
|
|
|
|
void AbstractGraphicsItem::paintNumberEllipse(int number,
|
|
int fontSize,
|
|
const QColor &color,
|
|
int position,
|
|
int count,
|
|
QPainter *painter)
|
|
{
|
|
painter->save();
|
|
|
|
QString numStr = QString::number(number);
|
|
QFont font = themeManager->cardTextFont();
|
|
font.setPixelSize(fontSize);
|
|
font.setWeight(QFont::Bold);
|
|
|
|
QFontMetrics fm(font);
|
|
double w = 1.3 * fm.horizontalAdvance(numStr);
|
|
double h = fm.height() * 1.3;
|
|
if (w < h) {
|
|
w = h;
|
|
}
|
|
|
|
painter->setPen(QColor(255, 255, 255, 0));
|
|
painter->setBrush(QBrush(QColor(color)));
|
|
|
|
QRectF textRect;
|
|
if (position == -1) {
|
|
textRect = QRectF((boundingRect().width() - w) / 2.0, (boundingRect().height() - h) / 2.0, w, h);
|
|
} else {
|
|
qreal xOffset = 10;
|
|
qreal yOffset = 20;
|
|
qreal spacing = 2;
|
|
if (position < 2) {
|
|
textRect = QRectF(count == 1 ? ((boundingRect().width() - w) / 2.0)
|
|
: (position % 2 == 0 ? xOffset : (boundingRect().width() - xOffset - w)),
|
|
yOffset, w, h);
|
|
} else {
|
|
textRect = QRectF(count == 3 ? ((boundingRect().width() - w) / 2.0)
|
|
: (position % 2 == 0 ? xOffset : (boundingRect().width() - xOffset - w)),
|
|
yOffset + (spacing + h) * (position / 2), w, h);
|
|
}
|
|
}
|
|
|
|
painter->drawEllipse(textRect);
|
|
|
|
painter->setPen(Qt::black);
|
|
painter->setFont(font);
|
|
painter->drawText(textRect, Qt::AlignCenter, numStr);
|
|
|
|
painter->restore();
|
|
}
|
|
|
|
int resetPainterTransform(QPainter *painter)
|
|
{
|
|
painter->resetTransform();
|
|
auto tx = painter->deviceTransform().inverted();
|
|
painter->setTransform(tx);
|
|
return tx.isScaling() ? 1.0 / tx.m11() : 1;
|
|
}
|