Warning, file /office/calligra/libs/main/KoPart.h 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) 1998, 1999 Torben Weis <weis@kde.org> 0003 Copyright (C) 2000-2005 David Faure <faure@kde.org> 0004 Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org> 0005 Copyright (C) 2010 Boudewijn Rempt <boud@kogmbh.com> 0006 0007 This library is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU Library General Public 0009 License as published by the Free Software Foundation; either 0010 version 2 of the License, or (at your option) any later version. 0011 0012 This library is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 Library General Public License for more details. 0016 0017 You should have received a copy of the GNU Library General Public License 0018 along with this library; see the file COPYING.LIB. If not, write to 0019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 * Boston, MA 02110-1301, USA. 0021 */ 0022 0023 #ifndef KOPART_H 0024 #define KOPART_H 0025 0026 #include <QList> 0027 #include <QUrl> 0028 0029 #include "komain_export.h" 0030 0031 #include <KoMainWindow.h> 0032 0033 class KoDocument; 0034 class KoView; 0035 class KoComponentData; 0036 class KoOpenPane; 0037 class QGraphicsItem; 0038 0039 0040 /** 0041 * Override this class in your application. It's the main entry point that 0042 * should provide the document, the view and the component data to the calligra 0043 * system. 0044 * 0045 * There is/will be a single KoPart instance for an application that will manage 0046 * the list of documents, views and mainwindows. 0047 * 0048 * It hasn't got much to do with kparts anymore. 0049 */ 0050 class KOMAIN_EXPORT KoPart : public QObject 0051 { 0052 Q_OBJECT 0053 0054 public: 0055 /** 0056 * Constructor. 0057 * 0058 * @param componentData data about the component 0059 * @param parent may be another KoDocument, or anything else. 0060 * Usually passed by KPluginFactory::create. 0061 */ 0062 explicit KoPart(const KoComponentData &componentData, QObject *parent); 0063 0064 /** 0065 * Destructor. 0066 * 0067 * The destructor does not delete any attached KoView objects and it does not 0068 * delete the attached widget as returned by widget(). 0069 */ 0070 ~KoPart() override; 0071 0072 /** 0073 * @return The componentData ( KoComponentData ) for this GUI client. You set the componentdata 0074 * in your subclass: setComponentData(AppFactory::componentData()); in the constructor 0075 */ 0076 KoComponentData componentData() const; 0077 0078 /** 0079 * @param document the document this part manages 0080 */ 0081 void setDocument(KoDocument *document); 0082 0083 /** 0084 * @return the document this part loads and saves to and makes views for 0085 */ 0086 KoDocument *document() const; 0087 0088 // ----------------- mainwindow management ----------------- 0089 0090 /** 0091 * Create a new main window, but does not add it to the current set of managed main windows. 0092 */ 0093 virtual KoMainWindow *createMainWindow() = 0; 0094 0095 /** 0096 * Appends the mainwindow to the list of mainwindows which show this 0097 * document as their root document. 0098 * 0099 * This method is automatically called from KoMainWindow::setRootDocument, 0100 * so you do not need to call it. 0101 */ 0102 virtual void addMainWindow(KoMainWindow *mainWindow); 0103 0104 /** 0105 * Removes the mainwindow from the list. 0106 */ 0107 virtual void removeMainWindow(KoMainWindow *mainWindow); 0108 0109 /** 0110 * @return the list of main windows. 0111 */ 0112 const QList<KoMainWindow*>& mainWindows() const; 0113 0114 /** 0115 * @return the number of shells for the main window 0116 */ 0117 int mainwindowCount() const; 0118 0119 void addRecentURLToAllMainWindows(const QUrl &url); 0120 0121 KoMainWindow *currentMainwindow() const; 0122 0123 public Q_SLOTS: 0124 0125 /** 0126 * This slot loads an existing file and deletes the start up widget. 0127 * @param url the file to load 0128 */ 0129 virtual void openExistingFile(const QUrl &url); 0130 0131 protected Q_SLOTS: 0132 0133 /** 0134 * This slot loads a template and deletes the start up widget. 0135 * @param url the template to load 0136 */ 0137 virtual void openTemplate(const QUrl &url); 0138 0139 private Q_SLOTS: 0140 0141 void startCustomDocument(); 0142 0143 0144 public: 0145 0146 //------------------ view management ------------------ 0147 0148 /** 0149 * Create a new view for the document. 0150 */ 0151 KoView *createView(KoDocument *document, QWidget *parent = 0); 0152 0153 /** 0154 * Adds a view to the document. If the part doesn't know yet about 0155 * the document, it is registered. 0156 * 0157 * This calls KoView::updateReadWrite to tell the new view 0158 * whether the document is readonly or not. 0159 */ 0160 virtual void addView(KoView *view, KoDocument *document); 0161 0162 /** 0163 * Removes a view of the document. 0164 */ 0165 virtual void removeView(KoView *view); 0166 0167 /** 0168 * @return a list of views this document is displayed in 0169 */ 0170 QList<KoView*> views() const; 0171 0172 /** 0173 * @return number of views this document is displayed in 0174 */ 0175 int viewCount() const; 0176 0177 /** 0178 * @return a QGraphicsItem canvas displaying this document. There is only one QGraphicsItem canvas that can 0179 * be shown by many QGraphicsView subclasses (those should reimplement KoCanvasController 0180 * as well). 0181 * 0182 * @param create if true, a new canvas item is created if there wasn't one. 0183 */ 0184 QGraphicsItem *canvasItem(KoDocument *document, bool create = true); 0185 0186 // ------- startup/openpane etc --------------- 0187 0188 /** 0189 * Template resource path used. This is used by the start up widget to show 0190 * the correct templates. 0191 */ 0192 QString templatesResourcePath() const; 0193 0194 0195 /** 0196 * Creates and shows the start up widget. 0197 * @param parent the KoMainWindow used as parent for the widget. 0198 * @param alwaysShow always show the widget even if the user has configured it to not show. 0199 */ 0200 virtual void showStartUpWidget(KoMainWindow *parent, bool alwaysShow = false); 0201 0202 /** 0203 * Removes the startupWidget shown at application start up. 0204 */ 0205 void deleteOpenPane(bool closing = false); 0206 0207 protected: 0208 0209 /** 0210 * Set the templates resource path used. This is used by the start up widget to show 0211 * the correct templates. 0212 */ 0213 void setTemplatesResourcePath(const QString &templatesResourcePath); 0214 0215 /** 0216 * Struct used in the list created by createCustomDocumentWidgets() 0217 */ 0218 struct CustomDocumentWidgetItem { 0219 /// Pointer to the custom document widget 0220 QWidget *widget; 0221 /// title used in the sidebar. If left empty it will be displayed as "Custom Document" 0222 QString title; 0223 /// icon used in the sidebar. If left empty it will use the unknown icon 0224 QString icon; 0225 }; 0226 0227 /** 0228 * Override this method in your derived class to show a widget in the startup 'dialog'. 0229 * This widget should allow the user to set settings for a custom document (i.e. one 0230 * not based on a template). 0231 * The returned widget should provide its own button (preferably 'Create') and 0232 * implement the logic to implement the document instance correctly. 0233 * After initializing the widget should emit a signal called 'documentSelected()' which 0234 * will remove the startupWidget and show the document. 0235 * @param parent the parent of the to be created widget. 0236 * @return a list of KoDocument::CustomDocumentWidgetItem. 0237 */ 0238 virtual QList<CustomDocumentWidgetItem> createCustomDocumentWidgets(QWidget *parent); 0239 0240 /** 0241 * Creates the open widget showed at application start up. 0242 * @param parent the parent widget 0243 * @param templateType the template-type (group) that should be selected on creation. 0244 */ 0245 KoOpenPane *createOpenPane(QWidget *parent, 0246 const QString& templatesResourcePath = QString()); 0247 0248 virtual KoView *createViewInstance(KoDocument *document, QWidget *parent) = 0; 0249 0250 /** 0251 * Override this to create a QGraphicsItem that does not rely 0252 * on proxying a KoCanvasController. 0253 */ 0254 virtual QGraphicsItem *createCanvasItem(KoDocument *document); 0255 0256 private: 0257 0258 Q_DISABLE_COPY(KoPart) 0259 0260 class Private; 0261 Private *const d; 0262 0263 }; 0264 0265 #endif