~ubuntu-branches/debian/sid/calligraplan/sid

« back to all changes in this revision

Viewing changes to src/libs/main/KoMainWindow.h

  • Committer: Package Import Robot
  • Author(s): Pino Toscano
  • Date: 2018-02-01 18:20:19 UTC
  • Revision ID: package-import@ubuntu.com-20180201182019-1qo7qaim5wejm5k9
Tags: upstream-3.1.0
ImportĀ upstreamĀ versionĀ 3.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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.
 
19
*/
 
20
 
 
21
#ifndef KOMAINWINDOW_H
 
22
#define KOMAINWINDOW_H
 
23
 
 
24
#include "komain_export.h"
 
25
 
 
26
#include <kxmlguiwindow.h>
 
27
//#include <KoCanvasObserverBase.h>
 
28
//#include <KoCanvasSupervisor.h>
 
29
 
 
30
class KoMainWindowPrivate;
 
31
class KoDocument;
 
32
class KoPart;
 
33
class KoView;
 
34
class KoPrintJob;
 
35
class KoDockFactoryBase;
 
36
class KRecentFilesAction;
 
37
class KoComponentData;
 
38
class QDockWidget;
 
39
 
 
40
struct KoPageLayout;
 
41
 
 
42
// Calligra class but not in main module
 
43
class QUrl;
 
44
 
 
45
/**
 
46
 * @brief Main window for a Calligra application
 
47
 *
 
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.
 
51
 *
 
52
 * @note This class does NOT need to be subclassed in your application.
 
53
 */
 
54
class KOMAIN_EXPORT KoMainWindow : public KXmlGuiWindow//, public KoCanvasSupervisor
 
55
{
 
56
    Q_OBJECT
 
57
public:
 
58
 
 
59
    /**
 
60
     *  Constructor.
 
61
     *
 
62
     *  Initializes a Calligra main window (with its basic GUI etc.).
 
63
     */
 
64
    explicit KoMainWindow(const QByteArray &nativeMimeType, const KoComponentData &instance);
 
65
 
 
66
    /**
 
67
     *  Destructor.
 
68
     */
 
69
    virtual ~KoMainWindow();
 
70
 
 
71
    // If noCleanup is set, KoMainWindow will not delete the root document
 
72
    // or part manager on destruction.
 
73
    void setNoCleanup(bool noCleanup);
 
74
 
 
75
    /**
 
76
     * Called when a document is assigned to this mainwindow.
 
77
     * This creates a view for this document, makes it the active part, etc.
 
78
     */
 
79
    void setRootDocument(KoDocument *doc, KoPart *part = 0, bool deletePrevious = true);
 
80
 
 
81
    /**
 
82
     * This is used to handle the document used at start up before it actually
 
83
     * added as root document.
 
84
     */
 
85
    void setPartToOpen(KoPart *part);
 
86
 
 
87
    /**
 
88
     * Update caption from document info - call when document info
 
89
     * (title in the about page) changes.
 
90
     */
 
91
    void updateCaption();
 
92
 
 
93
    KoComponentData componentData() const;
 
94
    void setComponentData(const KoComponentData &componentData);
 
95
 
 
96
    /**
 
97
     *  Retrieves the document that is displayed in the mainwindow.
 
98
     */
 
99
    KoDocument *rootDocument() const;
 
100
    KoView *rootView() const;
 
101
 
 
102
    /**
 
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.
 
105
     */
 
106
    void showToolbar(const char * tbName, bool shown);
 
107
 
 
108
    /**
 
109
     * @return TRUE if the toolbar @p tbName is visible
 
110
     */
 
111
    bool toolbarIsVisible(const char *tbName);
 
112
 
 
113
    /**
 
114
     * Sets the maximum number of recent documents entries.
 
115
     */
 
116
    void setMaxRecentItems(uint _number);
 
117
 
 
118
    /**
 
119
     * The document opened a URL -> store into recent documents list.
 
120
     */
 
121
    void addRecentURL(const QUrl &url);
 
122
 
 
123
    /**
 
124
     * Load the desired document and show it.
 
125
     * @param url the URL to open
 
126
     *
 
127
     * @return TRUE on success.
 
128
     */
 
129
    bool openDocument(const QUrl &url);
 
130
 
 
131
    /**
 
132
     * Load the URL into this document (and make it root doc after loading)
 
133
     *
 
134
     * Special method for KoApplication::start, don't use.
 
135
     */
 
136
    bool openDocument(KoPart *newPart, const QUrl &url);
 
137
 
 
138
    /**
 
139
     * Reloads the recent documents list.
 
140
     */
 
141
    void reloadRecentFileList();
 
142
 
 
143
    /**
 
144
     * Updates the window caption based on the document info and path.
 
145
     */
 
146
    void updateCaption(const QString & caption, bool mod);
 
147
    void updateReloadFileAction(KoDocument *doc);
 
148
 
 
149
    void setReadWrite(bool readwrite);
 
150
 
 
151
    /**
 
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)
 
156
     */
 
157
    QDockWidget* createDockWidget(KoDockFactoryBase* factory);
 
158
 
 
159
    /// Return the list of dock widgets belonging to this main window.
 
160
    QList<QDockWidget*> dockWidgets() const;
 
161
 
 
162
//    QList<KoCanvasObserverBase*> canvasObservers() const;
 
163
 
 
164
Q_SIGNALS:
 
165
    /**
 
166
     * This signal is emitted if the document has been saved successfully.
 
167
     */
 
168
    void documentSaved();
 
169
    /// This signals is emmitted before the save dialog is shown
 
170
    void saveDialogShown();
 
171
 
 
172
    /// This signal is emitted right after the docker states have been succefully restored from config
 
173
    void restoringDone();
 
174
 
 
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();
 
180
 
 
181
    /// This signal is emitted when the color theme changes
 
182
    void themeChanged();
 
183
 
 
184
    /// This signal is emitted when the shortcut key configuration has changed
 
185
    void keyBindingsChanged();
 
186
 
 
187
public Q_SLOTS:
 
188
 
 
189
    /**
 
190
     * Slot for eMailing the document using KMail
 
191
     *
 
192
     * This is a very simple extension that will allow any document
 
193
     * that is currently being edited to be emailed using KMail.
 
194
     */
 
195
    void slotEmailFile();
 
196
 
 
197
    /**
 
198
     *  Slot for opening a new document.
 
199
     *
 
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.
 
202
     */
 
203
    void slotFileNew();
 
204
 
 
205
    /**
 
206
     *  Slot for opening a saved file.
 
207
     *
 
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.
 
210
     */
 
211
    void slotFileOpen();
 
212
 
 
213
    /**
 
214
     *  Slot for opening a file among the recently opened files.
 
215
     *
 
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.
 
218
     */
 
219
    void slotFileOpenRecent(const QUrl &);
 
220
 
 
221
    /**
 
222
     *  Saves the current document with the current name.
 
223
     */
 
224
    void slotFileSave();
 
225
 
 
226
    /**
 
227
     *  Saves the current document with a new name.
 
228
     */
 
229
    void slotFileSaveAs();
 
230
 
 
231
    /**
 
232
     *  Prints the actual document.
 
233
     */
 
234
    void slotFilePrint();
 
235
    void slotFilePrintPreview();
 
236
 
 
237
    KoPrintJob* exportToPdf(const QString &pdfFileName = QString());
 
238
 
 
239
    /**
 
240
     * Show a dialog with author and document information.
 
241
     */
 
242
    void slotDocumentInfo();
 
243
 
 
244
    /**
 
245
     *  Closes the document.
 
246
     */
 
247
    void slotFileClose();
 
248
 
 
249
    /**
 
250
     *  Closes the mainwindow.
 
251
     */
 
252
    void slotFileQuit();
 
253
 
 
254
    /**
 
255
     *  Configure key bindings.
 
256
     */
 
257
    void slotConfigureKeys();
 
258
 
 
259
    /**
 
260
     *  Configure toolbars.
 
261
     */
 
262
    void slotConfigureToolbars();
 
263
 
 
264
    /**
 
265
     *  Post toolbar config.
 
266
     * (Plug action lists back in, etc.)
 
267
     */
 
268
    void slotNewToolbarConfig();
 
269
 
 
270
    /**
 
271
     *  Shows or hides a toolbar
 
272
     */
 
273
    void slotToolbarToggled(bool toggle);
 
274
 
 
275
    /**
 
276
     * Toggle full screen on/off.
 
277
     */
 
278
    void viewFullscreen(bool fullScreen);
 
279
 
 
280
    /**
 
281
     * Toggle docker titlebars on/off.
 
282
     */
 
283
    void showDockerTitleBars(bool show);
 
284
 
 
285
    /**
 
286
     * Reload file
 
287
     */
 
288
    void slotReloadFile();
 
289
 
 
290
    /**
 
291
     * File --> Import
 
292
     *
 
293
     * This will call slotFileOpen().  To differentiate this from an ordinary
 
294
     * call to slotFileOpen() call @ref isImporting().
 
295
     */
 
296
    void slotImportFile();
 
297
 
 
298
    /**
 
299
     * File --> Export
 
300
     *
 
301
     * This will call slotFileSaveAs().  To differentiate this from an ordinary
 
302
     * call to slotFileSaveAs() call @ref isExporting().
 
303
     */
 
304
    void slotExportFile();
 
305
 
 
306
    void slotEncryptDocument();
 
307
    void slotUncompressToDir();
 
308
 
 
309
    void slotProgress(int value);
 
310
 
 
311
    /**
 
312
     * Hide the dockers
 
313
     */
 
314
    void toggleDockersVisibility(bool visible);
 
315
 
 
316
    /**
 
317
     * Saves the document, asking for a filename if necessary.
 
318
     *
 
319
     * @param saveas if set to TRUE the user is always prompted for a filename
 
320
     *
 
321
     * @param silent if set to TRUE rootDocument()->setTitleModified will not be called.
 
322
     *
 
323
     * @param specialOutputFlag set to enums defined in KoDocument if save to special output format
 
324
     *
 
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)
 
328
     */
 
329
    bool saveDocument(bool saveas = false, bool silent = false, int specialOutputFlag = 0);
 
330
 
 
331
private:
 
332
 
 
333
    /**
 
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
 
339
     */
 
340
    enum InitDocFlags { /*InitDocAppStarting, */ InitDocFileNew, InitDocFileClose /*, InitDocEmbedded, InitDocEmpty*/ };
 
341
 
 
342
    /// Helper method for slotFileNew and slotFileClose
 
343
    void chooseNewDocument(InitDocFlags initDocFlags);
 
344
 
 
345
    /**
 
346
     * Create a new empty document.
 
347
     */
 
348
    KoPart* createPart() const;
 
349
 
 
350
    void closeEvent(QCloseEvent * e);
 
351
    void resizeEvent(QResizeEvent * e);
 
352
 
 
353
    /**
 
354
     * Ask user about saving changes to the document upon exit.
 
355
     */
 
356
    bool queryClose();
 
357
 
 
358
    bool openDocumentInternal(const QUrl &url, KoPart *newpart = 0, KoDocument *newdoc = 0);
 
359
 
 
360
    /**
 
361
     * Returns whether or not the current slotFileSave[As]() or saveDocument()
 
362
     * call is actually an export operation (like File --> Export).
 
363
     *
 
364
     * If this is true, you must call KoDocument::export() instead of
 
365
     * KoDocument::save() or KoDocument::saveAs(), in any reimplementation of
 
366
     * saveDocument().
 
367
     */
 
368
    bool isExporting() const;
 
369
 
 
370
    /**
 
371
     * Returns whether or not the current slotFileOpen() or openDocument()
 
372
     * call is actually an import operation (like File --> Import).
 
373
     *
 
374
     * If this is true, you must call KoDocument::import() instead of
 
375
     * KoDocument::openUrl(), in any reimplementation of openDocument() or
 
376
     * openDocumentInternal().
 
377
     */
 
378
    bool isImporting() const;
 
379
 
 
380
    KRecentFilesAction *recentAction() const;
 
381
 
 
382
private Q_SLOTS:
 
383
    /**
 
384
     * Save the list of recent files.
 
385
     */
 
386
    void saveRecentFiles();
 
387
 
 
388
    void slotLoadCompleted();
 
389
    void slotLoadCanceled(const QString &);
 
390
    void slotSaveCompleted();
 
391
    void slotSaveCanceled(const QString &);
 
392
    void forceDockTabFonts();
 
393
 
 
394
    /**
 
395
     * Slot to create a new view for the currently activate @ref #koDocument.
 
396
     */
 
397
    virtual void newView();
 
398
 
 
399
 
 
400
// ---------------------  PartManager
 
401
private:
 
402
 
 
403
    friend class KoPart;
 
404
    /**
 
405
     * Removes a part from the manager (this does not delete the object) .
 
406
     *
 
407
     * Sets the active part to 0 if @p part is the activePart() .
 
408
     */
 
409
    virtual void removePart( KoPart *part );
 
410
 
 
411
    /**
 
412
     * Sets the active part.
 
413
     *
 
414
     * The active part receives activation events.
 
415
     *
 
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 .
 
418
     */
 
419
    virtual void setActivePart(KoPart *part, QWidget *widget);
 
420
 
 
421
private Q_SLOTS:
 
422
 
 
423
    /**
 
424
     * @internal
 
425
     */
 
426
    void slotWidgetDestroyed();
 
427
    void slotDocumentTitleModified(const QString &caption, bool mod);
 
428
 
 
429
// ---------------------  PartManager
 
430
 
 
431
private:
 
432
 
 
433
    void createMainwindowGUI();
 
434
 
 
435
    /**
 
436
     * Asks the user if they really want to save the document.
 
437
     * Called only if outputFormat != nativeFormat.
 
438
     *
 
439
     * @return true if the document should be saved
 
440
     */
 
441
    bool exportConfirmation(const QByteArray &outputFormat);
 
442
 
 
443
    void saveWindowSettings();
 
444
 
 
445
    // retrieve the current KoView
 
446
    KoView* currentView() const;
 
447
 
 
448
private:
 
449
 
 
450
    KoMainWindowPrivate * const d;
 
451
};
 
452
 
 
453
#endif