From 9fc24c811a29d2ee056264ee6727d74758c31a4b Mon Sep 17 00:00:00 2001 From: Gauwal Date: Thu, 23 Oct 2025 22:19:32 +0200 Subject: [PATCH] UI: highlight pinned printings in Printing Selector Fixes #5930. Signed-off-by: Gauwal --- cockatrice/cockatrice.qrc | 1 + cockatrice/resources/icons/pin.svg | 24 +++++++ .../printing_selector_card_overlay_widget.cpp | 69 +++++++++++++++++++ .../printing_selector_card_overlay_widget.h | 4 ++ 4 files changed, 98 insertions(+) create mode 100644 cockatrice/resources/icons/pin.svg diff --git a/cockatrice/cockatrice.qrc b/cockatrice/cockatrice.qrc index 88d1e62dc..469cf3d77 100644 --- a/cockatrice/cockatrice.qrc +++ b/cockatrice/cockatrice.qrc @@ -25,6 +25,7 @@ resources/icons/lock.svg resources/icons/not_ready_start.svg resources/icons/pencil.svg + resources/icons/pin.svg resources/icons/player.svg resources/icons/ready_start.svg resources/icons/reload.svg diff --git a/cockatrice/resources/icons/pin.svg b/cockatrice/resources/icons/pin.svg new file mode 100644 index 000000000..71d4c9c9c --- /dev/null +++ b/cockatrice/resources/icons/pin.svg @@ -0,0 +1,24 @@ + + + + + + + diff --git a/cockatrice/src/interface/widgets/printing_selector/printing_selector_card_overlay_widget.cpp b/cockatrice/src/interface/widgets/printing_selector/printing_selector_card_overlay_widget.cpp index 56e5d1aab..d17a677ef 100644 --- a/cockatrice/src/interface/widgets/printing_selector/printing_selector_card_overlay_widget.cpp +++ b/cockatrice/src/interface/widgets/printing_selector/printing_selector_card_overlay_widget.cpp @@ -2,8 +2,13 @@ #include "printing_selector_card_display_widget.h" +#include +#include +#include #include +#include #include +#include #include #include #include @@ -46,6 +51,39 @@ PrintingSelectorCardOverlayWidget::PrintingSelectorCardOverlayWidget(QWidget *pa cardInfoPicture->setCard(_rootCard); 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 allZonesCardAmountWidget = new AllZonesCardAmountWidget(this, deckEditor, deckModel, deckView, cardSizeSlider, _rootCard); @@ -128,6 +166,37 @@ void PrintingSelectorCardOverlayWidget::enterEvent(QEvent *event) // Show the widget if amounts are 0 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. diff --git a/cockatrice/src/interface/widgets/printing_selector/printing_selector_card_overlay_widget.h b/cockatrice/src/interface/widgets/printing_selector/printing_selector_card_overlay_widget.h index 8bc865920..2606d068b 100644 --- a/cockatrice/src/interface/widgets/printing_selector/printing_selector_card_overlay_widget.h +++ b/cockatrice/src/interface/widgets/printing_selector/printing_selector_card_overlay_widget.h @@ -42,9 +42,13 @@ protected: signals: void cardPreferenceChanged(); +private slots: + void updatePinBadgeVisibility(); + private: CardInfoPictureWidget *cardInfoPicture; AllZonesCardAmountWidget *allZonesCardAmountWidget; + QLabel *pinBadge = nullptr; AbstractTabDeckEditor *deckEditor; DeckListModel *deckModel; QTreeView *deckView;