Cockatrice 2025-11-30-Development-2.11.0-beta.38
A cross-platform virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
CardInfoPictureWidget Class Reference

Widget that displays an enlarged image of a card, loading the image based on the card's info or showing a default image. More...

#include <card_info_picture_widget.h>

Inheritance diagram for CardInfoPictureWidget:
[legend]
Collaboration diagram for CardInfoPictureWidget:
[legend]

Public Slots

void setCard (const ExactCard &card)
 Sets the card to be displayed and updates the pixmap.
void setScaleFactor (int scale)
 Sets the scale factor for the widget.
void setHoverToZoomEnabled (bool enabled)
 Sets the hover to zoom feature.
void setRaiseOnEnterEnabled (bool enabled)
void updatePixmap ()
 Marks the pixmap as dirty and triggers a widget repaint.

Signals

void hoveredOnCard (const ExactCard &hoveredCard)
void cardScaleFactorChanged (int _scale)
void cardChanged (const ExactCard &card)
void cardClicked ()

Public Member Functions

 CardInfoPictureWidget (QWidget *parent=nullptr, bool hoverToZoomEnabled=false, bool raiseOnEnter=false)
 Constructs a CardInfoPictureWidget.
ExactCard getCard ()
QSize sizeHint () const override
 Provides the recommended size for the widget based on the scale factor.

Protected Member Functions

void resizeEvent (QResizeEvent *event) override
 Handles widget resizing by updating the pixmap size.
void paintEvent (QPaintEvent *) override
 Custom paint event that draws the card image with rounded corners.
void enterEvent (QEnterEvent *event) override
 Starts the hover timer to show the enlarged pixmap on hover.
void leaveEvent (QEvent *event) override
 Stops the hover timer and hides the enlarged pixmap when the mouse leaves.
void moveEvent (QMoveEvent *event) override
void mouseMoveEvent (QMouseEvent *event) override
 Moves the enlarged pixmap widget to follow the mouse cursor.
void mousePressEvent (QMouseEvent *event) override
void hideEvent (QHideEvent *event) override
void loadPixmap ()
 Loads the appropriate pixmap based on the current card info.
const QPixmap & getResizedPixmap () const
void showEnlargedPixmap () const
 Displays the enlarged version of the card's pixmap near the cursor.

Private Member Functions

QMenu * createRightClickMenu ()
QMenu * createViewRelatedCardsMenu ()
QMenu * createAddToOpenDeckMenu ()

Private Attributes

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
CardInfoPictureEnlargedWidgetenlargedPixmapWidget = nullptr
int enlargedPixmapOffset = 10
QTimer * hoverTimer
QPropertyAnimation * animation
QPoint originalPos
const int animationOffset = 10

Detailed Description

Widget that displays an enlarged image of a card, loading the image based on the card's info or showing a default image.

This widget can optionally display a larger version of the card's image when hovered over, depending on the hoverToZoomEnabled parameter.

Constructor & Destructor Documentation

◆ CardInfoPictureWidget()

CardInfoPictureWidget::CardInfoPictureWidget ( QWidget * parent = nullptr,
bool hoverToZoomEnabled = false,
bool raiseOnEnter = false )
explicit

Constructs a CardInfoPictureWidget.

Parameters
parentThe parent widget, if any.
hoverToZoomEnabledIf this widget will spawn a larger widget when hovered over.

Initializes the widget with a minimum height and sets the pixmap to a dirty state for initial loading.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ cardChanged

void CardInfoPictureWidget::cardChanged ( const ExactCard & card)
signal
Here is the caller graph for this function:

◆ cardClicked

void CardInfoPictureWidget::cardClicked ( )
signal
Here is the caller graph for this function:

◆ cardScaleFactorChanged

void CardInfoPictureWidget::cardScaleFactorChanged ( int _scale)
signal
Here is the caller graph for this function:

◆ createAddToOpenDeckMenu()

QMenu * CardInfoPictureWidget::createAddToOpenDeckMenu ( )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ createRightClickMenu()

QMenu * CardInfoPictureWidget::createRightClickMenu ( )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ createViewRelatedCardsMenu()

QMenu * CardInfoPictureWidget::createViewRelatedCardsMenu ( )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ enterEvent()

void CardInfoPictureWidget::enterEvent ( QEnterEvent * event)
overrideprotected

Starts the hover timer to show the enlarged pixmap on hover.

Parameters
eventThe enter event.
Here is the call graph for this function:

◆ getCard()

ExactCard CardInfoPictureWidget::getCard ( )
inline
Here is the caller graph for this function:

◆ getResizedPixmap()

const QPixmap & CardInfoPictureWidget::getResizedPixmap ( ) const
inlinenodiscardprotected
Here is the caller graph for this function:

◆ hideEvent()

void CardInfoPictureWidget::hideEvent ( QHideEvent * event)
overrideprotected

◆ hoveredOnCard

void CardInfoPictureWidget::hoveredOnCard ( const ExactCard & hoveredCard)
signal
Here is the caller graph for this function:

◆ leaveEvent()

void CardInfoPictureWidget::leaveEvent ( QEvent * event)
overrideprotected

Stops the hover timer and hides the enlarged pixmap when the mouse leaves.

Parameters
eventThe leave event.

◆ loadPixmap()

void CardInfoPictureWidget::loadPixmap ( )
protected

Loads the appropriate pixmap based on the current card info.

If info is valid, loads the card's image. Otherwise, loads a default card back image.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mouseMoveEvent()

void CardInfoPictureWidget::mouseMoveEvent ( QMouseEvent * event)
overrideprotected

Moves the enlarged pixmap widget to follow the mouse cursor.

Parameters
eventThe mouse move event.

◆ mousePressEvent()

void CardInfoPictureWidget::mousePressEvent ( QMouseEvent * event)
overrideprotected
Here is the call graph for this function:

◆ moveEvent()

void CardInfoPictureWidget::moveEvent ( QMoveEvent * event)
overrideprotected

◆ paintEvent()

void CardInfoPictureWidget::paintEvent ( QPaintEvent * event)
overrideprotected

Custom paint event that draws the card image with rounded corners.

Parameters
eventThe paint event (unused).

Checks if the pixmap needs to be reloaded. Then, calculates the size and position for centering the scaled pixmap within the widget, applies rounded corners, and draws the pixmap.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resizeEvent()

void CardInfoPictureWidget::resizeEvent ( QResizeEvent * event)
overrideprotected

Handles widget resizing by updating the pixmap size.

Parameters
eventThe resize event (unused).

Calls updatePixmap() to ensure the image scales appropriately when the widget is resized.

Here is the call graph for this function:

◆ setCard

void CardInfoPictureWidget::setCard ( const ExactCard & card)
slot

Sets the card to be displayed and updates the pixmap.

Parameters
cardA shared pointer to the card information (CardInfoPtr).

Disconnects any existing signal connections from the previous card info and connects to the pixmapUpdated signal of the new card to automatically update the pixmap when the card image changes.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setHoverToZoomEnabled

void CardInfoPictureWidget::setHoverToZoomEnabled ( bool enabled)
slot

Sets the hover to zoom feature.

Parameters
enabledIf true, enables the hover-to-zoom functionality; otherwise, disables it.

◆ setRaiseOnEnterEnabled

void CardInfoPictureWidget::setRaiseOnEnterEnabled ( bool enabled)
slot
Here is the caller graph for this function:

◆ setScaleFactor

void CardInfoPictureWidget::setScaleFactor ( int scale)
slot

Sets the scale factor for the widget.

Parameters
scaleThe scale factor to apply.

Adjusts the widget's size according to the scale factor and updates the pixmap.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ showEnlargedPixmap()

void CardInfoPictureWidget::showEnlargedPixmap ( ) const
protected

Displays the enlarged version of the card's pixmap near the cursor.

If card information is available, the enlarged pixmap is loaded, positioned near the cursor, and displayed.

Here is the caller graph for this function:

◆ sizeHint()

QSize CardInfoPictureWidget::sizeHint ( ) const
nodiscardoverride

Provides the recommended size for the widget based on the scale factor.

Returns
The recommended widget size.
Here is the caller graph for this function:

◆ updatePixmap

void CardInfoPictureWidget::updatePixmap ( )
slot

Marks the pixmap as dirty and triggers a widget repaint.

Sets pixmapDirty to true, indicating that the pixmap needs to be reloaded before the next display.

Here is the caller graph for this function:

Member Data Documentation

◆ animation

QPropertyAnimation* CardInfoPictureWidget::animation
private

◆ animationOffset

const int CardInfoPictureWidget::animationOffset = 10
private

◆ aspectRatio

qreal CardInfoPictureWidget::aspectRatio = magicTheGatheringCardAspectRatio
private

◆ baseHeight

int CardInfoPictureWidget::baseHeight = 200
private

◆ baseWidth

int CardInfoPictureWidget::baseWidth = 200
private

◆ enlargedPixmapOffset

int CardInfoPictureWidget::enlargedPixmapOffset = 10
private

◆ enlargedPixmapWidget

CardInfoPictureEnlargedWidget* CardInfoPictureWidget::enlargedPixmapWidget = nullptr
private

◆ exactCard

ExactCard CardInfoPictureWidget::exactCard
private

◆ hoverActivateThresholdInMs

int CardInfoPictureWidget::hoverActivateThresholdInMs = 500
private

◆ hoverTimer

QTimer* CardInfoPictureWidget::hoverTimer
private

◆ hoverToZoomEnabled

bool CardInfoPictureWidget::hoverToZoomEnabled
private

◆ magicTheGatheringCardAspectRatio

qreal CardInfoPictureWidget::magicTheGatheringCardAspectRatio = 1.396
private

◆ originalPos

QPoint CardInfoPictureWidget::originalPos
private

◆ pixmapDirty

bool CardInfoPictureWidget::pixmapDirty
private

◆ raiseOnEnter

bool CardInfoPictureWidget::raiseOnEnter
private

◆ resizedPixmap

QPixmap CardInfoPictureWidget::resizedPixmap
private

◆ scaleFactor

double CardInfoPictureWidget::scaleFactor = 100
private

◆ yuGiOhCardAspectRatio

qreal CardInfoPictureWidget::yuGiOhCardAspectRatio = 1.457
private

The documentation for this class was generated from the following files: