Logo Search packages:      
Sourcecode: palapeli version File versions  Download package

Palapeli::Pattern Class Reference

#include <Palapeli/Pattern>

Inheritance diagram for Palapeli::Pattern:

Palapeli::HexagonalPattern Palapeli::JigsawPattern Palapeli::RectangularPattern

List of all members.

Detailed Description

Slicing implementation in Palapeli pattern plugins.

This class is used in a Palapeli pattern plugin to provide the actual slicing implementation. Its configuration is generated by the Palapeli::PatternConfiguration subclass contained in the plugin.

To create your sub-class of Palapeli::Pattern, you will need to implement the doSlice function. This function can call the addPiece and addRelation functions to add pieces to the puzzle scene, and add neighbor relations between them. Use the mode function to find out what operation mode has been requested for the doSlice function. The following example illustrates a pattern which splits the base image into two equally sized parts:

class MyPattern : public Palapeli::Pattern {

//implement public constructor and public virtual destructor here

      virtual void doSlice(const QImage& image) {
            reportPieceCount(2); //the application has to know the piece count to display progress
            if (mode() == CreatePuzzle)
                  //construct images for the pieces
                  const int pieceWidth = image.width() / 2, pieceHeight = image.height();
                  QImage leftPiece = image.copy(QRect(0, 0, pieceWidth, pieceHeight));
                  QImage rightPiece = image.copy(QRect(pieceWidth, 0, pieceWidth, pieceHeight));
                  //add pieces; define a neighborship relation between them
                  addPiece(leftPiece, QRectF(0, 0, pieceWidth, pieceHeight));
                  addPiece(rightPiece, QRectF(pieceWidth, 0, pieceWidth, pieceHeight));
                  addRelation(0, 1); //0 and 1 are the consecutive indices of the pieces


Stefan Majewsky <majewsky@gmx.net>

Definition at line 74 of file pattern.h.

Public Types

enum  Mode { CreatePuzzle, SimulateCreation }
 Defines operation modes for this pattern. More...


void allPiecesGenerated ()
void pieceCountAvailable (int pieceCount)
void pieceGenerated (const QImage &image, const QImage &mask, const QRectF &positionInImage, const QPointF &sceneBasePosition)
void pieceGenerated (const QImage &image, const QRectF &positionInImage, const QPointF &sceneBasePosition)
void relationGenerated (int piece1Id, int piece2Id)

Public Member Functions

void loadPiecePositions (const QList< QPointF > &points)
Mode mode () const
 Pattern ()
 Constructs a new pattern object. This base constructor is currently unused; you should implement it to get configuration values from your Palapeli::PatternConfiguration object.
int pieceCount () const
void setMode (Mode mode)
void setSceneSizeFactor (qreal factor)
void slice (const QImage &image)
virtual ~Pattern ()

Protected Member Functions

void addPiece (const QImage &baseImage, const QImage &mask, const QRectF &positionInImage)
 Adds a piece to the puzzle scene.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This overload adds the possibility to pass a mask which will define a shape to be cut out from the given baseImage. This is useful because some environments seem to have problems with image composition in non-GUI threads.

void addPiece (const QImage &image, const QRectF &positionInImage)
 Adds a piece to the puzzle scene. Internally, the piece is assigned a consecutive index (0 for the first piece, 1 for the second piece, and so on) which has to be used when defining relations between the pieces.
void addRelation (int piece1Id, int piece2Id)
 Adds a neighbor relation between two pieces.
virtual void doSlice (const QImage &image)=0
 Provides the slicing algorithm. This function splits a given image into pieces and defines relations between them. These pieces and relations are used to build the puzzle.
void reportPieceCount (int pieceCount)
 Informs Palapeli about the number of pieces to expect. Call this from your slicing algorithm to inform Palapeli about the number of pieces to be expected. (This should, of course, be done before any pieces are added to the scene.) The Palapeli game engine will use this information to show a progress bar to the user.

Private Member Functions

QPointF generateNextBasePosition (const QRectF &positionInImage)

Private Attributes

PatternPrivate *const p

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

Generated by  Doxygen 1.6.0   Back to index