1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
/* This file is part of the KDE project
* Copyright (C) 2007, 2009 Thomas Zander <zander@kde.org>
* Copyright (C) 2011 Matus Hanzes <matus.hanzes@ixonos.com>
* Copyright (C) 2013 C. Boemann <cbo@boemann.dk>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KOANCHORINLINEOBJECT_H
#define KOANCHORINLINEOBJECT_H
#include "KoInlineObject.h"
#include "KoShapeAnchor.h"
#include "kotext_export.h"
class KoAnchorInlineObjectPrivate;
/**
* This class connects KoShapeAnchor to an inline character in the text document.
*
* This class is used when the shape anchor is of type: as-char
*
* It has to be registered to the inlineobjectmanager and thus forms the connection between the text
* and the KoShapeAnchor and by extension the so called 'anchored-shape' (any kind of shape)
*
* The KoAnchorInlineObject is placed as a character in text. As such it will move and be
* editable like any other character, including deletion.
*
* Since this is a real character it will be positioned by the textlayout engine and anything that
* will change the position of the text will thus also change the KoAnchorInlineObject character.
*
* The anchored-shape can be repositioned on the canvas if the text is relayouted (for example after
* editing the text. This is dependent on how the text layout is implemented.
*
* Steps to use a KoAnchorInlineObject are
* <ol>
* <li> Create KoShapeAnchor *anchor = new KoShapeAnchor(shape);
* <li> Use anchor->loadOdf() to load additional attributes like the "text:anchor-type"
* <li> if type is as-char create KoAnchorInlineObject *anchorObj = new KoAnchorInlineObject(anchor);
* </ol>
*/
class KOTEXT_EXPORT KoAnchorInlineObject : public KoInlineObject, public KoShapeAnchor::TextLocation
{
Q_OBJECT
public:
/**
* Constructor for an as-char anchor.
* @param parent the shapeanchor.
*/
explicit KoAnchorInlineObject(KoShapeAnchor *parent);
~KoAnchorInlineObject() override;
/// returns the parent anchor
KoShapeAnchor *anchor() const;
/// returns the cursor position in the document where this anchor is positioned.
int position() const override;
/// returns the document that this anchor is associated with.
const QTextDocument *document() const override;
/// reimplemented from KoInlineObject
void updatePosition(const QTextDocument *document,
int posInDocument, const QTextCharFormat &format) override;
/// reimplemented from KoInlineObject
void resize(const QTextDocument *document, QTextInlineObject &object,
int posInDocument, const QTextCharFormat &format, QPaintDevice *pd) override;
/// reimplemented from KoInlineObject
void paint(QPainter &painter, QPaintDevice *pd, const QTextDocument *document,
const QRectF &rect, const QTextInlineObject &object, int posInDocument, const QTextCharFormat &format) override;
qreal inlineObjectAscent() const;
qreal inlineObjectDescent() const;
/// reimplemented from KoInlineObject - should not do anything
bool loadOdf(const KoXmlElement &, KoShapeLoadingContext &) override;
/// reimplemented from KoInlineObject
void saveOdf(KoShapeSavingContext &context) override;
private:
Q_DECLARE_PRIVATE(KoAnchorInlineObject)
};
#endif
|