Commit c7f9ecd9 authored by Jan Hambrecht's avatar Jan Hambrecht

Added support for an optional fit margin to the zoom controller.

That margin is used when zooming to page/width so that there is
a constant margin between the viewport border and the page border.


svn path=/trunk/koffice/; revision=649638
parent 063b46ff
......@@ -31,6 +31,7 @@
KoZoomController::KoZoomController(KoCanvasController *co, KoZoomHandler *zh, KActionCollection *actionCollection)
: m_canvasController(co)
, m_zoomHandler(zh)
, m_fitMargin( 0 )
{
m_action = new KoZoomAction(KoZoomMode::ZOOM_PIXELS | KoZoomMode::ZOOM_WIDTH | KoZoomMode::ZOOM_PAGE, i18n("Zoom"), 0);
connect(m_action, SIGNAL(zoomChanged(KoZoomMode::Mode, double)),
......@@ -86,15 +87,15 @@ void KoZoomController::setZoom(KoZoomMode::Mode mode, double zoom)
}
else if(mode == KoZoomMode::ZOOM_WIDTH)
{
zoom = m_canvasController->viewport()->size().width()
zoom = (m_canvasController->viewport()->size().width() - 2*m_fitMargin)
/ (m_zoomHandler->resolutionX() * m_pageSize.width());
m_action->setEffectiveZoom(zoom);
}
}
else if(mode == KoZoomMode::ZOOM_PAGE)
{
zoom = m_canvasController->viewport()->size().width()
zoom = (m_canvasController->viewport()->size().width() - 2*m_fitMargin)
/ (m_zoomHandler->resolutionX() * m_pageSize.width());
zoom = qMin(zoom, m_canvasController->viewport()->size().height()
zoom = qMin(zoom, (m_canvasController->viewport()->size().height() - 2*m_fitMargin)
/ (m_zoomHandler->resolutionY() * m_pageSize.height()));
m_action->setEffectiveZoom(zoom);
......@@ -130,4 +131,9 @@ void KoZoomController::requestZoomBy(const double factor)
m_action->setEffectiveZoom(factor*zoom);
}
void KoZoomController::setFitMargin( int margin )
{
m_fitMargin = margin;
}
#include "KoZoomController.moc"
......@@ -80,6 +80,13 @@ public slots:
*/
void setDocumentSize( const QSizeF &documentSize );
/**
* Sets a fitting margin that is used when zooming to page size/width.
* Note that the fit margin is given in pixels.
* @param margin the new fit margin to use, the default is zero
*/
void setFitMargin( int margin );
signals:
// the document can use the emitted data for persistency purposes.
void zoomChanged (KoZoomMode::Mode mode, double zoom);
......@@ -108,6 +115,7 @@ private:
KoZoomAction *m_action;
QSizeF m_pageSize;
QSizeF m_documentSize;
int m_fitMargin;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment