// // OffscreenUi.h // interface/src/entities // // Created by Bradley Austin Davis on 2015-07-17 // Copyright 2015 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #pragma once #ifndef hifi_OffscreenQmlElement_h #define hifi_OffscreenQmlElement_h #include class QQmlContext; #define HIFI_QML_DECL \ private: \ static const QString NAME; \ static const QUrl QML; \ public: \ static void registerType(); \ static void show(std::function f = [](QQmlContext*, QObject*) {}); \ static void hide(); \ static void toggle(std::function f = [](QQmlContext*, QObject*) {}); \ static void load(std::function f = [](QQmlContext*, QObject*) {}); \ private: #define HIFI_QML_DECL_LAMBDA \ protected: \ static const QString NAME; \ static const QUrl QML; \ public: \ static void registerType(); \ static void show(); \ static void hide(); \ static void toggle(); \ static void load(); \ private: #define HIFI_QML_DEF(x) \ const QUrl x::QML = QUrl(#x ".qml"); \ const QString x::NAME = #x; \ \ void x::registerType() { \ qmlRegisterType("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \ } \ \ void x::show(std::function f) { \ auto offscreenUi = DependencyManager::get(); \ offscreenUi->show(QML, NAME, f); \ } \ \ void x::hide() { \ auto offscreenUi = DependencyManager::get(); \ offscreenUi->hide(NAME); \ } \ \ void x::toggle(std::function f) { \ auto offscreenUi = DependencyManager::get(); \ offscreenUi->toggle(QML, NAME, f); \ } \ void x::load(std::function f) { \ auto offscreenUi = DependencyManager::get(); \ offscreenUi->load(QML, f); \ } #define HIFI_QML_DEF_LAMBDA(x, f) \ const QUrl x::QML = QUrl(#x ".qml"); \ const QString x::NAME = #x; \ \ void x::registerType() { \ qmlRegisterType("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \ } \ void x::show() { \ auto offscreenUi = DependencyManager::get(); \ offscreenUi->show(QML, NAME, f); \ } \ void x::hide() { \ auto offscreenUi = DependencyManager::get(); \ offscreenUi->hide(NAME); \ } \ \ void x::toggle() { \ auto offscreenUi = DependencyManager::get(); \ offscreenUi->toggle(QML, NAME, f); \ } \ void x::load() { \ auto offscreenUi = DependencyManager::get(); \ offscreenUi->load(QML, f); \ } #endif