#ifndef CANVASITEM_FACTORY_H
#define CANVASITEM_FACTORY_H


#include <QObject>
#include <QColor>
#include <QRect>
#include <QString>
#include <QFontMetrics>
#include <QPixmapCache>
#include <QLabel>
#include <QDebug>
#include <QLineEdit>
#include "textitem.h"


class Canvas;


class CanvasItem : public QObject
{
    Q_OBJECT
    Q_PROPERTY(int layer READ layer_get WRITE layer_set)
    Q_PROPERTY(int x READ x_get WRITE x_set)
    Q_PROPERTY(int y READ y_get WRITE y_set)
    Q_PROPERTY(int w READ w_get WRITE w_set)
    Q_PROPERTY(int h READ h_get WRITE h_set)
    Q_PROPERTY(QString file READ file_get WRITE file_set)
    Q_PROPERTY(QString text READ text_get WRITE text_set)
    Q_PROPERTY(bool visible READ vis_get WRITE vis_set)
    Q_PROPERTY(QRect clip READ clip_get WRITE clip_set)
    Q_PROPERTY(bool deleted READ deleted_get WRITE deleted_set)
    Q_PROPERTY(QColor color READ color_get WRITE color_set)
    Q_PROPERTY(int descent READ descent_get)
    Q_PROPERTY(int horiz_advance READ horiz_advance_get)
    Q_PROPERTY(QFont font READ font_get WRITE font_set)
    Q_PROPERTY(QString fontFamily READ fontFamily_get WRITE fontFamily_set)
    Q_PROPERTY(int fontPixelSize READ fontPixelSize_get WRITE fontPixelSize_set)
public:
    CanvasItem(Canvas *parent, int x, int y, int w, int h);
    ~CanvasItem() { if (widget) delete widget; }
    void updateGeometry() { widget->setGeometry(x_get(),y_get(),w_get(),h_get()); }
    QRect clip_get() { return clip; }
    void clip_set(QRect l) { clip = l; }
    bool vis_get() { return visible; }
    void vis_set(bool l);
    QString text_get() { return text; }
    void text_set(QString l);
    QString file_get() { return file; }
    void file_set(QString l);
    int x_get() { return x; }
    void x_set(int l) { if(x==l) return; x = l; widget->move(x_get(),y_get()); } 
    int y_get() { return y; }
    void y_set(int l) { if(y==l) return; y = l; widget->move(x_get(),y_get()); }
    int w_get();
    void w_set(int l) { if(type==2) return; if(w==l) return; w = l; updateGeometry(); }
    int h_get();
    void h_set(int l) { if (type==2) return; if(h==l) return; h = l; updateGeometry(); }
    int layer_get() { return layer; }
    void layer_set(int l);
    bool deleted_get() { return deleted; }
    void deleted_set(bool v);
    QColor color_get() { return color; }
    void color_set(QColor col);
    int descent_get();
    void resize(int _w, int _h);
    void fill_set(int , int , int width, int height);
    int horiz_advance_get() { return w_get(); }
    QFont font_get() { return widget->font(); }
    void font_set(QFont f) { widget->setFont(f); }
    int fontPixelSize_get() { return font_get().pixelSize(); }
    void fontPixelSize_set(int s) { QFont f = font_get(); f.setPixelSize(s); font_set(f); }
    QString fontFamily_get() { return font_get().family(); }
    void fontFamily_set(QString fam) { QFont f = font_get(); f.setFamily(fam); font_set(f); }
    /* This code added to make wrapping any QWidget and adding it in to the python code very easy */
    void setCustomWidget(QWidget *custWid) { customWidget = custWid; }
public slots:
    virtual bool handleKey(QString key, bool down);
private:
    Canvas *parent;
    QWidget *parentWidget;
    QWidget *customWidget;
    int fillW, fillH;
    bool deleted;
    int horiz_advance;
    QFont font;
public:
    int type;
    QLabel *widget;
    int id;
    int layer;
    QString file;
    QColor color;
    bool visible;
    int x, y, w, h;
    QString text;
    QRect clip;
};


#endif // CANVASITEM_FACTORY_H

