Commit c0fff63c authored by Jan Hambrecht's avatar Jan Hambrecht

Added support for a margin around the document content to

karbons canvas. 
Added a function to the canvas controller to explicitly 
set a new preferred center point. Keep track of the changed
center point when panning and moving the scrollbars around.
Use the new function to center to the page when zooming
to page or width.


svn path=/trunk/koffice/; revision=650964
parent 4985b3df
......@@ -186,11 +186,15 @@ int KoCanvasController::canvasOffsetY() const {
}
void KoCanvasController::updateCanvasOffsetX() {
// save new preferred x-center
m_d->preferredCenterFractionX = (0.5 * viewport()->width() - canvasOffsetX() ) / m_d->documentSize.width();
emit canvasOffsetXChanged(canvasOffsetX());
m_d->viewportWidget->canvas()->setFocus(); // workaround ugly bug in Qt that the focus is transferred to the sliders
}
void KoCanvasController::updateCanvasOffsetY() {
// save new preferred y-center
m_d->preferredCenterFractionY = (0.5 * viewport()->height() - canvasOffsetY() ) / m_d->documentSize.height();
emit canvasOffsetYChanged(canvasOffsetY());
m_d->viewportWidget->canvas()->setFocus(); // workaround ugly bug in Qt that the focus is transferred to the sliders
}
......@@ -257,18 +261,17 @@ void KoCanvasController::recenterPreferred()
{
if(viewport()->width() >= m_d->documentSize.width()
&& viewport()->height() >= m_d->documentSize.height())
return; // no ned to center when image is smaller than viewport
return; // no need to center when image is smaller than viewport
QPoint center = QPoint(int(m_d->documentSize.width() * m_d->preferredCenterFractionX),
int(m_d->documentSize.height() * m_d->preferredCenterFractionY));
// convert into a canvas based point
QPoint cp = center + m_d->canvas->documentOrigin();
cp.rx() += m_d->canvas->canvasWidget()->x() + frameWidth();
cp.ry() += m_d->canvas->canvasWidget()->y() + frameWidth();
// convert into a viewport based point
center.rx() += m_d->canvas->canvasWidget()->x() + frameWidth();
center.ry() += m_d->canvas->canvasWidget()->y() + frameWidth();
// calculate the difference to the viewport centerpoint
QPoint topLeft = cp - 0.5 * QPoint( viewport()->width(), viewport()->height() );
QPoint topLeft = center - 0.5 * QPoint( viewport()->width(), viewport()->height() );
QScrollBar *hBar = horizontalScrollBar();
// try to centralize the centerpoint which we want to make visible
......@@ -423,6 +426,13 @@ void KoCanvasController::pan(const QPoint distance) {
vBar->setValue( vBar->value() + distance.y());
}
void KoCanvasController::setPreferredCenter( const QPoint &viewPoint )
{
m_d->preferredCenterFractionX = 1.0 * viewPoint.x() / m_d->documentSize.width();
m_d->preferredCenterFractionY = 1.0 * viewPoint.y() / m_d->documentSize.height();
recenterPreferred();
}
// XXX: Apparently events are not propagated to the viewport widget by
// QAbstractScrollArea
......
......@@ -188,6 +188,12 @@ public:
*/
void recenterPreferred();
/**
* Sets the preferred center point in pixels.
* @param viewPoint the new preferred center
*/
void setPreferredCenter( const QPoint &viewPoint );
void pan(const QPoint distance);
signals:
......
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