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 
438  void setPrevViewport();
439 
444  void setNextViewport();
445 
449  void setNextDocumentViewport(const DocumentViewport &viewport);
450 
456  void setNextDocumentDestination(const QString &namedDestination);
457 
461  void setZoom(int factor, DocumentObserver *excludeObserver = nullptr);
462 
467  NoOption = 0,
468  RemoveAllPrevious = 1
469  };
470  Q_DECLARE_FLAGS(PixmapRequestFlags, PixmapRequestFlag)
471 
472 
477  void requestPixmaps(const QLinkedList<PixmapRequest *> &requests);
478 
487  void requestPixmaps(const QLinkedList<PixmapRequest *> &requests, PixmapRequestFlags reqOptions);
488 
492  void requestTextPage(uint pageNumber);
493 
497  void addPageAnnotation(int page, Annotation *annotation);
498 
504  bool canModifyPageAnnotation(const Annotation *annotation) const;
505 
512  void prepareToModifyAnnotationProperties(Annotation *annotation);
513 
521  void modifyPageAnnotationProperties(int page, Annotation *annotation);
522 
531  void translatePageAnnotation(int page, Annotation *annotation, const Okular::NormalizedPoint &delta);
532 
545  void adjustPageAnnotation(int page, Annotation *annotation, const Okular::NormalizedPoint &delta1, const Okular::NormalizedPoint &delta2);
546 
558  void editPageAnnotationContents(int page, Annotation *annotation, const QString &newContents, int newCursorPos, int prevCursorPos, int prevAnchorPos);
559 
565  bool canRemovePageAnnotation(const Annotation *annotation) const;
566 
570  void removePageAnnotation(int page, Annotation *annotation);
571 
575  void removePageAnnotations(int page, const QList<Annotation *> &annotations);
576 
586  void setPageTextSelection(int page, RegularAreaRect *rect, const QColor &color);
587 
592  bool canUndo() const;
593 
598  bool canRedo() const;
599 
603  enum SearchType {
608  GoogleAny
609  };
610 
614  // TODO remove EndOfDocumentReached when we break API
619  EndOfDocumentReached
620  };
621 
633  void searchText(int searchID, const QString &text, bool fromStart, Qt::CaseSensitivity caseSensitivity, SearchType type, bool moveViewport, const QColor &color);
634 
638  void continueSearch(int searchID);
639 
646  void continueSearch(int searchID, SearchType type);
647 
651  void resetSearch(int searchID);
652 
656  BookmarkManager *bookmarkManager() const;
657 
661  void processAction(const Action *action);
662 
668  void processFormatAction(const Action *action, Okular::FormFieldText *fft);
669 
675  void processKeystrokeAction(const Action *action, Okular::FormFieldText *fft, bool &returnCode);
676 
682  void processFocusAction(const Action *action, Okular::FormField *field);
683 
689  void processValidateAction(const Action *action, Okular::FormFieldText *fft, bool &returnCode);
690 
694  QList<int> bookmarkedPageList() const;
695 
699  QString bookmarkedPageRange() const;
700 
704  void processSourceReference(const SourceReference *reference);
705 
709  bool canConfigurePrinter() const;
710 
717  PostscriptPrinting
718  };
719 
724  PrintingType printingSupport() const;
725 
729  bool supportsPrintToFile() const;
730 
734  bool print(QPrinter &printer);
735 
740  QString printError() const;
741 
750  QWidget *printConfigurationWidget() const;
751 
756  void fillConfigDialog(KConfigDialog *dialog);
757 
761  int configurableGenerators() const;
762 
766  QStringList supportedMimeTypes() const;
767 
771  KPluginMetaData generatorInfo() const;
772 
779  bool canSwapBackingFile() const;
780 
793  bool swapBackingFile(const QString &newFileName, const QUrl &url);
794 
806  bool swapBackingFileArchive(const QString &newFileName, const QUrl &url);
807 
813  void setHistoryClean(bool clean);
814 
823  SaveFormsCapability = 1,
824  SaveAnnotationsCapability = 2
825  };
826 
833  bool canSaveChanges(SaveCapability cap) const;
834 
844  bool canSaveChanges() const;
845 
852  bool saveChanges(const QString &fileName);
853 
860  bool saveChanges(const QString &fileName, QString *errorText);
861 
869  void registerView(View *view);
870 
876  void unregisterView(View *view);
877 
883  QByteArray fontData(const FontInfo &font) const;
884 
890  OpenResult openDocumentArchive(const QString &docFile, const QUrl &url, const QString &password = QString());
891 
897  bool saveDocumentArchive(const QString &fileName);
898 
906  bool extractArchivedFile(const QString &destFileName);
907 
917  const SourceReference *dynamicSourceReference(int pageNr, double absX, double absY);
918 
926  QPrinter::Orientation orientation() const;
927 
934  void setAnnotationEditingEnabled(bool enable);
935 
941  void walletDataForFile(const QString &fileName, QString *walletName, QString *walletFolder, QString *walletKey) const;
942 
951  bool isDocdataMigrationNeeded() const;
952 
960  void docdataMigrationDone();
961 
967  QAbstractItemModel *layersModel() const;
968 
974  QString openError() const;
975 
976 public Q_SLOTS:
981  void setRotation(int rotation);
982 
987  void setPageSize(const Okular::PageSize &size);
988 
992  void cancelSearch();
993 
998  void undo();
999 
1004  void redo();
1005 
1012  void editFormText(int pageNumber, Okular::FormFieldText *form, const QString &newContents, int newCursorPos, int prevCursorPos, int prevAnchorPos);
1013 
1018  void editFormList(int pageNumber, Okular::FormFieldChoice *form, const QList<int> &newChoices);
1019 
1028  void editFormCombo(int pageNumber, Okular::FormFieldChoice *form, const QString &newText, int newCursorPos, int prevCursorPos, int prevAnchorPos);
1029 
1035  void editFormButtons(int pageNumber, const QList<Okular::FormFieldButton *> &formButtons, const QList<bool> &newButtonStates);
1036 
1042  void reloadDocument() const;
1043 
1049  QByteArray requestSignedRevisionData(const Okular::SignatureInfo &info);
1050 
1056  void refreshPixmaps(int pageNumber);
1057 
1058 Q_SIGNALS:
1063  void aboutToClose();
1064 
1069  void close();
1070 
1075  void quit();
1076 
1081  void linkFind();
1082 
1087  void linkGoToPage();
1088 
1093  void linkPresentation();
1094 
1099  void linkEndPresentation();
1100 
1105  void openUrl(const QUrl &url);
1106 
1113  void error(const QString &text, int duration);
1114 
1121  void warning(const QString &text, int duration);
1122 
1129  void notice(const QString &text, int duration);
1130 
1135  void gotFont(const Okular::FontInfo &font);
1136 
1142  void fontReadingProgress(int page);
1143 
1147  void fontReadingEnded();
1148 
1152  void searchFinished(int searchID, Okular::Document::SearchStatus endStatus);
1153 
1167  void sourceReferenceActivated(const QString &absFileName, int line, int col, bool *handled);
1168 
1172  void processMovieAction(const Okular::MovieAction *action);
1173 
1178  void canUndoChanged(bool undoAvailable);
1179 
1184  void canRedoChanged(bool redoAvailable);
1185 
1190  void undoHistoryCleanChanged(bool clean);
1191 
1197  void processRenditionAction(const Okular::RenditionAction *action);
1198 
1207  void annotationContentsChangedByUndoRedo(Okular::Annotation *annotation, const QString &contents, int cursorPos, int anchorPos);
1208 
1217  void formTextChangedByUndoRedo(int page, Okular::FormFieldText *form, const QString &contents, int cursorPos, int anchorPos);
1218 
1224  void formListChangedByUndoRedo(int page, Okular::FormFieldChoice *form, const QList<int> &choices);
1225 
1231  void formComboChangedByUndoRedo(int page, Okular::FormFieldChoice *form, const QString &text, int cursorPos, int anchorPos);
1232 
1238  void formButtonsChangedByUndoRedo(int page, const QList<Okular::FormFieldButton *> &formButtons);
1239 
1245  void refreshFormWidget(Okular::FormField *field);
1246 
1247 private:
1249  friend class DocumentPrivate;
1250  friend class ::DocumentItem;
1251  friend class EditAnnotationContentsCommand;
1252  friend class EditFormTextCommand;
1253  friend class EditFormListCommand;
1254  friend class EditFormComboCommand;
1255  friend class EditFormButtonsCommand;
1257  DocumentPrivate *const d;
1258 
1259  Q_DISABLE_COPY(Document)
1260 };
1261 
1269 class OKULARCORE_EXPORT DocumentViewport
1270 {
1271 public:
1275  DocumentViewport(int number = -1);
1276 
1280  DocumentViewport(const QString &xmlDesc);
1281 
1285  QString toString() const;
1286 
1290  bool isValid() const;
1291 
1295  bool operator==(const DocumentViewport &other) const;
1296  bool operator<(const DocumentViewport &other) const;
1297 
1302 
1306  enum Position {
1307  Center = 1,
1308  TopLeft = 2
1309  };
1310 
1315  struct {
1316  bool enabled;
1317  double normalizedX;
1318  double normalizedY;
1319  Position pos;
1320  } rePos;
1321 
1325  struct {
1326  bool enabled;
1327  bool width;
1328  bool height;
1329  } autoFit;
1330 };
1331 
1350 class OKULARCORE_EXPORT DocumentSynopsis : public QDomDocument
1351 {
1352 public:
1356  DocumentSynopsis();
1357 
1362  DocumentSynopsis(const QDomDocument &document);
1363 };
1364 
1374 class OKULARCORE_EXPORT EmbeddedFile
1375 {
1376 public:
1380  EmbeddedFile();
1381 
1385  virtual ~EmbeddedFile();
1386 
1387  EmbeddedFile(const EmbeddedFile &) = delete;
1388  EmbeddedFile &operator=(const EmbeddedFile &) = delete;
1389 
1393  virtual QString name() const = 0;
1394 
1399  virtual QString description() const = 0;
1400 
1404  virtual QByteArray data() const = 0;
1405 
1412  virtual int size() const = 0;
1413 
1418  virtual QDateTime modificationDate() const = 0;
1419 
1424  virtual QDateTime creationDate() const = 0;
1425 };
1426 
1430 class OKULARCORE_EXPORT VisiblePageRect
1431 {
1432 public:
1439  explicit VisiblePageRect(int pageNumber = -1, const NormalizedRect &rectangle = NormalizedRect());
1440 
1445 
1450 };
1451 
1452 }
1453 
1454 Q_DECLARE_METATYPE(Okular::DocumentInfo::Key)
1455 Q_DECLARE_OPERATORS_FOR_FLAGS(Okular::Document::PixmapRequestFlags)
1456 
1457 #endif
1458 
1459 /* 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:715
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:716
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:606
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:603
SaveCapability
Saving capabilities.
Definition: document.h:822
global.h
Definition: action.h:19
An embedded file into the document.
Definition: document.h:1374
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:714
PixmapRequestFlag
Describes the possible options for the pixmap requests.
Definition: document.h:466
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:615
No match was found.
Definition: document.h:617
Interface of a choice form field.
Definition: form.h:336
Search complete document (all words in google style)
Definition: document.h:607
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:1430
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:1301
Search previous match.
Definition: document.h:605
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:1449
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:618
Permission
Describes the DRM capabilities.
Definition: global.h:26
A view on the document.
Definition: document.h:1269
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:616
Search next match.
Definition: document.h:604
Position
Describes the relative position of the viewport.
Definition: document.h:1306
The description of the document.
Definition: document.h:85
int pageNumber
The page number where the rectangle is located.
Definition: document.h:1444
A DOM tree that describes the Table of Contents.
Definition: document.h:1350
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 Tue Jul 14 2020 22:36:02 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.