Android: fix missing wheel events

Change-Id: I65b4f6a8fcbdad537a984064e332a4a1f34a265a
Task-number: QTBUG-43669
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
This commit is contained in:
J-P Nurmi 2017-06-09 14:46:29 +02:00
parent 68bcbe2470
commit 97eec16e4f
3 changed files with 40 additions and 0 deletions

View File

@ -61,6 +61,7 @@ import android.view.KeyEvent;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.InputDevice;
import java.lang.reflect.Method;
import java.security.KeyStore;
@ -470,6 +471,17 @@ public class QtNative
}
}
static public void sendGenericMotionEvent(MotionEvent event, int id)
{
if (event.getActionMasked() != MotionEvent.ACTION_SCROLL
|| (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != InputDevice.SOURCE_CLASS_POINTER) {
return;
}
mouseWheel(id, (int) event.getX(), (int) event.getY(),
event.getAxisValue(MotionEvent.AXIS_HSCROLL), event.getAxisValue(MotionEvent.AXIS_VSCROLL));
}
public static Context getContext() {
if (m_activity != null)
return m_activity;
@ -801,6 +813,7 @@ public class QtNative
public static native void mouseDown(int winId, int x, int y);
public static native void mouseUp(int winId, int x, int y);
public static native void mouseMove(int winId, int x, int y);
public static native void mouseWheel(int winId, int x, int y, float hdelta, float vdelta);
public static native void touchBegin(int winId);
public static native void touchAdd(int winId, int pointerId, int action, boolean primary, int x, int y, float major, float minor, float rotation, float pressure);
public static native void touchEnd(int winId, int action);

View File

@ -112,4 +112,11 @@ public class QtSurface extends SurfaceView implements SurfaceHolder.Callback
QtNative.sendTrackballEvent(event, getId());
return true;
}
@Override
public boolean onGenericMotionEvent(MotionEvent event)
{
QtNative.sendGenericMotionEvent(event, getId());
return true;
}
}

View File

@ -173,6 +173,25 @@ namespace QtAndroidInput
Qt::MouseButtons(Qt::LeftButton));
}
static void mouseWheel(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y, jfloat hdelta, jfloat vdelta)
{
if (m_ignoreMouseEvents)
return;
QPoint globalPos(x,y);
QWindow *tlw = m_mouseGrabber.data();
if (!tlw)
tlw = topLevelWindowAt(globalPos);
QPoint localPos = tlw ? (globalPos-tlw->position()) : globalPos;
QPoint angleDelta(hdelta * 120, vdelta * 120);
QWindowSystemInterface::handleWheelEvent(tlw,
localPos,
globalPos,
QPoint(),
angleDelta);
}
static void longPress(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y)
{
QAndroidInputContext *inputContext = QAndroidInputContext::androidInputContext();
@ -824,6 +843,7 @@ namespace QtAndroidInput
{"mouseDown", "(III)V", (void *)mouseDown},
{"mouseUp", "(III)V", (void *)mouseUp},
{"mouseMove", "(III)V", (void *)mouseMove},
{"mouseWheel", "(IIIFF)V", (void *)mouseWheel},
{"longPress", "(III)V", (void *)longPress},
{"isTabletEventSupported", "()Z", (void *)isTabletEventSupported},
{"tabletEvent", "(IIJIIIFFF)V", (void *)tabletEvent},