File indexing completed on 2024-05-05 17:09:08
0001 /* 0002 * This file is part of the KDE project 0003 * 0004 * Copyright (C) 2006-2009 Thorsten Zachmann <zachmann@kde.org> 0005 * Copyright (C) 2007 Thomas Zander <zander@kde.org> 0006 * Copyright (C) 2009 Inge Wallin <inge@lysator.liu.se> 0007 * Copyright (C) 2010 Boudewijn Rempt <boud@kogmbh.com> 0008 * Copyright (C) 2011 Shantanu Tushar <shaan7in@gmail.com> 0009 * Copyright (C) 2013 Arjen Hiemstra <ahiemstra@heimr.nl> 0010 * 0011 * This program is free software; you can redistribute it and/or 0012 * modify it under the terms of the GNU General Public License as 0013 * published by the Free Software Foundation; either version 2 of 0014 * the License, or (at your option) any later version. 0015 * 0016 * This program is distributed in the hope that it will be useful, 0017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0019 * GNU General Public License for more details. 0020 * 0021 * You should have received a copy of the GNU General Public License 0022 * along with this program; if not, write to the Free Software 0023 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 0024 * 02110-1301 USA 0025 */ 0026 0027 #include "CQPresentationView.h" 0028 #include "CQCanvasController.h" 0029 0030 #include <KoZoomController.h> 0031 #include <KoPADocument.h> 0032 #include <KoPACanvasBase.h> 0033 #include <KoPAPageBase.h> 0034 #include <KoPAViewModeNormal.h> 0035 #include <stage/part/KPrDocument.h> 0036 #include <KoShapeManager.h> 0037 #include <KoShapeLayer.h> 0038 #include <KoSelection.h> 0039 #include <KoPAPage.h> 0040 #include <KoPAMasterPage.h> 0041 #include <KoCanvasController.h> 0042 #include <KoPACanvasItem.h> 0043 #include <KoZoomHandler.h> 0044 #include <KoPart.h> 0045 0046 #include <QGraphicsItem> 0047 0048 //TODO: Cleanup code that is not called 0049 CQPresentationView::CQPresentationView (KoCanvasController* canvasController, KoPACanvasBase* canvas, KPrDocument* prDocument) 0050 : m_canvasController (canvasController), m_zoomController(0), m_paCanvas (canvas), m_prDocument (prDocument), m_page (0) 0051 { 0052 KoPAViewModeNormal* mode = new KoPAViewModeNormal (this, m_paCanvas); 0053 setViewMode (mode); 0054 } 0055 0056 CQPresentationView::~CQPresentationView() 0057 { 0058 0059 } 0060 0061 void CQPresentationView::setShowRulers (bool show) 0062 { 0063 Q_UNUSED(show); 0064 } 0065 0066 void CQPresentationView::editPaste() 0067 { 0068 0069 } 0070 0071 void CQPresentationView::pagePaste() 0072 { 0073 0074 } 0075 0076 void CQPresentationView::insertPage() 0077 { 0078 0079 } 0080 0081 void CQPresentationView::updatePageNavigationActions() 0082 { 0083 0084 } 0085 0086 void CQPresentationView::setActionEnabled (int actions, bool enable) 0087 { 0088 Q_UNUSED(actions); 0089 Q_UNUSED(enable); 0090 0091 } 0092 0093 void CQPresentationView::navigatePage (KoPageApp::PageNavigation pageNavigation) 0094 { 0095 Q_UNUSED(pageNavigation); 0096 } 0097 0098 KoPAPageBase* CQPresentationView::activePage() const 0099 { 0100 return m_page; 0101 } 0102 0103 void CQPresentationView::setActivePage (KoPAPageBase* page) 0104 { 0105 KoShapeManager* shapeManager = m_paCanvas->shapeManager(); 0106 KoShapeManager* masterShapeManager = m_paCanvas->masterShapeManager(); 0107 shapeManager->removeAdditional (m_page); 0108 m_page = page; 0109 shapeManager->addAdditional (page); 0110 QList<KoShape*> shapes = page->shapes(); 0111 shapeManager->setShapes (shapes, KoShapeManager::AddWithoutRepaint); 0112 //Make the top most layer active 0113 if (!shapes.isEmpty()) { 0114 KoShapeLayer* layer = dynamic_cast<KoShapeLayer*> (shapes.last()); 0115 shapeManager->selection()->setActiveLayer (layer); 0116 } 0117 0118 // if the page is not a master page itself set shapes of the master page 0119 KoPAPage* paPage = dynamic_cast<KoPAPage*> (page); 0120 if (paPage) { 0121 KoPAMasterPage* masterPage = paPage->masterPage(); 0122 QList<KoShape*> masterShapes = masterPage->shapes(); 0123 masterShapeManager->setShapes (masterShapes, KoShapeManager::AddWithoutRepaint); 0124 //Make the top most layer active 0125 if (!masterShapes.isEmpty()) { 0126 KoShapeLayer* layer = dynamic_cast<KoShapeLayer*> (masterShapes.last()); 0127 masterShapeManager->selection()->setActiveLayer (layer); 0128 } 0129 } else { 0130 // if the page is a master page no shapes are in the masterShapeManager 0131 masterShapeManager->setShapes (QList<KoShape*>()); 0132 } 0133 0134 // Set the current page number in the canvas resource provider 0135 m_paCanvas->resourceManager()->setResource (KoCanvasResourceManager::CurrentPage, m_prDocument->pageIndex (page) + 1); 0136 } 0137 0138 void CQPresentationView::doUpdateActivePage (KoPAPageBase* page) 0139 { 0140 // save the old offset into the page so we can use it also on the new page 0141 setActivePage (page); 0142 0143 m_paCanvas->updateSize(); 0144 KoPageLayout& layout = page->pageLayout(); 0145 0146 QSizeF pageSize (layout.width, layout.height); 0147 //m_paCanvas->setDocumentOrigin(QPointF(layout.width, layout.height)); 0148 m_paCanvas->setDocumentOrigin (QPointF (0, 0)); 0149 // the page is in the center of the canvas 0150 m_paCanvas->resourceManager()->setResource (KoCanvasResourceManager::PageSize, pageSize); 0151 zoomController()->setPageSize(pageSize); 0152 zoomController()->setDocumentSize(pageSize); 0153 //zoomController()->setZoom(KoZoomMode::ZOOM_PAGE, 1); 0154 0155 m_paCanvas->updateSize(); 0156 QGraphicsItem* item = dynamic_cast<QGraphicsItem*> (m_paCanvas); 0157 item->update(); 0158 0159 proxyObject->emitActivePageChanged(); 0160 } 0161 0162 KoZoomController* CQPresentationView::zoomController() const 0163 { 0164 return m_zoomController; 0165 } 0166 0167 KoPADocument* CQPresentationView::kopaDocument() const 0168 { 0169 return m_prDocument; 0170 } 0171 0172 KoPACanvasBase* CQPresentationView::kopaCanvas() const 0173 { 0174 return m_paCanvas; 0175 } 0176 0177 void CQPresentationView::connectToZoomController() 0178 { 0179 connect (zoomController(), SIGNAL(zoomChanged(KoZoomMode::Mode,qreal)), SLOT(slotZoomChanged(KoZoomMode::Mode,qreal))); 0180 } 0181 0182 void CQPresentationView::slotZoomChanged (KoZoomMode::Mode mode, qreal zoom) 0183 { 0184 Q_UNUSED (zoom); 0185 if (m_page) { 0186 if (mode == KoZoomMode::ZOOM_PAGE) { 0187 KoPageLayout& layout = m_page->pageLayout(); 0188 QRectF pageRect (0, 0, layout.width, layout.height); 0189 m_canvasController->ensureVisible (m_paCanvas->viewConverter()->documentToView (pageRect)); 0190 } else if (mode == KoZoomMode::ZOOM_WIDTH) { 0191 // horizontally center the page 0192 KoPageLayout& layout = m_page->pageLayout(); 0193 QRectF pageRect (0, 0, layout.width, layout.height); 0194 QRect viewRect = m_paCanvas->viewConverter()->documentToView (pageRect).toRect(); 0195 viewRect.translate (m_paCanvas->documentOrigin()); 0196 QRect currentVisible (qMax (0, -m_canvasController->canvasOffsetX()), 0197 qMax (0, -m_canvasController->canvasOffsetY()), 0198 m_canvasController->visibleWidth(), 0199 m_canvasController->visibleHeight()); 0200 int horizontalMove = viewRect.center().x() - currentVisible.center().x(); 0201 m_canvasController->pan (QPoint (horizontalMove, 0)); 0202 } 0203 dynamic_cast<KoPACanvasItem*> (m_paCanvas)->update(); 0204 } 0205 } 0206 0207 void CQPresentationView::setZoomController(KoZoomController* controller) 0208 { 0209 m_zoomController = controller; 0210 }