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

0001 /* This file is part of the KDE project
0002    Copyright (C) 2006 Martin Pfeiffer <hubipete@gmx.net> 
0003                  2009 Jeremias Epperlein <jeeree@web.de>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009   
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018    Boston, MA 02110-1301, USA.
0019  */
0020 
0021 #ifndef KOFORMULATOOL_H
0022 #define KOFORMULATOOL_H
0023 
0024 #include <KoToolBase.h>
0025 
0026 class KoFormulaShape;
0027 class FormulaEditor;
0028 class FormulaCommand;
0029 
0030 struct TemplateAction {
0031     QAction *action;
0032     QString data;
0033 };
0034 
0035 /**
0036  * @short The flake tool for a formula
0037  * @author Martin Pfeiffer <hubipete@gmx.net>
0038  */
0039 class KoFormulaTool : public KoToolBase {
0040     Q_OBJECT
0041 public:
0042     /// The standard constructor
0043     explicit KoFormulaTool( KoCanvasBase *canvas );
0044 
0045     /// The standard destructor
0046     ~KoFormulaTool() override;
0047 
0048     /// reimplemented
0049     void paint( QPainter &painter, const KoViewConverter &converter ) override;
0050 
0051     /// reimplemented
0052     void mousePressEvent( KoPointerEvent *event ) override ;
0053 
0054     /// reimplemented
0055     void mouseDoubleClickEvent( KoPointerEvent *event ) override;
0056 
0057     /// reimplemented
0058     void mouseMoveEvent( KoPointerEvent *event ) override;
0059 
0060     /// reimplemented
0061     void mouseReleaseEvent( KoPointerEvent *event ) override;
0062 
0063     void keyPressEvent( QKeyEvent *event ) override;
0064 
0065     void keyReleaseEvent( QKeyEvent *event ) override;
0066 
0067     void remove( bool backSpace );
0068 
0069     /// @return The currently manipulated KoFormulaShape
0070     KoFormulaShape* shape();
0071 
0072     /// @return The currently active cursor
0073     FormulaEditor* formulaEditor();
0074 
0075     /// Reset the cursor
0076     void resetFormulaEditor();
0077 
0078 public Q_SLOTS:
0079     /// Called when this tool instance is activated and fills m_formulaShape
0080     void activate(ToolActivation toolActivation, const QSet<KoShape*> &shapes) override;
0081 
0082     /// Called when this tool instance is deactivated
0083     void deactivate() override;
0084 
0085     /// Insert the element tied to the given @p action
0086     void insert( const QString& action );
0087 
0088     void changeTable( QAction* action);
0089     
0090     void insertSymbol( const QString& symbol);
0091 
0092     /// Reposition the cursor according to the data change
0093     void updateCursor(FormulaCommand* command, bool undo);
0094 
0095     void saveFormula();
0096 
0097     void loadFormula();
0098 
0099     
0100 protected:
0101     /// Create default option widget
0102     QWidget* createOptionWidget() override;
0103 
0104     void copy() const override;
0105 
0106     void deleteSelection() override;
0107 
0108     bool paste() override;
0109 
0110     QStringList supportedPasteMimeTypes() const override;
0111     
0112 private:
0113     /// Repaint the cursor and selection
0114     void repaintCursor();
0115 
0116     /// Creates all the actions provided by the tool
0117     void setupActions();
0118 
0119     void addTemplateAction(const QString &caption, const QString &name, const QString &data, const char *iconName);
0120 
0121     /// The FormulaShape the tool is manipulating
0122     KoFormulaShape* m_formulaShape;
0123 
0124     /// The FormulaEditor the tool uses to move around in the formula
0125     FormulaEditor* m_formulaEditor;
0126 
0127     QList<FormulaEditor*> m_cursorList;
0128 
0129     std::vector<TemplateAction> m_templateActions;
0130 };
0131 
0132 #endif