Cute Chess  0.1
graphicspiece.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 GRAPHICSPIECE_H
19 #define GRAPHICSPIECE_H
20 
21 #include <QGraphicsObject>
22 #include <board/piece.h>
23 class QSvgRenderer;
24 
36 class GraphicsPiece : public QGraphicsObject
37 {
38  Q_OBJECT
39 
40  public:
42  enum { Type = UserType + 4 };
43 
52  GraphicsPiece(const Chess::Piece& piece,
53  qreal squareSize,
54  const QString& elementId,
55  QSvgRenderer* renderer,
56  QGraphicsItem* parent = nullptr);
57 
58  // Inherited from QGraphicsObject
59  virtual int type() const;
60  virtual QRectF boundingRect() const;
61  virtual void paint(QPainter* painter,
62  const QStyleOptionGraphicsItem* option,
63  QWidget* widget = nullptr);
64 
66  Chess::Piece pieceType() const;
74  QGraphicsItem* container() const;
76  void setContainer(QGraphicsItem* item);
77 
78  public slots:
87  void restoreParent();
88 
89  private:
90  Chess::Piece m_piece;
91  QRectF m_rect;
92  QString m_elementId;
93  QSvgRenderer* m_renderer;
94  QGraphicsItem* m_container;
95 };
96 
97 #endif // GRAPHICSPIECE_H
A graphical representation of a chess piece.
Definition: graphicspiece.h:36
GraphicsPiece(const Chess::Piece &piece, qreal squareSize, const QString &elementId, QSvgRenderer *renderer, QGraphicsItem *parent=nullptr)
Definition: graphicspiece.cpp:22
QGraphicsItem * container() const
Definition: graphicspiece.cpp:80
void setContainer(QGraphicsItem *item)
Definition: graphicspiece.cpp:85
A chess piece.
Definition: piece.h:39
void restoreParent()
Definition: graphicspiece.cpp:90
Chess::Piece pieceType() const
Definition: graphicspiece.cpp:75