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 | |
26 | QT_BEGIN_NAMESPACE |
27 | |
28 | class QQuickItem; |
29 | class QQuickPixmap; |
30 | class QQmlContext; |
31 | |
32 | class Q_AUTOTEST_EXPORT QQuickTextDocumentWithImageResources : public QTextDocument, public QTextObjectInterface |
33 | { |
34 | Q_OBJECT |
35 | Q_INTERFACES(QTextObjectInterface) |
36 | public: |
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 | |
47 | public Q_SLOTS: |
48 | void clearResources(); |
49 | |
50 | Q_SIGNALS: |
51 | void imagesLoaded(); |
52 | |
53 | protected: |
54 | QVariant loadResource(int type, const QUrl &name) override; |
55 | |
56 | QQuickPixmap *loadPixmap(QQmlContext *context, const QUrl &name); |
57 | |
58 | private Q_SLOTS: |
59 | void requestFinished(); |
60 | |
61 | private: |
62 | QHash<QUrl, QQuickPixmap *> m_resources; |
63 | |
64 | int outstanding; |
65 | static QSet<QUrl> errors; |
66 | }; |
67 | |
68 | namespace QtPrivate { |
69 | class ProtectedLayoutAccessor: public QAbstractTextDocumentLayout |
70 | { |
71 | public: |
72 | inline QTextCharFormat formatAccessor(int pos) |
73 | { |
74 | return format(pos); |
75 | } |
76 | }; |
77 | } // namespace QtPrivate |
78 | |
79 | QT_END_NAMESPACE |
80 | |
81 | #endif // QQUICKDOCUMENT_P_H |
82 | |