1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKTEXTDOCUMENT_P_H
5#define QQUICKTEXTDOCUMENT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qhash.h>
19#include <QtCore/qvariant.h>
20#include <QtGui/qimage.h>
21#include <QtGui/qtextdocument.h>
22#include <QtGui/qabstracttextdocumentlayout.h>
23#include <QtGui/qtextlayout.h>
24#include <QtCore/private/qglobal_p.h>
25
26QT_BEGIN_NAMESPACE
27
28class QQuickItem;
29class QQuickPixmap;
30class QQmlContext;
31
32class Q_AUTOTEST_EXPORT QQuickTextDocumentWithImageResources : public QTextDocument, public QTextObjectInterface
33{
34 Q_OBJECT
35 Q_INTERFACES(QTextObjectInterface)
36public:
37 QQuickTextDocumentWithImageResources(QQuickItem *parent);
38 virtual ~QQuickTextDocumentWithImageResources();
39
40 int resourcesLoading() const { return outstanding; }
41
42 QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format) override;
43 void drawObject(QPainter *p, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format) override;
44
45 QImage image(const QTextImageFormat &format) const;
46
47public Q_SLOTS:
48 void clearResources();
49
50Q_SIGNALS:
51 void imagesLoaded();
52
53protected:
54 QVariant loadResource(int type, const QUrl &name) override;
55
56 QQuickPixmap *loadPixmap(QQmlContext *context, const QUrl &name);
57
58private Q_SLOTS:
59 void requestFinished();
60
61private:
62 QHash<QUrl, QQuickPixmap *> m_resources;
63
64 int outstanding;
65 static QSet<QUrl> errors;
66};
67
68namespace QtPrivate {
69class ProtectedLayoutAccessor: public QAbstractTextDocumentLayout
70{
71public:
72 inline QTextCharFormat formatAccessor(int pos)
73 {
74 return format(pos);
75 }
76};
77} // namespace QtPrivate
78
79QT_END_NAMESPACE
80
81#endif // QQUICKDOCUMENT_P_H
82

source code of qtdeclarative/src/quick/items/qquicktextdocument_p.h