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
This commit is contained in:
parent
bbf055c483
commit
0ff2c4e246
18 changed files with 121 additions and 26 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#include "../../client/settings/cache_settings.h"
|
||||
#include "../../interface/card_localization.h"
|
||||
#include "../../interface/card_picture_loader/card_picture_loader.h"
|
||||
#include "../../interface/theme_manager.h"
|
||||
#include "../card_dimensions.h"
|
||||
#include "../game_scene.h"
|
||||
#include "../z_values.h"
|
||||
|
|
@ -146,7 +147,7 @@ void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &transla
|
|||
painter->rotate(angle);
|
||||
painter->translate(-translatedSize.width() / 2, -translatedSize.height() / 2);
|
||||
|
||||
QFont f;
|
||||
QFont f = themeManager->appFont(AppFont::CardText);
|
||||
f.setPixelSize(fontSize * scale);
|
||||
|
||||
painter->setFont(f);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include "abstract_graphics_item.h"
|
||||
|
||||
#include "../../interface/theme_manager.h"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QFont>
|
||||
#include <QFontMetrics>
|
||||
|
|
@ -20,7 +22,7 @@ void AbstractGraphicsItem::paintNumberEllipse(int number,
|
|||
painter->save();
|
||||
|
||||
QString numStr = QString::number(number);
|
||||
QFont font("Serif");
|
||||
QFont font = themeManager->appFont(AppFont::CardText);
|
||||
font.setPixelSize(fontSize);
|
||||
font.setWeight(QFont::Bold);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "counter_general.h"
|
||||
|
||||
#include "../../interface/pixel_map_generator.h"
|
||||
#include "../../interface/theme_manager.h"
|
||||
#include "abstract_graphics_item.h"
|
||||
|
||||
#include <QFont>
|
||||
|
|
@ -41,7 +42,7 @@ void GeneralCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /
|
|||
painter->drawPixmap(QPoint(0, 0), pixmap);
|
||||
|
||||
if (value) {
|
||||
QFont f("Serif");
|
||||
QFont f = themeManager->appFont(AppFont::CardText);
|
||||
f.setPixelSize(qMax((int)(radius * scaleFactor), 10));
|
||||
f.setWeight(QFont::Bold);
|
||||
painter->setPen(Qt::black);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "../../game/player/player_info.h"
|
||||
#include "../../game/player/player_logic.h"
|
||||
#include "../../interface/pixel_map_generator.h"
|
||||
#include "../../interface/theme_manager.h"
|
||||
#include "../board/abstract_counter.h"
|
||||
#include "../board/abstract_graphics_item.h"
|
||||
#include "../board/arrow_target.h"
|
||||
|
|
@ -76,7 +77,7 @@ void PlayerCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*
|
|||
|
||||
QRectF translatedRect = path.controlPointRect();
|
||||
QSize translatedSize = translatedRect.size().toSize();
|
||||
QFont font("Serif");
|
||||
QFont font = themeManager->appFont(AppFont::CardText);
|
||||
font.setWeight(QFont::Bold);
|
||||
font.setPixelSize(qMax(qRound(translatedSize.height() / 1.3), 9));
|
||||
painter->setFont(font);
|
||||
|
|
@ -226,7 +227,7 @@ void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o
|
|||
name = name.mid(0, 10) + "...";
|
||||
}
|
||||
|
||||
QFont font;
|
||||
QFont font = themeManager->appFont(AppFont::CardText);
|
||||
font.setPixelSize(qMax(qRound(translatedNameRect.height() / 1.5), 9));
|
||||
painter->setFont(font);
|
||||
painter->setPen(Qt::white);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "art_crop_attribution.h"
|
||||
|
||||
#include "../../theme_manager.h"
|
||||
#include "libcockatrice/card/printing/printing_info.h"
|
||||
|
||||
#include <QColor>
|
||||
|
|
@ -35,7 +36,10 @@ QRectF paintArtAttribution(QPainter &painter,
|
|||
|
||||
painter.save();
|
||||
|
||||
// Family comes from the CardText theme role; the incoming painter size
|
||||
// stays the basis for the scale factor exactly as before.
|
||||
QFont font = painter.font();
|
||||
font.setFamily(themeManager->appFont(AppFont::CardText).family());
|
||||
font.setPointSizeF(qMax(6.0, font.pointSizeF() * scale));
|
||||
painter.setFont(font);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include "card_info_picture_with_text_overlay_widget.h"
|
||||
|
||||
#include "../../theme_manager.h"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QChar>
|
||||
#include <QFont>
|
||||
|
|
@ -43,6 +45,7 @@ CardInfoPictureWithTextOverlayWidget::CardInfoPictureWithTextOverlayWidget(QWidg
|
|||
fontSize(fontSize), textAlignment(alignment), highlighted(false)
|
||||
{
|
||||
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
connect(themeManager, &ThemeManager::fontsChanged, this, &CardInfoPictureWithTextOverlayWidget::applyCardTextFont);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -97,6 +100,13 @@ void CardInfoPictureWithTextOverlayWidget::setTextAlignment(const Qt::Alignment
|
|||
update();
|
||||
}
|
||||
|
||||
void CardInfoPictureWithTextOverlayWidget::applyCardTextFont()
|
||||
{
|
||||
// The overlay paint reads the CardText role font at paint time, so a
|
||||
// theme font change only needs a repaint here.
|
||||
update();
|
||||
}
|
||||
|
||||
void CardInfoPictureWithTextOverlayWidget::setHighlighted(bool _highlighted)
|
||||
{
|
||||
if (highlighted == _highlighted) {
|
||||
|
|
@ -168,8 +178,10 @@ void CardInfoPictureWithTextOverlayWidget::paintEvent(QPaintEvent *event)
|
|||
return;
|
||||
}
|
||||
|
||||
// Calculate the optimal font size
|
||||
QFont font = painter.font();
|
||||
// Calculate the optimal font size. The family comes from the CardText
|
||||
// theme role; the fontSize member stays the starting size and the
|
||||
// shrink-to-fit logic below is unchanged.
|
||||
QFont font = themeManager->appFont(AppFont::CardText);
|
||||
int optimalFontSize = fontSize; // Start with the user-defined font size
|
||||
const QFontMetrics baseMetrics(font);
|
||||
int textWidth = pixmapRect.width();
|
||||
|
|
@ -284,7 +296,7 @@ QSize CardInfoPictureWithTextOverlayWidget::minimumSizeHint() const
|
|||
const QSize pixmapSize = pixmap.isNull() ? QSize(0, 0) : pixmap.size();
|
||||
|
||||
// Get the font metrics for the overlay text
|
||||
QFont font;
|
||||
QFont font = themeManager->appFont(AppFont::CardText);
|
||||
font.setPointSize(fontSize);
|
||||
const QFontMetrics fontMetrics(font);
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,9 @@ protected:
|
|||
void mousePressEvent(QMouseEvent *event) override;
|
||||
[[nodiscard]] QSize minimumSizeHint() const override;
|
||||
|
||||
private slots:
|
||||
void applyCardTextFont();
|
||||
|
||||
private:
|
||||
void drawOutlinedText(QPainter &painter,
|
||||
const QRect &textRect,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "all_zones_card_amount_widget.h"
|
||||
|
||||
#include "../../theme_manager.h"
|
||||
#include "../general/display/shadow_background_label.h"
|
||||
#include "card_amount_widget.h"
|
||||
#include "libcockatrice/card/card_info.h"
|
||||
|
|
@ -67,6 +68,7 @@ AllZonesCardAmountWidget::AllZonesCardAmountWidget(QWidget *parent,
|
|||
buttonBoxSideboard->setVisible(!isToken);
|
||||
|
||||
connect(cardSizeSlider, &QSlider::valueChanged, this, &AllZonesCardAmountWidget::adjustFontSize);
|
||||
connect(themeManager, &ThemeManager::fontsChanged, this, &AllZonesCardAmountWidget::applyCardTextFont);
|
||||
|
||||
QTimer::singleShot(10, this, [this]() { adjustFontSize(this->cardSizeSlider->value()); });
|
||||
|
||||
|
|
@ -90,8 +92,9 @@ void AllZonesCardAmountWidget::adjustFontSize(int scalePercentage)
|
|||
int newFontSize = minFontSize + (scalePercentage - basePercentage) * (maxFontSize - minFontSize) / 225;
|
||||
newFontSize = std::clamp(newFontSize, minFontSize, maxFontSize);
|
||||
|
||||
// Update the font labels
|
||||
QFont zoneLabelFont = zoneLabelMainboard->font();
|
||||
// Update the font labels. The family comes from the CardText theme
|
||||
// role; the slider-driven point size stays as before.
|
||||
QFont zoneLabelFont = themeManager->appFont(AppFont::CardText);
|
||||
zoneLabelFont.setPointSize(newFontSize);
|
||||
zoneLabelMainboard->setFont(zoneLabelFont);
|
||||
zoneLabelSideboard->setFont(zoneLabelFont);
|
||||
|
|
@ -101,6 +104,11 @@ void AllZonesCardAmountWidget::adjustFontSize(int scalePercentage)
|
|||
repaint();
|
||||
}
|
||||
|
||||
void AllZonesCardAmountWidget::applyCardTextFont()
|
||||
{
|
||||
adjustFontSize(cardSizeSlider->value());
|
||||
}
|
||||
|
||||
void AllZonesCardAmountWidget::setAmounts(int mainboardAmount, int sideboardAmount, int tokensboardAmount)
|
||||
{
|
||||
buttonBoxMainboard->setAmount(mainboardAmount);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,9 @@ public slots:
|
|||
void adjustFontSize(int scalePercentage);
|
||||
void setAmounts(int mainboardAmount, int sideboardAmount, int tokensboardAmount);
|
||||
|
||||
private slots:
|
||||
void applyCardTextFont();
|
||||
|
||||
private:
|
||||
QVBoxLayout *layout;
|
||||
QSlider *cardSizeSlider;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "card_amount_widget.h"
|
||||
|
||||
#include "../../theme_manager.h"
|
||||
#include "../deck_editor/deck_state_manager.h"
|
||||
#include "../general/display/dynamic_font_size_push_button.h"
|
||||
#include "deck_list_model.h"
|
||||
|
|
@ -78,6 +79,7 @@ CardAmountWidget::CardAmountWidget(QWidget *parent,
|
|||
|
||||
// Connect slider for dynamic font size adjustment
|
||||
connect(cardSizeSlider, &QSlider::valueChanged, this, &CardAmountWidget::adjustFontSize);
|
||||
connect(themeManager, &ThemeManager::fontsChanged, this, &CardAmountWidget::applyCardTextFont);
|
||||
}
|
||||
|
||||
int CardAmountWidget::getAmount()
|
||||
|
|
@ -139,8 +141,9 @@ void CardAmountWidget::adjustFontSize(int scalePercentage)
|
|||
int newFontSize = minFontSize + (scalePercentage - basePercentage) * (maxFontSize - minFontSize) / 225;
|
||||
newFontSize = std::clamp(newFontSize, minFontSize, maxFontSize);
|
||||
|
||||
// Update the font for card count label
|
||||
QFont cardCountFont = cardCountInZone->font();
|
||||
// Update the font for card count label. The family comes from the
|
||||
// CardText theme role; the slider-driven point size stays as before.
|
||||
QFont cardCountFont = themeManager->appFont(AppFont::CardText);
|
||||
cardCountFont.setPointSize(newFontSize);
|
||||
cardCountInZone->setFont(cardCountFont);
|
||||
|
||||
|
|
@ -151,6 +154,11 @@ void CardAmountWidget::adjustFontSize(int scalePercentage)
|
|||
repaint();
|
||||
}
|
||||
|
||||
void CardAmountWidget::applyCardTextFont()
|
||||
{
|
||||
adjustFontSize(cardSizeSlider->value());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Updates the card count display in the widget.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ private slots:
|
|||
void removePrintingSideboard();
|
||||
void removePrintingTokensboard();
|
||||
void adjustFontSize(int scalePercentage);
|
||||
void applyCardTextFont();
|
||||
};
|
||||
|
||||
#endif // CARD_AMOUNT_WIDGET_H
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "archidekt_deck_preview_image_display_widget.h"
|
||||
|
||||
#include "../../../../../theme_manager.h"
|
||||
#include "../../../../general/display/shadow_background_label.h"
|
||||
|
||||
#include <QFont>
|
||||
|
|
@ -17,13 +18,9 @@ ArchidektDeckPreviewImageDisplayWidget::ArchidektDeckPreviewImageDisplayWidget(Q
|
|||
bottomLeftLabel = new ShadowBackgroundLabel(this, "");
|
||||
bottomRightLabel = new ShadowBackgroundLabel(this, "");
|
||||
|
||||
QFont f;
|
||||
f.setBold(true);
|
||||
f.setPointSize(16);
|
||||
topLeftLabel->setFont(f);
|
||||
topRightLabel->setFont(f);
|
||||
bottomLeftLabel->setFont(f);
|
||||
bottomRightLabel->setFont(f);
|
||||
applyCardTextFont();
|
||||
connect(themeManager, &ThemeManager::fontsChanged, this,
|
||||
&ArchidektDeckPreviewImageDisplayWidget::applyCardTextFont);
|
||||
|
||||
// Raise so labels appear above image
|
||||
topLeftLabel->raise();
|
||||
|
|
@ -32,6 +29,18 @@ ArchidektDeckPreviewImageDisplayWidget::ArchidektDeckPreviewImageDisplayWidget(Q
|
|||
bottomRightLabel->raise();
|
||||
}
|
||||
|
||||
void ArchidektDeckPreviewImageDisplayWidget::applyCardTextFont()
|
||||
{
|
||||
// Family comes from the CardText theme role; size and weight stay caller-side as before.
|
||||
QFont f = themeManager->appFont(AppFont::CardText);
|
||||
f.setBold(true);
|
||||
f.setPointSize(16);
|
||||
topLeftLabel->setFont(f);
|
||||
topRightLabel->setFont(f);
|
||||
bottomLeftLabel->setFont(f);
|
||||
bottomRightLabel->setFont(f);
|
||||
}
|
||||
|
||||
void ArchidektDeckPreviewImageDisplayWidget::setAspectRatio(float ratio)
|
||||
{
|
||||
aspectRatio = ratio;
|
||||
|
|
|
|||
|
|
@ -60,6 +60,9 @@ protected:
|
|||
*/
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void applyCardTextFont();
|
||||
|
||||
private:
|
||||
float aspectRatio = 1.0f; ///< Aspect ratio to maintain for the preview image
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "edhrec_api_response_card_details_display_widget.h"
|
||||
|
||||
#include "../../../../../../theme_manager.h"
|
||||
#include "../../../../../cards/card_info_picture_widget.h"
|
||||
#include "../../../../../cards/card_size_widget.h"
|
||||
#include "../../../../../general/display/background_plate_widget.h"
|
||||
|
|
@ -9,6 +10,7 @@
|
|||
#include "edhrec_api_response_card_synergy_display_widget.h"
|
||||
#include "libcockatrice/card/database/card_database_querier.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QLabel>
|
||||
#include <QMouseEvent>
|
||||
#include <QObject>
|
||||
|
|
@ -31,7 +33,9 @@ EdhrecApiResponseCardDetailsDisplayWidget::EdhrecApiResponseCardDetailsDisplayWi
|
|||
nameLabel = new QLabel(this);
|
||||
nameLabel->setText(toDisplay.name);
|
||||
nameLabel->setAlignment(Qt::AlignHCenter);
|
||||
nameLabel->setStyleSheet("font-size: 20px; font-weight: bold");
|
||||
applyCardTextFont();
|
||||
connect(themeManager, &ThemeManager::fontsChanged, this,
|
||||
&EdhrecApiResponseCardDetailsDisplayWidget::applyCardTextFont);
|
||||
|
||||
inclusionDisplayWidget = new EdhrecApiResponseCardInclusionDisplayWidget(this, toDisplay);
|
||||
|
||||
|
|
@ -93,3 +97,13 @@ void EdhrecApiResponseCardDetailsDisplayWidget::actRequestPageNavigation()
|
|||
{
|
||||
emit requestUrl(toDisplay.url);
|
||||
}
|
||||
|
||||
void EdhrecApiResponseCardDetailsDisplayWidget::applyCardTextFont()
|
||||
{
|
||||
// Family comes from the CardText theme role; the 20px size and bold
|
||||
// weight previously carried by the stylesheet stay caller-side.
|
||||
QFont cardFont = themeManager->appFont(AppFont::CardText);
|
||||
cardFont.setPointSize(20);
|
||||
cardFont.setWeight(QFont::Bold);
|
||||
nameLabel->setFont(cardFont);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,9 @@ public slots:
|
|||
signals:
|
||||
void requestUrl(QString url);
|
||||
|
||||
private slots:
|
||||
void applyCardTextFont();
|
||||
|
||||
private:
|
||||
EdhrecApiResponseCardDetails toDisplay;
|
||||
QVBoxLayout *layout;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "edhrec_api_response_commander_details_display_widget.h"
|
||||
|
||||
#include "../../../../../../theme_manager.h"
|
||||
#include "../../../../../cards/card_info_picture_widget.h"
|
||||
#include "../../../../../cards/card_size_widget.h"
|
||||
#include "../../api_response/cards/edhrec_commander_api_response_commander_details.h"
|
||||
|
|
@ -8,6 +9,7 @@
|
|||
#include "edhrec_commander_api_response_navigation_widget.h"
|
||||
#include "libcockatrice/card/database/card_database_querier.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QObject>
|
||||
|
|
@ -55,15 +57,16 @@ EdhrecCommanderResponseCommanderDetailsDisplayWidget::EdhrecCommanderResponseCom
|
|||
commanderName = new QLabel(this);
|
||||
commanderName->setText(commanderDetails.getName());
|
||||
commanderName->setAlignment(Qt::AlignCenter);
|
||||
commanderName->setStyleSheet("font-size: 28px; font-weight: bold");
|
||||
|
||||
label = new QLabel(this);
|
||||
label->setAlignment(Qt::AlignCenter);
|
||||
label->setStyleSheet("font-size: 16px");
|
||||
|
||||
salt = new QLabel(this);
|
||||
salt->setAlignment(Qt::AlignCenter);
|
||||
salt->setStyleSheet("font-size: 16px");
|
||||
|
||||
applyCardTextFont();
|
||||
connect(themeManager, &ThemeManager::fontsChanged, this,
|
||||
&EdhrecCommanderResponseCommanderDetailsDisplayWidget::applyCardTextFont);
|
||||
|
||||
cardPricesDisplayWidget = new EdhrecApiResponseCardPricesDisplayWidget(this, commanderDetails.getPrices());
|
||||
|
||||
|
|
@ -90,3 +93,18 @@ void EdhrecCommanderResponseCommanderDetailsDisplayWidget::retranslateUi()
|
|||
label->setText(commanderDetails.getLabel());
|
||||
salt->setText(tr("Salt: ") + QString::number(commanderDetails.getSalt()));
|
||||
}
|
||||
|
||||
void EdhrecCommanderResponseCommanderDetailsDisplayWidget::applyCardTextFont()
|
||||
{
|
||||
// Family comes from the CardText theme role; the point sizes and the
|
||||
// bold weight previously carried by the stylesheets stay caller-side.
|
||||
QFont nameFont = themeManager->appFont(AppFont::CardText);
|
||||
nameFont.setPointSize(28);
|
||||
nameFont.setWeight(QFont::Bold);
|
||||
commanderName->setFont(nameFont);
|
||||
|
||||
QFont detailsFont = themeManager->appFont(AppFont::CardText);
|
||||
detailsFont.setPointSize(16);
|
||||
label->setFont(detailsFont);
|
||||
salt->setFont(detailsFont);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,9 @@ public:
|
|||
QString baseUrl);
|
||||
void retranslateUi();
|
||||
|
||||
private slots:
|
||||
void applyCardTextFont();
|
||||
|
||||
private:
|
||||
EdhrecCommanderApiResponseCommanderDetails commanderDetails;
|
||||
QHBoxLayout *layout;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "card_completer_delegate.h"
|
||||
|
||||
#include "../../interface/theme_manager.h"
|
||||
#include "../../pixel_map_generator.h"
|
||||
#include "../cards/additional_info/mana_cost_widget.h"
|
||||
#include "libcockatrice/card/database/card_database_querier.h"
|
||||
|
|
@ -181,7 +182,7 @@ void CardCompleterDelegate::drawManaSymbol(QPainter *p, QPoint centre, const QSt
|
|||
p->setBrush(Qt::NoBrush);
|
||||
p->drawEllipse(pip.adjusted(1, 1, -1, -1));
|
||||
|
||||
QFont f = p->font();
|
||||
QFont f = themeManager->appFont(AppFont::CardText);
|
||||
f.setPixelSize(qMax(radius - 1, 7));
|
||||
f.setBold(true);
|
||||
|
||||
|
|
@ -429,7 +430,7 @@ void CardCompleterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
|||
const QRect nameRect = showInfoBand ? QRect(textLeft, rect.top() + 2, textWidth, 20)
|
||||
: QRect(textLeft, rect.top() + 2, textWidth, rect.height() - 4);
|
||||
|
||||
QFont f = option.font;
|
||||
QFont f = themeManager->appFont(AppFont::CardText);
|
||||
f.setPixelSize(13);
|
||||
f.setBold(true);
|
||||
|
||||
|
|
@ -451,7 +452,7 @@ void CardCompleterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
|||
if (showInfoBand) {
|
||||
const QRect infoRect(textLeft, rect.top() + 22, textWidth, rect.height() - 24);
|
||||
|
||||
QFont f = option.font;
|
||||
QFont f = themeManager->appFont(AppFont::CardText);
|
||||
f.setPixelSize(10);
|
||||
|
||||
painter->setFont(f);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue