1 /* This file is part of the KDE project 2 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> 3 Copyright (C) 2000-2005 David Faure <faure@kde.org> 4 Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org> 5 Copyright (C) 2010 Boudewijn Rempt <boud@kogmbh.com> 6 7 This library is free software; you can redistribute it and/or 8 modify it under the terms of the GNU Library General Public 9 License as published by the Free Software Foundation; either 10 version 2 of the License, or (at your option) any later version. 11 12 This library is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Library General Public License for more details. 16 17 You should have received a copy of the GNU Library General Public License 18 along with this library; see the file COPYING.LIB. If not, write to 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * Boston, MA 02110-1301, USA. 21 */ 22 23 #ifndef KOPART_H 24 #define KOPART_H 25 26 #include <QList> 27 #include <QUrl> 28 29 #include "komain_export.h" 30 31 #include <KoMainWindow.h> 32 33 class KoDocument; 34 class KoView; 35 class KoComponentData; 36 class KoOpenPane; 37 class QGraphicsItem; 38 39 40 /** 41 * Override this class in your application. It's the main entry point that 42 * should provide the document, the view and the component data to the calligra 43 * system. 44 * 45 * There is/will be a single KoPart instance for an application that will manage 46 * the list of documents, views and mainwindows. 47 * 48 * It hasn't got much to do with kparts anymore. 49 */ 50 class KOMAIN_EXPORT KoPart : public QObject 51 { 52 Q_OBJECT 53 54 public: 55 /** 56 * Constructor. 57 * 58 * @param componentData data about the component 59 * @param parent may be another KoDocument, or anything else. 60 * Usually passed by KPluginFactory::create. 61 */ 62 explicit KoPart(const KoComponentData &componentData, QObject *parent); 63 64 /** 65 * Destructor. 66 * 67 * The destructor does not delete any attached KoView objects and it does not 68 * delete the attached widget as returned by widget(). 69 */ 70 ~KoPart() override; 71 72 /** 73 * @return The componentData ( KoComponentData ) for this GUI client. You set the componentdata 74 * in your subclass: setComponentData(AppFactory::componentData()); in the constructor 75 */ 76 KoComponentData componentData() const; 77 78 /** 79 * @param document the document this part manages 80 */ 81 void setDocument(KoDocument *document); 82 83 /** 84 * @return the document this part loads and saves to and makes views for 85 */ 86 KoDocument *document() const; 87 88 // ----------------- mainwindow management ----------------- 89 90 /** 91 * Create a new main window, but does not add it to the current set of managed main windows. 92 */ 93 virtual KoMainWindow *createMainWindow() = 0; 94 95 /** 96 * Appends the mainwindow to the list of mainwindows which show this 97 * document as their root document. 98 * 99 * This method is automatically called from KoMainWindow::setRootDocument, 100 * so you do not need to call it. 101 */ 102 virtual void addMainWindow(KoMainWindow *mainWindow); 103 104 /** 105 * Removes the mainwindow from the list. 106 */ 107 virtual void removeMainWindow(KoMainWindow *mainWindow); 108 109 /** 110 * @return the list of main windows. 111 */ 112 const QList<KoMainWindow*>& mainWindows() const; 113 114 /** 115 * @return the number of shells for the main window 116 */ 117 int mainwindowCount() const; 118 119 void addRecentURLToAllMainWindows(const QUrl &url); 120 121 KoMainWindow *currentMainwindow() const; 122 123 public Q_SLOTS: 124 125 /** 126 * This slot loads an existing file and deletes the start up widget. 127 * @param url the file to load 128 */ 129 virtual void openExistingFile(const QUrl &url); 130 131 protected Q_SLOTS: 132 133 /** 134 * This slot loads a template and deletes the start up widget. 135 * @param url the template to load 136 */ 137 virtual void openTemplate(const QUrl &url); 138 139 private Q_SLOTS: 140 141 void startCustomDocument(); 142 143 144 public: 145 146 //------------------ view management ------------------ 147 148 /** 149 * Create a new view for the document. 150 */ 151 KoView *createView(KoDocument *document, QWidget *parent = 0); 152 153 /** 154 * Adds a view to the document. If the part doesn't know yet about 155 * the document, it is registered. 156 * 157 * This calls KoView::updateReadWrite to tell the new view 158 * whether the document is readonly or not. 159 */ 160 virtual void addView(KoView *view, KoDocument *document); 161 162 /** 163 * Removes a view of the document. 164 */ 165 virtual void removeView(KoView *view); 166 167 /** 168 * @return a list of views this document is displayed in 169 */ 170 QList<KoView*> views() const; 171 172 /** 173 * @return number of views this document is displayed in 174 */ 175 int viewCount() const; 176 177 /** 178 * @return a QGraphicsItem canvas displaying this document. There is only one QGraphicsItem canvas that can 179 * be shown by many QGraphicsView subclasses (those should reimplement KoCanvasController 180 * as well). 181 * 182 * @param create if true, a new canvas item is created if there wasn't one. 183 */ 184 QGraphicsItem *canvasItem(KoDocument *document, bool create = true); 185 186 // ------- startup/openpane etc --------------- 187 188 /** 189 * Template resource path used. This is used by the start up widget to show 190 * the correct templates. 191 */ 192 QString templatesResourcePath() const; 193 194 195 /** 196 * Creates and shows the start up widget. 197 * @param parent the KoMainWindow used as parent for the widget. 198 * @param alwaysShow always show the widget even if the user has configured it to not show. 199 */ 200 virtual void showStartUpWidget(KoMainWindow *parent, bool alwaysShow = false); 201 202 /** 203 * Removes the startupWidget shown at application start up. 204 */ 205 void deleteOpenPane(bool closing = false); 206 207 protected: 208 209 /** 210 * Set the templates resource path used. This is used by the start up widget to show 211 * the correct templates. 212 */ 213 void setTemplatesResourcePath(const QString &templatesResourcePath); 214 215 /** 216 * Struct used in the list created by createCustomDocumentWidgets() 217 */ 218 struct CustomDocumentWidgetItem { 219 /// Pointer to the custom document widget 220 QWidget *widget; 221 /// title used in the sidebar. If left empty it will be displayed as "Custom Document" 222 QString title; 223 /// icon used in the sidebar. If left empty it will use the unknown icon 224 QString icon; 225 }; 226 227 /** 228 * Override this method in your derived class to show a widget in the startup 'dialog'. 229 * This widget should allow the user to set settings for a custom document (i.e. one 230 * not based on a template). 231 * The returned widget should provide its own button (preferably 'Create') and 232 * implement the logic to implement the document instance correctly. 233 * After initializing the widget should emit a signal called 'documentSelected()' which 234 * will remove the startupWidget and show the document. 235 * @param parent the parent of the to be created widget. 236 * @return a list of KoDocument::CustomDocumentWidgetItem. 237 */ 238 virtual QList<CustomDocumentWidgetItem> createCustomDocumentWidgets(QWidget *parent); 239 240 /** 241 * Creates the open widget showed at application start up. 242 * @param parent the parent widget 243 * @param templateType the template-type (group) that should be selected on creation. 244 */ 245 KoOpenPane *createOpenPane(QWidget *parent, 246 const QString& templatesResourcePath = QString()); 247 248 virtual KoView *createViewInstance(KoDocument *document, QWidget *parent) = 0; 249 250 /** 251 * Override this to create a QGraphicsItem that does not rely 252 * on proxying a KoCanvasController. 253 */ 254 virtual QGraphicsItem *createCanvasItem(KoDocument *document); 255 256 private: 257 258 Q_DISABLE_COPY(KoPart) 259 260 class Private; 261 Private *const d; 262 263 }; 264 265 #endif 266