Warning, file /office/calligra/libs/flake/KoCanvasBase.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002 
0003    Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018    Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #include "KoCanvasBase.h"
0022 #include "KoCanvasResourceManager.h"
0023 #include "KoShapeController.h"
0024 #include "KoCanvasController.h"
0025 #include "KoViewConverter.h"
0026 #include "KoSnapGuide.h"
0027 #include "SnapGuideConfigWidget.h"
0028 #include "KoShapeManager.h"
0029 #include "KoToolProxy.h"
0030 #include "KoSelection.h"
0031 
0032 class Q_DECL_HIDDEN KoCanvasBase::Private
0033 {
0034 public:
0035     Private() : shapeController(0),
0036         resourceManager(0),
0037         isResourceManagerShared(false),
0038         controller(0),
0039         snapGuide(0)
0040     {
0041     }
0042 
0043     ~Private() {
0044         delete shapeController;
0045         if (!isResourceManagerShared) {
0046             delete resourceManager;
0047         }
0048         delete snapGuide;
0049     }
0050     KoShapeController *shapeController;
0051     KoCanvasResourceManager *resourceManager;
0052     bool isResourceManagerShared;
0053     KoCanvasController *controller;
0054     KoSnapGuide *snapGuide;
0055 };
0056 
0057 KoCanvasBase::KoCanvasBase(KoShapeBasedDocumentBase *shapeBasedDocument, KoCanvasResourceManager *sharedResourceManager)
0058         : d(new Private())
0059 {
0060     d->resourceManager = sharedResourceManager ?
0061         sharedResourceManager : new KoCanvasResourceManager();
0062     d->isResourceManagerShared = sharedResourceManager;
0063 
0064     d->shapeController = new KoShapeController(this, shapeBasedDocument);
0065     d->snapGuide = new KoSnapGuide(this);
0066 }
0067 
0068 KoCanvasBase::~KoCanvasBase()
0069 {
0070     delete d;
0071 }
0072 
0073 QPointF KoCanvasBase::viewToDocument(const QPointF &viewPoint) const
0074 {
0075     return viewConverter()->viewToDocument(viewPoint - documentOrigin());
0076 }
0077 
0078 KoShapeController *KoCanvasBase::shapeController() const
0079 {
0080     return d->shapeController;
0081 }
0082 
0083 void KoCanvasBase::disconnectCanvasObserver(QObject *object)
0084 {
0085     if (shapeManager()) shapeManager()->selection()->disconnect(object);
0086     if (resourceManager()) resourceManager()->disconnect(object);
0087     if (shapeManager()) shapeManager()->disconnect(object);
0088     if (toolProxy()) toolProxy()->disconnect(object);
0089 }
0090 
0091 
0092 KoCanvasResourceManager *KoCanvasBase::resourceManager() const
0093 {
0094     return d->resourceManager;
0095 }
0096 
0097 void KoCanvasBase::ensureVisible(const QRectF &rect)
0098 {
0099     if (d->controller && d->controller->canvas())
0100         d->controller->ensureVisible(
0101                 d->controller->canvas()->viewConverter()->documentToView(rect));
0102 }
0103 
0104 void KoCanvasBase::setCanvasController(KoCanvasController *controller)
0105 {
0106     d->controller = controller;
0107 }
0108 
0109 KoCanvasController *KoCanvasBase::canvasController() const
0110 {
0111     return d->controller;
0112 }
0113 
0114 void KoCanvasBase::clipToDocument(const KoShape *, QPointF &) const
0115 {
0116 }
0117 
0118 KoSnapGuide * KoCanvasBase::snapGuide() const
0119 {
0120     return d->snapGuide;
0121 }
0122 
0123 KoGuidesData * KoCanvasBase::guidesData()
0124 {
0125     return 0;
0126 }
0127 
0128 QWidget *KoCanvasBase::createSnapGuideConfigWidget() const
0129 {
0130     return new SnapGuideConfigWidget(d->snapGuide);
0131 }