#ifndef CANVAS_H
#define CANVAS_H


#include <QLabel>
#include <QPainter>
#include <QStringList>
#include <QPixmapCache>
#include <QTimer>
#include <QList>
#include "canvasitemfactory.h"


class Canvas : public QWidget
{
    Q_OBJECT
public:
    Canvas();
    ~Canvas();
    void realShowWidget(CanvasItem *item);
signals:
    void keyPressed(int);
    void keyReleased(int);
public:
    void keyPressEvent(QKeyEvent *ke);
    void keyReleaseEvent(QKeyEvent *ke);

    QList<CanvasItem*> items;

    static bool canvasItemLessThan(const CanvasItem *a, const CanvasItem *b)
    {
        if (a->layer == b->layer)
            return a->id < b->id;
        return a->layer < b->layer;
    }

    void removeItem(CanvasItem *a)
    {
	QList<CanvasItem*>::iterator i = items.begin();
	while (i != items.end()) {
	    if ((*i) == a) {
		if (a->widget)
		    a->widget->hide();
	        i = items.erase(i);
		break;
	    } else {
		++i;
	    }
	}
    }
};


#endif // CANVAS_H

