diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index 4d3697304..4fbba62e2 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -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 diff --git a/cockatrice/src/client/ui/widgets/cards/card_size_widget.cpp b/cockatrice/src/client/ui/widgets/cards/card_size_widget.cpp index d5827cd2a..8ca07c4de 100644 --- a/cockatrice/src/client/ui/widgets/cards/card_size_widget.cpp +++ b/cockatrice/src/client/ui/widgets/cards/card_size_widget.cpp @@ -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); diff --git a/cockatrice/src/client/ui/widgets/general/display/dynamic_font_size_label.cpp b/cockatrice/src/client/ui/widgets/general/display/dynamic_font_size_label.cpp index 2a48de86e..a9b800500 100644 --- a/cockatrice/src/client/ui/widgets/general/display/dynamic_font_size_label.cpp +++ b/cockatrice/src/client/ui/widgets/general/display/dynamic_font_size_label.cpp @@ -4,13 +4,12 @@ #include #include -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(widget); + QLabel *label = qobject_cast(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(); } \ No newline at end of file diff --git a/cockatrice/src/client/ui/widgets/general/display/dynamic_font_size_label.h b/cockatrice/src/client/ui/widgets/general/display/dynamic_font_size_label.h index a4da774c3..c27def74d 100644 --- a/cockatrice/src/client/ui/widgets/general/display/dynamic_font_size_label.h +++ b/cockatrice/src/client/ui/widgets/general/display/dynamic_font_size_label.h @@ -1,16 +1,19 @@ #ifndef DYNAMICFONTSIZELABEL_H #define DYNAMICFONTSIZELABEL_H -#include #include +#include -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); diff --git a/cockatrice/src/client/ui/widgets/general/display/dynamic_font_size_push_button.cpp b/cockatrice/src/client/ui/widgets/general/display/dynamic_font_size_push_button.cpp index c3b6c18ed..fce4512e8 100644 --- a/cockatrice/src/client/ui/widgets/general/display/dynamic_font_size_push_button.cpp +++ b/cockatrice/src/client/ui/widgets/general/display/dynamic_font_size_push_button.cpp @@ -1,14 +1,12 @@ #include "dynamic_font_size_push_button.h" -#include #include "dynamic_font_size_label.h" +#include #include -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 diff --git a/cockatrice/src/client/ui/widgets/general/display/dynamic_font_size_push_button.h b/cockatrice/src/client/ui/widgets/general/display/dynamic_font_size_push_button.h index 1ed134e10..eb33a7d80 100644 --- a/cockatrice/src/client/ui/widgets/general/display/dynamic_font_size_push_button.h +++ b/cockatrice/src/client/ui/widgets/general/display/dynamic_font_size_push_button.h @@ -2,18 +2,18 @@ #define DYNAMICFONTSIZEPUSHBUTTON_H #include -#include #include +#include 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 \ No newline at end of file diff --git a/cockatrice/src/client/ui/widgets/general/display/shadow_background_label.cpp b/cockatrice/src/client/ui/widgets/general/display/shadow_background_label.cpp index 1d53bb05e..5ecc9a415 100644 --- a/cockatrice/src/client/ui/widgets/general/display/shadow_background_label.cpp +++ b/cockatrice/src/client/ui/widgets/general/display/shadow_background_label.cpp @@ -1,9 +1,9 @@ #include "shadow_background_label.h" -#include -#include -ShadowBackgroundLabel::ShadowBackgroundLabel(QWidget *parent, const QString &text) - : QLabel(parent) +#include +#include + +ShadowBackgroundLabel::ShadowBackgroundLabel(QWidget *parent, const QString &text) : QLabel(parent) { setAttribute(Qt::WA_TranslucentBackground); // Allows transparency setText("" + text + ""); @@ -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(); diff --git a/cockatrice/src/client/ui/widgets/general/display/shadow_background_label.h b/cockatrice/src/client/ui/widgets/general/display/shadow_background_label.h index c608e1b6b..992c8e81c 100644 --- a/cockatrice/src/client/ui/widgets/general/display/shadow_background_label.h +++ b/cockatrice/src/client/ui/widgets/general/display/shadow_background_label.h @@ -3,7 +3,8 @@ #include -class ShadowBackgroundLabel : public QLabel { +class ShadowBackgroundLabel : public QLabel +{ Q_OBJECT public: diff --git a/cockatrice/src/client/ui/widgets/printing_selector/all_zones_card_amount_widget.cpp b/cockatrice/src/client/ui/widgets/printing_selector/all_zones_card_amount_widget.cpp index c72604d6e..f8cf0cb77 100644 --- a/cockatrice/src/client/ui/widgets/printing_selector/all_zones_card_amount_widget.cpp +++ b/cockatrice/src/client/ui/widgets/printing_selector/all_zones_card_amount_widget.cpp @@ -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); } diff --git a/cockatrice/src/client/ui/widgets/printing_selector/card_amount_widget.cpp b/cockatrice/src/client/ui/widgets/printing_selector/card_amount_widget.cpp index 00eec6f9b..232f50892 100644 --- a/cockatrice/src/client/ui/widgets/printing_selector/card_amount_widget.cpp +++ b/cockatrice/src/client/ui/widgets/printing_selector/card_amount_widget.cpp @@ -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); }