1 /* This file is part of the KDE project
2 * Copyright (C) 2007, 2009-2010 Thomas Zander <zander@kde.org>
3 * Copyright (C) 2010 Ko Gmbh <cbo@kogmbh.com>
4 * Copyright (C) 2011 Matus Hanzes <matus.hanzes@ixonos.com>
5 * Copyright (C) 2013 C. Boemann <cbo@boemann.dk>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23 #include "KoAnchorTextRange.h"
24 #include "KoShapeAnchor.h"
25
26 #include <KoShapeSavingContext.h>
27 #include <KoShape.h>
28
29 #include "TextDebug.h"
30
31
32 class KoAnchorTextRangePrivate
33 {
34 public:
KoAnchorTextRangePrivate(KoShapeAnchor * p)35 KoAnchorTextRangePrivate(KoShapeAnchor *p)
36 : parent(p)
37 {
38 }
39
40 KoShapeAnchor *parent;
41 };
42
KoAnchorTextRange(KoShapeAnchor * parent,const QTextCursor & cursor)43 KoAnchorTextRange::KoAnchorTextRange(KoShapeAnchor *parent, const QTextCursor &cursor)
44 : KoTextRange(cursor)
45 , d_ptr(new KoAnchorTextRangePrivate(parent))
46 {
47 Q_ASSERT(parent);
48 parent->setTextLocation(this);
49 }
50
~KoAnchorTextRange()51 KoAnchorTextRange::~KoAnchorTextRange()
52 {
53 delete d_ptr;
54 }
55
anchor() const56 KoShapeAnchor *KoAnchorTextRange::anchor() const
57 {
58 Q_D(const KoAnchorTextRange);
59 return d->parent;
60 }
61
document() const62 const QTextDocument *KoAnchorTextRange::document() const
63 {
64 return KoTextRange::document();
65 }
66
position() const67 int KoAnchorTextRange::position() const
68 {
69 return rangeStart();
70 }
71
updateContainerModel()72 void KoAnchorTextRange::updateContainerModel()
73 {
74 Q_D(KoAnchorTextRange);
75
76 if (!d->parent->shape()->isVisible()) {
77 // Per default the shape this anchor presents is hidden and we only make it visible once an
78 // explicit placement is made. This prevents shapes that are anchored at e.g. hidden
79 // textboxes to not become visible.
80 d->parent->shape()->setVisible(true);
81 }
82
83 if (d->parent->placementStrategy() != 0) {
84 d->parent->placementStrategy()->updateContainerModel();
85 }
86 }
87
loadOdf(const KoXmlElement &,KoShapeLoadingContext &)88 bool KoAnchorTextRange::loadOdf(const KoXmlElement &, KoShapeLoadingContext &)
89 {
90 return true;
91 }
92
saveOdf(KoShapeSavingContext & context,int position,KoTextRange::TagType tagType) const93 void KoAnchorTextRange::saveOdf(KoShapeSavingContext &context, int position, KoTextRange::TagType tagType) const
94 {
95 Q_UNUSED(position);
96 Q_UNUSED(tagType);
97
98 Q_D(const KoAnchorTextRange);
99 if (tagType == KoTextRange::StartTag) {
100 d->parent->saveOdf(context);
101 }
102 }
103