mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-08-02 22:30:24 -07:00
Good Lint Inc.
This commit is contained in:
parent
61b33aa808
commit
1640262e8d
10 changed files with 75 additions and 72 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -4,10 +4,9 @@
|
|||
#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)
|
||||
|
|
@ -31,7 +30,6 @@ void DynamicFontSizeLabel::paintEvent(QPaintEvent *event)
|
|||
// LOG(true, "Paint delay" << ((float)timer.nsecsElapsed())/1000000.0 << " mS");
|
||||
}
|
||||
|
||||
|
||||
float DynamicFontSizeLabel::getWidgetMaximumFontSize(QWidget *widget, QString text)
|
||||
{
|
||||
QFont font = widget->font();
|
||||
|
|
@ -74,9 +72,9 @@ float DynamicFontSizeLabel::getWidgetMaximumFontSize(QWidget *widget, QString te
|
|||
/* 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, (label->wordWrap() ? Qt::TextWordWrap : 0) | label->alignment(), text);
|
||||
} else {
|
||||
newFontSizeRect = fm.boundingRect(widgetRect, 0, text);
|
||||
}
|
||||
|
||||
|
|
@ -85,7 +83,8 @@ float DynamicFontSizeLabel::getWidgetMaximumFontSize(QWidget *widget, QString te
|
|||
|
||||
/* 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;
|
||||
// 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) {
|
||||
|
|
@ -98,26 +97,29 @@ float DynamicFontSizeLabel::getWidgetMaximumFontSize(QWidget *widget, QString te
|
|||
}
|
||||
/* 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;
|
||||
// qDebug() << "++ contentsRect()" << label->contentsRect() << "rect"<< label->rect() << " newFontSizeRect"
|
||||
// << newFontSizeRect << "Tight" << text << currentSize;
|
||||
currentSize += step;
|
||||
}
|
||||
}
|
||||
return lastTestedSize;
|
||||
}
|
||||
|
||||
void DynamicFontSizeLabel::setTextColor(QColor color){
|
||||
void DynamicFontSizeLabel::setTextColor(QColor color)
|
||||
{
|
||||
if (color.isValid() && color != textColor) {
|
||||
textColor = color;
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
||||
~DynamicFontSizeLabel() {}
|
||||
~DynamicFontSizeLabel()
|
||||
{
|
||||
}
|
||||
|
||||
static float getWidgetMaximumFontSize(QWidget *widget, QString text);
|
||||
|
||||
|
|
@ -25,7 +28,6 @@ protected:
|
|||
void mousePressEvent(QMouseEvent *event);
|
||||
QColor textColor;
|
||||
|
||||
|
||||
// QWidget interface
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
#define DYNAMICFONTSIZEPUSHBUTTON_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include <QWidget>
|
||||
|
||||
class DynamicFontSizePushButton : public QPushButton
|
||||
{
|
||||
|
|
@ -24,7 +24,6 @@ protected:
|
|||
|
||||
private:
|
||||
QColor textColor;
|
||||
|
||||
};
|
||||
|
||||
#endif // DYNAMICFONTSIZEPUSHBUTTON_H
|
||||
|
|
@ -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>");
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
|
||||
#include <QLabel>
|
||||
|
||||
class ShadowBackgroundLabel : public QLabel {
|
||||
class ShadowBackgroundLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue