blob: 022021687b2d5bd495dc73c65ce7baf8d1774c62 (
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "plaintextedit.h"
namespace Utils {
class QTCREATOR_UTILS_EXPORT TextEditorLayout : public PlainTextDocumentLayout
{
public:
explicit TextEditorLayout(PlainTextDocumentLayout *docLayout);
void handleBlockVisibilityChanged(const QTextBlock &block);
QTextLayout *blockLayout(const QTextBlock &block) const override;
void clearBlockLayout(QTextBlock &block) const override;
void clearBlockLayout(QTextBlock &start, QTextBlock &end, bool &blockVisibilityChanged) const override;
void relayout() override;
int additionalBlockHeight(const QTextBlock &block) const override;
QRectF replacementBlockBoundingRect(const QTextBlock &block) const override;
int lineSpacing() const override;
int relativeLineSpacing() const override;
void documentChanged(int from, int charsRemoved, int charsAdded) override;
int blockLineCount(const QTextBlock &block) const override;
void setBlockLineCount(QTextBlock &block, int lineCount) const override;
void setBlockLayedOut(const QTextBlock &block) const override;
int lineCount() const override;
int firstLineNumberOf(const QTextBlock &block) const override;
bool blockLayoutValid(int index) const;
int blockHeight(const QTextBlock &block, int lineSpacing) const;
int offsetForBlock(const QTextBlock &b) const;
int offsetForLine(int line) const;
int lineForOffset(int offset) const;
int documentPixelHeight() const;
QTextBlock findBlockByLineNumber(int lineNumber) const override;
bool moveCursorImpl(
QTextCursor &cursor,
QTextCursor::MoveOperation operation,
QTextCursor::MoveMode mode = QTextCursor::MoveAnchor) const;
bool moveCursor(
QTextCursor &cursor,
QTextCursor::MoveOperation operation,
QTextCursor::MoveMode mode = QTextCursor::MoveAnchor,
int steps = 1) const override;
private:
struct LayoutData
{
std::unique_ptr<QTextLayout> layout;
int lineCount = 1;
bool layedOut = false;
void clearLayout()
{
if (layout)
layout->clearLayout();
lineCount = 1;
layedOut = false;
}
};
LayoutData &layoutData(int index) const;
void resetOffsetCache(int blockNumber) const;
void resizeOffsetCache(int blockNumber) const;
struct OffsetData
{
int offset = -1;
int firstLine = -1;
};
mutable std::vector<LayoutData> m_layoutData;
mutable std::vector<OffsetData> m_offsetCache;
bool updatingFormats = false;
};
} // namespace Utils
|