aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/diffeditor/selectabletexteditorwidget.h
blob: 4b0d465204f5596135dfc049ddc2a079fa8bd4e4 (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
// 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/texteditor.h>

namespace TextEditor { class DisplaySettings; }

namespace DiffEditor::Internal {

class DiffSelection
{
public:
    QTextCharFormat *format = nullptr;
    int start = -1;
    int end = -1;
};

// block number, list of ranges
// DiffSelection.start - can be -1 (continues from the previous line)
// DiffSelection.end - can be -1 (spans to the end of line, even after the last character in line)
using DiffSelections = QMap<int, QList<DiffSelection>>;

class SelectableTextEditorWidget : public TextEditor::TextEditorWidget
{
    Q_OBJECT
public:
    SelectableTextEditorWidget(Utils::Id id, QWidget *parent = nullptr);
    ~SelectableTextEditorWidget() override;
    void setSelections(const DiffSelections &selections);

    void setDisplaySettings(const TextEditor::DisplaySettings &displaySettings) override;

    static DiffSelections polishedSelections(const DiffSelections &selections);
    static void setFoldingIndent(const QTextBlock &block, int indent);

private:
    void paintBlock(QPainter *painter,
                    const QTextBlock &block,
                    const QPointF &offset,
                    const QVector<QTextLayout::FormatRange> &selections,
                    const QRect &clipRect) const override;

    DiffSelections m_diffSelections;
};

} // namespace DiffEditor::Internal