forked from KDE/okular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
part.h
369 lines (323 loc) · 12.6 KB
/
part.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/***************************************************************************
* Copyright (C) 2002 by Wilco Greven <[email protected]> *
* Copyright (C) 2003-2004 by Christophe Devriese *
* <[email protected]> *
* Copyright (C) 2003 by Andy Goossens <[email protected]> *
* Copyright (C) 2003 by Laurent Montel <[email protected]> *
* Copyright (C) 2004 by Dominique Devriese <[email protected]> *
* Copyright (C) 2004-2007 by Albert Astals Cid <[email protected]> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef _PART_H_
#define _PART_H_
#include <QIcon>
#include <QList>
#include <QPointer>
#include <QProcess>
#include <QtDBus>
#include <QUrl>
#include <KCompressionDevice>
#include <KIO/Job>
#include <KMessageWidget>
#include <KParts/ReadWritePart>
#include <KPluginFactory>
#include "core/observer.h"
#include "core/document.h"
#include "kdocumentviewer.h"
#include "interfaces/viewerinterface.h"
#include "okularpart_export.h"
class QAction;
class QWidget;
class QPrinter;
class QMenu;
class KConfigDialog;
class KConfigGroup;
class KDirWatch;
class KToggleAction;
class KToggleFullScreenAction;
class KSelectAction;
class KAboutData;
class QTemporaryFile;
class QAction;
namespace KParts { class GUIActivateEvent; }
class FindBar;
class ThumbnailList;
class PageSizeLabel;
class PageView;
class PresentationWidget;
class ProgressWidget;
class SearchWidget;
class Sidebar;
class TOC;
class MiniBar;
class MiniBarLogic;
class FileKeeper;
class Reviews;
class BookmarkList;
class DrawingToolActions;
class Layers;
namespace Okular
{
class BrowserExtension;
class ExportFormat;
/**
* Describes the possible embedding modes of the part
*
* @since 0.14 (KDE 4.8)
*/
enum EmbedMode
{
UnknownEmbedMode,
NativeShellMode, // embedded in the native Okular' shell
PrintPreviewMode, // embedded to show the print preview of a document
KHTMLPartMode, // embedded in KHTML
ViewerWidgetMode // the part acts as a widget that can display all kinds of documents
};
/**
* This is a "Part". It that does all the real work in a KPart
* application.
*
* @short Main Part
* @author Wilco Greven <[email protected]>
* @version 0.2
*/
class OKULARPART_EXPORT Part : public KParts::ReadWritePart, public Okular::DocumentObserver, public KDocumentViewer, public Okular::ViewerInterface
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.okular")
Q_INTERFACES(KDocumentViewer)
Q_INTERFACES(Okular::ViewerInterface)
friend class PartTest;
public:
// Default constructor
/**
* If one element of 'args' contains one of the strings "Print/Preview" or "ViewerWidget",
* the part will be set up in the corresponding mode. Additionally, it is possible to specify
* which config file should be used by adding a string containing "ConfigFileName=<file name>"
* to 'args'.
**/
Part(QWidget* parentWidget, QObject* parent, const QVariantList& args);
// Destructor
~Part();
// inherited from DocumentObserver
void notifySetup( const QVector< Okular::Page * > &pages, int setupFlags ) override;
void notifyViewportChanged( bool smoothMove ) override;
void notifyPageChanged( int page, int flags ) override;
bool openDocument(const QUrl &url, uint page) override;
void startPresentation() override;
QStringList supportedMimeTypes() const override;
QUrl realUrl() const;
void showSourceLocation(const QString& fileName, int line, int column, bool showGraphically = true) override;
void clearLastShownSourceLocation() override;
bool isWatchFileModeEnabled() const override;
void setWatchFileModeEnabled(bool enable) override;
bool areSourceLocationsShownGraphically() const override;
void setShowSourceLocationsGraphically(bool show) override;
bool openNewFilesInTabs() const override;
public Q_SLOTS: // dbus
Q_SCRIPTABLE Q_NOREPLY void goToPage(uint page) override;
Q_SCRIPTABLE Q_NOREPLY void openDocument( const QString &doc );
Q_SCRIPTABLE uint pages();
Q_SCRIPTABLE uint currentPage();
Q_SCRIPTABLE QString currentDocument();
Q_SCRIPTABLE QString documentMetaData( const QString &metaData ) const;
Q_SCRIPTABLE void slotPreferences();
Q_SCRIPTABLE void slotFind();
Q_SCRIPTABLE void slotPrintPreview();
Q_SCRIPTABLE void slotPreviousPage();
Q_SCRIPTABLE void slotNextPage();
Q_SCRIPTABLE void slotGotoFirst();
Q_SCRIPTABLE void slotGotoLast();
Q_SCRIPTABLE void slotTogglePresentation();
Q_SCRIPTABLE Q_NOREPLY void reload();
Q_SCRIPTABLE Q_NOREPLY void enableStartWithPrint();
Q_SIGNALS:
void enablePrintAction(bool enable);
void openSourceReference(const QString& absFileName, int line, int column);
void viewerMenuStateChange(bool enabled);
void enableCloseAction(bool enable);
void mimeTypeChanged(QMimeType mimeType);
void urlsDropped( const QList<QUrl>& urls );
void fitWindowToPage( const QSize& pageViewPortSize, const QSize& pageSize );
protected:
// reimplemented from KParts::ReadWritePart
bool openFile() override;
bool openUrl(const QUrl &url) override;
void guiActivateEvent(KParts::GUIActivateEvent *event) override;
void displayInfoMessage( const QString &message, KMessageWidget::MessageType messageType = KMessageWidget::Information, int duration = -1 );
public:
bool saveFile() override;
bool queryClose() override;
bool closeUrl() override;
bool closeUrl(bool promptToSave) override;
void setReadWrite(bool readwrite) override;
bool saveAs(const QUrl & saveUrl) override;
protected Q_SLOTS:
// connected to actions
void openUrlFromDocument(const QUrl &url);
void openUrlFromBookmarks(const QUrl &url);
void handleDroppedUrls( const QList<QUrl>& urls );
void slotGoToPage();
void slotHistoryBack();
void slotHistoryNext();
void slotAddBookmark();
void slotRenameBookmarkFromMenu();
void slotRenameCurrentViewportBookmark();
void slotPreviousBookmark();
void slotNextBookmark();
void slotFindNext();
void slotFindPrev();
void slotSaveFileAs();
void slotSaveCopyAs();
void slotGetNewStuff();
void slotNewConfig();
void slotShowMenu(const Okular::Page *page, const QPoint &point);
void slotShowProperties();
void slotShowEmbeddedFiles();
void slotShowLeftPanel();
void slotShowBottomBar();
void slotShowPresentation();
void slotHidePresentation();
void slotExportAs(QAction *);
bool slotImportPSFile();
void slotAboutBackend();
void slotReload();
void close();
void cannotQuit();
void slotShowFindBar();
void slotHideFindBar();
void slotJobStarted(KIO::Job *job);
void slotJobFinished(KJob *job);
void loadCancelled(const QString &reason);
void setWindowTitleFromDocument();
// can be connected to widget elements
void updateViewActions();
void updateBookmarksActions();
void enableTOC(bool enable);
void slotRebuildBookmarkMenu();
void enableLayers( bool enable );
public Q_SLOTS:
// connected to Shell action (and browserExtension), not local one
void slotPrint();
void slotFileDirty( const QString& );
void slotDoFileDirty();
void psTransformEnded(int, QProcess::ExitStatus);
KConfigDialog * slotGeneratorPreferences();
void errorMessage( const QString &message, int duration = 0 );
void warningMessage( const QString &message, int duration = -1 );
void noticeMessage( const QString &message, int duration = -1 );
void moveSplitter( const int sideWidgetSize );
private:
bool aboutToShowContextMenu(QMenu *menu, QAction *action, QMenu *contextMenu);
bool eventFilter(QObject * watched, QEvent * event) override;
Document::OpenResult doOpenFile(const QMimeType &mime, const QString &fileNameToOpen, bool *isCompressedFile);
void setupViewerActions();
void setViewerShortcuts();
void setupActions();
void setupPrint( QPrinter &printer );
void doPrint( QPrinter &printer );
bool handleCompressed(QString &destpath, const QString &path, KCompressionDevice::CompressionType compressionType );
void rebuildBookmarkMenu( bool unplugActions = true );
void updateAboutBackendAction();
void unsetDummyMode();
void slotRenameBookmark( const DocumentViewport &viewport );
void resetStartArguments();
static int numberOfParts;
QTemporaryFile *m_tempfile;
// the document
Okular::Document * m_document;
QString m_temporaryLocalFile;
bool isDocumentArchive;
// main widgets
Sidebar *m_sidebar;
SearchWidget *m_searchWidget;
FindBar * m_findBar;
KMessageWidget * m_topMessage;
KMessageWidget * m_formsMessage;
KMessageWidget * m_infoMessage;
QPointer<ThumbnailList> m_thumbnailList;
QPointer<PageView> m_pageView;
QPointer<TOC> m_toc;
QPointer<MiniBarLogic> m_miniBarLogic;
QPointer<MiniBar> m_miniBar;
QPointer<MiniBar> m_pageNumberTool;
QPointer<QWidget> m_bottomBar;
QPointer<PresentationWidget> m_presentationWidget;
QPointer<ProgressWidget> m_progressWidget;
QPointer<PageSizeLabel> m_pageSizeLabel;
QPointer<Reviews> m_reviewsWidget;
QPointer<BookmarkList> m_bookmarkList;
QPointer<Layers> m_layers;
// document watcher (and reloader) variables
KDirWatch *m_watcher;
QTimer *m_dirtyHandler;
QUrl m_oldUrl;
Okular::DocumentViewport m_viewportDirty;
bool m_wasPresentationOpen;
QWidget *m_dirtyToolboxItem;
bool m_wasSidebarVisible;
bool m_wasSidebarCollapsed;
bool m_fileWasRemoved;
Rotation m_dirtyPageRotation;
// Remember the search history
QStringList m_searchHistory;
// actions
QAction *m_gotoPage;
QAction *m_prevPage;
QAction *m_nextPage;
QAction *m_beginningOfDocument;
QAction *m_endOfDocument;
QAction *m_historyBack;
QAction *m_historyNext;
QAction *m_addBookmark;
QAction *m_renameBookmark;
QAction *m_prevBookmark;
QAction *m_nextBookmark;
QAction *m_copy;
QAction *m_selectAll;
QAction *m_find;
QAction *m_findNext;
QAction *m_findPrev;
QAction *m_saveAs;
QAction *m_saveCopyAs;
QAction *m_printPreview;
QAction *m_showProperties;
QAction *m_showEmbeddedFiles;
QAction *m_exportAs;
QAction *m_exportAsText;
QAction *m_exportAsDocArchive;
QAction *m_showPresentation;
KToggleAction* m_showMenuBarAction;
KToggleAction* m_showLeftPanel;
KToggleAction* m_showBottomBar;
KToggleFullScreenAction* m_showFullScreenAction;
QAction *m_aboutBackend;
QAction *m_reload;
QMenu *m_exportAsMenu;
QAction *m_closeFindBar;
DrawingToolActions *m_presentationDrawingActions;
bool m_actionsSearched;
BrowserExtension *m_bExtension;
QList<Okular::ExportFormat> m_exportFormats;
QList<QAction*> m_bookmarkActions;
bool m_cliPresentation;
bool m_cliPrint;
QString m_addBookmarkText;
QIcon m_addBookmarkIcon;
EmbedMode m_embedMode;
QUrl m_realUrl;
KXMLGUIClient *m_generatorGuiClient;
FileKeeper *m_keeper;
// Timer for m_infoMessage
QTimer *m_infoTimer;
private Q_SLOTS:
void slotAnnotationPreferences();
void slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool *handled);
};
}
#endif
/* kate: replace-tabs on; indent-width 4; */