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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
/* This file is part of the KDE project
* Copyright (C) 2010 Thomas Zander <zander@kde.org>
* Copyright (C) 2001-2006 David Faure <faure@kde.org>
* Copyright (C) 2007 Sebastian Sauer <mail@dipe.org>
* Copyright (C) 2007 Pierre Ducroquet <pinaraf@gmail.com>
* Copyright (C) 2007-2009 Thorsten Zachmann <zachmann@kde.org>
* Copyright (C) 2008 Girish Ramakrishnan <girish@forwardbias.in>
* Copyright (C) 2009 KO GmbH <cbo@kogmbh.com>
* Copyright (C) 2009 Pierre Stirnweiss <pstirnweiss@googlemail.com>
* Copyright (C) 2010 KO GmbH <ben.martin@kogmbh.com>
* Copyright (C) 2011 Pavol Korinek <pavol.korinek@ixonos.com>
* Copyright (C) 2011 Lukáš Tvrdý <lukas.tvrdy@ixonos.com>
*
* 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 KOTEXTLOADER_H
#define KOTEXTLOADER_H
#include <QObject>
#include "kotext_export.h"
#include <KoXmlReaderForward.h>
class QTextCursor;
class QTextTable;
class QRect;
class KoShapeLoadingContext;
class KoShape;
/**
* The KoTextLoader loads is use to load text for one and only one textdocument or shape
* to the scribe text-engine using QTextCursor objects. So if you have two shapes 2 different
* KoTextLoader are used for that. Also if you have a frame with text inside a text a new
* KoTextLoader is used.
*
* If you want to use the KoTextLoader for text that needs styles from styles.xml. e.g.
* test shapes on master pages, you need to set KoOdfLoadingContext::setUseStylesAutoStyles( true ).
*
* Don't forget to unset it if you later want to load text that needs content.xml.
*/
class KOTEXT_EXPORT KoTextLoader : public QObject
{
Q_OBJECT
public:
/**
* Normalizes the whitespaces in the string \p in according to the ODF ruleset
* for stripping whitespaces and returns the result. If \p leadingSpace is
* true a leading space is stripped too.
*
* This is different from QString::simplifyWhiteSpace() because that one removes
* leading and trailing whitespace, but such whitespace is significant in ODF.
* So we use this function to compress sequences of space characters into single
* spaces.
*/
static QString normalizeWhitespace(const QString &in, bool leadingSpace);
/**
* Constructor.
* Notice that despite this being a QObject there is no 'parent' available for
* memory management here.
*
* @param context The context the KoTextLoader is called in
*/
explicit KoTextLoader(KoShapeLoadingContext &context, KoShape *shape = 0);
/**
* Destructor.
*/
~KoTextLoader() override;
enum LoadBodyMode
{
LoadMode,
PasteMode
};
/**
* Load the body from the \p element into the \p cursor .
*
* This method got called e.g. at the \a KoTextShapeData::loadOdf() method if a TextShape
* instance likes to load an ODF element.
*
* @param element the element to start loading at
* @param cursor the text cursor to insert the body after
* @param pasteMode does special handling of section needed, in case we are pasting text
*/
void loadBody(const KoXmlElement &element, QTextCursor &cursor, LoadBodyMode pasteMode = LoadMode);
Q_SIGNALS:
/**
* This signal is emitted during loading with a percentage within 1-100 range
* \param percent the progress as a percentage
*/
void sigProgress(int percent);
private:
/**
* Load the paragraph from the \p element into the \p cursor .
*/
void loadParagraph(const KoXmlElement &element, QTextCursor &cursor);
/**
* Load the heading from the \p element into the \p cursor .
*/
void loadHeading(const KoXmlElement &element, QTextCursor &cursor);
/**
* Load the list from the \p element into the \p cursor .
*/
void loadList(const KoXmlElement &element, QTextCursor &cursor);
/**
* Load a list-item into the cursor
*/
void loadListItem(const KoXmlElement &e, QTextCursor &cursor, int level);
/**
* Load the section from the \p element into the \p cursor .
*/
void loadSection(const KoXmlElement &element, QTextCursor &cursor);
/**
* Load the text into the \p cursor .
*/
void loadText(const QString &text, QTextCursor &cursor,
bool *stripLeadingSpace, bool isLastNode);
/**
* Load the span from the \p element into the \p cursor .
*/
void loadSpan(const KoXmlElement &element, QTextCursor &cursor, bool *leadingSpace);
/**
* Load the table from the \p element into the \p cursor.
*
* The table and its contents are placed in a new shape.
*/
void loadTable(const KoXmlElement &element, QTextCursor& cursor);
/**
* Loads a table column
*/
void loadTableColumn(const KoXmlElement &element, QTextTable *table, int &columns);
/**
* Loads a table-row into the cursor
*/
void loadTableRow(const KoXmlElement &element, QTextTable *table, QVector<QRect> &spanStore, QTextCursor &cursor, int &rows);
/**
* Loads a table-cell into the cursor
*/
void loadTableCell(const KoXmlElement &element, QTextTable *table, QVector<QRect> &spanStore, QTextCursor &cursor, int ¤tCell);
/**
* Load a note \p element into the \p cursor.
*/
void loadNote(const KoXmlElement &element, QTextCursor& cursor);
/**
* Load a citation \p element into the \p cursor.
*/
void loadCite(const KoXmlElement &element, QTextCursor& cursor);
/**
* Load the shape element and assign hyperlink to it \p element into the \p cursor .
*/
void loadShapeWithHyperLink(const KoXmlElement &element, QTextCursor& cursor);
/**
* Load the shape element \p element into the \p cursor .
*/
KoShape *loadShape(const KoXmlElement &element, QTextCursor& cursor);
/**
* Load the table of content element \p element into the \p cursor .
*/
void loadTableOfContents(const KoXmlElement &element, QTextCursor& cursor);
/**
* Load the bibliography element \p element into the \p cursor .
*/
void loadBibliography(const KoXmlElement &element, QTextCursor& cursor);
/**
* This is called in loadBody before reading the body starts.
*/
void startBody(int total);
/**
* This is called in loadBody on each item that is read within the body.
*/
void processBody();
/**
* This is called in loadBody once the body was read.
*/
void endBody();
/// \internal d-pointer class.
class Private;
/// \internal d-pointer instance.
Private* const d;
};
#endif
|