1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef EXTRUDEDTEXTGEOMETRY_P_H
5#define EXTRUDEDTEXTGEOMETRY_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 <QQuick3DGeometry>
19#include <QQmlEngine>
20#include <QVector3D>
21#include <QFont>
22
23#if QT_CONFIG(concurrent)
24#include <QFuture>
25#include <QFutureWatcher>
26#endif
27
28QT_BEGIN_NAMESPACE
29
30class ExtrudedTextGeometry : public QQuick3DGeometry
31{
32 Q_OBJECT
33 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
34 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
35 Q_PROPERTY(float depth READ depth WRITE setDepth NOTIFY depthChanged)
36 Q_PROPERTY(float scale READ scale WRITE setScale NOTIFY scaleChanged FINAL)
37 Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged)
38 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
39 QML_ELEMENT
40 QML_ADDED_IN_VERSION(6, 9)
41public:
42 enum Status { Null, Ready, Loading, Error };
43 Q_ENUM(Status)
44
45 explicit ExtrudedTextGeometry(QQuick3DObject *parent = nullptr);
46 ~ExtrudedTextGeometry() override;
47
48 QString text() const;
49 void setText(const QString &newText);
50
51 QFont font() const;
52 void setFont(const QFont &newFont);
53
54 float depth() const;
55 void setDepth(float newDepth);
56
57 float scale() const;
58 void setScale(float newScale);
59
60 bool asynchronous() const;
61 void setAsynchronous(bool newAsynchronous);
62
63 Status status() const;
64
65 using IndexType = quint32;
66
67private Q_SLOTS:
68 void doUpdateGeometry();
69 void requestFinished();
70
71Q_SIGNALS:
72 void textChanged();
73 void fontChanged();
74 void depthChanged();
75 void scaleChanged();
76 void asynchronousChanged();
77 void statusChanged();
78
79private:
80 struct GeometryData {
81 QByteArray vertexData;
82 QByteArray indexData;
83 QVector3D boundsMin;
84 QVector3D boundsMax;
85 };
86
87 void scheduleGeometryUpdate();
88 void updateGeometry(const GeometryData &geometryData);
89
90 static ExtrudedTextGeometry::GeometryData generateExtrudedTextGeometry(const QString &text,
91 const QFont &font,
92 float depth,
93 float scale);
94#if QT_CONFIG(concurrent)
95 static void generateExtrudedTextGeometryAsync(QPromise<ExtrudedTextGeometry::GeometryData> &promise,
96 const QString &text,
97 const QFont &font,
98 float depth,
99 float scale);
100#endif
101
102
103 QString m_text;
104 QFont m_font = QFont(QStringLiteral("Arial"), 4);
105 float m_depth = 1.0f;
106 float m_scale = 1.0f;
107 bool m_asynchronous = true;
108 Status m_status = Null;
109#if QT_CONFIG(concurrent)
110 QFuture<GeometryData> m_geometryDataFuture;
111 QFutureWatcher<GeometryData> m_geometryDataWatcher;
112#endif
113 bool m_geometryUpdateRequested = false;
114 bool m_pendingAsyncUpdate = false;
115};
116
117QT_END_NAMESPACE
118
119#endif // EXTRUDEDTEXTGEOMETRY_P_H
120

source code of qtquick3d/src/helpers/extrudedtextgeometry_p.h