kformula/flake

FormulaCommand.h

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
00003                       Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
00004                  2006 Martin Pfeiffer <hubipete@gmx.net>
00005                  2009 Jeremias Epperlein <jeeree@web.de>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #ifndef FORMULACOMMAND_H
00024 #define FORMULACOMMAND_H
00025 
00026 #include <QUndoCommand>
00027 #include <QList>
00028 #include <QHash>
00029 #include <QMetaType>
00030 #include "FormulaCursor.h"
00031 class BasicElement;
00032 class TokenElement;
00033 class FormulaData;
00034 class GlyphElement;
00035 class TableElement;
00036 class TableRowElement;
00037 
00047 class FormulaCommand :  public QUndoCommand {
00048 public:
00049     FormulaCommand(QUndoCommand* parent=0);
00050     
00051     virtual void changeCursor(FormulaCursor& cursor, bool undo) const;
00052 
00053     void setUndoCursorPosition(const FormulaCursor& position);
00054     void setRedoCursorPosition(const FormulaCursor& position);
00055 
00056 protected:
00057     bool m_done;
00058 
00059 private:
00060     FormulaCursor m_undoCursorPosition;
00061     FormulaCursor m_redoCursorPosition;
00062 };
00063 
00064 Q_DECLARE_METATYPE(FormulaCommand*)
00065 
00066 
00067 class FormulaCommandReplaceText : public FormulaCommand {
00068 public:
00069     FormulaCommandReplaceText( TokenElement* owner, int position,int length, const QString& added , QUndoCommand *parent=0);
00070 
00071     ~FormulaCommandReplaceText();
00072 
00074     void redo();
00075 
00077     void undo();
00078 
00079 private:
00081     TokenElement* m_ownerElement;
00082 
00084     int m_position;
00085 
00086     int m_length;
00087 
00088     int m_glyphpos;
00089     
00091     QString m_added;
00092 
00093     QString m_removed;
00094 
00095     QList<GlyphElement*> m_removedGlyphs;
00096 };
00097 
00098 class FormulaCommandReplaceElements : public FormulaCommand {
00099 public:
00100     FormulaCommandReplaceElements( RowElement* owner, int position, int length, QList<BasicElement*> elements , bool wrap=false, QUndoCommand *parent=0);
00101 
00102     ~FormulaCommandReplaceElements();
00103 
00105     void redo();
00106 
00108     void undo();
00109 
00110 private:
00112     RowElement* m_ownerElement;
00113 
00115     int m_position;
00116 
00117     int m_placeholderPosition;
00118     
00119     int m_length;
00120 
00121     bool m_wrap;
00122 
00123     RowElement* m_placeholderParent;
00124 
00125 //     BasicElement* m_placeholder;
00126 
00128     QList<BasicElement*> m_added;
00129 
00131     QList<BasicElement*> m_removed;
00132 };
00133 
00134 class FormulaCommandLoad : public FormulaCommand {
00135 public:
00136     FormulaCommandLoad( FormulaData* data, FormulaElement* newelement, QUndoCommand *parent=0);
00137 
00138     ~FormulaCommandLoad ();
00139     
00141     void redo();
00142 
00144     void undo();
00145 
00146 private:
00147     FormulaData* m_data;
00148     FormulaElement* m_oldel;
00149     FormulaElement* m_newel;
00150 };
00151 
00152 class FormulaCommandReplaceRow : public FormulaCommand {
00153 public:
00154     FormulaCommandReplaceRow ( FormulaData* data, FormulaCursor oldPosition, TableElement* table, int number, int oldlength, int newlength );
00155 
00156     ~FormulaCommandReplaceRow ();
00157 
00159     void redo();
00160 
00162     void undo();
00163 
00164 private:
00165     FormulaData* m_data;
00166     TableElement* m_table;
00167     TableRowElement* m_empty;
00168     int m_number;
00169     QList<BasicElement*> m_newRows;
00170     QList<BasicElement*> m_oldRows;
00171 };
00172 
00173 class FormulaCommandReplaceColumn : public FormulaCommand {
00174 public:
00175     FormulaCommandReplaceColumn ( FormulaData* data, FormulaCursor oldPosition, TableElement* table, int number, int oldlength, int newlength );
00176 
00177     ~FormulaCommandReplaceColumn ();
00178 
00180     void redo();
00181 
00183     void undo();
00184 
00185 private:
00186     FormulaData* m_data;
00187 
00189     TableElement* m_table;
00190 
00192     TableRowElement* m_empty;
00193 
00195     QList<BasicElement*> m_oldRows;
00196 
00198     int m_position;
00199 
00201     QList< QList<BasicElement*> > m_newColumns;
00202 
00204     QList< QList<BasicElement*> > m_oldColumns;
00205 };
00206 
00207 
00208 
00209 // /**
00210 //  * @short The command for changes of an element's attributes
00211 //  * 
00212 //  * Whenever the user changes the attributes assigned to an element an instance of this
00213 //  * class is created to make it possible to revert the changes. The former attributes
00214 //  * are stored in m_oldAttributes.
00215 //  */
00216 // class FormulaCommandAttribute : public QUndoCommand {
00217 // public:
00218 //     /**
00219 //      * The constructor
00220 //      * @param cursor The FormulaCursor where the elements will be replaced 
00221 //      * @param attributes The list of the old attributes
00222 //      */
00223 //     FormulaCommandAttribute( FormulaCursor* cursor, QHash<QString,QString> attributes );
00224 // 
00225 //     /// Execute the command
00226 //     void redo();
00227 // 
00228 //     /// Revert the actions done in redo()
00229 //     void undo();
00230 //     
00231 // private:
00232 //     /// The BasicElement whose attributes have been changed
00233 //     BasicElement* m_ownerElement;
00234 //     
00235 //     /// All attributes that are set newly
00236 //     QHash<QString,QString> m_attributes;
00237 //     
00238 //     /// All attributes the element had before
00239 //     QHash<QString,QString> m_oldAttributes;
00240 // };
00241 
00242 #endif // FORMULACOMMAND_H