mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-09 19:43:26 -08:00
* [VisualDatabase] Draw the card grid with a model/view instead of a widget per card The visual card database built one CardInfoPictureWithTextOverlayWidget per card, 100 per page, and tore them down on every search, resize and scroll page. It also looked each card up again by name from the model row, kept a shadow QList<ExactCard>, and carried paging state plus a 5 s timer that only existed to defer the first page. Replace that with a real view on a flattened model: - CardDatabaseDisplayModel gains CardInfoRole and cardInfoAt(), so a view can get the CardInfoPtr behind a proxy row without a name round trip. - New CardDatabaseVisualDisplayModel (libcockatrice_models) flattens the filtered and sorted proxy into one entry per displayed card picture: the preferred printing normally, every printing of the selected sets while set filters are active. Proxy changes rebuild it on a 30 ms coalescing timer. - New CardDatabaseVisualView (QListView IconMode) paints only visible rows through the new CardPictureDelegate, keeps the old interaction contract (left/right/middle press -> cardClicked, hover -> cardHovered, Ctrl+wheel resize, no selection, no focus stealing, scroll to top on a new result) and repaints when CardPictureLoader reports an async image. - CardSizeWidget::enableCtrlScrollResize() also watches scroll-area viewports, which is what makes Ctrl+wheel work over a QListView. - VisualDatabaseDisplayWidget drops the paging, the shadow list, the dead members and the 5 s timer. Behaviour-preserving: no gameplay change, no new user-facing strings. * [VisualDatabase] Fix the card grid wheel step QListView hands the delegate's item height to the scroll bar as its single step under ScrollPerPixel, so QAbstractSlider moved wheelScrollLines() whole card rows per notch. Handle the wheel in the view instead: one line is an eighth of the grid cell, so a notch moves about a third of a card row at any card size and still follows the OS line count. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
100 lines
2.8 KiB
C++
100 lines
2.8 KiB
C++
/**
|
|
* @file card_info_picture_widget.h
|
|
* @ingroup CardWidgets
|
|
*/
|
|
//! \todo Document this file.
|
|
|
|
#ifndef CARD_INFO_PICTURE_H
|
|
#define CARD_INFO_PICTURE_H
|
|
|
|
#include <QLoggingCategory>
|
|
#include <QMouseEvent>
|
|
#include <QPixmap>
|
|
#include <QPoint>
|
|
#include <QWidget>
|
|
#include <libcockatrice/card/printing/exact_card.h>
|
|
#include <qtmetamacros.h>
|
|
|
|
class CardInfoPictureEnlargedWidget;
|
|
class QPropertyAnimation;
|
|
class QTimer;
|
|
|
|
inline Q_LOGGING_CATEGORY(CardInfoPictureWidgetLog, "card_info_picture_widget");
|
|
|
|
class QMenu;
|
|
|
|
class CardInfoPictureWidget : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
/// Width of a card picture at 100 % scale, in pixels.
|
|
static constexpr int BASE_WIDTH = 200;
|
|
/// Height / width of a card picture.
|
|
static constexpr qreal ASPECT_RATIO = 1.396;
|
|
|
|
explicit CardInfoPictureWidget(QWidget *parent = nullptr,
|
|
bool hoverToZoomEnabled = false,
|
|
bool raiseOnEnter = false);
|
|
ExactCard getCard()
|
|
{
|
|
return exactCard;
|
|
}
|
|
[[nodiscard]] QSize sizeHint() const override;
|
|
|
|
/**
|
|
* @brief The size a card picture has at @p scaleFactor percent.
|
|
* @param scaleFactor Percentage of BASE_WIDTH, as set by the card size slider.
|
|
*/
|
|
[[nodiscard]] static QSize sizeForScaleFactor(int scaleFactor);
|
|
|
|
public slots:
|
|
void setCard(const ExactCard &card);
|
|
void setScaleFactor(int scale); // New slot for scaling
|
|
void setHoverToZoomEnabled(bool enabled);
|
|
void setRaiseOnEnterEnabled(bool enabled);
|
|
void updatePixmap();
|
|
|
|
signals:
|
|
void hoveredOnCard(const ExactCard &hoveredCard);
|
|
void cardScaleFactorChanged(int _scale);
|
|
void cardChanged(const ExactCard &card);
|
|
void cardClicked(QMouseEvent *event, const ExactCard &card);
|
|
|
|
protected:
|
|
void resizeEvent(QResizeEvent *event) override;
|
|
void paintEvent(QPaintEvent *) override;
|
|
void enterEvent(QEnterEvent *event) override;
|
|
void leaveEvent(QEvent *event) override;
|
|
void moveEvent(QMoveEvent *event) override;
|
|
void mouseMoveEvent(QMouseEvent *event) override;
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
void hideEvent(QHideEvent *event) override;
|
|
void loadPixmap();
|
|
[[nodiscard]] const QPixmap &getResizedPixmap() const
|
|
{
|
|
return resizedPixmap;
|
|
}
|
|
void showEnlargedPixmap();
|
|
void destroyEnlargedPixmapWidget();
|
|
|
|
private:
|
|
ExactCard exactCard;
|
|
double scaleFactor = 100;
|
|
QPixmap resizedPixmap;
|
|
bool pixmapDirty;
|
|
bool hoverToZoomEnabled;
|
|
bool raiseOnEnter;
|
|
|
|
CardInfoPictureEnlargedWidget *enlargedPixmapWidget = nullptr;
|
|
|
|
QTimer *hoverTimer;
|
|
QPropertyAnimation *animation;
|
|
QPoint originalPos; // Store the original position
|
|
|
|
QMenu *createRightClickMenu();
|
|
QMenu *createViewRelatedCardsMenu();
|
|
QMenu *createAddToOpenDeckMenu();
|
|
};
|
|
|
|
#endif
|