KTextEditor

abstractexporter.h
1/*
2 SPDX-FileCopyrightText: 2009 Milian Wolff <mail@milianw.de>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef ABSTRACTEXPORTER_H
8#define ABSTRACTEXPORTER_H
9
10#include <QTextStream>
11
12#include <ktexteditor/attribute.h>
13#include <ktexteditor/document.h>
14#include <ktexteditor/range.h>
15#include <ktexteditor/view.h>
16
17class AbstractExporter
18{
19public:
20 /// If \p m_encapsulate is set, you should add some kind of header in the ctor
21 /// to \p m_output.
22 AbstractExporter(KTextEditor::View *view, QTextStream &output, const bool encapsulate = false)
23 : m_view(view)
24 , m_output(output)
25 , m_encapsulate(encapsulate)
26 , m_defaultAttribute(nullptr)
27 {
28 QColor defaultBackground;
29 QVariant variant = m_view->configValue(QStringLiteral("background-color"));
30 if (variant.canConvert<QColor>()) {
31 defaultBackground = variant.value<QColor>();
32 }
33
34 m_defaultAttribute = view->defaultStyleAttribute(KSyntaxHighlighting::Theme::TextStyle::Normal);
35 m_defaultAttribute->setBackground(QBrush(defaultBackground));
36 }
37
38 /// Gets called after everything got exported.
39 /// Hence, if \p m_encapsulate is set, you should probably add some kind of footer here.
40 virtual ~AbstractExporter()
41 {
42 }
43
44 /// Begin a new line.
45 virtual void openLine() = 0;
46
47 /// Finish the current line.
48 virtual void closeLine(const bool lastLine) = 0;
49
50 /// Export \p text with given text attribute \p attrib.
51 virtual void exportText(const QString &text, const KTextEditor::Attribute::Ptr &attrib) = 0;
52
53protected:
54 KTextEditor::View *m_view;
55 QTextStream &m_output;
56 bool m_encapsulate;
57 KTextEditor::Attribute::Ptr m_defaultAttribute;
58};
59
60#endif
A text widget with KXMLGUIClient that represents a Document.
Definition view.h:244
virtual QVariant configValue(const QString &key)=0
Get a value for the key.
virtual QExplicitlySharedDataPointer< KTextEditor::Attribute > defaultStyleAttribute(KSyntaxHighlighting::Theme::TextStyle defaultStyle) const =0
Returns the attribute for the default style defaultStyle.
bool canConvert() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:17:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.