1 /* This file is part of the KDE project 2 Copyright (C) 2006 Martin Pfeiffer <hubipete@gmx.net> 3 2009 Jeremias Epperlein <jeeree@web.de> 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Library General Public 7 License as published by the Free Software Foundation; either 8 version 2 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Library General Public License for more details. 14 15 You should have received a copy of the GNU Library General Public License 16 along with this library; see the file COPYING.LIB. If not, write to 17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef KOFORMULATOOL_H 22 #define KOFORMULATOOL_H 23 24 #include <KoToolBase.h> 25 26 class KoFormulaShape; 27 class FormulaEditor; 28 class FormulaCommand; 29 30 struct TemplateAction { 31 QAction *action; 32 QString data; 33 }; 34 35 /** 36 * @short The flake tool for a formula 37 * @author Martin Pfeiffer <hubipete@gmx.net> 38 */ 39 class KoFormulaTool : public KoToolBase { 40 Q_OBJECT 41 public: 42 /// The standard constructor 43 explicit KoFormulaTool( KoCanvasBase *canvas ); 44 45 /// The standard destructor 46 ~KoFormulaTool() override; 47 48 /// reimplemented 49 void paint( QPainter &painter, const KoViewConverter &converter ) override; 50 51 /// reimplemented 52 void mousePressEvent( KoPointerEvent *event ) override ; 53 54 /// reimplemented 55 void mouseDoubleClickEvent( KoPointerEvent *event ) override; 56 57 /// reimplemented 58 void mouseMoveEvent( KoPointerEvent *event ) override; 59 60 /// reimplemented 61 void mouseReleaseEvent( KoPointerEvent *event ) override; 62 63 void keyPressEvent( QKeyEvent *event ) override; 64 65 void keyReleaseEvent( QKeyEvent *event ) override; 66 67 void remove( bool backSpace ); 68 69 /// @return The currently manipulated KoFormulaShape 70 KoFormulaShape* shape(); 71 72 /// @return The currently active cursor 73 FormulaEditor* formulaEditor(); 74 75 /// Reset the cursor 76 void resetFormulaEditor(); 77 78 public Q_SLOTS: 79 /// Called when this tool instance is activated and fills m_formulaShape 80 void activate(ToolActivation toolActivation, const QSet<KoShape*> &shapes) override; 81 82 /// Called when this tool instance is deactivated 83 void deactivate() override; 84 85 /// Insert the element tied to the given @p action 86 void insert( const QString& action ); 87 88 void changeTable( QAction* action); 89 90 void insertSymbol( const QString& symbol); 91 92 /// Reposition the cursor according to the data change 93 void updateCursor(FormulaCommand* command, bool undo); 94 95 void saveFormula(); 96 97 void loadFormula(); 98 99 100 protected: 101 /// Create default option widget 102 QWidget* createOptionWidget() override; 103 104 void copy() const override; 105 106 void deleteSelection() override; 107 108 bool paste() override; 109 110 QStringList supportedPasteMimeTypes() const override; 111 112 private: 113 /// Repaint the cursor and selection 114 void repaintCursor(); 115 116 /// Creates all the actions provided by the tool 117 void setupActions(); 118 119 void addTemplateAction(const QString &caption, const QString &name, const QString &data, const char *iconName); 120 121 /// The FormulaShape the tool is manipulating 122 KoFormulaShape* m_formulaShape; 123 124 /// The FormulaEditor the tool uses to move around in the formula 125 FormulaEditor* m_formulaEditor; 126 127 QList<FormulaEditor*> m_cursorList; 128 129 std::vector<TemplateAction> m_templateActions; 130 }; 131 132 #endif 133