/** * 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(); }
/** * Slot for vertical scroll events. */ void QG_GraphicView::slotVScrolled(int value) { // Scrollbar behaviour tends to change with every Qt version.. // so let's keep old code in here for now //static int running = false; //if (!running) { //running = true; ////RS_DEBUG->print("value y: %d\n", value); if (vScrollBar->maximum()==vScrollBar->minimum()) { centerOffsetY(); } else { setOffsetY(value); } //if (isUpdateEnabled()) { // updateGrid(); redraw(); }
/** * Slot for vertical scroll events. */ void QG_GraphicView::slotVScrolled(int value) { // Scrollbar behaviour tends to change with every Qt version.. // so let's keep old code in here for now //static int running = false; //if (!running) { //running = true; // DEBUG_HEADER(); RS_DEBUG->print(/*RS_Debug::D_WARNING,*/ "%s %s(): set vertical offset from %d to %d\n", __FILE__, __FUNCTION__, getOffsetY(), value); if (vScrollBar->maximum()==vScrollBar->minimum()) { centerOffsetY(); } else { setOffsetY(value); } //if (isUpdateEnabled()) { // updateGrid(); redraw(); }
/** * performs autozoom * * @param axis include axis in zoom * @param keepAspectRatio true: keep aspect ratio 1:1 * false: factors in x and y are stretched to the max */ void RS_GraphicView::zoomAuto(bool axis, bool keepAspectRatio) { RS_DEBUG->print("RS_GraphicView::zoomAuto"); if (container) { container->calculateBorders(); double sx, sy; if (axis) { sx = std::max(container->getMax().x, 0.0) - std::min(container->getMin().x, 0.0); sy = std::max(container->getMax().y, 0.0) - std::min(container->getMin().y, 0.0); } else { sx = container->getSize().x; sy = container->getSize().y; } // std::cout<<" RS_GraphicView::zoomAuto("<<axis<<","<<keepAspectRatio<<")"<<std::endl; double fx=1., fy=1.; unsigned short fFlags=0; if (sx>RS_TOLERANCE) { fx = (getWidth()-borderLeft-borderRight) / sx; } else { fFlags += 1; //invalid x factor } if (sy>RS_TOLERANCE) { fy = (getHeight()-borderTop-borderBottom) / sy; } else { fFlags += 2; //invalid y factor } // std::cout<<"0: fx= "<<fx<<"\tfy="<<fy<<std::endl; RS_DEBUG->print("f: %f/%f", fx, fy); switch(fFlags){ case 1: fx=fy; break; case 2: fy=fx; break; case 3: return; //do not do anything, invalid factors default: if (keepAspectRatio) { fx = fy = std::min(fx, fy); } // break; } // std::cout<<"1: fx= "<<fx<<"\tfy="<<fy<<std::endl; RS_DEBUG->print("f: %f/%f", fx, fy); //exclude invalid factors fFlags=0; if (fx<RS_TOLERANCE||fx>RS_MAXDOUBLE) { fx=1.0; fFlags += 1; } if (fy<RS_TOLERANCE||fy>RS_MAXDOUBLE) { fy=1.0; fFlags += 2; } if(fFlags == 3 ) return; saveView(); // std::cout<<"2: fx= "<<fx<<"\tfy="<<fy<<std::endl; setFactorX(fx); setFactorY(fy); RS_DEBUG->print("f: %f/%f", fx, fy); // RS_DEBUG->print("adjustZoomControls"); adjustZoomControls(); // RS_DEBUG->print("centerOffsetX"); centerOffsetX(); // RS_DEBUG->print("centerOffsetY"); centerOffsetY(); // RS_DEBUG->print("adjustOffsetControls"); adjustOffsetControls(); // RS_DEBUG->print("updateGrid"); // updateGrid(); redraw(); } RS_DEBUG->print("RS_GraphicView::zoomAuto OK"); }