1 /* This file is part of the KDE project
2 * Copyright (C) 2010 KO GmbH <ben.martin@kogmbh.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "KoTextMeta.h"
21
22 #include <KoShapeSavingContext.h>
23 #include <KoXmlReader.h>
24 #include <KoXmlWriter.h>
25 #include <KoTextInlineRdf.h>
26
27 #include <QTextDocument>
28 #include <QTextInlineObject>
29 #include <QPointer>
30
31 #include "TextDebug.h"
32
33 // Include Q_UNSUSED classes, for building on Windows
34 #include <KoShapeLoadingContext.h>
35
36 class Q_DECL_HIDDEN KoTextMeta::Private
37 {
38 public:
Private(const QTextDocument * doc)39 Private(const QTextDocument *doc)
40 : document(doc),
41 posInDocument(0) { }
42 const QTextDocument *document;
43 int posInDocument;
44 QPointer<KoTextMeta> endBookmark;
45 BookmarkType type;
46 };
47
KoTextMeta(const QTextDocument * document)48 KoTextMeta::KoTextMeta(const QTextDocument *document)
49 : KoInlineObject(false),
50 d(new Private(document))
51 {
52 d->endBookmark.clear();
53 }
54
~KoTextMeta()55 KoTextMeta::~KoTextMeta()
56 {
57 delete d;
58 }
59
saveOdf(KoShapeSavingContext & context)60 void KoTextMeta::saveOdf(KoShapeSavingContext &context)
61 {
62 KoXmlWriter &writer = context.xmlWriter();
63
64 debugText << "kom.save() this:" << (void*)this << " d->type:" << d->type;
65 if (inlineRdf()) {
66 debugText << "kom.save() have inline Rdf";
67 }
68
69 if (d->type == StartBookmark) {
70 writer.startElement("text:meta", false);
71 writer.addAttribute("text:name", "foo");
72
73 if (inlineRdf()) {
74 inlineRdf()->saveOdf(context, &writer);
75 }
76 } else {
77 debugText << "adding endelement.";
78 writer.endElement();
79 }
80 debugText << "kom.save() done this:" << (void*)this << " d->type:" << d->type;
81 }
82
loadOdf(const KoXmlElement & element,KoShapeLoadingContext & context)83 bool KoTextMeta::loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context)
84 {
85 Q_UNUSED(element);
86 Q_UNUSED(context);
87 debugText << "kom.load()";
88 return true;
89 }
90
updatePosition(const QTextDocument * document,int posInDocument,const QTextCharFormat & format)91 void KoTextMeta::updatePosition(const QTextDocument *document, int posInDocument, const QTextCharFormat &format)
92 {
93 Q_UNUSED(format);
94 d->document = document;
95 d->posInDocument = posInDocument;
96 }
97
resize(const QTextDocument * document,QTextInlineObject & object,int posInDocument,const QTextCharFormat & format,QPaintDevice * pd)98 void KoTextMeta::resize(const QTextDocument *document, QTextInlineObject &object, int posInDocument, const QTextCharFormat &format, QPaintDevice *pd)
99 {
100 Q_UNUSED(document);
101 Q_UNUSED(posInDocument);
102 Q_UNUSED(format);
103 Q_UNUSED(pd);
104 object.setWidth(0);
105 object.setAscent(0);
106 object.setDescent(0);
107 }
108
paint(QPainter &,QPaintDevice *,const QTextDocument *,const QRectF &,const QTextInlineObject &,int,const QTextCharFormat &)109 void KoTextMeta::paint(QPainter &, QPaintDevice *, const QTextDocument *, const QRectF &, const QTextInlineObject &, int , const QTextCharFormat &)
110 {
111 // nothing to paint.
112 }
113
setType(BookmarkType type)114 void KoTextMeta::setType(BookmarkType type)
115 {
116 d->type = type;
117 }
118
type() const119 KoTextMeta::BookmarkType KoTextMeta::type() const
120 {
121 return d->type;
122 }
123
setEndBookmark(KoTextMeta * bookmark)124 void KoTextMeta::setEndBookmark(KoTextMeta *bookmark)
125 {
126 d->type = StartBookmark;
127 bookmark->d->type = EndBookmark;
128 d->endBookmark = bookmark;
129 }
130
endBookmark() const131 KoTextMeta *KoTextMeta::endBookmark() const
132 {
133 return d->endBookmark.data();
134 }
135
position() const136 int KoTextMeta::position() const
137 {
138 return d->posInDocument;
139 }
140