Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 50c01b14 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Get rid of KoCanvasController::zoomMode

This was used to distinguish between the various ways a spreadsheet,
word processor or drawing application need to zoom, so it's an
obsolete bit of koffice/calligra complication.
parent ab48251b
......@@ -28,15 +28,13 @@ class Q_DECL_HIDDEN KoCanvasController::Private
{
public:
Private()
: canvasMode(Centered)
, margin(0)
: margin(0)
, preferredCenterFractionX(0.5)
, preferredCenterFractionY(0.5)
, actionCollection(0)
{
}
CanvasMode canvasMode;
int margin;
QSize documentSize;
QPoint documentOffset;
......@@ -59,26 +57,6 @@ KoCanvasController::~KoCanvasController()
delete proxyObject;
}
void KoCanvasController::setCanvasMode(CanvasMode mode)
{
d->canvasMode = mode;
switch (mode) {
case AlignTop:
d->preferredCenterFractionX = 0;
d->preferredCenterFractionY = 0.5;
break;
case Infinite:
case Centered:
d->preferredCenterFractionX = 0.5;
d->preferredCenterFractionY = 0.5;
break;
case Spreadsheet:
d->preferredCenterFractionX = 0;
d->preferredCenterFractionY = 0;
break;
};
}
void KoCanvasController::setMargin(int margin)
{
d->margin = margin;
......@@ -89,12 +67,6 @@ int KoCanvasController::margin() const
return d->margin;
}
KoCanvasController::CanvasMode KoCanvasController::canvasMode() const
{
return d->canvasMode;
}
KoCanvasBase* KoCanvasController::canvas() const
{
return 0;
......
......@@ -70,13 +70,6 @@ class KoCanvasControllerProxyObject;
class KRITAFLAKE_EXPORT KoCanvasController
{
public:
/// An enum to alter the positioning and size of the canvas inside the canvas controller
enum CanvasMode {
AlignTop, ///< canvas is top aligned if smaller than the viewport
Centered, ///< canvas is centered if smaller than the viewport
Infinite, ///< canvas is never smaller than the viewport
Spreadsheet ///< same as Infinite, but supports right-to-left layouts
};
// proxy QObject: use this to connect to slots and signals.
QPointer<KoCanvasControllerProxyObject> proxyObject;
......@@ -100,15 +93,6 @@ public:
*/
virtual void setMargin(int margin);
/**
* Sets the how the canvas behaves if the zoomed document becomes smaller than the viewport.
* @param mode the new canvas mode, CanvasMode::Centered is the default value
*/
virtual void setCanvasMode(KoCanvasController::CanvasMode mode);
/// Returns the current canvas mode
virtual KoCanvasController::CanvasMode canvasMode() const;
/**
* compatibility with QAbstractScrollArea
*/
......
......@@ -63,11 +63,7 @@ void KoCanvasControllerWidget::Private::setDocumentOffset()
// If it isn't an OpenGL canvas
if (qobject_cast<QOpenGLWidget*>(canvasWidget) == 0) {
QPoint diff = q->documentOffset() - pt;
if (q->canvasMode() == Spreadsheet && canvasWidget->layoutDirection() == Qt::RightToLeft) {
canvasWidget->scroll(-diff.x(), diff.y());
} else {
canvasWidget->scroll(diff.x(), diff.y());
}
canvasWidget->scroll(diff.x(), diff.y());
}
}
......
......@@ -393,16 +393,8 @@ void Viewport::resetLayout()
if (marginRight > 0) resizeW = viewW - marginRight;
if (marginBottom > 0) resizeH = viewH - marginBottom;
}
if (m_parent->canvasMode() == KoCanvasController::AlignTop) {
// have up to m_margin pixels at top.
moveY = qMin(m_margin, moveY);
}
if (m_canvas) {
QRect geom;
if (m_parent->canvasMode() == KoCanvasController::Infinite)
geom = QRect(0, 0, viewW, viewH);
else
geom = QRect(moveX, moveY, resizeW, resizeH);
QRect geom = QRect(0, 0, viewW, viewH);
if (m_canvas->geometry() != geom) {
m_canvas->setGeometry(geom);
m_canvas->update();
......
......@@ -236,7 +236,6 @@ KisView::KisView(KisDocument *document, KoCanvasResourceManager *resourceManager
d->canvasController.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
d->canvasController.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
d->canvasController.setDrawShadow(false);
d->canvasController.setCanvasMode(KoCanvasController::Infinite);
d->canvasController.setVastScrolling(cfg.vastScrolling());
d->canvasController.setCanvas(&d->canvas);
......
......@@ -56,7 +56,7 @@ void KoZoomController::Private::init(KoCanvasController *co,
KoZoomController::KoZoomController(KoCanvasController *co, KoZoomHandler *zh, KActionCollection *actionCollection, KoZoomAction::SpecialButtons specialButtons, QObject *parent)
: QObject(parent),
d(new Private(this, specialButtons))
d(new Private(this, specialButtons))
{
d->init(co, zh, actionCollection);
}
......@@ -141,19 +141,18 @@ void KoZoomController::setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resoluti
void KoZoomController::setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const QPointF &stillPoint)
{
if (d->zoomHandler->zoomMode() == mode &&
qFuzzyCompare(d->zoomHandler->zoom(), zoom) &&
qFuzzyCompare(d->zoomHandler->resolutionX(), resolutionX) &&
qFuzzyCompare(d->zoomHandler->resolutionY(), resolutionY)) {
qFuzzyCompare(d->zoomHandler->zoom(), zoom) &&
qFuzzyCompare(d->zoomHandler->resolutionX(), resolutionX) &&
qFuzzyCompare(d->zoomHandler->resolutionY(), resolutionY)) {
return; // no change
}
qreal oldEffectiveZoom = d->action->effectiveZoom();
QSize oldPageViewportSize = documentToViewport(d->pageSize);
QSize oldTextViewportSize = documentToViewport(QSizeF(d->textMaxX-d->textMinX, 1));
qreal yfixAlignTop = d->canvasController->viewportSize().height();
if(!qFuzzyCompare(d->zoomHandler->resolutionX(), resolutionX) ||
!qFuzzyCompare(d->zoomHandler->resolutionY(), resolutionY)) {
!qFuzzyCompare(d->zoomHandler->resolutionY(), resolutionY)) {
d->zoomHandler->setResolution(resolutionX, resolutionY);
}
......@@ -164,22 +163,22 @@ void KoZoomController::setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resoluti
}
else if(mode == KoZoomMode::ZOOM_WIDTH) {
zoom = (d->canvasController->viewportSize().width() - 2 * d->fitMargin)
/ (oldPageViewportSize.width() / d->zoomHandler->zoom());
/ (oldPageViewportSize.width() / d->zoomHandler->zoom());
d->action->setSelectedZoomMode(mode);
d->action->setEffectiveZoom(zoom);
}
else if(mode == KoZoomMode::ZOOM_PAGE) {
zoom = (d->canvasController->viewportSize().width() - 2 * d->fitMargin)
/ (oldPageViewportSize.width() / d->zoomHandler->zoom());
/ (oldPageViewportSize.width() / d->zoomHandler->zoom());
zoom = qMin(zoom, (d->canvasController->viewportSize().height() - 2 * d->fitMargin)
/ (oldPageViewportSize.height() / d->zoomHandler->zoom()));
/ (oldPageViewportSize.height() / d->zoomHandler->zoom()));
d->action->setSelectedZoomMode(mode);
d->action->setEffectiveZoom(zoom);
}
else if (mode == KoZoomMode::ZOOM_TEXT) {
zoom = (d->canvasController->viewportSize().width() - 2 * d->fitMargin)
/ (oldTextViewportSize.width() / d->zoomHandler->zoom());
/ (oldTextViewportSize.width() / d->zoomHandler->zoom());
d->action->setSelectedZoomMode(mode);
d->action->setEffectiveZoom(zoom);
}
......@@ -192,7 +191,7 @@ void KoZoomController::setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resoluti
warnWidgets << "Setting zoom while there is no document size set, this will fail";
else if (d->pageSize.width() > d->documentSize.width() || d->pageSize.height() > d->documentSize.height())
warnWidgets << "ZoomController; Your page size is larger than your document size (" <<
d->pageSize << " > " << d->documentSize << ")\n";
d->pageSize << " > " << d->documentSize << ")\n";
#endif
QSize documentViewportSize = documentToViewport(d->documentSize);
......@@ -207,38 +206,16 @@ void KoZoomController::setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resoluti
d->canvasController->proxyObject->blockSignals(false);
// Finally ask the canvasController to recenter
if (d->canvasController->canvasMode() == KoCanvasController::Infinite) {
QPointF documentCenter;
if (mode == KoZoomMode::ZOOM_WIDTH || mode == KoZoomMode::ZOOM_PAGE) {
documentCenter = QRectF(QPointF(), documentViewportSize).center();
}
else {
qreal zoomCoeff = d->action->effectiveZoom() / oldEffectiveZoom;
QPointF oldCenter = d->canvasController->preferredCenter();
documentCenter = stillPoint * zoomCoeff - (stillPoint - 1.0 / zoomCoeff * oldCenter);
}
d->canvasController->setPreferredCenter(documentCenter);
QPointF documentCenter;
if (mode == KoZoomMode::ZOOM_WIDTH || mode == KoZoomMode::ZOOM_PAGE) {
documentCenter = QRectF(QPointF(), documentViewportSize).center();
}
else if (mode == KoZoomMode::ZOOM_TEXT) {
QPointF documentCenter = d->canvasController->preferredCenter();
yfixAlignTop -= d->canvasController->viewportSize().height();
documentCenter.setX(d->zoomHandler->documentToViewX(d->textMinX + d->textMaxX) * 0.5);
documentCenter.setY(documentCenter.y() - yfixAlignTop);
d->canvasController->setPreferredCenter(documentCenter);
} else {
if (d->canvasController->canvasMode() == KoCanvasController::AlignTop) {
QPointF documentCenter = d->canvasController->preferredCenter();
documentCenter.setX(0.0);
d->canvasController->setPreferredCenter(documentCenter);
} else {
d->canvasController->recenterPreferred();
}
else {
qreal zoomCoeff = d->action->effectiveZoom() / oldEffectiveZoom;
QPointF oldCenter = d->canvasController->preferredCenter();
documentCenter = stillPoint * zoomCoeff - (stillPoint - 1.0 / zoomCoeff * oldCenter);
}
// now that we have the final offset, let's emit some signals
//d->canvasController->proxyObject->emitCanvasOffsetXChanged(d->canvasController->canvasOffsetX());
//d->canvasController->proxyObject->emitCanvasOffsetYChanged(d->canvasController->canvasOffsetY());
d->canvasController->setPreferredCenter(documentCenter);
emit zoomChanged(mode, d->action->effectiveZoom());
}
......
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