/**************************************************************************** ** ** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt 3D Studio. ** ** $QT_BEGIN_LICENSE:GPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3 or (at your option) any later version ** approved by the KDE Free Qt Foundation. The licenses are as published by ** the Free Software Foundation and appearing in the file LICENSE.GPL3 ** included in the packaging of this file. Please review the following ** information to ensure the GNU General Public License requirements will ** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "q3dspresentation_p.h" #include "q3dsengine_p.h" QT_BEGIN_NAMESPACE void Q3DSPresentationController::initializePresentationController(Q3DSEngine *engine, Q3DSPresentation *presentation) { m_pcEngine = engine; QObject::connect(engine, &Q3DSEngine::customSignalEmitted, engine, [engine, presentation](Q3DSGraphObject *obj, const QString &name) { emit presentation->customSignalEmitted(engine->makePath(obj), name); }); QObject::connect(engine, &Q3DSEngine::slideEntered, engine, [this, engine, presentation](Q3DSGraphObject *context, int index, const QString &name) { // A bit dodgy fix for QT3DS-3306 to make sure that calls to object visibility setters // before slide and animations are valid, are not overrun. This can happen when visibility // is set at presentationLoaded signal, but the change is lost when initializing the slide // object properties to values read from presentation file itself. QHashIterator iter(m_pendingVisibilityChanges); while (iter.hasNext()) { iter.next(); iter.key()->setProperty("eyeball", iter.value()); } m_pendingVisibilityChanges.clear(); emit presentation->slideEntered(engine->makePath(context), index, name); }); QObject::connect(engine, &Q3DSEngine::slideExited, engine, [engine, presentation](Q3DSGraphObject *context, int index, const QString &name) { emit presentation->slideExited(engine->makePath(context), index, name); }); // Setting a data input value needs a scenemanager. Therefore we must defer further. QObject::connect(engine, &Q3DSEngine::presentationLoaded, engine, [this]() { for (auto p : m_pendingDataInputSets) m_pcEngine->setDataInputValue(p.first, p.second); m_pendingDataInputSets.clear(); }); } void Q3DSPresentationController::handlePresentationKeyPressEvent(QKeyEvent *e) { if (m_pcEngine) m_pcEngine->handleKeyPressEvent(e); } void Q3DSPresentationController::handlePresentationKeyReleaseEvent(QKeyEvent *e) { if (m_pcEngine) m_pcEngine->handleKeyReleaseEvent(e); } void Q3DSPresentationController::handlePresentationMousePressEvent(QMouseEvent *e) { if (m_pcEngine) m_pcEngine->handleMousePressEvent(e); } void Q3DSPresentationController::handlePresentationMouseMoveEvent(QMouseEvent *e) { if (m_pcEngine) m_pcEngine->handleMouseMoveEvent(e); } void Q3DSPresentationController::handlePresentationMouseReleaseEvent(QMouseEvent *e) { if (m_pcEngine) m_pcEngine->handleMouseReleaseEvent(e); } void Q3DSPresentationController::handlePresentationMouseDoubleClickEvent(QMouseEvent *e) { if (m_pcEngine) m_pcEngine->handleMouseDoubleClickEvent(e); } #if QT_CONFIG(wheelevent) void Q3DSPresentationController::handlePresentationWheelEvent(QWheelEvent *e) { if (m_pcEngine) m_pcEngine->handleWheelEvent(e); } #endif void Q3DSPresentationController::handlePresentationTouchEvent(QTouchEvent *e) { if (m_pcEngine) m_pcEngine->handleTouchEvent(e); } #if QT_CONFIG(tabletevent) void Q3DSPresentationController::handlePresentationTabletEvent(QTabletEvent *e) { if (m_pcEngine) m_pcEngine->handleTabletEvent(e); } #endif void Q3DSPresentationController::handleDataInputValue(const QString &name, const QVariant &value) { if (m_pcEngine) m_pcEngine->setDataInputValue(name, value); else m_pendingDataInputSets.append({ name, value }); // defer to initializePresentationController } QVector Q3DSPresentationController::handleGetDataInputs() const { if (m_pcEngine) return m_pcEngine->dataInputs(); else return {}; } QVector Q3DSPresentationController::handleGetDataInputs( const QVariant &metadataKey) const { if (m_pcEngine) return m_pcEngine->dataInputs(metadataKey); else return {}; } bool Q3DSPresentationController::handleIsValidDataInput(const Q3DSDataInput *di) const { if (m_pcEngine) return m_pcEngine->isValidDataInput(di); else return false; } QVariant Q3DSPresentationController::handleDataInputMetaData( const Q3DSDataInput *di, const QVariant &key) const { if (m_pcEngine) return m_pcEngine->dataInputMetaData(di, key); else return {}; } QList Q3DSPresentationController::handleDataInputMetaDataKeys( const Q3DSDataInput *di) const { if (m_pcEngine) return m_pcEngine->dataInputMetaDataKeys(di); else return {}; } void Q3DSPresentationController::handleFireEvent(const QString &elementPath, const QString &eventName) { if (!m_pcEngine) return; // Assume that the path is in the main presentation when no explicit // presentation is specified in the path. Q3DSUipPresentation *pres = m_pcEngine->presentation(0); Q3DSGraphObject *target = m_pcEngine->findObjectByHashIdOrNameOrPath(nullptr, pres, elementPath, &pres); // pres is now the actual presentation (which is important to know // since the event queuing needs the scenemanager). if (target) m_pcEngine->fireEvent(target, pres, eventName); } void Q3DSPresentationController::handleGoToTime(const QString &elementPath, float timeSeconds) { if (!m_pcEngine) return; Q3DSUipPresentation *pres = m_pcEngine->presentation(0); Q3DSGraphObject *context = m_pcEngine->findObjectByHashIdOrNameOrPath(nullptr, pres, elementPath, &pres); if (context) m_pcEngine->goToTime(context, pres, timeSeconds * 1000); } void Q3DSPresentationController::handleGoToSlideByName(const QString &elementPath, const QString &name) { if (!m_pcEngine) return; Q3DSUipPresentation *pres = m_pcEngine->presentation(0); Q3DSGraphObject *context = m_pcEngine->findObjectByHashIdOrNameOrPath(nullptr, pres, elementPath, &pres); if (context) m_pcEngine->goToSlideByName(context, pres, name); } void Q3DSPresentationController::handleGoToSlideByIndex(const QString &elementPath, int index) { if (!m_pcEngine) return; Q3DSUipPresentation *pres = m_pcEngine->presentation(0); Q3DSGraphObject *context = m_pcEngine->findObjectByHashIdOrNameOrPath(nullptr, pres, elementPath, &pres); if (context) m_pcEngine->goToSlideByIndex(context, pres, index); } void Q3DSPresentationController::handleGoToSlideByDirection(const QString &elementPath, bool next, bool wrap) { if (!m_pcEngine) return; Q3DSUipPresentation *pres = m_pcEngine->presentation(0); Q3DSGraphObject *context = m_pcEngine->findObjectByHashIdOrNameOrPath(nullptr, pres, elementPath, &pres); if (context) m_pcEngine->goToSlideByDirection(context, pres, next, wrap); } QVariant Q3DSPresentationController::handleGetAttribute(const QString &elementPath, const QString &attribute) { if (!m_pcEngine) return QVariant(); Q3DSGraphObject *obj = m_pcEngine->findObjectByHashIdOrNameOrPath(nullptr, m_pcEngine->presentation(0), elementPath); if (!obj) { qWarning("No such object %s", qPrintable(elementPath)); return QVariant(); } return obj->property(attribute.toLatin1()); } void Q3DSPresentationController::handleSetAttribute(const QString &elementPath, const QString &attributeName, const QVariant &value) { if (!m_pcEngine) return; Q3DSGraphObject *obj = m_pcEngine->findObjectByHashIdOrNameOrPath(nullptr, m_pcEngine->presentation(0), elementPath); if (!obj) { qWarning("No such object %s", qPrintable(elementPath)); return; } // this handles QVector2D and QVector3D as expected for vec2 and vec3 properties Q3DSPropertyChangeList cl { Q3DSPropertyChange::fromVariant(attributeName, value) }; // Capture visibility changes incoming when slide system is not ready. if ((attributeName == QLatin1String("eyeball") || attributeName == QLatin1String("visible")) && !m_pcEngine->isAnimatorsReady()) { m_pendingVisibilityChanges.insert(obj, value.toString() == QLatin1String("true")); } obj->applyPropertyChanges(cl); obj->notifyPropertyChanges(cl); } void Q3DSPresentationController::handleSetProfileUiVisible(bool visible, float scale) { if (m_pcEngine) { m_pcEngine->setProfileUiVisible(visible); m_pcEngine->configureProfileUi(scale); } } bool Q3DSPresentationController::compareElementPath(const QString &a, const QString &b) const { if (!m_pcEngine) return false; Q3DSUipPresentation *defaultPresentation = m_pcEngine->presentation(0); const Q3DSGraphObject *objA = m_pcEngine->findObjectByHashIdOrNameOrPath(nullptr, defaultPresentation, a); const Q3DSGraphObject *objB = m_pcEngine->findObjectByHashIdOrNameOrPath(nullptr, defaultPresentation, b); return objA == objB; } void Q3DSPresentationController::handleSetDelayedLoading(bool enable) { if (m_pcEngine) m_pcEngine->setDelayedLoading(enable); } void Q3DSPresentationController::handlePreloadSlide(const QString &elementPath) { if (m_pcEngine) { Q3DSUipPresentation *pres = m_pcEngine->presentation(0); Q3DSGraphObject *context = m_pcEngine->findObjectByHashIdOrNameOrPath(nullptr, pres, elementPath, &pres); if (!context || context->type() != Q3DSGraphObject::Slide) return; Q3DSSlide *slide = static_cast(context); m_pcEngine->preloadSlide(slide, pres); } } void Q3DSPresentationController::handleUnloadSlide(const QString &elementPath) { if (m_pcEngine) { Q3DSUipPresentation *pres = m_pcEngine->presentation(0); Q3DSGraphObject *context = m_pcEngine->findObjectByHashIdOrNameOrPath(nullptr, pres, elementPath, &pres); if (!context || context->type() != Q3DSGraphObject::Slide) return; Q3DSSlide *slide = static_cast(context); m_pcEngine->unloadSlide(slide, pres); } } QT_END_NAMESPACE