mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-03-21 17:55:21 -05:00
Implement a little "raise on enter" animation for deck preview widgets. (#5844)
* Implement a little "raise on enter" animation for deck preview widgets. * Why does the linter need to be run twice? * Fix build. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
2dc1b875d2
commit
8af1f2b6d9
|
|
@ -30,8 +30,9 @@
|
|||
*
|
||||
* Initializes the widget with a minimum height and sets the pixmap to a dirty state for initial loading.
|
||||
*/
|
||||
CardInfoPictureWidget::CardInfoPictureWidget(QWidget *parent, const bool hoverToZoomEnabled)
|
||||
: QWidget(parent), info(nullptr), pixmapDirty(true), hoverToZoomEnabled(hoverToZoomEnabled)
|
||||
CardInfoPictureWidget::CardInfoPictureWidget(QWidget *parent, const bool _hoverToZoomEnabled, const bool _raiseOnEnter)
|
||||
: QWidget(parent), info(nullptr), pixmapDirty(true), hoverToZoomEnabled(_hoverToZoomEnabled),
|
||||
raiseOnEnter(_raiseOnEnter)
|
||||
{
|
||||
setMinimumHeight(baseHeight);
|
||||
if (hoverToZoomEnabled) {
|
||||
|
|
@ -45,6 +46,17 @@ CardInfoPictureWidget::CardInfoPictureWidget(QWidget *parent, const bool hoverTo
|
|||
hoverTimer->setSingleShot(true);
|
||||
connect(hoverTimer, &QTimer::timeout, this, &CardInfoPictureWidget::showEnlargedPixmap);
|
||||
|
||||
// Store the widget's original position
|
||||
originalPos = this->pos();
|
||||
|
||||
// Create the animation
|
||||
animation = new QPropertyAnimation(this, "pos");
|
||||
animation->setDuration(200); // 200ms animation duration
|
||||
animation->setEasingCurve(QEasingCurve::OutQuad);
|
||||
|
||||
animation->setStartValue(originalPos);
|
||||
animation->setEndValue(originalPos - QPoint(0, animationOffset));
|
||||
|
||||
connect(&SettingsCache::instance(), &SettingsCache::roundCardCornersChanged, this, [this](bool _roundCardCorners) {
|
||||
Q_UNUSED(_roundCardCorners);
|
||||
|
||||
|
|
@ -84,6 +96,11 @@ void CardInfoPictureWidget::setHoverToZoomEnabled(const bool enabled)
|
|||
setMouseTracking(enabled);
|
||||
}
|
||||
|
||||
void CardInfoPictureWidget::setRaiseOnEnterEnabled(const bool enabled)
|
||||
{
|
||||
raiseOnEnter = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handles widget resizing by updating the pixmap size.
|
||||
* @param event The resize event (unused).
|
||||
|
|
@ -93,6 +110,7 @@ void CardInfoPictureWidget::setHoverToZoomEnabled(const bool enabled)
|
|||
void CardInfoPictureWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QWidget::resizeEvent(event);
|
||||
originalPos = pos(); // Update the baseline position
|
||||
updatePixmap();
|
||||
}
|
||||
|
||||
|
|
@ -234,6 +252,18 @@ void CardInfoPictureWidget::enterEvent(QEvent *event)
|
|||
|
||||
// Emit signal indicating a card is being hovered on
|
||||
emit hoveredOnCard(info);
|
||||
|
||||
if (raiseOnEnter) {
|
||||
if (animation->state() == QAbstractAnimation::Running) {
|
||||
animation->pause(); // Pause current animation
|
||||
} else {
|
||||
originalPos = this->pos(); // Update the baseline position
|
||||
animation->setStartValue(originalPos);
|
||||
animation->setEndValue(originalPos - QPoint(0, animationOffset));
|
||||
}
|
||||
animation->setDirection(QAbstractAnimation::Forward);
|
||||
animation->start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -243,10 +273,32 @@ void CardInfoPictureWidget::enterEvent(QEvent *event)
|
|||
void CardInfoPictureWidget::leaveEvent(QEvent *event)
|
||||
{
|
||||
QWidget::leaveEvent(event);
|
||||
|
||||
if (hoverToZoomEnabled) {
|
||||
hoverTimer->stop();
|
||||
enlargedPixmapWidget->hide();
|
||||
}
|
||||
|
||||
if (raiseOnEnter) {
|
||||
if (animation->state() == QAbstractAnimation::Running) {
|
||||
animation->pause(); // Pause current animation
|
||||
}
|
||||
animation->setDirection(QAbstractAnimation::Backward);
|
||||
animation->start();
|
||||
}
|
||||
}
|
||||
|
||||
void CardInfoPictureWidget::moveEvent(QMoveEvent *event)
|
||||
{
|
||||
QWidget::moveEvent(event);
|
||||
|
||||
hoverTimer->stop();
|
||||
enlargedPixmapWidget->hide();
|
||||
|
||||
if (animation->state() == QAbstractAnimation::Running) {
|
||||
return;
|
||||
}
|
||||
originalPos = this->pos(); // Update the baseline position
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "../../../../game/cards/card_info.h"
|
||||
#include "card_info_picture_enlarged_widget.h"
|
||||
|
||||
#include <QPropertyAnimation>
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
|
||||
|
|
@ -17,17 +18,20 @@ class CardInfoPictureWidget : public QWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CardInfoPictureWidget(QWidget *parent = nullptr, bool hoverToZoomEnabled = false);
|
||||
explicit CardInfoPictureWidget(QWidget *parent = nullptr,
|
||||
bool hoverToZoomEnabled = false,
|
||||
bool raiseOnEnter = false);
|
||||
CardInfoPtr getInfo()
|
||||
{
|
||||
return info;
|
||||
}
|
||||
[[nodiscard]] QSize sizeHint() const override;
|
||||
void setHoverToZoomEnabled(bool enabled);
|
||||
|
||||
public slots:
|
||||
void setCard(CardInfoPtr card);
|
||||
void setScaleFactor(int scale); // New slot for scaling
|
||||
void setHoverToZoomEnabled(bool enabled);
|
||||
void setRaiseOnEnterEnabled(bool enabled);
|
||||
void updatePixmap();
|
||||
|
||||
signals:
|
||||
|
|
@ -45,6 +49,7 @@ protected:
|
|||
void enterEvent(QEvent *event) override; // Qt5 signature
|
||||
#endif
|
||||
void leaveEvent(QEvent *event) override;
|
||||
void moveEvent(QMoveEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void loadPixmap();
|
||||
|
|
@ -65,10 +70,14 @@ private:
|
|||
QPixmap resizedPixmap;
|
||||
bool pixmapDirty;
|
||||
bool hoverToZoomEnabled;
|
||||
bool raiseOnEnter;
|
||||
int hoverActivateThresholdInMs = 500;
|
||||
CardInfoPictureEnlargedWidget *enlargedPixmapWidget;
|
||||
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
|
||||
|
||||
QMenu *createRightClickMenu();
|
||||
QMenu *createViewRelatedCardsMenu();
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
* @brief Constructs a CardPictureWithTextOverlay widget.
|
||||
* @param parent The parent widget.
|
||||
* @param hoverToZoomEnabled If this widget will spawn a larger widget when hovered over.
|
||||
* @param raiseOnEnter If this widget will raise slightly when entered.
|
||||
* @param textColor The color of the overlay text.
|
||||
* @param outlineColor The color of the outline around the text.
|
||||
* @param fontSize The font size of the overlay text.
|
||||
|
|
@ -18,11 +19,12 @@
|
|||
*/
|
||||
CardInfoPictureWithTextOverlayWidget::CardInfoPictureWithTextOverlayWidget(QWidget *parent,
|
||||
const bool hoverToZoomEnabled,
|
||||
const bool raiseOnEnter,
|
||||
const QColor &textColor,
|
||||
const QColor &outlineColor,
|
||||
const int fontSize,
|
||||
const Qt::Alignment alignment)
|
||||
: CardInfoPictureWidget(parent, hoverToZoomEnabled), textColor(textColor), outlineColor(outlineColor),
|
||||
: CardInfoPictureWidget(parent, hoverToZoomEnabled, raiseOnEnter), textColor(textColor), outlineColor(outlineColor),
|
||||
fontSize(fontSize), textAlignment(alignment)
|
||||
{
|
||||
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class CardInfoPictureWithTextOverlayWidget : public CardInfoPictureWidget
|
|||
public:
|
||||
explicit CardInfoPictureWithTextOverlayWidget(QWidget *parent = nullptr,
|
||||
bool hoverToZoomEnabled = false,
|
||||
bool raiseOnEnter = false,
|
||||
const QColor &textColor = Qt::white,
|
||||
const QColor &outlineColor = Qt::black,
|
||||
int fontSize = 12,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include "deck_preview_card_picture_widget.h"
|
||||
|
||||
#include "../../../../settings/cache_settings.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QFontMetrics>
|
||||
|
|
@ -22,15 +24,24 @@
|
|||
*/
|
||||
DeckPreviewCardPictureWidget::DeckPreviewCardPictureWidget(QWidget *parent,
|
||||
const bool hoverToZoomEnabled,
|
||||
const bool raiseOnEnter,
|
||||
const QColor &textColor,
|
||||
const QColor &outlineColor,
|
||||
const int fontSize,
|
||||
const Qt::Alignment alignment)
|
||||
: CardInfoPictureWithTextOverlayWidget(parent, hoverToZoomEnabled, textColor, outlineColor, fontSize, alignment)
|
||||
: CardInfoPictureWithTextOverlayWidget(parent,
|
||||
hoverToZoomEnabled,
|
||||
raiseOnEnter,
|
||||
textColor,
|
||||
outlineColor,
|
||||
fontSize,
|
||||
alignment)
|
||||
{
|
||||
singleClickTimer = new QTimer(this);
|
||||
singleClickTimer->setSingleShot(true);
|
||||
connect(singleClickTimer, &QTimer::timeout, this, [this]() { emit imageClicked(lastMouseEvent, this); });
|
||||
connect(&SettingsCache::instance(), &SettingsCache::visualDeckStorageSelectionAnimationChanged, this,
|
||||
&CardInfoPictureWidget::setRaiseOnEnterEnabled);
|
||||
}
|
||||
|
||||
void DeckPreviewCardPictureWidget::mousePressEvent(QMouseEvent *event)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class DeckPreviewCardPictureWidget final : public CardInfoPictureWithTextOverlay
|
|||
public:
|
||||
explicit DeckPreviewCardPictureWidget(QWidget *parent,
|
||||
bool hoverToZoomEnabled = false,
|
||||
bool raiseOnEnter = false,
|
||||
const QColor &textColor = Qt::white,
|
||||
const QColor &outlineColor = Qt::black,
|
||||
int fontSize = 12,
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ DeckPreviewWidget::DeckPreviewWidget(QWidget *_parent,
|
|||
&VisualDeckStorageTagFilterWidget::refreshTags);
|
||||
deckLoader->loadFromFileAsync(filePath, DeckLoader::getFormatFromName(filePath), false);
|
||||
|
||||
bannerCardDisplayWidget = new DeckPreviewCardPictureWidget(this);
|
||||
bannerCardDisplayWidget =
|
||||
new DeckPreviewCardPictureWidget(this, false, visualDeckStorageWidget->deckPreviewSelectionAnimationEnabled);
|
||||
|
||||
connect(bannerCardDisplayWidget, &DeckPreviewCardPictureWidget::imageClicked, this,
|
||||
&DeckPreviewWidget::imageClickedEvent);
|
||||
|
|
|
|||
|
|
@ -125,6 +125,10 @@ VisualDeckStorageWidget::VisualDeckStorageWidget(QWidget *parent) : QWidget(pare
|
|||
tagFilterWidget = new VisualDeckStorageTagFilterWidget(this);
|
||||
updateTagsVisibility(SettingsCache::instance().getVisualDeckStorageShowTagFilter());
|
||||
|
||||
deckPreviewSelectionAnimationEnabled = SettingsCache::instance().getVisualDeckStorageSelectionAnimation();
|
||||
connect(&SettingsCache::instance(), &SettingsCache::visualDeckStorageSelectionAnimationChanged, this,
|
||||
&VisualDeckStorageWidget::updateSelectionAnimationEnabled);
|
||||
|
||||
// deck area
|
||||
scrollArea = new QScrollArea(this);
|
||||
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
|
|
@ -270,4 +274,9 @@ void VisualDeckStorageWidget::updateTagsVisibility(const bool visible)
|
|||
} else {
|
||||
tagFilterWidget->setHidden(true);
|
||||
}
|
||||
}
|
||||
|
||||
void VisualDeckStorageWidget::updateSelectionAnimationEnabled(const bool enabled)
|
||||
{
|
||||
deckPreviewSelectionAnimationEnabled = enabled;
|
||||
}
|
||||
|
|
@ -31,6 +31,7 @@ public:
|
|||
|
||||
CardSizeWidget *cardSizeWidget;
|
||||
VisualDeckStorageTagFilterWidget *tagFilterWidget;
|
||||
bool deckPreviewSelectionAnimationEnabled;
|
||||
|
||||
public slots:
|
||||
void createRootFolderWidget(); // Refresh the display of cards based on the current sorting option
|
||||
|
|
@ -39,6 +40,7 @@ public slots:
|
|||
void updateColorFilter();
|
||||
void updateSearchFilter();
|
||||
void updateTagsVisibility(bool visible);
|
||||
void updateSelectionAnimationEnabled(bool enabled);
|
||||
void updateSortOrder();
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
|
|
|||
|
|
@ -676,6 +676,11 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage()
|
|||
connect(&visualDeckStorageInGameCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
|
||||
&SettingsCache::setVisualDeckStorageInGame);
|
||||
|
||||
visualDeckStorageSelectionAnimationCheckBox.setChecked(
|
||||
SettingsCache::instance().getVisualDeckStorageSelectionAnimation());
|
||||
connect(&visualDeckStorageSelectionAnimationCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
|
||||
&SettingsCache::setVisualDeckStorageSelectionAnimation);
|
||||
|
||||
visualDeckStoragePromptForConversionSelector.addItem(""); // these will be set in retranslateUI
|
||||
visualDeckStoragePromptForConversionSelector.addItem("");
|
||||
visualDeckStoragePromptForConversionSelector.addItem("");
|
||||
|
|
@ -697,8 +702,9 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage()
|
|||
auto *deckEditorGrid = new QGridLayout;
|
||||
deckEditorGrid->addWidget(&openDeckInNewTabCheckBox, 0, 0);
|
||||
deckEditorGrid->addWidget(&visualDeckStorageInGameCheckBox, 1, 0);
|
||||
deckEditorGrid->addWidget(&visualDeckStoragePromptForConversionLabel, 2, 0);
|
||||
deckEditorGrid->addWidget(&visualDeckStoragePromptForConversionSelector, 2, 1);
|
||||
deckEditorGrid->addWidget(&visualDeckStorageSelectionAnimationCheckBox, 2, 0);
|
||||
deckEditorGrid->addWidget(&visualDeckStoragePromptForConversionLabel, 3, 0);
|
||||
deckEditorGrid->addWidget(&visualDeckStoragePromptForConversionSelector, 3, 1);
|
||||
|
||||
deckEditorGroupBox = new QGroupBox;
|
||||
deckEditorGroupBox->setLayout(deckEditorGrid);
|
||||
|
|
@ -759,6 +765,7 @@ void UserInterfaceSettingsPage::retranslateUi()
|
|||
deckEditorGroupBox->setTitle(tr("Deck editor/storage settings"));
|
||||
openDeckInNewTabCheckBox.setText(tr("Open deck in new tab by default"));
|
||||
visualDeckStorageInGameCheckBox.setText(tr("Use visual deck storage in game lobby"));
|
||||
visualDeckStorageSelectionAnimationCheckBox.setText(tr("Use selection animation for Visual Deck Storage"));
|
||||
visualDeckStoragePromptForConversionLabel.setText(
|
||||
tr("When adding a tag in the visual deck storage to a .txt deck:"));
|
||||
visualDeckStoragePromptForConversionSelector.setItemText(visualDeckStoragePromptForConversionIndexNone,
|
||||
|
|
|
|||
|
|
@ -154,6 +154,7 @@ private:
|
|||
QLabel visualDeckStoragePromptForConversionLabel;
|
||||
QComboBox visualDeckStoragePromptForConversionSelector;
|
||||
QCheckBox visualDeckStorageInGameCheckBox;
|
||||
QCheckBox visualDeckStorageSelectionAnimationCheckBox;
|
||||
QLabel rewindBufferingMsLabel;
|
||||
QSpinBox rewindBufferingMsBox;
|
||||
QGroupBox *generalGroupBox;
|
||||
|
|
|
|||
|
|
@ -280,6 +280,8 @@ SettingsCache::SettingsCache()
|
|||
settings->value("interface/visualdeckstoragepromptforconversion", true).toBool();
|
||||
visualDeckStorageAlwaysConvert = settings->value("interface/visualdeckstoragealwaysconvert", false).toBool();
|
||||
visualDeckStorageInGame = settings->value("interface/visualdeckstorageingame", true).toBool();
|
||||
visualDeckStorageSelectionAnimation =
|
||||
settings->value("interface/visualdeckstorageselectionanimation", true).toBool();
|
||||
horizontalHand = settings->value("hand/horizontal", true).toBool();
|
||||
invertVerticalCoordinate = settings->value("table/invert_vertical", false).toBool();
|
||||
minPlayersForMultiColumnLayout = settings->value("interface/min_players_multicolumn", 4).toInt();
|
||||
|
|
@ -761,6 +763,13 @@ void SettingsCache::setVisualDeckStorageInGame(QT_STATE_CHANGED_T value)
|
|||
emit visualDeckStorageInGameChanged(visualDeckStorageInGame);
|
||||
}
|
||||
|
||||
void SettingsCache::setVisualDeckStorageSelectionAnimation(QT_STATE_CHANGED_T value)
|
||||
{
|
||||
visualDeckStorageSelectionAnimation = value;
|
||||
settings->setValue("interface/visualdeckstorageselectionanimation", visualDeckStorageSelectionAnimation);
|
||||
emit visualDeckStorageSelectionAnimationChanged(visualDeckStorageSelectionAnimation);
|
||||
}
|
||||
|
||||
void SettingsCache::setHorizontalHand(QT_STATE_CHANGED_T _horizontalHand)
|
||||
{
|
||||
horizontalHand = static_cast<bool>(_horizontalHand);
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ signals:
|
|||
void visualDeckStorageDrawUnusedColorIdentitiesChanged(bool _visible);
|
||||
void visualDeckStorageUnusedColorIdentitiesOpacityChanged(bool value);
|
||||
void visualDeckStorageInGameChanged(bool enabled);
|
||||
void visualDeckStorageSelectionAnimationChanged(bool enabled);
|
||||
void horizontalHandChanged();
|
||||
void handJustificationChanged();
|
||||
void invertVerticalCoordinateChanged();
|
||||
|
|
@ -145,6 +146,7 @@ private:
|
|||
bool visualDeckStoragePromptForConversion;
|
||||
bool visualDeckStorageAlwaysConvert;
|
||||
bool visualDeckStorageInGame;
|
||||
bool visualDeckStorageSelectionAnimation;
|
||||
bool horizontalHand;
|
||||
bool invertVerticalCoordinate;
|
||||
int minPlayersForMultiColumnLayout;
|
||||
|
|
@ -466,6 +468,10 @@ public:
|
|||
{
|
||||
return visualDeckStorageInGame;
|
||||
}
|
||||
bool getVisualDeckStorageSelectionAnimation() const
|
||||
{
|
||||
return visualDeckStorageSelectionAnimation;
|
||||
}
|
||||
bool getHorizontalHand() const
|
||||
{
|
||||
return horizontalHand;
|
||||
|
|
@ -806,6 +812,7 @@ public slots:
|
|||
void setVisualDeckStoragePromptForConversion(bool _visualDeckStoragePromptForConversion);
|
||||
void setVisualDeckStorageAlwaysConvert(bool _visualDeckStorageAlwaysConvert);
|
||||
void setVisualDeckStorageInGame(QT_STATE_CHANGED_T value);
|
||||
void setVisualDeckStorageSelectionAnimation(QT_STATE_CHANGED_T value);
|
||||
void setHorizontalHand(QT_STATE_CHANGED_T _horizontalHand);
|
||||
void setInvertVerticalCoordinate(QT_STATE_CHANGED_T _invertVerticalCoordinate);
|
||||
void setMinPlayersForMultiColumnLayout(int _minPlayersForMultiColumnLayout);
|
||||
|
|
|
|||
|
|
@ -246,6 +246,9 @@ void SettingsCache::setVisualDeckStorageAlwaysConvert(bool /* _visualDeckStorage
|
|||
void SettingsCache::setVisualDeckStorageInGame(QT_STATE_CHANGED_T /* value */)
|
||||
{
|
||||
}
|
||||
void SettingsCache::setVisualDeckStorageSelectionAnimation(QT_STATE_CHANGED_T /* value */)
|
||||
{
|
||||
}
|
||||
void SettingsCache::setHorizontalHand(QT_STATE_CHANGED_T /* _horizontalHand */)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -250,6 +250,9 @@ void SettingsCache::setVisualDeckStorageAlwaysConvert(bool /* _visualDeckStorage
|
|||
void SettingsCache::setVisualDeckStorageInGame(QT_STATE_CHANGED_T /* value */)
|
||||
{
|
||||
}
|
||||
void SettingsCache::setVisualDeckStorageSelectionAnimation(QT_STATE_CHANGED_T /* value */)
|
||||
{
|
||||
}
|
||||
void SettingsCache::setHorizontalHand(QT_STATE_CHANGED_T /* _horizontalHand */)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user