|
Cute Chess
0.1
|
A graphical representation of a chess piece. More...
#include <graphicspiece.h>
Public Types | |
| enum | { Type = UserType + 4 } |
Public Slots | |
| void | restoreParent () |
Public Member Functions | |
| virtual QRectF | boundingRect () const |
| QGraphicsItem * | container () 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 |
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.
| anonymous enum |
The type value returned by type().
| 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.
| 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.
| Chess::Piece GraphicsPiece::pieceType | ( | ) | const |
Returns the type of the chess piece.
|
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.
| void GraphicsPiece::setContainer | ( | QGraphicsItem * | item | ) |
Sets the container to item.
1.8.11