Cute Chess 0.1
graphicsboard.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 GRAPHICSBOARD_H
20#define GRAPHICSBOARD_H
21
22#include <QGraphicsItem>
23#include <QColor>
24#include <QVector>
25#include <board/square.h>
26#include <board/piece.h>
27class GraphicsPiece;
28class QPropertyAnimation;
29
30
39{
40 public:
42 enum { Type = UserType + 1 };
43
51 explicit GraphicsBoard(int files,
52 int ranks,
53 qreal squareSize,
54 QGraphicsItem* parent = nullptr);
56 virtual ~GraphicsBoard();
57
58 // Inherited from QGraphicsItem
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
71 Chess::Square squareAt(const QPointF& point) const;
78 QPointF squarePos(const Chess::Square& square) const;
85 Chess::Piece pieceTypeAt(const Chess::Square& square) const;
92 GraphicsPiece* pieceAt(const Chess::Square& square) const;
100
102 void clearSquares();
109 void setSquare(const Chess::Square& square, GraphicsPiece* piece);
115 void movePiece(const Chess::Square& source,
116 const Chess::Square& target);
117
119 void clearHighlights();
126 void setHighlights(const QList<Chess::Square>& squares);
127
132 bool isFlipped() const;
133
135 void setFlipped(bool flipped);
136
137 private:
138 int squareIndex(const Chess::Square& square) const;
139
140 int m_files;
141 int m_ranks;
142 qreal m_squareSize;
143 qreal m_coordSize;
144 QRectF m_rect;
145 QColor m_lightColor;
146 QColor m_darkColor;
147 QColor m_textColor;
148 QVector<GraphicsPiece*> m_squares;
149 QPropertyAnimation* m_highlightAnim;
150 bool m_flipped;
151};
152
153#endif // GRAPHICSBOARD_H
A chess piece.
Definition piece.h:41
A generic chess square type consisting of a file and a rank.
Definition square.h:34
bool isFlipped() const
Definition graphicsboard.cpp:312
Chess::Piece pieceTypeAt(const Chess::Square &square) const
Definition graphicsboard.cpp:191
void clearHighlights()
Definition graphicsboard.cpp:268
virtual ~GraphicsBoard()
Definition graphicsboard.cpp:78
void setSquare(const Chess::Square &square, GraphicsPiece *piece)
Definition graphicsboard.cpp:232
QPointF squarePos(const Chess::Square &square) const
Definition graphicsboard.cpp:169
void setFlipped(bool flipped)
Definition graphicsboard.cpp:317
GraphicsPiece * pieceAt(const Chess::Square &square) const
Definition graphicsboard.cpp:199
void clearSquares()
Definition graphicsboard.cpp:226
void movePiece(const Chess::Square &source, const Chess::Square &target)
Definition graphicsboard.cpp:250
void setHighlights(const QList< Chess::Square > &squares)
Definition graphicsboard.cpp:278
Chess::Square squareAt(const QPointF &point) const
Definition graphicsboard.cpp:156
GraphicsBoard(int files, int ranks, qreal squareSize, QGraphicsItem *parent=nullptr)
Definition graphicsboard.cpp:53
GraphicsPiece * takePieceAt(const Chess::Square &square)
Definition graphicsboard.cpp:209
A graphical representation of a chess piece.
Definition graphicspiece.h:38