#ifndef PQPIXMAP_H
#define PQPIXMAP_H

#include <QPixmap>
#include <pqobject.h>

class PQPixmap;
class PQPixmap : public PQObject, public QPixmap
{
    Q_OBJECT
    PQ_OBJECT_EX(QPixmap)

    Q_PROPERTY(int width READ width)
    Q_PROPERTY(int height READ height)
    Q_PROPERTY(QSize size READ size)
    Q_PROPERTY(QRect rect READ rect)
    Q_PROPERTY(bool hasAlpha READ hasAlpha)
    Q_PROPERTY(bool hasAlphaChannel READ hasAlphaChannel)

public:
    Q_INVOKABLE explicit PQPixmap();
    Q_INVOKABLE explicit PQPixmap(int width, int height);
    Q_INVOKABLE explicit PQPixmap(const QSize &size);
    Q_INVOKABLE explicit PQPixmap(const QString &fileName,
                                  const char *format = Q_NULLPTR,
                                  int flags = Qt::AutoColor);
    Q_INVOKABLE explicit PQPixmap(const char * const xpm[]);
    Q_INVOKABLE explicit PQPixmap(PQPixmap *pixmap);
    Q_INVOKABLE explicit PQPixmap(const QPixmap &pixmap);
    ~PQPixmap();

    Q_INVOKABLE bool isNull() const;

    Q_INVOKABLE int width() const;
    Q_INVOKABLE int height() const;
    Q_INVOKABLE QSize size() const;
    Q_INVOKABLE QRect rect() const;
    Q_INVOKABLE int depth() const;

    Q_INVOKABLE void fill(const QString &fillColor = "Qt::white");

    Q_INVOKABLE double devicePixelRatio() const;
    Q_INVOKABLE void setDevicePixelRatio(double scaleFactor);

    Q_INVOKABLE bool hasAlpha() const;
    Q_INVOKABLE bool hasAlphaChannel() const;

    Q_INVOKABLE PQPixmap *grabWindow(int id, int x=0, int y=0, int w=-1, int h=-1);
    Q_INVOKABLE PQPixmap *grabWidget(QObject *widget, int x=0, int y=0, int w=-1, int h=-1);
    Q_INVOKABLE PQPixmap *scaled(int w, int h, int aspectMode = Qt::IgnoreAspectRatio,
                    int mode = Qt::FastTransformation) const;
    Q_INVOKABLE PQPixmap *scaledToWidth(int w, int mode = Qt::FastTransformation) const;
    Q_INVOKABLE PQPixmap *scaledToHeight(int h, int mode = Qt::FastTransformation) const;
    Q_INVOKABLE PQPixmap *rotated(double angle, int axis = Qt::ZAxis, int mode = Qt::FastTransformation) const;
    Q_INVOKABLE PQPixmap *rotatedRadians(double angle, int axis = Qt::ZAxis, int mode = Qt::FastTransformation) const;
    Q_INVOKABLE PQPixmap *translated(double dx, double dy, int mode = Qt::FastTransformation) const;

    Q_INVOKABLE bool load(const QString& fileName, const QByteArray &format = QByteArray(), int flags = Qt::AutoColor);
    Q_INVOKABLE bool loadFromData(const QByteArray &data, const QByteArray &format = QByteArray(), int flags = Qt::AutoColor);
    Q_INVOKABLE bool save(const QString& fileName, const QByteArray &format = QByteArray(), int quality = -1) const;

    Q_INVOKABLE PQPixmap *copy(int x, int y, int width, int height) const;

    Q_INVOKABLE void scroll(int dx, int dy, int x, int y, int width, int height);

    Q_INVOKABLE bool isDetached() const;
    Q_INVOKABLE void detach();

    Q_INVOKABLE QPaintEngine *paintEngine() const Q_DECL_OVERRIDE;
    Q_INVOKABLE QPlatformPixmap *handle() const;
    Q_INVOKABLE DataPtr &data_ptr();
};

Q_DECLARE_METATYPE(QPixmap*)
Q_DECLARE_METATYPE(PQPixmap*)

#endif // PQPIXMAP_H
