Warning, file /office/calligra/libs/text/KoTextEditingPlugin.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2007 Thomas Zander <zander@kde.org> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 #ifndef KOTEXTEDITINGPLUGIN_H 0020 #define KOTEXTEDITINGPLUGIN_H 0021 0022 #include <QObject> 0023 #include <QHash> 0024 #include "kotext_export.h" 0025 0026 class QAction; 0027 class QTextDocument; 0028 class QTextCursor; 0029 class QString; 0030 0031 /** 0032 * This is a base class for a text editing plugin as used by the text tool. 0033 * When the user types text into the text shape text editing plugins will be notified of 0034 * changes in the text document. The plugin is meant to be for altering or checking text as the user 0035 * types it, 0036 * To ensure a good user experience this plugin will only be called when it makes sense from 0037 * a users perspective. 0038 * The finishedWord() method will be called when the user makes at least one change to 0039 * a word and then moves the cursor out of the word, a similar approach happens with the 0040 * finishedParagraph(), it will only be called after the cursor has been moved out of the paragraph. 0041 */ 0042 class KOTEXT_EXPORT KoTextEditingPlugin : public QObject 0043 { 0044 Q_OBJECT 0045 public: 0046 /// constructor 0047 KoTextEditingPlugin(); 0048 ~KoTextEditingPlugin() override; 0049 0050 /** 0051 * This method will be called when the user makes at least one change to 0052 * a word and then moves the cursor out of the word. 0053 * You are free to alter the word via the textDocument. Be aware that operations should be done 0054 * via a QTextCursor and should retain any formatting already present on the text. 0055 * @param document the text document that was altered. 0056 * @param cursorPosition the last altered position in the word. 0057 */ 0058 virtual void finishedWord(QTextDocument *document, int cursorPosition) = 0; 0059 0060 /** 0061 * This method will be called when the user makes at least one change to 0062 * a paragraph and then moves the cursor out of the paragraph. 0063 * You are free to alter the paragraph via the textDocument. Be aware that operations should be done 0064 * via a QTextCursor and should retain any formatting already present on the text. 0065 * Note that finishedWord() is always called just prior to the call to this method. 0066 * @param document the text document that was altered. 0067 * @param cursorPosition the last altered position in the paragraph. 0068 */ 0069 virtual void finishedParagraph(QTextDocument *document, int cursorPosition) = 0; 0070 0071 /** 0072 * This method will be called just before the user makes at simple manual change to 0073 * the text. Such as inserting a single character. 0074 * This is for information only. You should not make any corrections to the text at this point 0075 * @param document the text document that was altered. 0076 * @param cursorPosition the last altered position in the paragraph. 0077 */ 0078 virtual void startingSimpleEdit(QTextDocument *document, int cursorPosition) = 0; 0079 0080 /** 0081 * This method will be called when the user selects a portion of text and selects this plugin 0082 * to handle it. 0083 * You are free to alter the text via the textDocument. Be aware that operations should be done 0084 * via a QTextCursor and should retain any formatting already present on the text. 0085 * @param document the text document that was altered. 0086 * @param startPosition the position at the start of the selection 0087 * @param endPosition the position at the end of the selection 0088 */ 0089 virtual void checkSection(QTextDocument *document, int startPosition, int endPosition); 0090 0091 /// can be called when this plugin needs the current position of the textcursor 0092 virtual void setCurrentCursorPosition(QTextDocument *document, int cursorPosition); 0093 0094 /** 0095 * Retrieves the entire collection of actions for the plugin 0096 */ 0097 QHash<QString, QAction*> actions() const; 0098 0099 Q_SIGNALS: 0100 /// emitted when a series of commands is started that together need to become 1 undo action. 0101 void startMacro(const QString &name); 0102 /// emitted when a series of commands has ended that together should be 1 undo action. 0103 void stopMacro(); 0104 0105 protected: 0106 /** 0107 * Helper method that allows you to easily get the word out of the document. 0108 * This method will create a selection on the parameter cursor where the altered word 0109 * is selected. 0110 * Example usage: 0111 * @code 0112 QTextCursor cursor(document); 0113 selectWord(cursor, cursorPosition); 0114 QString word = cursor.selectedText(); 0115 * @endcode 0116 * @param cursor the cursor to alter. 0117 * @param cursorPosition the position of the cursor somewhere in the word. 0118 */ 0119 void selectWord(QTextCursor &cursor, int cursorPosition) const; 0120 /** 0121 * Helper method that allows you to easily get the text of the paragraph which 0122 * holds the cursor position. 0123 * Please realize that altering of the paragraph text should be done on a 0124 * QTextCursor and not by altering the returned string. Doing so would loose 0125 * all text formatting of the paragraph. 0126 * @param document the document. 0127 * @param cursorPosition the position of the cursor somewhere in the word. 0128 */ 0129 QString paragraph(QTextDocument *document, int cursorPosition) const; 0130 0131 /** 0132 * Add an action under the given name to the action collection. 0133 * 0134 * @param name The name by which the action be retrieved again from the collection. 0135 * @param action The action to add. 0136 */ 0137 void addAction(const QString &name, QAction *action); 0138 0139 private: 0140 class Private; 0141 Private * const d; 0142 }; 0143 0144 #endif