Newer
Older
Import / projects / LGN-IP3870 / qtpyui / server / qrectangle.cpp
#include "qrectangle.h"
#include <QPainter>
#include <QDirectPainter>
#include <canvasitemfactory.h>

QRectangle::QRectangle(CanvasItem *item, QWidget *parent)
	: QLabel(parent), item(item)
	//: TextItem(parent), item(item)
{
	//printf("constructing a rectangle with (%i %i %i %i)\n", item->x, item->y, item->w, item->h);
	setGeometry(QRect(item->x, item->y, item->w, item->h));
}

QRectangle::~QRectangle()
{
}

void QRectangle::paintEvent(QPaintEvent *e)
{
	//printf("painting a rectangle with geom(%i %i %i %i)\n", item->x, item->y, item->w, item->h);
	//printf("local widget geom(%i %i %i %i)\n", x(), y(), width(), height());
	//printf("global widget geom(%i %i %i %i)\n", mapToGlobal(pos()).x(), mapToGlobal(pos()).y(), width(), height());
	QPainter painter;
	painter.begin(this);
	QPen pen(item->color);
	painter.setPen(pen);
	if ( item->color == QColor(255,255,254,255) )
		//item->color = QColor(255,255,0,255); // Easier to work with
		item->color = QColor(0,0,8,255); // Transparent color
	QBrush brush(item->color);
	painter.setBrush(brush);
	//painter.drawRect(QRect(QPoint(0,0),QSize(width()-1, height()-1)));
	painter.drawRect(QRect(0,0,item->w,item->h));
	painter.end();
}