1 | // Copyright (C) 2023 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "q3dlight_p.h" |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | /*! |
9 | * \class Q3DLight |
10 | * \inmodule QtGraphs |
11 | * \brief Representation of a light source in 3D space. |
12 | * |
13 | * Q3DLight represents a monochrome light source in 3D space. |
14 | * |
15 | * \note Default light has isAutoPosition() \c true. |
16 | */ |
17 | |
18 | /*! |
19 | * \qmltype Light3D |
20 | * \inqmlmodule QtGraphs |
21 | * \ingroup graphs_qml |
22 | * \instantiates Q3DLight |
23 | * \brief Representation of a light source in 3D space. |
24 | * |
25 | * Light3D represents a monochrome light source in 3D space. |
26 | * |
27 | * \note Default light has autoPosition \c true. |
28 | */ |
29 | |
30 | /*! |
31 | * \qmlproperty bool Light3D::autoPosition |
32 | * Defines whether the light position follows the camera automatically. |
33 | * \note Has no effect if shadows are enabled. Remember to disable shadows before setting light's |
34 | * position, or it will be overwritten by automatic positioning if this |
35 | * property is \c false. |
36 | */ |
37 | |
38 | /*! |
39 | * Constructs a new 3D light located at origin. An optional \a parent parameter can be given |
40 | * and is then passed to QObject constructor. |
41 | */ |
42 | Q3DLight::Q3DLight(QObject *parent) : |
43 | Q3DObject(new Q3DLightPrivate(this), parent) |
44 | { |
45 | } |
46 | |
47 | /*! |
48 | * Destroys the light object. |
49 | */ |
50 | Q3DLight::~Q3DLight() |
51 | { |
52 | } |
53 | |
54 | /*! |
55 | * \property Q3DLight::autoPosition |
56 | * \brief Whether the light position follows the camera automatically. |
57 | * \note Has no effect if shadows are enabled. Remember to disable shadows before setting light's |
58 | * position, or it will be overwritten by automatic positioning if |
59 | * \c isAutoPosition() is \c false. |
60 | */ |
61 | void Q3DLight::setAutoPosition(bool enabled) |
62 | { |
63 | Q_D(Q3DLight); |
64 | if (enabled != d->m_automaticLight) { |
65 | d->m_automaticLight = enabled; |
66 | setDirty(true); |
67 | emit autoPositionChanged(autoPosition: enabled); |
68 | } |
69 | } |
70 | |
71 | bool Q3DLight::isAutoPosition() |
72 | { |
73 | const Q_D(Q3DLight); |
74 | return d->m_automaticLight; |
75 | } |
76 | |
77 | Q3DLightPrivate::Q3DLightPrivate(Q3DLight *q) : |
78 | Q3DObjectPrivate(q), |
79 | m_automaticLight(false) |
80 | { |
81 | } |
82 | |
83 | Q3DLightPrivate::~Q3DLightPrivate() |
84 | { |
85 | } |
86 | |
87 | void Q3DLightPrivate::sync(Q3DLight &other) |
88 | { |
89 | Q_Q(Q3DLight); |
90 | if (q->isDirty()) { |
91 | other.setPosition(q->position()); |
92 | other.setAutoPosition(q->isAutoPosition()); |
93 | q->setDirty(false); |
94 | } |
95 | } |
96 | |
97 | QT_END_NAMESPACE |
98 | |