Okular

document.h
1 /***************************************************************************
2  * Copyright (C) 2004-2005 by Enrico Ros <[email protected]> *
3  * Copyright (C) 2004-2008 by Albert Astals Cid <[email protected]> *
4  * Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group *
5  * company, [email protected] Work sponsored by the *
6  * LiMux project of the city of Munich *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  ***************************************************************************/
13 
14 #ifndef _OKULAR_DOCUMENT_H_
15 #define _OKULAR_DOCUMENT_H_
16 
17 #include "area.h"
18 #include "global.h"
19 #include "okularcore_export.h"
20 #include "pagesize.h"
21 
22 #include <QDomDocument>
23 #include <QObject>
24 #include <QPrinter>
25 #include <QStringList>
26 #include <QVector>
27 
28 #include <QMimeType>
29 #include <QUrl>
30 
31 class KConfigDialog;
32 class KPluginMetaData;
33 class KXMLGUIClient;
34 class DocumentItem;
35 class QAbstractItemModel;
36 
37 namespace Okular
38 {
39 class Annotation;
40 class BookmarkManager;
41 class DocumentInfoPrivate;
42 class DocumentObserver;
43 class DocumentPrivate;
44 class DocumentSynopsis;
45 class DocumentViewport;
46 class EmbeddedFile;
47 class ExportFormat;
48 class FontInfo;
49 class FormField;
50 class FormFieldText;
51 class FormFieldButton;
52 class FormFieldChoice;
53 class Generator;
54 class Action;
55 class MovieAction;
56 class Page;
57 class PixmapRequest;
58 class RenditionAction;
59 class SourceReference;
60 class View;
61 class VisiblePageRect;
62 class SignatureInfo;
63 
65 #define PART_SEARCH_ID 1
66 #define PAGEVIEW_SEARCH_ID 2
67 #define SW_SEARCH_ID 3
68 #define PRESENTATION_SEARCH_ID 4
69 
74 class OKULARCORE_EXPORT DocumentInfo
75 {
76  friend class Document;
77 
78 public:
82  enum Key {
100  Invalid
101  };
102 
106  DocumentInfo();
107  DocumentInfo(const DocumentInfo &info);
108  DocumentInfo &operator=(const DocumentInfo &);
109 
110  ~DocumentInfo();
111 
117  QStringList keys() const;
118 
123  QString get(Key key) const;
124 
129  QString get(const QString &key) const;
130 
135  void set(const QString &key, const QString &value, const QString &title = QString());
136 
141  void set(Key key, const QString &value);
142 
149  QString getKeyTitle(const QString &key) const;
150 
155  static QString getKeyString(Key key);
156 
161  static QString getKeyTitle(Key key);
162 
167  static Key getKeyFromString(const QString &key);
168 
169 private:
170  DocumentInfoPrivate *d;
171 };
172 
190 class OKULARCORE_EXPORT Document : public QObject
191 {
192  Q_OBJECT
193 
194 public:
198  explicit Document(QWidget *widget);
199 
203  ~Document() override;
204 
209  enum OpenResult {
210  OpenSuccess, //< The document was opened successfully
211  OpenError, //< The document failed to open
212  OpenNeedsPassword //< The document needs a password to be opened or the one provided is not the correct
213  };
214 
219  OpenResult openDocument(const QString &docFile, const QUrl &url, const QMimeType &mime, const QString &password = QString());
220 
224  void closeDocument();
225 
229  void addObserver(DocumentObserver *observer);
230 
234  void removeObserver(DocumentObserver *observer);
235 
239  void reparseConfig();
240 
244  bool isOpened() const;
245 
249  DocumentInfo documentInfo() const;
250 
255  DocumentInfo documentInfo(const QSet<DocumentInfo::Key> &keys) const;
256 
261  const DocumentSynopsis *documentSynopsis() const;
262 
270  void startFontReading();
271 
276  void stopFontReading();
277 
282  bool canProvideFontInformation() const;
283 
288  const QList<EmbeddedFile *> *embeddedFiles() const;
289 
294  const Page *page(int number) const;
295 
299  const DocumentViewport &viewport() const;
300 
305  void setVisiblePageRects(const QVector<VisiblePageRect *> &visiblePageRects, DocumentObserver *excludeObserver = nullptr);
306 
310  const QVector<VisiblePageRect *> &visiblePageRects() const;
311 
315  uint currentPage() const;
316 
320  uint pages() const;
321 
325  QUrl currentDocument() const;
326 
331  bool isAllowed(Permission action) const;
332 
336  bool supportsSearching() const;
337 
341  bool supportsPageSizes() const;
342 
348  bool supportsTiles() const;
349 
355  PageSize::List pageSizes() const;
356 
360  bool canExportToText() const;
361 
365  bool exportToText(const QString &fileName) const;
366 
371  QList<ExportFormat> exportFormats() const;
372 
376  bool exportTo(const QString &fileName, const ExportFormat &format) const;
377 
381  bool historyAtBegin() const;
382 
386  bool historyAtEnd() const;
387 
392  QVariant metaData(const QString &key, const QVariant &option = QVariant()) const;
393 
397  Rotation rotation() const;
398 
403  QSizeF allPagesSize() const;
404 
409  QString pageSizeString(int page) const;
410 
414  KXMLGUIClient *guiClient();
415 
423  void setViewportPage(int page, DocumentObserver *excludeObserver = nullptr, bool smoothMove = false);
424 
432  void setViewport(const DocumentViewport &viewport, DocumentObserver *excludeObserver = nullptr, bool smoothMove = false);
433 
443  void setViewportWithHistory(const DocumentViewport &viewport, DocumentObserver *excludeObserver = nullptr, bool smoothMove = false, bool updateHistory = true);
444 
449  void setPrevViewport();
450 
455  void setNextViewport();
456 
460  void setNextDocumentViewport(const DocumentViewport &viewport);
461 
467  void setNextDocumentDestination(const QString &namedDestination);
468 
472  void setZoom(int factor, DocumentObserver *excludeObserver = nullptr);
473 
478  NoOption = 0,
479  RemoveAllPrevious = 1
480  };
481  Q_DECLARE_FLAGS(PixmapRequestFlags, PixmapRequestFlag)
482 
483 
488  void requestPixmaps(const QLinkedList<PixmapRequest *> &requests);
489 
498  void requestPixmaps(const QLinkedList<PixmapRequest *> &requests, PixmapRequestFlags reqOptions);
499 
503  void requestTextPage(uint pageNumber);
504 
508  void addPageAnnotation(int page, Annotation *annotation);
509 
515  bool canModifyPageAnnotation(const Annotation *annotation) const;
516 
523  void prepareToModifyAnnotationProperties(Annotation *annotation);
524 
532  void modifyPageAnnotationProperties(int page, Annotation *annotation);
533 
542  void translatePageAnnotation(int page, Annotation *annotation, const Okular::NormalizedPoint &delta);
543 
556  void adjustPageAnnotation(int page, Annotation *annotation, const Okular::NormalizedPoint &delta1, const Okular::NormalizedPoint &delta2);
557 
569  void editPageAnnotationContents(int page, Annotation *annotation, const QString &newContents, int newCursorPos, int prevCursorPos, int prevAnchorPos);
570 
576  bool canRemovePageAnnotation(const Annotation *annotation) const;
577 
581  void removePageAnnotation(int page, Annotation *annotation);
582 
586  void removePageAnnotations(int page, const QList<Annotation *> &annotations);
587 
597  void setPageTextSelection(int page, RegularAreaRect *rect, const QColor &color);
598 
603  bool canUndo() const;
604 
609  bool canRedo() const;
610 
614  enum SearchType {
619  GoogleAny
620  };
621 
625  // TODO remove EndOfDocumentReached when we break API
630  EndOfDocumentReached
631  };
632 
644  void searchText(int searchID, const QString &text, bool fromStart, Qt::CaseSensitivity caseSensitivity, SearchType type, bool moveViewport, const QColor &color);
645 
649  void continueSearch(int searchID);
650 
657  void continueSearch(int searchID, SearchType type);
658 
662  void resetSearch(int searchID);
663 
667  BookmarkManager *bookmarkManager() const;
668 
672  void processAction(const Action *action);
673 
679  void processFormatAction(const Action *action, Okular::FormFieldText *fft);
680 
686  void processKeystrokeAction(const Action *action, Okular::FormFieldText *fft, bool &returnCode);
687 
693  void processFocusAction(const Action *action, Okular::FormField *field);
694 
700  void processValidateAction(const Action *action, Okular::FormFieldText *fft, bool &returnCode);
701 
705  QList<int> bookmarkedPageList() const;
706 
710  QString bookmarkedPageRange() const;
711 
715  void processSourceReference(const SourceReference *reference);
716 
720  bool canConfigurePrinter() const;
721 
728  PostscriptPrinting
729  };
730 
735  PrintingType printingSupport() const;
736 
740  bool supportsPrintToFile() const;
741 
745  bool print(QPrinter &printer);
746 
751  QString printError() const;
752 
761  QWidget *printConfigurationWidget() const;
762 
767  void fillConfigDialog(KConfigDialog *dialog);
768 
772  int configurableGenerators() const;
773 
777  QStringList supportedMimeTypes() const;
778 
782  KPluginMetaData generatorInfo() const;
783 
790  bool canSwapBackingFile() const;
791 
804  bool swapBackingFile(const QString &newFileName, const QUrl &url);
805 
817  bool swapBackingFileArchive(const QString &newFileName, const QUrl &url);
818 
824  void setHistoryClean(bool clean);
825 
834  SaveFormsCapability = 1,
835  SaveAnnotationsCapability = 2
836  };
837 
844  bool canSaveChanges(SaveCapability cap) const;
845 
855  bool canSaveChanges() const;
856 
863  bool saveChanges(const QString &fileName);
864 
871  bool saveChanges(const QString &fileName, QString *errorText);
872 
880  void registerView(View *view);
881 
887  void unregisterView(View *view);
888 
894  QByteArray fontData(const FontInfo &font) const;
895 
901  OpenResult openDocumentArchive(const QString &docFile, const QUrl &url, const QString &password = QString());
902 
908  bool saveDocumentArchive(const QString &fileName);
909 
917  bool extractArchivedFile(const QString &destFileName);
918 
928  const SourceReference *dynamicSourceReference(int pageNr, double absX, double absY);
929 
937  QPrinter::Orientation orientation() const;
938 
945  void setAnnotationEditingEnabled(bool enable);
946 
952  void walletDataForFile(const QString &fileName, QString *walletName, QString *walletFolder, QString *walletKey) const;
953 
962  bool isDocdataMigrationNeeded() const;
963 
971  void docdataMigrationDone();
972 
978  QAbstractItemModel *layersModel() const;
979 
985  QString openError() const;
986 
987 public Q_SLOTS:
992  void setRotation(int rotation);
993 
998  void setPageSize(const Okular::PageSize &size);
999 
1003  void cancelSearch();
1004 
1009  void undo();
1010 
1015  void redo();
1016 
1023  void editFormText(int pageNumber, Okular::FormFieldText *form, const QString &newContents, int newCursorPos, int prevCursorPos, int prevAnchorPos);
1024 
1029  void editFormList(int pageNumber, Okular::FormFieldChoice *form, const QList<int> &newChoices);
1030 
1039  void editFormCombo(int pageNumber, Okular::FormFieldChoice *form, const QString &newText, int newCursorPos, int prevCursorPos, int prevAnchorPos);
1040 
1046  void editFormButtons(int pageNumber, const QList<Okular::FormFieldButton *> &formButtons, const QList<bool> &newButtonStates);
1047 
1053  void reloadDocument() const;
1054 
1060  QByteArray requestSignedRevisionData(const Okular::SignatureInfo &info);
1061 
1067  void refreshPixmaps(int pageNumber);
1068 
1069 Q_SIGNALS:
1074  void aboutToClose();
1075 
1080  void close();
1081 
1086  void quit();
1087 
1092  void linkFind();
1093 
1098  void linkGoToPage();
1099 
1104  void linkPresentation();
1105 
1110  void linkEndPresentation();
1111 
1116  void openUrl(const QUrl &url);
1117 
1124  void error(const QString &text, int duration);
1125 
1132  void warning(const QString &text, int duration);
1133 
1140  void notice(const QString &text, int duration);
1141 
1146  void gotFont(const Okular::FontInfo &font);
1147 
1153  void fontReadingProgress(int page);
1154 
1158  void fontReadingEnded();
1159 
1163  void searchFinished(int searchID, Okular::Document::SearchStatus endStatus);
1164 
1178  void sourceReferenceActivated(const QString &absFileName, int line, int col, bool *handled);
1179 
1183  void processMovieAction(const Okular::MovieAction *action);
1184 
1189  void canUndoChanged(bool undoAvailable);
1190 
1195  void canRedoChanged(bool redoAvailable);
1196 
1201  void undoHistoryCleanChanged(bool clean);
1202 
1208  void processRenditionAction(const Okular::RenditionAction *action);
1209 
1218  void annotationContentsChangedByUndoRedo(Okular::Annotation *annotation, const QString &contents, int cursorPos, int anchorPos);
1219 
1228  void formTextChangedByUndoRedo(int page, Okular::FormFieldText *form, const QString &contents, int cursorPos, int anchorPos);
1229 
1235  void formListChangedByUndoRedo(int page, Okular::FormFieldChoice *form, const QList<int> &choices);
1236 
1242  void formComboChangedByUndoRedo(int page, Okular::FormFieldChoice *form, const QString &text, int cursorPos, int anchorPos);
1243 
1249  void formButtonsChangedByUndoRedo(int page, const QList<Okular::FormFieldButton *> &formButtons);
1250 
1256  void refreshFormWidget(Okular::FormField *field);
1257 
1258 private:
1260  friend class DocumentPrivate;
1261  friend class ::DocumentItem;
1262  friend class EditAnnotationContentsCommand;
1263  friend class EditFormTextCommand;
1264  friend class EditFormListCommand;
1265  friend class EditFormComboCommand;
1266  friend class EditFormButtonsCommand;
1268  DocumentPrivate *const d;
1269 
1270  Q_DISABLE_COPY(Document)
1271 };
1272 
1280 class OKULARCORE_EXPORT DocumentViewport
1281 {
1282 public:
1286  DocumentViewport(int number = -1);
1287 
1291  DocumentViewport(const QString &xmlDesc);
1292 
1296  QString toString() const;
1297 
1301  bool isValid() const;
1302 
1306  bool operator==(const DocumentViewport &other) const;
1307  bool operator<(const DocumentViewport &other) const;
1308 
1313 
1317  enum Position {
1318  Center = 1,
1319  TopLeft = 2
1320  };
1321 
1326  struct {
1327  bool enabled;
1328  double normalizedX;
1329  double normalizedY;
1330  Position pos;
1331  } rePos;
1332 
1336  struct {
1337  bool enabled;
1338  bool width;
1339  bool height;
1340  } autoFit;
1341 };
1342 
1361 class OKULARCORE_EXPORT DocumentSynopsis : public QDomDocument
1362 {
1363 public:
1367  DocumentSynopsis();
1368 
1373  DocumentSynopsis(const QDomDocument &document);
1374 };
1375 
1385 class OKULARCORE_EXPORT EmbeddedFile
1386 {
1387 public:
1391  EmbeddedFile();
1392 
1396  virtual ~EmbeddedFile();
1397 
1398  EmbeddedFile(const EmbeddedFile &) = delete;
1399  EmbeddedFile &operator=(const EmbeddedFile &) = delete;
1400 
1404  virtual QString name() const = 0;
1405 
1410  virtual QString description() const = 0;
1411 
1415  virtual QByteArray data() const = 0;
1416 
1423  virtual int size() const = 0;
1424 
1429  virtual QDateTime modificationDate() const = 0;
1430 
1435  virtual QDateTime creationDate() const = 0;
1436 };
1437 
1441 class OKULARCORE_EXPORT VisiblePageRect
1442 {
1443 public:
1450  explicit VisiblePageRect(int pageNumber = -1, const NormalizedRect &rectangle = NormalizedRect());
1451 
1456 
1461 };
1462 
1463 }
1464 
1465 Q_DECLARE_METATYPE(Okular::DocumentInfo::Key)
1466 Q_DECLARE_OPERATORS_FOR_FLAGS(Okular::Document::PixmapRequestFlags)
1467 
1468 #endif
1469 
1470 /* kate: replace-tabs on; indent-width 4; */
NormalizedPoint is a helper class which stores the coordinates of a normalized point.
Definition: area.h:119
Rotation
A rotation.
Definition: global.h:48
Printing Not Supported.
Definition: document.h:726
The category of the document.
Definition: document.h:94
The copyright of the document.
Definition: document.h:89
The mime type of the document.
Definition: document.h:93
Native Cross-Platform Printing.
Definition: document.h:727
The author of the document.
Definition: document.h:86
View on the document.
Definition: view.h:32
The path of the file.
Definition: document.h:96
The subject of the document.
Definition: document.h:84
Search complete document.
Definition: document.h:617
A NormalizedRect is a rectangle which can be defined by two NormalizedPoints.
Definition: area.h:191
This is a list of NormalizedRect, to describe an area consisting of multiple rectangles using normali...
Definition: area.h:911
SearchType
Describes the possible search types.
Definition: document.h:614
SaveCapability
Saving capabilities.
Definition: document.h:833
global.h
Definition: action.h:19
An embedded file into the document.
Definition: document.h:1385
Key
The list of predefined keys.
Definition: document.h:82
OpenResult
Describes the result of an open document operation.
Definition: document.h:209
Interface of a text form field.
Definition: form.h:249
The title of the document.
Definition: document.h:83
The Movie action executes an operation on a video on activation.
Definition: action.h:448
PrintingType
What type of printing a document supports.
Definition: document.h:725
PixmapRequestFlag
Describes the possible options for the pixmap requests.
Definition: document.h:477
A small class that represents the information of a font.
Definition: fontinfo.h:27
The date of creation of the document.
Definition: document.h:91
SearchStatus
Describes how search ended.
Definition: document.h:626
No match was found.
Definition: document.h:628
Interface of a choice form field.
Definition: form.h:336
Search complete document (all words in google style)
Definition: document.h:618
CaseSensitivity
The Document.
Definition: document.h:190
Collector for all the data belonging to a page.
Definition: page.h:52
An area of a specified page.
Definition: document.h:1441
A helper class to store information about digital signature.
int pageNumber
The number of the page nearest the center of the viewport.
Definition: document.h:1312
Search previous match.
Definition: document.h:616
The keywords which describe the content of the document.
Definition: document.h:95
Encapsulates data that describes an action.
Definition: action.h:43
The DocumentInfo structure can be filled in by generators to display metadata about the currently ope...
Definition: document.h:74
NormalizedRect rect
The rectangle in normalized coordinates.
Definition: document.h:1460
Defines a source reference.
All the custom keys the generator supports.
Definition: document.h:99
The number of pages of the document.
Definition: document.h:90
The size of the document.
Definition: document.h:97
Defines an entry for the export menu.
Definition: generator.h:80
The creator of the document (this can be different from the author)
Definition: document.h:87
Annotation struct holds properties shared by all annotations.
Definition: annotations.h:88
A small class that represents the size of a page.
Definition: pagesize.h:26
The size of the pages (if all pages have the same size)
Definition: document.h:98
Base class for objects being notified when something changes.
Definition: observer.h:31
The search was cancelled.
Definition: document.h:629
Permission
Describes the DRM capabilities.
Definition: global.h:26
A view on the document.
Definition: document.h:1280
The Rendition action executes an operation on a video or executes some JavaScript code on activation...
Definition: action.h:502
Any match was found.
Definition: document.h:627
Search next match.
Definition: document.h:615
Position
Describes the relative position of the viewport.
Definition: document.h:1317
The description of the document.
Definition: document.h:85
int pageNumber
The page number where the rectangle is located.
Definition: document.h:1455
A DOM tree that describes the Table of Contents.
Definition: document.h:1361
Bookmarks manager utility.
Describes a pixmap type request.
Definition: generator.h:630
The date of last modification of the document.
Definition: document.h:92
The base interface of a form field.
Definition: form.h:41
The producer of the document (e.g. some software)
Definition: document.h:88
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Nov 30 2020 22:36:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.