1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Data Visualization module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30#include "q3dlight_p.h"
31
32QT_BEGIN_NAMESPACE_DATAVISUALIZATION
33
34/*!
35 * \class Q3DLight
36 * \inmodule QtDataVisualization
37 * \brief Representation of a light source in 3D space.
38 * \since QtDataVisualization 1.0
39 *
40 * Q3DLight represents a monochrome light source in 3D space.
41 *
42 * \note Default light has isAutoPosition() \c true.
43 */
44
45/*!
46 * \qmltype Light3D
47 * \inqmlmodule QtDataVisualization
48 * \since QtDataVisualization 1.0
49 * \ingroup datavisualization_qml
50 * \instantiates Q3DLight
51 * \brief Representation of a light source in 3D space.
52 *
53 * Light3D represents a monochrome light source in 3D space.
54 *
55 * \note Default light has autoPosition \c true.
56 */
57
58/*!
59 * \qmlproperty bool Light3D::autoPosition
60 * \since QtDataVisualization 1.3
61 * Defines whether the light position follows the camera automatically.
62 * \note Has no effect if shadows are enabled. Remember to disable shadows before setting light's
63 * position, or it will be overwritten by automatic positioning if this
64 * property is \c false.
65 */
66
67/*!
68 * Constructs a new 3D light located at origin. An optional \a parent parameter can be given
69 * and is then passed to QObject constructor.
70 */
71Q3DLight::Q3DLight(QObject *parent) :
72 Q3DObject(parent),
73 d_ptr(new Q3DLightPrivate(this))
74{
75}
76
77/*!
78 * Destroys the light object.
79 */
80Q3DLight::~Q3DLight()
81{
82}
83
84/*!
85 * \property Q3DLight::autoPosition
86 * \since QtDataVisualization 5.9
87 * \brief Whether the light position follows the camera automatically.
88 * \note Has no effect if shadows are enabled. Remember to disable shadows before setting light's
89 * position, or it will be overwritten by automatic positioning if
90 * \c isAutoPosition() is \c false.
91 */
92void Q3DLight::setAutoPosition(bool enabled)
93{
94 if (enabled != d_ptr->m_automaticLight) {
95 d_ptr->m_automaticLight = enabled;
96 setDirty(true);
97 emit autoPositionChanged(autoPosition: enabled);
98 }
99}
100
101bool Q3DLight::isAutoPosition()
102{
103 return d_ptr->m_automaticLight;
104}
105
106Q3DLightPrivate::Q3DLightPrivate(Q3DLight *q) :
107 q_ptr(q),
108 m_automaticLight(false)
109{
110}
111
112Q3DLightPrivate::~Q3DLightPrivate()
113{
114}
115
116void Q3DLightPrivate::sync(Q3DLight &other)
117{
118 if (q_ptr->isDirty()) {
119 other.setPosition(q_ptr->position());
120 other.setAutoPosition(q_ptr->isAutoPosition());
121 q_ptr->setDirty(false);
122 }
123}
124
125QT_END_NAMESPACE_DATAVISUALIZATION
126

source code of qtdatavis3d/src/datavisualization/engine/q3dlight.cpp