~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to karbon/ui/KarbonZoomController.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* This file is part of the KDE project
2
 
 * Copyright (C) 2008 Jan Hambrecht <jaham@gmx.net>
 
2
 * Copyright (C) 2008,2010 Jan Hambrecht <jaham@gmx.net>
 
3
 * Copyright (C) 2010 Boudewijn Rempt <boud@kogmbh.com>
3
4
 *
4
5
 * This library is free software; you can redistribute it and/or
5
6
 * modify it under the terms of the GNU Library General Public
25
26
#include <KoCanvasBase.h>
26
27
#include <KoZoomHandler.h>
27
28
#include <KoResourceManager.h>
 
29
#include <KoShapeManager.h>
 
30
#include <KoSelection.h>
28
31
 
29
32
#include <KActionCollection>
30
33
#include <KLocale>
51
54
    int fitMargin;
52
55
};
53
56
 
54
 
KarbonZoomController::KarbonZoomController(KoCanvasController *controller, KActionCollection *actionCollection)
55
 
        : QObject(controller), d(new Private())
 
57
KarbonZoomController::KarbonZoomController(KoCanvasController *controller, KActionCollection *actionCollection, QObject *parent)
 
58
        : QObject(parent), d(new Private())
56
59
{
57
60
    d->canvasController = controller;
58
61
 
72
75
    d->canvas = dynamic_cast<KarbonCanvas*>(d->canvasController->canvas());
73
76
    d->zoomHandler = dynamic_cast<KoZoomHandler*>(const_cast<KoViewConverter*>(d->canvas->viewConverter()));
74
77
 
75
 
    connect(d->canvasController, SIGNAL(sizeChanged(const QSize &)), this, SLOT(setAvailableSize()));
76
 
    connect(d->canvasController, SIGNAL(zoomBy(const qreal)), this, SLOT(requestZoomBy(const qreal)));
77
 
    connect(d->canvasController, SIGNAL(moveDocumentOffset(const QPoint&)),
 
78
    connect(d->canvasController->proxyObject, SIGNAL(sizeChanged(const QSize &)), this, SLOT(setAvailableSize()));
 
79
    connect(d->canvasController->proxyObject, SIGNAL(zoomBy(const qreal)), this, SLOT(requestZoomBy(const qreal)));
 
80
    connect(d->canvasController->proxyObject, SIGNAL(moveDocumentOffset(const QPoint&)),
78
81
            d->canvas, SLOT(setDocumentOffset(const QPoint&)));
79
82
 
80
83
    connect(d->canvas->resourceManager(), SIGNAL(resourceChanged(int, const QVariant &)),
106
109
        if (zoom == 0.0) return;
107
110
        d->action->setZoom(zoom);
108
111
    } else if (mode == KoZoomMode::ZOOM_WIDTH) {
109
 
        zoom = (d->canvasController->viewport()->size().width() - 2 * d->fitMargin)
 
112
        zoom = (d->canvasController->viewportSize().width() - 2 * d->fitMargin)
110
113
               / (d->zoomHandler->resolutionX() * d->pageSize.width());
111
114
        d->action->setSelectedZoomMode(mode);
112
115
        d->action->setEffectiveZoom(zoom);
113
116
    } else if (mode == KoZoomMode::ZOOM_PAGE) {
114
 
        zoom = (d->canvasController->viewport()->size().width() - 2 * d->fitMargin)
 
117
        zoom = (d->canvasController->viewportSize().width() - 2 * d->fitMargin)
115
118
               / (d->zoomHandler->resolutionX() * d->pageSize.width());
116
 
        zoom = qMin(zoom, (d->canvasController->viewport()->size().height() - 2 * d->fitMargin)
 
119
        zoom = qMin(zoom, (d->canvasController->viewportSize().height() - 2 * d->fitMargin)
117
120
                    / (d->zoomHandler->resolutionY() * d->pageSize.height()));
118
121
 
119
122
        d->action->setSelectedZoomMode(mode);
128
131
 
129
132
    // now calculate the preferred center in document coordinates
130
133
    QPointF docCenter = d->zoomHandler->viewToDocument(preferredCenter - documentOrigin);
 
134
    KoSelection * selection = d->canvas->shapeManager()->selection();
 
135
    if( selection->count()) {
 
136
        docCenter = selection->boundingRect().center();
 
137
    }
131
138
 
132
139
    d->zoomHandler->setZoom(zoom);
133
140
 
135
142
    // Actually canvasController doesn't know about zoom, but the document in pixels
136
143
    // has change as a result of the zoom change
137
144
    QSizeF viewSize = d->zoomHandler->documentToView(documentRect).size();
138
 
    d->canvasController->setDocumentSize(QSize(qRound(viewSize.width()), qRound(viewSize.height())));
 
145
    d->canvasController->updateDocumentSize(QSize(qRound(viewSize.width()), qRound(viewSize.height())), true);
139
146
 
140
147
    d->canvas->adjustOrigin();
141
148
 
189
196
        // has changed as a result of the page layout change
190
197
        QRectF documentRect = d->canvas->documentViewRect();
191
198
        QSizeF viewSize = d->zoomHandler->documentToView(documentRect).size();
192
 
        d->canvasController->setDocumentSize(QSize(qRound(viewSize.width()), qRound(viewSize.height())));
 
199
        d->canvasController->updateDocumentSize(QSize(qRound(viewSize.width()), qRound(viewSize.height())), true);
193
200
        d->canvas->adjustOrigin();
194
201
        d->canvas->update();
195
202
    }