1 /* This file is part of the KDE project 2 * Copyright (C) 2007 Thomas Zander <zander@kde.org> 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 #ifndef KOINLINENOTE_H 20 #define KOINLINENOTE_H 21 22 #include "KoInlineObject.h" 23 #include "kritatext_export.h" 24 25 class QTextFrame; 26 27 /** 28 * This object is an inline object, which means it is anchored in the text-flow and it can hold note info. 29 * Typical notes that use this are Footnotes, Endnotes and Annotations (also known as comments). 30 */ 31 class KRITATEXT_EXPORT KoInlineNote : public KoInlineObject 32 { 33 Q_OBJECT 34 public: 35 /// The type of note specifies how the application will use the text from the note. 36 enum Type { 37 Footnote, ///< Notes of this type will have their text placed at the bottom of a shape. 38 Endnote, ///< Notes of this type are used as endnotes in applications that support it. 39 Annotation ///< Notes of this type will have their text placed in the document margin. 40 }; 41 42 /** 43 * Construct a new note to be inserted in the text using KoTextEditor::insertInlineObject() for example. 44 * @param type the type of note, which specifies how the application will use the text from the new note. 45 */ 46 explicit KoInlineNote(Type type); 47 // destructor 48 ~KoInlineNote() override; 49 50 /** 51 * Set the textframe where we will create our own textframe within 52 * Our textframe is the one containing the real note contents. 53 * @param text the new text 54 */ 55 void setMotherFrame(QTextFrame *text); 56 57 /** 58 * Set the label that is shown at the spot this inline note is inserted. 59 * @param text the new label 60 */ 61 void setLabel(const QString &text); 62 63 /** 64 * Indirectly set the label that is shown at the spot this inline note is inserted. 65 * @param autoNumber the number that the label will portray. 0 should be the first 66 */ 67 void setAutoNumber(int autoNumber); 68 69 /// return the current text 70 QTextFrame *textFrame() const; 71 72 /// return the current label 73 QString label() const; 74 75 /** 76 * @return whether the label should be automatically recreated or if the label is static. 77 */ 78 bool autoNumbering() const; 79 80 /** 81 * Set whether the label should be automatically recreated. 82 * @param on if true then changes in footnote-ordering will recalcualte the label. 83 */ 84 void setAutoNumbering(bool on); 85 86 /// return the type of note. 87 Type type() const; 88 89 bool loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context) override; 90 91 ///reimplemented 92 void saveOdf(KoShapeSavingContext &context) override; 93 94 int getPosInDocument() const; 95 96 protected: 97 /// reimplemented 98 void updatePosition(const QTextDocument *document, 99 int posInDocument, const QTextCharFormat &format) override; 100 /// reimplemented 101 void resize(const QTextDocument *document, QTextInlineObject &object, 102 int posInDocument, const QTextCharFormat &format, QPaintDevice *pd) override; 103 /// reimplemented 104 void paint(QPainter &painter, QPaintDevice *pd, const QTextDocument *document, 105 const QRectF &rect, const QTextInlineObject &object, int posInDocument, const QTextCharFormat &format) override; 106 107 private: 108 friend class InsertNoteCommand; 109 110 // only to be used on subsequent redo of insertion 111 void setTextFrame(QTextFrame *textFrame); 112 113 class Private; 114 Private * const d; 115 }; 116 117 #endif 118