Cute Chess 0.1
graphicspiecereserve.h
1/*
2 This file is part of Cute Chess.
3 Copyright (C) 2008-2018 Cute Chess authors
4
5 Cute Chess is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 Cute Chess is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Cute Chess. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#ifndef GRAPHICSPIECERESERVE_H
20#define GRAPHICSPIECERESERVE_H
21
22#include <QGraphicsItem>
23#include <QMultiMap>
24#include <board/piece.h>
25class GraphicsPiece;
26
27
36{
37 public:
39 enum { Type = UserType + 3 };
40
48 explicit GraphicsPieceReserve(qreal squareSize,
49 QGraphicsItem* parent = nullptr);
50
51 // Inherited from QGraphicsItem
52 virtual int type() const;
53 virtual QRectF boundingRect() const;
54 virtual void paint(QPainter* painter,
55 const QStyleOptionGraphicsItem* option,
56 QWidget* widget = nullptr);
57
59 int pieceCount(const Chess::Piece& piece) const;
75
76 private:
77 QPointF piecePos(Chess::Side side, int index) const;
78 QRectF textRect(Chess::Side side, int index) const;
79 QRectF textRect(const Chess::Piece& piece) const;
80 void updateTiles();
82
83 qreal m_tileWidth;
84 qreal m_tileHeight;
85 QRectF m_rect;
86 PieceMap m_pieces;
87 int m_rowCount;
88 QList<Chess::Piece> m_tiles[2];
89};
90
91#endif // GRAPHICSPIECERESERVE_H
A chess piece.
Definition piece.h:41
The side or color of a chess player.
Definition side.h:36
GraphicsPiece * piece(const Chess::Piece &piece) const
Definition graphicspiecereserve.cpp:83
GraphicsPieceReserve(qreal squareSize, QGraphicsItem *parent=nullptr)
Definition graphicspiecereserve.cpp:24
void addPiece(GraphicsPiece *piece)
Definition graphicspiecereserve.cpp:115
GraphicsPiece * takePiece(const Chess::Piece &piece)
Definition graphicspiecereserve.cpp:88
int pieceCount(const Chess::Piece &piece) const
Definition graphicspiecereserve.cpp:78
A graphical representation of a chess piece.
Definition graphicspiece.h:38