File indexing completed on 2024-05-12 16:34:01
0001 /* This file is part of the KDE project 0002 Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org> 0003 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de> 0004 2006 Martin Pfeiffer <hubipete@gmx.net> 0005 2009 Jeremias Epperlein <jeeree@web.de> 0006 0007 This library is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU Library General Public 0009 License as published by the Free Software Foundation; either 0010 version 2 of the License, or (at your option) any later version. 0011 0012 This library is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 Library General Public License for more details. 0016 0017 You should have received a copy of the GNU Library General Public License 0018 along with this library; see the file COPYING.LIB. If not, write to 0019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 Boston, MA 02110-1301, USA. 0021 */ 0022 0023 #ifndef FORMULACOMMAND_H 0024 #define FORMULACOMMAND_H 0025 0026 #include <kundo2command.h> 0027 #include <QList> 0028 #include <QHash> 0029 #include <QMetaType> 0030 #include "FormulaCursor.h" 0031 class BasicElement; 0032 class TokenElement; 0033 class FormulaData; 0034 class GlyphElement; 0035 class TableElement; 0036 class TableRowElement; 0037 0038 /** 0039 * 0040 * All FormulaCommands are used to manipulate the formula in various ways. 0041 * They all provide a redo and undo method as well as changeCursor method 0042 * which sets the cursor after the current action. A extra method for this is necessary, 0043 * as there might be no cursor when a undo/redo is done, because the tool was deactivated 0044 * 0045 **/ 0046 0047 class FormulaCommand : public KUndo2Command { 0048 public: 0049 explicit FormulaCommand(KUndo2Command *parent=0); 0050 0051 virtual void changeCursor(FormulaCursor& cursor, bool undo) const; 0052 0053 void setUndoCursorPosition(const FormulaCursor& position); 0054 void setRedoCursorPosition(const FormulaCursor& position); 0055 0056 protected: 0057 bool m_done; 0058 0059 private: 0060 FormulaCursor m_undoCursorPosition; 0061 FormulaCursor m_redoCursorPosition; 0062 }; 0063 0064 Q_DECLARE_METATYPE(FormulaCommand*) 0065 0066 0067 class FormulaCommandReplaceText : public FormulaCommand { 0068 public: 0069 FormulaCommandReplaceText( TokenElement* owner, int position,int length, const QString& added , KUndo2Command *parent=0); 0070 0071 ~FormulaCommandReplaceText() override; 0072 0073 /// Execute the command 0074 void redo() override; 0075 0076 /// Revert the actions done in redo() 0077 void undo() override; 0078 0079 private: 0080 /// The BasicElement that owns the newly added Text 0081 TokenElement* m_ownerElement; 0082 0083 /// The position inside m_ownerElement 0084 int m_position; 0085 0086 int m_length; 0087 0088 int m_glyphpos; 0089 0090 /// The list of added elements 0091 QString m_added; 0092 0093 QString m_removed; 0094 0095 QList<GlyphElement*> m_removedGlyphs; 0096 }; 0097 0098 class FormulaCommandReplaceElements : public FormulaCommand { 0099 public: 0100 FormulaCommandReplaceElements( RowElement* owner, int position, int length, QList<BasicElement*> elements , bool wrap=false, KUndo2Command *parent=0); 0101 0102 ~FormulaCommandReplaceElements() override; 0103 0104 /// Execute the command 0105 void redo() override; 0106 0107 /// Revert the actions done in redo() 0108 void undo() override; 0109 0110 private: 0111 /// The BasicElement that owns the newly added Text 0112 RowElement* m_ownerElement; 0113 0114 /// The position inside m_ownerElement 0115 int m_position; 0116 0117 int m_placeholderPosition; 0118 0119 int m_length; 0120 0121 bool m_wrap; 0122 0123 RowElement* m_placeholderParent; 0124 0125 // BasicElement* m_placeholder; 0126 0127 /// The list of added elements 0128 QList<BasicElement*> m_added; 0129 0130 /// The list of removed elements 0131 QList<BasicElement*> m_removed; 0132 }; 0133 0134 class FormulaCommandLoad : public FormulaCommand { 0135 public: 0136 FormulaCommandLoad( FormulaData* data, FormulaElement* newelement, KUndo2Command *parent=0); 0137 0138 ~FormulaCommandLoad () override; 0139 0140 /// Execute the command 0141 void redo() override; 0142 0143 /// Revert the actions done in redo() 0144 void undo() override; 0145 0146 private: 0147 FormulaData* m_data; 0148 FormulaElement* m_oldel; 0149 FormulaElement* m_newel; 0150 }; 0151 0152 class FormulaCommandReplaceRow : public FormulaCommand { 0153 public: 0154 FormulaCommandReplaceRow ( FormulaData* data, FormulaCursor oldPosition, TableElement* table, int number, int oldlength, int newlength ); 0155 0156 ~FormulaCommandReplaceRow () override; 0157 0158 /// Execute the command 0159 void redo() override; 0160 0161 /// Revert the actions done in redo() 0162 void undo() override; 0163 0164 private: 0165 FormulaData* m_data; 0166 TableElement* m_table; 0167 TableRowElement* m_empty; 0168 int m_number; 0169 QList<BasicElement*> m_newRows; 0170 QList<BasicElement*> m_oldRows; 0171 }; 0172 0173 class FormulaCommandReplaceColumn : public FormulaCommand { 0174 public: 0175 FormulaCommandReplaceColumn ( FormulaData* data, FormulaCursor oldPosition, TableElement* table, int number, int oldlength, int newlength ); 0176 0177 ~FormulaCommandReplaceColumn () override; 0178 0179 /// Execute the command 0180 void redo() override; 0181 0182 /// Revert the actions done in redo() 0183 void undo() override; 0184 0185 private: 0186 FormulaData* m_data; 0187 0188 ///the table we are manipulating 0189 TableElement* m_table; 0190 0191 ///used to hold the new empty row, if we remove the whole table 0192 TableRowElement* m_empty; 0193 0194 ///used to store the old rows, if we remove the whole table 0195 QList<BasicElement*> m_oldRows; 0196 0197 ///the position where we start to insert / remove rows 0198 int m_position; 0199 0200 ///used to store the old columns 0201 QList< QList<BasicElement*> > m_newColumns; 0202 0203 ///used to store the new columns 0204 QList< QList<BasicElement*> > m_oldColumns; 0205 }; 0206 0207 0208 0209 // /** 0210 // * @short The command for changes of an element's attributes 0211 // * 0212 // * Whenever the user changes the attributes assigned to an element an instance of this 0213 // * class is created to make it possible to revert the changes. The former attributes 0214 // * are stored in m_oldAttributes. 0215 // */ 0216 // class FormulaCommandAttribute : public KUndo2Command { 0217 // public: 0218 // /** 0219 // * The constructor 0220 // * @param cursor The FormulaCursor where the elements will be replaced 0221 // * @param attributes The list of the old attributes 0222 // */ 0223 // FormulaCommandAttribute( FormulaCursor* cursor, QHash<QString,QString> attributes ); 0224 // 0225 // /// Execute the command 0226 // void redo(); 0227 // 0228 // /// Revert the actions done in redo() 0229 // void undo(); 0230 // 0231 // private: 0232 // /// The BasicElement whose attributes have been changed 0233 // BasicElement* m_ownerElement; 0234 // 0235 // /// All attributes that are set newly 0236 // QHash<QString,QString> m_attributes; 0237 // 0238 // /// All attributes the element had before 0239 // QHash<QString,QString> m_oldAttributes; 0240 // }; 0241 0242 #endif // FORMULACOMMAND_H