#ifndef __TEXT_ITEM_H__
#define __TEXT_ITEM_H__


#include <QWidget>
#include <QPainter>
#include <QPixmapCache>


class TextItem : public QWidget
{
public:
	TextItem(QWidget*parent) : QWidget(parent), type(0) {
	}
	~TextItem() { }
	//QString text() { return str; }
	void setText(QString text) { 
		// type = 0; str = text; return;

//		printf("set Text %s\n", text.toLatin1().data());

		type = 1;
		if ( !QPixmapCache::find(text + "_text", pix) ) {
			QFontMetrics fm(font());
			int w = fm.width(text);
			int h = 30; // fm.height(text);
			pix = QPixmap(w, h);
			pix.fill(QColor(0,0,0,0));
			QPainter p(&pix);
			p.drawText(0, 20, text);
			QPixmapCache::insert(text + "_text", pix);
		}
	}
	void setPixmap(QPixmap pixmap) { type = 1; pix = pixmap; }
	void paintEvent(QPaintEvent *pe) {
		QPainter p(this);
		if (type == 0)
			p.drawText(0, 20, str);
		else if (type == 1)
			p.drawPixmap(0, 0, pix);
	}
private:
	QPixmap pix;
	QString str;
	int type;
}; 


#endif


