KoCanvasBase.cpp 3.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/* This file is part of the KDE project

   Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "KoCanvasBase.h"
22
#include "KoCanvasResourceManager.h"
Thomas Zander's avatar
Thomas Zander committed
23
#include "KoShapeController.h"
24
#include "KoCanvasController.h"
25
#include "KoViewConverter.h"
26
#include "KoSnapGuide.h"
27
#include "SnapGuideConfigWidget.h"
28 29 30
#include "KoShapeManager.h"
#include "KoToolProxy.h"
#include "KoSelection.h"
Halla Rempt's avatar
Halla Rempt committed
31 32 33
#include <kconfiggroup.h>
#include <ksharedptr.h>
#include <ksharedconfig.h>
34

35 36
class KoCanvasBase::Private
{
Thomas Zander's avatar
Thomas Zander committed
37
public:
Thomas Zander's avatar
Thomas Zander committed
38 39 40
    Private() : shapeController(0),
        resourceManager(0),
        controller(0),
41
        snapGuide(0)
Thomas Zander's avatar
Thomas Zander committed
42 43
    {
    }
44

Thomas Zander's avatar
Thomas Zander committed
45 46
    ~Private() {
        delete shapeController;
Thomas Zander's avatar
Thomas Zander committed
47
        delete resourceManager;
48
        delete snapGuide;
Thomas Zander's avatar
Thomas Zander committed
49 50
    }
    KoShapeController *shapeController;
51
    KoCanvasResourceManager *resourceManager;
52
    KoCanvasController *controller;
Thomas Zander's avatar
Thomas Zander committed
53
    KoSnapGuide *snapGuide;
Thomas Zander's avatar
Thomas Zander committed
54 55
};

56
KoCanvasBase::KoCanvasBase(KoShapeBasedDocumentBase *shapeBasedDocument)
57
        : d(new Private())
58
{
59
    d->resourceManager = new KoCanvasResourceManager();
60
    d->shapeController = new KoShapeController(this, shapeBasedDocument);
61
    d->snapGuide = new KoSnapGuide(this);
62 63 64
}

KoCanvasBase::~KoCanvasBase()
65
{
Thomas Zander's avatar
Thomas Zander committed
66
    delete d;
67
}
68

C. Boemann's avatar
C. Boemann committed
69 70 71 72
QPointF KoCanvasBase::viewToDocument(const QPointF &viewPoint) const
{
    return viewConverter()->viewToDocument(viewPoint - documentOrigin());;
}
Thomas Zander's avatar
Thomas Zander committed
73

Thomas Zander's avatar
Thomas Zander committed
74
KoShapeController *KoCanvasBase::shapeController() const
75
{
Thomas Zander's avatar
Thomas Zander committed
76 77 78
    return d->shapeController;
}

79 80 81 82 83 84 85 86 87
void KoCanvasBase::disconnectCanvasObserver(QObject *object)
{
    shapeManager()->selection()->disconnect(object);
    resourceManager()->disconnect(object);
    shapeManager()->disconnect(object);
    toolProxy()->disconnect(object);
}


88
KoCanvasResourceManager *KoCanvasBase::resourceManager() const
Thomas Zander's avatar
Thomas Zander committed
89
{
Thomas Zander's avatar
Thomas Zander committed
90
    return d->resourceManager;
Thomas Zander's avatar
Thomas Zander committed
91
}
92

93 94
void KoCanvasBase::ensureVisible(const QRectF &rect)
{
95 96 97
    if (d->controller && d->controller->canvas())
        d->controller->ensureVisible(
                d->controller->canvas()->viewConverter()->documentToView(rect));
98 99
}

100 101
void KoCanvasBase::setCanvasController(KoCanvasController *controller)
{
102 103
    d->controller = controller;
}
104

Thomas Zander's avatar
Thomas Zander committed
105
KoCanvasController *KoCanvasBase::canvasController() const
106 107 108 109
{
    return d->controller;
}

110 111
void KoCanvasBase::clipToDocument(const KoShape *, QPointF &) const
{
112
}
113

114 115 116 117
KoSnapGuide * KoCanvasBase::snapGuide() const
{
    return d->snapGuide;
}
118 119 120 121 122

KoGuidesData * KoCanvasBase::guidesData()
{
    return 0;
}
123 124 125 126 127

QWidget *KoCanvasBase::createSnapGuideConfigWidget() const
{
    return new SnapGuideConfigWidget(d->snapGuide);
}