mirror of
https://github.com/lubosz/overte.git
synced 2025-04-27 06:15:31 +02:00
First pass of keyboard raising and lowering
This commit is contained in:
parent
442f6207fb
commit
3d5e8fc213
5 changed files with 32 additions and 14 deletions
interface/resources
libraries/entities-renderer/src
scripts/system/controllers
|
@ -9,20 +9,22 @@
|
|||
//
|
||||
(function () {
|
||||
var POLL_FREQUENCY = 500; // ms
|
||||
var lastRaiseKeyboard = false;
|
||||
var MAX_WARNINGS = 3;
|
||||
var numWarnings = 0;
|
||||
|
||||
function shouldRaiseKeyboard() {
|
||||
return document.activeElement.nodeName == "INPUT" || document.activeElement.nodeName == "TEXTAREA";
|
||||
};
|
||||
|
||||
setInterval(function () {
|
||||
var newRaiseKeyboard = shouldRaiseKeyboard();
|
||||
if (newRaiseKeyboard != lastRaiseKeyboard) {
|
||||
var event = newRaiseKeyboard ? "_RAISE_KEYBOARD" : "_LOWER_KEYBOARD";
|
||||
if (typeof EventBridge != "undefined") {
|
||||
EventBridge.emitWebEvent(event);
|
||||
} else {
|
||||
var event = shouldRaiseKeyboard() ? "_RAISE_KEYBOARD" : "_LOWER_KEYBOARD";
|
||||
if (typeof EventBridge != "undefined") {
|
||||
EventBridge.emitWebEvent(event);
|
||||
} else {
|
||||
if (numWarnings < MAX_WARNINGS) {
|
||||
console.log("WARNING: no global EventBridge object found");
|
||||
numWarnings++;
|
||||
}
|
||||
lastRaiseKeyboard = newRaiseKeyboard;
|
||||
}
|
||||
}, POLL_FREQUENCY);
|
||||
})();
|
||||
|
|
|
@ -5,6 +5,7 @@ import QtWebChannel 1.0
|
|||
Item {
|
||||
property alias url: root.url
|
||||
property alias eventBridge: eventBridgeWrapper.eventBridge
|
||||
property bool keyboardRaised: false
|
||||
|
||||
QtObject {
|
||||
id: eventBridgeWrapper
|
||||
|
@ -17,7 +18,7 @@ Item {
|
|||
x: 0
|
||||
y: 0
|
||||
width: parent.width
|
||||
height: parent.height - keyboard1.height
|
||||
height: keyboardRaised ? parent.height - keyboard.height : parent.height
|
||||
|
||||
// creates a global EventBridge object.
|
||||
WebEngineScript {
|
||||
|
@ -61,6 +62,7 @@ Item {
|
|||
}
|
||||
|
||||
onUrlChanged: {
|
||||
keyboardRaised = false;
|
||||
var originalUrl = url.toString();
|
||||
root.newUrl = urlHandler.fixupUrl(originalUrl).toString();
|
||||
if (root.newUrl !== originalUrl) {
|
||||
|
@ -104,9 +106,11 @@ Item {
|
|||
|
||||
// virtual keyboard
|
||||
Keyboard {
|
||||
id: keyboard1
|
||||
x: 197
|
||||
y: 182
|
||||
id: keyboard
|
||||
y: keyboardRaised ? parent.height : 0
|
||||
height: keyboardRaised ? 200 : 0
|
||||
visible: keyboardRaised
|
||||
enabled: keyboardRaised
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 0
|
||||
anchors.left: parent.left
|
||||
|
|
|
@ -55,7 +55,14 @@ void WebEntityAPIHelper::emitWebEvent(const QVariant& message) {
|
|||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "emitWebEvent", Qt::QueuedConnection, Q_ARG(QVariant, message));
|
||||
} else {
|
||||
emit webEventReceived(message);
|
||||
// special case to handle raising and lowering the virtual keyboard
|
||||
if (message.type() == QVariant::String && message.toString() == "_RAISE_KEYBOARD" && _ptr) {
|
||||
_ptr->setKeyboardRaised(true);
|
||||
} else if (message.type() == QVariant::String && message.toString() == "_LOWER_KEYBOARD" && _ptr) {
|
||||
_ptr->setKeyboardRaised(false);
|
||||
} else {
|
||||
emit webEventReceived(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -357,3 +364,7 @@ void RenderableWebEntityItem::synthesizeKeyPress(QString key) {
|
|||
void RenderableWebEntityItem::emitScriptEvent(const QVariant& message) {
|
||||
_webEntityAPIHelper.emitScriptEvent(message);
|
||||
}
|
||||
|
||||
void RenderableWebEntityItem::setKeyboardRaised(bool raised) {
|
||||
_webSurface->getRootItem()->setProperty("keyboardRaised", QVariant(raised));
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ public:
|
|||
bool needsToCallUpdate() const override { return _webSurface != nullptr; }
|
||||
|
||||
void emitScriptEvent(const QVariant& message);
|
||||
void setKeyboardRaised(bool raised);
|
||||
|
||||
SIMPLE_RENDERABLE();
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ Script.include("/~/system/libraries/Xform.js");
|
|||
// add lines where the hand ray picking is happening
|
||||
//
|
||||
var WANT_DEBUG = false;
|
||||
var WANT_DEBUG_STATE = true;
|
||||
var WANT_DEBUG_STATE = false;
|
||||
var WANT_DEBUG_SEARCH_NAME = null;
|
||||
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue