Android: Map touch position to global coordinates
When QtWindow is not at 0,0 of its parent, not mapping the position leads to offsets in the touched position in Android vs where it is received in Qt, e.g. needing to touch below a button's actual position to trigger a click. Task-number: QTBUG-126178 Pick-to: 6.7 Change-Id: Icd62ed59f0f323ba3977145c3304e4e874aa4fa2 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit 15674f4ce9ea455b47f68d8871d5676d7a731630) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
371113810e
commit
a4f4058d64
@ -266,7 +266,7 @@ namespace QtAndroidInput
|
||||
m_touchPoints.clear();
|
||||
}
|
||||
|
||||
static void touchAdd(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint id, jint action, jboolean /*primary*/, jint x, jint y,
|
||||
static void touchAdd(JNIEnv */*env*/, jobject /*thiz*/, jint winId, jint id, jint action, jboolean /*primary*/, jint x, jint y,
|
||||
jfloat major, jfloat minor, jfloat rotation, jfloat pressure)
|
||||
{
|
||||
QEventPoint::State state = QEventPoint::State::Stationary;
|
||||
@ -287,16 +287,25 @@ namespace QtAndroidInput
|
||||
|
||||
const int dw = availableWidthPixels();
|
||||
const int dh = availableHeightPixels();
|
||||
QWindow *window = QtAndroid::windowFromId(winId);
|
||||
if (!window) {
|
||||
qCWarning(lcQpaInputMethods, "Touch event received for non-existing window %d", winId);
|
||||
return;
|
||||
}
|
||||
|
||||
QPointF mappedTouchPoint = window->mapToGlobal(QPointF(x, y));
|
||||
QWindowSystemInterface::TouchPoint touchPoint;
|
||||
touchPoint.id = id;
|
||||
touchPoint.pressure = pressure;
|
||||
touchPoint.rotation = qRadiansToDegrees(rotation);
|
||||
touchPoint.normalPosition = QPointF(double(x / dw), double(y / dh));
|
||||
touchPoint.normalPosition = QPointF((mappedTouchPoint.x() / dw),
|
||||
(mappedTouchPoint.y() / dh));
|
||||
touchPoint.state = state;
|
||||
touchPoint.area = QRectF(x - double(minor * 0.5f),
|
||||
y - double(major * 0.5f),
|
||||
touchPoint.area = QRectF(mappedTouchPoint.x() - double(minor * 0.5f),
|
||||
mappedTouchPoint.y() - double(major * 0.5f),
|
||||
double(minor),
|
||||
double(major));
|
||||
|
||||
m_touchPoints.push_back(touchPoint);
|
||||
if (state == QEventPoint::State::Pressed) {
|
||||
QAndroidInputContext *inputContext = QAndroidInputContext::androidInputContext();
|
||||
|
Loading…
x
Reference in New Issue
Block a user