File indexing completed on 2024-05-05 04:05:48

0001 /*
0002     SPDX-FileCopyrightText: 2009 Stefan Majewsky <majewsky@gmx.net>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef LIBPALA_SLICERJOB_H
0008 #define LIBPALA_SLICERJOB_H
0009 
0010 #include "libpala_export.h"
0011 
0012 #include <QMap>
0013 #include <QPoint>
0014 #include <QVariant>
0015 #include <QImage>
0016 
0017 #include <memory>
0018 
0019 namespace Pala
0020 {
0021     class Slicer;
0022     class SlicerMode;
0023 
0024     /**
0025      * \class SlicerJob slicerjob.h <Pala/SlicerJob>
0026      * \brief Representation of a single run of a slicing algorithm.
0027      *
0028      * This class holds everything that concerns a single slicing job: It starts out with the image and the arguments (i.e., the values that the user has chosen for the properties defined by the slicing algorithm). The Pala::Slicer::run method should then use this information to slice the image into pieces and define neighborship relations between them.
0029      *
0030      * \sa Pala::Slicer::run
0031      */
0032     class LIBPALA_EXPORT SlicerJob
0033     {
0034         public:
0035             ///Creates a new slicer job.
0036             explicit SlicerJob(const QImage& image, const QMap<QByteArray, QVariant>& args);
0037             ///Deletes this slicer job.
0038             virtual ~SlicerJob();
0039 
0040             ///Returns an argument of this job, i.e. the value that the user has chosen for the slicing algorithm's property with the given \a key.
0041             QVariant argument(const QByteArray& key) const;
0042             ///Returns the image that should be sliced.
0043             QImage image() const;
0044             ///Returns the selected slicer mode, or 0 if the slicer does not define any slicer modes.
0045             const Pala::SlicerMode* mode() const;
0046 
0047             //The following functions belong to the interface to the Palapeli application. They are not documented because the documentation is targeted at slicer developers.
0048             ///\internal
0049             QMap<int, QImage> pieces() const;
0050             ///\internal
0051             QMap<int, QPoint> pieceOffsets() const;
0052             ///\internal
0053             QList<QPair<int, int> > relations() const;
0054             ///\internal
0055             void setMode(const Pala::SlicerMode* mode);
0056 
0057             /**
0058              * \brief Add a generated piece to the result set of this slicing job.
0059              * The \a pieceID can later be used to refer to this piece in the addRelation() method. The given \a offset describes the position of the top-left edge of the given piece \a image in the complete image.
0060              *
0061              * \note It is good practice to make the piece image as small as possible, and use the offset to move it to the right position in the image's coordinates. Big images might result in bad performance, even if most of the images is fully transparent.
0062              * \warning You should not use negative piece IDs. These might be used internally.
0063              */
0064             void addPiece(int pieceID, const QImage& image, const QPoint& offset = QPoint());
0065             /**
0066              * \brief Generate a piece, and add it to the result set of this slicing job.
0067              * The \a pieceID can later be used to refer to this piece in the addRelation() method. The given \a offset describes the position of the top-left edge of the given mask in the complete image.
0068              *
0069              * \note It is good practice to make the mask as small as possible, and use the offset to move it to the right position in the image's coordinates. Big masks result in big piece images, which might in turn result in bad performance, even if most of the images is fully transparent.
0070              * \warning You should not use negative piece IDs. These might be used internally.
0071              */
0072             void addPieceFromMask(int pieceID, const QImage& mask, const QPoint& offset = QPoint());
0073             /**
0074              * \brief Define a neighborship relation between two pieces.
0075              * Neighborship relations are crucial for the gameplay: Palapeli needs to know somehow which pieces are neighbors, to let these pieces snap together when they're near each other.
0076              */
0077             void addRelation(int pieceID1, int pieceID2);
0078         protected:
0079             ///\internal
0080             void respectSlicerFlags(int flags);
0081             friend class Slicer;
0082         private:
0083             std::unique_ptr<class SlicerJobPrivate> const d_ptr;
0084             Q_DECLARE_PRIVATE(SlicerJob)
0085             Q_DISABLE_COPY(SlicerJob)
0086     };
0087 }
0088 
0089 #endif // LIBPALA_SLICERJOB_H