File indexing completed on 2024-05-26 16:15:03
0001 /* This file is part of the KDE project 0002 Copyright (C) 2006-2010 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 #ifndef KOPADOCUMENT_H 0021 #define KOPADOCUMENT_H 0022 0023 #include <KoOdf.h> 0024 #include <KoDocument.h> 0025 #include <KoShapeBasedDocumentBase.h> 0026 #include "KoPageApp.h" 0027 #include "kopageapp_export.h" 0028 0029 class KoPAPage; 0030 class KoPAPageBase; 0031 class KoPAMasterPage; 0032 class KoPALoadingContext; 0033 class KoPASavingContext; 0034 0035 class KoInlineTextObjectManager; 0036 0037 /// Document class that stores KoPAPage and KoPAMasterPage objects 0038 class KOPAGEAPP_EXPORT KoPADocument : public KoDocument, public KoShapeBasedDocumentBase 0039 { 0040 Q_OBJECT 0041 public: 0042 0043 explicit KoPADocument(KoPart *part); 0044 ~KoPADocument() override; 0045 0046 QPixmap generatePreview(const QSize& size) override; 0047 void paintContent( QPainter &painter, const QRect &rect) override; 0048 0049 bool loadXML( const KoXmlDocument & doc, KoStore *store ) override; 0050 bool loadOdf( KoOdfReadStore & odfStore ) override; 0051 0052 bool saveOdf( SavingContext & documentContext ) override; 0053 0054 /** 0055 * The tag the body is saved in 0056 */ 0057 virtual const char *odfTagName( bool withNamespace ) = 0; 0058 0059 /** 0060 * Load master pages 0061 * 0062 * @param masterStyles 0063 * @param context 0064 */ 0065 QList<KoPAPageBase *> loadOdfMasterPages( const QHash<QString, KoXmlElement*> masterStyles, KoPALoadingContext & context ); 0066 0067 /** 0068 * Save pages 0069 * 0070 * This is used by saveOdf and for copy and paste of pages. 0071 * 0072 * For all pages that are specified also the master slide has to be specified. 0073 */ 0074 bool saveOdfPages( KoPASavingContext & paContext, QList<KoPAPageBase *> &pages, QList<KoPAPageBase *> &masterPages ); 0075 0076 /** 0077 * Save document styles 0078 */ 0079 virtual void saveOdfDocumentStyles( KoPASavingContext & context ); 0080 0081 /** 0082 * Load document styles 0083 */ 0084 virtual bool loadOdfDocumentStyles( KoPALoadingContext & context ); 0085 0086 /** 0087 * Get page by index. 0088 * 0089 * @param index of the page 0090 * @param masterPage if true return a masterPage, if false a normal page 0091 */ 0092 KoPAPageBase* pageByIndex( int index, bool masterPage ) const; 0093 0094 /// reimplemnted 0095 int pageCount() const override; 0096 0097 /** 0098 * Get the index of the page 0099 * 0100 * @param page The page you want to get the index for 0101 * 0102 * @return The index of the page or -1 if the page is not found 0103 */ 0104 int pageIndex( KoPAPageBase * page ) const; 0105 0106 /** 0107 * Get page by navigation 0108 * 0109 * @param currentPage the current page 0110 * @param pageNavigation how to navigate from the current page 0111 * 0112 * @return the page which is reached by pageNavigation 0113 */ 0114 KoPAPageBase* pageByNavigation( KoPAPageBase * currentPage, KoPageApp::PageNavigation pageNavigation ) const; 0115 0116 /** 0117 * Insert page to the document at index 0118 * 0119 * The function checks if it is a normal or a master page and puts it in 0120 * the correct list. 0121 * 0122 * @param page to insert to document 0123 * @param index where the page will be inserted. 0124 */ 0125 void insertPage( KoPAPageBase* page, int index ); 0126 0127 /** 0128 * Insert @p page to the document after page @p before 0129 * 0130 * The function checks if it is a normal or a master page and puts it in 0131 * the correct list. 0132 * 0133 * @param page to insert to document 0134 * @param after the page which the inserted page should come after. Set after to 0 to add at the beginning 0135 */ 0136 void insertPage( KoPAPageBase* page, KoPAPageBase* after ); 0137 0138 /** 0139 * Take @page from the page 0140 * 0141 * @param page taken from the document 0142 * @return the position of the page was taken from the document, or -1 if the page was not found 0143 */ 0144 int takePage( KoPAPageBase *page ); 0145 0146 /** 0147 * Remove the page from the document 0148 * 0149 * This generates the command and adds the command that deletes the page 0150 * 0151 * @param page The page that gets removed 0152 */ 0153 virtual void removePage( KoPAPageBase * page ); 0154 0155 /** 0156 * Remove the given pages from the document 0157 * 0158 * This generates the command and adds the command that deletes the pages 0159 * 0160 * @param pages The list of pages that gets removed 0161 */ 0162 virtual void removePages(QList<KoPAPageBase*> &pages); 0163 0164 void addShape( KoShape *shape ) override; 0165 void removeShape( KoShape* shape ) override; 0166 0167 QList<KoPAPageBase*> pages( bool masterPages = false ) const; 0168 0169 /** 0170 * Get a new page for inserting into the document 0171 * 0172 * The page is created with new. 0173 * 0174 * Reimplement when you need a derived class in your kopageapplication 0175 */ 0176 virtual KoPAPage *newPage(KoPAMasterPage *masterPage); 0177 0178 /** 0179 * Get a new master page for inserting into the document 0180 * 0181 * The page is created with new. 0182 * 0183 * Reimplement when you need a derived class in your kopageapplication 0184 */ 0185 virtual KoPAMasterPage * newMasterPage(); 0186 0187 /** 0188 * Get the type of the document 0189 */ 0190 virtual KoOdf::DocumentType documentType() const = 0; 0191 0192 0193 /// return the inlineTextObjectManager for this document. 0194 KoInlineTextObjectManager *inlineTextObjectManager() const; 0195 0196 void setRulersVisible(bool visible); 0197 bool rulersVisible() const; 0198 0199 /** 0200 * Get the page on which the shape is located 0201 * 0202 * @param shape The shape for which the page should be found 0203 * @return The page on which the shape is located 0204 */ 0205 KoPAPageBase * pageByShape( KoShape * shape ) const; 0206 0207 /** 0208 * Get the page type used in the document 0209 * 0210 * The default page type KoPageApp::Page is returned 0211 */ 0212 virtual KoPageApp::PageType pageType() const; 0213 0214 /** 0215 * Get the thumbnail for the page. 0216 * 0217 * Use this method instead the one in the pages directly 0218 */ 0219 QPixmap pageThumbnail(KoPAPageBase* page, const QSize& size); 0220 0221 QImage pageThumbImage(KoPAPageBase* page, const QSize& size); 0222 0223 void emitUpdate(KoPAPageBase *page) {emit update(page);} 0224 0225 /** 0226 * Sets where "defaultstyles.xml" can be found in the "data" locations. 0227 * Needs to be set before the document is loaded. 0228 * @param defaultStylesResourcePath the relative path from the data locations 0229 */ 0230 void setDefaultStylesResourcePath(const QString &defaultStylesResourcePath); 0231 QString defaultStylesResourcePath() const; 0232 0233 void setShowPageMargins(bool state); 0234 bool showPageMargins() const; 0235 0236 public Q_SLOTS: 0237 /// reimplemented 0238 void initEmpty() override; 0239 0240 Q_SIGNALS: 0241 void shapeAdded(KoShape* shape); 0242 void shapeRemoved(KoShape* shape); 0243 void pageAdded(KoPAPageBase* page); 0244 0245 /// This is a general signal to tell you a page was removed 0246 void pageRemoved(KoPAPageBase* page, int index = -1); 0247 0248 /// when page is removed this signal indicates you should replace it if it was active 0249 void replaceActivePage(KoPAPageBase *page, KoPAPageBase *newActivePage); 0250 0251 /** 0252 * Update all views this document is displayed on 0253 * 0254 * @param page specify a page to be updated, all views with this page as active page will be updated. 0255 */ 0256 void update(KoPAPageBase *page); 0257 0258 /** 0259 * @brief Tells if an action is possible or not 0260 * 0261 * The actions are of Type KoPAAction 0262 * 0263 * @param actions bitwise or of which actions should be enabled/disabled 0264 * @param possible new state of the actions 0265 */ 0266 void actionsPossible(int actions, bool enable); 0267 0268 protected: 0269 /** 0270 * Load the presentation declaration 0271 * 0272 * The default implementation is empty 0273 */ 0274 virtual bool loadOdfProlog( const KoXmlElement & body, KoPALoadingContext & context ); 0275 0276 0277 /** 0278 * Load the epilogue 0279 * 0280 * The default implementation is empty 0281 */ 0282 virtual bool loadOdfEpilogue( const KoXmlElement & body, KoPALoadingContext & context ); 0283 0284 /** 0285 * Save the prologue 0286 * 0287 * The default implementation is empty 0288 */ 0289 virtual bool saveOdfProlog( KoPASavingContext & paContext ); 0290 0291 /** 0292 * Save the epilogue 0293 * 0294 * The default implementation is empty 0295 */ 0296 virtual bool saveOdfEpilogue( KoPASavingContext & paContext ); 0297 0298 /** 0299 * Save settings 0300 */ 0301 bool saveOdfSettings( KoStore * store ); 0302 0303 /** 0304 * Load settings 0305 */ 0306 void loadOdfSettings( const KoXmlDocument & settingsDoc ); 0307 0308 /** 0309 * This function is called by at the end of addShape. This is used 0310 * e.g. for doing work on the application which is in the KoShapeAppData. 0311 * 0312 * The default implementation does nothing 0313 */ 0314 virtual void postAddShape( KoPAPageBase * page, KoShape * shape ); 0315 0316 /** 0317 * This function is called by at the end of removeShape. This is used 0318 * e.g. for doing work on the application which is in the KoShapeAppData. 0319 * 0320 * The default implementation does nothing 0321 */ 0322 virtual void postRemoveShape( KoPAPageBase * page, KoShape * shape ); 0323 0324 /** 0325 * This function is called with the command that will remove the page 0326 * given. 0327 * The default implementation is empty. 0328 * 0329 * @param page The page that will be removed 0330 * @param parent The command that will be used to delete the page 0331 */ 0332 virtual void pageRemoved( KoPAPageBase * page, KUndo2Command * parent ); 0333 0334 /// Load the configuration 0335 void loadConfig(); 0336 /// Save the configuration 0337 void saveConfig(); 0338 0339 /// set the page count so it gets shown correctly in variables 0340 void updatePageCount(); 0341 0342 /// set the url so it gets shown correctly in variables 0343 void updateDocumentURL(); 0344 0345 void setupOpenFileSubProgress() override; 0346 0347 private: 0348 0349 friend class KoPAPastePage; 0350 /** 0351 * Load pages 0352 * 0353 * @param body 0354 * @param context 0355 */ 0356 QList<KoPAPageBase *> loadOdfPages( const KoXmlElement & body, KoPALoadingContext & context ); 0357 0358 0359 private: 0360 class Private; 0361 Private * const d; 0362 }; 0363 0364 #endif /* KOPADOCUMENT_H */