File indexing completed on 2024-04-28 04:32:42
0001 /* 0002 SPDX-FileCopyrightText: 2013 Jon Mease <jon.mease@gmail.com> 0003 0004 Work sponsored by the LiMux project of the city of Munich: 0005 SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB a KDAB Group company <info@kdab.com> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #ifndef _OKULAR_DOCUMENT_COMMANDS_P_H_ 0011 #define _OKULAR_DOCUMENT_COMMANDS_P_H_ 0012 0013 #include <QDomNode> 0014 #include <QUndoCommand> 0015 0016 #include "area.h" 0017 0018 namespace Okular 0019 { 0020 class Document; 0021 class Annotation; 0022 class DocumentPrivate; 0023 class FormFieldText; 0024 class FormFieldButton; 0025 class FormFieldChoice; 0026 class Page; 0027 0028 class OkularUndoCommand : public QUndoCommand 0029 { 0030 public: 0031 virtual bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) = 0; 0032 }; 0033 0034 class AddAnnotationCommand : public OkularUndoCommand 0035 { 0036 public: 0037 AddAnnotationCommand(Okular::DocumentPrivate *docPriv, Okular::Annotation *annotation, int pageNumber); 0038 0039 ~AddAnnotationCommand() override; 0040 0041 void undo() override; 0042 0043 void redo() override; 0044 0045 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 0046 0047 private: 0048 Okular::DocumentPrivate *m_docPriv; 0049 Okular::Annotation *m_annotation; 0050 int m_pageNumber; 0051 bool m_done; 0052 }; 0053 0054 class RemoveAnnotationCommand : public OkularUndoCommand 0055 { 0056 public: 0057 RemoveAnnotationCommand(Okular::DocumentPrivate *doc, Okular::Annotation *annotation, int pageNumber); 0058 ~RemoveAnnotationCommand() override; 0059 void undo() override; 0060 void redo() override; 0061 0062 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 0063 0064 private: 0065 Okular::DocumentPrivate *m_docPriv; 0066 Okular::Annotation *m_annotation; 0067 int m_pageNumber; 0068 bool m_done; 0069 }; 0070 0071 class ModifyAnnotationPropertiesCommand : public OkularUndoCommand 0072 { 0073 public: 0074 ModifyAnnotationPropertiesCommand(Okular::DocumentPrivate *docPriv, Okular::Annotation *annotation, int pageNumber, const QDomNode &oldProperties, const QDomNode &newProperties); 0075 0076 void undo() override; 0077 void redo() override; 0078 0079 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 0080 0081 private: 0082 Okular::DocumentPrivate *m_docPriv; 0083 Okular::Annotation *m_annotation; 0084 int m_pageNumber; 0085 QDomNode m_prevProperties; 0086 QDomNode m_newProperties; 0087 }; 0088 0089 class TranslateAnnotationCommand : public OkularUndoCommand 0090 { 0091 public: 0092 TranslateAnnotationCommand(Okular::DocumentPrivate *docPriv, Okular::Annotation *annotation, int pageNumber, const Okular::NormalizedPoint &delta, bool completeDrag); 0093 void undo() override; 0094 void redo() override; 0095 int id() const override; 0096 bool mergeWith(const QUndoCommand *uc) override; 0097 Okular::NormalizedPoint minusDelta(); 0098 Okular::NormalizedRect translateBoundingRectangle(const Okular::NormalizedPoint &delta); 0099 0100 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 0101 0102 private: 0103 Okular::DocumentPrivate *m_docPriv; 0104 Okular::Annotation *m_annotation; 0105 int m_pageNumber; 0106 Okular::NormalizedPoint m_delta; 0107 bool m_completeDrag; 0108 }; 0109 0110 class AdjustAnnotationCommand : public OkularUndoCommand 0111 { 0112 public: 0113 AdjustAnnotationCommand(Okular::DocumentPrivate *docPriv, Okular::Annotation *annotation, int pageNumber, const Okular::NormalizedPoint &delta1, const Okular::NormalizedPoint &delta2, bool completeDrag); 0114 void undo() override; 0115 void redo() override; 0116 int id() const override; 0117 bool mergeWith(const QUndoCommand *uc) override; 0118 Okular::NormalizedRect adjustBoundingRectangle(const Okular::NormalizedPoint &delta1, const Okular::NormalizedPoint &delta2); 0119 0120 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 0121 0122 private: 0123 Okular::DocumentPrivate *m_docPriv; 0124 Okular::Annotation *m_annotation; 0125 int m_pageNumber; 0126 Okular::NormalizedPoint m_delta1; 0127 Okular::NormalizedPoint m_delta2; 0128 bool m_completeDrag; 0129 }; 0130 0131 class EditTextCommand : public OkularUndoCommand 0132 { 0133 public: 0134 EditTextCommand(const QString &newContents, int newCursorPos, const QString &prevContents, int prevCursorPos, int prevAnchorPos); 0135 0136 void undo() override = 0; 0137 void redo() override = 0; 0138 int id() const override = 0; 0139 bool mergeWith(const QUndoCommand *uc) override; 0140 0141 private: 0142 enum EditType { 0143 CharBackspace, ///< Edit made up of one or more single character backspace operations 0144 CharDelete, ///< Edit made up of one or more single character delete operations 0145 CharInsert, ///< Edit made up of one or more single character insertion operations 0146 OtherEdit ///< All other edit operations (these will not be merged together) 0147 }; 0148 0149 QString oldContentsLeftOfCursor(); 0150 QString newContentsLeftOfCursor(); 0151 QString oldContentsRightOfCursor(); 0152 QString newContentsRightOfCursor(); 0153 0154 protected: 0155 QString m_newContents; 0156 int m_newCursorPos; 0157 QString m_prevContents; 0158 int m_prevCursorPos; 0159 int m_prevAnchorPos; 0160 EditType m_editType; 0161 }; 0162 0163 class EditAnnotationContentsCommand : public EditTextCommand 0164 { 0165 public: 0166 EditAnnotationContentsCommand(Okular::DocumentPrivate *docPriv, Okular::Annotation *annotation, int pageNumber, const QString &newContents, int newCursorPos, const QString &prevContents, int prevCursorPos, int prevAnchorPos); 0167 0168 void undo() override; 0169 void redo() override; 0170 int id() const override; 0171 bool mergeWith(const QUndoCommand *uc) override; 0172 0173 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 0174 0175 private: 0176 Okular::DocumentPrivate *m_docPriv; 0177 Okular::Annotation *m_annotation; 0178 int m_pageNumber; 0179 }; 0180 0181 class EditFormTextCommand : public EditTextCommand 0182 { 0183 public: 0184 EditFormTextCommand(Okular::DocumentPrivate *docPriv, Okular::FormFieldText *form, int pageNumber, const QString &newContents, int newCursorPos, const QString &prevContents, int prevCursorPos, int prevAnchorPos); 0185 void undo() override; 0186 void redo() override; 0187 int id() const override; 0188 bool mergeWith(const QUndoCommand *uc) override; 0189 0190 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 0191 0192 private: 0193 Okular::DocumentPrivate *m_docPriv; 0194 Okular::FormFieldText *m_form; 0195 int m_pageNumber; 0196 }; 0197 0198 class EditFormListCommand : public OkularUndoCommand 0199 { 0200 public: 0201 EditFormListCommand(Okular::DocumentPrivate *docPriv, FormFieldChoice *form, int pageNumber, const QList<int> &newChoices, const QList<int> &prevChoices); 0202 0203 void undo() override; 0204 void redo() override; 0205 0206 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 0207 0208 private: 0209 Okular::DocumentPrivate *m_docPriv; 0210 FormFieldChoice *m_form; 0211 int m_pageNumber; 0212 QList<int> m_newChoices; 0213 QList<int> m_prevChoices; 0214 }; 0215 0216 class EditFormComboCommand : public EditTextCommand 0217 { 0218 public: 0219 EditFormComboCommand(Okular::DocumentPrivate *docPriv, FormFieldChoice *form, int pageNumber, const QString &newContents, int newCursorPos, const QString &prevContents, int prevCursorPos, int prevAnchorPos); 0220 0221 void undo() override; 0222 void redo() override; 0223 int id() const override; 0224 bool mergeWith(const QUndoCommand *uc) override; 0225 0226 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 0227 0228 private: 0229 Okular::DocumentPrivate *m_docPriv; 0230 FormFieldChoice *m_form; 0231 int m_pageNumber; 0232 int m_newIndex; 0233 int m_prevIndex; 0234 }; 0235 0236 class EditFormButtonsCommand : public OkularUndoCommand 0237 { 0238 public: 0239 EditFormButtonsCommand(Okular::DocumentPrivate *docPriv, int pageNumber, const QList<FormFieldButton *> &formButtons, const QList<bool> &newButtonStates); 0240 0241 void undo() override; 0242 void redo() override; 0243 0244 bool refreshInternalPageReferences(const QVector<Okular::Page *> &newPagesVector) override; 0245 0246 private: 0247 void clearFormButtonStates(); 0248 0249 private: 0250 Okular::DocumentPrivate *m_docPriv; 0251 int m_pageNumber; 0252 QList<FormFieldButton *> m_formButtons; 0253 QList<int> m_pageNumbers; 0254 QList<bool> m_newButtonStates; 0255 QList<bool> m_prevButtonStates; 0256 }; 0257 0258 } 0259 #endif 0260 0261 /* kate: replace-tabs on; indent-width 4; */