Warning, file /office/calligra/libs/main/KoMainWindow.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-2004 David Faure <faure@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef KOMAINWINDOW_H 0022 #define KOMAINWINDOW_H 0023 0024 #include "komain_export.h" 0025 0026 #include <kxmlguiwindow.h> 0027 #include <KoCanvasObserverBase.h> 0028 #include <KoCanvasSupervisor.h> 0029 0030 class KoMainWindowPrivate; 0031 class KoDocument; 0032 class KoPart; 0033 class KoView; 0034 class KoPrintJob; 0035 class KoDockFactoryBase; 0036 class KRecentFilesAction; 0037 class KoComponentData; 0038 class QDockWidget; 0039 0040 struct KoPageLayout; 0041 0042 // Calligra class but not in main module 0043 class KoDockerManager; 0044 class QUrl; 0045 0046 /** 0047 * @brief Main window for a Calligra application 0048 * 0049 * This class is used to represent a main window 0050 * of a Calligra component. Each main window contains 0051 * a menubar and some toolbars. 0052 * 0053 * @note This class does NOT need to be subclassed in your application. 0054 */ 0055 class KOMAIN_EXPORT KoMainWindow : public KXmlGuiWindow, public KoCanvasSupervisor 0056 { 0057 Q_OBJECT 0058 public: 0059 0060 /** 0061 * Constructor. 0062 * 0063 * Initializes a Calligra main window (with its basic GUI etc.). 0064 */ 0065 explicit KoMainWindow(const QByteArray &nativeMimeType, const KoComponentData &instance); 0066 0067 /** 0068 * Destructor. 0069 */ 0070 ~KoMainWindow() override; 0071 0072 // If noCleanup is set, KoMainWindow will not delete the root document 0073 // or part manager on destruction. 0074 void setNoCleanup(bool noCleanup); 0075 0076 /** 0077 * Called when a document is assigned to this mainwindow. 0078 * This creates a view for this document, makes it the active part, etc. 0079 */ 0080 void setRootDocument(KoDocument *doc, KoPart *part = 0, bool deletePrevious = true); 0081 0082 /** 0083 * This is used to handle the document used at start up before it actually 0084 * added as root document. 0085 */ 0086 void setPartToOpen(KoPart *part); 0087 0088 /** 0089 * Update caption from document info - call when document info 0090 * (title in the about page) changes. 0091 */ 0092 void updateCaption(); 0093 0094 KoComponentData componentData() const; 0095 void setComponentData(const KoComponentData &componentData); 0096 0097 /** 0098 * Retrieves the document that is displayed in the mainwindow. 0099 */ 0100 KoDocument *rootDocument() const; 0101 KoView *rootView() const; 0102 0103 /** 0104 * The application should call this to show or hide a toolbar. 0105 * It also takes care of the corresponding action in the settings menu. 0106 */ 0107 void showToolbar(const char * tbName, bool shown); 0108 0109 /** 0110 * @return TRUE if the toolbar @p tbName is visible 0111 */ 0112 bool toolbarIsVisible(const char *tbName); 0113 0114 /** 0115 * Sets the maximum number of recent documents entries. 0116 */ 0117 void setMaxRecentItems(uint _number); 0118 0119 /** 0120 * The document opened a URL -> store into recent documents list. 0121 */ 0122 void addRecentURL(const QUrl &url); 0123 0124 /** 0125 * Load the desired document and show it. 0126 * @param url the URL to open 0127 * 0128 * @return TRUE on success. 0129 */ 0130 bool openDocument(const QUrl &url); 0131 0132 /** 0133 * Load the URL into this document (and make it root doc after loading) 0134 * 0135 * Special method for KoApplication::start, don't use. 0136 */ 0137 bool openDocument(KoPart *newPart, const QUrl &url); 0138 0139 /** 0140 * Reloads the recent documents list. 0141 */ 0142 void reloadRecentFileList(); 0143 0144 /** 0145 * Updates the window caption based on the document info and path. 0146 */ 0147 void updateCaption(const QString & caption, bool mod); 0148 void updateReloadFileAction(KoDocument *doc); 0149 void updateVersionsFileAction(KoDocument *doc); 0150 0151 void setReadWrite(bool readwrite); 0152 0153 /** 0154 * Returns the dockwidget specified by the @p factory. If the dock widget doesn't exist yet it's created. 0155 * Add a "view_palette_action_menu" action to your view menu if you want to use closable dock widgets. 0156 * @param factory the factory used to create the dock widget if needed 0157 * @return the dock widget specified by @p factory (may be 0) 0158 */ 0159 QDockWidget* createDockWidget(KoDockFactoryBase* factory); 0160 0161 /// Return the list of dock widgets belonging to this main window. 0162 QList<QDockWidget*> dockWidgets() const; 0163 0164 QList<KoCanvasObserverBase*> canvasObservers() const override; 0165 0166 /** 0167 * @return the KoDockerManager which is assigned 0168 * WARNING: this could be 0, if no docker have been assigned yet. In that case create one 0169 * and assign it. 0170 * Note This should only be called by KoView 0171 * setDockerManager to assign it. 0172 */ 0173 KoDockerManager * dockerManager() const; 0174 0175 Q_SIGNALS: 0176 /** 0177 * This signal is emitted if the document has been saved successfully. 0178 */ 0179 void documentSaved(); 0180 /// This signals is emitted before the save dialog is shown 0181 void saveDialogShown(); 0182 0183 /// This signal is emitted right after the docker states have been successfully restored from config 0184 void restoringDone(); 0185 0186 /// This signal is emitted when this windows has finished loading of a 0187 /// document. The document may be opened in another window in the end. 0188 /// In this case, the signal means there is no link between the window 0189 /// and the document anymore. 0190 void loadCompleted(KoMainWindow *); 0191 0192 /// This signal is emitted when this windows has canceled loading of a document. 0193 void loadCanceled(); 0194 0195 /// This signal is emitted when the color theme changes 0196 void themeChanged(); 0197 0198 /// This signal is emitted when the shortcut key configuration has changed 0199 void keyBindingsChanged(); 0200 0201 public Q_SLOTS: 0202 0203 /** 0204 * Slot for eMailing the document using KMail 0205 * 0206 * This is a very simple extension that will allow any document 0207 * that is currently being edited to be emailed using KMail. 0208 */ 0209 void slotEmailFile(); 0210 0211 /** 0212 * Slot for opening a new document. 0213 * 0214 * If the current document is empty, the new document replaces it. 0215 * If not, a new mainwindow will be opened for showing the document. 0216 */ 0217 void slotFileNew(); 0218 0219 /** 0220 * Slot for opening a saved file. 0221 * 0222 * If the current document is empty, the opened document replaces it. 0223 * If not a new mainwindow will be opened for showing the opened file. 0224 */ 0225 void slotFileOpen(); 0226 0227 /** 0228 * Slot for opening a file among the recently opened files. 0229 * 0230 * If the current document is empty, the opened document replaces it. 0231 * If not a new mainwindow will be opened for showing the opened file. 0232 */ 0233 void slotFileOpenRecent(const QUrl &); 0234 0235 /** 0236 * Saves the current document with the current name. 0237 */ 0238 void slotFileSave(); 0239 0240 /** 0241 * Saves the current document with a new name. 0242 */ 0243 void slotFileSaveAs(); 0244 0245 /** 0246 * Prints the actual document. 0247 */ 0248 void slotFilePrint(); 0249 void slotFilePrintPreview(); 0250 0251 KoPrintJob* exportToPdf(const QString &pdfFileName = QString()); 0252 KoPrintJob* exportToPdf(const KoPageLayout &pageLayout, const QString &pdfFileName = QString()); 0253 0254 /** 0255 * Show a dialog with author and document information. 0256 */ 0257 void slotDocumentInfo(); 0258 0259 /** 0260 * Closes the document. 0261 */ 0262 void slotFileClose(); 0263 0264 /** 0265 * Closes the mainwindow. 0266 */ 0267 void slotFileQuit(); 0268 0269 /** 0270 * Configure key bindings. 0271 */ 0272 void slotConfigureKeys(); 0273 0274 /** 0275 * Configure toolbars. 0276 */ 0277 void slotConfigureToolbars(); 0278 0279 /** 0280 * Post toolbar config. 0281 * (Plug action lists back in, etc.) 0282 */ 0283 void slotNewToolbarConfig(); 0284 0285 /** 0286 * Shows or hides a toolbar 0287 */ 0288 void slotToolbarToggled(bool toggle); 0289 0290 /** 0291 * Toggle full screen on/off. 0292 */ 0293 void viewFullscreen(bool fullScreen); 0294 0295 /** 0296 * Toggle docker titlebars on/off. 0297 */ 0298 void showDockerTitleBars(bool show); 0299 0300 /** 0301 * Reload file 0302 */ 0303 void slotReloadFile(); 0304 0305 /** 0306 * This will call a dialogbox to add version to list of files 0307 */ 0308 void slotVersionsFile(); 0309 0310 /** 0311 * File --> Import 0312 * 0313 * This will call slotFileOpen(). To differentiate this from an ordinary 0314 * call to slotFileOpen() call isImporting(). 0315 */ 0316 void slotImportFile(); 0317 0318 /** 0319 * File --> Export 0320 * 0321 * This will call slotFileSaveAs(). To differentiate this from an ordinary 0322 * call to slotFileSaveAs() call isExporting(). 0323 */ 0324 void slotExportFile(); 0325 0326 void slotEncryptDocument(); 0327 void slotUncompressToDir(); 0328 0329 void slotProgress(int value); 0330 0331 /** 0332 * Hide the dockers 0333 */ 0334 void toggleDockersVisibility(bool visible); 0335 0336 /** 0337 * Saves the document, asking for a filename if necessary. 0338 * 0339 * @param saveas if set to TRUE the user is always prompted for a filename 0340 * 0341 * @param silent if set to TRUE rootDocument()->setTitleModified will not be called. 0342 * 0343 * @param specialOutputFlag set to enums defined in KoDocument if save to special output format 0344 * 0345 * @return TRUE on success, false on error or cancel 0346 * (don't display anything in this case, the error dialog box is also implemented here 0347 * but restore the original URL in slotFileSaveAs) 0348 */ 0349 bool saveDocument(bool saveas = false, bool silent = false, int specialOutputFlag = 0); 0350 0351 private: 0352 0353 /** 0354 * This setting indicates who is calling chooseNewDocument. 0355 * Usually the app will want to 0356 * - show the template dialog with 'everything' if InitDocAppStarting, InitDocFileClose or InitDocEmbedded 0357 * - show the template dialog with 'templates only' if InitDocFileNew 0358 * - create an empty document with default settings if InitDocEmpty 0359 */ 0360 enum InitDocFlags { /*InitDocAppStarting, */ InitDocFileNew, InitDocFileClose /*, InitDocEmbedded, InitDocEmpty*/ }; 0361 0362 /// Helper method for slotFileNew and slotFileClose 0363 void chooseNewDocument(InitDocFlags initDocFlags); 0364 0365 /** 0366 * Create a new empty document. 0367 */ 0368 KoPart* createPart() const; 0369 0370 void closeEvent(QCloseEvent * e) override; 0371 void resizeEvent(QResizeEvent * e) override; 0372 0373 /** 0374 * Ask user about saving changes to the document upon exit. 0375 */ 0376 bool queryClose() override; 0377 0378 bool openDocumentInternal(const QUrl &url, KoPart *newpart = 0, KoDocument *newdoc = 0); 0379 0380 /** 0381 * Returns whether or not the current slotFileSave[As]() or saveDocument() 0382 * call is actually an export operation (like File --> Export). 0383 * 0384 * If this is true, you must call KoDocument::export() instead of 0385 * KoDocument::save() or KoDocument::saveAs(), in any reimplementation of 0386 * saveDocument(). 0387 */ 0388 bool isExporting() const; 0389 0390 /** 0391 * Returns whether or not the current slotFileOpen() or openDocument() 0392 * call is actually an import operation (like File --> Import). 0393 * 0394 * If this is true, you must call KoDocument::import() instead of 0395 * KoDocument::openUrl(), in any reimplementation of openDocument() or 0396 * openDocumentInternal(). 0397 */ 0398 bool isImporting() const; 0399 0400 KRecentFilesAction *recentAction() const; 0401 0402 private Q_SLOTS: 0403 /** 0404 * Save the list of recent files. 0405 */ 0406 void saveRecentFiles(); 0407 0408 void slotLoadCompleted(); 0409 void slotLoadCanceled(const QString &); 0410 void slotSaveCompleted(); 0411 void slotSaveCanceled(const QString &); 0412 void forceDockTabFonts(); 0413 0414 /** 0415 * Slot to create a new view for the currently activate @ref #koDocument. 0416 */ 0417 virtual void newView(); 0418 0419 0420 // --------------------- PartManager 0421 private: 0422 0423 friend class KoPart; 0424 /** 0425 * Removes a part from the manager (this does not delete the object) . 0426 * 0427 * Sets the active part to 0 if @p part is the activePart() . 0428 */ 0429 virtual void removePart( KoPart *part ); 0430 0431 /** 0432 * Sets the active part. 0433 * 0434 * The active part receives activation events. 0435 * 0436 * @p widget can be used to specify which widget was responsible for the activation. 0437 * This is important if you have multiple views for a document/part , like in KOffice . 0438 */ 0439 virtual void setActivePart(KoPart *part, QWidget *widget); 0440 0441 private Q_SLOTS: 0442 0443 /** 0444 * @internal 0445 */ 0446 void slotWidgetDestroyed(); 0447 void slotDocumentTitleModified(const QString &caption, bool mod); 0448 0449 // --------------------- PartManager 0450 0451 private: 0452 0453 void createMainwindowGUI(); 0454 0455 /** 0456 * Asks the user if they really want to save the document. 0457 * Called only if outputFormat != nativeFormat. 0458 * 0459 * @return true if the document should be saved 0460 */ 0461 bool exportConfirmation(const QByteArray &outputFormat); 0462 0463 void saveWindowSettings(); 0464 0465 // retrieve the current KoView 0466 KoView* currentView() const; 0467 0468 private: 0469 0470 KoMainWindowPrivate * const d; 0471 }; 0472 0473 #endif