From f83040c572249d9a823d7b3f50b8f8f043ddda13 Mon Sep 17 00:00:00 2001 From: beholder Date: Fri, 13 Oct 2017 22:23:38 +0300 Subject: [PATCH] updating code accordingly to the comments --- libraries/ui/src/ui/OffscreenQmlSurface.cpp | 60 ++++++++++----------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/libraries/ui/src/ui/OffscreenQmlSurface.cpp b/libraries/ui/src/ui/OffscreenQmlSurface.cpp index 69d6b8d6ab..01026ae5ff 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurface.cpp +++ b/libraries/ui/src/ui/OffscreenQmlSurface.cpp @@ -1018,6 +1018,32 @@ void OffscreenQmlSurface::synthesizeKeyPress(QString key, QObject* targetOverrid } } +static void forEachKeyboard(QQuickItem* item, std::function function) { + QObject* itemObject = item; + while (itemObject) { + if (itemObject->parent()) { + itemObject = itemObject->parent(); + } else { + break; + } + } + + auto keyboards = itemObject->findChildren("keyboard"); + + for (auto keyboardObject : keyboards) { + auto keyboard = qobject_cast(keyboardObject); + if (keyboard == nullptr) { + continue; + } + + if (function) { + function(keyboard); + } + } +} + +static const int TEXTINPUT_PASSWORD = 2; + void OffscreenQmlSurface::setKeyboardRaised(QObject* object, bool raised, bool numeric) { #if Q_OS_ANDROID return; @@ -1030,43 +1056,17 @@ void OffscreenQmlSurface::setKeyboardRaised(QObject* object, bool raised, bool n // if HMD is being worn, allow keyboard to open. allow it to close, HMD or not. if (!raised || qApp->property(hifi::properties::HMD).toBool()) { QQuickItem* item = dynamic_cast(object); - if (!item) + if (!item) { return; + } auto echoMode = item->property("echoMode"); - bool isPasswordField = echoMode.isValid() && echoMode.toInt() == 2 /* TextInput.Password */; + bool isPasswordField = echoMode.isValid() && echoMode.toInt() == TEXTINPUT_PASSWORD; // we need to somehow pass 'isPasswordField' to visible keyboard so it will change its 'mirror text' to asterixes // the issue in some cases there might be more than one keyboard in object tree and it is hard to understand which one is being used at the moment // unfortunately attempts to check for visibility failed becuase visibility is not updated yet. So... I don't see other way than just update properties for all the keyboards - struct Local { - static void forEachKeyboard(QQuickItem* item, std::function function) { - QObject* itemObject = item; - while (itemObject) { - if (itemObject->parent()) { - itemObject = itemObject->parent(); - } - else { - break; - } - } - - auto keyboards = itemObject->findChildren("keyboard"); - - for (auto keyboardObject : keyboards) { - auto keyboard = qobject_cast(keyboardObject); - if (keyboard == nullptr) { - continue; - } - - if (function) { - function(keyboard); - } - } - } - }; - - Local::forEachKeyboard(item, [&](QQuickItem* keyboard) { + forEachKeyboard(item, [&](QQuickItem* keyboard) { keyboard->setProperty("mirroredText", QVariant::fromValue(QString(""))); keyboard->setProperty("password", isPasswordField); });