Cute Chess 0.1
GraphicsPiece Class Reference

A graphical representation of a chess piece. More...

#include <graphicspiece.h>

Inheritance diagram for GraphicsPiece:

Public Types

enum  { Type = UserType + 4 }

Public Slots

void restoreParent ()

Public Member Functions

virtual QRectF boundingRect () const
QGraphicsItemcontainer () const
 GraphicsPiece (const Chess::Piece &piece, qreal squareSize, const QString &elementId, QSvgRenderer *renderer, QGraphicsItem *parent=nullptr)
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr)
Chess::Piece pieceType () const
void setContainer (QGraphicsItem *item)
virtual int type () const

Detailed Description

A graphical representation of a chess piece.

A GraphicsPiece object is a chess piece that can be easily dragged and animated in a QGraphicsScene. Scalable Vector Graphics (SVG) are used to ensure that the pieces look good at any resolution, and a shared SVG renderer is used.

For convenience reasons the boundingRect() of a piece should be equal to that of a square on the chessboard.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

The type value returned by type().

Constructor & Destructor Documentation

◆ GraphicsPiece()

GraphicsPiece::GraphicsPiece ( const Chess::Piece & piece,
qreal squareSize,
const QString & elementId,
QSvgRenderer * renderer,
QGraphicsItem * parent = nullptr )

Creates a new GraphicsPiece object of type piece.

The painted image is scaled to fit inside a square that is squareSize wide and high. elementId is the XML ID of the piece picture which is rendered by renderer.

Member Function Documentation

◆ container()

QGraphicsItem * GraphicsPiece::container ( ) const

Returns the container of the piece.

Usually the container is the chessboard or the piece reserve. A piece can have a container even if it doesn't have a parent item.

◆ pieceType()

Chess::Piece GraphicsPiece::pieceType ( ) const

Returns the type of the chess piece.

◆ restoreParent

void GraphicsPiece::restoreParent ( )
slot

Restores the parent item (container).

If the piece doesn't have a parent item but does have a container, this function sets the parent item to the container. Usually this function is called after an animation or drag operation that had cleared the parent item to make the piece a top-level item.

◆ setContainer()

void GraphicsPiece::setContainer ( QGraphicsItem * item)

Sets the container to item.


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