improved rubber band drag
This commit is contained in:
parent
99387861cd
commit
99c0a41d18
15 changed files with 139 additions and 14 deletions
|
@ -16,6 +16,7 @@ HEADERS += src/counter.h \
|
||||||
src/remoteclient.h \
|
src/remoteclient.h \
|
||||||
src/window_main.h \
|
src/window_main.h \
|
||||||
src/cardzone.h \
|
src/cardzone.h \
|
||||||
|
src/selectzone.h \
|
||||||
src/player.h \
|
src/player.h \
|
||||||
src/playertarget.h \
|
src/playertarget.h \
|
||||||
src/cardlist.h \
|
src/cardlist.h \
|
||||||
|
@ -96,6 +97,7 @@ SOURCES += src/counter.cpp \
|
||||||
src/player.cpp \
|
src/player.cpp \
|
||||||
src/playertarget.cpp \
|
src/playertarget.cpp \
|
||||||
src/cardzone.cpp \
|
src/cardzone.cpp \
|
||||||
|
src/selectzone.cpp \
|
||||||
src/cardlist.cpp \
|
src/cardlist.cpp \
|
||||||
src/abstractcarditem.cpp \
|
src/abstractcarditem.cpp \
|
||||||
src/carditem.cpp \
|
src/carditem.cpp \
|
||||||
|
|
|
@ -195,3 +195,18 @@ bool GameScene::event(QEvent *event)
|
||||||
}
|
}
|
||||||
return QGraphicsScene::event(event);
|
return QGraphicsScene::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameScene::startRubberBand(const QPointF &selectionOrigin)
|
||||||
|
{
|
||||||
|
emit sigStartRubberBand(selectionOrigin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameScene::resizeRubberBand(const QPointF &cursorPoint)
|
||||||
|
{
|
||||||
|
emit sigResizeRubberBand(cursorPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameScene::stopRubberBand()
|
||||||
|
{
|
||||||
|
emit sigStopRubberBand();
|
||||||
|
}
|
||||||
|
|
|
@ -23,6 +23,10 @@ public:
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
const QRectF &getPlayersRect() const { return playersRect; }
|
const QRectF &getPlayersRect() const { return playersRect; }
|
||||||
void processViewSizeChange(const QSize &newSize);
|
void processViewSizeChange(const QSize &newSize);
|
||||||
|
|
||||||
|
void startRubberBand(const QPointF &selectionOrigin);
|
||||||
|
void resizeRubberBand(const QPointF &cursorPoint);
|
||||||
|
void stopRubberBand();
|
||||||
public slots:
|
public slots:
|
||||||
void toggleZoneView(Player *player, const QString &zoneName, int numberCards);
|
void toggleZoneView(Player *player, const QString &zoneName, int numberCards);
|
||||||
void addRevealedZoneView(Player *player, CardZone *zone, const QList<ServerInfo_Card *> &cardList);
|
void addRevealedZoneView(Player *player, CardZone *zone, const QList<ServerInfo_Card *> &cardList);
|
||||||
|
@ -35,6 +39,10 @@ private slots:
|
||||||
void rearrange();
|
void rearrange();
|
||||||
protected:
|
protected:
|
||||||
bool event(QEvent *event);
|
bool event(QEvent *event);
|
||||||
|
signals:
|
||||||
|
void sigStartRubberBand(const QPointF &selectionOrigin);
|
||||||
|
void sigResizeRubberBand(const QPointF &cursorPoint);
|
||||||
|
void sigStopRubberBand();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,18 +2,22 @@
|
||||||
#include "gamescene.h"
|
#include "gamescene.h"
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
#include <QRubberBand>
|
||||||
|
|
||||||
GameView::GameView(QGraphicsScene *scene, QWidget *parent)
|
GameView::GameView(QGraphicsScene *scene, QWidget *parent)
|
||||||
: QGraphicsView(scene, parent)
|
: QGraphicsView(scene, parent), rubberBand(0)
|
||||||
{
|
{
|
||||||
setBackgroundBrush(QBrush(QColor(0, 0, 0)));
|
setBackgroundBrush(QBrush(QColor(0, 0, 0)));
|
||||||
setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing/* | QPainter::SmoothPixmapTransform*/);
|
setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing/* | QPainter::SmoothPixmapTransform*/);
|
||||||
setDragMode(RubberBandDrag);
|
|
||||||
setFocusPolicy(Qt::NoFocus);
|
setFocusPolicy(Qt::NoFocus);
|
||||||
setViewportUpdateMode(BoundingRectViewportUpdate);
|
setViewportUpdateMode(BoundingRectViewportUpdate);
|
||||||
|
|
||||||
connect(scene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(updateSceneRect(const QRectF &)));
|
connect(scene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(updateSceneRect(const QRectF &)));
|
||||||
|
|
||||||
|
connect(scene, SIGNAL(sigStartRubberBand(const QPointF &)), this, SLOT(startRubberBand(const QPointF &)));
|
||||||
|
connect(scene, SIGNAL(sigResizeRubberBand(const QPointF &)), this, SLOT(resizeRubberBand(const QPointF &)));
|
||||||
|
connect(scene, SIGNAL(sigStopRubberBand()), this, SLOT(stopRubberBand()));
|
||||||
|
|
||||||
aCloseMostRecentZoneView = new QAction(this);
|
aCloseMostRecentZoneView = new QAction(this);
|
||||||
aCloseMostRecentZoneView->setShortcut(tr("Esc"));
|
aCloseMostRecentZoneView->setShortcut(tr("Esc"));
|
||||||
connect(aCloseMostRecentZoneView, SIGNAL(triggered()), scene, SLOT(closeMostRecentZoneView()));
|
connect(aCloseMostRecentZoneView, SIGNAL(triggered()), scene, SLOT(closeMostRecentZoneView()));
|
||||||
|
@ -35,3 +39,25 @@ void GameView::updateSceneRect(const QRectF &rect)
|
||||||
qDebug(QString("updateSceneRect = %1,%2").arg(rect.width()).arg(rect.height()).toLatin1());
|
qDebug(QString("updateSceneRect = %1,%2").arg(rect.width()).arg(rect.height()).toLatin1());
|
||||||
fitInView(rect, Qt::KeepAspectRatio);
|
fitInView(rect, Qt::KeepAspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameView::startRubberBand(const QPointF &_selectionOrigin)
|
||||||
|
{
|
||||||
|
selectionOrigin = _selectionOrigin;
|
||||||
|
rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
|
||||||
|
rubberBand->setGeometry(QRect(mapFromScene(selectionOrigin), QSize(0, 0)));
|
||||||
|
rubberBand->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameView::resizeRubberBand(const QPointF &cursorPoint)
|
||||||
|
{
|
||||||
|
if (rubberBand)
|
||||||
|
rubberBand->setGeometry(QRect(mapFromScene(selectionOrigin), mapFromScene(cursorPoint)).normalized());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameView::stopRubberBand()
|
||||||
|
{
|
||||||
|
if (rubberBand) {
|
||||||
|
rubberBand->deleteLater();
|
||||||
|
rubberBand = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,12 +3,20 @@
|
||||||
|
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
|
|
||||||
|
class QRubberBand;
|
||||||
|
|
||||||
class GameView : public QGraphicsView {
|
class GameView : public QGraphicsView {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QAction *aCloseMostRecentZoneView;
|
QAction *aCloseMostRecentZoneView;
|
||||||
|
QRubberBand *rubberBand;
|
||||||
|
QPointF selectionOrigin;
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *event);
|
void resizeEvent(QResizeEvent *event);
|
||||||
|
private slots:
|
||||||
|
void startRubberBand(const QPointF &selectionOrigin);
|
||||||
|
void resizeRubberBand(const QPointF &cursorPoint);
|
||||||
|
void stopRubberBand();
|
||||||
public slots:
|
public slots:
|
||||||
void updateSceneRect(const QRectF &rect);
|
void updateSceneRect(const QRectF &rect);
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
|
|
||||||
HandZone::HandZone(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent)
|
HandZone::HandZone(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent)
|
||||||
: CardZone(_p, "hand", false, false, _contentsKnown, parent), zoneHeight(_zoneHeight)
|
: SelectZone(_p, "hand", false, false, _contentsKnown, parent), zoneHeight(_zoneHeight)
|
||||||
{
|
{
|
||||||
connect(settingsCache, SIGNAL(handBgPathChanged()), this, SLOT(updateBgPixmap()));
|
connect(settingsCache, SIGNAL(handBgPathChanged()), this, SLOT(updateBgPixmap()));
|
||||||
updateBgPixmap();
|
updateBgPixmap();
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#ifndef HANDZONE_H
|
#ifndef HANDZONE_H
|
||||||
#define HANDZONE_H
|
#define HANDZONE_H
|
||||||
|
|
||||||
#include "cardzone.h"
|
#include "selectzone.h"
|
||||||
|
|
||||||
class HandZone : public CardZone {
|
class HandZone : public SelectZone {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
qreal width, zoneHeight;
|
qreal width, zoneHeight;
|
||||||
|
|
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();
|
||||||
|
}
|
||||||
|
|
18
cockatrice/src/selectzone.h
Normal file
18
cockatrice/src/selectzone.h
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef SELECTZONE_H
|
||||||
|
#define SELECTZONE_H
|
||||||
|
|
||||||
|
#include "cardzone.h"
|
||||||
|
|
||||||
|
class SelectZone : public CardZone {
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
QPointF selectionOrigin;
|
||||||
|
protected:
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
public:
|
||||||
|
SelectZone(Player *_player, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent = 0, bool isView = false);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -7,7 +7,7 @@
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
|
|
||||||
StackZone::StackZone(Player *_p, int _zoneHeight, QGraphicsItem *parent)
|
StackZone::StackZone(Player *_p, int _zoneHeight, QGraphicsItem *parent)
|
||||||
: CardZone(_p, "stack", false, false, true, parent), zoneHeight(_zoneHeight)
|
: SelectZone(_p, "stack", false, false, true, parent), zoneHeight(_zoneHeight)
|
||||||
{
|
{
|
||||||
connect(settingsCache, SIGNAL(stackBgPathChanged()), this, SLOT(updateBgPixmap()));
|
connect(settingsCache, SIGNAL(stackBgPathChanged()), this, SLOT(updateBgPixmap()));
|
||||||
updateBgPixmap();
|
updateBgPixmap();
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#ifndef STACKZONE_H
|
#ifndef STACKZONE_H
|
||||||
#define STACKZONE_H
|
#define STACKZONE_H
|
||||||
|
|
||||||
#include "cardzone.h"
|
#include "selectzone.h"
|
||||||
|
|
||||||
class StackZone : public CardZone {
|
class StackZone : public SelectZone {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
qreal zoneHeight;
|
qreal zoneHeight;
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include "arrowitem.h"
|
#include "arrowitem.h"
|
||||||
|
|
||||||
TableZone::TableZone(Player *_p, QGraphicsItem *parent)
|
TableZone::TableZone(Player *_p, QGraphicsItem *parent)
|
||||||
: CardZone(_p, "table", true, false, true, parent), active(false)
|
: SelectZone(_p, "table", true, false, true, parent), active(false)
|
||||||
{
|
{
|
||||||
connect(settingsCache, SIGNAL(tableBgPathChanged()), this, SLOT(updateBgPixmap()));
|
connect(settingsCache, SIGNAL(tableBgPathChanged()), this, SLOT(updateBgPixmap()));
|
||||||
connect(settingsCache, SIGNAL(economicalGridChanged()), this, SLOT(reorganizeCards()));
|
connect(settingsCache, SIGNAL(economicalGridChanged()), this, SLOT(reorganizeCards()));
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#ifndef TABLEZONE_H
|
#ifndef TABLEZONE_H
|
||||||
#define TABLEZONE_H
|
#define TABLEZONE_H
|
||||||
|
|
||||||
#include "cardzone.h"
|
#include "selectzone.h"
|
||||||
|
|
||||||
class TableZone : public CardZone {
|
class TableZone : public SelectZone {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
void sizeChanged();
|
void sizeChanged();
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
|
|
||||||
ZoneViewZone::ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards, QGraphicsItem *parent)
|
ZoneViewZone::ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards, QGraphicsItem *parent)
|
||||||
: CardZone(_p, _origZone->getName(), false, false, true, parent, true), bRect(QRectF()), minRows(0), numberCards(_numberCards), origZone(_origZone), sortByName(false), sortByType(false)
|
: SelectZone(_p, _origZone->getName(), false, false, true, parent, true), bRect(QRectF()), minRows(0), numberCards(_numberCards), origZone(_origZone), sortByName(false), sortByType(false)
|
||||||
{
|
{
|
||||||
origZone->setView(this);
|
origZone->setView(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
#ifndef ZONEVIEWERZONE_H
|
#ifndef ZONEVIEWERZONE_H
|
||||||
#define ZONEVIEWERZONE_H
|
#define ZONEVIEWERZONE_H
|
||||||
|
|
||||||
#include "cardzone.h"
|
#include "selectzone.h"
|
||||||
#include <QGraphicsLayoutItem>
|
#include <QGraphicsLayoutItem>
|
||||||
|
|
||||||
class ZoneViewWidget;
|
class ZoneViewWidget;
|
||||||
class ProtocolResponse;
|
class ProtocolResponse;
|
||||||
class ServerInfo_Card;
|
class ServerInfo_Card;
|
||||||
|
|
||||||
class ZoneViewZone : public CardZone, public QGraphicsLayoutItem {
|
class ZoneViewZone : public SelectZone, public QGraphicsLayoutItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QRectF bRect, optimumRect;
|
QRectF bRect, optimumRect;
|
||||||
|
|
Loading…
Reference in a new issue