/***************************************************************************
 *   Copyright 2007-2008 Wouter Haffmans <cheetah@simply-life.net>         *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU General Public License as        *
 *   published by the Free Software Foundation; either version 2 of        *
 *   the License or (at your option) version 3 or any later version        *
 *   accepted by the membership of KDE e.V. (or its successor approved     *
 *   by the membership of KDE e.V.), which shall act as a proxy            *
 *   defined in Section 14 of version 3 of the license.                    *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 ***************************************************************************/

#ifndef CANVASSCENE_H
#define CANVASSCENE_H

#include <QGraphicsScene>

class QPainter;
class QResizeEvent;

/**
 * Represents the scene for a KidDraw canvas/drawing. It offers specialized
 * options for the background.
 */
class CanvasScene : public QGraphicsScene
{
Q_OBJECT
    Q_PROPERTY(QPixmap backgroundTexture
        READ backgroundTexture
        WRITE setBackgroundTexture)
    Q_PROPERTY(QImage backgroundImage
        READ backgroundImage
        WRITE setBackgroundImage
        STORED false)
    Q_PROPERTY(BackgroundStyle backgroundStyle
        READ backgroundStyle
        WRITE setBackgroundStyle)

public:
    typedef enum {
        center      = 0x00,
        stretch     = 0x01,
        tile        = 0x02,
        topLeft     = 0x10,
        topRight    = 0x20,
        bottomLeft  = 0x40,
        bottomRight = 0x80
    } BackgroundStyle;

    CanvasScene(QObject *parent = 0);

    ~CanvasScene();

    static QString backgroundStyleToString(BackgroundStyle style);
    static BackgroundStyle backgroundStyleFromString(QString string);

    QPixmap backgroundTexture();
    QImage  backgroundImage();
    BackgroundStyle backgroundStyle();

public slots:
    void setBackgroundTexture(QPixmap texture);
    void setBackgroundImage(QImage image);
    void setBackgroundStyle(BackgroundStyle style);

protected:
    virtual void drawBackground(QPainter *painter, const QRectF &exposed);
    virtual void resizeEvent(QResizeEvent *event);

private:
    QColor  m_color;
    QPixmap m_texture;
    BackgroundStyle m_style;
};

#endif
