#include <QKeyEvent>
#include <QPixmapCache>
#include <canvas.h>
#include <canvasfactory.h>


bool alphaPaintingEnabled = false;


Canvas::Canvas() : QWidget(0)
{
    //setAttribute(Qt::WA_PaintOnScreen);
    QPixmapCache::setCacheLimit(8000);
}


Canvas::~Canvas()
{
}


void Canvas::keyPressEvent(QKeyEvent *ke)
{
    emit keyPressed((int)ke->key());
}


void Canvas::keyReleaseEvent(QKeyEvent *ke)
{
    emit keyReleased((int)ke->key());
}


void Canvas::realShowWidget(CanvasItem *itm)
{
    QList<CanvasItem*>::iterator i = qUpperBound( items.begin(), items.end(), itm, canvasItemLessThan );
    for ( CanvasItem *item = *i; i != items.end(); item = *(++i) ) {
        if (item->visible) {
    	    itm->widget->stackUnder(item->widget);
	    return;
	}
    }
    itm->widget->raise();
}


