Cockatrice 2026-01-14-Development-2.11.0-beta.46
A cross-platform virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
card_info_picture_widget.h
Go to the documentation of this file.
1
6
7#ifndef CARD_INFO_PICTURE_H
8#define CARD_INFO_PICTURE_H
9
11
12#include <QPropertyAnimation>
13#include <QWidget>
15
16inline Q_LOGGING_CATEGORY(CardInfoPictureWidgetLog, "card_info_picture_widget");
17
19class QMenu;
20
21class CardInfoPictureWidget : public QWidget
22{
23 Q_OBJECT
24
25public:
26 explicit CardInfoPictureWidget(QWidget *parent = nullptr,
27 bool hoverToZoomEnabled = false,
28 bool raiseOnEnter = false);
30 {
31 return exactCard;
32 }
33 [[nodiscard]] QSize sizeHint() const override;
34
35public slots:
36 void setCard(const ExactCard &card);
37 void setScaleFactor(int scale); // New slot for scaling
38 void setHoverToZoomEnabled(bool enabled);
39 void setRaiseOnEnterEnabled(bool enabled);
40 void updatePixmap();
41
42signals:
43 void hoveredOnCard(const ExactCard &hoveredCard);
44 void cardScaleFactorChanged(int _scale);
45 void cardChanged(const ExactCard &card);
47
48protected:
49 void resizeEvent(QResizeEvent *event) override;
50 void paintEvent(QPaintEvent *) override;
51#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
52 void enterEvent(QEnterEvent *event) override; // Qt6 signature
53#else
54 void enterEvent(QEvent *event) override; // Qt5 signature
55#endif
56 void leaveEvent(QEvent *event) override;
57 void moveEvent(QMoveEvent *event) override;
58 void mouseMoveEvent(QMouseEvent *event) override;
59 void mousePressEvent(QMouseEvent *event) override;
60 void hideEvent(QHideEvent *event) override;
61 void loadPixmap();
62 [[nodiscard]] const QPixmap &getResizedPixmap() const
63 {
64 return resizedPixmap;
65 }
66 void showEnlargedPixmap();
68
69private:
72 qreal yuGiOhCardAspectRatio = 1.457;
74 int baseWidth = 200;
75 int baseHeight = 200;
76 double scaleFactor = 100;
84 QTimer *hoverTimer;
85 QPropertyAnimation *animation;
86 QPoint originalPos; // Store the original position
87 const int animationOffset = 10; // Adjust this for how much the widget moves up
88
89 QMenu *createRightClickMenu();
92};
93
94#endif
Q_LOGGING_CATEGORY(CardInfoPictureWidgetLog, "card_info_picture_widget")
Definition abstract_card_item.h:22
Definition card_info_picture_enlarged_widget.h:15
void setScaleFactor(int scale)
Sets the scale factor for the widget.
Definition card_info_picture_widget.cpp:120
CardInfoPictureWidget(QWidget *parent=nullptr, bool hoverToZoomEnabled=false, bool raiseOnEnter=false)
Constructs a CardInfoPictureWidget.
Definition card_info_picture_widget.cpp:34
void setCard(const ExactCard &card)
Sets the card to be displayed and updates the pixmap.
Definition card_info_picture_widget.cpp:71
bool hoverToZoomEnabled
Definition card_info_picture_widget.h:79
int hoverActivateThresholdInMs
Definition card_info_picture_widget.h:81
QPropertyAnimation * animation
Definition card_info_picture_widget.h:85
void leaveEvent(QEvent *event) override
Stops the hover timer and hides the enlarged pixmap when the mouse leaves.
Definition card_info_picture_widget.cpp:270
void cardChanged(const ExactCard &card)
const QPixmap & getResizedPixmap() const
Definition card_info_picture_widget.h:62
void showEnlargedPixmap()
Displays the enlarged version of the card's pixmap near the cursor.
Definition card_info_picture_widget.cpp:443
int enlargedPixmapOffset
Definition card_info_picture_widget.h:83
void hideEvent(QHideEvent *event) override
Definition card_info_picture_widget.cpp:341
void moveEvent(QMoveEvent *event) override
Definition card_info_picture_widget.cpp:288
QPixmap resizedPixmap
Definition card_info_picture_widget.h:77
ExactCard exactCard
Definition card_info_picture_widget.h:70
qreal aspectRatio
Definition card_info_picture_widget.h:73
void mousePressEvent(QMouseEvent *event) override
Definition card_info_picture_widget.cpp:329
void resizeEvent(QResizeEvent *event) override
Handles widget resizing by updating the pixmap size.
Definition card_info_picture_widget.cpp:107
CardInfoPictureEnlargedWidget * enlargedPixmapWidget
Definition card_info_picture_widget.h:82
void enterEvent(QEnterEvent *event) override
Starts the hover timer to show the enlarged pixmap on hover.
Definition card_info_picture_widget.cpp:238
void hoveredOnCard(const ExactCard &hoveredCard)
bool raiseOnEnter
Definition card_info_picture_widget.h:80
bool pixmapDirty
Definition card_info_picture_widget.h:78
void mouseMoveEvent(QMouseEvent *event) override
Moves the enlarged pixmap widget to follow the mouse cursor.
Definition card_info_picture_widget.cpp:305
void updatePixmap()
Marks the pixmap as dirty and triggers a widget repaint.
Definition card_info_picture_widget.cpp:138
QMenu * createAddToOpenDeckMenu()
Definition card_info_picture_widget.cpp:406
qreal yuGiOhCardAspectRatio
Definition card_info_picture_widget.h:72
void setHoverToZoomEnabled(bool enabled)
Sets the hover to zoom feature.
Definition card_info_picture_widget.cpp:90
QMenu * createRightClickMenu()
Definition card_info_picture_widget.cpp:347
void setRaiseOnEnterEnabled(bool enabled)
Definition card_info_picture_widget.cpp:96
QPoint originalPos
Definition card_info_picture_widget.h:86
QTimer * hoverTimer
Definition card_info_picture_widget.h:84
void loadPixmap()
Loads the appropriate pixmap based on the current card info.
Definition card_info_picture_widget.cpp:149
qreal magicTheGatheringCardAspectRatio
Definition card_info_picture_widget.h:71
QSize sizeHint() const override
Provides the recommended size for the widget based on the scale factor.
Definition card_info_picture_widget.cpp:227
void paintEvent(QPaintEvent *) override
Custom paint event that draws the card image with rounded corners.
Definition card_info_picture_widget.cpp:168
void destroyEnlargedPixmapWidget()
Definition card_info_picture_widget.cpp:478
const int animationOffset
Definition card_info_picture_widget.h:87
int baseWidth
Definition card_info_picture_widget.h:74
ExactCard getCard()
Definition card_info_picture_widget.h:29
int baseHeight
Definition card_info_picture_widget.h:75
void cardScaleFactorChanged(int _scale)
QMenu * createViewRelatedCardsMenu()
Definition card_info_picture_widget.cpp:361
double scaleFactor
Definition card_info_picture_widget.h:76
Represents a specific card instance, defined by its CardInfo and a particular printing.
Definition exact_card.h:19