~ubuntu-branches/ubuntu/saucy/kate/saucy

« back to all changes in this revision

Viewing changes to addons/ktexteditor/exporter/abstractexporter.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell, Rohan Garg, Jonathan Riddell
  • Date: 2013-06-21 00:48:29 UTC
  • mfrom: (1.1.28)
  • Revision ID: package-import@ubuntu.com-20130621004829-y2ui02eg0j47h94y
Tags: 4:4.10.80-0ubuntu1
[ Rohan Garg ]
* New upstream release
  - Update and sort install files
  - Drop kubuntu_pate_find_python.diff, kubuntu_kate_initial_preference.patch,
    kubuntu_find_python.diff from debian/patches , not required

[ Jonathan Riddell ]
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * This file is part of the KDE libraries
 
3
 * Copyright (C) 2009 Milian Wolff <mail@milianw.de>
 
4
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
#ifndef ABSTRACTEXPORTER_H
 
21
#define ABSTRACTEXPORTER_H
 
22
 
 
23
#include <QtCore/QTextStream>
 
24
 
 
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>
 
31
 
 
32
class AbstractExporter
 
33
{
 
34
  public:
 
35
    /// If \p m_encapsulate is set, you should add some kind of header in the ctor
 
36
    /// to \p m_output.
 
37
    AbstractExporter(KTextEditor::View* view,
 
38
                     QTextStream &output, const bool encapsulate = false)
 
39
      : m_view(view), m_output(output), m_encapsulate(encapsulate), 
 
40
        m_defaultAttribute(0)
 
41
    {
 
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>();
 
47
        }
 
48
      }
 
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));
 
52
      }
 
53
    }
 
54
 
 
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()
 
58
    {}
 
59
 
 
60
    /// Begin a new line.
 
61
    virtual void openLine() = 0;
 
62
 
 
63
    /// Finish the current line.
 
64
    virtual void closeLine(const bool lastLine) = 0;
 
65
 
 
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;
 
70
 
 
71
  protected:
 
72
    KTextEditor::View* m_view;
 
73
    QTextStream &m_output;
 
74
    bool m_encapsulate;
 
75
    KTextEditor::Attribute::Ptr m_defaultAttribute;
 
76
};
 
77
 
 
78
#endif // ABSTRACTEXPORTER_H
 
79
 
 
80
// kate: space-indent on; indent-width 2; replace-tabs on;