mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 08:34:52 -07:00
improved rubber band drag
This commit is contained in:
parent
99387861cd
commit
99c0a41d18
15 changed files with 139 additions and 14 deletions
48
cockatrice/src/selectzone.cpp
Normal file
48
cockatrice/src/selectzone.cpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#include <QGraphicsSceneMouseEvent>
|
||||
#include "selectzone.h"
|
||||
#include "gamescene.h"
|
||||
|
||||
SelectZone::SelectZone(Player *_player, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent, bool isView)
|
||||
: CardZone(_player, _name, _hasCardAttr, _isShufflable, _contentsKnown, parent, isView)
|
||||
{
|
||||
}
|
||||
|
||||
void SelectZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->buttons().testFlag(Qt::LeftButton)) {
|
||||
QPointF pos = event->pos();
|
||||
if (pos.x() < 0)
|
||||
pos.setX(0);
|
||||
QRectF br = boundingRect();
|
||||
if (pos.x() > br.width())
|
||||
pos.setX(br.width());
|
||||
if (pos.y() < 0)
|
||||
pos.setY(0);
|
||||
if (pos.y() > br.height())
|
||||
pos.setY(br.height());
|
||||
|
||||
QRectF selectionRect = QRectF(selectionOrigin, pos).normalized();
|
||||
for (int i = 0; i < cards.size(); ++i)
|
||||
cards[i]->setSelected(selectionRect.intersects(cards[i]->mapRectToParent(cards[i]->boundingRect())));
|
||||
|
||||
static_cast<GameScene *>(scene())->resizeRubberBand(scenePos() + pos);
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void SelectZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
selectionOrigin = event->pos();
|
||||
static_cast<GameScene *>(scene())->startRubberBand(event->scenePos());
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void SelectZone::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
selectionOrigin = QPoint();
|
||||
static_cast<GameScene *>(scene())->stopRubberBand();
|
||||
event->accept();
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue