Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
extrudedtextgeometry_p.h
Go to the documentation of this file.
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 <QtQuick3DHelpers/qtquick3dhelpersexports.h>
19#include <QQuick3DGeometry>
20#include <QQmlEngine>
21#include <QVector3D>
22#include <QFont>
23
24#if QT_CONFIG(concurrent)
25#include <QFuture>
26#include <QFutureWatcher>
27#endif
28
30
31class Q_QUICK3DHELPERS_EXPORT ExtrudedTextGeometry : public QQuick3DGeometry
32{
33 Q_OBJECT
34 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
35 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
36 Q_PROPERTY(float depth READ depth WRITE setDepth NOTIFY depthChanged)
37 Q_PROPERTY(float scale READ scale WRITE setScale NOTIFY scaleChanged FINAL)
38 Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged)
39 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
40 QML_ELEMENT
41 QML_ADDED_IN_VERSION(6, 9)
42public:
43 enum Status { Null, Ready, Loading, Error };
44 Q_ENUM(Status)
45
46 explicit ExtrudedTextGeometry(QQuick3DObject *parent = nullptr);
47 ~ExtrudedTextGeometry() override;
48
49 QString text() const;
50 void setText(const QString &newText);
51
52 QFont font() const;
53 void setFont(const QFont &newFont);
54
55 float depth() const;
56 void setDepth(float newDepth);
57
58 float scale() const;
59 void setScale(float newScale);
60
61 bool asynchronous() const;
62 void setAsynchronous(bool newAsynchronous);
63
64 Status status() const;
65
66 using IndexType = quint32;
67
68private Q_SLOTS:
69 void doUpdateGeometry();
70 void requestFinished();
71
72Q_SIGNALS:
73 void textChanged();
74 void fontChanged();
75 void depthChanged();
76 void scaleChanged();
77 void asynchronousChanged();
78 void statusChanged();
79
80private:
81 struct GeometryData {
82 QByteArray vertexData;
83 QByteArray indexData;
84 QVector3D boundsMin;
85 QVector3D boundsMax;
86 };
87
88 void scheduleGeometryUpdate();
89 void updateGeometry(const GeometryData &geometryData);
90
91 static ExtrudedTextGeometry::GeometryData generateExtrudedTextGeometry(const QString &text,
92 const QFont &font,
93 float depth,
94 float scale);
95#if QT_CONFIG(concurrent)
96 static void generateExtrudedTextGeometryAsync(QPromise<ExtrudedTextGeometry::GeometryData> &promise,
97 const QString &text,
98 const QFont &font,
99 float depth,
100 float scale);
101#endif
102
103
104 QString m_text;
105 QFont m_font = QFont(QStringLiteral("Arial"), 4);
106 float m_depth = 1.0f;
107 float m_scale = 1.0f;
108 bool m_asynchronous = true;
109 Status m_status = Null;
110#if QT_CONFIG(concurrent)
111 QFuture<GeometryData> m_geometryDataFuture;
112 QFutureWatcher<GeometryData> m_geometryDataWatcher;
113#endif
114 bool m_geometryUpdateRequested = false;
115 bool m_pendingAsyncUpdate = false;
116};
117
118QT_END_NAMESPACE
119
120#endif // EXTRUDEDTEXTGEOMETRY_P_H
QVector3D mix(const QVector3D &a, const QVector3D &b, float ratio)
TriangulationData triangulate(const QString &text, const QFont &font, float scale)
std::vector< ExtrudedTextGeometry::IndexType > indices
std::vector< ExtrudedTextGeometry::IndexType > outlineIndices