Exemple #1
0
void ReportView::drawBackground(QPainter *painter, const QRectF &rect)
{
	QGraphicsView::drawBackground(painter, rect);

	if (!scene())
		return;

	// Shadow
	QRectF sceneRect = this->scene()->sceneRect();
	QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height());
	QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5);
	if (rightShadow.intersects(rect) || rightShadow.contains(rect))
		painter->fillRect(rightShadow, Qt::darkGray);
	if (bottomShadow.intersects(rect) || bottomShadow.contains(rect))
		painter->fillRect(bottomShadow, Qt::darkGray);

	// Fill
	Report *report = (Report*)scene();
	QPoint size = mapFromScene(report->gridSize().width(), report->gridSize().height())
		- mapFromScene(QPointF());
	QPixmap pixmap(size.x(), size.y());
	{
		pixmap.fill();
		QPainter p(&pixmap);
		QPen pen(Qt::DotLine);
		pen.setColor(Qt::gray);
		p.setPen(pen);
		p.drawLine(0, 0, size.x(), 0);
		p.drawLine(0, 0, 0, size.y());
	}
	painter->setBrush(pixmap);
	painter->drawRect(sceneRect);
}