Cute Chess  0.1
Public Types | Public Member Functions | List of all members
GraphicsBoard Class Reference

A graphical chessboard. More...

#include <graphicsboard.h>

Inheritance diagram for GraphicsBoard:
QGraphicsItem

Public Types

enum  { Type = UserType + 1 }
 
- Public Types inherited from QGraphicsItem
enum  CacheMode
 
enum  Extension
 
enum  GraphicsItemFlag
 

Public Member Functions

virtual QRectF boundingRect () const
 
void clearHighlights ()
 
void clearSquares ()
 
 GraphicsBoard (int files, int ranks, qreal squareSize, QGraphicsItem *parent=nullptr)
 
bool isFlipped () const
 
void movePiece (const Chess::Square &source, const Chess::Square &target)
 
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr)
 
GraphicsPiecepieceAt (const Chess::Square &square) const
 
Chess::Piece pieceTypeAt (const Chess::Square &square) const
 
void setFlipped (bool flipped)
 
void setHighlights (const QList< Chess::Square > &squares)
 
void setSquare (const Chess::Square &square, GraphicsPiece *piece)
 
Chess::Square squareAt (const QPointF &point) const
 
QPointF squarePos (const Chess::Square &square) const
 
GraphicsPiecetakePieceAt (const Chess::Square &square)
 
virtual int type () const
 
virtual ~GraphicsBoard ()
 

Detailed Description

A graphical chessboard.

GraphicsBoard is a graphical representation of the squares on a chessboard. It also has ownership of the chess pieces on the board, ie. it is the pieces' parent item and container.

Member Enumeration Documentation

anonymous enum

The type value returned by type().

Constructor & Destructor Documentation

GraphicsBoard::GraphicsBoard ( int  files,
int  ranks,
qreal  squareSize,
QGraphicsItem parent = nullptr 
)
explicit

Creates a new GraphicsBoard object.

The board will have files files/columns and ranks ranks/rows, and the squares' width and height will be squareSize.

GraphicsBoard::~GraphicsBoard ( )
virtual

Destroys the GraphicsBoard object.

Member Function Documentation

void GraphicsBoard::clearHighlights ( )

Clears all highlights.

void GraphicsBoard::clearSquares ( )

Deletes all pieces and removes them from the scene.

bool GraphicsBoard::isFlipped ( ) const

Returns true if the board is flipped; otherwise returns false.

void GraphicsBoard::movePiece ( const Chess::Square source,
const Chess::Square target 
)

Moves the piece from source to target.

If target already contains a piece, it is deleted.

GraphicsPiece * GraphicsBoard::pieceAt ( const Chess::Square square) const

Returns the GraphicsPiece object at square.

Returns 0 if square is not on the board or if there's no piece placed on it.

Chess::Piece GraphicsBoard::pieceTypeAt ( const Chess::Square square) const

Returns the type of piece at square.

Returns a null piece if square is not on the board or if there's no piece placed on it.

void GraphicsBoard::setFlipped ( bool  flipped)

Sets board flipping to flipped.

void GraphicsBoard::setHighlights ( const QList< Chess::Square > &  squares)

Highlights squares.

This function clears all previous highlights and marks the squares in squares as possible target squares of a chess move.

void GraphicsBoard::setSquare ( const Chess::Square square,
GraphicsPiece piece 
)

Sets the piece at square to piece.

If square already contains a piece, it is deleted. If piece is 0, the square becomes empty.

Chess::Square GraphicsBoard::squareAt ( const QPointF point) const

Returns the chess square at point.

point is in item coordinates. Returns a null square if point is not on the board.

QPointF GraphicsBoard::squarePos ( const Chess::Square square) const

Returns the position of square.

The returned position is in item coordinates. Returns a null point if square is not on the board.

GraphicsPiece * GraphicsBoard::takePieceAt ( const Chess::Square square)

Removes the GraphicsPiece object at square and returns it.

Returns 0 if square is not on the board or if there's no piece placed on it.


The documentation for this class was generated from the following files: