Working web entity keyboard

* Missing many keys
* Does not dynamically appear and disappear
This commit is contained in:
Anthony J. Thibault 2016-08-31 17:57:13 -07:00
parent 37d7e926d9
commit 823420ae0a
6 changed files with 70 additions and 23 deletions

View file

@ -11,22 +11,40 @@ Item {
id: mouseArea1 id: mouseArea1
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
onCanceled: {
keyItem.state = ""
}
onClicked: {
mouse.accepted = true
webEntity.synthesizeKeyPress(glyph)
}
onDoubleClicked: {
mouse.accepted = true
}
onEntered: { onEntered: {
keyItem.state = "mouseOver" keyItem.state = "mouseOver"
} }
onExited: { onExited: {
keyItem.state = "" keyItem.state = ""
} }
onPressed: { onPressed: {
keyItem.state = "mouseClicked" keyItem.state = "mouseClicked"
mouse.accepted = true
} }
onReleased: { onReleased: {
keyItem.state = "" if (containsMouse) {
} keyItem.state = "mouseOver"
onClicked: { } else {
} keyItem.state = ""
onCanceled: { }
keyItem.state = "" mouse.accepted = true
} }
} }

View file

@ -2,6 +2,7 @@ import QtQuick 2.0
Item { Item {
id: keyboardBase id: keyboardBase
height: 200
Rectangle { Rectangle {
id: leftRect id: leftRect
y: 0 y: 0

View file

@ -6,7 +6,12 @@ Item {
WebEngineView { WebEngineView {
id: root id: root
anchors.fill: parent
x: 0
y: 0
width: parent.width
height: parent.height - keyboard1.height
property string newUrl: "" property string newUrl: ""
profile.httpUserAgent: "Mozilla/5.0 Chrome (HighFidelityInterface)" profile.httpUserAgent: "Mozilla/5.0 Chrome (HighFidelityInterface)"

View file

@ -37,6 +37,12 @@ static uint64_t MAX_NO_RENDER_INTERVAL = 30 * USECS_PER_SECOND;
static int MAX_WINDOW_SIZE = 4096; static int MAX_WINDOW_SIZE = 4096;
static float OPAQUE_ALPHA_THRESHOLD = 0.99f; static float OPAQUE_ALPHA_THRESHOLD = 0.99f;
void WebEntityQMLAPIHelper::synthesizeKeyPress(QString key) {
if (_ptr) {
_ptr->synthesizeKeyPress(key);
}
}
EntityItemPointer RenderableWebEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { EntityItemPointer RenderableWebEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
EntityItemPointer entity{ new RenderableWebEntityItem(entityID) }; EntityItemPointer entity{ new RenderableWebEntityItem(entityID) };
entity->setProperties(properties); entity->setProperties(properties);
@ -51,9 +57,12 @@ RenderableWebEntityItem::RenderableWebEntityItem(const EntityItemID& entityItemI
_touchDevice.setType(QTouchDevice::TouchScreen); _touchDevice.setType(QTouchDevice::TouchScreen);
_touchDevice.setName("RenderableWebEntityItemTouchDevice"); _touchDevice.setName("RenderableWebEntityItemTouchDevice");
_touchDevice.setMaximumTouchPoints(4); _touchDevice.setMaximumTouchPoints(4);
_webEntityQMLAPIHelper.setPtr(this);
} }
RenderableWebEntityItem::~RenderableWebEntityItem() { RenderableWebEntityItem::~RenderableWebEntityItem() {
_webEntityQMLAPIHelper.setPtr(nullptr);
destroyWebSurface(); destroyWebSurface();
qDebug() << "Destroyed web entity " << getID(); qDebug() << "Destroyed web entity " << getID();
} }
@ -76,6 +85,7 @@ bool RenderableWebEntityItem::buildWebSurface(EntityTreeRenderer* renderer) {
_webSurface->resume(); _webSurface->resume();
_webSurface->getRootItem()->setProperty("url", _sourceUrl); _webSurface->getRootItem()->setProperty("url", _sourceUrl);
_webSurface->getRootContext()->setContextProperty("desktop", QVariant()); _webSurface->getRootContext()->setContextProperty("desktop", QVariant());
_webSurface->getRootContext()->setContextProperty("webEntity", &_webEntityQMLAPIHelper);
_connection = QObject::connect(_webSurface, &OffscreenQmlSurface::textureUpdated, [&](GLuint textureId) { _connection = QObject::connect(_webSurface, &OffscreenQmlSurface::textureUpdated, [&](GLuint textureId) {
_texture = textureId; _texture = textureId;
}); });
@ -98,13 +108,8 @@ bool RenderableWebEntityItem::buildWebSurface(EntityTreeRenderer* renderer) {
point.setState(Qt::TouchPointReleased); point.setState(Qt::TouchPointReleased);
glm::vec2 windowPos = event.getPos2D() * (METERS_TO_INCHES * _dpi); glm::vec2 windowPos = event.getPos2D() * (METERS_TO_INCHES * _dpi);
QPointF windowPoint(windowPos.x, windowPos.y); QPointF windowPoint(windowPos.x, windowPos.y);
auto item = _webSurface->getRootItem()->childAt(windowPos.x, windowPos.y);
QPointF localPoint = windowPoint;
if (item) {
localPoint = item->mapFromScene(windowPoint);
}
point.setScenePos(windowPoint); point.setScenePos(windowPoint);
point.setPos(localPoint); point.setPos(windowPoint);
QList<QTouchEvent::TouchPoint> touchPoints; QList<QTouchEvent::TouchPoint> touchPoints;
touchPoints.push_back(point); touchPoints.push_back(point);
QTouchEvent* touchEvent = new QTouchEvent(QEvent::TouchEnd, nullptr, Qt::NoModifier, Qt::TouchPointReleased, touchPoints); QTouchEvent* touchEvent = new QTouchEvent(QEvent::TouchEnd, nullptr, Qt::NoModifier, Qt::TouchPointReleased, touchPoints);
@ -224,13 +229,6 @@ void RenderableWebEntityItem::handlePointerEvent(const PointerEvent& event) {
glm::vec2 windowPos = event.getPos2D() * (METERS_TO_INCHES * _dpi); glm::vec2 windowPos = event.getPos2D() * (METERS_TO_INCHES * _dpi);
QPointF windowPoint(windowPos.x, windowPos.y); QPointF windowPoint(windowPos.x, windowPos.y);
auto item = _webSurface->getRootItem()->childAt(windowPos.x, windowPos.y);
QPointF localPoint = windowPoint;
if (item) {
localPoint = item->mapFromScene(windowPoint);
}
if (event.getType() == PointerEvent::Move) { if (event.getType() == PointerEvent::Move) {
// Forward a mouse move event to webSurface // Forward a mouse move event to webSurface
QMouseEvent* mouseEvent = new QMouseEvent(QEvent::MouseMove, windowPoint, windowPoint, windowPoint, Qt::NoButton, Qt::NoButton, Qt::NoModifier); QMouseEvent* mouseEvent = new QMouseEvent(QEvent::MouseMove, windowPoint, windowPoint, windowPoint, Qt::NoButton, Qt::NoButton, Qt::NoModifier);
@ -266,7 +264,7 @@ void RenderableWebEntityItem::handlePointerEvent(const PointerEvent& event) {
QTouchEvent::TouchPoint point; QTouchEvent::TouchPoint point;
point.setId(event.getID()); point.setId(event.getID());
point.setState(touchPointState); point.setState(touchPointState);
point.setPos(localPoint); point.setPos(windowPoint);
point.setScreenPos(windowPoint); point.setScreenPos(windowPoint);
QList<QTouchEvent::TouchPoint> touchPoints; QList<QTouchEvent::TouchPoint> touchPoints;
touchPoints.push_back(point); touchPoints.push_back(point);
@ -323,3 +321,11 @@ bool RenderableWebEntityItem::isTransparent() {
float fadeRatio = _isFading ? Interpolate::calculateFadeRatio(_fadeStartTime) : 1.0f; float fadeRatio = _isFading ? Interpolate::calculateFadeRatio(_fadeStartTime) : 1.0f;
return fadeRatio < OPAQUE_ALPHA_THRESHOLD; return fadeRatio < OPAQUE_ALPHA_THRESHOLD;
} }
void RenderableWebEntityItem::synthesizeKeyPress(QString key) {
auto utf8Key = key.toUtf8();
QKeyEvent* pressEvent = new QKeyEvent(QEvent::KeyPress, (int)utf8Key[0], Qt::NoModifier, key);
QKeyEvent* releaseEvent = new QKeyEvent(QEvent::KeyRelease, (int)utf8Key[0], Qt::NoModifier, key);
QCoreApplication::postEvent(getEventHandler(), pressEvent);
QCoreApplication::postEvent(getEventHandler(), releaseEvent);
}

View file

@ -22,6 +22,19 @@ class OffscreenQmlSurface;
class QWindow; class QWindow;
class QObject; class QObject;
class EntityTreeRenderer; class EntityTreeRenderer;
class RenderableWebEntityItem;
class WebEntityQMLAPIHelper : public QObject {
Q_OBJECT
public:
void setPtr(RenderableWebEntityItem* ptr) {
_ptr = ptr;
}
Q_INVOKABLE void synthesizeKeyPress(QString key);
protected:
RenderableWebEntityItem* _ptr{ nullptr };
};
class RenderableWebEntityItem : public WebEntityItem { class RenderableWebEntityItem : public WebEntityItem {
public: public:
@ -46,6 +59,9 @@ public:
virtual bool isTransparent() override; virtual bool isTransparent() override;
public:
void synthesizeKeyPress(QString key);
private: private:
bool buildWebSurface(EntityTreeRenderer* renderer); bool buildWebSurface(EntityTreeRenderer* renderer);
void destroyWebSurface(); void destroyWebSurface();
@ -59,6 +75,7 @@ private:
QTouchEvent _lastTouchEvent { QEvent::TouchUpdate }; QTouchEvent _lastTouchEvent { QEvent::TouchUpdate };
uint64_t _lastRenderTime{ 0 }; uint64_t _lastRenderTime{ 0 };
QTouchDevice _touchDevice; QTouchDevice _touchDevice;
WebEntityQMLAPIHelper _webEntityQMLAPIHelper;
QMetaObject::Connection _mousePressConnection; QMetaObject::Connection _mousePressConnection;
QMetaObject::Connection _mouseReleaseConnection; QMetaObject::Connection _mouseReleaseConnection;
@ -66,5 +83,4 @@ private:
QMetaObject::Connection _hoverLeaveConnection; QMetaObject::Connection _hoverLeaveConnection;
}; };
#endif // hifi_RenderableWebEntityItem_h #endif // hifi_RenderableWebEntityItem_h

View file

@ -21,7 +21,7 @@ Script.include("/~/system/libraries/Xform.js");
// add lines where the hand ray picking is happening // add lines where the hand ray picking is happening
// //
var WANT_DEBUG = false; var WANT_DEBUG = false;
var WANT_DEBUG_STATE = false; var WANT_DEBUG_STATE = true;
var WANT_DEBUG_SEARCH_NAME = null; var WANT_DEBUG_SEARCH_NAME = null;
// //
@ -2159,6 +2159,7 @@ function MyController(hand) {
}; };
} else { } else {
pointerEvent = this.touchingEnterPointerEvent; pointerEvent = this.touchingEnterPointerEvent;
pointerEvent.type = "Release";
pointerEvent.button = "Primary"; pointerEvent.button = "Primary";
pointerEvent.isPrimaryButton = false; pointerEvent.isPrimaryButton = false;
} }