1 /* 2 SPDX-FileCopyrightText: 2013 Jon Mease <jon.mease@gmail.com> 3 4 Work sponsored by the LiMux project of the city of Munich: 5 SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB a KDAB Group company <info@kdab.com> 6 7 SPDX-License-Identifier: GPL-2.0-or-later 8 */ 9 10 #ifndef _OKULAR_DOCUMENT_COMMANDS_P_H_ 11 #define _OKULAR_DOCUMENT_COMMANDS_P_H_ 12 13 #include <QDomNode> 14 #include <QUndoCommand> 15 16 #include "area.h" 17 18 namespace Okular 19 { 20 class Document; 21 class Annotation; 22 class DocumentPrivate; 23 class FormFieldText; 24 class FormFieldButton; 25 class FormFieldChoice; 26 class Page; 27 28 class OkularUndoCommand : public QUndoCommand 29 { 30 public: 31 virtual bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) = 0; 32 }; 33 34 class AddAnnotationCommand : public OkularUndoCommand 35 { 36 public: 37 AddAnnotationCommand(Okular::DocumentPrivate *docPriv, Okular::Annotation *annotation, int pageNumber); 38 39 ~AddAnnotationCommand() override; 40 41 void undo() override; 42 43 void redo() override; 44 45 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 46 47 private: 48 Okular::DocumentPrivate *m_docPriv; 49 Okular::Annotation *m_annotation; 50 int m_pageNumber; 51 bool m_done; 52 }; 53 54 class RemoveAnnotationCommand : public OkularUndoCommand 55 { 56 public: 57 RemoveAnnotationCommand(Okular::DocumentPrivate *doc, Okular::Annotation *annotation, int pageNumber); 58 ~RemoveAnnotationCommand() override; 59 void undo() override; 60 void redo() override; 61 62 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 63 64 private: 65 Okular::DocumentPrivate *m_docPriv; 66 Okular::Annotation *m_annotation; 67 int m_pageNumber; 68 bool m_done; 69 }; 70 71 class ModifyAnnotationPropertiesCommand : public OkularUndoCommand 72 { 73 public: 74 ModifyAnnotationPropertiesCommand(Okular::DocumentPrivate *docPriv, Okular::Annotation *annotation, int pageNumber, const QDomNode &oldProperties, const QDomNode &newProperties); 75 76 void undo() override; 77 void redo() override; 78 79 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 80 81 private: 82 Okular::DocumentPrivate *m_docPriv; 83 Okular::Annotation *m_annotation; 84 int m_pageNumber; 85 QDomNode m_prevProperties; 86 QDomNode m_newProperties; 87 }; 88 89 class TranslateAnnotationCommand : public OkularUndoCommand 90 { 91 public: 92 TranslateAnnotationCommand(Okular::DocumentPrivate *docPriv, Okular::Annotation *annotation, int pageNumber, const Okular::NormalizedPoint &delta, bool completeDrag); 93 void undo() override; 94 void redo() override; 95 int id() const override; 96 bool mergeWith(const QUndoCommand *uc) override; 97 Okular::NormalizedPoint minusDelta(); 98 Okular::NormalizedRect translateBoundingRectangle(const Okular::NormalizedPoint &delta); 99 100 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 101 102 private: 103 Okular::DocumentPrivate *m_docPriv; 104 Okular::Annotation *m_annotation; 105 int m_pageNumber; 106 Okular::NormalizedPoint m_delta; 107 bool m_completeDrag; 108 }; 109 110 class AdjustAnnotationCommand : public OkularUndoCommand 111 { 112 public: 113 AdjustAnnotationCommand(Okular::DocumentPrivate *docPriv, Okular::Annotation *annotation, int pageNumber, const Okular::NormalizedPoint &delta1, const Okular::NormalizedPoint &delta2, bool completeDrag); 114 void undo() override; 115 void redo() override; 116 int id() const override; 117 bool mergeWith(const QUndoCommand *uc) override; 118 Okular::NormalizedRect adjustBoundingRectangle(const Okular::NormalizedPoint &delta1, const Okular::NormalizedPoint &delta2); 119 120 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 121 122 private: 123 Okular::DocumentPrivate *m_docPriv; 124 Okular::Annotation *m_annotation; 125 int m_pageNumber; 126 Okular::NormalizedPoint m_delta1; 127 Okular::NormalizedPoint m_delta2; 128 bool m_completeDrag; 129 }; 130 131 class EditTextCommand : public OkularUndoCommand 132 { 133 public: 134 EditTextCommand(const QString &newContents, int newCursorPos, const QString &prevContents, int prevCursorPos, int prevAnchorPos); 135 136 void undo() override = 0; 137 void redo() override = 0; 138 int id() const override = 0; 139 bool mergeWith(const QUndoCommand *uc) override; 140 141 private: 142 enum EditType { 143 CharBackspace, ///< Edit made up of one or more single character backspace operations 144 CharDelete, ///< Edit made up of one or more single character delete operations 145 CharInsert, ///< Edit made up of one or more single character insertion operations 146 OtherEdit ///< All other edit operations (these will not be merged together) 147 }; 148 149 QString oldContentsLeftOfCursor(); 150 QString newContentsLeftOfCursor(); 151 QString oldContentsRightOfCursor(); 152 QString newContentsRightOfCursor(); 153 154 protected: 155 QString m_newContents; 156 int m_newCursorPos; 157 QString m_prevContents; 158 int m_prevCursorPos; 159 int m_prevAnchorPos; 160 EditType m_editType; 161 }; 162 163 class EditAnnotationContentsCommand : public EditTextCommand 164 { 165 public: 166 EditAnnotationContentsCommand(Okular::DocumentPrivate *docPriv, Okular::Annotation *annotation, int pageNumber, const QString &newContents, int newCursorPos, const QString &prevContents, int prevCursorPos, int prevAnchorPos); 167 168 void undo() override; 169 void redo() override; 170 int id() const override; 171 bool mergeWith(const QUndoCommand *uc) override; 172 173 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 174 175 private: 176 Okular::DocumentPrivate *m_docPriv; 177 Okular::Annotation *m_annotation; 178 int m_pageNumber; 179 }; 180 181 class EditFormTextCommand : public EditTextCommand 182 { 183 public: 184 EditFormTextCommand(Okular::DocumentPrivate *docPriv, Okular::FormFieldText *form, int pageNumber, const QString &newContents, int newCursorPos, const QString &prevContents, int prevCursorPos, int prevAnchorPos); 185 void undo() override; 186 void redo() override; 187 int id() const override; 188 bool mergeWith(const QUndoCommand *uc) override; 189 190 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 191 192 private: 193 Okular::DocumentPrivate *m_docPriv; 194 Okular::FormFieldText *m_form; 195 int m_pageNumber; 196 }; 197 198 class EditFormListCommand : public OkularUndoCommand 199 { 200 public: 201 EditFormListCommand(Okular::DocumentPrivate *docPriv, FormFieldChoice *form, int pageNumber, const QList<int> &newChoices, const QList<int> &prevChoices); 202 203 void undo() override; 204 void redo() override; 205 206 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 207 208 private: 209 Okular::DocumentPrivate *m_docPriv; 210 FormFieldChoice *m_form; 211 int m_pageNumber; 212 QList<int> m_newChoices; 213 QList<int> m_prevChoices; 214 }; 215 216 class EditFormComboCommand : public EditTextCommand 217 { 218 public: 219 EditFormComboCommand(Okular::DocumentPrivate *docPriv, FormFieldChoice *form, int pageNumber, const QString &newContents, int newCursorPos, const QString &prevContents, int prevCursorPos, int prevAnchorPos); 220 221 void undo() override; 222 void redo() override; 223 int id() const override; 224 bool mergeWith(const QUndoCommand *uc) override; 225 226 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 227 228 private: 229 Okular::DocumentPrivate *m_docPriv; 230 FormFieldChoice *m_form; 231 int m_pageNumber; 232 int m_newIndex; 233 int m_prevIndex; 234 }; 235 236 class EditFormButtonsCommand : public OkularUndoCommand 237 { 238 public: 239 EditFormButtonsCommand(Okular::DocumentPrivate *docPriv, int pageNumber, const QList<FormFieldButton *> &formButtons, const QList<bool> &newButtonStates); 240 241 void undo() override; 242 void redo() override; 243 244 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 245 246 private: 247 void clearFormButtonStates(); 248 249 private: 250 Okular::DocumentPrivate *m_docPriv; 251 int m_pageNumber; 252 QList<FormFieldButton *> m_formButtons; 253 QList<bool> m_newButtonStates; 254 QList<bool> m_prevButtonStates; 255 }; 256 257 } 258 #endif 259 260 /* kate: replace-tabs on; indent-width 4; */ 261