Good Lint Inc.

This commit is contained in:
Lukas Brübach 2024-12-16 02:48:48 +01:00 committed by ZeldaZach
parent 61b33aa808
commit 1640262e8d
No known key found for this signature in database
10 changed files with 75 additions and 72 deletions

View file

@ -81,9 +81,9 @@ set(cockatrice_SOURCES
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/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/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/server/message_log_widget.cpp
src/client/ui/layouts/overlap_layout.cpp

View file

@ -2,7 +2,8 @@
#include "../../../../settings/cache_settings.h"
CardSizeWidget::CardSizeWidget(QWidget *parent, FlowWidget *flowWidget, int defaultValue) : parent(parent), flowWidget(flowWidget)
CardSizeWidget::CardSizeWidget(QWidget *parent, FlowWidget *flowWidget, int defaultValue)
: parent(parent), flowWidget(flowWidget)
{
cardSizeLayout = new QHBoxLayout(this);
setLayout(cardSizeLayout);

View file

@ -4,13 +4,12 @@
#include <QDebug>
#include <QElapsedTimer>
DynamicFontSizeLabel::DynamicFontSizeLabel(QWidget* parent, Qt::WindowFlags f)
: QLabel(parent, f) {
DynamicFontSizeLabel::DynamicFontSizeLabel(QWidget *parent, Qt::WindowFlags f) : QLabel(parent, f)
{
setIndent(0);
}
void DynamicFontSizeLabel::mousePressEvent(QMouseEvent* event)
void DynamicFontSizeLabel::mousePressEvent(QMouseEvent *event)
{
Q_UNUSED(event)
emit clicked();
@ -18,20 +17,19 @@ void DynamicFontSizeLabel::mousePressEvent(QMouseEvent* event)
void DynamicFontSizeLabel::paintEvent(QPaintEvent *event)
{
//QElapsedTimer timer;
//timer.start();
// QElapsedTimer timer;
// timer.start();
QFont newFont = font();
float fontSize = getWidgetMaximumFontSize(this, this->text());
newFont.setPointSizeF(fontSize);
setFont(newFont);
//qDebug() << "Font size set to" << fontSize;
// qDebug() << "Font size set to" << fontSize;
QLabel::paintEvent(event);
//LOG(true, "Paint delay" << ((float)timer.nsecsElapsed())/1000000.0 << " mS");
// LOG(true, "Paint delay" << ((float)timer.nsecsElapsed())/1000000.0 << " mS");
}
float DynamicFontSizeLabel::getWidgetMaximumFontSize(QWidget *widget, QString text)
{
QFont font = widget->font();
@ -42,18 +40,18 @@ float DynamicFontSizeLabel::getWidgetMaximumFontSize(QWidget *widget, QString te
QRectF newFontSizeRect;
float currentSize = font.pointSizeF();
float step = currentSize/2.0;
float step = currentSize / 2.0;
/* If too small, increase step */
if (step<=FONT_PRECISION){
step = FONT_PRECISION*4.0;
if (step <= FONT_PRECISION) {
step = FONT_PRECISION * 4.0;
}
float lastTestedSize = currentSize;
float currentHeight = 0;
float currentWidth = 0;
if (text==""){
if (text == "") {
return currentSize;
}
@ -62,7 +60,7 @@ float DynamicFontSizeLabel::getWidgetMaximumFontSize(QWidget *widget, QString te
}
/* Only stop when step is small enough and new size is smaller than QWidget */
while(step>FONT_PRECISION || (currentHeight > widgetHeight) || (currentWidth > widgetWidth)){
while (step > FONT_PRECISION || (currentHeight > widgetHeight) || (currentWidth > widgetWidth)) {
/* Keep last tested value */
lastTestedSize = currentSize;
@ -72,52 +70,56 @@ float DynamicFontSizeLabel::getWidgetMaximumFontSize(QWidget *widget, QString te
QFontMetricsF fm(font);
/* Check if widget is QLabel */
QLabel *label = qobject_cast<QLabel*>(widget);
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);
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 ((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;
if (step > FONT_PRECISION) {
step /= 2.0;
}
/* Do not allow negative size */
if (currentSize<=0){
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;
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){
void DynamicFontSizeLabel::setTextColor(QColor color)
{
if (color.isValid() && color != textColor) {
textColor = color;
setStyleSheet("color : "+color.name()+";");
setStyleSheet("color : " + color.name() + ";");
}
}
QColor DynamicFontSizeLabel::getTextColor(){
QColor DynamicFontSizeLabel::getTextColor()
{
return textColor;
}
void DynamicFontSizeLabel::setTextAndColor(const QString &text, QColor color){
void DynamicFontSizeLabel::setTextAndColor(const QString &text, QColor color)
{
setTextColor(color);
setText(text);
}
@ -131,5 +133,5 @@ QSize DynamicFontSizeLabel::minimumSizeHint() const
/* Do not give any size hint as it it changes during paintEvent */
QSize DynamicFontSizeLabel::sizeHint() const
{
return QWidget::sizeHint();
return QWidget::sizeHint();
}

View file

@ -1,16 +1,19 @@
#ifndef DYNAMICFONTSIZELABEL_H
#define DYNAMICFONTSIZELABEL_H
#include <QLabel>
#include <QColor>
#include <QLabel>
class DynamicFontSizeLabel : public QLabel {
class DynamicFontSizeLabel : public QLabel
{
Q_OBJECT
public:
explicit DynamicFontSizeLabel(QWidget* parent = NULL, Qt::WindowFlags f = Qt::WindowFlags());
explicit DynamicFontSizeLabel(QWidget *parent = NULL, Qt::WindowFlags f = Qt::WindowFlags());
~DynamicFontSizeLabel() {}
~DynamicFontSizeLabel()
{
}
static float getWidgetMaximumFontSize(QWidget *widget, QString text);
@ -18,14 +21,13 @@ public:
void setTextColor(QColor color);
QColor getTextColor();
void setTextAndColor(const QString &text, QColor color = QColor::Invalid);
signals:
void clicked();
signals:
void clicked();
protected:
void mousePressEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent *event);
QColor textColor;
// QWidget interface
protected:
void paintEvent(QPaintEvent *event);

View file

@ -1,14 +1,12 @@
#include "dynamic_font_size_push_button.h"
#include <QDebug>
#include "dynamic_font_size_label.h"
#include <QDebug>
#include <QPainter>
DynamicFontSizePushButton::DynamicFontSizePushButton(QWidget* parent)
: QPushButton(parent)
DynamicFontSizePushButton::DynamicFontSizePushButton(QWidget *parent) : QPushButton(parent)
{
}
void DynamicFontSizePushButton::paintEvent(QPaintEvent *event)
@ -38,8 +36,8 @@ void DynamicFontSizePushButton::paintEvent(QPaintEvent *event)
gradient.setColorAt(1, QColor(48, 48, 48));
} else {
// Normal state
gradient.setColorAt(0, QColor(64, 64, 64)); // start color
gradient.setColorAt(1, QColor(32, 32, 32)); // end color
gradient.setColorAt(0, QColor(64, 64, 64)); // start color
gradient.setColorAt(1, QColor(32, 32, 32)); // end color
}
painter.setBrush(gradient);
painter.setPen(Qt::NoPen); // No border

View file

@ -2,18 +2,18 @@
#define DYNAMICFONTSIZEPUSHBUTTON_H
#include <QObject>
#include <QWidget>
#include <QPushButton>
#include <QWidget>
class DynamicFontSizePushButton : public QPushButton
{
public:
explicit DynamicFontSizePushButton(QWidget* parent = NULL);
explicit DynamicFontSizePushButton(QWidget *parent = NULL);
/* This method overwrite stylesheet */
void setTextColor(QColor color);
QColor getTextColor();
void setTextAndColor(const QString &text, QColor color=QColor::Invalid);
void setTextAndColor(const QString &text, QColor color = QColor::Invalid);
// QWidget interface
QSize minimumSizeHint() const;
@ -24,7 +24,6 @@ protected:
private:
QColor textColor;
};
#endif // DYNAMICFONTSIZEPUSHBUTTON_H

View file

@ -1,9 +1,9 @@
#include "shadow_background_label.h"
#include <QPainter>
#include <QPaintEvent>
ShadowBackgroundLabel::ShadowBackgroundLabel(QWidget *parent, const QString &text)
: QLabel(parent)
#include <QPaintEvent>
#include <QPainter>
ShadowBackgroundLabel::ShadowBackgroundLabel(QWidget *parent, const QString &text) : QLabel(parent)
{
setAttribute(Qt::WA_TranslucentBackground); // Allows transparency
setText("<font color='white'>" + text + "</font>");
@ -24,7 +24,7 @@ void ShadowBackgroundLabel::paintEvent(QPaintEvent *event)
// Semi-transparent background
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setBrush(QColor(0, 0, 0, 128)); // Semi-transparent black
painter.setPen(Qt::NoPen); // No border
painter.setPen(Qt::NoPen); // No border
// Compute the painting rectangle accounting for margins
QRect adjustedRect = this->rect();

View file

@ -3,7 +3,8 @@
#include <QLabel>
class ShadowBackgroundLabel : public QLabel {
class ShadowBackgroundLabel : public QLabel
{
Q_OBJECT
public:

View file

@ -21,11 +21,11 @@ AllZonesCardAmountWidget::AllZonesCardAmountWidget(QWidget *parent,
setContentsMargins(5, 5, 5, 5); // Padding around the text
zoneLabelMainboard = new ShadowBackgroundLabel(this, tr("Mainboard"));
buttonBoxMainboard =
new CardAmountWidget(this, deckEditor, deckModel, deckView, cardSizeSlider, rootCard, setInfoForCard, DECK_ZONE_MAIN);
buttonBoxMainboard = new CardAmountWidget(this, deckEditor, deckModel, deckView, cardSizeSlider, rootCard,
setInfoForCard, DECK_ZONE_MAIN);
zoneLabelSideboard = new ShadowBackgroundLabel(this, tr("Sideboard"));
buttonBoxSideboard =
new CardAmountWidget(this, deckEditor, deckModel, deckView, cardSizeSlider, rootCard, setInfoForCard, DECK_ZONE_SIDE);
buttonBoxSideboard = new CardAmountWidget(this, deckEditor, deckModel, deckView, cardSizeSlider, rootCard,
setInfoForCard, DECK_ZONE_SIDE);
layout->addWidget(zoneLabelMainboard, 0, Qt::AlignHCenter | Qt::AlignBottom);
layout->addWidget(buttonBoxMainboard, 0, Qt::AlignHCenter | Qt::AlignTop);
@ -35,9 +35,7 @@ AllZonesCardAmountWidget::AllZonesCardAmountWidget(QWidget *parent,
connect(cardSizeSlider, &QSlider::valueChanged, this, &AllZonesCardAmountWidget::adjustFontSize);
QTimer::singleShot(10, this, [this]() {
adjustFontSize(this->cardSizeSlider->value());
});
QTimer::singleShot(10, this, [this]() { adjustFontSize(this->cardSizeSlider->value()); });
setMouseTracking(true);
}

View file

@ -116,7 +116,8 @@ void CardAmountWidget::addPrinting(const QString &zone)
}
deckModel->removeRow(find_card.row(), find_card.parent());
};
newCardIndex = deckModel->findCard(rootCard->getName(), zone, setInfoForCard.getProperty("uuid"), setInfoForCard.getProperty("num"));
newCardIndex = deckModel->findCard(rootCard->getName(), zone, setInfoForCard.getProperty("uuid"),
setInfoForCard.getProperty("num"));
deckView->setCurrentIndex(newCardIndex);
deckView->setFocus(Qt::FocusReason::MouseFocusReason);
}
@ -170,7 +171,8 @@ void CardAmountWidget::offsetCountAtIndex(const QModelIndex &idx, int offset)
void CardAmountWidget::decrementCardHelper(const QString &zone)
{
QModelIndex idx;
idx = deckModel->findCard(rootCard->getName(), zone, setInfoForCard.getProperty("uuid"), setInfoForCard.getProperty("num"));
idx = deckModel->findCard(rootCard->getName(), zone, setInfoForCard.getProperty("uuid"),
setInfoForCard.getProperty("num"));
offsetCountAtIndex(idx, -1);
}