1 /* 2 SPDX-FileCopyrightText: 2005 Enrico Ros <eros.kde@email.it> 3 4 SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 7 #ifndef _OKULAR_PAGEVIEWANNOTATOR_H_ 8 #define _OKULAR_PAGEVIEWANNOTATOR_H_ 9 10 #include <QLinkedList> 11 #include <QObject> 12 #include <qdom.h> 13 14 #include <KActionCollection> 15 16 #include "annotationtools.h" 17 #include "pageviewutils.h" 18 19 class QKeyEvent; 20 class QMouseEvent; 21 class QPainter; 22 class AnnotationActionHandler; 23 24 namespace Okular 25 { 26 class Document; 27 } 28 29 // engines are defined and implemented in the cpp 30 class AnnotatorEngine; 31 class AnnotationTools; 32 class PageView; 33 34 /** 35 * @short PageView object devoted to annotation creation/handling. 36 * 37 * PageViewAnnotator is the okular class used for visually creating annotations. 38 * It uses internal 'engines' for interacting with user events and attaches 39 * the newly created annotation to the document when the creation is complete. 40 * In the meanwhile all PageView events (actually mouse/paint ones) are routed 41 * to this class that performs a rough visual representation of what the 42 * annotation will become when finished. 43 * 44 * m_builtinToolsDefinition is a AnnotationTools object that wraps a DOM object that 45 * contains Annotations/Engine association for the items placed in the toolbar. 46 * The XML is parsed after selecting a toolbar item, in which case an Ann is 47 * initialized with the values in the XML and an engine is created to handle 48 * that annotation. m_builtinToolsDefinition is created in reparseConfig according to 49 * user configuration. m_builtinToolsDefinition is updated (and saved to disk) (1) each 50 * time a property of an annotation (color, font, etc) is changed by the user, 51 * and (2) each time a "quick annotation" is selected, in which case the properties 52 * of the selected quick annotation are written over those of the corresponding 53 * builtin tool 54 */ 55 class PageViewAnnotator : public QObject 56 { 57 Q_OBJECT 58 public: 59 static const int STAMP_TOOL_ID; 60 61 PageViewAnnotator(PageView *parent, Okular::Document *storage); 62 ~PageViewAnnotator() override; 63 64 // methods used when creating the annotation 65 // @return Is a tool currently selected? 66 bool active() const; 67 // @return Are we currently annotating (using the selected tool)? 68 bool annotating() const; 69 70 void setSignatureMode(bool enabled); 71 bool signatureMode() const; 72 73 // returns the preferred cursor for the current tool. call this only 74 // if active() == true 75 QCursor cursor() const; 76 77 QRect routeMouseEvent(QMouseEvent *event, PageViewItem *item); 78 QRect routeTabletEvent(QTabletEvent *event, PageViewItem *item, const QPoint localOriginInGlobal); 79 QRect performRouteMouseOrTabletEvent(const AnnotatorEngine::EventType eventType, const AnnotatorEngine::Button button, const AnnotatorEngine::Modifiers modifiers, const QPointF pos, PageViewItem *item); 80 bool routeKeyEvent(QKeyEvent *event); 81 bool routePaints(const QRect wantedRect) const; 82 void routePaint(QPainter *painter, const QRect paintRect); 83 84 void reparseConfig(); 85 86 static QString defaultToolName(const QDomElement &toolElement); 87 static QPixmap makeToolPixmap(const QDomElement &toolElement); 88 89 // methods related to the annotation actions 90 void setupActions(KActionCollection *ac); 91 // setup those actions that first require the GUI is fully created 92 void setupActionsPostGUIActivated(); 93 // @return Is continuous mode active (pin annotation)? 94 bool continuousMode(); 95 /** 96 * State of constrain ratio and angle action. 97 * While annotating, this value is XOR-ed with the Shift modifier. 98 */ 99 bool constrainRatioAndAngleActive(); 100 // enable/disable the annotation actions 101 void setToolsEnabled(bool enabled); 102 // enable/disable the text-selection annotation actions 103 void setTextToolsEnabled(bool enabled); 104 105 enum class ShowTip { Yes, No }; 106 // selects the active tool 107 void selectBuiltinTool(int toolId, ShowTip showTip); 108 // selects a stamp tool and sets the stamp symbol 109 void selectStampTool(const QString &stampSymbol); 110 // selects the active quick tool 111 void selectQuickTool(int toolId); 112 // selects the last used tool 113 void selectLastTool(); 114 // deselects the tool and uncheck all the annotation actions 115 void detachAnnotation(); 116 117 // returns the builtin annotation tool with the given Id 118 QDomElement builtinTool(int toolId); 119 // returns the quick annotation tool with the given Id 120 QDomElement quickTool(int toolId); 121 122 // methods that write the properties 123 void setAnnotationWidth(double width); 124 void setAnnotationColor(const QColor &color); 125 void setAnnotationInnerColor(const QColor &color); 126 void setAnnotationOpacity(double opacity); 127 void setAnnotationFont(const QFont &font); 128 129 public Q_SLOTS: 130 void setContinuousMode(bool enabled); 131 /** 132 * State of constrain ratio and angle action. 133 * While annotating, this value is XOR-ed with the Shift modifier. 134 */ 135 void setConstrainRatioAndAngle(bool enabled); 136 void addToQuickAnnotations(); 137 void slotAdvancedSettings(); 138 139 Q_SIGNALS: 140 /** 141 * This signal is emitted whenever an annotation tool is activated or all the tools get deactivated 142 */ 143 void toolActive(bool active); 144 void requestOpenFile(const QString &filePath, int pageNumber); 145 146 private: 147 void reparseBuiltinToolsConfig(); 148 void reparseQuickToolsConfig(); 149 // save the builtin annotation tools to Okular settings 150 void saveBuiltinAnnotationTools(); 151 // selects the active tool 152 void selectTool(AnnotationTools *toolsDefinition, int toolId, ShowTip showTip); 153 // returns the engine QDomElement of the the currently active tool 154 QDomElement currentEngineElement(); 155 // returns the annotation QDomElement of the the currently active tool 156 QDomElement currentAnnotationElement(); 157 158 // global class pointers 159 Okular::Document *m_document; 160 PageView *m_pageView; 161 AnnotationActionHandler *m_actionHandler; 162 AnnotatorEngine *m_engine; 163 AnnotationTools *m_builtinToolsDefinition; 164 AnnotationTools *m_quickToolsDefinition; 165 bool m_continuousMode; 166 bool m_constrainRatioAndAngle; 167 bool m_signatureMode; 168 169 // creation related variables 170 AnnotationTools *m_lastToolsDefinition; 171 int m_lastToolId; 172 QRect m_lastDrawnRect; 173 PageViewItem *m_lockedItem; 174 // selected annotation name 175 // QString m_selectedAnnotationName; 176 }; 177 178 #endif 179 180 /* kate: replace-tabs on; indent-width 4; */ 181