1/****************************************************************************
2**
3** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
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 Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qabstractlight.h"
41#include "qabstractlight_p.h"
42
43QT_BEGIN_NAMESPACE
44
45namespace Qt3DRender
46{
47
48/*!
49 * \qmltype Light
50 * \inqmlmodule Qt3D.Render
51 * \instantiates Qt3DRender::QAbstractLight
52 * \brief Encapsulate a QAbstractLight object in a Qt 3D scene.
53 * \since 5.6
54 */
55
56QAbstractLightPrivate::QAbstractLightPrivate(QAbstractLight::Type type)
57 : m_type(type)
58 , m_shaderData(new QShaderData)
59{
60 m_shaderData->setProperty(name: "type", value: type);
61 m_shaderData->setProperty(name: "color", value: QColor(Qt::white));
62 m_shaderData->setProperty(name: "intensity", value: 0.5f);
63}
64
65QAbstractLightPrivate::~QAbstractLightPrivate()
66{
67}
68
69/*!
70 \qmlproperty enumeration Qt3D.Render::Light::type
71 \readonly
72
73 Holds the particular type of light.
74
75 \value Light.PointLight
76 A point light
77 \value Light.DirectionalLight
78 A directional light
79 \value Light.SpotLight
80 a spot light
81*/
82/*!
83 \property Qt3DRender::QAbstractLight::type
84
85 The type of light.
86*/
87/*!
88 \enum Qt3DRender::QAbstractLight::Type
89
90 Identifies the particular type of light.
91
92 \value PointLight
93 \value DirectionalLight
94 \value SpotLight
95*/
96Qt3DCore::QNodeCreatedChangeBasePtr QAbstractLight::createNodeCreationChange() const
97{
98 auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QAbstractLightData>::create(arguments: this);
99 auto &data = creationChange->data;
100 Q_D(const QAbstractLight);
101 data.shaderDataId = qIdForNode(node: d->m_shaderData);
102 return creationChange;
103}
104
105/*!
106 \class Qt3DRender::QAbstractLight
107 \inmodule Qt3DRender
108 \brief Encapsulate a QAbstractLight object in a Qt 3D scene.
109 \since 5.6
110*/
111
112/*! \internal */
113QAbstractLight::QAbstractLight(QAbstractLightPrivate &dd, QNode *parent)
114 : QComponent(dd, parent)
115{
116 Q_D(QAbstractLight);
117 d->m_shaderData->setParent(this);
118}
119
120QAbstractLight::~QAbstractLight()
121{
122}
123
124/*!
125 Holds the current QAbstractLight type.
126*/
127QAbstractLight::Type QAbstractLight::type() const
128{
129 Q_D(const QAbstractLight);
130 return d->m_type;
131}
132
133/*!
134 * \qmlproperty QColor Qt3D.Render.Light::color
135 *
136 * Holds the current Light color.
137 */
138/*!
139 * \property Qt3DRender::QAbstractLight::color
140 *
141 * Holds the current QAbstractLight color.
142 */
143QColor QAbstractLight::color() const
144{
145 Q_D(const QAbstractLight);
146 return d->m_shaderData->property(name: "color").value<QColor>();
147}
148
149void QAbstractLight::setColor(const QColor &c)
150{
151 Q_D(QAbstractLight);
152 if (color() != c) {
153 d->m_shaderData->setProperty(name: "color", value: c);
154 emit colorChanged(color: c);
155 }
156}
157
158/*!
159 \qmlproperty float Qt3D.Render.Light::intensity
160
161 Holds the current Light intensity.
162*/
163/*!
164 \property Qt3DRender::QAbstractLight::intensity
165
166 Holds the current QAbstractLight intensity.
167*/
168float QAbstractLight::intensity() const
169{
170 Q_D(const QAbstractLight);
171 return d->m_shaderData->property(name: "intensity").toFloat();
172}
173
174void QAbstractLight::setIntensity(float value)
175{
176 Q_D(QAbstractLight);
177 if (intensity() != value) {
178 d->m_shaderData->setProperty(name: "intensity", value);
179 emit intensityChanged(intensity: value);
180 }
181}
182
183} // namespace Qt3DRender
184
185QT_END_NAMESPACE
186

source code of qt3d/src/render/lights/qabstractlight.cpp