mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 13:03:55 +02:00
Merge pull request #4446 from huffman/marketplace-window
Marketplace window
This commit is contained in:
commit
641581a825
12 changed files with 92 additions and 33 deletions
|
@ -118,6 +118,10 @@ var importingSVOOverlay = Overlays.addOverlay("text", {
|
|||
visible: false,
|
||||
});
|
||||
|
||||
var MARKETPLACE_URL = "https://metaverse.highfidelity.io/marketplace";
|
||||
var marketplaceWindow = new WebWindow('Marketplace', MARKETPLACE_URL, 900, 700, false);
|
||||
marketplaceWindow.setVisible(false);
|
||||
|
||||
var toolBar = (function () {
|
||||
var that = {},
|
||||
toolBar,
|
||||
|
@ -322,7 +326,7 @@ var toolBar = (function () {
|
|||
return true;
|
||||
}
|
||||
if (browseModelsButton === toolBar.clicked(clickedOverlay)) {
|
||||
browseModelsButtonDown = true;
|
||||
marketplaceWindow.setVisible(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -897,6 +901,8 @@ function importSVO(importURL) {
|
|||
if (isActive) {
|
||||
selectionManager.setSelections(pastedEntityIDs);
|
||||
}
|
||||
|
||||
Window.raiseMainWindow();
|
||||
} else {
|
||||
Window.alert("There was an error importing the entity file.");
|
||||
}
|
||||
|
@ -1025,7 +1031,7 @@ PropertiesTool = function(opts) {
|
|||
var that = {};
|
||||
|
||||
var url = Script.resolvePath('html/entityProperties.html');
|
||||
var webView = new WebWindow('Entity Properties', url, 200, 280);
|
||||
var webView = new WebWindow('Entity Properties', url, 200, 280, true);
|
||||
|
||||
var visible = false;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ EntityListTool = function(opts) {
|
|||
var that = {};
|
||||
|
||||
var url = Script.resolvePath('html/entityList.html');
|
||||
var webView = new WebWindow('Entities', url, 200, 280);
|
||||
var webView = new WebWindow('Entities', url, 200, 280, true);
|
||||
|
||||
var visible = false;
|
||||
|
||||
|
|
|
@ -229,7 +229,7 @@ GridTool = function(opts) {
|
|||
var listeners = [];
|
||||
|
||||
var url = Script.resolvePath('html/gridControls.html');
|
||||
var webView = new WebWindow('Grid', url, 200, 280);
|
||||
var webView = new WebWindow('Grid', url, 200, 280, true);
|
||||
|
||||
horizontalGrid.addListener(function(data) {
|
||||
webView.eventBridge.emitScriptEvent(JSON.stringify(data));
|
||||
|
|
|
@ -873,6 +873,10 @@ void Application::controlledBroadcastToNodes(const QByteArray& packet, const Nod
|
|||
}
|
||||
}
|
||||
|
||||
void Application::importSVOFromURL(QUrl url) {
|
||||
emit svoImportRequested(url.url());
|
||||
}
|
||||
|
||||
bool Application::event(QEvent* event) {
|
||||
|
||||
// handle custom URL
|
||||
|
|
|
@ -216,6 +216,8 @@ public:
|
|||
float getFieldOfView() { return _fieldOfView.get(); }
|
||||
void setFieldOfView(float fov) { _fieldOfView.set(fov); }
|
||||
|
||||
void importSVOFromURL(QUrl url);
|
||||
|
||||
NodeToOctreeSceneStats* getOcteeSceneStats() { return &_octreeServerSceneStats; }
|
||||
void lockOctreeSceneStats() { _octreeSceneStatsLock.lockForRead(); }
|
||||
void unlockOctreeSceneStats() { _octreeSceneStatsLock.unlock(); }
|
||||
|
|
|
@ -18,8 +18,10 @@
|
|||
#include <QListWidget>
|
||||
|
||||
#include "Application.h"
|
||||
#include "WindowScriptingInterface.h"
|
||||
#include "ui/DataWebPage.h"
|
||||
#include "MainWindow.h"
|
||||
#include "WebWindowClass.h"
|
||||
#include "WindowScriptingInterface.h"
|
||||
|
||||
ScriptEventBridge::ScriptEventBridge(QObject* parent) : QObject(parent) {
|
||||
}
|
||||
|
@ -32,27 +34,47 @@ void ScriptEventBridge::emitScriptEvent(const QString& data) {
|
|||
emit scriptEventReceived(data);
|
||||
}
|
||||
|
||||
|
||||
WebWindowClass::WebWindowClass(const QString& title, const QString& url, int width, int height)
|
||||
WebWindowClass::WebWindowClass(const QString& title, const QString& url, int width, int height, bool isToolWindow)
|
||||
: QObject(NULL),
|
||||
_eventBridge(new ScriptEventBridge(this)) {
|
||||
_eventBridge(new ScriptEventBridge(this)),
|
||||
_isToolWindow(isToolWindow) {
|
||||
|
||||
ToolWindow* toolWindow = Application::getInstance()->getToolWindow();
|
||||
if (_isToolWindow) {
|
||||
ToolWindow* toolWindow = Application::getInstance()->getToolWindow();
|
||||
|
||||
_dockWidget = new QDockWidget(title, toolWindow);
|
||||
_dockWidget->setFeatures(QDockWidget::DockWidgetMovable);
|
||||
auto dockWidget = new QDockWidget(title, toolWindow);
|
||||
dockWidget->setFeatures(QDockWidget::DockWidgetMovable);
|
||||
|
||||
_webView = new QWebView(_dockWidget);
|
||||
_webView = new QWebView(dockWidget);
|
||||
addEventBridgeToWindowObject();
|
||||
|
||||
dockWidget->setWidget(_webView);
|
||||
|
||||
toolWindow->addDockWidget(Qt::RightDockWidgetArea, dockWidget);
|
||||
|
||||
_windowWidget = dockWidget;
|
||||
} else {
|
||||
_windowWidget = new QWidget(Application::getInstance()->getWindow(), Qt::Window);
|
||||
_windowWidget->setMinimumSize(width, height);
|
||||
|
||||
auto layout = new QVBoxLayout(_windowWidget);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
_windowWidget->setLayout(layout);
|
||||
|
||||
_webView = new QWebView(_windowWidget);
|
||||
|
||||
layout->addWidget(_webView);
|
||||
|
||||
addEventBridgeToWindowObject();
|
||||
}
|
||||
|
||||
_webView->setPage(new DataWebPage());
|
||||
_webView->setUrl(url);
|
||||
addEventBridgeToWindowObject();
|
||||
|
||||
_dockWidget->setWidget(_webView);
|
||||
|
||||
toolWindow->addDockWidget(Qt::RightDockWidgetArea, _dockWidget);
|
||||
|
||||
connect(this, &WebWindowClass::destroyed, _windowWidget, &QWidget::deleteLater);
|
||||
connect(_webView->page()->mainFrame(), &QWebFrame::javaScriptWindowObjectCleared,
|
||||
this, &WebWindowClass::addEventBridgeToWindowObject);
|
||||
connect(this, &WebWindowClass::destroyed, _dockWidget, &QWidget::deleteLater);
|
||||
}
|
||||
|
||||
WebWindowClass::~WebWindowClass() {
|
||||
|
@ -64,10 +86,14 @@ void WebWindowClass::addEventBridgeToWindowObject() {
|
|||
|
||||
void WebWindowClass::setVisible(bool visible) {
|
||||
if (visible) {
|
||||
QMetaObject::invokeMethod(
|
||||
Application::getInstance()->getToolWindow(), "setVisible", Qt::BlockingQueuedConnection, Q_ARG(bool, visible));
|
||||
if (_isToolWindow) {
|
||||
QMetaObject::invokeMethod(
|
||||
Application::getInstance()->getToolWindow(), "setVisible", Qt::BlockingQueuedConnection, Q_ARG(bool, visible));
|
||||
} else {
|
||||
QMetaObject::invokeMethod(_windowWidget, "raise", Qt::BlockingQueuedConnection);
|
||||
}
|
||||
}
|
||||
QMetaObject::invokeMethod(_dockWidget, "setVisible", Qt::BlockingQueuedConnection, Q_ARG(bool, visible));
|
||||
QMetaObject::invokeMethod(_windowWidget, "setVisible", Qt::BlockingQueuedConnection, Q_ARG(bool, visible));
|
||||
}
|
||||
|
||||
QScriptValue WebWindowClass::constructor(QScriptContext* context, QScriptEngine* engine) {
|
||||
|
@ -78,7 +104,8 @@ QScriptValue WebWindowClass::constructor(QScriptContext* context, QScriptEngine*
|
|||
Q_ARG(const QString&, file),
|
||||
Q_ARG(QString, context->argument(1).toString()),
|
||||
Q_ARG(int, context->argument(2).toInteger()),
|
||||
Q_ARG(int, context->argument(3).toInteger()));
|
||||
Q_ARG(int, context->argument(3).toInteger()),
|
||||
Q_ARG(bool, context->argument(4).toBool()));
|
||||
|
||||
connect(engine, &QScriptEngine::destroyed, retVal, &WebWindowClass::deleteLater);
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ class WebWindowClass : public QObject {
|
|||
Q_OBJECT
|
||||
Q_PROPERTY(QObject* eventBridge READ getEventBridge)
|
||||
public:
|
||||
WebWindowClass(const QString& title, const QString& url, int width, int height);
|
||||
WebWindowClass(const QString& title, const QString& url, int width, int height, bool isToolWindow = false);
|
||||
~WebWindowClass();
|
||||
|
||||
static QScriptValue constructor(QScriptContext* context, QScriptEngine* engine);
|
||||
|
@ -46,9 +46,10 @@ public slots:
|
|||
void addEventBridgeToWindowObject();
|
||||
|
||||
private:
|
||||
QDockWidget* _dockWidget;
|
||||
QWidget* _windowWidget;
|
||||
QWebView* _webView;
|
||||
ScriptEventBridge* _eventBridge;
|
||||
bool _isToolWindow;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -35,8 +35,8 @@ WindowScriptingInterface::WindowScriptingInterface() :
|
|||
connect(Application::getInstance(), &Application::svoImportRequested, this, &WindowScriptingInterface::svoImportRequested);
|
||||
}
|
||||
|
||||
WebWindowClass* WindowScriptingInterface::doCreateWebWindow(const QString& title, const QString& url, int width, int height) {
|
||||
return new WebWindowClass(title, url, width, height);
|
||||
WebWindowClass* WindowScriptingInterface::doCreateWebWindow(const QString& title, const QString& url, int width, int height, bool isToolWindow) {
|
||||
return new WebWindowClass(title, url, width, height, isToolWindow);
|
||||
}
|
||||
|
||||
QScriptValue WindowScriptingInterface::hasFocus() {
|
||||
|
@ -44,8 +44,13 @@ QScriptValue WindowScriptingInterface::hasFocus() {
|
|||
}
|
||||
|
||||
void WindowScriptingInterface::setFocus() {
|
||||
Application::getInstance()->getWindow()->activateWindow();
|
||||
Application::getInstance()->getWindow()->setFocus();
|
||||
auto window = Application::getInstance()->getWindow();
|
||||
window->activateWindow();
|
||||
window->setFocus();
|
||||
}
|
||||
|
||||
void WindowScriptingInterface::raiseMainWindow() {
|
||||
Application::getInstance()->getWindow()->raise();
|
||||
}
|
||||
|
||||
void WindowScriptingInterface::setCursorVisible(bool visible) {
|
||||
|
|
|
@ -43,6 +43,7 @@ public slots:
|
|||
void setCursorVisible(bool visible);
|
||||
QScriptValue hasFocus();
|
||||
void setFocus();
|
||||
void raiseMainWindow();
|
||||
QScriptValue alert(const QString& message = "");
|
||||
QScriptValue confirm(const QString& message = "");
|
||||
QScriptValue form(const QString& title, QScriptValue array);
|
||||
|
@ -83,7 +84,7 @@ private slots:
|
|||
void nonBlockingFormAccepted() { _nonBlockingFormActive = false; _formResult = QDialog::Accepted; emit nonBlockingFormClosed(); }
|
||||
void nonBlockingFormRejected() { _nonBlockingFormActive = false; _formResult = QDialog::Rejected; emit nonBlockingFormClosed(); }
|
||||
|
||||
WebWindowClass* doCreateWebWindow(const QString& title, const QString& url, int width, int height);
|
||||
WebWindowClass* doCreateWebWindow(const QString& title, const QString& url, int width, int height, bool isToolWindow);
|
||||
|
||||
private:
|
||||
QString jsRegExp2QtRegExp(QString string);
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include <qnetworkrequest.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include <AddressManager.h>
|
||||
#include <OAuthNetworkAccessManager.h>
|
||||
|
||||
|
@ -21,7 +22,7 @@ DataWebPage::DataWebPage(QObject* parent) :
|
|||
{
|
||||
// use an OAuthNetworkAccessManager instead of regular QNetworkAccessManager so our requests are authed
|
||||
setNetworkAccessManager(OAuthNetworkAccessManager::getInstance());
|
||||
|
||||
|
||||
// give the page an empty stylesheet
|
||||
settings()->setUserStyleSheetUrl(QUrl());
|
||||
}
|
||||
|
@ -31,8 +32,12 @@ void DataWebPage::javaScriptConsoleMessage(const QString& message, int lineNumbe
|
|||
}
|
||||
|
||||
bool DataWebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, QWebPage::NavigationType type) {
|
||||
|
||||
|
||||
if (!request.url().toString().startsWith(HIFI_URL_SCHEME)) {
|
||||
if (request.url().path().toLower().endsWith(SVO_EXTENSION)) {
|
||||
Application::getInstance()->importSVOFromURL(request.url());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// this is a hifi URL - have the AddressManager handle it
|
||||
|
@ -40,4 +45,8 @@ bool DataWebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkReques
|
|||
Qt::AutoConnection, Q_ARG(const QString&, request.url().toString()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString DataWebPage::userAgentForUrl(const QUrl & url) const {
|
||||
return INTERFACE_USER_AGENT;
|
||||
}
|
||||
|
|
|
@ -14,12 +14,15 @@
|
|||
|
||||
#include <qwebpage.h>
|
||||
|
||||
const QString INTERFACE_USER_AGENT = "HighFidelityInterface/1.0";
|
||||
|
||||
class DataWebPage : public QWebPage {
|
||||
public:
|
||||
DataWebPage(QObject* parent = 0);
|
||||
protected:
|
||||
void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID);
|
||||
bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, QWebPage::NavigationType type);
|
||||
virtual QString userAgentForUrl(const QUrl & url) const;
|
||||
};
|
||||
|
||||
#endif // hifi_DataWebPage_h
|
||||
#endif // hifi_DataWebPage_h
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <QThreadStorage>
|
||||
|
||||
#include "AccountManager.h"
|
||||
#include "LimitedNodeList.h"
|
||||
#include "SharedUtil.h"
|
||||
|
||||
#include "OAuthNetworkAccessManager.h"
|
||||
|
@ -32,7 +33,7 @@ QNetworkReply* OAuthNetworkAccessManager::createRequest(QNetworkAccessManager::O
|
|||
QIODevice* outgoingData) {
|
||||
AccountManager& accountManager = AccountManager::getInstance();
|
||||
|
||||
if (accountManager.hasValidAccessToken()) {
|
||||
if (accountManager.hasValidAccessToken() && req.url().host() == DEFAULT_NODE_AUTH_URL.host()) {
|
||||
QNetworkRequest authenticatedRequest(req);
|
||||
authenticatedRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
||||
authenticatedRequest.setRawHeader(ACCESS_TOKEN_AUTHORIZATION_HEADER,
|
||||
|
|
Loading…
Reference in a new issue