Remove close button (for now) and change "Add tags ..." to "Edit tags ..."

This commit is contained in:
Lukas Brübach 2025-01-12 22:46:55 +01:00
parent 3976ab8d5d
commit 856cfb7d87
3 changed files with 17 additions and 17 deletions

View file

@ -26,6 +26,6 @@ DeckPreviewDeckTagsDisplayWidget::DeckPreviewDeckTagsDisplayWidget(DeckPreviewWi
for (const QString &tag : this->deckLoader->getTags()) { for (const QString &tag : this->deckLoader->getTags()) {
flowWidget->addWidget(new DeckPreviewTagDisplayWidget(this, tag)); flowWidget->addWidget(new DeckPreviewTagDisplayWidget(this, tag));
} }
flowWidget->addWidget(new DeckPreviewTagAdditionWidget(this, tr("Add tags ..."))); flowWidget->addWidget(new DeckPreviewTagAdditionWidget(this, tr("Edit tags ...")));
layout->addWidget(flowWidget); layout->addWidget(flowWidget);
} }

View file

@ -19,15 +19,15 @@ DeckPreviewTagAdditionWidget::DeckPreviewTagAdditionWidget(DeckPreviewDeckTagsDi
layout->addWidget(tagLabel_); layout->addWidget(tagLabel_);
// Create close button // Create close button
closeButton_ = new QPushButton("x", this); // closeButton_ = new QPushButton("x", this);
closeButton_->setFixedSize(16, 16); // Small square button // closeButton_->setFixedSize(16, 16); // Small square button
layout->addWidget(closeButton_); // layout->addWidget(closeButton_);
// Adjust widget size // Adjust widget size
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
// Connect close button to the remove signal // Connect close button to the remove signal
connect(closeButton_, &QPushButton::clicked, this, &DeckPreviewTagAdditionWidget::tagClosed); // connect(closeButton_, &QPushButton::clicked, this, &DeckPreviewTagAdditionWidget::tagClosed);
} }
void DeckPreviewTagAdditionWidget::mousePressEvent(QMouseEvent *event) void DeckPreviewTagAdditionWidget::mousePressEvent(QMouseEvent *event)

View file

@ -14,25 +14,25 @@ DeckPreviewTagDisplayWidget::DeckPreviewTagDisplayWidget(QWidget *parent, const
layout->setSpacing(5); layout->setSpacing(5);
// Add a stretch spacer for text and close button separation // Add a stretch spacer for text and close button separation
layout->addStretch(); // Ensures the close button stays at the far-right side // layout->addStretch(); // Ensures the close button stays at the far-right side
// Create close button // Create close button
closeButton = new QPushButton("x", this); // closeButton = new QPushButton("x", this);
closeButton->setFixedSize(16, 16); // Small square button // closeButton->setFixedSize(16, 16); // Small square button
closeButton->setFocusPolicy(Qt::NoFocus); // closeButton->setFocusPolicy(Qt::NoFocus);
// Set font for close button to ensure the "x" appears correctly // Set font for close button to ensure the "x" appears correctly
QFont closeButtonFont = closeButton->font(); // QFont closeButtonFont = closeButton->font();
closeButtonFont.setPointSize(10); // Adjust the size to make the "x" clear // closeButtonFont.setPointSize(10); // Adjust the size to make the "x" clear
closeButton->setFont(closeButtonFont); // closeButton->setFont(closeButtonFont);
layout->addWidget(closeButton); // layout->addWidget(closeButton);
// Adjust widget size // Adjust widget size
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
// Connect close button to the remove signal // Connect close button to the remove signal
connect(closeButton, &QPushButton::clicked, this, &DeckPreviewTagDisplayWidget::tagClosed); // connect(closeButton, &QPushButton::clicked, this, &DeckPreviewTagDisplayWidget::tagClosed);
} }
QSize DeckPreviewTagDisplayWidget::sizeHint() const QSize DeckPreviewTagDisplayWidget::sizeHint() const
@ -40,7 +40,7 @@ QSize DeckPreviewTagDisplayWidget::sizeHint() const
// Calculate the size based on the tag name and close button // Calculate the size based on the tag name and close button
QFontMetrics fm(font()); QFontMetrics fm(font());
int textWidth = fm.horizontalAdvance(tagName); int textWidth = fm.horizontalAdvance(tagName);
int width = textWidth + closeButton->width() + 50; // Add extra padding int width = textWidth + 50; // Add extra padding
int height = fm.height() + 10; // Height based on font size + padding int height = fm.height() + 10; // Height based on font size + padding
return QSize(width, height); return QSize(width, height);
@ -86,9 +86,9 @@ void DeckPreviewTagDisplayWidget::paintEvent(QPaintEvent *event)
painter.setFont(font); painter.setFont(font);
// Calculate text rect to avoid overlap with the close button // Calculate text rect to avoid overlap with the close button
int closeButtonWidth = closeButton->width(); // int closeButtonWidth = closeButton->width();
int margin = 10; // Left and right margins int margin = 10; // Left and right margins
QRect textRect(margin, 0, width() - closeButtonWidth - margin * 2, height()); QRect textRect(margin, 0, width() - margin * 2, height());
// Draw the text with a black border for better legibility // Draw the text with a black border for better legibility
painter.setPen(Qt::black); painter.setPen(Qt::black);