mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 16:32:16 -07:00
Style tag addition widget to be consistent.
This commit is contained in:
parent
e45da02f09
commit
209d07dd62
2 changed files with 64 additions and 14 deletions
|
|
@ -2,32 +2,33 @@
|
||||||
|
|
||||||
#include "deck_preview_tag_dialog.h"
|
#include "deck_preview_tag_dialog.h"
|
||||||
|
|
||||||
|
#include <QFontMetrics>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
DeckPreviewTagAdditionWidget::DeckPreviewTagAdditionWidget(DeckPreviewDeckTagsDisplayWidget *_parent,
|
DeckPreviewTagAdditionWidget::DeckPreviewTagAdditionWidget(DeckPreviewDeckTagsDisplayWidget *_parent,
|
||||||
const QString &tagName)
|
const QString &_tagName)
|
||||||
: QWidget(_parent), parent(_parent), tagName_(tagName)
|
: QWidget(_parent), parent(_parent), tagName_(_tagName)
|
||||||
{
|
{
|
||||||
// Create layout
|
// Create layout
|
||||||
auto *layout = new QHBoxLayout(this);
|
auto *layout = new QHBoxLayout(this);
|
||||||
layout->setContentsMargins(5, 5, 5, 5);
|
layout->setContentsMargins(5, 5, 5, 5);
|
||||||
layout->setSpacing(5);
|
layout->setSpacing(5);
|
||||||
|
|
||||||
// Create label for the tag name
|
|
||||||
tagLabel_ = new QLabel(tagName_, this);
|
|
||||||
layout->addWidget(tagLabel_);
|
|
||||||
|
|
||||||
// Create close button
|
|
||||||
// closeButton_ = new QPushButton("x", this);
|
|
||||||
// closeButton_->setFixedSize(16, 16); // Small square button
|
|
||||||
// layout->addWidget(closeButton_);
|
|
||||||
|
|
||||||
// Adjust widget size
|
// Adjust widget size
|
||||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||||
|
}
|
||||||
|
|
||||||
// Connect close button to the remove signal
|
QSize DeckPreviewTagAdditionWidget::sizeHint() const
|
||||||
// connect(closeButton_, &QPushButton::clicked, this, &DeckPreviewTagAdditionWidget::tagClosed);
|
{
|
||||||
|
// Calculate the size based on the tag name
|
||||||
|
QFontMetrics fm(font());
|
||||||
|
int textWidth = fm.horizontalAdvance(tagName_);
|
||||||
|
int width = textWidth + 50; // Add extra padding
|
||||||
|
int height = fm.height() + 10; // Height based on font size + padding
|
||||||
|
|
||||||
|
return QSize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckPreviewTagAdditionWidget::mousePressEvent(QMouseEvent *event)
|
void DeckPreviewTagAdditionWidget::mousePressEvent(QMouseEvent *event)
|
||||||
|
|
@ -47,3 +48,50 @@ void DeckPreviewTagAdditionWidget::mousePressEvent(QMouseEvent *event)
|
||||||
parent->parent->parent->refreshBannerCards();
|
parent->parent->parent->refreshBannerCards();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeckPreviewTagAdditionWidget::paintEvent(QPaintEvent *event)
|
||||||
|
{
|
||||||
|
QPainter painter(this);
|
||||||
|
|
||||||
|
// Set background color
|
||||||
|
QColor backgroundColor = Qt::lightGray;
|
||||||
|
painter.setBrush(backgroundColor);
|
||||||
|
painter.setPen(Qt::NoPen);
|
||||||
|
|
||||||
|
// Draw background
|
||||||
|
painter.drawRect(rect());
|
||||||
|
|
||||||
|
// Draw border
|
||||||
|
QColor borderColor = Qt::gray;
|
||||||
|
QPen borderPen(borderColor, 1);
|
||||||
|
painter.setPen(borderPen);
|
||||||
|
painter.drawRect(rect().adjusted(0, 0, -1, -1)); // Adjust for pen width
|
||||||
|
|
||||||
|
// Calculate font size based on widget height
|
||||||
|
QFont font = painter.font();
|
||||||
|
int fontSize = std::max(10, height() / 2); // Ensure a minimum font size of 10
|
||||||
|
font.setPointSize(fontSize);
|
||||||
|
painter.setFont(font);
|
||||||
|
|
||||||
|
// Calculate text rect with margin
|
||||||
|
int margin = 10; // Left and right margins
|
||||||
|
QRect textRect(margin, 0, width() - margin * 2, height());
|
||||||
|
|
||||||
|
// Draw the text with a black border for better legibility
|
||||||
|
painter.setPen(Qt::black);
|
||||||
|
|
||||||
|
// Draw text border by offsetting
|
||||||
|
for (int dx = -1; dx <= 1; ++dx) {
|
||||||
|
for (int dy = -1; dy <= 1; ++dy) {
|
||||||
|
if (dx != 0 || dy != 0) {
|
||||||
|
painter.drawText(textRect.translated(dx, dy), Qt::AlignLeft | Qt::AlignVCenter, tagName_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw the actual text
|
||||||
|
painter.setPen(Qt::white);
|
||||||
|
painter.drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, tagName_);
|
||||||
|
|
||||||
|
QWidget::paintEvent(event);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ class DeckPreviewTagAdditionWidget : public QWidget
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DeckPreviewTagAdditionWidget(DeckPreviewDeckTagsDisplayWidget *_parent, const QString &tagName);
|
explicit DeckPreviewTagAdditionWidget(DeckPreviewDeckTagsDisplayWidget *_parent, const QString &tagName);
|
||||||
|
QSize sizeHint() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void tagClicked(); // Emitted when the tag is clicked
|
void tagClicked(); // Emitted when the tag is clicked
|
||||||
|
|
@ -20,6 +21,7 @@ signals:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
|
void paintEvent(QPaintEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeckPreviewDeckTagsDisplayWidget *parent;
|
DeckPreviewDeckTagsDisplayWidget *parent;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue