2
* This file is part of the KDE libraries
3
* Copyright (C) 2009 Milian Wolff <mail@milianw.de>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License version 2 as published by the Free Software Foundation.
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.
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.
20
#ifndef ABSTRACTEXPORTER_H
21
#define ABSTRACTEXPORTER_H
23
#include <QtCore/QTextStream>
25
#include <ktexteditor/range.h>
26
#include <ktexteditor/attribute.h>
27
#include <ktexteditor/document.h>
28
#include <ktexteditor/view.h>
29
#include <ktexteditor/configinterface.h>
30
#include <ktexteditor/highlightinterface.h>
32
class AbstractExporter
35
/// If \p m_encapsulate is set, you should add some kind of header in the ctor
37
AbstractExporter(KTextEditor::View* view,
38
QTextStream &output, const bool encapsulate = false)
39
: m_view(view), m_output(output), m_encapsulate(encapsulate),
42
QColor defaultBackground;
43
if ( KTextEditor::ConfigInterface* ciface = qobject_cast< KTextEditor::ConfigInterface* >(m_view) ) {
44
QVariant variant = ciface->configValue("background-color");
45
if ( variant.canConvert<QColor>() ) {
46
defaultBackground = variant.value<QColor>();
49
if ( KTextEditor::HighlightInterface* hiface = qobject_cast< KTextEditor::HighlightInterface* >(m_view->document()) ) {
50
m_defaultAttribute = hiface->defaultStyle(KTextEditor::HighlightInterface::dsNormal);
51
m_defaultAttribute->setBackground(QBrush(defaultBackground));
55
/// Gets called after everything got exported.
56
/// Hence, if \p m_encapsulate is set, you should probably add some kind of footer here.
57
virtual ~AbstractExporter()
61
virtual void openLine() = 0;
63
/// Finish the current line.
64
virtual void closeLine(const bool lastLine) = 0;
66
/// Export \p text with given text attribute \p attrib.
67
/// NOTE: Check \p attrib, it might be null for KTextEditors that do not implement the
68
/// HighlightInterface.
69
virtual void exportText(const QString& text, const KTextEditor::Attribute::Ptr& attrib) = 0;
72
KTextEditor::View* m_view;
73
QTextStream &m_output;
75
KTextEditor::Attribute::Ptr m_defaultAttribute;
78
#endif // ABSTRACTEXPORTER_H
80
// kate: space-indent on; indent-width 2; replace-tabs on;