Warning, file /office/calligra/libs/text/KoAnchorTextRange.cpp 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) 2007, 2009-2010 Thomas Zander <zander@kde.org>
0003  * Copyright (C) 2010 Ko Gmbh <cbo@kogmbh.com>
0004  * Copyright (C) 2011 Matus Hanzes <matus.hanzes@ixonos.com>
0005  * Copyright (C) 2013 C. Boemann <cbo@boemann.dk>
0006  *
0007  * This library is free software; you can redistribute it and/or
0008  * modify it under the terms of the GNU Library General Public
0009  * License as published by the Free Software Foundation; either
0010  * version 2 of the License, or (at your option) any later version.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Library General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Library General Public License
0018  * along with this library; see the file COPYING.LIB.  If not, write to
0019  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020  * Boston, MA 02110-1301, USA.
0021  */
0022 
0023 #include "KoAnchorTextRange.h"
0024 #include "KoShapeAnchor.h"
0025 
0026 #include <KoShapeSavingContext.h>
0027 #include <KoShape.h>
0028 
0029 #include "TextDebug.h"
0030 
0031 
0032 class KoAnchorTextRangePrivate
0033 {
0034 public:
0035     KoAnchorTextRangePrivate(KoShapeAnchor *p)
0036         : parent(p)
0037     {
0038     }
0039 
0040     KoShapeAnchor *parent;
0041 };
0042 
0043 KoAnchorTextRange::KoAnchorTextRange(KoShapeAnchor *parent, const QTextCursor &cursor)
0044     : KoTextRange(cursor)
0045     , d_ptr(new KoAnchorTextRangePrivate(parent))
0046 {
0047     Q_ASSERT(parent);
0048     parent->setTextLocation(this);
0049 }
0050 
0051 KoAnchorTextRange::~KoAnchorTextRange()
0052 {
0053 }
0054 
0055 KoShapeAnchor *KoAnchorTextRange::anchor() const
0056 {
0057     Q_D(const KoAnchorTextRange);
0058     return d->parent;
0059 }
0060 
0061 const QTextDocument *KoAnchorTextRange::document() const
0062 {
0063     return KoTextRange::document();
0064 }
0065 
0066 int KoAnchorTextRange::position() const
0067 {
0068     return rangeStart();
0069 }
0070 
0071 void KoAnchorTextRange::updateContainerModel()
0072 {
0073     Q_D(KoAnchorTextRange);
0074 
0075     if (!d->parent->shape()->isVisible()) {
0076         // Per default the shape this anchor presents is hidden and we only make it visible once an
0077         // explicit placement is made. This prevents shapes that are anchored at e.g. hidden
0078         // textboxes to not become visible.
0079         d->parent->shape()->setVisible(true);
0080     }
0081 
0082     if (d->parent->placementStrategy() != 0) {
0083         d->parent->placementStrategy()->updateContainerModel();
0084     }
0085 }
0086 
0087 bool KoAnchorTextRange::loadOdf(const KoXmlElement &, KoShapeLoadingContext &)
0088 {
0089     return true;
0090 }
0091 
0092 void KoAnchorTextRange::saveOdf(KoShapeSavingContext &context, int position, KoTextRange::TagType tagType) const
0093 {
0094     Q_UNUSED(position);
0095     Q_UNUSED(tagType);
0096 
0097     Q_D(const KoAnchorTextRange);
0098     if (tagType == KoTextRange::StartTag) {
0099         d->parent->saveOdf(context);
0100     }
0101 }