Warning, file /office/calligra/libs/text/KoInlineObject.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 KOINLINEOBJECTBASE_H
0020 #define KOINLINEOBJECTBASE_H
0021 
0022 #include "kotext_export.h"
0023 #include <KoXmlReaderForward.h>
0024 
0025 #include <QObject>
0026 #include <QTextInlineObject>
0027 
0028 class QVariant;
0029 class QTextDocument;
0030 class QTextCharFormat;
0031 class QPaintDevice;
0032 class QPainter;
0033 class QRectF;
0034 
0035 class KoInlineTextObjectManager;
0036 class KoInlineObjectPrivate;
0037 class KoShapeSavingContext;
0038 class KoTextInlineRdf;
0039 class KoShapeLoadingContext;
0040 
0041 /**
0042  * Base class for all inline-text-objects.
0043  *
0044  * In a TextShape you can insert objects that move with the text.
0045  * They are essentially anchored to a specific position in the text, as
0046  * one character.
0047  *
0048  * @see KoInlineTextObjectManager
0049  */
0050 class KOTEXT_EXPORT KoInlineObject : public QObject
0051 {
0052     Q_OBJECT
0053 public:
0054     enum Property {
0055         DocumentURL,
0056         PageCount,
0057         AuthorName,
0058         SenderEmail,
0059         SenderCompany,
0060         SenderPhoneWork,
0061         SenderPhonePrivate,
0062         SenderFax,
0063         SenderCountry,
0064         Title,
0065         Keywords,
0066         Subject,
0067         Description,
0068         Comments,
0069         SenderPostalCode,
0070         SenderCity,
0071         SenderStreet,
0072         SenderTitle,
0073         SenderFirstname,
0074         SenderLastname,
0075         SenderPosition,
0076         AuthorInitials,
0077         Chapter, ///< Chapter (number, name, number and name, plain number, plain number and name) variables.
0078 
0079         KarbonStart = 1000,      ///< Base number for Karbon specific values.
0080         KexiStart = 2000,        ///< Base number for Kexi specific values.
0081         FlowStart = 3000,        ///< Base number for Flow specific values.
0082         PlanStart = 4000,        ///< Base number for Plan specific values.
0083         StageStart = 5000,       ///< Base number for Stage specific values.
0084         WordsStart = 6000,       ///< Base number for Words specific values.
0085         VariableManagerStart = 7000, ///< Start of numbers reserved for the KoVariableManager
0086         UserGet = 12000,         ///< User defined variable user-field-get
0087         UserInput = 12001        ///< User defined variable user-field-input
0088     };
0089 
0090     /**
0091      * constructor
0092      * @param propertyChangeListener if set to true this instance will be notified of changes of properties.
0093      * @see KoInlineTextObjectManager::setProperty()
0094      * @see propertyChangeListener()
0095      */
0096     explicit KoInlineObject(bool propertyChangeListener = false);
0097     ~KoInlineObject() override;
0098 
0099     /**
0100      * Will be called by the manager when this variable is added.
0101      * Remember that inheriting classes should not use the manager() in the constructor, since it will be 0
0102      * @param manager the object manager for this object.
0103      */
0104     void setManager(KoInlineTextObjectManager *manager);
0105 
0106     /**
0107      * Return the object manager set on this inline object.
0108      */
0109     KoInlineTextObjectManager *manager() const;
0110 
0111     /**
0112      * Just prior to the first time this object will be shown this method will be called.
0113      * The object plugin should reimplement this to initialize the object after the manager
0114      * has been set, but before the text has been layouted.
0115      * The default implementation does nothing.
0116      */
0117     virtual void setup() {}
0118 
0119     /**
0120      * Save this inlineObject as ODF
0121      * @param context the context for saving.
0122      */
0123     virtual void saveOdf(KoShapeSavingContext &context) = 0;
0124 
0125     /**
0126      * Update position of the inline object.
0127      * This is called each time the paragraph this inline object is in is re-layouted giving you the opportunity
0128      * to reposition your object based on the new information.
0129      * @param document the text document this inline object is operating on.
0130      * @param posInDocument the character position in the document (param document) this inline object is at.
0131      * @param format the character format for the inline object.
0132      */
0133     virtual void updatePosition(const QTextDocument *document, int posInDocument, const QTextCharFormat &format) = 0;
0134 
0135     /**
0136      * Update the size of the inline object.
0137      * Each time the text is painted, as well as when the paragraph this variable is in, this method
0138      * is called. You should alter the size of the object if the content has changed.
0139      * Altering the size is done by altering the 'object' parameter using QTextInlineObject::setWidth(),
0140      * QTextInlineObject::setAscent() and QTextInlineObject::setDescent() methods.
0141      * Note that this method is called while painting; and thus is time sensitive; avoid doing anything time
0142      * consuming.
0143      * Note make sure that the width is 0 when there is nothing to be shown for the object.
0144      * @param document the text document this inline object is operating on.
0145      * @param object the inline object properties
0146      * @param posInDocument the character position in the document (param document) this inline object is at.
0147      * @param format the character format for the inline object.
0148      * @param pd the postscript-paintdevice that all text is rendered on. Use this for QFont and related
0149      *  classes so the inline object can be reused on any paintdevice.
0150      */
0151     virtual void resize(const QTextDocument *document, QTextInlineObject &object,
0152                         int posInDocument, const QTextCharFormat &format, QPaintDevice *pd) = 0;
0153 
0154     /**
0155      * Paint the inline-object-base using the provided painter within the rectangle specified by rect.
0156      * @param document the text document this inline object is operating on.
0157      * @param object the inline object properties
0158      * @param posInDocument the character position in the document (param document) this inline object is at.
0159      * @param format the character format for the inline object.
0160      * @param pd the postscript-paintdevice that all text is rendered on. Use this for QFont and related
0161      *  classes so the inline object can be reused on any paintdevice.
0162      * @param painter the painting object to paint on.  Note that unline many places in calligra painting
0163      *    should happen at the position indicated by the rect, not at top-left.
0164      * @param rect the rectangle inside which the variable can paint itself.  Painting outside the rect
0165      *    will give various problems with regards to repainting issues.
0166      */
0167     virtual void paint(QPainter &painter, QPaintDevice *pd, const QTextDocument *document,
0168                        const QRectF &rect, const QTextInlineObject &object, int posInDocument, const QTextCharFormat &format) = 0;
0169 
0170     /**
0171      * Overwrite this if you are interested in propertychanges.
0172      * @param property the property id that has been changed, one from the Property enum.
0173      *    You should ignore all properties you don't use as new properties can be added at any time.
0174      * @param value the new value of the property wrapped in a QVariant.  Properties can be a lot of
0175      *     different class types. Ints, bools, QStrings etc.
0176      * example:
0177      * @code
0178      *  void KoDateVariable::propertyChanged(Property key, const QVariant &value) {
0179      *      if(key == KoInlineObject::PageCount)
0180      *          setValue(QString::number(value.toInt()));
0181      *  }
0182      * @endcode
0183      * @see propertyChangeListener()
0184      */
0185     virtual void propertyChanged(Property property, const QVariant &value);
0186 
0187     /// return the inline-object Id that is assigned for this object.
0188     int id() const;
0189 
0190     /// Set the inline-object Id that is assigned for this object by the KoInlineTextObjectManager.
0191     void setId(int id);
0192 
0193     /**
0194      * When true, notify this object of property changes.
0195      * Each inlineObject can use properties like the PageCount or the document name.
0196      * Only objects that actually have a need for such information be a listener to avoid unneeded
0197      * overhead.
0198      * When this returns true, the propertyChanged() method will be called.
0199      * @see KoInlineTextObjectManager::setProperty()
0200      */
0201     bool propertyChangeListener() const;
0202 
0203     /**
0204      * An inline object might have some Rdf metadata associated with it
0205      * in content.xml
0206      * Ownership of the rdf object is taken by this object, you should not
0207      * delete it.
0208      */
0209     void setInlineRdf(KoTextInlineRdf *rdf);
0210     /**
0211      * Get any Rdf which was stored in content.xml for this inline object
0212      * This object continues to own the object, do not delete it.
0213      */
0214     KoTextInlineRdf *inlineRdf() const;
0215 
0216     /**
0217      * Load a variable from odf.
0218      *
0219      * @param element element which represents the shape in odf
0220      * @param context the KoShapeLoadingContext used for loading
0221      *
0222      * @return false if loading failed
0223      */
0224     virtual bool loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context) =  0;
0225 
0226 protected:
0227     explicit KoInlineObject(KoInlineObjectPrivate &, bool propertyChangeListener = false);
0228 
0229     KoInlineObjectPrivate *d_ptr;
0230 
0231 private:
0232     Q_DECLARE_PRIVATE(KoInlineObject)
0233     friend KOTEXT_EXPORT QDebug operator<<(QDebug, const KoInlineObject *);
0234 };
0235 
0236 KOTEXT_EXPORT QDebug operator<<(QDebug dbg, const KoInlineObject *o);
0237 
0238 #endif