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