Warning, file /office/calligra/libs/text/KoInlineTextObjectManager.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) 2006-2009 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 KOINLINETEXTOBJECTMANAGER_H 0020 #define KOINLINETEXTOBJECTMANAGER_H 0021 0022 #include "KoInlineObject.h" 0023 #include "KoVariableManager.h" 0024 #include "kotext_export.h" 0025 0026 // Qt 0027 #include <QHash> 0028 #include <QTextBlock> 0029 0030 class KoCanvasBase; 0031 class KoTextLocator; 0032 class KoInlineNote; 0033 class KoInlineCite; 0034 0035 class QTextCharFormat; 0036 class QAction; 0037 0038 /** 0039 * A container to register all the inlineTextObjects with. 0040 * Inserting an inline-object in a QTextDocument should be done via this manager which will 0041 * insert a placeholder in the text and you should add the KoInlineTextObjectManager to the 0042 * KoTextDocument. 0043 */ 0044 class KOTEXT_EXPORT KoInlineTextObjectManager : public QObject 0045 { 0046 Q_OBJECT 0047 public: 0048 enum Properties { 0049 InlineInstanceId = 577297549 // If you change this, don't forget to change KoCharacterStyle.h 0050 }; 0051 0052 /// Constructor 0053 explicit KoInlineTextObjectManager(QObject *parent = 0); 0054 ~KoInlineTextObjectManager() override; 0055 0056 /** 0057 * Retrieve a formerly added inline object based on the format. 0058 * @param format the textCharFormat 0059 */ 0060 KoInlineObject *inlineTextObject(const QTextCharFormat &format) const; 0061 0062 /** 0063 * Retrieve a formerly added inline object based on the cursor position. 0064 * @param cursor the cursor which position is used. The anchor is ignored. 0065 */ 0066 KoInlineObject *inlineTextObject(const QTextCursor &cursor) const; 0067 0068 /** 0069 * Retrieve a formerly added inline object based on the KoInlineObject::id() of the object. 0070 * @param id the id assigned to the inline text object when it was added. 0071 */ 0072 KoInlineObject *inlineTextObject(int id) const; 0073 0074 QList<KoInlineObject*> inlineTextObjects() const; 0075 0076 /** 0077 * Insert a new inline object into the manager as well as the document. 0078 * This method will cause a placeholder to be inserted into the text at cursor position, 0079 * possibly replacing a selection. The object will then be used as an inline 0080 * character and painted at the specified location in the text. 0081 * @param cursor the cursor which indicated the document and the position in that document 0082 * where the inline object will be inserted. 0083 * @param object the inline object to insert. 0084 */ 0085 void insertInlineObject(QTextCursor &cursor, KoInlineObject *object); 0086 0087 /** 0088 * Add inline object into the manager. 0089 * 0090 * This methods add the inline object into the manager. This is useful if you have a command 0091 * that removes and adds a inline object to the manager. If the object already was inserted before 0092 * (the object id is already set) it keeps the old id, otherwise a new id will be generated. 0093 * 0094 * @param object the inline object to insert. 0095 */ 0096 void addInlineObject(KoInlineObject* object); 0097 0098 /** 0099 * Remove an inline object from this manager. The object will also be removed from 0100 * the bookmarkmanager if it is a bookmark. This is not done smart: you might end up 0101 * with dangling start or end bookmarks. 0102 * Should really only be called by KoTextEditor's delete commands 0103 * @param object the object to be removed 0104 */ 0105 void removeInlineObject(KoInlineObject *object); 0106 0107 /** 0108 * Set a property that may have changed which will be forwarded to all registered textObjects. 0109 * If the key has changed then all registered InlineObject instances that have stated to want 0110 * updates will get called with the change. 0111 * The property will be stored to allow it to be retrieved via the intProperty() and friends. 0112 * @see KoInlineObject::propertyChangeListener() 0113 */ 0114 void setProperty(KoInlineObject::Property key, const QVariant &value); 0115 0116 /// retrieve a property 0117 QVariant property(KoInlineObject::Property key) const; 0118 0119 /// retrieve an int property 0120 int intProperty(KoInlineObject::Property key) const; 0121 0122 /// retrieve a bool property 0123 bool boolProperty(KoInlineObject::Property key) const; 0124 0125 /// retrieve a string property 0126 QString stringProperty(KoInlineObject::Property key) const; 0127 0128 /// remove a property from the store. 0129 void removeProperty(KoInlineObject::Property key); 0130 0131 /** 0132 * Return the variableManager. 0133 */ 0134 const KoVariableManager *variableManager() const; 0135 /** 0136 * Return the variableManager. 0137 */ 0138 KoVariableManager *variableManager(); 0139 0140 /** 0141 * Create a list of actions that can be used to plug into a menu, for example. 0142 * This method internally uses KoInlineObjectRegistry::createInsertVariableActions() but extends 0143 * the list with all registered variable-names. 0144 * Each of these actions, when executed, will insert the relevant variable in the current text-position. 0145 * The actions assume that the text tool is selected, if thats not the case then they will silently fail. 0146 * @param host the canvas for which these actions are created. Note that the actions will get these 0147 * actions as a parent (for memory management purposes) as well. 0148 * @see KoVariableManager 0149 */ 0150 QList<QAction*> createInsertVariableActions(KoCanvasBase *host) const; 0151 0152 QList<KoTextLocator*> textLocators() const; 0153 0154 /** 0155 * It returns a list of all end notes in the document 0156 */ 0157 QList<KoInlineNote*> endNotes() const; 0158 0159 QMap<QString, KoInlineCite*> citations(bool duplicatesEnabled = true) const; 0160 0161 QList<KoInlineCite*> citationsSortedByPosition(bool duplicatesEnabled = true, 0162 QTextBlock block = QTextBlock()) const; 0163 0164 public Q_SLOTS: 0165 void documentInformationUpdated(const QString &info, const QString &data); 0166 0167 Q_SIGNALS: 0168 /** 0169 * Emitted whenever a property is set and it turns out to be changed. 0170 */ 0171 void propertyChanged(int, const QVariant &variant); 0172 0173 private: 0174 void insertObject(KoInlineObject *object); 0175 0176 QHash<int, KoInlineObject*> m_objects; 0177 QHash<int, KoInlineObject*> m_deletedObjects; 0178 QList<KoInlineObject*> m_listeners; // holds objects also in m_objects, but which want propertyChanges 0179 int m_lastObjectId; 0180 QHash<int, QVariant> m_properties; 0181 0182 KoVariableManager m_variableManager; 0183 }; 0184 0185 Q_DECLARE_METATYPE(KoInlineTextObjectManager*) 0186 #endif