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 <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
BogDan Vatra 2017-12-15 15:56:25 +02:00
parent f6fd8dceea
commit 80f52812f2
2 changed files with 18 additions and 0 deletions

View File

@ -471,6 +471,13 @@ QAndroidInputContext::QAndroidInputContext()
updateSelectionHandles(); 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() QAndroidInputContext::~QAndroidInputContext()
@ -590,6 +597,10 @@ void QAndroidInputContext::updateSelectionHandles()
QPoint editMenuPoint(curRect.center().x(), curRect.top()); QPoint editMenuPoint(curRect.center().x(), curRect.top());
QtAndroidInput::updateHandles(m_handleMode, cursorPoint * pixelDensity, QtAndroidInput::updateHandles(m_handleMode, cursorPoint * pixelDensity,
editMenuPoint * pixelDensity); editMenuPoint * pixelDensity);
m_handleMode |= ShowCursor;
// The VK is hidden, reset the timer
if (m_hideCursorHandleTimer.isActive())
m_hideCursorHandleTimer.start();
return; return;
} }
@ -603,6 +614,7 @@ void QAndroidInputContext::updateSelectionHandles()
QPoint righPoint(rightRect.bottomRight().toPoint() * pixelDensity); QPoint righPoint(rightRect.bottomRight().toPoint() * pixelDensity);
QtAndroidInput::updateHandles(ShowSelection, leftPoint, righPoint, QtAndroidInput::updateHandles(ShowSelection, leftPoint, righPoint,
query.value(Qt::ImCurrentSelection).toString().isRightToLeft()); 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 (m_focusObject && inputItemRectangle().contains(x, y)) {
// If the user touch the input rectangle, we can show the cursor handle // If the user touch the input rectangle, we can show the cursor handle
m_handleMode = ShowCursor; m_handleMode = ShowCursor;
// The VK will appear in a moment, stop the timer
m_hideCursorHandleTimer.stop();
QMetaObject::invokeMethod(this, "updateSelectionHandles", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "updateSelectionHandles", Qt::QueuedConnection);
} }
} }
@ -747,6 +761,8 @@ void QAndroidInputContext::hideSelectionHandles()
if (m_handleMode & ShowSelection) { if (m_handleMode & ShowSelection) {
m_handleMode = Hidden; m_handleMode = Hidden;
updateSelectionHandles(); updateSelectionHandles();
} else {
m_hideCursorHandleTimer.start();
} }
} }

View File

@ -44,6 +44,7 @@
#include <qpa/qplatforminputcontext.h> #include <qpa/qplatforminputcontext.h>
#include <jni.h> #include <jni.h>
#include <qevent.h> #include <qevent.h>
#include <QTimer>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -157,6 +158,7 @@ private:
HandleModes m_handleMode; HandleModes m_handleMode;
QAtomicInt m_batchEditNestingLevel; QAtomicInt m_batchEditNestingLevel;
QObject *m_focusObject; QObject *m_focusObject;
QTimer m_hideCursorHandleTimer;
}; };
Q_DECLARE_OPERATORS_FOR_FLAGS(QAndroidInputContext::HandleModes) Q_DECLARE_OPERATORS_FOR_FLAGS(QAndroidInputContext::HandleModes)
QT_END_NAMESPACE QT_END_NAMESPACE