mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 15:29:32 +02:00
Cleanup, moving some QML objects to OffscreenUI
This commit is contained in:
parent
a883891197
commit
462cc325e5
5 changed files with 65 additions and 77 deletions
|
@ -692,8 +692,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
|
||||||
if (offscreenUi->navigationFocused()) {
|
if (offscreenUi->navigationFocused()) {
|
||||||
auto actionEnum = static_cast<Action>(action);
|
auto actionEnum = static_cast<Action>(action);
|
||||||
int key = Qt::Key_unknown;
|
int key = Qt::Key_unknown;
|
||||||
bool navAxis = false;
|
|
||||||
static int lastKey = Qt::Key_unknown;
|
static int lastKey = Qt::Key_unknown;
|
||||||
|
bool navAxis = false;
|
||||||
switch (actionEnum) {
|
switch (actionEnum) {
|
||||||
case Action::UI_NAV_VERTICAL:
|
case Action::UI_NAV_VERTICAL:
|
||||||
navAxis = true;
|
navAxis = true;
|
||||||
|
@ -732,16 +732,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
|
||||||
}
|
}
|
||||||
|
|
||||||
if (navAxis) {
|
if (navAxis) {
|
||||||
qDebug() << "Axis " << action << " value " << state;
|
|
||||||
if (lastKey != Qt::Key_unknown) {
|
if (lastKey != Qt::Key_unknown) {
|
||||||
qDebug() << "Releasing key " << lastKey;
|
|
||||||
QKeyEvent event(QEvent::KeyRelease, lastKey, Qt::NoModifier);
|
QKeyEvent event(QEvent::KeyRelease, lastKey, Qt::NoModifier);
|
||||||
sendEvent(offscreenUi->getWindow(), &event);
|
sendEvent(offscreenUi->getWindow(), &event);
|
||||||
lastKey = Qt::Key_unknown;
|
lastKey = Qt::Key_unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key != Qt::Key_unknown) {
|
if (key != Qt::Key_unknown) {
|
||||||
qDebug() << "Pressing key " << key;
|
|
||||||
QKeyEvent event(QEvent::KeyPress, key, Qt::NoModifier);
|
QKeyEvent event(QEvent::KeyPress, key, Qt::NoModifier);
|
||||||
sendEvent(offscreenUi->getWindow(), &event);
|
sendEvent(offscreenUi->getWindow(), &event);
|
||||||
lastKey = key;
|
lastKey = key;
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
|
|
||||||
using MouseTranslator = std::function<QPointF(const QPointF&)>;
|
using MouseTranslator = std::function<QPointF(const QPointF&)>;
|
||||||
|
|
||||||
void create(QOpenGLContext* context);
|
virtual void create(QOpenGLContext* context);
|
||||||
void resize(const QSize& size);
|
void resize(const QSize& size);
|
||||||
QSize size() const;
|
QSize size() const;
|
||||||
Q_INVOKABLE QObject* load(const QUrl& qmlSource, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {});
|
Q_INVOKABLE QObject* load(const QUrl& qmlSource, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {});
|
||||||
|
|
|
@ -9,10 +9,11 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
#include "OffscreenUi.h"
|
#include "OffscreenUi.h"
|
||||||
#include <QOpenGLDebugLogger>
|
|
||||||
#include <QQuickWindow>
|
#include <QtQml/QtQml>
|
||||||
#include <QGLWidget>
|
#include <QtQuick/QQuickWindow>
|
||||||
#include <QtQml>
|
|
||||||
|
#include <AccountManager.h>
|
||||||
#include "ErrorDialog.h"
|
#include "ErrorDialog.h"
|
||||||
#include "MessageDialog.h"
|
#include "MessageDialog.h"
|
||||||
|
|
||||||
|
@ -27,7 +28,52 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class OffscreenFlags : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(bool navigationFocused READ isNavigationFocused WRITE setNavigationFocused NOTIFY navigationFocusedChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
OffscreenFlags(QObject* parent = nullptr) : QObject(parent) {}
|
||||||
|
bool isNavigationFocused() const { return _navigationFocused; }
|
||||||
|
void setNavigationFocused(bool focused) {
|
||||||
|
if (_navigationFocused != focused) {
|
||||||
|
_navigationFocused = focused;
|
||||||
|
emit navigationFocusedChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void navigationFocusedChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool _navigationFocused { false };
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class UrlFixer : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE QString fixupUrl(const QString& originalUrl) {
|
||||||
|
static const QString ACCESS_TOKEN_PARAMETER = "access_token";
|
||||||
|
static const QString ALLOWED_HOST = "metaverse.highfidelity.com";
|
||||||
|
QString result = originalUrl;
|
||||||
|
QUrl url(originalUrl);
|
||||||
|
QUrlQuery query(url);
|
||||||
|
if (url.host() == ALLOWED_HOST && query.allQueryItemValues(ACCESS_TOKEN_PARAMETER).empty()) {
|
||||||
|
qDebug() << "Updating URL with auth token";
|
||||||
|
AccountManager& accountManager = AccountManager::getInstance();
|
||||||
|
query.addQueryItem(ACCESS_TOKEN_PARAMETER, accountManager.getAccountInfo().getAccessToken().token);
|
||||||
|
url.setQuery(query.query());
|
||||||
|
result = url.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static UrlFixer * urlFixer { nullptr };
|
||||||
|
static OffscreenFlags* offscreenFlags { nullptr };
|
||||||
|
|
||||||
// This hack allows the QML UI to work with keys that are also bound as
|
// This hack allows the QML UI to work with keys that are also bound as
|
||||||
// shortcuts at the application level. However, it seems as though the
|
// shortcuts at the application level. However, it seems as though the
|
||||||
|
@ -58,9 +104,15 @@ OffscreenUi::OffscreenUi() {
|
||||||
::qmlRegisterType<OffscreenUiRoot>("Hifi", 1, 0, "Root");
|
::qmlRegisterType<OffscreenUiRoot>("Hifi", 1, 0, "Root");
|
||||||
}
|
}
|
||||||
|
|
||||||
OffscreenUi::~OffscreenUi() {
|
void OffscreenUi::create(QOpenGLContext* context) {
|
||||||
}
|
OffscreenQmlSurface::create(context);
|
||||||
|
auto rootContext = getRootContext();
|
||||||
|
|
||||||
|
offscreenFlags = new OffscreenFlags();
|
||||||
|
rootContext->setContextProperty("offscreenFlags", offscreenFlags);
|
||||||
|
urlFixer = new UrlFixer();
|
||||||
|
rootContext->setContextProperty("urlFixer", urlFixer);
|
||||||
|
}
|
||||||
|
|
||||||
void OffscreenUi::show(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QObject*)> f) {
|
void OffscreenUi::show(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QObject*)> f) {
|
||||||
QQuickItem* item = getRootItem()->findChild<QQuickItem*>(name);
|
QQuickItem* item = getRootItem()->findChild<QQuickItem*>(name);
|
||||||
|
@ -139,47 +191,14 @@ void OffscreenUi::error(const QString& text) {
|
||||||
pDialog->setEnabled(true);
|
pDialog->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
OffscreenUi::ButtonCallback OffscreenUi::NO_OP_CALLBACK = [](QMessageBox::StandardButton) {};
|
OffscreenUi::ButtonCallback OffscreenUi::NO_OP_CALLBACK = [](QMessageBox::StandardButton) {};
|
||||||
|
|
||||||
static const char * const NAVIGATION_FOCUSED_PROPERTY = "NavigationFocused";
|
|
||||||
class OffscreenFlags : public QObject{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_PROPERTY(bool navigationFocused READ isNavigationFocused WRITE setNavigationFocused NOTIFY navigationFocusedChanged)
|
|
||||||
public:
|
|
||||||
OffscreenFlags(QObject* parent = nullptr) : QObject(parent) {}
|
|
||||||
bool isNavigationFocused() const { return _navigationFocused; }
|
|
||||||
void setNavigationFocused(bool focused) {
|
|
||||||
if (_navigationFocused != focused) {
|
|
||||||
_navigationFocused = focused;
|
|
||||||
emit navigationFocusedChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void navigationFocusedChanged();
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool _navigationFocused { false };
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
OffscreenFlags* getFlags(QQmlContext* context) {
|
|
||||||
static OffscreenFlags* offscreenFlags { nullptr };
|
|
||||||
if (!offscreenFlags) {
|
|
||||||
offscreenFlags = new OffscreenFlags(context);
|
|
||||||
context->setContextProperty("OffscreenFlags", offscreenFlags);
|
|
||||||
}
|
|
||||||
return offscreenFlags;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OffscreenUi::navigationFocused() {
|
bool OffscreenUi::navigationFocused() {
|
||||||
return getFlags(getRootContext())->isNavigationFocused();
|
return offscreenFlags->isNavigationFocused();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OffscreenUi::setNavigationFocused(bool focused) {
|
void OffscreenUi::setNavigationFocused(bool focused) {
|
||||||
getFlags(getRootContext())->setNavigationFocused(focused);
|
offscreenFlags->setNavigationFocused(focused);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "OffscreenUi.moc"
|
#include "OffscreenUi.moc"
|
||||||
|
|
|
@ -25,7 +25,7 @@ class OffscreenUi : public OffscreenQmlSurface, public Dependency {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OffscreenUi();
|
OffscreenUi();
|
||||||
virtual ~OffscreenUi();
|
virtual void create(QOpenGLContext* context) override;
|
||||||
void show(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {});
|
void show(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {});
|
||||||
void toggle(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {});
|
void toggle(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {});
|
||||||
bool shouldSwallowShortcut(QEvent* event);
|
bool shouldSwallowShortcut(QEvent* event);
|
||||||
|
|
|
@ -29,36 +29,10 @@
|
||||||
static const char* const URL_PROPERTY = "source";
|
static const char* const URL_PROPERTY = "source";
|
||||||
static const QRegExp HIFI_URL_PATTERN { "^hifi://" };
|
static const QRegExp HIFI_URL_PATTERN { "^hifi://" };
|
||||||
|
|
||||||
class UrlFixer : public QObject {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
Q_INVOKABLE QString fixupUrl(const QString& originalUrl) {
|
|
||||||
static const QString ACCESS_TOKEN_PARAMETER = "access_token";
|
|
||||||
static const QString ALLOWED_HOST = "metaverse.highfidelity.com";
|
|
||||||
QString result = originalUrl;
|
|
||||||
QUrl url(originalUrl);
|
|
||||||
QUrlQuery query(url);
|
|
||||||
if (url.host() == ALLOWED_HOST && query.allQueryItemValues(ACCESS_TOKEN_PARAMETER).empty()) {
|
|
||||||
qDebug() << "Updating URL with auth token";
|
|
||||||
AccountManager& accountManager = AccountManager::getInstance();
|
|
||||||
query.addQueryItem(ACCESS_TOKEN_PARAMETER, accountManager.getAccountInfo().getAccessToken().token);
|
|
||||||
url.setQuery(query.query());
|
|
||||||
result = url.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static UrlFixer URL_FIXER;
|
|
||||||
|
|
||||||
// Method called by Qt scripts to create a new web window in the overlay
|
// Method called by Qt scripts to create a new web window in the overlay
|
||||||
QScriptValue QmlWebWindowClass::constructor(QScriptContext* context, QScriptEngine* engine) {
|
QScriptValue QmlWebWindowClass::constructor(QScriptContext* context, QScriptEngine* engine) {
|
||||||
return QmlWindowClass::internalConstructor("QmlWebWindow.qml", context, engine,
|
return QmlWindowClass::internalConstructor("QmlWebWindow.qml", context, engine,
|
||||||
[&](QQmlContext* context, QObject* object) {
|
[&](QQmlContext* context, QObject* object) { return new QmlWebWindowClass(object); });
|
||||||
context->setContextProperty("urlFixer", &URL_FIXER);
|
|
||||||
return new QmlWebWindowClass(object);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlWebWindowClass::QmlWebWindowClass(QObject* qmlWindow) : QmlWindowClass(qmlWindow) {
|
QmlWebWindowClass::QmlWebWindowClass(QObject* qmlWindow) : QmlWindowClass(qmlWindow) {
|
||||||
|
@ -100,6 +74,4 @@ void QmlWebWindowClass::setURL(const QString& urlString) {
|
||||||
QMetaObject::invokeMethod(this, "setURL", Qt::QueuedConnection, Q_ARG(QString, urlString));
|
QMetaObject::invokeMethod(this, "setURL", Qt::QueuedConnection, Q_ARG(QString, urlString));
|
||||||
}
|
}
|
||||||
_qmlWindow->setProperty(URL_PROPERTY, urlString);
|
_qmlWindow->setProperty(URL_PROPERTY, urlString);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "QmlWebWindowClass.moc"
|
|
Loading…
Reference in a new issue