UI: highlight pinned printings in Printing Selector

Fixes #5930.

Signed-off-by: Gauwal <gauwain2611@hotmail.com>
This commit is contained in:
Gauwal 2025-10-23 22:19:32 +02:00
parent 817a3f979e
commit 9fc24c811a
4 changed files with 98 additions and 0 deletions

View file

@ -25,6 +25,7 @@
<file>resources/icons/lock.svg</file> <file>resources/icons/lock.svg</file>
<file>resources/icons/not_ready_start.svg</file> <file>resources/icons/not_ready_start.svg</file>
<file>resources/icons/pencil.svg</file> <file>resources/icons/pencil.svg</file>
<file>resources/icons/pin.svg</file>
<file>resources/icons/player.svg</file> <file>resources/icons/player.svg</file>
<file>resources/icons/ready_start.svg</file> <file>resources/icons/ready_start.svg</file>
<file>resources/icons/reload.svg</file> <file>resources/icons/reload.svg</file>

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="64" height="64">
<g transform="matrix(0 1 -1 0 99.465813 0)" opacity="0.7">
<path fill="#000000" fill-rule="evenodd" clip-rule="evenodd"
stroke="#ffffff"
stroke-width="4"
stroke-linejoin="round"
stroke-linecap="round"
d="M65.5 62
L78 49
C73.5 44.5 69.5 42 63 44
L45 31 C47 25 46 22 41.5 18
L19 41.5
C23 45.5 25 46.5 31 45
L44 62.5
C42.3 69 45 73.5 49 78
L61.5 65.5
L84 87
L87 87
L87.5 86.5
L87.5 83.5 Z" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 736 B

View file

@ -2,8 +2,13 @@
#include "printing_selector_card_display_widget.h" #include "printing_selector_card_display_widget.h"
#include <QGraphicsEffect>
#include <QIcon>
#include <QLabel>
#include <QMenu> #include <QMenu>
#include <QMessageBox>
#include <QMouseEvent> #include <QMouseEvent>
#include <QStackedWidget>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <libcockatrice/card/database/card_database_manager.h> #include <libcockatrice/card/database/card_database_manager.h>
#include <libcockatrice/card/relation/card_relation.h> #include <libcockatrice/card/relation/card_relation.h>
@ -46,6 +51,39 @@ PrintingSelectorCardOverlayWidget::PrintingSelectorCardOverlayWidget(QWidget *pa
cardInfoPicture->setCard(_rootCard); cardInfoPicture->setCard(_rootCard);
mainLayout->addWidget(cardInfoPicture); mainLayout->addWidget(cardInfoPicture);
// Pin badge shown when this printing is pinned (hidden by default)
pinBadge = new QLabel(this);
pinBadge->setObjectName(QStringLiteral("printingSelectorPinBadge"));
// try resource first, fallback to show visible text
QPixmap pinPix = QPixmap("theme:icons/pin");
if (!pinPix.isNull()) {
const double scaleFactor = 1;
const QSize targetSize(int(pinPix.width() * scaleFactor), int(pinPix.height() * scaleFactor));
pinPix = pinPix.scaled(targetSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
pinBadge->setPixmap(pinPix);
pinBadge->setFixedSize(pinPix.size());
pinBadge->setStyleSheet("background: transparent;");
} else {
// visible fallback so you can see the badge even without the SVG
pinBadge->setText(QStringLiteral("PIN"));
pinBadge->setAlignment(Qt::AlignCenter);
pinBadge->setFixedSize(24, 12);
pinBadge->setStyleSheet("background: yellow; color: black; border: 1px solid red;");
}
pinBadge->setAttribute(Qt::WA_TransparentForMouseEvents);
pinBadge->setVisible(false);
pinBadge->raise();
// Update when this overlay emits cardPreferenceChanged or when size/scale changes
connect(this, &PrintingSelectorCardOverlayWidget::cardPreferenceChanged, this,
&PrintingSelectorCardOverlayWidget::updatePinBadgeVisibility);
connect(cardSizeSlider, &QSlider::valueChanged, this, &PrintingSelectorCardOverlayWidget::updatePinBadgeVisibility);
// initial state
updatePinBadgeVisibility();
// Add AllZonesCardAmountWidget // Add AllZonesCardAmountWidget
allZonesCardAmountWidget = allZonesCardAmountWidget =
new AllZonesCardAmountWidget(this, deckEditor, deckModel, deckView, cardSizeSlider, _rootCard); new AllZonesCardAmountWidget(this, deckEditor, deckModel, deckView, cardSizeSlider, _rootCard);
@ -128,6 +166,37 @@ void PrintingSelectorCardOverlayWidget::enterEvent(QEvent *event)
// Show the widget if amounts are 0 // Show the widget if amounts are 0
allZonesCardAmountWidget->setVisible(true); allZonesCardAmountWidget->setVisible(true);
} }
/**
* @brief Updates the pin badge visibility and position based on the card's pinned state.
*
* This method checks whether the current card printing is pinned and updates the
* pin badge accordingly. If the card is pinned, the badge is made visible and positioned in the
* top-right corner of the card image with appropriate margins. If the card is not pinned, the
* badge is hidden.
*
* The method is called whenever the card preference changes or the card size is adjusted via
* the slider to ensure the badge remains properly positioned.
*/
void PrintingSelectorCardOverlayWidget::updatePinBadgeVisibility()
{
if (!pinBadge || !cardInfoPicture)
return;
const auto &preferredProviderId =
SettingsCache::instance().cardOverrides().getCardPreferenceOverride(rootCard.getName());
const auto &cardProviderId = rootCard.getPrinting().getUuid();
const bool isPinned = (!preferredProviderId.isEmpty() && preferredProviderId == cardProviderId);
pinBadge->setVisible(isPinned);
if (isPinned) {
const int margin = qMax(3, int(cardInfoPicture->width() * 0.03));
int x = qMax(0, cardInfoPicture->width() - pinBadge->width() - margin);
int y = margin * 3;
pinBadge->move(x, y);
pinBadge->raise();
}
}
/** /**
* @brief Handles the mouse leave event when the cursor leaves the overlay widget area. * @brief Handles the mouse leave event when the cursor leaves the overlay widget area.

View file

@ -42,9 +42,13 @@ protected:
signals: signals:
void cardPreferenceChanged(); void cardPreferenceChanged();
private slots:
void updatePinBadgeVisibility();
private: private:
CardInfoPictureWidget *cardInfoPicture; CardInfoPictureWidget *cardInfoPicture;
AllZonesCardAmountWidget *allZonesCardAmountWidget; AllZonesCardAmountWidget *allZonesCardAmountWidget;
QLabel *pinBadge = nullptr;
AbstractTabDeckEditor *deckEditor; AbstractTabDeckEditor *deckEditor;
DeckListModel *deckModel; DeckListModel *deckModel;
QTreeView *deckView; QTreeView *deckView;