Warning, file /office/calligra/libs/pageapp/KoPACanvasBase.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 Copyright (C) 2006-2007 Thorsten Zachmann <zachmann@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KoPACanvasBase.h" 0021 0022 #include <KoShapeManager.h> 0023 #include <KoToolProxy.h> 0024 #include <KoGridData.h> 0025 #include <KoUnit.h> 0026 #include <KoText.h> 0027 0028 #include "KoPADocument.h" 0029 #include "KoPAViewBase.h" 0030 #include "KoPAPageBase.h" 0031 #include "KoPAPageProvider.h" 0032 0033 class Q_DECL_HIDDEN KoPACanvasBase::Private 0034 { 0035 public: 0036 Private(KoPADocument * doc) 0037 : view(0) 0038 , doc(doc) 0039 , shapeManager(0) 0040 , masterShapeManager(0) 0041 , toolProxy(0) 0042 , showPageMargins(false) 0043 {} 0044 0045 ~Private() 0046 { 0047 delete toolProxy; 0048 delete masterShapeManager; 0049 delete shapeManager; 0050 } 0051 0052 ///< the origin of the page rect inside the canvas in document points 0053 QPointF origin() const 0054 { 0055 return view->viewMode()->origin(); 0056 } 0057 0058 KoPAViewBase * view; 0059 KoPADocument * doc; 0060 KoShapeManager * shapeManager; 0061 KoShapeManager * masterShapeManager; 0062 KoToolProxy * toolProxy; 0063 QPoint documentOffset; 0064 bool showPageMargins; 0065 }; 0066 0067 KoPACanvasBase::KoPACanvasBase( KoPADocument * doc ) 0068 : KoCanvasBase( doc ) 0069 , d(new Private(doc)) 0070 { 0071 d->shapeManager = new KoShapeManager( this ); 0072 d->masterShapeManager = new KoShapeManager( this ); 0073 d->toolProxy = new KoToolProxy( this ); 0074 } 0075 0076 KoPACanvasBase::~KoPACanvasBase() 0077 { 0078 delete d; 0079 } 0080 0081 void KoPACanvasBase::setView(KoPAViewBase *view) 0082 { 0083 d->view = view; 0084 } 0085 0086 KoPADocument* KoPACanvasBase::document() const 0087 { 0088 return d->doc; 0089 } 0090 0091 KoToolProxy* KoPACanvasBase::toolProxy() const 0092 { 0093 return d->toolProxy; 0094 } 0095 0096 KoPAViewBase* KoPACanvasBase::koPAView() const 0097 { 0098 return d->view; 0099 } 0100 0101 QPoint KoPACanvasBase::documentOrigin() const 0102 { 0103 return viewConverter()->documentToView(d->origin()).toPoint(); 0104 } 0105 0106 void KoPACanvasBase::setDocumentOrigin(const QPointF & o) 0107 { 0108 d->view->viewMode()->setOrigin(o); 0109 } 0110 0111 void KoPACanvasBase::gridSize( qreal *horizontal, qreal *vertical ) const 0112 { 0113 *horizontal = d->doc->gridData().gridX(); 0114 *vertical = d->doc->gridData().gridY(); 0115 } 0116 0117 bool KoPACanvasBase::snapToGrid() const 0118 { 0119 return d->doc->gridData().snapToGrid(); 0120 } 0121 0122 void KoPACanvasBase::addCommand( KUndo2Command *command ) 0123 { 0124 d->doc->addCommand( command ); 0125 } 0126 0127 KoShapeManager * KoPACanvasBase::shapeManager() const 0128 { 0129 return d->shapeManager; 0130 } 0131 0132 KoShapeManager * KoPACanvasBase::masterShapeManager() const 0133 { 0134 return d->masterShapeManager; 0135 } 0136 0137 KoViewConverter * KoPACanvasBase::viewConverter() const 0138 { 0139 return d->view->viewMode()->viewConverter( const_cast<KoPACanvasBase *>( this ) ); 0140 } 0141 0142 KoUnit KoPACanvasBase::unit() const 0143 { 0144 return d->doc->unit(); 0145 } 0146 0147 const QPoint & KoPACanvasBase::documentOffset() const 0148 { 0149 return d->documentOffset; 0150 } 0151 0152 void KoPACanvasBase::setDocumentOffset(const QPoint &offset) { 0153 d->documentOffset = offset; 0154 } 0155 0156 QPoint KoPACanvasBase::widgetToView(const QPoint& p) const 0157 { 0158 return p - viewConverter()->documentToView(d->origin()).toPoint(); 0159 } 0160 0161 QRect KoPACanvasBase::widgetToView(const QRect& r) const 0162 { 0163 return r.translated(viewConverter()->documentToView(-d->origin()).toPoint()); 0164 } 0165 0166 QPoint KoPACanvasBase::viewToWidget(const QPoint& p) const 0167 { 0168 return p + viewConverter()->documentToView(d->origin()).toPoint(); 0169 } 0170 0171 QRect KoPACanvasBase::viewToWidget(const QRect& r) const 0172 { 0173 return r.translated(viewConverter()->documentToView(d->origin()).toPoint()); 0174 } 0175 0176 KoGuidesData * KoPACanvasBase::guidesData() 0177 { 0178 return &d->doc->guidesData(); 0179 } 0180 0181 void KoPACanvasBase::paint(QPainter &painter, const QRectF &paintRect) { 0182 0183 KoPAPageBase *activePage(d->view->activePage()); 0184 if (d->view->activePage()) { 0185 int pageNumber = d->doc->pageIndex( d->view->activePage() ) + 1; 0186 QVariant var = d->doc->resourceManager()->resource(KoText::PageProvider); 0187 static_cast<KoPAPageProvider*>(var.value<void*>())->setPageData(pageNumber, activePage); 0188 d->view->viewMode()->paint(this, painter, paintRect); 0189 } 0190 } 0191 0192 void KoPACanvasBase::setShowPageMargins(bool state) 0193 { 0194 d->showPageMargins = state; 0195 } 0196 0197 bool KoPACanvasBase::showPageMargins() const 0198 { 0199 return d->showPageMargins; 0200 }