File indexing completed on 2024-04-14 03:55:09
0001 /* 0002 SPDX-FileCopyrightText: 2009 Milian Wolff <mail@milianw.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef ABSTRACTEXPORTER_H 0008 #define ABSTRACTEXPORTER_H 0009 0010 #include <QTextStream> 0011 0012 #include <ktexteditor/attribute.h> 0013 #include <ktexteditor/document.h> 0014 #include <ktexteditor/range.h> 0015 #include <ktexteditor/view.h> 0016 0017 class AbstractExporter 0018 { 0019 public: 0020 /// If \p m_encapsulate is set, you should add some kind of header in the ctor 0021 /// to \p m_output. 0022 AbstractExporter(KTextEditor::View *view, QTextStream &output, const bool encapsulate = false) 0023 : m_view(view) 0024 , m_output(output) 0025 , m_encapsulate(encapsulate) 0026 , m_defaultAttribute(nullptr) 0027 { 0028 QColor defaultBackground; 0029 QVariant variant = m_view->configValue(QStringLiteral("background-color")); 0030 if (variant.canConvert<QColor>()) { 0031 defaultBackground = variant.value<QColor>(); 0032 } 0033 0034 m_defaultAttribute = view->defaultStyleAttribute(KSyntaxHighlighting::Theme::TextStyle::Normal); 0035 m_defaultAttribute->setBackground(QBrush(defaultBackground)); 0036 } 0037 0038 /// Gets called after everything got exported. 0039 /// Hence, if \p m_encapsulate is set, you should probably add some kind of footer here. 0040 virtual ~AbstractExporter() 0041 { 0042 } 0043 0044 /// Begin a new line. 0045 virtual void openLine() = 0; 0046 0047 /// Finish the current line. 0048 virtual void closeLine(const bool lastLine) = 0; 0049 0050 /// Export \p text with given text attribute \p attrib. 0051 virtual void exportText(const QString &text, const KTextEditor::Attribute::Ptr &attrib) = 0; 0052 0053 protected: 0054 KTextEditor::View *m_view; 0055 QTextStream &m_output; 0056 bool m_encapsulate; 0057 KTextEditor::Attribute::Ptr m_defaultAttribute; 0058 }; 0059 0060 #endif