mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 02:53:25 -08:00
* [Game] Raise rubber band above count label and collapse multi-selection on click Raise rubber band on start and collapse multi-selection to clicked card when left-clicking an already-selected card with no modifiers. * [Game] Collapse multi-selection on release instead of press Collapsing at press time dropped the selection before the drag started, which broke dragging multiple cards. Keep the selection on press and collapse it on release when the pointer stayed within the drag distance. * [Game] Defer selection collapse until the double-click window passes A release without drag collapsed the multi-selection immediately, so a double-click that followed (playSelected acts on scene()->selectedItems()) only ever saw the single clicked card. When the card handles double-clicks on the selection, arm the collapse on a single-shot timer for QApplication::doubleClickInterval() instead and cancel it from the double-click handler; a new press disarms the other cards and a selection-count guard covers rubber-band/ctrl changes meanwhile. * [Game] Keep sideboard multi-selection on double-click DeckViewCard overrides doubleClickActsOnSelection to preserve the selection, restoring master behavior where double-clicking moves all selected cards between main and side. DeckView cancels any pending collapse before reading the selection. * [Game] Remove duplicated inline selection-collapse declarations * [Game] Fix DeckView collapse call visibility and multi-selection collapse Make cancelPendingSelectionCollapse() public so DeckView can call it on selected DeckViewCards. Always arm the deferred collapse on release instead of skipping cards whose double-click acts on the selection; the double-click-interval timer plus the cancel calls in CardItem::mouseDoubleClickEvent and DeckView::mouseDoubleClickEvent already preserve the selection for double-clicks. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
187 lines
4.8 KiB
C++
187 lines
4.8 KiB
C++
/**
|
|
* @file deck_view.h
|
|
* @ingroup Lobby
|
|
*/
|
|
//! \todo Document this file.
|
|
|
|
#ifndef DECKVIEW_H
|
|
#define DECKVIEW_H
|
|
|
|
#include "../board/abstract_card_drag_item.h"
|
|
#include "../board/abstract_card_item.h"
|
|
#include "../board/graphics_item_type.h"
|
|
|
|
#include <QGraphicsItem>
|
|
#include <QGraphicsScene>
|
|
#include <QGraphicsView>
|
|
#include <QList>
|
|
#include <QMap>
|
|
#include <QMultiMap>
|
|
#include <QPair>
|
|
#include <QPointF>
|
|
#include <QRectF>
|
|
#include <QSizeF>
|
|
#include <QString>
|
|
#include <QtGlobal>
|
|
#include <libcockatrice/protocol/pb/move_card_to_zone.pb.h>
|
|
#include <qtmetamacros.h>
|
|
|
|
class DeckList;
|
|
class DeckViewCardContainer;
|
|
class DeckViewCardDragItem;
|
|
class QObject;
|
|
class QWidget;
|
|
struct CardRef;
|
|
|
|
class DeckViewCard : public AbstractCardItem
|
|
{
|
|
private:
|
|
QString originZone;
|
|
DeckViewCardDragItem *dragItem;
|
|
|
|
public:
|
|
explicit DeckViewCard(QGraphicsItem *parent = nullptr,
|
|
const CardRef &cardRef = {},
|
|
const QString &_originZone = QString());
|
|
~DeckViewCard() override;
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
|
[[nodiscard]] const QString &getOriginZone() const
|
|
{
|
|
return originZone;
|
|
}
|
|
bool doubleClickActsOnSelection() const override
|
|
{
|
|
return true;
|
|
}
|
|
|
|
protected:
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
|
};
|
|
|
|
class DeckViewCardDragItem : public AbstractCardDragItem
|
|
{
|
|
private:
|
|
DeckViewCardContainer *currentZone;
|
|
void handleDrop(DeckViewCardContainer *target);
|
|
|
|
public:
|
|
DeckViewCardDragItem(DeckViewCard *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag = 0);
|
|
void updatePosition(const QPointF &cursorScenePos) override;
|
|
|
|
protected:
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
|
};
|
|
|
|
class DeckViewCardContainer : public QGraphicsItem
|
|
{
|
|
private:
|
|
static const int separatorY = 20;
|
|
static const int paddingY = 10;
|
|
static bool sortCardsByName(DeckViewCard *c1, DeckViewCard *c2);
|
|
|
|
QString name;
|
|
QList<DeckViewCard *> cards;
|
|
QMultiMap<QString, DeckViewCard *> cardsByType;
|
|
QList<QPair<int, int>> currentRowsAndCols;
|
|
qreal width, height;
|
|
[[nodiscard]] int getCardTypeTextWidth() const;
|
|
|
|
public:
|
|
enum
|
|
{
|
|
Type = typeDeckViewCardContainer
|
|
};
|
|
[[nodiscard]] int type() const override
|
|
{
|
|
return Type;
|
|
}
|
|
explicit DeckViewCardContainer(const QString &_name);
|
|
[[nodiscard]] QRectF boundingRect() const override;
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
|
void addCard(DeckViewCard *card);
|
|
void removeCard(DeckViewCard *card);
|
|
[[nodiscard]] const QList<DeckViewCard *> &getCards() const
|
|
{
|
|
return cards;
|
|
}
|
|
[[nodiscard]] const QString &getName() const
|
|
{
|
|
return name;
|
|
}
|
|
void setWidth(qreal _width);
|
|
|
|
[[nodiscard]] QList<QPair<int, int>> getRowsAndCols() const;
|
|
[[nodiscard]] QSizeF calculateBoundingRect(const QList<QPair<int, int>> &rowsAndCols) const;
|
|
void rearrangeItems(const QList<QPair<int, int>> &rowsAndCols);
|
|
};
|
|
|
|
class DeckViewScene : public QGraphicsScene
|
|
{
|
|
Q_OBJECT
|
|
signals:
|
|
void newCardAdded(AbstractCardItem *card);
|
|
void sideboardPlanChanged();
|
|
|
|
private:
|
|
bool locked;
|
|
DeckList *deck;
|
|
QMap<QString, DeckViewCardContainer *> cardContainers;
|
|
qreal optimalAspectRatio;
|
|
void rebuildTree();
|
|
|
|
public:
|
|
explicit DeckViewScene(QObject *parent = nullptr);
|
|
~DeckViewScene() override;
|
|
void setLocked(bool _locked)
|
|
{
|
|
locked = _locked;
|
|
}
|
|
[[nodiscard]] bool getLocked() const
|
|
{
|
|
return locked;
|
|
}
|
|
void clearContents();
|
|
void setDeck(const DeckList &_deck);
|
|
void setOptimalAspectRatio(qreal _optimalAspectRatio)
|
|
{
|
|
optimalAspectRatio = _optimalAspectRatio;
|
|
}
|
|
void rearrangeItems();
|
|
void updateContents();
|
|
[[nodiscard]] QList<MoveCard_ToZone> getSideboardPlan() const;
|
|
void resetSideboardPlan();
|
|
void applySideboardPlan(const QList<MoveCard_ToZone> &plan);
|
|
};
|
|
|
|
class DeckView : public QGraphicsView
|
|
{
|
|
Q_OBJECT
|
|
private:
|
|
DeckViewScene *deckViewScene;
|
|
|
|
protected:
|
|
void resizeEvent(QResizeEvent *event) override;
|
|
public slots:
|
|
void updateSceneRect(const QRectF &rect);
|
|
signals:
|
|
void newCardAdded(AbstractCardItem *card);
|
|
void sideboardPlanChanged();
|
|
|
|
public:
|
|
explicit DeckView(QWidget *parent = nullptr);
|
|
void setDeck(const DeckList &_deck);
|
|
void clearDeck();
|
|
void setLocked(bool _locked)
|
|
{
|
|
deckViewScene->setLocked(_locked);
|
|
}
|
|
[[nodiscard]] QList<MoveCard_ToZone> getSideboardPlan() const
|
|
{
|
|
return deckViewScene->getSideboardPlan();
|
|
}
|
|
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
|
void resetSideboardPlan();
|
|
};
|
|
|
|
#endif
|