mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
* [Settings] Split cache_settings into multiple files Took 9 minutes Took 4 minutes * [Settings] Fwd declare settings classes in cache_settings Took 15 minutes * Fix oracle includes. Took 8 minutes * Address comments, fix windows CI Took 8 minutes * fix copy constructor visibility Took 3 minutes * lint Took 2 minutes * Fix native format tests. Took 5 minutes * Remove test header guard Took 4 seconds * Remove tests invalid in CI environ Took 24 seconds * Adjust to rebase. Took 11 minutes * Change settings file name. Took 8 minutes --------- Co-authored-by: Lukas Brübach <lukas.bruebach@bdosecurity.de> Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
75 lines
2.6 KiB
C++
75 lines
2.6 KiB
C++
#include "abstract_card_drag_item.h"
|
|
|
|
#include "../../client/settings/cache_settings.h"
|
|
#include "../z_values.h"
|
|
|
|
#include <QCursor>
|
|
#include <QDebug>
|
|
#include <QGraphicsSceneMouseEvent>
|
|
#include <QPainter>
|
|
#include <libcockatrice/settings/cards_display_settings.h>
|
|
|
|
const QColor GHOST_MASK = QColor(255, 255, 255, 50);
|
|
|
|
AbstractCardDragItem::AbstractCardDragItem(AbstractCardItem *_item,
|
|
const QPointF &_hotSpot,
|
|
AbstractCardDragItem *parentDrag)
|
|
: QGraphicsItem(), item(_item), hotSpot(_hotSpot)
|
|
{
|
|
if (parentDrag) {
|
|
parentDrag->addChildDrag(this);
|
|
setZValue(ZValues::childDragZValue(hotSpot.x(), hotSpot.y()));
|
|
connect(parentDrag, &QObject::destroyed, this, &AbstractCardDragItem::deleteLater);
|
|
} else {
|
|
hotSpot = QPointF{qBound(0.0, hotSpot.x(), CardDimensions::WIDTH_F - 1),
|
|
qBound(0.0, hotSpot.y(), CardDimensions::HEIGHT_F - 1)};
|
|
setCursor(Qt::ClosedHandCursor);
|
|
setZValue(ZValues::DRAG_ITEM);
|
|
}
|
|
if (item->getTapped()) {
|
|
setTransform(QTransform()
|
|
.translate(CardDimensions::WIDTH_HALF_F, CardDimensions::HEIGHT_HALF_F)
|
|
.rotate(90)
|
|
.translate(-CardDimensions::WIDTH_HALF_F, -CardDimensions::HEIGHT_HALF_F));
|
|
}
|
|
|
|
setCacheMode(DeviceCoordinateCache);
|
|
|
|
connect(&SettingsCache::instance().cardsDisplay(), &CardsDisplaySettings::roundCardCornersChanged, this,
|
|
[this](bool _roundCardCorners) {
|
|
Q_UNUSED(_roundCardCorners);
|
|
|
|
prepareGeometryChange();
|
|
update();
|
|
});
|
|
|
|
connect(item, &QObject::destroyed, this, &AbstractCardDragItem::deleteLater);
|
|
}
|
|
|
|
QPainterPath AbstractCardDragItem::shape() const
|
|
{
|
|
QPainterPath shape;
|
|
qreal cardCornerRadius =
|
|
SettingsCache::instance().cardsDisplay().getRoundCardCorners() ? 0.05 * CardDimensions::WIDTH_F : 0.0;
|
|
shape.addRoundedRect(boundingRect(), cardCornerRadius, cardCornerRadius);
|
|
return shape;
|
|
}
|
|
|
|
void AbstractCardDragItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
{
|
|
item->paint(painter, option, widget);
|
|
|
|
// adds a mask to the card so it looks like the card hasnt been placed yet
|
|
painter->fillPath(shape(), GHOST_MASK);
|
|
}
|
|
|
|
void AbstractCardDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
event->accept();
|
|
updatePosition(event->scenePos());
|
|
}
|
|
|
|
void AbstractCardDragItem::addChildDrag(AbstractCardDragItem *child)
|
|
{
|
|
childDrags << child;
|
|
}
|