mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 22:42:14 -07:00
Fix: adjust pin highlighting behavior + making it sharp/not blurry
This commit is contained in:
parent
9fc24c811a
commit
c627110a2d
1 changed files with 25 additions and 10 deletions
|
|
@ -3,17 +3,21 @@
|
||||||
#include "printing_selector_card_display_widget.h"
|
#include "printing_selector_card_display_widget.h"
|
||||||
|
|
||||||
#include <QGraphicsEffect>
|
#include <QGraphicsEffect>
|
||||||
|
#include <QImageReader>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QSvgRenderer>
|
||||||
#include <QStackedWidget>
|
#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>
|
||||||
#include <libcockatrice/settings/cache_settings.h>
|
#include <libcockatrice/settings/cache_settings.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructs a PrintingSelectorCardOverlayWidget for displaying a card overlay.
|
* @brief Constructs a PrintingSelectorCardOverlayWidget for displaying a card overlay.
|
||||||
|
|
@ -55,17 +59,28 @@ PrintingSelectorCardOverlayWidget::PrintingSelectorCardOverlayWidget(QWidget *pa
|
||||||
pinBadge = new QLabel(this);
|
pinBadge = new QLabel(this);
|
||||||
pinBadge->setObjectName(QStringLiteral("printingSelectorPinBadge"));
|
pinBadge->setObjectName(QStringLiteral("printingSelectorPinBadge"));
|
||||||
|
|
||||||
// try resource first, fallback to show visible text
|
bool pinLoaded = false;
|
||||||
QPixmap pinPix = QPixmap("theme:icons/pin");
|
QImageReader pinReader(QStringLiteral("theme:icons/pin"));
|
||||||
|
|
||||||
if (!pinPix.isNull()) {
|
if (pinReader.canRead()) {
|
||||||
const double scaleFactor = 1;
|
const QSize targetSize(64, 64);
|
||||||
const QSize targetSize(int(pinPix.width() * scaleFactor), int(pinPix.height() * scaleFactor));
|
const qreal dpr = pinBadge->devicePixelRatioF();
|
||||||
pinPix = pinPix.scaled(targetSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
const QSize rasterSize(
|
||||||
pinBadge->setPixmap(pinPix);
|
qMax(1, static_cast<int>(std::ceil(targetSize.width() * dpr))),
|
||||||
pinBadge->setFixedSize(pinPix.size());
|
qMax(1, static_cast<int>(std::ceil(targetSize.height() * dpr))));
|
||||||
pinBadge->setStyleSheet("background: transparent;");
|
pinReader.setScaledSize(rasterSize);
|
||||||
} else {
|
const QImage pinImage = pinReader.read();
|
||||||
|
if (!pinImage.isNull()) {
|
||||||
|
QPixmap pinPix = QPixmap::fromImage(pinImage);
|
||||||
|
pinPix.setDevicePixelRatio(dpr);
|
||||||
|
pinBadge->setPixmap(pinPix);
|
||||||
|
pinBadge->setFixedSize(targetSize);
|
||||||
|
pinBadge->setStyleSheet(QStringLiteral("background: transparent;"));
|
||||||
|
pinLoaded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pinLoaded) {
|
||||||
// visible fallback so you can see the badge even without the SVG
|
// visible fallback so you can see the badge even without the SVG
|
||||||
pinBadge->setText(QStringLiteral("PIN"));
|
pinBadge->setText(QStringLiteral("PIN"));
|
||||||
pinBadge->setAlignment(Qt::AlignCenter);
|
pinBadge->setAlignment(Qt::AlignCenter);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue