mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
[CardInfoPictureWidget] Refactor constant fields to static const (#6575)
* [CardInfoPictureWidget] Refactor constant fields to static const * rename constants * reformat * comment out unused
This commit is contained in:
parent
165c4ddd2a
commit
5cc5767c87
2 changed files with 32 additions and 26 deletions
|
|
@ -15,6 +15,18 @@
|
|||
#include <libcockatrice/card/relation/card_relation.h>
|
||||
#include <utility>
|
||||
|
||||
static constexpr qreal MTG_CARD_ASPECT_RATIO = 1.396;
|
||||
// static constexpr qreal YUGIOH_CARD_ASPECT_RATIO = 1.457;
|
||||
static constexpr qreal ASPECT_RATIO = MTG_CARD_ASPECT_RATIO;
|
||||
|
||||
static constexpr int BASE_WIDTH = 200;
|
||||
static constexpr int BASE_HEIGHT = 200;
|
||||
|
||||
static constexpr int ENLARGED_PIXMAP_OFFSET = 10;
|
||||
|
||||
static constexpr int HOVER_ACTIVATE_THRESHOLD_MS = 500;
|
||||
static constexpr int ANIMATION_OFFSET = 10; // Adjust this for how much the widget moves up
|
||||
|
||||
/**
|
||||
* @class CardInfoPictureWidget
|
||||
* @brief Widget that displays an enlarged image of a card, loading the image based on the card's info or showing a
|
||||
|
|
@ -34,7 +46,7 @@
|
|||
CardInfoPictureWidget::CardInfoPictureWidget(QWidget *parent, const bool _hoverToZoomEnabled, const bool _raiseOnEnter)
|
||||
: QWidget(parent), pixmapDirty(true), hoverToZoomEnabled(_hoverToZoomEnabled), raiseOnEnter(_raiseOnEnter)
|
||||
{
|
||||
setMinimumHeight(baseHeight);
|
||||
setMinimumHeight(BASE_HEIGHT);
|
||||
if (hoverToZoomEnabled) {
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
|
@ -52,7 +64,7 @@ CardInfoPictureWidget::CardInfoPictureWidget(QWidget *parent, const bool _hoverT
|
|||
animation->setEasingCurve(QEasingCurve::OutQuad);
|
||||
|
||||
animation->setStartValue(originalPos);
|
||||
animation->setEndValue(originalPos - QPoint(0, animationOffset));
|
||||
animation->setEndValue(originalPos - QPoint(0, ANIMATION_OFFSET));
|
||||
|
||||
connect(&SettingsCache::instance(), &SettingsCache::roundCardCornersChanged, this, [this](bool _roundCardCorners) {
|
||||
Q_UNUSED(_roundCardCorners);
|
||||
|
|
@ -119,8 +131,8 @@ void CardInfoPictureWidget::resizeEvent(QResizeEvent *event)
|
|||
*/
|
||||
void CardInfoPictureWidget::setScaleFactor(const int scale)
|
||||
{
|
||||
const int newWidth = baseWidth * scale / 100;
|
||||
const int newHeight = static_cast<int>(newWidth * aspectRatio);
|
||||
const int newWidth = BASE_WIDTH * scale / 100;
|
||||
const int newHeight = static_cast<int>(newWidth * ASPECT_RATIO);
|
||||
|
||||
scaleFactor = scale;
|
||||
|
||||
|
|
@ -226,8 +238,8 @@ void CardInfoPictureWidget::paintEvent(QPaintEvent *event)
|
|||
*/
|
||||
QSize CardInfoPictureWidget::sizeHint() const
|
||||
{
|
||||
return {static_cast<int>(baseWidth * scaleFactor / 100.0),
|
||||
static_cast<int>(baseWidth * scaleFactor / 100.0 * aspectRatio)};
|
||||
return {static_cast<int>(BASE_WIDTH * scaleFactor / 100.0),
|
||||
static_cast<int>(BASE_WIDTH * scaleFactor / 100.0 * ASPECT_RATIO)};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -244,7 +256,7 @@ void CardInfoPictureWidget::enterEvent(QEvent *event)
|
|||
|
||||
// If hover-to-zoom is enabled, start the hover timer
|
||||
if (hoverToZoomEnabled) {
|
||||
hoverTimer->start(hoverActivateThresholdInMs);
|
||||
hoverTimer->start(HOVER_ACTIVATE_THRESHOLD_MS);
|
||||
}
|
||||
|
||||
// Emit signal indicating a card is being hovered on
|
||||
|
|
@ -256,7 +268,7 @@ void CardInfoPictureWidget::enterEvent(QEvent *event)
|
|||
} else {
|
||||
originalPos = this->pos(); // Update the baseline position
|
||||
animation->setStartValue(originalPos);
|
||||
animation->setEndValue(originalPos - QPoint(0, animationOffset));
|
||||
animation->setEndValue(originalPos - QPoint(0, ANIMATION_OFFSET));
|
||||
}
|
||||
animation->setDirection(QAbstractAnimation::Forward);
|
||||
animation->start();
|
||||
|
|
@ -311,15 +323,15 @@ void CardInfoPictureWidget::mouseMoveEvent(QMouseEvent *event)
|
|||
const QRect screenGeometry = QGuiApplication::screenAt(cursorPos)->geometry();
|
||||
const QSize widgetSize = enlargedPixmapWidget->size();
|
||||
|
||||
int newX = cursorPos.x() + enlargedPixmapOffset;
|
||||
int newY = cursorPos.y() + enlargedPixmapOffset;
|
||||
int newX = cursorPos.x() + ENLARGED_PIXMAP_OFFSET;
|
||||
int newY = cursorPos.y() + ENLARGED_PIXMAP_OFFSET;
|
||||
|
||||
// Adjust if out of bounds
|
||||
if (newX + widgetSize.width() > screenGeometry.right()) {
|
||||
newX = cursorPos.x() - widgetSize.width() - enlargedPixmapOffset;
|
||||
newX = cursorPos.x() - widgetSize.width() - ENLARGED_PIXMAP_OFFSET;
|
||||
}
|
||||
if (newY + widgetSize.height() > screenGeometry.bottom()) {
|
||||
newY = cursorPos.y() - widgetSize.height() - enlargedPixmapOffset;
|
||||
newY = cursorPos.y() - widgetSize.height() - ENLARGED_PIXMAP_OFFSET;
|
||||
}
|
||||
|
||||
enlargedPixmapWidget->move(newX, newY);
|
||||
|
|
@ -453,21 +465,21 @@ void CardInfoPictureWidget::showEnlargedPixmap()
|
|||
connect(this, &QObject::destroyed, enlargedPixmapWidget, &CardInfoPictureEnlargedWidget::deleteLater);
|
||||
}
|
||||
|
||||
const QSize enlargedSize(static_cast<int>(size().width() * 2), static_cast<int>(size().width() * aspectRatio * 2));
|
||||
const QSize enlargedSize(static_cast<int>(size().width() * 2), static_cast<int>(size().width() * ASPECT_RATIO * 2));
|
||||
enlargedPixmapWidget->setCardPixmap(exactCard, enlargedSize);
|
||||
|
||||
const QPoint cursorPos = QCursor::pos();
|
||||
const QRect screenGeometry = QGuiApplication::screenAt(cursorPos)->geometry();
|
||||
const QSize widgetSize = enlargedPixmapWidget->size();
|
||||
|
||||
int newX = cursorPos.x() + enlargedPixmapOffset;
|
||||
int newY = cursorPos.y() + enlargedPixmapOffset;
|
||||
int newX = cursorPos.x() + ENLARGED_PIXMAP_OFFSET;
|
||||
int newY = cursorPos.y() + ENLARGED_PIXMAP_OFFSET;
|
||||
|
||||
if (newX + widgetSize.width() > screenGeometry.right()) {
|
||||
newX = cursorPos.x() - widgetSize.width() - enlargedPixmapOffset;
|
||||
newX = cursorPos.x() - widgetSize.width() - ENLARGED_PIXMAP_OFFSET;
|
||||
}
|
||||
if (newY + widgetSize.height() > screenGeometry.bottom()) {
|
||||
newY = cursorPos.y() - widgetSize.height() - enlargedPixmapOffset;
|
||||
newY = cursorPos.y() - widgetSize.height() - ENLARGED_PIXMAP_OFFSET;
|
||||
}
|
||||
|
||||
enlargedPixmapWidget->move(newX, newY);
|
||||
|
|
|
|||
|
|
@ -68,23 +68,17 @@ protected:
|
|||
|
||||
private:
|
||||
ExactCard exactCard;
|
||||
qreal magicTheGatheringCardAspectRatio = 1.396;
|
||||
qreal yuGiOhCardAspectRatio = 1.457;
|
||||
qreal aspectRatio = magicTheGatheringCardAspectRatio;
|
||||
int baseWidth = 200;
|
||||
int baseHeight = 200;
|
||||
double scaleFactor = 100;
|
||||
QPixmap resizedPixmap;
|
||||
bool pixmapDirty;
|
||||
bool hoverToZoomEnabled;
|
||||
bool raiseOnEnter;
|
||||
int hoverActivateThresholdInMs = 500;
|
||||
|
||||
CardInfoPictureEnlargedWidget *enlargedPixmapWidget = nullptr;
|
||||
int enlargedPixmapOffset = 10;
|
||||
|
||||
QTimer *hoverTimer;
|
||||
QPropertyAnimation *animation;
|
||||
QPoint originalPos; // Store the original position
|
||||
const int animationOffset = 10; // Adjust this for how much the widget moves up
|
||||
QPoint originalPos; // Store the original position
|
||||
|
||||
QMenu *createRightClickMenu();
|
||||
QMenu *createViewRelatedCardsMenu();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue