File indexing completed on 2024-05-12 16:34:02

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 FORMULAEDITOR_H
0024 #define FORMULAEDITOR_H
0025 
0026 #include "koformula_export.h"
0027 #include <QString>
0028 #include <QPair>
0029 #include "FormulaData.h"
0030 #include "FormulaCursor.h"
0031 
0032 class BasicElement;
0033 class QString;
0034 class QPainter;
0035 
0036 /**
0037  * @short The Class responsible for manipulating a formula
0038  *
0039  * Every manipulation of a formula is done by the tool through this class. It holds
0040  * the current selection and provides methods to change the content of the formula
0041  * according to this selection. The m_data is used to notify the shape and tool of
0042  * changes in the formula.
0043  *
0044  */
0045 
0046 class KOFORMULA_EXPORT FormulaEditor {
0047 public:
0048     /// The constructor - set the FormulaCursor at the position specified in @p cursor
0049     explicit FormulaEditor( FormulaCursor cursor, FormulaData* data );
0050 
0051     /// The constructor - set the FormulaCursor to the left of the main element of @p data
0052     explicit FormulaEditor( FormulaData* data );
0053 
0054     /**
0055      * Draw the cursor to the given QPainter
0056      * only for convenience
0057      * @param painter The QPainter the cursor draws itsself to
0058      */
0059     void paint( QPainter &painter ) const;
0060 
0061     /**
0062      * Insert text content at the current cursor position
0063      * @param text The text to insert
0064      */
0065     FormulaCommand* insertText( const QString& text );
0066 
0067     /**
0068      * Insert an element at the current cursor position
0069      * @param element The element to be inserted
0070      */
0071     FormulaCommand* insertElement( BasicElement* element );
0072 
0073     /// Insert the elements encoded in MathML in data
0074     FormulaCommand* insertMathML( const QString& data );
0075 
0076     /// Manipulate the rows/columns of a table
0077     FormulaCommand* changeTable(bool insert, bool rows);
0078     
0079     /**
0080      * Remove an element from the formula
0081      * @param elementBeforePosition Indicates removal of element before or after cursor
0082      */
0083     FormulaCommand* remove( bool elementBeforePosition );
0084     
0085     /// @return The FormulaData which is navigated by this cursor
0086     FormulaData* formulaData() const;
0087 
0088     /// set the FormulaData which is navigated by this cursor
0089     void setData(FormulaData* data);
0090 
0091     /// @return the buffer with the last user input
0092     QString inputBuffer() const;
0093 
0094     /// set the cursor that holds the current position and selection
0095     void setCursor(FormulaCursor& cursor);
0096 
0097     /// @return the cursor that contains the current selection and position 
0098     FormulaCursor& cursor();
0099 
0100 private:
0101     /// @return the mathml token element, that should be used for this character
0102     QString tokenType(const QChar& character) const;
0103 
0104 private:
0105     /// the cursor that contains the current selection and position 
0106     FormulaCursor m_cursor;
0107 
0108     /// The formulaData 
0109     FormulaData* m_data;
0110 
0111     /// Buffer for the user input
0112     QString m_inputBuffer;
0113 
0114 };
0115 
0116 #endif // FORMULAEDITOR_H