Example #1
0
/**
 * Zooms to page extends.
 */
void RS_GraphicView::zoomPage() {

	RS_DEBUG->print("RS_GraphicView::zoomPage");
	if (!container) {
		return;
	}

	RS_Graphic* graphic = container->getGraphic();
	if (!graphic) {
		return;
	}

	RS_Vector s = graphic->getPaperSize()/graphic->getPaperScale();

	double fx, fy;

	if (s.x>RS_TOLERANCE) {
		fx = (getWidth()-borderLeft-borderRight) / s.x;
	} else {
		fx = 1.0;
	}

	if (s.y>RS_TOLERANCE) {
		fy = (getHeight()-borderTop-borderBottom) / s.y;
	} else {
		fy = 1.0;
	}

	RS_DEBUG->print("f: %f/%f", fx, fy);

	fx = fy = std::min(fx, fy);

	RS_DEBUG->print("f: %f/%f", fx, fy);

	if (fx<RS_TOLERANCE) {
		fx=fy=1.0;
	}

	setFactorX(fx);
	setFactorY(fy);

	RS_DEBUG->print("f: %f/%f", fx, fy);

	centerOffsetX();
	centerOffsetY();
	adjustOffsetControls();
	adjustZoomControls();
	//    updateGrid();

	redraw();
}
Example #2
0
/**
 * Draws the paper border (for print previews).
 * This function can ONLY be called from within a paintEvent because it will
 * use the painter
 *
 * @see drawIt()
 */
void RS_GraphicView::drawPaper(RS_Painter *painter) {

	if (!container) {
		return;
	}

	RS_Graphic* graphic = container->getGraphic();
	if (graphic->getPaperScale()<1.0e-6) {
		return;
	}

	// draw paper:
	// RVT_PORT rewritten from     painter->setPen(Qt::gray);
	painter->setPen(QColor(Qt::gray));

	RS_Vector pinsbase = graphic->getPaperInsertionBase();
	RS_Vector size = graphic->getPaperSize();
	double scale = graphic->getPaperScale();

	RS_Vector v1 = toGui((RS_Vector(0,0)-pinsbase)/scale);
	RS_Vector v2 = toGui((size-pinsbase)/scale);

	// gray background:
	painter->fillRect(0,0, getWidth(), getHeight(),
					  RS_Color(200,200,200));

	// shadow
	painter->fillRect(
				(int)(v1.x)+6, (int)(v1.y)+6,
				(int)((v2.x-v1.x)), (int)((v2.y-v1.y)),
				RS_Color(64,64,64));

	// border:
	painter->fillRect(
				(int)(v1.x), (int)(v1.y),
				(int)((v2.x-v1.x)), (int)((v2.y-v1.y)),
				RS_Color(64,64,64));

	// paper
	painter->fillRect(
				(int)(v1.x)+1, (int)(v1.y)-1,
				(int)((v2.x-v1.x))-2, (int)((v2.y-v1.y))+2,
				RS_Color(255,255,255));

}