mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -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>
83 lines
2.9 KiB
C++
83 lines
2.9 KiB
C++
#include "card_picture_delegate.h"
|
|
|
|
#include "../../../client/settings/cache_settings.h"
|
|
#include "../../card_picture_loader/card_picture_loader.h"
|
|
#include "card_art_utils.h"
|
|
#include "card_database_visual_display_model.h"
|
|
#include "libcockatrice/card/printing/exact_card.h"
|
|
#include "libcockatrice/settings/cards_display_settings.h"
|
|
|
|
#include <QPainter>
|
|
#include <QPainterPath>
|
|
#include <QPixmap>
|
|
#include <QRect>
|
|
#include <QStyleOptionViewItem>
|
|
#include <libcockatrice/card/printing/printing_info.h>
|
|
|
|
CardPictureDelegate::CardPictureDelegate(CardDatabaseVisualDisplayModel *_model, QObject *parent)
|
|
: QStyledItemDelegate(parent), model(_model)
|
|
{
|
|
}
|
|
|
|
void CardPictureDelegate::setCardSize(const QSize &size)
|
|
{
|
|
if (cardSize == size) {
|
|
return;
|
|
}
|
|
|
|
cardSize = size;
|
|
}
|
|
|
|
void CardPictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
{
|
|
if (model == nullptr) {
|
|
return;
|
|
}
|
|
|
|
const ExactCard card = model->cardAt(index.row());
|
|
if (!card) {
|
|
return;
|
|
}
|
|
|
|
// The grid cell is the card plus SPACING; give the picture the rest.
|
|
const int inset = SPACING / 2;
|
|
const QRect cardArea = option.rect.adjusted(inset, inset, -inset, -inset);
|
|
|
|
QPixmap pixmap;
|
|
CardPictureLoader::getCardBackLoadingInProgressPixmap(pixmap, cardArea.size());
|
|
CardPictureLoader::getPixmap(pixmap, card, cardArea.size());
|
|
|
|
if (pixmap.isNull()) {
|
|
return;
|
|
}
|
|
|
|
if (SettingsCache::instance().cardsDisplay().getAutoRotateSidewaysLayoutCards()) {
|
|
pixmap = CardArtUtils::rotateSidewaysLayoutArt(pixmap, card);
|
|
}
|
|
|
|
// Fit the picture into the cell and center it, like CardInfoPictureWidget does.
|
|
const QSize pictureSize = pixmap.deviceIndependentSize().toSize().scaled(cardArea.size(), Qt::KeepAspectRatio);
|
|
const QRect pictureRect(cardArea.center().x() - pictureSize.width() / 2,
|
|
cardArea.center().y() - pictureSize.height() / 2, pictureSize.width(),
|
|
pictureSize.height());
|
|
|
|
const qreal radius = SettingsCache::instance().cardsDisplay().getRoundCardCorners()
|
|
? 0.05 * static_cast<qreal>(pictureRect.width())
|
|
: 0.0;
|
|
|
|
painter->save();
|
|
painter->setRenderHint(QPainter::Antialiasing);
|
|
painter->setRenderHint(QPainter::SmoothPixmapTransform);
|
|
QPainterPath shape;
|
|
shape.addRoundedRect(pictureRect, radius, radius);
|
|
painter->setClipPath(shape);
|
|
// Source rect is in device pixels, target in logical ones: drawPixmap scales
|
|
// between them without the device pixel ratio being applied twice.
|
|
painter->drawPixmap(pictureRect, pixmap, QRectF(pixmap.rect()));
|
|
painter->restore();
|
|
}
|
|
|
|
QSize CardPictureDelegate::sizeHint(const QStyleOptionViewItem & /*option*/, const QModelIndex & /*index*/) const
|
|
{
|
|
return cardSize + QSize(SPACING, SPACING);
|
|
}
|