Now that we can see the board, it is time to put the pieces on it. We are going to use images for that purpose. In my case, we found a number of SVG files with chess pieces and decided to use them. SVG is a vector graphics format where all curves are defined not as a fixed set of points but rather as mathematic curves. Their main benefit is that they scale very well without causing an aliasing effect.
Let's equip our view with a registry of images to be used for "stamping" a particular piece type. Since each piece type is identified with char, we can use it to generate keys for a map of images. Let's put the following API into ChessView
:
public: void setPiece(char type, const QIcon &icon); QIcon piece(char type) const; private: QMap<char,QIcon> m_pieces;
For the image type, we do not use QImage
or QPixmap
but rather QIcon
. This is because QIcon
can store many pixmaps of different sizes and use the most appropriate one when we request an...