mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-21 01:42:15 -07:00
Try to wrangle font sizes.
This commit is contained in:
parent
a2f519222d
commit
f3a7be7e3f
12 changed files with 369 additions and 57 deletions
|
|
@ -81,6 +81,9 @@ set(cockatrice_SOURCES
|
||||||
src/client/ui/widgets/cards/card_info_picture_enlarged_widget.cpp
|
src/client/ui/widgets/cards/card_info_picture_enlarged_widget.cpp
|
||||||
src/client/ui/widgets/cards/card_info_picture_with_text_overlay_widget.cpp
|
src/client/ui/widgets/cards/card_info_picture_with_text_overlay_widget.cpp
|
||||||
src/client/ui/widgets/general/display/labeled_input.cpp
|
src/client/ui/widgets/general/display/labeled_input.cpp
|
||||||
|
src/client/ui/widgets/general/display/dynamic_font_size_label.cpp
|
||||||
|
src/client/ui/widgets/general/display/dynamic_font_size_push_button.cpp
|
||||||
|
src/client/ui/widgets/general/display/shadow_background_label.cpp
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
src/server/message_log_widget.cpp
|
src/server/message_log_widget.cpp
|
||||||
src/client/ui/layouts/overlap_layout.cpp
|
src/client/ui/layouts/overlap_layout.cpp
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,131 @@
|
||||||
|
#include "dynamic_font_size_label.h"
|
||||||
|
#define FONT_PRECISION (0.5)
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QElapsedTimer>
|
||||||
|
|
||||||
|
DynamicFontSizeLabel::DynamicFontSizeLabel(QWidget* parent, Qt::WindowFlags f)
|
||||||
|
: QLabel(parent, f) {
|
||||||
|
setIndent(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DynamicFontSizeLabel::mousePressEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
Q_UNUSED(event)
|
||||||
|
emit clicked();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DynamicFontSizeLabel::paintEvent(QPaintEvent *event)
|
||||||
|
{
|
||||||
|
//QElapsedTimer timer;
|
||||||
|
//timer.start();
|
||||||
|
|
||||||
|
QFont newFont = font();
|
||||||
|
float fontSize = getWidgetMaximumFontSize(this, this->text());
|
||||||
|
newFont.setPointSizeF(fontSize);
|
||||||
|
setFont(newFont);
|
||||||
|
//qDebug() << "Font size set to" << fontSize;
|
||||||
|
|
||||||
|
QLabel::paintEvent(event);
|
||||||
|
//LOG(true, "Paint delay" << ((float)timer.nsecsElapsed())/1000000.0 << " mS");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float DynamicFontSizeLabel::getWidgetMaximumFontSize(QWidget *widget, QString text)
|
||||||
|
{
|
||||||
|
QFont font = widget->font();
|
||||||
|
const QRect widgetRect = widget->contentsRect();
|
||||||
|
const float widgetWidth = widgetRect.width();
|
||||||
|
const float widgetHeight = widgetRect.height();
|
||||||
|
|
||||||
|
QRectF newFontSizeRect;
|
||||||
|
float currentSize = font.pointSizeF();
|
||||||
|
|
||||||
|
float step = currentSize/2.0;
|
||||||
|
|
||||||
|
/* If too small, increase step */
|
||||||
|
if (step<=FONT_PRECISION){
|
||||||
|
step = FONT_PRECISION*4.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float lastTestedSize = currentSize;
|
||||||
|
|
||||||
|
float currentHeight = 0;
|
||||||
|
float currentWidth = 0;
|
||||||
|
if (text==""){
|
||||||
|
return currentSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Only stop when step is small enough and new size is smaller than QWidget */
|
||||||
|
while(step>FONT_PRECISION || (currentHeight > widgetHeight) || (currentWidth > widgetWidth)){
|
||||||
|
/* Keep last tested value */
|
||||||
|
lastTestedSize = currentSize;
|
||||||
|
|
||||||
|
/* Test label with its font */
|
||||||
|
font.setPointSizeF(currentSize);
|
||||||
|
/* Use font metrics to test */
|
||||||
|
QFontMetricsF fm(font);
|
||||||
|
|
||||||
|
/* Check if widget is QLabel */
|
||||||
|
QLabel *label = qobject_cast<QLabel*>(widget);
|
||||||
|
if (label) {
|
||||||
|
newFontSizeRect = fm.boundingRect(widgetRect, (label->wordWrap()?Qt::TextWordWrap:0) | label->alignment(), text);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
newFontSizeRect = fm.boundingRect(widgetRect, 0, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
currentHeight = newFontSizeRect.height();
|
||||||
|
currentWidth = newFontSizeRect.width();
|
||||||
|
|
||||||
|
/* If new font size is too big, decrease it */
|
||||||
|
if ((currentHeight > widgetHeight) || (currentWidth > widgetWidth)){
|
||||||
|
//qDebug() << "-- contentsRect()" << label->contentsRect() << "rect"<< label->rect() << " newFontSizeRect" << newFontSizeRect << "Tight" << text << currentSize;
|
||||||
|
currentSize -=step;
|
||||||
|
/* if step is small enough, keep it constant, so it converge to biggest font size */
|
||||||
|
if (step>FONT_PRECISION){
|
||||||
|
step/=2.0;
|
||||||
|
}
|
||||||
|
/* Do not allow negative size */
|
||||||
|
if (currentSize<=0){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* If new font size is smaller than maximum possible size, increase it */
|
||||||
|
else{
|
||||||
|
//qDebug() << "++ contentsRect()" << label->contentsRect() << "rect"<< label->rect() << " newFontSizeRect" << newFontSizeRect << "Tight" << text << currentSize;
|
||||||
|
currentSize +=step;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lastTestedSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DynamicFontSizeLabel::setTextColor(QColor color){
|
||||||
|
if (color.isValid() && color!=textColor){
|
||||||
|
textColor = color;
|
||||||
|
setStyleSheet("color : "+color.name()+";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor DynamicFontSizeLabel::getTextColor(){
|
||||||
|
return textColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DynamicFontSizeLabel::setTextAndColor(const QString &text, QColor color){
|
||||||
|
setTextColor(color);
|
||||||
|
setText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Do not give any size hint as it it changes during paintEvent */
|
||||||
|
QSize DynamicFontSizeLabel::minimumSizeHint() const
|
||||||
|
{
|
||||||
|
return QWidget::minimumSizeHint();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Do not give any size hint as it it changes during paintEvent */
|
||||||
|
QSize DynamicFontSizeLabel::sizeHint() const
|
||||||
|
{
|
||||||
|
return QWidget::sizeHint();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
#ifndef DYNAMICFONTSIZELABEL_H
|
||||||
|
#define DYNAMICFONTSIZELABEL_H
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QColor>
|
||||||
|
|
||||||
|
class DynamicFontSizeLabel : public QLabel {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DynamicFontSizeLabel(QWidget* parent = NULL, Qt::WindowFlags f = Qt::WindowFlags());
|
||||||
|
|
||||||
|
~DynamicFontSizeLabel() {}
|
||||||
|
|
||||||
|
static float getWidgetMaximumFontSize(QWidget *widget, QString text);
|
||||||
|
|
||||||
|
/* This method overwrite stylesheet */
|
||||||
|
void setTextColor(QColor color);
|
||||||
|
QColor getTextColor();
|
||||||
|
void setTextAndColor(const QString &text, QColor color = QColor::Invalid);
|
||||||
|
signals:
|
||||||
|
void clicked();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QMouseEvent* event);
|
||||||
|
QColor textColor;
|
||||||
|
|
||||||
|
|
||||||
|
// QWidget interface
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *event);
|
||||||
|
|
||||||
|
// QWidget interface
|
||||||
|
public:
|
||||||
|
QSize minimumSizeHint() const;
|
||||||
|
QSize sizeHint() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DYNAMICFONTSIZELABEL_H
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
#include "dynamic_font_size_push_button.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include "dynamic_font_size_label.h"
|
||||||
|
|
||||||
|
DynamicFontSizePushButton::DynamicFontSizePushButton(QWidget* parent)
|
||||||
|
:QPushButton(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DynamicFontSizePushButton::paintEvent(QPaintEvent *event)
|
||||||
|
{
|
||||||
|
//QElapsedTimer timer;
|
||||||
|
//timer.start();
|
||||||
|
|
||||||
|
QFont newFont = font();
|
||||||
|
float fontSize = DynamicFontSizeLabel::getWidgetMaximumFontSize(this, this->text());
|
||||||
|
newFont.setPointSizeF(fontSize);
|
||||||
|
setFont(newFont);
|
||||||
|
|
||||||
|
QPushButton::paintEvent(event);
|
||||||
|
//LOG(true, "Paint delay" << ((float)timer.nsecsElapsed())/1000000.0 << " mS");
|
||||||
|
}
|
||||||
|
|
||||||
|
void DynamicFontSizePushButton::setTextColor(QColor color){
|
||||||
|
if (color.isValid() && color!=textColor){
|
||||||
|
textColor = color;
|
||||||
|
setStyleSheet("color : "+color.name()+";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DynamicFontSizePushButton::setTextAndColor(const QString &text, QColor color){
|
||||||
|
setTextColor(color);
|
||||||
|
setText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor DynamicFontSizePushButton::getTextColor(){
|
||||||
|
return textColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Do not give any size hint as it it changes during paintEvent */
|
||||||
|
QSize DynamicFontSizePushButton::minimumSizeHint() const
|
||||||
|
{
|
||||||
|
return QWidget::minimumSizeHint();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Do not give any size hint as it it changes during paintEvent */
|
||||||
|
QSize DynamicFontSizePushButton::sizeHint() const
|
||||||
|
{
|
||||||
|
return QWidget::sizeHint();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef DYNAMICFONTSIZEPUSHBUTTON_H
|
||||||
|
#define DYNAMICFONTSIZEPUSHBUTTON_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
class DynamicFontSizePushButton : public QPushButton
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit DynamicFontSizePushButton(QWidget* parent = NULL);
|
||||||
|
|
||||||
|
/* This method overwrite stylesheet */
|
||||||
|
void setTextColor(QColor color);
|
||||||
|
QColor getTextColor();
|
||||||
|
|
||||||
|
void setTextAndColor(const QString &text, QColor color=QColor::Invalid);
|
||||||
|
|
||||||
|
// QWidget interface
|
||||||
|
QSize minimumSizeHint() const;
|
||||||
|
QSize sizeHint() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QColor textColor;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DYNAMICFONTSIZEPUSHBUTTON_H
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
#include "shadow_background_label.h"
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPaintEvent>
|
||||||
|
|
||||||
|
ShadowBackgroundLabel::ShadowBackgroundLabel(QWidget *parent, const QString &text)
|
||||||
|
: QLabel(parent)
|
||||||
|
{
|
||||||
|
setAttribute(Qt::WA_TranslucentBackground); // Allows transparency
|
||||||
|
setText(text);
|
||||||
|
setAlignment(Qt::AlignCenter);
|
||||||
|
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShadowBackgroundLabel::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
QLabel::resizeEvent(event);
|
||||||
|
update(); // Repaint borders explicitly
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShadowBackgroundLabel::paintEvent(QPaintEvent *event)
|
||||||
|
{
|
||||||
|
QPainter painter(this);
|
||||||
|
|
||||||
|
// Semi-transparent background
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
painter.setBrush(QColor(0, 0, 0, 128)); // Semi-transparent black
|
||||||
|
painter.setPen(Qt::NoPen); // No border
|
||||||
|
|
||||||
|
// Compute the painting rectangle accounting for margins
|
||||||
|
QRect adjustedRect = this->rect();
|
||||||
|
int margin = contentsMargins().left(); // Assuming equal margins
|
||||||
|
adjustedRect.adjust(margin, margin, -margin, -margin);
|
||||||
|
|
||||||
|
// Draw rounded rectangle
|
||||||
|
painter.drawRoundedRect(adjustedRect, 5, 5); // Rounded corners (radius: 5)
|
||||||
|
|
||||||
|
// Let QLabel handle text rendering
|
||||||
|
QLabel::paintEvent(event);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef STYLEDLABEL_H
|
||||||
|
#define STYLEDLABEL_H
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
|
class ShadowBackgroundLabel : public QLabel {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ShadowBackgroundLabel(QWidget *parent, const QString &text);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
void paintEvent(QPaintEvent *event) override; // Custom painting logic
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // STYLEDLABEL_H
|
||||||
|
|
@ -1,43 +1,29 @@
|
||||||
#include "all_zones_card_amount_widget.h"
|
#include "all_zones_card_amount_widget.h"
|
||||||
|
|
||||||
|
#include "../general/display/shadow_background_label.h"
|
||||||
|
|
||||||
AllZonesCardAmountWidget::AllZonesCardAmountWidget(QWidget *parent,
|
AllZonesCardAmountWidget::AllZonesCardAmountWidget(QWidget *parent,
|
||||||
TabDeckEditor *deckEditor,
|
TabDeckEditor *deckEditor,
|
||||||
DeckListModel *deckModel,
|
DeckListModel *deckModel,
|
||||||
QTreeView *deckView,
|
QTreeView *deckView,
|
||||||
|
QSlider *cardSizeSlider,
|
||||||
CardInfoPtr rootCard,
|
CardInfoPtr rootCard,
|
||||||
CardInfoPerSet setInfoForCard)
|
CardInfoPerSet setInfoForCard)
|
||||||
: QWidget(parent), deckEditor(deckEditor), deckModel(deckModel), deckView(deckView), rootCard(rootCard),
|
: QWidget(parent), deckEditor(deckEditor), deckModel(deckModel), deckView(deckView), cardSizeSlider(cardSizeSlider),
|
||||||
setInfoForCard(setInfoForCard)
|
rootCard(rootCard), setInfoForCard(setInfoForCard)
|
||||||
{
|
{
|
||||||
layout = new QVBoxLayout(this);
|
layout = new QVBoxLayout(this);
|
||||||
layout->setAlignment(Qt::AlignCenter);
|
layout->setAlignment(Qt::AlignHCenter);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
setContentsMargins(5, 5, 5, 5); // Padding around the text
|
||||||
|
|
||||||
zoneLabelMainboard = new QLabel(tr("Mainboard"), this);
|
zoneLabelMainboard = new ShadowBackgroundLabel(this, tr("Mainboard"));
|
||||||
zoneLabelMainboard->setStyleSheet(R"(
|
|
||||||
QLabel {
|
|
||||||
background-color: rgba(0, 0, 0, 128); /* Semi-transparent black */
|
|
||||||
color: white; /* Text color */
|
|
||||||
font-size: 16px;
|
|
||||||
border-radius: 5px; /* Rounded corners */
|
|
||||||
padding: 5px; /* Padding around text */
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
buttonBoxMainboard =
|
buttonBoxMainboard =
|
||||||
new CardAmountWidget(this, deckEditor, deckModel, deckView, rootCard, setInfoForCard, DECK_ZONE_MAIN);
|
new CardAmountWidget(this, deckEditor, deckModel, deckView, cardSizeSlider, rootCard, setInfoForCard, DECK_ZONE_MAIN);
|
||||||
zoneLabelSideboard = new QLabel(tr("Sideboard"), this);
|
zoneLabelSideboard = new ShadowBackgroundLabel(this, tr("Sideboard"));
|
||||||
zoneLabelSideboard->setStyleSheet(R"(
|
|
||||||
QLabel {
|
|
||||||
background-color: rgba(0, 0, 0, 128); /* Semi-transparent black */
|
|
||||||
color: white; /* Text color */
|
|
||||||
font-size: 16px;
|
|
||||||
border-radius: 5px; /* Rounded corners */
|
|
||||||
padding: 5px; /* Padding around text */
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
buttonBoxSideboard =
|
buttonBoxSideboard =
|
||||||
new CardAmountWidget(this, deckEditor, deckModel, deckView, rootCard, setInfoForCard, DECK_ZONE_SIDE);
|
new CardAmountWidget(this, deckEditor, deckModel, deckView, cardSizeSlider, rootCard, setInfoForCard, DECK_ZONE_SIDE);
|
||||||
|
|
||||||
layout->addWidget(zoneLabelMainboard, 0, Qt::AlignHCenter | Qt::AlignBottom);
|
layout->addWidget(zoneLabelMainboard, 0, Qt::AlignHCenter | Qt::AlignBottom);
|
||||||
layout->addWidget(buttonBoxMainboard, 0, Qt::AlignHCenter | Qt::AlignTop);
|
layout->addWidget(buttonBoxMainboard, 0, Qt::AlignHCenter | Qt::AlignTop);
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ public:
|
||||||
TabDeckEditor *deckEditor,
|
TabDeckEditor *deckEditor,
|
||||||
DeckListModel *deckModel,
|
DeckListModel *deckModel,
|
||||||
QTreeView *deckView,
|
QTreeView *deckView,
|
||||||
|
QSlider *cardSizeSlider,
|
||||||
CardInfoPtr rootCard,
|
CardInfoPtr rootCard,
|
||||||
CardInfoPerSet setInfoForCard);
|
CardInfoPerSet setInfoForCard);
|
||||||
int getMainboardAmount();
|
int getMainboardAmount();
|
||||||
|
|
@ -31,6 +32,7 @@ private:
|
||||||
TabDeckEditor *deckEditor;
|
TabDeckEditor *deckEditor;
|
||||||
DeckListModel *deckModel;
|
DeckListModel *deckModel;
|
||||||
QTreeView *deckView;
|
QTreeView *deckView;
|
||||||
|
QSlider *cardSizeSlider;
|
||||||
CardInfoPtr rootCard;
|
CardInfoPtr rootCard;
|
||||||
CardInfoPerSet setInfoForCard;
|
CardInfoPerSet setInfoForCard;
|
||||||
QLabel *zoneLabelMainboard;
|
QLabel *zoneLabelMainboard;
|
||||||
|
|
|
||||||
|
|
@ -1,50 +1,30 @@
|
||||||
#include "card_amount_widget.h"
|
#include "card_amount_widget.h"
|
||||||
|
|
||||||
|
#include "../general/display/dynamic_font_size_push_button.h"
|
||||||
|
|
||||||
CardAmountWidget::CardAmountWidget(QWidget *parent,
|
CardAmountWidget::CardAmountWidget(QWidget *parent,
|
||||||
TabDeckEditor *deckEditor,
|
TabDeckEditor *deckEditor,
|
||||||
DeckListModel *deckModel,
|
DeckListModel *deckModel,
|
||||||
QTreeView *deckView,
|
QTreeView *deckView,
|
||||||
|
QSlider *cardSizeSlider,
|
||||||
CardInfoPtr &rootCard,
|
CardInfoPtr &rootCard,
|
||||||
CardInfoPerSet &setInfoForCard,
|
CardInfoPerSet &setInfoForCard,
|
||||||
QString zoneName)
|
QString zoneName)
|
||||||
: QWidget(parent), deckEditor(deckEditor), deckModel(deckModel), deckView(deckView), rootCard(rootCard),
|
: QWidget(parent), deckEditor(deckEditor), deckModel(deckModel), deckView(deckView), cardSizeSlider(cardSizeSlider),
|
||||||
setInfoForCard(setInfoForCard), zoneName(zoneName), hovered(false)
|
rootCard(rootCard), setInfoForCard(setInfoForCard), zoneName(zoneName), hovered(false)
|
||||||
{
|
{
|
||||||
layout = new QHBoxLayout(this);
|
layout = new QHBoxLayout(this);
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
layout->setSpacing(10);
|
layout->setSpacing(10);
|
||||||
this->setLayout(layout);
|
this->setLayout(layout);
|
||||||
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||||
|
|
||||||
incrementButton = new QPushButton(this);
|
incrementButton = new DynamicFontSizePushButton(this);
|
||||||
|
incrementButton->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||||
incrementButton->setText("+");
|
incrementButton->setText("+");
|
||||||
decrementButton = new QPushButton(this);
|
decrementButton = new DynamicFontSizePushButton(this);
|
||||||
decrementButton->setText("-");
|
decrementButton->setText("-");
|
||||||
|
|
||||||
incrementButton->setFixedSize(30, 30);
|
|
||||||
decrementButton->setFixedSize(30, 30);
|
|
||||||
|
|
||||||
// Apply styles for gradient buttons
|
|
||||||
QString buttonStyle = R"(
|
|
||||||
QPushButton {
|
|
||||||
background: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1,
|
|
||||||
stop:0 rgba(64, 64, 64, 255), stop:1 rgba(32, 32, 32, 255));
|
|
||||||
border: none;
|
|
||||||
color: white;
|
|
||||||
font-size: 16px;
|
|
||||||
}
|
|
||||||
QPushButton:hover {
|
|
||||||
background: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1,
|
|
||||||
stop:0 rgba(96, 96, 96, 255), stop:1 rgba(48, 48, 48, 255));
|
|
||||||
}
|
|
||||||
QPushButton:pressed {
|
|
||||||
background: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1,
|
|
||||||
stop:0 rgba(128, 128, 128, 255), stop:1 rgba(64, 64, 64, 255));
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
incrementButton->setStyleSheet(buttonStyle);
|
|
||||||
decrementButton->setStyleSheet(buttonStyle);
|
|
||||||
|
|
||||||
// Set up connections
|
// Set up connections
|
||||||
if (zoneName == DECK_ZONE_MAIN) {
|
if (zoneName == DECK_ZONE_MAIN) {
|
||||||
connect(incrementButton, &QPushButton::clicked, this, &CardAmountWidget::addPrintingMainboard);
|
connect(incrementButton, &QPushButton::clicked, this, &CardAmountWidget::addPrintingMainboard);
|
||||||
|
|
@ -55,7 +35,6 @@ CardAmountWidget::CardAmountWidget(QWidget *parent,
|
||||||
}
|
}
|
||||||
|
|
||||||
cardCountInZone = new QLabel(QString::number(countCardsInZone(zoneName)), this);
|
cardCountInZone = new QLabel(QString::number(countCardsInZone(zoneName)), this);
|
||||||
cardCountInZone->setStyleSheet("color: white; font-size: 16px;");
|
|
||||||
cardCountInZone->setAlignment(Qt::AlignCenter);
|
cardCountInZone->setAlignment(Qt::AlignCenter);
|
||||||
|
|
||||||
layout->addWidget(decrementButton);
|
layout->addWidget(decrementButton);
|
||||||
|
|
@ -65,6 +44,10 @@ CardAmountWidget::CardAmountWidget(QWidget *parent,
|
||||||
// React to model changes
|
// React to model changes
|
||||||
connect(deckModel, &DeckListModel::dataChanged, this, &CardAmountWidget::updateCardCount);
|
connect(deckModel, &DeckListModel::dataChanged, this, &CardAmountWidget::updateCardCount);
|
||||||
connect(deckModel, &QAbstractItemModel::rowsRemoved, this, &CardAmountWidget::updateCardCount);
|
connect(deckModel, &QAbstractItemModel::rowsRemoved, this, &CardAmountWidget::updateCardCount);
|
||||||
|
|
||||||
|
// Connect slider for dynamic font size adjustment
|
||||||
|
connect(cardSizeSlider, &QSlider::valueChanged, this, &CardAmountWidget::adjustFontSize);
|
||||||
|
adjustFontSize(cardSizeSlider->value());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardAmountWidget::paintEvent(QPaintEvent *event)
|
void CardAmountWidget::paintEvent(QPaintEvent *event)
|
||||||
|
|
@ -80,9 +63,35 @@ void CardAmountWidget::paintEvent(QPaintEvent *event)
|
||||||
QWidget::paintEvent(event);
|
QWidget::paintEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardAmountWidget::adjustFontSize(int scalePercentage)
|
||||||
|
{
|
||||||
|
qDebug() << scalePercentage;
|
||||||
|
const int minFontSize = 8; // Minimum font size
|
||||||
|
const int maxFontSize = 24; // Maximum font size
|
||||||
|
const int basePercentage = 100; // Scale at 100%
|
||||||
|
|
||||||
|
int newFontSize = minFontSize + (scalePercentage - basePercentage) * (maxFontSize - minFontSize) / (250 - 25);
|
||||||
|
newFontSize = std::clamp(newFontSize, minFontSize, maxFontSize);
|
||||||
|
|
||||||
|
qDebug() << newFontSize;
|
||||||
|
|
||||||
|
// Update the font for card count label
|
||||||
|
QFont cardCountFont = cardCountInZone->font();
|
||||||
|
cardCountFont.setPointSize(newFontSize);
|
||||||
|
cardCountInZone->setFont(cardCountFont);
|
||||||
|
|
||||||
|
incrementButton->setFixedSize(parentWidget()->size().width() / 3, parentWidget()->size().height() / 9);
|
||||||
|
decrementButton->setFixedSize(parentWidget()->size().width() / 3, parentWidget()->size().height() / 9);
|
||||||
|
|
||||||
|
// Repaint the widget (if necessary)
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
void CardAmountWidget::updateCardCount()
|
void CardAmountWidget::updateCardCount()
|
||||||
{
|
{
|
||||||
cardCountInZone->setText(QString::number(countCardsInZone(zoneName)));
|
cardCountInZone->setText(QString::number(countCardsInZone(zoneName)));
|
||||||
|
layout->invalidate();
|
||||||
|
layout->activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardAmountWidget::addPrinting(const QString &zone)
|
void CardAmountWidget::addPrinting(const QString &zone)
|
||||||
|
|
@ -153,7 +162,7 @@ void CardAmountWidget::offsetCountAtIndex(const QModelIndex &idx, int offset)
|
||||||
void CardAmountWidget::decrementCardHelper(const QString &zone)
|
void CardAmountWidget::decrementCardHelper(const QString &zone)
|
||||||
{
|
{
|
||||||
QModelIndex idx;
|
QModelIndex idx;
|
||||||
idx = deckModel->findCard(rootCard->getName(), zone, setInfoForCard.getProperty("uuid"));
|
idx = deckModel->findCard(rootCard->getName(), zone, setInfoForCard.getProperty("uuid"), setInfoForCard.getProperty("num"));
|
||||||
offsetCountAtIndex(idx, -1);
|
offsetCountAtIndex(idx, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ public:
|
||||||
TabDeckEditor *deckEditor,
|
TabDeckEditor *deckEditor,
|
||||||
DeckListModel *deckModel,
|
DeckListModel *deckModel,
|
||||||
QTreeView *deckView,
|
QTreeView *deckView,
|
||||||
|
QSlider *cardSizeSlider,
|
||||||
CardInfoPtr &rootCard,
|
CardInfoPtr &rootCard,
|
||||||
CardInfoPerSet &setInfoForCard,
|
CardInfoPerSet &setInfoForCard,
|
||||||
QString zoneName);
|
QString zoneName);
|
||||||
|
|
@ -40,6 +41,7 @@ private:
|
||||||
TabDeckEditor *deckEditor;
|
TabDeckEditor *deckEditor;
|
||||||
DeckListModel *deckModel;
|
DeckListModel *deckModel;
|
||||||
QTreeView *deckView;
|
QTreeView *deckView;
|
||||||
|
QSlider *cardSizeSlider;
|
||||||
CardInfoPtr rootCard;
|
CardInfoPtr rootCard;
|
||||||
CardInfoPerSet setInfoForCard;
|
CardInfoPerSet setInfoForCard;
|
||||||
QString zoneName;
|
QString zoneName;
|
||||||
|
|
@ -60,6 +62,7 @@ private slots:
|
||||||
void addPrintingSideboard();
|
void addPrintingSideboard();
|
||||||
void removePrintingMainboard();
|
void removePrintingMainboard();
|
||||||
void removePrintingSideboard();
|
void removePrintingSideboard();
|
||||||
|
void adjustFontSize(int scalePercentage);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CARD_AMOUNT_WIDGET_H
|
#endif // CARD_AMOUNT_WIDGET_H
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ PrintingSelectorCardOverlayWidget::PrintingSelectorCardOverlayWidget(QWidget *pa
|
||||||
|
|
||||||
// Add AllZonesCardAmountWidget
|
// Add AllZonesCardAmountWidget
|
||||||
allZonesCardAmountWidget =
|
allZonesCardAmountWidget =
|
||||||
new AllZonesCardAmountWidget(this, deckEditor, deckModel, deckView, setCard, setInfoForCard);
|
new AllZonesCardAmountWidget(this, deckEditor, deckModel, deckView, cardSizeSlider, setCard, setInfoForCard);
|
||||||
|
|
||||||
allZonesCardAmountWidget->raise(); // Ensure it's on top of the picture
|
allZonesCardAmountWidget->raise(); // Ensure it's on top of the picture
|
||||||
// Set initial visibility based on amounts
|
// Set initial visibility based on amounts
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue