From 598f1ffacae8369d12ad427104db6a171dac145e Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Sat, 7 Apr 2007 17:45:36 +0000 Subject: [PATCH] Provide a roughly working feature for inline objects. Which is (flake) shapes that get their position defined by an anchor in the text; the character (anchor) moves, then so does the shape. This implementation aims to be a lot broader in scope than the one in KOffce1. We now have horizontal and vertical alignments. So a shape can always stay left or right of the paragraph the marker is in. Or always top or bottom of frame / paragraph / line. As well as a specified distance from the anchor-character. svn path=/trunk/koffice/; revision=651432 --- libs/kotext/KoInlineObject.h | 4 +++- libs/kotext/KoTextAnchor.cpp | 8 +++----- libs/kotext/KoTextDocumentLayout.h | 7 +++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/libs/kotext/KoInlineObject.h b/libs/kotext/KoInlineObject.h index 54f4f33bf9..171d194216 100644 --- a/libs/kotext/KoInlineObject.h +++ b/libs/kotext/KoInlineObject.h @@ -121,8 +121,10 @@ public: /** * Update the size of the inline object. * Each time the text is painted, as well as when the paragraph this variable is in, this method - * is called. You should alter the size of the variable if the content has changed. + * is called. You should alter the size of the object if the content has changed. * Altering the size is done by altering the 'object' parameter using QTextInlineObject::setWidth(), + * Note that this method is called while painting; and thus is time sensitive; avoid doing anything time + * consuming. * QTextInlineObject::setAscent() and QTextInlineObject::setDescent() methods. * @param document the text document this inline object is operating on. * @param object the inline object properties diff --git a/libs/kotext/KoTextAnchor.cpp b/libs/kotext/KoTextAnchor.cpp index b905fb09c4..5f1c21510d 100644 --- a/libs/kotext/KoTextAnchor.cpp +++ b/libs/kotext/KoTextAnchor.cpp @@ -57,6 +57,7 @@ kDebug() << "setContainer " << container << endl; bool first = model == 0; // first time model = dynamic_cast (container->model()); if(first) { +kDebug() << "**** setContainer first time\n"; distance = shape->position(); model->addAnchor(parent); } @@ -113,8 +114,8 @@ kDebug() << "KoTextAnchor::updatePosition " << posInDocument << endl; d->position = posInDocument; d->setContainer(dynamic_cast (shapeForPosition(document, posInDocument))); - if(d->model) - d->model->reposition(d->shape); +// if(d->model) +// d->model->reposition(d->shape); } void KoTextAnchor::resize(const QTextDocument *document, QTextInlineObject object, int posInDocument, const QTextCharFormat &format, QPaintDevice *pd) { @@ -123,9 +124,6 @@ void KoTextAnchor::resize(const QTextDocument *document, QTextInlineObject objec Q_UNUSED(posInDocument); Q_UNUSED(format); Q_UNUSED(pd); - - if(d->model) - d->model->reposition(d->shape); } void KoTextAnchor::paint (QPainter &painter, QPaintDevice *pd, const QTextDocument *document, const QRectF &rect, QTextInlineObject object, int posInDocument, const QTextCharFormat &format) { diff --git a/libs/kotext/KoTextDocumentLayout.h b/libs/kotext/KoTextDocumentLayout.h index 75398a4323..f8b73fc017 100644 --- a/libs/kotext/KoTextDocumentLayout.h +++ b/libs/kotext/KoTextDocumentLayout.h @@ -166,13 +166,12 @@ protected: /// make sure we start a layout run virtual void relayout(); -private: /// reimplemented - void drawInlineObject(QPainter *painter, const QRectF &rect, QTextInlineObject object, int position, const QTextFormat &format); + virtual void drawInlineObject(QPainter *painter, const QRectF &rect, QTextInlineObject object, int position, const QTextFormat &format); /// reimplemented - void positionInlineObject(QTextInlineObject item, int position, const QTextFormat &format); + virtual void positionInlineObject(QTextInlineObject item, int position, const QTextFormat &format); /// reimplemented - void resizeInlineObject(QTextInlineObject item, int position, const QTextFormat &format); + virtual void resizeInlineObject(QTextInlineObject item, int position, const QTextFormat &format); private: Q_PRIVATE_SLOT(d, void relayoutPrivate()) -- GitLab