1
/* This file is part of the KDE project
2
Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3
Copyright (C) 2000-2004 David Faure <faure@kde.org>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
Boston, MA 02110-1301, USA.
21
#ifndef KOMAINWINDOW_H
22
#define KOMAINWINDOW_H
24
#include "komain_export.h"
26
#include <kxmlguiwindow.h>
27
//#include <KoCanvasObserverBase.h>
28
//#include <KoCanvasSupervisor.h>
30
class KoMainWindowPrivate;
35
class KoDockFactoryBase;
36
class KRecentFilesAction;
37
class KoComponentData;
42
// Calligra class but not in main module
46
* @brief Main window for a Calligra application
48
* This class is used to represent a main window
49
* of a Calligra component. Each main window contains
50
* a menubar and some toolbars.
52
* @note This class does NOT need to be subclassed in your application.
54
class KOMAIN_EXPORT KoMainWindow : public KXmlGuiWindow//, public KoCanvasSupervisor
62
* Initializes a Calligra main window (with its basic GUI etc.).
64
explicit KoMainWindow(const QByteArray &nativeMimeType, const KoComponentData &instance);
69
virtual ~KoMainWindow();
71
// If noCleanup is set, KoMainWindow will not delete the root document
72
// or part manager on destruction.
73
void setNoCleanup(bool noCleanup);
76
* Called when a document is assigned to this mainwindow.
77
* This creates a view for this document, makes it the active part, etc.
79
void setRootDocument(KoDocument *doc, KoPart *part = 0, bool deletePrevious = true);
82
* This is used to handle the document used at start up before it actually
83
* added as root document.
85
void setPartToOpen(KoPart *part);
88
* Update caption from document info - call when document info
89
* (title in the about page) changes.
93
KoComponentData componentData() const;
94
void setComponentData(const KoComponentData &componentData);
97
* Retrieves the document that is displayed in the mainwindow.
99
KoDocument *rootDocument() const;
100
KoView *rootView() const;
103
* The application should call this to show or hide a toolbar.
104
* It also takes care of the corresponding action in the settings menu.
106
void showToolbar(const char * tbName, bool shown);
109
* @return TRUE if the toolbar @p tbName is visible
111
bool toolbarIsVisible(const char *tbName);
114
* Sets the maximum number of recent documents entries.
116
void setMaxRecentItems(uint _number);
119
* The document opened a URL -> store into recent documents list.
121
void addRecentURL(const QUrl &url);
124
* Load the desired document and show it.
125
* @param url the URL to open
127
* @return TRUE on success.
129
bool openDocument(const QUrl &url);
132
* Load the URL into this document (and make it root doc after loading)
134
* Special method for KoApplication::start, don't use.
136
bool openDocument(KoPart *newPart, const QUrl &url);
139
* Reloads the recent documents list.
141
void reloadRecentFileList();
144
* Updates the window caption based on the document info and path.
146
void updateCaption(const QString & caption, bool mod);
147
void updateReloadFileAction(KoDocument *doc);
149
void setReadWrite(bool readwrite);
152
* Returns the dockwidget specified by the @p factory. If the dock widget doesn't exist yet it's created.
153
* Add a "view_palette_action_menu" action to your view menu if you want to use closable dock widgets.
154
* @param factory the factory used to create the dock widget if needed
155
* @return the dock widget specified by @p factory (may be 0)
157
QDockWidget* createDockWidget(KoDockFactoryBase* factory);
159
/// Return the list of dock widgets belonging to this main window.
160
QList<QDockWidget*> dockWidgets() const;
162
// QList<KoCanvasObserverBase*> canvasObservers() const;
166
* This signal is emitted if the document has been saved successfully.
168
void documentSaved();
169
/// This signals is emmitted before the save dialog is shown
170
void saveDialogShown();
172
/// This signal is emitted right after the docker states have been succefully restored from config
173
void restoringDone();
175
/// This signal is emitted when this windows has finished loading of a
176
/// document. The document may be opened in another window in the end.
177
/// In this case, the signal means there is no link between the window
178
/// and the document anymore.
179
void loadCompleted();
181
/// This signal is emitted when the color theme changes
184
/// This signal is emitted when the shortcut key configuration has changed
185
void keyBindingsChanged();
190
* Slot for eMailing the document using KMail
192
* This is a very simple extension that will allow any document
193
* that is currently being edited to be emailed using KMail.
195
void slotEmailFile();
198
* Slot for opening a new document.
200
* If the current document is empty, the new document replaces it.
201
* If not, a new mainwindow will be opened for showing the document.
206
* Slot for opening a saved file.
208
* If the current document is empty, the opened document replaces it.
209
* If not a new mainwindow will be opened for showing the opened file.
214
* Slot for opening a file among the recently opened files.
216
* If the current document is empty, the opened document replaces it.
217
* If not a new mainwindow will be opened for showing the opened file.
219
void slotFileOpenRecent(const QUrl &);
222
* Saves the current document with the current name.
227
* Saves the current document with a new name.
229
void slotFileSaveAs();
232
* Prints the actual document.
234
void slotFilePrint();
235
void slotFilePrintPreview();
237
KoPrintJob* exportToPdf(const QString &pdfFileName = QString());
240
* Show a dialog with author and document information.
242
void slotDocumentInfo();
245
* Closes the document.
247
void slotFileClose();
250
* Closes the mainwindow.
255
* Configure key bindings.
257
void slotConfigureKeys();
260
* Configure toolbars.
262
void slotConfigureToolbars();
265
* Post toolbar config.
266
* (Plug action lists back in, etc.)
268
void slotNewToolbarConfig();
271
* Shows or hides a toolbar
273
void slotToolbarToggled(bool toggle);
276
* Toggle full screen on/off.
278
void viewFullscreen(bool fullScreen);
281
* Toggle docker titlebars on/off.
283
void showDockerTitleBars(bool show);
288
void slotReloadFile();
293
* This will call slotFileOpen(). To differentiate this from an ordinary
294
* call to slotFileOpen() call @ref isImporting().
296
void slotImportFile();
301
* This will call slotFileSaveAs(). To differentiate this from an ordinary
302
* call to slotFileSaveAs() call @ref isExporting().
304
void slotExportFile();
306
void slotEncryptDocument();
307
void slotUncompressToDir();
309
void slotProgress(int value);
314
void toggleDockersVisibility(bool visible);
317
* Saves the document, asking for a filename if necessary.
319
* @param saveas if set to TRUE the user is always prompted for a filename
321
* @param silent if set to TRUE rootDocument()->setTitleModified will not be called.
323
* @param specialOutputFlag set to enums defined in KoDocument if save to special output format
325
* @return TRUE on success, false on error or cancel
326
* (don't display anything in this case, the error dialog box is also implemented here
327
* but restore the original URL in slotFileSaveAs)
329
bool saveDocument(bool saveas = false, bool silent = false, int specialOutputFlag = 0);
334
* This setting indicates who is calling chooseNewDocument.
335
* Usually the app will want to
336
* - show the template dialog with 'everything' if InitDocAppStarting, InitDocFileClose or InitDocEmbedded
337
* - show the template dialog with 'templates only' if InitDocFileNew
338
* - create an empty document with default settings if InitDocEmpty
340
enum InitDocFlags { /*InitDocAppStarting, */ InitDocFileNew, InitDocFileClose /*, InitDocEmbedded, InitDocEmpty*/ };
342
/// Helper method for slotFileNew and slotFileClose
343
void chooseNewDocument(InitDocFlags initDocFlags);
346
* Create a new empty document.
348
KoPart* createPart() const;
350
void closeEvent(QCloseEvent * e);
351
void resizeEvent(QResizeEvent * e);
354
* Ask user about saving changes to the document upon exit.
358
bool openDocumentInternal(const QUrl &url, KoPart *newpart = 0, KoDocument *newdoc = 0);
361
* Returns whether or not the current slotFileSave[As]() or saveDocument()
362
* call is actually an export operation (like File --> Export).
364
* If this is true, you must call KoDocument::export() instead of
365
* KoDocument::save() or KoDocument::saveAs(), in any reimplementation of
368
bool isExporting() const;
371
* Returns whether or not the current slotFileOpen() or openDocument()
372
* call is actually an import operation (like File --> Import).
374
* If this is true, you must call KoDocument::import() instead of
375
* KoDocument::openUrl(), in any reimplementation of openDocument() or
376
* openDocumentInternal().
378
bool isImporting() const;
380
KRecentFilesAction *recentAction() const;
384
* Save the list of recent files.
386
void saveRecentFiles();
388
void slotLoadCompleted();
389
void slotLoadCanceled(const QString &);
390
void slotSaveCompleted();
391
void slotSaveCanceled(const QString &);
392
void forceDockTabFonts();
395
* Slot to create a new view for the currently activate @ref #koDocument.
397
virtual void newView();
400
// --------------------- PartManager
405
* Removes a part from the manager (this does not delete the object) .
407
* Sets the active part to 0 if @p part is the activePart() .
409
virtual void removePart( KoPart *part );
412
* Sets the active part.
414
* The active part receives activation events.
416
* @p widget can be used to specify which widget was responsible for the activation.
417
* This is important if you have multiple views for a document/part , like in KOffice .
419
virtual void setActivePart(KoPart *part, QWidget *widget);
426
void slotWidgetDestroyed();
427
void slotDocumentTitleModified(const QString &caption, bool mod);
429
// --------------------- PartManager
433
void createMainwindowGUI();
436
* Asks the user if they really want to save the document.
437
* Called only if outputFormat != nativeFormat.
439
* @return true if the document should be saved
441
bool exportConfirmation(const QByteArray &outputFormat);
443
void saveWindowSettings();
445
// retrieve the current KoView
446
KoView* currentView() const;
450
KoMainWindowPrivate * const d;