Skip to content

Commit

Permalink
print preview: auto zoomPage, bug#3442277
Browse files Browse the repository at this point in the history
  • Loading branch information
dxli committed Nov 27, 2011
1 parent 8e481a9 commit 06abac8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 59 deletions.
85 changes: 43 additions & 42 deletions src/actions/rs_actionprintpreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
* Constructor.
*/
RS_ActionPrintPreview::RS_ActionPrintPreview(RS_EntityContainer& container,
RS_GraphicView& graphicView)
:RS_ActionInterface("Print Preview",
container, graphicView) {
RS_GraphicView& graphicView)
:RS_ActionInterface("Print Preview",
container, graphicView) {
showOptions();
}

Expand All @@ -48,15 +48,15 @@ RS_ActionPrintPreview::~RS_ActionPrintPreview() {


QAction* RS_ActionPrintPreview::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) {
// tr("Print Preview")
QAction* action = new QAction(tr("Print Pre&view"), NULL);
// tr("Print Preview")
QAction* action = new QAction(tr("Print Pre&view"), NULL);
#if QT_VERSION >= 0x040600
action->setIcon(QIcon::fromTheme("document-print-preview", QIcon(":/actions/fileprintpreview.png")));
action->setIcon(QIcon::fromTheme("document-print-preview", QIcon(":/actions/fileprintpreview.png")));
#else
action->setIcon(QIcon(":/actions/fileprintpreview.png"));
action->setIcon(QIcon(":/actions/fileprintpreview.png"));
#endif
//action->zetStatusTip(tr("Shows a preview of a print"));
return action;
//action->zetStatusTip(tr("Shows a preview of a print"));
return action;
}


Expand All @@ -73,23 +73,23 @@ void RS_ActionPrintPreview::trigger() {}


void RS_ActionPrintPreview::mouseMoveEvent(QMouseEvent* e) {
switch (getStatus()) {
case Moving:
v2 = graphicView->toGraph(e->x(), e->y());
if (graphic!=NULL) {
RS_Vector pinsbase = graphic->getPaperInsertionBase();

double scale = graphic->getPaperScale();
switch (getStatus()) {
case Moving:
v2 = graphicView->toGraph(e->x(), e->y());
if (graphic!=NULL) {
RS_Vector pinsbase = graphic->getPaperInsertionBase();

graphic->setPaperInsertionBase(pinsbase-v2*scale+v1*scale);
}
v1 = v2;
graphicView->redraw(RS2::RedrawGrid); // DRAW Grid also draws paper, background items
break;
double scale = graphic->getPaperScale();

default:
break;
graphic->setPaperInsertionBase(pinsbase-v2*scale+v1*scale);
}
v1 = v2;
graphicView->redraw(RS2::RedrawGrid); // DRAW Grid also draws paper, background items
break;

default:
break;
}
}


Expand All @@ -110,16 +110,16 @@ void RS_ActionPrintPreview::mousePressEvent(QMouseEvent* e) {


void RS_ActionPrintPreview::mouseReleaseEvent(QMouseEvent* e) {
switch (getStatus()) {
case Moving:
setStatus(Neutral);
break;
switch (getStatus()) {
case Moving:
setStatus(Neutral);
break;

default:
RS_DIALOGFACTORY->requestPreviousMenu();
e->accept();
break;
}
}
}


Expand Down Expand Up @@ -183,26 +183,27 @@ void RS_ActionPrintPreview::center() {
void RS_ActionPrintPreview::fit() {
if (graphic!=NULL) {
graphic->fitToPage();
graphicView->zoomPage();
graphicView->redraw();
}
}


void RS_ActionPrintPreview::setScale(double f) {
if (graphic!=NULL) {
graphic->setPaperScale(f);
graphic->setPaperScale(f);
graphicView->redraw();
}
}
}



double RS_ActionPrintPreview::getScale() {
double ret = 1.0;
double ret = 1.0;
if (graphic!=NULL) {
ret = graphic->getPaperScale();
}
return ret;
ret = graphic->getPaperScale();
}
return ret;
}


Expand All @@ -211,20 +212,20 @@ void RS_ActionPrintPreview::setBlackWhite(bool bw) {
if (bw) {
graphicView->setDrawingMode(RS2::ModeBW);
}
else {
else {
graphicView->setDrawingMode(RS2::ModeFull);
}
graphicView->redraw();
}
graphicView->redraw();
}


RS2::Unit RS_ActionPrintPreview::getUnit() {
if (graphic!=NULL) {
return graphic->getUnit();
}
else {
return RS2::None;
}
return graphic->getUnit();
}
else {
return RS2::None;
}
}


Expand Down
20 changes: 5 additions & 15 deletions src/lib/gui/rs_graphicview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,19 +801,14 @@ void RS_GraphicView::zoomWindow(RS_Vector v1, RS_Vector v2,

double zoomX=480.0; // Zoom for X-Axis
double zoomY=640.0; // Zoom for Y-Axis (Set smaller one)
double dum; // Dummy for switching values
int zoomBorder = 0;

// Switch left/right and top/bottom is necessary:
if(v1.x>v2.x) {
dum=v1.x;
v1.x=v2.x;
v2.x=dum;
std::swap(v1.x,v2.x);
}
if(v1.y>v2.y) {
dum=v1.y;
v1.y=v2.y;
v2.y=dum;
std::swap(v1.y,v2.y);
}

// Get zoom in X and zoom in Y:
Expand All @@ -839,12 +834,8 @@ void RS_GraphicView::zoomWindow(RS_Vector v1, RS_Vector v2,
}
}

if(zoomX<0.0) {
zoomX*=-1;
}
if(zoomY<0.0) {
zoomY*=-1;
}
zoomX=fabs(zoomX);
zoomY=fabs(zoomY);

// Borders in pixel after zoom
int pixLeft =(int)(v1.x*zoomX);
Expand Down Expand Up @@ -928,8 +919,7 @@ void RS_GraphicView::zoomPage() {
return;
}

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

double fx, fy;

Expand Down
6 changes: 4 additions & 2 deletions src/main/qc_applicationwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2695,8 +2695,6 @@ void QC_ApplicationWindow::slotFilePrintPreview(bool on) {
// Link the block list to the block widget
graphic->addBlockListListener(blockWidget);

// Center by default:
graphic->centerToPage();
}

// Link the graphic view to the mouse widget:
Expand All @@ -2718,6 +2716,10 @@ void QC_ApplicationWindow::slotFilePrintPreview(bool on) {
} else {
w->show();
}

if(graphic!=NULL){
graphic->fitToPage();
}
w->getGraphicView()->zoomPage();
setFocus();

Expand Down

0 comments on commit 06abac8

Please sign in to comment.