#include "imgwidget.h"

ImgWidget::ImgWidget (QWidget* parent, const char* name)
			: QWidget(parent, name)
{
	this->pmbuf = new QPixmap();
	this->pixels = new QImage();
}
		
bool ImgWidget::loadImage (const QString& fname)
{
	// Try to load the image
	if (this->pixels->load(fname))
	{
		this->setMinimumSize(this->pixels->size());
	
		// The convertFromImage() function is slow!
		// You shouldn't be calling it in paintEvent()
		this->pmbuf->convertFromImage(*(this->pixels));
		
		return 1;
	}
	else 
		return 0;
}

void ImgWidget::paintEvent(QPaintEvent* pEv)
{
	// Here is the critical code: do a fast block linear transfer
	// of the pixmap data
	bitBlt(this, 0, 0, this->pmbuf);
}
		

