HifiExperimentsfix some warningse6f462e2 years agoHistory
674 lines · 26.6 KB · C++
RawDownload
    }} void WindowScriptingInterface::displayAnnouncement(const QString& message) {    emit announcement(message);} bool WindowScriptingInterface::isPhysicsEnabled() {    return qApp->isPhysicsEnabled();} int WindowScriptingInterface::openMessageBox(QString title, QString text, int buttons, int defaultButton) {    if (QThread::currentThread() != thread()) {        int result;        BLOCKING_INVOKE_METHOD(this, "openMessageBox",            Q_RETURN_ARG(int, result),            Q_ARG(QString, title),            Q_ARG(QString, text),            Q_ARG(int, buttons),            Q_ARG(int, defaultButton));        return result;    }     return createMessageBox(title, text, buttons, defaultButton);} /*@jsdoc * <p>The buttons that may be included in a message box created by {@link Window.openMessageBox|openMessageBox} are defined by * numeric values: * <table> *   <thead> *     <tr> *       <th>Button</th> *       <th>Value</th> *       <th>Description</th> *     </tr> *   </thead> *   <tbody> *     <tr> <td><strong>NoButton</strong></td> <td><code>0x0</code></td> <td>An invalid button.</td> </tr> *     <tr> <td><strong>Ok</strong></td> <td><code>0x400</code></td> <td>"OK"</td> </tr> *     <tr> <td><strong>Save</strong></td> <td><code>0x800</code></td> <td>"Save"</td> </tr> *     <tr> <td><strong>SaveAll</strong></td> <td><code>0x1000</code></td> <td>"Save All"</td> </tr> *     <tr> <td><strong>Open</strong></td> <td><code>0x2000</code></td> <td>"Open"</td> </tr> *     <tr> <td><strong>Yes</strong></td> <td><code>0x4000</code></td> <td>"Yes"</td> </tr> *     <tr> <td><strong>YesToAll</strong></td> <td><code>0x8000</code></td> <td>"Yes to All"</td> </tr> *     <tr> <td><strong>No</strong></td> <td><code>0x10000</code></td> <td>"No"</td> </tr> *     <tr> <td><strong>NoToAll</strong></td> <td><code>0x20000</code></td> <td>"No to All"</td> </tr> *     <tr> <td><strong>Abort</strong></td> <td><code>0x40000</code></td> <td>"Abort"</td> </tr> *     <tr> <td><strong>Retry</strong></td> <td><code>0x80000</code></td> <td>"Retry"</td> </tr> *     <tr> <td><strong>Ignore</strong></td> <td><code>0x100000</code></td> <td>"Ignore"</td> </tr> *     <tr> <td><strong>Close</strong></td> <td><code>0x200000</code></td> <td>"Close"</td> </tr> *     <tr> <td><strong>Cancel</strong></td> <td><code>0x400000</code></td> <td>"Cancel"</td> </tr> *     <tr> <td><strong>Discard</strong></td> <td><code>0x800000</code></td> <td>"Discard" or "Don't Save"</td> </tr> *     <tr> <td><strong>Help</strong></td> <td><code>0x1000000</code></td> <td>"Help"</td> </tr> *     <tr> <td><strong>Apply</strong></td> <td><code>0x2000000</code></td> <td>"Apply"</td> </tr> *     <tr> <td><strong>Reset</strong></td> <td><code>0x4000000</code></td> <td>"Reset"</td> </tr> *     <tr> <td><strong>RestoreDefaults</strong></td> <td><code>0x8000000</code></td> <td>"Restore Defaults"</td> </tr> *   </tbody> * </table> * @typedef {number} Window.MessageBoxButton */int WindowScriptingInterface::createMessageBox(QString title, QString text, int buttons, int defaultButton) {    if (auto offscreenUI = DependencyManager::get<OffscreenUi>()) {        auto messageBox = offscreenUI->createMessageBox(OffscreenUi::ICON_INFORMATION, title, text,            static_cast<QFlags<QMessageBox::StandardButton>>(buttons), static_cast<QMessageBox::StandardButton>(defaultButton));        connect(messageBox, SIGNAL(selected(int)), this, SLOT(onMessageBoxSelected(int)));         _lastMessageBoxID += 1;        _messageBoxes.insert(_lastMessageBoxID, messageBox);    }     return _lastMessageBoxID;} void WindowScriptingInterface::updateMessageBox(int id, QString title, QString text, int buttons, int defaultButton) {    auto messageBox = _messageBoxes.value(id);    if (messageBox) {        if (QThread::currentThread() != thread()) {            QMetaObject::invokeMethod(this, "updateMessageBox",                Q_ARG(int, id),                Q_ARG(QString, title),                Q_ARG(QString, text),                Q_ARG(int, buttons),                Q_ARG(int, defaultButton));            return;        }         messageBox->setProperty("title", title);        messageBox->setProperty("text", text);        messageBox->setProperty("buttons", buttons);        messageBox->setProperty("defaultButton", defaultButton);    }} void WindowScriptingInterface::closeMessageBox(int id) {    auto messageBox = _messageBoxes.value(id);    if (messageBox) {        if (QThread::currentThread() != thread()) {            QMetaObject::invokeMethod(this, "closeMessageBox",                Q_ARG(int, id));            return;        }         disconnect(messageBox);        messageBox->setVisible(false);        messageBox->deleteLater();        _messageBoxes.remove(id);    }} void WindowScriptingInterface::onMessageBoxSelected(int button) {    auto messageBox = qobject_cast<QQuickItem*>(sender());    Q_ASSERT(messageBox != nullptr);    auto keys = _messageBoxes.keys(messageBox);    if (keys.length() > 0) {        auto id = keys[0];  // Should be just one message box.        emit messageBoxClosed(id, button);        disconnect(messageBox);        messageBox->setVisible(false);        messageBox->deleteLater();        _messageBoxes.remove(id);    }}  float WindowScriptingInterface::domainLoadingProgress() {    return qApp->getOctreePacketProcessor().domainLoadingProgress();} int WindowScriptingInterface::getDisplayPluginCount() {    return (int)PluginManager::getInstance()->getDisplayPlugins().size();} QString WindowScriptingInterface::getDisplayPluginName(int index) {    return PluginManager::getInstance()->getDisplayPlugins().at(index)->getName();} bool WindowScriptingInterface::isDisplayPluginHmd(int index) {    return PluginManager::getInstance()->getDisplayPlugins().at(index)->isHmd();} int WindowScriptingInterface::getActiveDisplayPlugin() {    auto active = qApp->getActiveDisplayPlugin();    auto size = getDisplayPluginCount();    for (int i = 0; i < size; ++i) {        if (PluginManager::getInstance()->getDisplayPlugins().at(i) == active) {            return i;        }    }    return -1;} void WindowScriptingInterface::setActiveDisplayPlugin(int index) {    auto name = PluginManager::getInstance()->getDisplayPlugins().at(index)->getName();    qApp->setActiveDisplayPlugin(name);} void WindowScriptingInterface::openWebBrowser(const QString& url) {    auto offscreenUI = DependencyManager::get<OffscreenUi>();    if (!offscreenUI) {        return;    }     if (QThread::currentThread() != thread()) {        QMetaObject::invokeMethod(this, "openWebBrowser", Q_ARG(const QString&, url));        return;    }     offscreenUI->load("Browser.qml", [=](QQmlContext* context, QObject* newObject) {        if (!url.isEmpty()) {            newObject->setProperty("url", url);        }    });}

Lines 501–674 of 674. Previous lines