/***********************************************************************
 *
 * Copyright (C) 2013, 2014 Graeme Gott <graeme@gottcode.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 ***********************************************************************/

#ifndef DOCX_WRITER_H
#define DOCX_WRITER_H

#include <QCoreApplication>
#include <QString>
#include <QXmlStreamWriter>
class QIODevice;
class QTextBlock;
class QTextBlockFormat;
class QTextCharFormat;
class QTextDocument;

class DocxWriter
{
	Q_DECLARE_TR_FUNCTIONS(DocxWriter)

public:
	DocxWriter();

	QString errorString() const
	{
		return m_error;
	}

	void setStrict(bool strict);
	bool write(QIODevice* device, const QTextDocument* document);

private:
	QByteArray writeDocument(const QTextDocument* document);
	void writeParagraph(const QTextBlock& block);
	void writeText(const QString& text, int start, int end);
	void writeParagraphProperties(const QTextBlockFormat& block_format, const QTextCharFormat& char_format);
	bool writeRunProperties(const QTextCharFormat& char_format, const QString& parent_element = QString());
	void writePropertyElement(const QString& element, bool& empty);
	void writePropertyElement(const QString& element, const QString& parent_element, bool& empty);

private:
	QXmlStreamWriter m_xml;
	bool m_strict;
	QString m_error;
};

#endif
