From 80f52812f2651e6d427bb3dd2e338b60fb25d48b Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Fri, 15 Dec 2017 15:56:25 +0200 Subject: Hide cursor handle after ~4s on inactivity When the VK is hidden keep cursor handle the cursor handle visible for ~4s after user last activity. Task-number: QTBUG-66806 Change-Id: I8122c5886efaeee86bb691ad971aa7a3e3d7f8e1 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/plugins/platforms/android/qandroidinputcontext.cpp | 16 ++++++++++++++++ src/plugins/platforms/android/qandroidinputcontext.h | 2 ++ 2 files changed, 18 insertions(+) (limited to 'src/plugins/platforms/android') diff --git a/src/plugins/platforms/android/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp index d6da1998cf..430eaf638b 100644 --- a/src/plugins/platforms/android/qandroidinputcontext.cpp +++ b/src/plugins/platforms/android/qandroidinputcontext.cpp @@ -471,6 +471,13 @@ QAndroidInputContext::QAndroidInputContext() updateSelectionHandles(); } }); + m_hideCursorHandleTimer.setInterval(4000); + m_hideCursorHandleTimer.setSingleShot(true); + m_hideCursorHandleTimer.setTimerType(Qt::VeryCoarseTimer); + connect(&m_hideCursorHandleTimer, &QTimer::timeout, this, [this]{ + m_handleMode = Hidden; + updateSelectionHandles(); + }); } QAndroidInputContext::~QAndroidInputContext() @@ -590,6 +597,10 @@ void QAndroidInputContext::updateSelectionHandles() QPoint editMenuPoint(curRect.center().x(), curRect.top()); QtAndroidInput::updateHandles(m_handleMode, cursorPoint * pixelDensity, editMenuPoint * pixelDensity); + m_handleMode |= ShowCursor; + // The VK is hidden, reset the timer + if (m_hideCursorHandleTimer.isActive()) + m_hideCursorHandleTimer.start(); return; } @@ -603,6 +614,7 @@ void QAndroidInputContext::updateSelectionHandles() QPoint righPoint(rightRect.bottomRight().toPoint() * pixelDensity); QtAndroidInput::updateHandles(ShowSelection, leftPoint, righPoint, query.value(Qt::ImCurrentSelection).toString().isRightToLeft()); + m_hideCursorHandleTimer.stop(); } /* @@ -690,6 +702,8 @@ void QAndroidInputContext::touchDown(int x, int y) if (m_focusObject && inputItemRectangle().contains(x, y)) { // If the user touch the input rectangle, we can show the cursor handle m_handleMode = ShowCursor; + // The VK will appear in a moment, stop the timer + m_hideCursorHandleTimer.stop(); QMetaObject::invokeMethod(this, "updateSelectionHandles", Qt::QueuedConnection); } } @@ -747,6 +761,8 @@ void QAndroidInputContext::hideSelectionHandles() if (m_handleMode & ShowSelection) { m_handleMode = Hidden; updateSelectionHandles(); + } else { + m_hideCursorHandleTimer.start(); } } diff --git a/src/plugins/platforms/android/qandroidinputcontext.h b/src/plugins/platforms/android/qandroidinputcontext.h index a6e22fa4f7..1b351f16bd 100644 --- a/src/plugins/platforms/android/qandroidinputcontext.h +++ b/src/plugins/platforms/android/qandroidinputcontext.h @@ -44,6 +44,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -157,6 +158,7 @@ private: HandleModes m_handleMode; QAtomicInt m_batchEditNestingLevel; QObject *m_focusObject; + QTimer m_hideCursorHandleTimer; }; Q_DECLARE_OPERATORS_FOR_FLAGS(QAndroidInputContext::HandleModes) QT_END_NAMESPACE -- cgit v1.2.3