mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-10 01:36:26 +02:00
show and hide keyboard for qml windows
This commit is contained in:
parent
dd39d46883
commit
c396196e0f
3 changed files with 37 additions and 8 deletions
|
@ -18,7 +18,7 @@ import "hifi/toolbars"
|
||||||
import "controls-uit" as HifiControls
|
import "controls-uit" as HifiControls
|
||||||
|
|
||||||
Window {
|
Window {
|
||||||
property bool keyboardRaised: true
|
property bool keyboardRaised: false
|
||||||
property bool punctuationMode: false
|
property bool punctuationMode: false
|
||||||
|
|
||||||
id: root
|
id: root
|
||||||
|
@ -70,6 +70,7 @@ Window {
|
||||||
|
|
||||||
AddressBarDialog {
|
AddressBarDialog {
|
||||||
id: addressBarDialog
|
id: addressBarDialog
|
||||||
|
objectName: "AddressBarDialogDialog"
|
||||||
implicitWidth: backgroundImage.width
|
implicitWidth: backgroundImage.width
|
||||||
implicitHeight: backgroundImage.height + (keyboardRaised ? 200 : 0)
|
implicitHeight: backgroundImage.height + (keyboardRaised ? 200 : 0)
|
||||||
// The buttons have their button state changed on hover, so we have to manually fix them up here
|
// The buttons have their button state changed on hover, so we have to manually fix them up here
|
||||||
|
@ -126,6 +127,7 @@ Window {
|
||||||
}
|
}
|
||||||
Image {
|
Image {
|
||||||
id: backgroundImage
|
id: backgroundImage
|
||||||
|
objectName: "AddressBarDialogImage"
|
||||||
source: "../images/address-bar.svg"
|
source: "../images/address-bar.svg"
|
||||||
width: 576 * root.scale
|
width: 576 * root.scale
|
||||||
height: 80 * root.scale
|
height: 80 * root.scale
|
||||||
|
@ -175,6 +177,7 @@ Window {
|
||||||
TextInput {
|
TextInput {
|
||||||
id: addressLine
|
id: addressLine
|
||||||
focus: true
|
focus: true
|
||||||
|
objectName: "AddressBarDialogTextInput"
|
||||||
anchors {
|
anchors {
|
||||||
top: parent.top
|
top: parent.top
|
||||||
bottom: parent.bottom
|
bottom: parent.bottom
|
||||||
|
|
|
@ -814,15 +814,29 @@ QVariant OffscreenQmlSurface::returnFromUiThread(std::function<QVariant()> funct
|
||||||
return function();
|
return function();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OffscreenQmlSurface::focusDestroyed(QObject *obj) {
|
||||||
|
_currentFocusItem = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void OffscreenQmlSurface::onFocusObjectChanged(QObject* object) {
|
void OffscreenQmlSurface::onFocusObjectChanged(QObject* object) {
|
||||||
if (!object) {
|
QQuickItem* item = dynamic_cast<QQuickItem*>(object);
|
||||||
|
if (!item) {
|
||||||
setFocusText(false);
|
setFocusText(false);
|
||||||
|
_currentFocusItem = nullptr;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QInputMethodQueryEvent query(Qt::ImEnabled);
|
QInputMethodQueryEvent query(Qt::ImEnabled);
|
||||||
qApp->sendEvent(object, &query);
|
qApp->sendEvent(object, &query);
|
||||||
setFocusText(query.value(Qt::ImEnabled).toBool());
|
setFocusText(query.value(Qt::ImEnabled).toBool());
|
||||||
|
|
||||||
|
if (_currentFocusItem) {
|
||||||
|
disconnect(_currentFocusItem, &QObject::destroyed, this, 0);
|
||||||
|
setKeyboardRaised(_currentFocusItem, false);
|
||||||
|
}
|
||||||
|
setKeyboardRaised(item, item->hasActiveFocus());
|
||||||
|
_currentFocusItem = item;
|
||||||
|
connect(_currentFocusItem, &QObject::destroyed, this, &OffscreenQmlSurface::focusDestroyed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OffscreenQmlSurface::setFocusText(bool newFocusText) {
|
void OffscreenQmlSurface::setFocusText(bool newFocusText) {
|
||||||
|
@ -880,15 +894,25 @@ void OffscreenQmlSurface::synthesizeKeyPress(QString key) {
|
||||||
QCoreApplication::postEvent(getEventHandler(), releaseEvent);
|
QCoreApplication::postEvent(getEventHandler(), releaseEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OffscreenQmlSurface::setKeyboardRaised(bool raised) {
|
void OffscreenQmlSurface::setKeyboardRaised(QObject* object, bool raised) {
|
||||||
|
|
||||||
// raise the keyboard only while in HMD mode and it's being requested.
|
// raise the keyboard only while in HMD mode and it's being requested.
|
||||||
// XXX
|
// XXX
|
||||||
// bool value = AbstractViewStateInterface::instance()->isHMDMode() && raised;
|
// bool value = AbstractViewStateInterface::instance()->isHMDMode() && raised;
|
||||||
// getRootItem()->setProperty("keyboardRaised", QVariant(value));
|
// getRootItem()->setProperty("keyboardRaised", QVariant(value));
|
||||||
|
|
||||||
getRootItem()->setProperty("keyboardRaised", QVariant(raised));
|
if (!object) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QQuickItem* item = dynamic_cast<QQuickItem*>(object);
|
||||||
|
while (item) {
|
||||||
|
if (item->property("keyboardRaised").isValid()) {
|
||||||
|
item->setProperty("keyboardRaised", QVariant(raised));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
item = dynamic_cast<QQuickItem*>(item->parentItem());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OffscreenQmlSurface::emitScriptEvent(const QVariant& message) {
|
void OffscreenQmlSurface::emitScriptEvent(const QVariant& message) {
|
||||||
|
@ -905,9 +929,9 @@ void OffscreenQmlSurface::emitWebEvent(const QVariant& message) {
|
||||||
} else {
|
} else {
|
||||||
// special case to handle raising and lowering the virtual keyboard
|
// special case to handle raising and lowering the virtual keyboard
|
||||||
if (message.type() == QVariant::String && message.toString() == "_RAISE_KEYBOARD") {
|
if (message.type() == QVariant::String && message.toString() == "_RAISE_KEYBOARD") {
|
||||||
setKeyboardRaised(true);
|
setKeyboardRaised(getRootItem(), true);
|
||||||
} else if (message.type() == QVariant::String && message.toString() == "_LOWER_KEYBOARD") {
|
} else if (message.type() == QVariant::String && message.toString() == "_LOWER_KEYBOARD") {
|
||||||
setKeyboardRaised(false);
|
setKeyboardRaised(getRootItem(), false);
|
||||||
} else {
|
} else {
|
||||||
emit webEventReceived(message);
|
emit webEventReceived(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ public:
|
||||||
QPointF mapToVirtualScreen(const QPointF& originalPoint, QObject* originalWidget);
|
QPointF mapToVirtualScreen(const QPointF& originalPoint, QObject* originalWidget);
|
||||||
bool eventFilter(QObject* originalDestination, QEvent* event) override;
|
bool eventFilter(QObject* originalDestination, QEvent* event) override;
|
||||||
|
|
||||||
Q_INVOKABLE void setKeyboardRaised(bool raised);
|
void setKeyboardRaised(QObject* object, bool raised);
|
||||||
Q_INVOKABLE void synthesizeKeyPress(QString key);
|
Q_INVOKABLE void synthesizeKeyPress(QString key);
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ public slots:
|
||||||
void requestUpdate();
|
void requestUpdate();
|
||||||
void requestRender();
|
void requestRender();
|
||||||
void onAboutToQuit();
|
void onAboutToQuit();
|
||||||
|
void focusDestroyed(QObject *obj);
|
||||||
|
|
||||||
// event bridge
|
// event bridge
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -119,6 +119,8 @@ private:
|
||||||
uint8_t _maxFps{ 60 };
|
uint8_t _maxFps{ 60 };
|
||||||
MouseTranslator _mouseTranslator{ [](const QPointF& p) { return p.toPoint(); } };
|
MouseTranslator _mouseTranslator{ [](const QPointF& p) { return p.toPoint(); } };
|
||||||
QWindow* _proxyWindow { nullptr };
|
QWindow* _proxyWindow { nullptr };
|
||||||
|
|
||||||
|
QQuickItem* _currentFocusItem { nullptr };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue