2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2014-02-13 16:43:28 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2014-02-13 16:43:28 +01:00
|
|
|
|
2014-09-26 09:14:03 +02:00
|
|
|
#include <texteditor/texteditor.h>
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
namespace DiffEditor {
|
2015-01-30 15:02:04 +01:00
|
|
|
namespace Internal {
|
2014-02-13 16:43:28 +01:00
|
|
|
|
2015-01-30 15:02:04 +01:00
|
|
|
class DiffSelection
|
2014-02-13 16:43:28 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2018-11-07 23:22:59 +01:00
|
|
|
DiffSelection() = default;
|
2017-12-06 21:30:57 +01:00
|
|
|
DiffSelection(QTextCharFormat *f) : format(f) {}
|
2014-02-13 16:43:28 +01:00
|
|
|
DiffSelection(int s, int e, QTextCharFormat *f) : start(s), end(e), format(f) {}
|
|
|
|
|
|
2017-12-06 21:30:57 +01:00
|
|
|
int start = -1;
|
|
|
|
|
int end = -1;
|
|
|
|
|
QTextCharFormat *format = nullptr;
|
2014-02-13 16:43:28 +01:00
|
|
|
};
|
|
|
|
|
|
2015-01-30 15:02:04 +01:00
|
|
|
class SelectableTextEditorWidget : public TextEditor::TextEditorWidget
|
2014-02-13 16:43:28 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2020-06-26 13:59:38 +02:00
|
|
|
SelectableTextEditorWidget(Utils::Id id, QWidget *parent = nullptr);
|
2015-06-01 17:55:31 +02:00
|
|
|
~SelectableTextEditorWidget() override;
|
2014-09-25 15:48:21 +02:00
|
|
|
void setSelections(const QMap<int, QList<DiffSelection> > &selections);
|
2014-02-13 16:43:28 +01:00
|
|
|
|
2017-10-11 14:14:10 +02:00
|
|
|
static void setFoldingIndent(const QTextBlock &block, int indent);
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
private:
|
2014-09-25 15:48:21 +02:00
|
|
|
void paintBlock(QPainter *painter,
|
|
|
|
|
const QTextBlock &block,
|
|
|
|
|
const QPointF &offset,
|
|
|
|
|
const QVector<QTextLayout::FormatRange> &selections,
|
2015-06-01 17:55:31 +02:00
|
|
|
const QRect &clipRect) const override;
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
// 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)
|
2014-09-25 15:48:21 +02:00
|
|
|
QMap<int, QList<DiffSelection> > m_diffSelections;
|
2014-02-13 16:43:28 +01:00
|
|
|
};
|
|
|
|
|
|
2015-01-30 15:02:04 +01:00
|
|
|
} // namespace Internal
|
2014-02-13 16:43:28 +01:00
|
|
|
} // namespace DiffEditor
|