Cute Chess 0.1
boardscene.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 BOARDSCENE_H
20#define BOARDSCENE_H
21
22#include <QGraphicsScene>
23#include <QMultiMap>
24#include <QPointer>
25#include <board/square.h>
26#include <board/genericmove.h>
27#include <board/boardtransition.h>
28#include <board/result.h>
29namespace Chess
30{
31 class Board;
32 class Move;
33 class Side;
34 class Piece;
35}
36class ChessGame;
37class QSvgRenderer;
38class QAbstractAnimation;
39class QPropertyAnimation;
40class GraphicsBoard;
42class GraphicsPiece;
43class PieceChooser;
44
45
58{
59 Q_OBJECT
60
61 public:
63 explicit BoardScene(QObject* parent = nullptr);
65 virtual ~BoardScene();
66
68 Chess::Board* board() const;
76
77 public slots:
86 void populate();
88 void setFenString(const QString& fenString);
90 void makeMove(const Chess::Move& move);
92 void makeMove(const Chess::GenericMove& move);
94 void undoMove();
96 void flip();
101 void onGameFinished(ChessGame* game, Chess::Result result);
102
103 signals:
111 const Chess::Side& side);
112
113 protected:
114 // Inherited from QGraphicsScene
115 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
116 virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
117 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
118
119 private slots:
120 void onTransitionFinished();
121 void onPromotionChosen(const Chess::Piece& promotion);
122
123 private:
124 void cancelUserMove();
125
126 enum MoveDirection
127 {
128 Forward,
129 Backward
130 };
131
132 QPointF squarePos(const Chess::Square& square) const;
133 GraphicsPiece* pieceAt(const QPointF& pos) const;
134 GraphicsPiece* createPiece(const Chess::Piece& piece);
135 QPropertyAnimation* pieceAnimation(GraphicsPiece* piece,
136 const QPointF& endPoint) const;
137 void stopAnimation();
138 void tryMove(GraphicsPiece* piece, const QPointF& targetPos);
139 void selectPiece(const QList<Chess::Piece>& types,
140 const char* member);
141 void addMoveArrow(const QPointF& sourcePos,
142 const QPointF& targetPos);
143 void applyTransition(const Chess::BoardTransition& transition,
144 MoveDirection direction);
145 void updateMoves();
146
147 Chess::Board* m_board;
148 MoveDirection m_direction;
149 Chess::BoardTransition m_transition;
151 QPointF m_sourcePos;
152 GraphicsBoard* m_squares;
153 GraphicsPieceReserve* m_reserve;
154 QPointer<PieceChooser> m_chooser;
155 QPointer<QAbstractAnimation> m_anim;
156 QSvgRenderer* m_renderer;
159 Chess::GenericMove m_promotionMove;
160 GraphicsPiece* m_highlightPiece;
161 QGraphicsItemGroup* m_moveArrows;
162};
163
164#endif // BOARDSCENE_H
void flip()
Definition boardscene.cpp:193
void setBoard(Chess::Board *board)
Definition boardscene.cpp:66
virtual ~BoardScene()
Definition boardscene.cpp:55
void populate()
Definition boardscene.cpp:83
void makeMove(const Chess::Move &move)
Definition boardscene.cpp:145
void humanMove(const Chess::GenericMove &move, const Chess::Side &side)
Chess::Board * board() const
Definition boardscene.cpp:61
void onGameFinished(ChessGame *game, Chess::Result result)
Definition boardscene.cpp:357
void setFenString(const QString &fenString)
Definition boardscene.cpp:135
BoardScene(QObject *parent=nullptr)
Definition boardscene.cpp:41
void undoMove()
Definition boardscene.cpp:166
Definition chessgame.h:39
Details of a board transition caused by a move.
Definition boardtransition.h:41
An internal chessboard class.
Definition board.h:58
A chess move independent of chess variant or opening book format.
Definition genericmove.h:35
A small and efficient chessmove class.
Definition move.h:43
A chess piece.
Definition piece.h:41
The result of a chess game.
Definition result.h:35
The side or color of a chess player.
Definition side.h:36
A generic chess square type consisting of a file and a rank.
Definition square.h:34
A graphical chessboard.
Definition graphicsboard.h:39
A graphical reserve for captured chess pieces.
Definition graphicspiecereserve.h:36
A graphical representation of a chess piece.
Definition graphicspiece.h:38
A light-weight QGraphicsObject dialog for selecting a chess piece.
Definition piecechooser.h:36