| 1 | // Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qabstractlight.h" |
| 5 | #include "qabstractlight_p.h" |
| 6 | |
| 7 | QT_BEGIN_NAMESPACE |
| 8 | |
| 9 | namespace Qt3DRender |
| 10 | { |
| 11 | |
| 12 | /*! |
| 13 | * \qmltype Light |
| 14 | * \inqmlmodule Qt3D.Render |
| 15 | * \nativetype Qt3DRender::QAbstractLight |
| 16 | * \brief Encapsulate a QAbstractLight object in a Qt 3D scene. |
| 17 | * \since 5.6 |
| 18 | */ |
| 19 | |
| 20 | QAbstractLightPrivate::QAbstractLightPrivate(QAbstractLight::Type type) |
| 21 | : m_type(type) |
| 22 | , m_shaderData(new QShaderData) |
| 23 | { |
| 24 | m_shaderData->setProperty(name: "type", value: type); |
| 25 | m_shaderData->setProperty(name: "color", value: QColor(Qt::white)); |
| 26 | m_shaderData->setProperty(name: "intensity", value: 0.5f); |
| 27 | } |
| 28 | |
| 29 | QAbstractLightPrivate::~QAbstractLightPrivate() |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | /*! |
| 34 | \qmlproperty enumeration Qt3D.Render::Light::type |
| 35 | \readonly |
| 36 | |
| 37 | Holds the particular type of light. |
| 38 | |
| 39 | \value Light.PointLight |
| 40 | A point light |
| 41 | \value Light.DirectionalLight |
| 42 | A directional light |
| 43 | \value Light.SpotLight |
| 44 | a spot light |
| 45 | */ |
| 46 | /*! |
| 47 | \property Qt3DRender::QAbstractLight::type |
| 48 | |
| 49 | The type of light. |
| 50 | */ |
| 51 | /*! |
| 52 | \enum Qt3DRender::QAbstractLight::Type |
| 53 | |
| 54 | Identifies the particular type of light. |
| 55 | |
| 56 | \value PointLight |
| 57 | \value DirectionalLight |
| 58 | \value SpotLight |
| 59 | */ |
| 60 | |
| 61 | /*! |
| 62 | \class Qt3DRender::QAbstractLight |
| 63 | \inmodule Qt3DRender |
| 64 | \brief Encapsulate a QAbstractLight object in a Qt 3D scene. |
| 65 | \since 5.6 |
| 66 | */ |
| 67 | |
| 68 | /*! \internal */ |
| 69 | QAbstractLight::QAbstractLight(QAbstractLightPrivate &dd, QNode *parent) |
| 70 | : QComponent(dd, parent) |
| 71 | { |
| 72 | Q_D(QAbstractLight); |
| 73 | d->m_shaderData->setParent(this); |
| 74 | } |
| 75 | |
| 76 | QAbstractLight::~QAbstractLight() |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | /*! |
| 81 | Holds the current QAbstractLight type. |
| 82 | */ |
| 83 | QAbstractLight::Type QAbstractLight::type() const |
| 84 | { |
| 85 | Q_D(const QAbstractLight); |
| 86 | return d->m_type; |
| 87 | } |
| 88 | |
| 89 | /*! |
| 90 | * \qmlproperty color Qt3D.Render.Light::color |
| 91 | * |
| 92 | * Holds the current Light color. |
| 93 | */ |
| 94 | /*! |
| 95 | * \property Qt3DRender::QAbstractLight::color |
| 96 | * |
| 97 | * Holds the current QAbstractLight color. |
| 98 | */ |
| 99 | QColor QAbstractLight::color() const |
| 100 | { |
| 101 | Q_D(const QAbstractLight); |
| 102 | return d->m_shaderData->property(name: "color").value<QColor>(); |
| 103 | } |
| 104 | |
| 105 | void QAbstractLight::setColor(const QColor &c) |
| 106 | { |
| 107 | Q_D(QAbstractLight); |
| 108 | if (color() != c) { |
| 109 | d->m_shaderData->setProperty(name: "color", value: c); |
| 110 | emit colorChanged(color: c); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /*! |
| 115 | \qmlproperty real Qt3D.Render.Light::intensity |
| 116 | |
| 117 | Holds the current Light intensity. |
| 118 | */ |
| 119 | /*! |
| 120 | \property Qt3DRender::QAbstractLight::intensity |
| 121 | |
| 122 | Holds the current QAbstractLight intensity. |
| 123 | */ |
| 124 | float QAbstractLight::intensity() const |
| 125 | { |
| 126 | Q_D(const QAbstractLight); |
| 127 | return d->m_shaderData->property(name: "intensity").toFloat(); |
| 128 | } |
| 129 | |
| 130 | void QAbstractLight::setIntensity(float value) |
| 131 | { |
| 132 | Q_D(QAbstractLight); |
| 133 | if (intensity() != value) { |
| 134 | d->m_shaderData->setProperty(name: "intensity", value); |
| 135 | emit intensityChanged(intensity: value); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | } // namespace Qt3DRender |
| 140 | |
| 141 | QT_END_NAMESPACE |
| 142 | |
| 143 | #include "moc_qabstractlight.cpp" |
| 144 |
