mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 02:24:58 +02:00
Merge pull request #9639 from hyperlogic/feature/tablet-pal
Ported PAL to tablet
This commit is contained in:
commit
2ec4f118fd
9 changed files with 158 additions and 24 deletions
interface
libraries
fbx/src
gl/src/gl
script-engine/src
scripts/system
|
@ -16,6 +16,8 @@ import QtQuick.Controls 1.4
|
|||
import "../styles-uit"
|
||||
import "../controls-uit" as HifiControls
|
||||
|
||||
// references HMD, Users, UserActivityLogger from root context
|
||||
|
||||
Rectangle {
|
||||
id: pal
|
||||
// Size
|
||||
|
@ -26,7 +28,7 @@ Rectangle {
|
|||
// Properties
|
||||
property int myCardHeight: 90
|
||||
property int rowHeight: 70
|
||||
property int actionButtonWidth: 75
|
||||
property int actionButtonWidth: 55
|
||||
property int nameCardWidth: palContainer.width - actionButtonWidth*(iAmAdmin ? 4 : 2) - 4 - hifi.dimensions.scrollbarBackgroundWidth
|
||||
property var myData: ({displayName: "", userName: "", audioLevel: 0.0, admin: true}) // valid dummy until set
|
||||
property var ignored: ({}); // Keep a local list of ignored avatars & their data. Necessary because HashMap is slow to respond after ignoring.
|
||||
|
@ -35,7 +37,9 @@ Rectangle {
|
|||
// Keep a local list of per-avatar gainSliderValueDBs. Far faster than fetching this data from the server.
|
||||
// NOTE: if another script modifies the per-avatar gain, this value won't be accurate!
|
||||
property var gainSliderValueDB: ({});
|
||||
|
||||
|
||||
HifiConstants { id: hifi }
|
||||
|
||||
// The letterbox used for popup messages
|
||||
LetterboxMessage {
|
||||
id: letterboxMessage
|
||||
|
@ -54,8 +58,8 @@ Rectangle {
|
|||
property bool punctuationMode: false
|
||||
id: palContainer
|
||||
// Size
|
||||
width: pal.width - 50
|
||||
height: pal.height - 50
|
||||
width: pal.width - 10
|
||||
height: pal.height - 10
|
||||
// Style
|
||||
color: pal.color
|
||||
// Anchors
|
||||
|
@ -397,7 +401,7 @@ Rectangle {
|
|||
width: 20
|
||||
height: 28
|
||||
anchors.right: adminTab.right
|
||||
anchors.rightMargin: 31 + hifi.dimensions.scrollbarBackgroundWidth
|
||||
anchors.rightMargin: 10 + hifi.dimensions.scrollbarBackgroundWidth
|
||||
anchors.top: adminTab.top
|
||||
anchors.topMargin: 2
|
||||
RalewayRegular {
|
||||
|
@ -422,6 +426,8 @@ Rectangle {
|
|||
onExited: adminHelpText.color = hifi.colors.redHighlight
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HifiControls.Keyboard {
|
||||
id: keyboard
|
||||
raised: myCard.currentlyEditingDisplayName && HMD.active
|
||||
|
@ -432,7 +438,7 @@ Rectangle {
|
|||
right: parent.right
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Timer used when selecting table rows that aren't yet present in the model
|
||||
// (i.e. when selecting avatars using edit.js or sphere overlays)
|
||||
Timer {
|
||||
|
|
|
@ -18,6 +18,16 @@ Item {
|
|||
loader.item.scriptURL = injectedJavaScriptUrl;
|
||||
}
|
||||
|
||||
// used to send a message from qml to interface script.
|
||||
signal sendToScript(var message);
|
||||
|
||||
// used to receive messages from interface script
|
||||
function fromScript(message) {
|
||||
if (loader.item.hasOwnProperty("fromScript")) {
|
||||
loader.item.fromScript(message);
|
||||
}
|
||||
}
|
||||
|
||||
SoundEffect {
|
||||
id: buttonClickSound
|
||||
volume: 0.1
|
||||
|
@ -55,6 +65,9 @@ Item {
|
|||
}
|
||||
});
|
||||
}
|
||||
if (loader.item.hasOwnProperty("sendToScript")) {
|
||||
loader.item.sendToScript.connect(tabletRoot.sendToScript);
|
||||
}
|
||||
loader.item.forceActiveFocus();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,11 +23,14 @@
|
|||
#include <DependencyManager.h>
|
||||
#include <GeometryCache.h>
|
||||
#include <GeometryUtil.h>
|
||||
#include <scripting/HMDScriptingInterface.h>
|
||||
#include <gl/OffscreenQmlSurface.h>
|
||||
#include <PathUtils.h>
|
||||
#include <RegisteredMetaTypes.h>
|
||||
#include <TabletScriptingInterface.h>
|
||||
#include <TextureCache.h>
|
||||
#include <UsersScriptingInterface.h>
|
||||
#include <UserActivityLoggerScriptingInterface.h>
|
||||
#include <AbstractViewStateInterface.h>
|
||||
#include <gl/OffscreenQmlSurface.h>
|
||||
#include <gl/OffscreenQmlSurfaceCache.h>
|
||||
|
@ -149,6 +152,10 @@ void Web3DOverlay::loadSourceURL() {
|
|||
_webSurface->load(_url, [&](QQmlContext* context, QObject* obj) {});
|
||||
_webSurface->resume();
|
||||
|
||||
_webSurface->getRootContext()->setContextProperty("Users", DependencyManager::get<UsersScriptingInterface>().data());
|
||||
_webSurface->getRootContext()->setContextProperty("HMD", DependencyManager::get<HMDScriptingInterface>().data());
|
||||
_webSurface->getRootContext()->setContextProperty("UserActivityLogger", DependencyManager::get<UserActivityLoggerScriptingInterface>().data());
|
||||
|
||||
if (_webSurface->getRootItem() && _webSurface->getRootItem()->objectName() == "tabletRoot") {
|
||||
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
|
||||
auto flags = tabletScriptingInterface->getFlags();
|
||||
|
|
|
@ -62,7 +62,9 @@ template<class T> QVariant readBinaryArray(QDataStream& in, int& position) {
|
|||
position += sizeof(T) * arrayLength;
|
||||
in.readRawData(arrayData.data(), arrayData.size());
|
||||
}
|
||||
memcpy(&values[0], arrayData.constData(), arrayData.size());
|
||||
if (arrayData.size() > 0) {
|
||||
memcpy(&values[0], arrayData.constData(), arrayData.size());
|
||||
}
|
||||
} else {
|
||||
values.reserve(arrayLength);
|
||||
const unsigned int DEFLATE_ENCODING = 1;
|
||||
|
|
|
@ -604,6 +604,9 @@ QObject* OffscreenQmlSurface::finishQmlLoad(std::function<void(QQmlContext*, QOb
|
|||
qFatal("Could not load object as root item");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
connect(newItem, SIGNAL(sendToScript(QVariant)), this, SIGNAL(fromQml(QVariant)));
|
||||
|
||||
// The root item is ready. Associate it with the window.
|
||||
_rootItem = newItem;
|
||||
_rootItem->setParentItem(_quickWindow->contentItem());
|
||||
|
@ -952,4 +955,13 @@ void OffscreenQmlSurface::emitWebEvent(const QVariant& message) {
|
|||
}
|
||||
}
|
||||
|
||||
void OffscreenQmlSurface::sendToQml(const QVariant& message) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "emitQmlEvent", Qt::QueuedConnection, Q_ARG(QVariant, message));
|
||||
} else if (_rootItem) {
|
||||
// call fromScript method on qml root
|
||||
QMetaObject::invokeMethod(_rootItem, "fromScript", Qt::QueuedConnection, Q_ARG(QVariant, message));
|
||||
}
|
||||
}
|
||||
|
||||
#include "OffscreenQmlSurface.moc"
|
||||
|
|
|
@ -107,6 +107,11 @@ signals:
|
|||
void scriptEventReceived(const QVariant& message);
|
||||
void webEventReceived(const QVariant& message);
|
||||
|
||||
// qml event bridge
|
||||
public slots:
|
||||
void sendToQml(const QVariant& message);
|
||||
signals:
|
||||
void fromQml(QVariant message);
|
||||
|
||||
protected:
|
||||
bool filterEnabled(QObject* originalDestination, QEvent* event) const;
|
||||
|
|
|
@ -183,6 +183,18 @@ void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot, QObject* qmlOffscr
|
|||
_qmlTabletRoot = qmlTabletRoot;
|
||||
if (_qmlTabletRoot && _qmlOffscreenSurface) {
|
||||
QObject::connect(_qmlOffscreenSurface, SIGNAL(webEventReceived(QVariant)), this, SIGNAL(webEventReceived(QVariant)));
|
||||
|
||||
// forward qml surface events to interface js
|
||||
connect(dynamic_cast<OffscreenQmlSurface*>(_qmlOffscreenSurface), &OffscreenQmlSurface::fromQml, [this](QVariant message) {
|
||||
if (message.canConvert<QJSValue>()) {
|
||||
emit fromQml(qvariant_cast<QJSValue>(message).toVariant());
|
||||
} else if (message.canConvert<QString>()) {
|
||||
emit fromQml(message.toString());
|
||||
} else {
|
||||
qWarning() << "fromQml: Unsupported message type " << message;
|
||||
}
|
||||
});
|
||||
|
||||
gotoHomeScreen();
|
||||
|
||||
QMetaObject::invokeMethod(_qmlTabletRoot, "setUsername", Q_ARG(const QVariant&, QVariant(getUsername())));
|
||||
|
@ -197,6 +209,7 @@ void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot, QObject* qmlOffscr
|
|||
} else {
|
||||
removeButtonsFromHomeScreen();
|
||||
_state = State::Uninitialized;
|
||||
emit screenChanged(QVariant("Closed"), QVariant(""));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,10 +221,21 @@ void TabletProxy::gotoMenuScreen() {
|
|||
QObject::connect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToMenuScreen()), Qt::DirectConnection);
|
||||
QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(VRMENU_SOURCE_URL)));
|
||||
_state = State::Menu;
|
||||
emit screenChanged(QVariant("Menu"), QVariant(VRMENU_SOURCE_URL));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TabletProxy::loadQMLSource(const QVariant& path) {
|
||||
if (_qmlTabletRoot) {
|
||||
if (_state != State::QML) {
|
||||
removeButtonsFromHomeScreen();
|
||||
QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, path));
|
||||
_state = State::QML;
|
||||
emit screenChanged(QVariant("QML"), path);
|
||||
}
|
||||
}
|
||||
}
|
||||
void TabletProxy::gotoHomeScreen() {
|
||||
if (_qmlTabletRoot) {
|
||||
if (_state != State::Home) {
|
||||
|
@ -220,6 +244,7 @@ void TabletProxy::gotoHomeScreen() {
|
|||
QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(TABLET_SOURCE_URL)));
|
||||
QMetaObject::invokeMethod(_qmlTabletRoot, "playButtonClickSound");
|
||||
_state = State::Home;
|
||||
emit screenChanged(QVariant("Home"), QVariant(TABLET_SOURCE_URL));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -236,6 +261,7 @@ void TabletProxy::gotoWebScreen(const QString& url, const QString& injectedJavaS
|
|||
if (_state != State::Web) {
|
||||
QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(WEB_VIEW_SOURCE_URL)));
|
||||
_state = State::Web;
|
||||
emit screenChanged(QVariant("Web"), QVariant(url));
|
||||
}
|
||||
QMetaObject::invokeMethod(_qmlTabletRoot, "loadWebUrl", Q_ARG(const QVariant&, QVariant(url)),
|
||||
Q_ARG(const QVariant&, QVariant(injectedJavaScriptUrl)));
|
||||
|
@ -298,6 +324,12 @@ void TabletProxy::emitScriptEvent(QVariant msg) {
|
|||
}
|
||||
}
|
||||
|
||||
void TabletProxy::sendToQml(QVariant msg) {
|
||||
if (_qmlOffscreenSurface) {
|
||||
QMetaObject::invokeMethod(_qmlOffscreenSurface, "sendToQml", Qt::AutoConnection, Q_ARG(QVariant, msg));
|
||||
}
|
||||
}
|
||||
|
||||
void TabletProxy::addButtonsToHomeScreen() {
|
||||
auto tablet = getQmlTablet();
|
||||
if (!tablet) {
|
||||
|
|
|
@ -89,6 +89,8 @@ public:
|
|||
Q_INVOKABLE void gotoWebScreen(const QString& url);
|
||||
Q_INVOKABLE void gotoWebScreen(const QString& url, const QString& injectedJavaScriptUrl);
|
||||
|
||||
Q_INVOKABLE void loadQMLSource(const QVariant& path);
|
||||
|
||||
/**jsdoc
|
||||
* Creates a new button, adds it to this and returns it.
|
||||
* @function TabletProxy#addButton
|
||||
|
@ -120,6 +122,13 @@ public:
|
|||
*/
|
||||
Q_INVOKABLE void emitScriptEvent(QVariant msg);
|
||||
|
||||
/**jsdoc
|
||||
* Used to send an event to the qml embedded in the tablet
|
||||
* @function TabletProxy#sendToQml
|
||||
* @param msg {object|string}
|
||||
*/
|
||||
Q_INVOKABLE void sendToQml(QVariant msg);
|
||||
|
||||
Q_INVOKABLE bool onHomeScreen();
|
||||
|
||||
QObject* getTabletSurface();
|
||||
|
@ -137,6 +146,22 @@ signals:
|
|||
*/
|
||||
void webEventReceived(QVariant msg);
|
||||
|
||||
/**jsdoc
|
||||
* Signaled when this tablet receives an event from the qml embedded in the tablet
|
||||
* @function TabletProxy#fromQml
|
||||
* @param msg {object|string}
|
||||
* @returns {Signal}
|
||||
*/
|
||||
void fromQml(QVariant msg);
|
||||
|
||||
/**jsdoc
|
||||
* Signales when this tablet screen changes.
|
||||
* @function TabletProxy#screenChanged
|
||||
* @param type {string} - "Home", "Web", "Menu", "QML", "Closed"
|
||||
* @param url {string} - only valid for Web and QML.
|
||||
*/
|
||||
void screenChanged(QVariant type, QVariant url);
|
||||
|
||||
private slots:
|
||||
void addButtonsToHomeScreen();
|
||||
void addButtonsToMenuScreen();
|
||||
|
@ -149,7 +174,7 @@ protected:
|
|||
QQuickItem* _qmlTabletRoot { nullptr };
|
||||
QObject* _qmlOffscreenSurface { nullptr };
|
||||
|
||||
enum class State { Uninitialized, Home, Web, Menu };
|
||||
enum class State { Uninitialized, Home, Web, Menu, QML };
|
||||
State _state { State::Uninitialized };
|
||||
};
|
||||
|
||||
|
|
|
@ -203,8 +203,7 @@ var pal = new OverlayWindow({
|
|||
height: 640,
|
||||
visible: false
|
||||
});
|
||||
pal.fromQml.connect(function (message) { // messages are {method, params}, like json-rpc. See also sendToQml.
|
||||
print('From PAL QML:', JSON.stringify(message));
|
||||
function fromQml(message) { // messages are {method, params}, like json-rpc. See also sendToQml.
|
||||
switch (message.method) {
|
||||
case 'selected':
|
||||
selectedIds = message.params;
|
||||
|
@ -259,7 +258,15 @@ pal.fromQml.connect(function (message) { // messages are {method, params}, like
|
|||
default:
|
||||
print('Unrecognized message from Pal.qml:', JSON.stringify(message));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function sendToQml(message) {
|
||||
if (Settings.getValue("HUDUIEnabled")) {
|
||||
pal.sendToQml(message);
|
||||
} else {
|
||||
tablet.sendToQml(message);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Main operations.
|
||||
|
@ -298,10 +305,10 @@ function populateUserList(selectData) {
|
|||
data.push(avatarPalDatum);
|
||||
print('PAL data:', JSON.stringify(avatarPalDatum));
|
||||
});
|
||||
pal.sendToQml({ method: 'users', params: data });
|
||||
sendToQml({ method: 'users', params: data });
|
||||
if (selectData) {
|
||||
selectData[2] = true;
|
||||
pal.sendToQml({ method: 'select', params: selectData });
|
||||
sendToQml({ method: 'select', params: selectData });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,7 +329,7 @@ function usernameFromIDReply(id, username, machineFingerprint, isAdmin) {
|
|||
}
|
||||
print('Username Data:', JSON.stringify(data));
|
||||
// Ship the data off to QML
|
||||
pal.sendToQml({ method: 'updateUsername', params: data });
|
||||
sendToQml({ method: 'updateUsername', params: data });
|
||||
}
|
||||
|
||||
var pingPong = true;
|
||||
|
@ -396,7 +403,7 @@ function handleClick(pickRay) {
|
|||
ExtendedOverlay.applyPickRay(pickRay, function (overlay) {
|
||||
// Don't select directly. Tell qml, who will give us back a list of ids.
|
||||
var message = {method: 'select', params: [[overlay.key], !overlay.selected, false]};
|
||||
pal.sendToQml(message);
|
||||
sendToQml(message);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
@ -492,6 +499,7 @@ if (Settings.getValue("HUDUIEnabled")) {
|
|||
visible: true,
|
||||
alpha: 0.9
|
||||
});
|
||||
pal.fromQml.connect(fromQml);
|
||||
} else {
|
||||
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||
button = tablet.addButton({
|
||||
|
@ -499,7 +507,9 @@ if (Settings.getValue("HUDUIEnabled")) {
|
|||
icon: "icons/tablet-icons/people-i.svg",
|
||||
sortOrder: 7
|
||||
});
|
||||
tablet.fromQml.connect(fromQml);
|
||||
}
|
||||
|
||||
var isWired = false;
|
||||
var audioTimer;
|
||||
var AUDIO_LEVEL_UPDATE_INTERVAL_MS = 100; // 10hz for now (change this and change the AVERAGING_RATIO too)
|
||||
|
@ -518,10 +528,26 @@ function off() {
|
|||
Users.requestsDomainListData = false;
|
||||
}
|
||||
function onClicked() {
|
||||
if (!pal.visible) {
|
||||
if (Settings.getValue("HUDUIEnabled")) {
|
||||
if (!pal.visible) {
|
||||
Users.requestsDomainListData = true;
|
||||
populateUserList();
|
||||
pal.raise();
|
||||
isWired = true;
|
||||
Script.update.connect(updateOverlays);
|
||||
Controller.mousePressEvent.connect(handleMouseEvent);
|
||||
Controller.mouseMoveEvent.connect(handleMouseMoveEvent);
|
||||
triggerMapping.enable();
|
||||
triggerPressMapping.enable();
|
||||
audioTimer = createAudioInterval(conserveResources ? AUDIO_LEVEL_CONSERVED_UPDATE_INTERVAL_MS : AUDIO_LEVEL_UPDATE_INTERVAL_MS);
|
||||
} else {
|
||||
off();
|
||||
}
|
||||
pal.setVisible(!pal.visible);
|
||||
} else {
|
||||
tablet.loadQMLSource("../Pal.qml");
|
||||
Users.requestsDomainListData = true;
|
||||
populateUserList();
|
||||
pal.raise();
|
||||
isWired = true;
|
||||
Script.update.connect(updateOverlays);
|
||||
Controller.mousePressEvent.connect(handleMouseEvent);
|
||||
|
@ -529,10 +555,7 @@ function onClicked() {
|
|||
triggerMapping.enable();
|
||||
triggerPressMapping.enable();
|
||||
audioTimer = createAudioInterval(conserveResources ? AUDIO_LEVEL_CONSERVED_UPDATE_INTERVAL_MS : AUDIO_LEVEL_UPDATE_INTERVAL_MS);
|
||||
} else {
|
||||
off();
|
||||
}
|
||||
pal.setVisible(!pal.visible);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -550,7 +573,7 @@ function receiveMessage(channel, messageString, senderID) {
|
|||
if (!pal.visible) {
|
||||
onClicked();
|
||||
}
|
||||
pal.sendToQml(message); // Accepts objects, not just strings.
|
||||
sendToQml(message); // Accepts objects, not just strings.
|
||||
break;
|
||||
default:
|
||||
print('Unrecognized PAL message', messageString);
|
||||
|
@ -607,13 +630,13 @@ function createAudioInterval(interval) {
|
|||
var userId = id || 0;
|
||||
param[userId] = level;
|
||||
});
|
||||
pal.sendToQml({method: 'updateAudioLevel', params: param});
|
||||
sendToQml({method: 'updateAudioLevel', params: param});
|
||||
}, interval);
|
||||
}
|
||||
|
||||
function avatarDisconnected(nodeID) {
|
||||
// remove from the pal list
|
||||
pal.sendToQml({method: 'avatarDisconnected', params: [nodeID]});
|
||||
sendToQml({method: 'avatarDisconnected', params: [nodeID]});
|
||||
}
|
||||
//
|
||||
// Button state.
|
||||
|
@ -624,11 +647,20 @@ function onVisibleChanged() {
|
|||
button.clicked.connect(onClicked);
|
||||
pal.visibleChanged.connect(onVisibleChanged);
|
||||
pal.closed.connect(off);
|
||||
|
||||
if (!Settings.getValue("HUDUIEnabled")) {
|
||||
tablet.screenChanged.connect(function (type, url) {
|
||||
if (type !== "QML" || url !== "../Pal.qml") {
|
||||
off();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Users.usernameFromIDReply.connect(usernameFromIDReply);
|
||||
Users.avatarDisconnected.connect(avatarDisconnected);
|
||||
|
||||
function clearLocalQMLDataAndClosePAL() {
|
||||
pal.sendToQml({ method: 'clearLocalQMLData' });
|
||||
sendToQml({ method: 'clearLocalQMLData' });
|
||||
if (pal.visible) {
|
||||
onClicked(); // Close the PAL
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue