1 /* This file is part of the KDE project 2 * Copyright (C) 2008 Girish Ramakrishnan <girish@forwardbias.in> 3 * Copyright (C) 2009 Thomas Zander <zander@kde.org> 4 * Copyright (C) 2008 Pierre Stirnweiss <pierre.stirnweiss_calligra@gadz.org> 5 * Copyright (C) 2014-2015 Denis Kuplyakov <dener.kup@gmail.com> 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Library General Public 9 * License as published by the Free Software Foundation; either 10 * version 2 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Library General Public License for more details. 16 * 17 * You should have received a copy of the GNU Library General Public License 18 * along with this library; see the file COPYING.LIB. If not, write to 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * Boston, MA 02110-1301, USA. 21 */ 22 23 #ifndef KOTEXTDOCUMENT_H 24 #define KOTEXTDOCUMENT_H 25 26 #include <QTextDocument> 27 #include <QWeakPointer> 28 #include <QAbstractTextDocumentLayout> 29 #include <QUrl> 30 31 #include <styles/KoListStyle.h> 32 33 class KoList; 34 class KoStyleManager; 35 class KoInlineTextObjectManager; 36 class KoTextRangeManager; 37 class KUndo2Stack; 38 class KoTextEditor; 39 class KoOdfLineNumberingConfiguration; 40 class KoChangeTracker; 41 class KoShapeController; 42 class KoSectionModel; 43 44 class QTextCharFormat; 45 46 /** 47 * KoTextDocument provides an easy mechanism to set and access the 48 * editing members of a QTextDocument. The meta data are stored as resources 49 * in the QTextDocument using QTextDocument::addResource() and fetched 50 * using QTextDocument::resource(). 51 * 52 */ 53 class KRITATEXT_EXPORT KoTextDocument 54 { 55 public: 56 /// Constructor 57 KoTextDocument(QTextDocument *document); // krazy:exclude=explicit 58 /// Constructor 59 KoTextDocument(const QTextDocument *document); // krazy:exclude=explicit 60 /// Constructor 61 KoTextDocument(QWeakPointer<QTextDocument> document); // krazy:exclude=explicit 62 63 /// Destructor 64 ~KoTextDocument(); 65 66 /// Returns the document that was passed in the constructor 67 QTextDocument *document() const; 68 69 ///Returns the text editor for that document 70 KoTextEditor *textEditor() const; 71 72 ///Sets the text editor for the document 73 void setTextEditor(KoTextEditor *textEditor); 74 75 /// Sets the style manager that defines the named styles in the document 76 void setStyleManager(KoStyleManager *styleManager); 77 78 /// Returns the style manager 79 KoStyleManager *styleManager() const; 80 81 /// Sets the change tracker of the document 82 void setChangeTracker(KoChangeTracker *changeTracker); 83 84 ///Returns the change tracker of the document 85 KoChangeTracker *changeTracker() const; 86 87 void setLineNumberingConfiguration(KoOdfLineNumberingConfiguration *lineNumberingConfiguration); 88 89 /// @return the notes configuration 90 KoOdfLineNumberingConfiguration *lineNumberingConfiguration() const; 91 92 ///Sets the global undo stack 93 void setUndoStack(KUndo2Stack *undoStack); 94 95 ///Returns the global undo stack 96 KUndo2Stack *undoStack() const; 97 98 ///Sets the global heading list 99 void setHeadingList(KoList *list); 100 101 ///Returns the global heading list 102 KoList *headingList() const; 103 104 /// Sets the lists of the document 105 void setLists(const QList<KoList *> &lists); 106 107 /// Returns the lists in the document 108 QList<KoList *> lists() const; 109 110 /// Adds a list to the document 111 void addList(KoList *list); 112 113 /// Removes a list from the document 114 void removeList(KoList *list); 115 116 /// Returns the KoList that holds \a block; 0 if block is not part of any list 117 KoList *list(const QTextBlock &block) const; 118 119 /// Returns the KoList that holds \a list 120 KoList *list(QTextList *textList) const; 121 122 /// Return the KoList that holds \a listId 123 KoList *list(KoListStyle::ListIdType listId) const; 124 125 /// Return the selections used during painting. 126 QVector<QAbstractTextDocumentLayout::Selection> selections() const; 127 128 /** 129 * Set the selections to use for painting. 130 * 131 * The selections are used to apply temporary styling to 132 * parts of a document. 133 * 134 * \param selections The new selections to use. 135 */ 136 void setSelections(const QVector<QAbstractTextDocumentLayout::Selection> &selections); 137 138 /// Returns the KoInlineTextObjectManager 139 KoInlineTextObjectManager *inlineTextObjectManager() const; 140 141 /// Set the KoInlineTextObjectManager 142 void setInlineTextObjectManager(KoInlineTextObjectManager *manager); 143 144 /// @return section model for the document 145 KoSectionModel *sectionModel(); 146 147 /// Sets the section model for the document 148 void setSectionModel(KoSectionModel *model); 149 150 /// Returns the KoTextRangeManager 151 KoTextRangeManager *textRangeManager() const; 152 153 /// Set the KoTextRangeManager 154 void setTextRangeManager(KoTextRangeManager *manager); 155 156 /// Set the KoDocument's shapeController. This controller exists as long as KoDocument exists. It should only be used for deleting shapes. 157 void setShapeController(KoShapeController *controller); 158 159 /// Returns the shapeController 160 KoShapeController *shapeController() const; 161 162 QTextFrame* auxillaryFrame(); 163 164 /** 165 * Specifies if tabs are relative to paragraph indent. 166 * 167 * By default it's false. 168 */ 169 void setRelativeTabs(bool relative); 170 171 /** 172 * Returns if tabs are placed relative to paragraph indent. 173 * 174 * By default, this is false. 175 * 176 * @see setRelativeTabs 177 */ 178 bool relativeTabs() const; 179 180 void setParaTableSpacingAtStart(bool spacingAtStart); 181 bool paraTableSpacingAtStart() const; 182 183 /** 184 * Returns the character format for the frame of this document. 185 * 186 * @return the character format for the frame of this document. 187 * @see setFrameCharFormat 188 */ 189 QTextCharFormat frameCharFormat() const; 190 191 /** 192 * Sets the character format for the frame of this document. 193 * 194 * @param format the character format for the frame of this document. 195 * @see frameCharFormat 196 */ 197 void setFrameCharFormat(const QTextCharFormat &format); 198 199 /** 200 * Returns the block format for the frame of this document. 201 * 202 * @return the block format for the frame of this document. 203 * @see setFrameBlockFormat 204 */ 205 QTextBlockFormat frameBlockFormat() const; 206 207 /** 208 * Sets the block format for the frame of this document. 209 * 210 * @param format the block format for the frame of this document. 211 * @see frameBlockFormat 212 */ 213 void setFrameBlockFormat(const QTextBlockFormat &format); 214 215 /** 216 * Clears the text in the document. Unlike QTextDocument::clear(), this 217 * function does not clear the resources of the QTextDocument. 218 */ 219 void clearText(); 220 221 /// Enum (type) used to add resources using QTextDocument::addResource() 222 enum ResourceType { 223 StyleManager = QTextDocument::UserResource, 224 Lists, 225 TextRangeManager, 226 InlineTextManager, 227 ChangeTrackerResource, 228 UndoStack, 229 TextEditor, 230 LineNumberingConfiguration, 231 RelativeTabs, 232 HeadingList, 233 Selections, 234 LayoutTextPage, /// this is used for setting the correct page variable on the first resize and should not be used for other purposes 235 ParaTableSpacingAtStart, /// this is used during layouting to specify if at the first paragraph margin-top should be applied. 236 IndexGeneratorManager, 237 FrameCharFormat, 238 FrameBlockFormat, 239 ShapeController, 240 SectionModel 241 }; 242 243 static const QUrl StyleManagerURL; 244 static const QUrl ListsURL; 245 static const QUrl TextRangeManagerURL; 246 static const QUrl InlineObjectTextManagerURL; 247 static const QUrl ChangeTrackerURL; 248 static const QUrl UndoStackURL; 249 static const QUrl TextEditorURL; 250 static const QUrl LineNumberingConfigurationURL; 251 static const QUrl BibliographyConfigurationURL; 252 static const QUrl RelativeTabsURL; 253 static const QUrl HeadingListURL; 254 static const QUrl SelectionsURL; 255 static const QUrl LayoutTextPageUrl; 256 static const QUrl ParaTableSpacingAtStartUrl; 257 static const QUrl IndexGeneratorManagerUrl; 258 static const QUrl FrameCharFormatUrl; 259 static const QUrl FrameBlockFormatUrl; 260 static const QUrl ShapeControllerUrl; 261 static const QUrl SectionModelUrl; 262 263 private: 264 QTextDocument *m_document; 265 }; 266 267 #endif // KOTEXTDOCUMENT_H 268