* Make cards rounded Magic cards have rounded corners, and playing cards tend to have rounded corners as well, but Cockatrice currently displays rectangular cards. This can cause visual glitches when using image scans where the border does not extend in the corner, and for this reason Cockatrice always draws a (rectangular) border around the card to try and make it look a bit better. In this patch I take a different approach: rather than try to make rounded pegs, er, cards, go into a square hole, the hole is now rounded. More precisely, the AbstractCardItem now has a rounded rectangular shape (with a corner of 5% of the width of the card, identical to that of modern M:TG physical cards). As a side effect, the card drawing gets a bit simplified by getting rid of transformPainter() when drawing the card outline and using the QPainter::drawPixmap overloads that takes a target QRectF instead. This means we no longer have to bother about card rotation when painting since that's taken care of by the Graphics View framework (which transformPainter() undoes). * format * Also give PileZone rounded corners * Forgot untap status + bits of CardDragItem * fix deckviewcard calculations * Rounded CardInfoPicture
66 lines
1.5 KiB
C++
66 lines
1.5 KiB
C++
#include "cardinfopicture.h"
|
|
|
|
#include "carditem.h"
|
|
#include "main.h"
|
|
#include "pictureloader.h"
|
|
|
|
#include <QStylePainter>
|
|
#include <QWidget>
|
|
|
|
CardInfoPicture::CardInfoPicture(QWidget *parent) : QWidget(parent), info(nullptr), pixmapDirty(true)
|
|
{
|
|
setMinimumHeight(100);
|
|
}
|
|
|
|
void CardInfoPicture::setCard(CardInfoPtr card)
|
|
{
|
|
if (info) {
|
|
disconnect(info.data(), nullptr, this, nullptr);
|
|
}
|
|
|
|
info = card;
|
|
|
|
if (info) {
|
|
connect(info.data(), SIGNAL(pixmapUpdated()), this, SLOT(updatePixmap()));
|
|
}
|
|
|
|
updatePixmap();
|
|
}
|
|
|
|
void CardInfoPicture::resizeEvent(QResizeEvent *)
|
|
{
|
|
updatePixmap();
|
|
}
|
|
|
|
void CardInfoPicture::updatePixmap()
|
|
{
|
|
pixmapDirty = true;
|
|
update();
|
|
}
|
|
|
|
void CardInfoPicture::loadPixmap()
|
|
{
|
|
if (info)
|
|
PictureLoader::getPixmap(resizedPixmap, info, size());
|
|
else
|
|
PictureLoader::getCardBackPixmap(resizedPixmap, size());
|
|
}
|
|
|
|
void CardInfoPicture::paintEvent(QPaintEvent *)
|
|
{
|
|
if (width() == 0 || height() == 0)
|
|
return;
|
|
|
|
if (pixmapDirty)
|
|
loadPixmap();
|
|
|
|
QSize scaledSize = resizedPixmap.size().scaled(size(), Qt::KeepAspectRatio);
|
|
QPoint topLeft{(width() - scaledSize.width()) / 2, (height() - scaledSize.height()) / 2};
|
|
qreal radius = 0.05 * scaledSize.width();
|
|
|
|
QStylePainter painter(this);
|
|
QPainterPath shape;
|
|
shape.addRoundedRect(QRect(topLeft, scaledSize), radius, radius);
|
|
painter.setClipPath(shape);
|
|
painter.drawItemPixmap(QRect(topLeft, scaledSize), Qt::AlignCenter, resizedPixmap);
|
|
}
|