aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qsginternaltextnode_p.h
blob: 0d296579127d12294758a63fdc6892a2dfda0cf7 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QSGINTERNALTEXTNODE_P_H
#define QSGINTERNALTEXTNODE_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include "qsgtextnode.h"
#include "qquicktext_p.h"
#include <qglyphrun.h>

#include <QtGui/qcolor.h>
#include <QtGui/qtextlayout.h>
#include <QtCore/qvarlengtharray.h>
#include <QtCore/qscopedpointer.h>

QT_BEGIN_NAMESPACE

class QSGGlyphNode;
class QTextBlock;
class QColor;
class QTextDocument;
class QSGContext;
class QRawFont;
class QSGInternalRectangleNode;
class QSGClipNode;
class QSGTexture;
class QSGRenderContext;

class QQuickTextNodeEngine;

class Q_QUICK_EXPORT QSGInternalTextNode : public QSGTextNode
{
public:
    QSGInternalTextNode(QSGRenderContext *renderContext);
    ~QSGInternalTextNode();

    static bool isComplexRichText(QTextDocument *);

    void setColor(QColor color) override
    {
        m_color = color;
    }

    QColor color() const override
    {
        return m_color;
    }

    void setTextStyle(TextStyle textStyle) override
    {
        m_textStyle = textStyle;
    }

    TextStyle textStyle() override
    {
        return m_textStyle;
    }

    void setStyleColor(QColor styleColor) override
    {
        m_styleColor = styleColor;
    }

    QColor styleColor() const override
    {
        return m_styleColor;
    }

    void setLinkColor(QColor linkColor) override
    {
        m_linkColor = linkColor;
    }

    QColor linkColor() const override
    {
        return m_linkColor;
    }

    void setSelectionColor(QColor selectionColor) override
    {
        m_selectionColor = selectionColor;
    }

    QColor selectionColor() const override
    {
        return m_selectionColor;
    }

    void setSelectionTextColor(QColor selectionTextColor) override
    {
        m_selectionTextColor = selectionTextColor;
    }

    QColor selectionTextColor() const override
    {
        return m_selectionTextColor;
    }

    void setRenderTypeQuality(int renderTypeQuality) override
    {
        m_renderTypeQuality = renderTypeQuality;
    }
    int renderTypeQuality() const override
    {
        return m_renderTypeQuality;
    }

    void setRenderType(RenderType renderType) override
    {
        m_renderType = renderType;
    }

    RenderType renderType() const override
    {
        return m_renderType;
    }

    void setFiltering(QSGTexture::Filtering filtering) override
    {
        m_filtering = filtering;
    }

    QSGTexture::Filtering filtering() const override
    {
        return m_filtering;
    }

    void setViewport(const QRectF &viewport) override
    {
        m_viewport = viewport;
    }

    QRectF viewport() const override
    {
        return m_viewport;
    }

    void setCursor(const QRectF &rect, const QColor &color);
    void clearCursor();

    void addRectangleNode(const QRectF &rect, const QColor &color);
    virtual void addDecorationNode(const QRectF &rect, const QColor &color);
    void addImage(const QRectF &rect, const QImage &image);
    void clear() override;
    QSGGlyphNode *addGlyphs(const QPointF &position, const QGlyphRun &glyphs, const QColor &color,
                            QQuickText::TextStyle style = QQuickText::Normal, const QColor &styleColor = QColor(),
                            QSGNode *parentNode = 0);

    QSGInternalRectangleNode *cursorNode() const { return m_cursorNode; }
    QPair<int, int> renderedLineRange() const { return { m_firstLineInViewport, m_firstLinePastViewport }; }

protected:
    void doAddTextLayout(QPointF position,
                         QTextLayout *textLayout,
                         int selectionStart,
                         int selectionEnd,
                         int lineStart,
                         int lineCount) override;

    void doAddTextDocument(QPointF position,
                           QTextDocument *textDocument,
                           int selectionStart,
                           int selectionEnd) override;

private:
    QSGInternalRectangleNode *m_cursorNode = nullptr;
    QList<QSGTexture *> m_textures;
    QSGRenderContext *m_renderContext = nullptr;
    RenderType m_renderType = QtRendering;
    TextStyle m_textStyle = Normal;
    QRectF m_viewport;
    QColor m_color = QColor(0, 0, 0);
    QColor m_styleColor = QColor(0, 0, 0);
    QColor m_linkColor = QColor(0, 0, 255);
    QColor m_selectionColor = QColor(0, 0, 128);
    QColor m_selectionTextColor = QColor(255, 255, 255);
    QSGTexture::Filtering m_filtering = QSGTexture::Nearest;
    int m_renderTypeQuality = -1;
    int m_firstLineInViewport = -1;
    int m_firstLinePastViewport = -1;

    friend class QQuickTextEdit;
    friend class QQuickTextEditPrivate;
};

QT_END_NAMESPACE

#endif // QSGINTERNALTEXTNODE_P_H