aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor/textindenter.h
blob: 03b6f5d75c5c1d62497cc6d361ec1dccc3df9226 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#pragma once

#include "texteditor_global.h"

#include "indenter.h"
#include "tabsettings.h"

QT_BEGIN_NAMESPACE
class QTextDocument;
class QTextCursor;
class QChar;
QT_END_NAMESPACE

namespace TextEditor {

class TEXTEDITOR_EXPORT TextIndenter : public Indenter
{
public:
    explicit TextIndenter(QTextDocument *doc);
    ~TextIndenter() override;

    int indentFor(const QTextBlock &block,
                  const TabSettings &tabSettings,
                  int cursorPositionInEditor = -1) override;

    IndentationForBlock indentationForBlocks(const QVector<QTextBlock> &blocks,
                                             const TabSettings &tabSettings,
                                             int cursorPositionInEditor = -1) override;
    void indentBlock(const QTextBlock &block,
                     const QChar &typedChar,
                     const TabSettings &tabSettings,
                     int cursorPositionInEditor = -1) override;

    void indent(const QTextCursor &cursor,
                const QChar &typedChar,
                const TabSettings &tabSettings,
                int cursorPositionInEditor = -1) override;

    void reindent(const QTextCursor &cursor,
                  const TabSettings &tabSettings,
                  int cursorPositionInEditor = -1) override;
    std::optional<TabSettings> tabSettings() const override;
};

class TEXTEDITOR_EXPORT PlainTextIndenter : public TextIndenter
{
public:
    using TextIndenter::TextIndenter;

    void autoIndent(const QTextCursor &cursor,
                    const TabSettings &tabSettings,
                    int cursorPositionInEditor = -1) override;
};

} // namespace TextEditor