// // DesktopScriptingInterface.h // interface/src/scripting // // Created by David Rowe on 25 Aug 2015. // 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 // #ifndef hifi_DesktopScriptingInterface_h #define hifi_DesktopScriptingInterface_h #include #include #include #include "ui/InteractiveWindow.h" /**jsdoc * The Desktop API provides the dimensions of the computer screen, sets the opacity of the HUD surface, and * enables QML and HTML windows to be shown inside or outside of Interface. * * @namespace Desktop * * @hifi-interface * @hifi-client-entity * @hifi-avatar * * @property {number} width - The width of the computer screen including task bar and system menu, in pixels. * Read-only. * @property {number} height - The height of the computer screen including task bar and system menu, in pixels. * Read-only. * @property {InteractiveWindow.Flags} ALWAYS_ON_TOP - A flag value that makes an {@link InteractiveWindow} always display on * top. Read-only. * @property {InteractiveWindow.Flags} CLOSE_BUTTON_HIDES - A flag value that makes an {@link InteractiveWindow} hide instead * of closing when the user clicks the "close" button. Read-only. * @property {InteractiveWindow.PresentationModes} PresentationMode - The possible display options for an * {@link InteractiveWindow}: display inside Interface or in a separate desktop window. Read-only. * @property {InteractiveWindow.DockAreas} DockArea - The possible docking locations of an {@link InteractiveWindow}: top, * bottom, left, or right of the Interface window. * Read-only. * @property {InteractiveWindow.RelativePositionAnchors} RelativePositionAnchor - The possible "relative position anchors" for an {@link InteractiveWindow}: top left, * top right, bottom right, or bottom left of the Interface window. * Read-only. */ class DesktopScriptingInterface : public QObject, public Dependency { Q_OBJECT Q_PROPERTY(int width READ getWidth) // Physical width of screen(s) including task bars and system menus Q_PROPERTY(int height READ getHeight) // Physical height of screen(s) including task bars and system menus Q_PROPERTY(QVariantMap PresentationMode READ getPresentationMode CONSTANT FINAL) Q_PROPERTY(QVariantMap DockArea READ getDockArea CONSTANT FINAL) Q_PROPERTY(QVariantMap RelativePositionAnchor READ getRelativePositionAnchor CONSTANT FINAL) Q_PROPERTY(int ALWAYS_ON_TOP READ flagAlwaysOnTop CONSTANT FINAL) Q_PROPERTY(int CLOSE_BUTTON_HIDES READ flagCloseButtonHides CONSTANT FINAL) public: DesktopScriptingInterface(QObject* parent= nullptr, bool restricted = false); /**jsdoc * Sets the opacity of the HUD surface. * @function Desktop.setHUDAlpha * @param {number} alpha - The opacity, 0.0 – 1.0. */ Q_INVOKABLE void setHUDAlpha(float alpha); /**jsdoc * Opens a QML window within Interface: in the Interface window in desktop mode or on the HUD surface in HMD mode. If a * window of the specified name already exists, it is shown, otherwise a new window is created from the QML. * @function Desktop.show * @param {string} url - The QML file that specifies the window content. * @param {string} name - A unique name for the window. * @example Open the general settings dialog. * Desktop.show("hifi/dialogs/GeneralPreferencesDialog.qml", "GeneralPreferencesDialog"); */ Q_INVOKABLE void show(const QString& path, const QString& title); /**jsdoc * Creates a new window that can be displayed either within Interface or as a separate desktop window. * @function Desktop.createWindow * @param {string} url - The QML file that specifies the window content. The QML file can use a WebView * control (defined by "WebView.qml" included in the Interface install) to embed an HTML web page (complete with * EventBridge object). * @param {InteractiveWindow.Properties} [properties] - Initial window properties. * @returns {InteractiveWindow} A new window object. * @example Open a dialog in its own window separate from Interface. * var nativeWindow = Desktop.createWindow(Script.resourcesPath() + 'qml/OverlayWindowTest.qml', { * title: "Native Window", * presentationMode: Desktop.PresentationMode.NATIVE, * size: { x: 500, y: 400 } * }); * * Script.scriptEnding.connect(function () { * nativeWindow.close(); * }); */ Q_INVOKABLE InteractiveWindowPointer createWindow(const QString& sourceUrl, const QVariantMap& properties = QVariantMap()); int getWidth(); int getHeight(); private: static int flagAlwaysOnTop() { return AlwaysOnTop; } static int flagCloseButtonHides() { return CloseButtonHides; } Q_INVOKABLE InteractiveWindowPointer createWindowOnThread(const QString& sourceUrl, const QVariantMap& properties, QThread* targetThread); static QVariantMap getDockArea(); static QVariantMap getRelativePositionAnchor(); Q_INVOKABLE static QVariantMap getPresentationMode(); const bool _restricted; }; #endif // hifi_DesktopScriptingInterface_h