KoMainWindow.h 12.9 KB
Newer Older
Casper Boemann's avatar
Casper Boemann committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* This file is part of the KDE project
   Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
   Copyright (C) 2000-2004 David Faure <faure@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
   Boston, MA 02110-1301, USA.
Casper Boemann's avatar
Casper Boemann committed
19 20
*/

21 22 23 24
#ifndef KOMAINWINDOW_H
#define KOMAINWINDOW_H

#include "komain_export.h"
Casper Boemann's avatar
Casper Boemann committed
25

26
#include <kxmlguiwindow.h>
27
#include <KoCanvasObserverBase.h>
Thomas Zander's avatar
Thomas Zander committed
28
#include <KoCanvasSupervisor.h>
29

Casper Boemann's avatar
Casper Boemann committed
30
class KoMainWindowPrivate;
31
class KoDocument;
32
class KoPart;
33
class KoView;
34
class KoPrintJob;
35
class KoDockFactoryBase;
Casper Boemann's avatar
Casper Boemann committed
36 37
class KRecentFilesAction;
class QDockWidget;
38

39
struct KoPageLayout;
40

Boudewijn Rempt's avatar
Boudewijn Rempt committed
41
// Calligra class but not in main module
42
class KoDockerManager;
43
class KUrl;
Casper Boemann's avatar
Casper Boemann committed
44 45

/**
Boudewijn Rempt's avatar
Boudewijn Rempt committed
46
 * @brief Main window for a Calligra application
Casper Boemann's avatar
Casper Boemann committed
47 48
 *
 * This class is used to represent a main window
Boudewijn Rempt's avatar
Boudewijn Rempt committed
49
 * of a Calligra component. Each main window contains
Casper Boemann's avatar
Casper Boemann committed
50 51 52 53
 * a menubar and some toolbars.
 *
 * @note This class does NOT need to be subclassed in your application.
 */
54
class KOMAIN_EXPORT KoMainWindow : public KXmlGuiWindow, public KoCanvasSupervisor
Casper Boemann's avatar
Casper Boemann committed
55 56 57 58 59 60 61
{
    Q_OBJECT
public:

    /**
     *  Constructor.
     *
Boudewijn Rempt's avatar
Boudewijn Rempt committed
62
     *  Initializes a Calligra main window (with its basic GUI etc.).
Casper Boemann's avatar
Casper Boemann committed
63
     */
64
    explicit KoMainWindow(const QByteArray nativeMimeType, const KComponentData &instance);
Casper Boemann's avatar
Casper Boemann committed
65 66 67 68 69 70

    /**
     *  Destructor.
     */
    virtual ~KoMainWindow();

71 72 73 74
    // If noCleanup is set, KoMainWindow will not delete the root document
    // or part manager on destruction.
    void setNoCleanup(bool noCleanup);

Casper Boemann's avatar
Casper Boemann committed
75 76 77 78
    /**
     * Called when a document is assigned to this mainwindow.
     * This creates a view for this document, makes it the active part, etc.
     */
79
    void setRootDocument(KoDocument *doc, KoPart *part = 0, bool deletePrevious = true);
Casper Boemann's avatar
Casper Boemann committed
80 81 82 83 84

    /**
     * This is used to handle the document used at start up before it actually
     * added as root document.
     */
85
    void setPartToOpen(KoPart *part);
Casper Boemann's avatar
Casper Boemann committed
86 87 88 89 90

    /**
     * Update caption from document info - call when document info
     * (title in the about page) changes.
     */
91
    void updateCaption();
Casper Boemann's avatar
Casper Boemann committed
92 93 94 95

    /**
     *  Retrieves the document that is displayed in the mainwindow.
     */
96 97
    KoDocument *rootDocument() const;
    KoView *rootView() const;
Casper Boemann's avatar
Casper Boemann committed
98 99 100 101 102

    /**
     * The application should call this to show or hide a toolbar.
     * It also takes care of the corresponding action in the settings menu.
     */
103
    void showToolbar(const char * tbName, bool shown);
Casper Boemann's avatar
Casper Boemann committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117

    /**
     * @return TRUE if the toolbar @p tbName is visible
     */
    bool toolbarIsVisible(const char *tbName);

    /**
     * Sets the maximum number of recent documents entries.
     */
    void setMaxRecentItems(uint _number);

    /**
     * The document opened a URL -> store into recent documents list.
     */
118
    void addRecentURL(const KUrl& url);
Casper Boemann's avatar
Casper Boemann committed
119 120 121 122 123 124 125

    /**
     * Load the desired document and show it.
     * @param url the URL to open
     *
     * @return TRUE on success.
     */
126
    bool openDocument(const KUrl & url);
Casper Boemann's avatar
Casper Boemann committed
127 128 129 130 131 132

    /**
     * Load the URL into this document (and make it root doc after loading)
     *
     * Special method for KoApplication::start, don't use.
     */
133
    bool openDocument(KoPart *newPart, const KUrl & url);
Casper Boemann's avatar
Casper Boemann committed
134 135 136 137 138 139 140 141 142

    /**
     * Reloads the recent documents list.
     */
    void reloadRecentFileList();

    /**
     * Updates the window caption based on the document info and path.
     */
143
    void updateCaption(const QString & caption, bool mod);
Casper Boemann's avatar
Casper Boemann committed
144 145 146
    void updateReloadFileAction(KoDocument *doc);
    void updateVersionsFileAction(KoDocument *doc);

147
    void setReadWrite(bool readwrite);
Casper Boemann's avatar
Casper Boemann committed
148 149 150 151 152

    /**
     * Returns the dockwidget specified by the @p factory. If the dock widget doesn't exist yet it's created.
     * Add a "view_palette_action_menu" action to your view menu if you want to use closable dock widgets.
     * @param factory the factory used to create the dock widget if needed
153
     * @return the dock widget specified by @p factory (may be 0)
Casper Boemann's avatar
Casper Boemann committed
154
     */
155
    QDockWidget* createDockWidget(KoDockFactoryBase* factory);
Casper Boemann's avatar
Casper Boemann committed
156

157 158 159
    /// Return the list of dock widgets belonging to this main window.
    QList<QDockWidget*> dockWidgets();

160
    QList<KoCanvasObserverBase*> canvasObservers();
161

162 163 164 165 166 167 168 169 170
    /**
     * @return the KoDockerManager which is assigned
     * WARNING: this could be 0, if no docker have been assigned yet. In that case create one
      * and assign it.
     * Note This should only be called by KoView
     * @ref setDockerManager to assign it.
     */
    KoDockerManager * dockerManager() const;

171
Q_SIGNALS:
Casper Boemann's avatar
Casper Boemann committed
172 173 174 175 176 177
    /**
     * This signal is emitted if the document has been saved successfully.
     */
    void documentSaved();
    /// This signals is emmitted before the save dialog is shown
    void saveDialogShown();
178

179 180
    /// This signal is emitted right after the docker states have been succefully restored from config
    void restoringDone();
Dmitry Kazakov's avatar
Dmitry Kazakov committed
181 182 183 184 185 186

    /// This signal is emitted when this windows has finished loading of a
    /// document. The document may be opened in another window in the end.
    /// In this case, the signal means there is no link between the window
    /// and the document anymore.
    void loadCompleted();
187

188 189 190
    /// This signal is emitted when the color theme changes
    void themeChanged();

191 192 193
    /// This signal is emitted when the shortcut key configuration has changed
    void keyBindingsChanged();

194
public Q_SLOTS:
Casper Boemann's avatar
Casper Boemann committed
195 196 197 198 199 200 201 202 203 204 205 206 207

    /**
     * Slot for eMailing the document using KMail
     *
     * This is a very simple extension that will allow any document
     * that is currently being edited to be emailed using KMail.
     */
    void slotEmailFile();

    /**
     *  Slot for opening a new document.
     *
     *  If the current document is empty, the new document replaces it.
208
     *  If not, a new mainwindow will be opened for showing the document.
Casper Boemann's avatar
Casper Boemann committed
209
     */
210
    void slotFileNew();
Casper Boemann's avatar
Casper Boemann committed
211 212 213 214 215

    /**
     *  Slot for opening a saved file.
     *
     *  If the current document is empty, the opened document replaces it.
216
     *  If not a new mainwindow will be opened for showing the opened file.
Casper Boemann's avatar
Casper Boemann committed
217
     */
218
    void slotFileOpen();
Casper Boemann's avatar
Casper Boemann committed
219 220 221 222 223

    /**
     *  Slot for opening a file among the recently opened files.
     *
     *  If the current document is empty, the opened document replaces it.
224
     *  If not a new mainwindow will be opened for showing the opened file.
Casper Boemann's avatar
Casper Boemann committed
225
     */
226
    void slotFileOpenRecent(const KUrl &);
Casper Boemann's avatar
Casper Boemann committed
227 228 229 230

    /**
     *  Saves the current document with the current name.
     */
231
    void slotFileSave();
Casper Boemann's avatar
Casper Boemann committed
232 233 234 235

    /**
     *  Saves the current document with a new name.
     */
236
    void slotFileSaveAs();
Casper Boemann's avatar
Casper Boemann committed
237 238 239 240

    /**
     *  Prints the actual document.
     */
241 242
    void slotFilePrint();
    void slotFilePrintPreview();
243

244
    KoPrintJob* exportToPdf(const QString &pdfFileName = QString());
245
    KoPrintJob* exportToPdf(KoPageLayout pageLayout, QString pdfFileName = QString());
Casper Boemann's avatar
Casper Boemann committed
246 247 248 249

    /**
     * Show a dialog with author and document information.
     */
250
    void slotDocumentInfo();
Casper Boemann's avatar
Casper Boemann committed
251 252 253 254

    /**
     *  Closes the document.
     */
255
    void slotFileClose();
Casper Boemann's avatar
Casper Boemann committed
256 257

    /**
258
     *  Closes the mainwindow.
Casper Boemann's avatar
Casper Boemann committed
259
     */
260
    void slotFileQuit();
Casper Boemann's avatar
Casper Boemann committed
261 262 263 264

    /**
     *  Configure key bindings.
     */
265
    void slotConfigureKeys();
Casper Boemann's avatar
Casper Boemann committed
266 267 268 269

    /**
     *  Configure toolbars.
     */
270
    void slotConfigureToolbars();
Casper Boemann's avatar
Casper Boemann committed
271 272 273 274 275

    /**
     *  Post toolbar config.
     * (Plug action lists back in, etc.)
     */
276
    void slotNewToolbarConfig();
Casper Boemann's avatar
Casper Boemann committed
277 278 279 280

    /**
     *  Shows or hides a toolbar
     */
281
    void slotToolbarToggled(bool toggle);
Casper Boemann's avatar
Casper Boemann committed
282

283 284 285
    /**
     * Toggle full screen on/off.
     */
286
    void viewFullscreen(bool fullScreen);
287

288 289 290 291 292
    /**
     * Toggle docker titlebars on/off.
     */
    void showDockerTitleBars(bool show);

Casper Boemann's avatar
Casper Boemann committed
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
    /**
     * Reload file
     */
    void slotReloadFile();

    /**
     * This will call a dialogbox to add version to list of files
     */
    void slotVersionsFile();

    /**
     * File --> Import
     *
     * This will call slotFileOpen().  To differentiate this from an ordinary
     * call to slotFileOpen() call @ref isImporting().
     */
    void slotImportFile();

    /**
     * File --> Export
     *
     * This will call slotFileSaveAs().  To differentiate this from an ordinary
     * call to slotFileSaveAs() call @ref isExporting().
     */
    void slotExportFile();

319 320 321
    void slotEncryptDocument();
    void slotUncompressToDir();

322 323
    void slotProgress(int value);

324 325 326
    /**
     * Hide the dockers
     */
327
    void toggleDockersVisibility(bool visible);
328

329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
    /**
     * Saves the document, asking for a filename if necessary.
     *
     * @param saveas if set to TRUE the user is always prompted for a filename
     *
     * @param silent if set to TRUE rootDocument()->setTitleModified will not be called.
     *
     * @param specialOutputFlag set to enums defined in KoDocument if save to special output format
     *
     * @return TRUE on success, false on error or cancel
     *         (don't display anything in this case, the error dialog box is also implemented here
     *         but restore the original URL in slotFileSaveAs)
     */
    bool saveDocument(bool saveas = false, bool silent = false, int specialOutputFlag = 0);

Boudewijn Rempt's avatar
Boudewijn Rempt committed
344
private:
Casper Boemann's avatar
Casper Boemann committed
345 346 347 348 349 350 351 352 353 354 355

    /**
     * This setting indicates who is calling chooseNewDocument.
     * Usually the app will want to
     * - show the template dialog with 'everything' if InitDocAppStarting, InitDocFileClose or InitDocEmbedded
     * - show the template dialog with 'templates only' if InitDocFileNew
     * - create an empty document with default settings if InitDocEmpty
     */
    enum InitDocFlags { /*InitDocAppStarting, */ InitDocFileNew, InitDocFileClose /*, InitDocEmbedded, InitDocEmpty*/ };

    /// Helper method for slotFileNew and slotFileClose
356
    void chooseNewDocument(InitDocFlags initDocFlags);
Casper Boemann's avatar
Casper Boemann committed
357 358 359 360

    /**
     * Create a new empty document.
     */
361
    KoPart* createPart() const;
Casper Boemann's avatar
Casper Boemann committed
362

363 364
    void closeEvent(QCloseEvent * e);
    void resizeEvent(QResizeEvent * e);
Casper Boemann's avatar
Casper Boemann committed
365 366 367 368

    /**
     * Ask user about saving changes to the document upon exit.
     */
369
    bool queryClose();
Casper Boemann's avatar
Casper Boemann committed
370

371
    bool openDocumentInternal(const KUrl &url, KoPart *newpart = 0, KoDocument *newdoc = 0);
Casper Boemann's avatar
Casper Boemann committed
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387

    /**
     * Returns whether or not the current slotFileSave[As]() or saveDocument()
     * call is actually an export operation (like File --> Export).
     *
     * If this is true, you must call KoDocument::export() instead of
     * KoDocument::save() or KoDocument::saveAs(), in any reimplementation of
     * saveDocument().
     */
    bool isExporting() const;

    /**
     * Returns whether or not the current slotFileOpen() or openDocument()
     * call is actually an import operation (like File --> Import).
     *
     * If this is true, you must call KoDocument::import() instead of
388
     * KoDocument::openUrl(), in any reimplementation of openDocument() or
Casper Boemann's avatar
Casper Boemann committed
389 390 391 392
     * openDocumentInternal().
     */
    bool isImporting() const;

393
    KRecentFilesAction *recentAction() const;
Casper Boemann's avatar
Casper Boemann committed
394

395
private Q_SLOTS:
396 397 398 399
    /**
     * Save the list of recent files.
     */
    void saveRecentFiles();
400

401
    void slotLoadCompleted();
402
    void slotLoadCanceled(const QString &);
403 404
    void slotSaveCompleted();
    void slotSaveCanceled(const QString &);
405
    void forceDockTabFonts();
Casper Boemann's avatar
Casper Boemann committed
406

407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
    /**
     * Slot to create a new view for the currently activate @ref #koDocument.
     */
    virtual void newView();


// ---------------------  PartManager
private:

    friend class KoPart;
    /**
     * Removes a part from the manager (this does not delete the object) .
     *
     * Sets the active part to 0 if @p part is the activePart() .
     */
    virtual void removePart( KoPart *part );

    /**
     * Sets the active part.
     *
     * The active part receives activation events.
     *
     * @p widget can be used to specify which widget was responsible for the activation.
     * This is important if you have multiple views for a document/part , like in KOffice .
     */
    virtual void setActivePart(KoPart *part, QWidget *widget);

434
private Q_SLOTS:
435 436 437 438 439 440 441 442 443

    /**
     * @internal
     */
    void slotWidgetDestroyed();
    void slotDocumentTitleModified(const QString &caption, bool mod);

// ---------------------  PartManager

444
private:
445 446 447

    void createMainwindowGUI();

Casper Boemann's avatar
Casper Boemann committed
448 449 450 451 452 453
    /**
     * Asks the user if they really want to save the document.
     * Called only if outputFormat != nativeFormat.
     *
     * @return true if the document should be saved
     */
454
    bool exportConfirmation(const QByteArray &outputFormat);
Casper Boemann's avatar
Casper Boemann committed
455 456 457

    void saveWindowSettings();

458 459 460
    // retrieve the current KoView
    KoView* currentView() const;

Casper Boemann's avatar
Casper Boemann committed
461
private:
462

Casper Boemann's avatar
Casper Boemann committed
463 464 465 466
    KoMainWindowPrivate * const d;
};

#endif