From a24cd41367b5a055abd992e52dcc6ac0e9ee43eb Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Tue, 4 Dec 2018 14:19:09 -0800 Subject: [PATCH] getting textfield into focus --- .../resources/qml/LoginDialog/LinkAccountBody.qml | 10 +++++++--- interface/src/Application.cpp | 12 +++++++----- interface/src/Application.h | 2 ++ interface/src/ui/LoginDialog.cpp | 8 +++++++- interface/src/ui/LoginDialog.h | 4 ++++ interface/src/ui/overlays/Web3DOverlay.cpp | 8 -------- interface/src/ui/overlays/Web3DOverlay.h | 1 - 7 files changed, 27 insertions(+), 18 deletions(-) diff --git a/interface/resources/qml/LoginDialog/LinkAccountBody.qml b/interface/resources/qml/LoginDialog/LinkAccountBody.qml index 1da2924b33..89cf8594eb 100644 --- a/interface/resources/qml/LoginDialog/LinkAccountBody.qml +++ b/interface/resources/qml/LoginDialog/LinkAccountBody.qml @@ -166,7 +166,6 @@ Item { topMargin: loginErrorMessage.height } placeholderText: "Username or Email" - focus: true activeFocusOnPress: true Keys.onPressed: { switch (event.key) { @@ -489,8 +488,13 @@ Item { } } - onFocusChanged: { - emailField.focus = focus; + Connections { + target: loginDialog + onFocusEnabled: { + Qt.callLater(function() { + emailField.forceActiveFocus(); + }) + } } Component.onCompleted: { diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 776abf3f2a..cdf44100a0 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -5849,6 +5849,9 @@ void Application::setKeyboardFocusOverlay(const OverlayID& overlayID) { _keyboardFocusHighlight->setVisible(false); } } + if (overlayID == _loginDialogOverlayID) { + emit loginDialogFocusEnabled(); + } } } @@ -8178,9 +8181,9 @@ void Application::loadDomainConnectionDialog() { } void Application::toggleLogDialog() { - //if (getLoginDialogPoppedUp()) { - // return; - //} + if (getLoginDialogPoppedUp()) { + return; + } if (! _logDialog) { _logDialog = new LogDialog(nullptr, getLogger()); } @@ -8749,8 +8752,7 @@ void Application::createLoginDialogOverlay() { overlays.editOverlay(keyboard->getAnchorID(), properties); keyboard->setResetKeyboardPositionOnRaise(false); } - auto loginDialogOverlay = std::dynamic_pointer_cast(getOverlays().getOverlay(_loginDialogOverlayID)); - loginDialogOverlay->setActiveFocus(true); + setKeyboardFocusOverlay(_loginDialogOverlayID); getApplicationCompositor().getReticleInterface()->setAllowMouseCapture(false); getApplicationCompositor().getReticleInterface()->setVisible(false); if (!_loginStateManager.isSetUp()) { diff --git a/interface/src/Application.h b/interface/src/Application.h index 573919cd26..64bb96a57b 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -344,6 +344,8 @@ signals: void interstitialModeChanged(bool isInInterstitialMode); + void loginDialogFocusEnabled(); + void miniTabletEnabledChanged(bool enabled); public slots: diff --git a/interface/src/ui/LoginDialog.cpp b/interface/src/ui/LoginDialog.cpp index d6a67207be..e17abc4d3e 100644 --- a/interface/src/ui/LoginDialog.cpp +++ b/interface/src/ui/LoginDialog.cpp @@ -42,8 +42,9 @@ LoginDialog::LoginDialog(QQuickItem *parent) : OffscreenQmlDialog(parent) { this, &LoginDialog::handleLoginCompleted); connect(accountManager.data(), &AccountManager::loginFailed, this, &LoginDialog::handleLoginFailed); -#endif + connect(qApp, SIGNAL(loginDialogFocusEnabled()), this, SLOT(onFocusEnabled())); connect(this, SIGNAL(dismissedLoginDialog()), qApp, SLOT(onDismissedLoginDialog())); +#endif } LoginDialog::~LoginDialog() { @@ -307,3 +308,8 @@ void LoginDialog::signupFailed(QNetworkReply* reply) { emit handleSignupFailed(DEFAULT_SIGN_UP_FAILURE_MESSAGE); } } + +void LoginDialog::onFocusEnabled() { + forceActiveFocus(); + emit focusEnabled(); +} diff --git a/interface/src/ui/LoginDialog.h b/interface/src/ui/LoginDialog.h index 230e18881a..b5f45de48a 100644 --- a/interface/src/ui/LoginDialog.h +++ b/interface/src/ui/LoginDialog.h @@ -48,6 +48,8 @@ signals: // occurs upon dismissing the encouraging log in. void dismissedLoginDialog(); + void focusEnabled(); + public slots: void linkCompleted(QNetworkReply* reply); void linkFailed(QNetworkReply* reply); @@ -58,6 +60,8 @@ public slots: void signupCompleted(QNetworkReply* reply); void signupFailed(QNetworkReply* reply); + void onFocusEnabled(); + protected slots: Q_INVOKABLE void dismissLoginDialog(); diff --git a/interface/src/ui/overlays/Web3DOverlay.cpp b/interface/src/ui/overlays/Web3DOverlay.cpp index bd1d884ee9..3f06b43a9e 100644 --- a/interface/src/ui/overlays/Web3DOverlay.cpp +++ b/interface/src/ui/overlays/Web3DOverlay.cpp @@ -473,14 +473,6 @@ void Web3DOverlay::handlePointerEventAsMouse(const PointerEvent& event) { QCoreApplication::sendEvent(_webSurface->getWindow(), &mouseEvent); } -void Web3DOverlay::setActiveFocus(bool focus) { - if (_webSurface && focus) { - if (focus) { - _webSurface->getRootItem()->forceActiveFocus(); - } - } -} - void Web3DOverlay::setProperties(const QVariantMap& properties) { Billboard3DOverlay::setProperties(properties); diff --git a/interface/src/ui/overlays/Web3DOverlay.h b/interface/src/ui/overlays/Web3DOverlay.h index f52075df5b..4137ed8680 100644 --- a/interface/src/ui/overlays/Web3DOverlay.h +++ b/interface/src/ui/overlays/Web3DOverlay.h @@ -44,7 +44,6 @@ public: Q_INVOKABLE void handlePointerEvent(const PointerEvent& event); void handlePointerEventAsTouch(const PointerEvent& event); void handlePointerEventAsMouse(const PointerEvent& event); - void setActiveFocus(bool focus); // setters void setURL(const QString& url);