Commit 20782b33 authored by Adrian Page's avatar Adrian Page

Implement the 'actual pixels' zoom mode.


svn path=/trunk/koffice/; revision=654364
parent 7760ae06
......@@ -369,6 +369,8 @@ void KisView2::slotLoadingFinished()
m_d->statusBar->imageSizeChanged(img->width(), img->height());
}
m_d->zoomManager->setDocumentResolution(img->xRes(), img->yRes());
m_d->layerManager->layersUpdated();
updateGUI();
......
......@@ -151,4 +151,9 @@ void KisZoomManager::slotZoomChanged(KoZoomMode::Mode mode, double zoom)
m_view->canvas()->update();
}
void KisZoomManager::setDocumentResolution( double xResolution, double yResolution )
{
m_zoomController->setDocumentResolution(xResolution, yResolution);
}
#include "kis_zoom_manager.moc"
......@@ -53,6 +53,14 @@ public:
void setup(KActionCollection * actionCollection);
void updateGUI();
/**
* Set the document resolution in pixels per pt.
*
* @param xResolution resolution along x in pixels per point.
* @param yResolution resolution along y in pixels per point.
*/
void setDocumentResolution( double xResolution, double yResolution );
private slots:
void slotZoomChanged(KoZoomMode::Mode mode, double zoom);
......
......@@ -303,10 +303,12 @@ void Viewport::resetLayout()
resizeH -= moveY;
moveY = 0;
}
if( m_parent->canvasMode() == KoCanvasController::Infinite )
m_canvas->setGeometry( 0, 0, viewW, viewH );
else
m_canvas->setGeometry( moveX, moveY, resizeW, resizeH );
if (m_canvas) {
if( m_parent->canvasMode() == KoCanvasController::Infinite )
m_canvas->setGeometry( 0, 0, viewW, viewH );
else
m_canvas->setGeometry( moveX, moveY, resizeW, resizeH );
}
// kDebug() << "View port geom: " << geometry() << endl;
// kDebug() << "Canvas widget geom: " << m_canvas->geometry() << endl;
......
......@@ -33,6 +33,8 @@ KoZoomController::KoZoomController(KoCanvasController *co, KoZoomHandler *zh, KA
: m_canvasController(co)
, m_zoomHandler(zh)
, m_fitMargin( 0 )
, m_documentXResolution( 1 )
, m_documentYResolution( 1 )
{
m_action = new KoZoomAction(KoZoomMode::ZOOM_PIXELS | KoZoomMode::ZOOM_WIDTH | KoZoomMode::ZOOM_PAGE, i18n("Zoom"), 0);
connect(m_action, SIGNAL(zoomChanged(KoZoomMode::Mode, double)),
......@@ -56,8 +58,9 @@ void KoZoomController::setZoom(double /*zoom*/)
{
}
void KoZoomController::setZoomMode(KoZoomMode /*mode*/)
void KoZoomController::setZoomMode(KoZoomMode::Mode mode)
{
setZoom(mode, 1);
}
void KoZoomController::setPageSize(const QSizeF &pageSize)
......@@ -78,6 +81,15 @@ void KoZoomController::setDocumentSize( const QSizeF &documentSize )
int(0.5 + m_zoomHandler->documentToViewY(m_documentSize.height())) ) );
}
void KoZoomController::setDocumentResolution( double xResolution, double yResolution )
{
m_documentXResolution = xResolution;
m_documentYResolution = yResolution;
if(m_zoomHandler->zoomMode() == KoZoomMode::ZOOM_PIXELS)
setZoom(KoZoomMode::ZOOM_PIXELS, 0);
}
void KoZoomController::setZoom(KoZoomMode::Mode mode, double zoom)
{
m_zoomHandler->setZoomMode(mode);
......@@ -102,8 +114,18 @@ void KoZoomController::setZoom(KoZoomMode::Mode mode, double zoom)
m_action->setEffectiveZoom(zoom);
}
m_zoomHandler->setZoom(zoom);
emit zoomChanged(mode, zoom);
if(mode == KoZoomMode::ZOOM_PIXELS)
{
m_zoomHandler->setZoomedResolution(m_documentXResolution, m_documentYResolution);
zoom = m_zoomHandler->zoomFactorX();
m_action->setEffectiveZoom(zoom);
emit zoomChanged(mode, zoom);
}
else
{
m_zoomHandler->setZoom(zoom);
emit zoomChanged(mode, zoom);
}
// Tell the canvasController that the zoom has changed
// Actually canvasController doesn't know about zoom, but the document in pixels
......
......@@ -67,7 +67,7 @@ public:
/// setter for the view to set the zoom and level.
void setZoom(double zoom);
void setZoomMode(KoZoomMode mode);
void setZoomMode(KoZoomMode::Mode mode);
public slots:
/// every time the canvas changes content size, tell us. Note that the size is in pt.
......@@ -81,6 +81,15 @@ public slots:
*/
void setDocumentSize( const QSizeF &documentSize );
/**
* Set the document resolution in pixels per pt. This information is only
* required if the application uses the ZOOM_PIXELS ZoomMode.
*
* @param xResolution resolution along x in pixels per point.
* @param yResolution resolution along y in pixels per point.
*/
void setDocumentResolution( double xResolution, double yResolution );
/**
* Sets a fitting margin that is used when zooming to page size/width.
* Note that the fit margin is given in pixels.
......@@ -117,6 +126,8 @@ private:
QSizeF m_pageSize;
QSizeF m_documentSize;
int m_fitMargin;
double m_documentXResolution;
double m_documentYResolution;
};
#endif
......@@ -15,6 +15,18 @@ target_link_libraries(zoomhandler_test ${KDE4_KDEUI_LIBS} kofficeui kofficecore
add_test(libs-kofficeui-zoomhandler_test zoomhandler_test)
########### next target ###############
set(zoomcontroller_test_SRCS zoomcontroller_test.cpp )
kde4_automoc(${zoomcontroller_test_SRCS})
kde4_add_executable(zoomcontroller_test RUN_UNINSTALLED ${zoomcontroller_test_SRCS})
target_link_libraries(zoomcontroller_test ${KDE4_KDEUI_LIBS} kofficeui kofficecore ${QT_QTTEST_LIBRARY})
add_test(libs-kofficeui-zoomcontroller_test zoomcontroller_test)
########### end ###############
endif(KDE4_BUILD_TESTS)
/*
* Copyright (C) Adrian Page <adrian@pagenet.plus.com>, (C) 2007
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QTest>
#include <QCoreApplication>
#include <qtest_kde.h>
#include <kactioncollection.h>
#include <kdebug.h>
#include "KoCanvasController.h"
#include "KoZoomHandler.h"
#include "KoZoomController.h"
#include "KoGlobal.h"
#include "KoUnit.h"
#include "zoomcontroller_test.h"
void zoomcontroller_test::testApi()
{
KoZoomHandler zoomHandler;
KoZoomController zoomController(new KoCanvasController(), &zoomHandler, new KActionCollection(this));
zoomHandler.setZoomAndResolution(100, 123, 456);
zoomController.setDocumentResolution(50, 60);
zoomController.setZoomMode(KoZoomMode::ZOOM_PIXELS);
QVERIFY( zoomHandler.zoomedResolutionX() == 50);
QVERIFY( zoomHandler.zoomedResolutionY() == 60);
}
QTEST_KDEMAIN(zoomcontroller_test, GUI)
#include "zoomcontroller_test.moc"
/*
* Copyright (C) Adrian Page <adrian@pagenet.plus.com>, (C) 2007
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef ZOOMCONTROLLER_TEST_H
#define ZOOMCONTROLLER_TEST_H
#include <QtTest/QtTest>
class zoomcontroller_test : public QObject
{
Q_OBJECT
private slots:
// tests
void testApi();
};
#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