-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With a patch to Qt to interpret those axis values.
- Loading branch information
1 parent
52ce966
commit 288ea4d
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
Description: Tilt support for QTabletEvent on Android. | ||
|
||
--- a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java | ||
+++ b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java | ||
@@ -563,8 +563,20 @@ | ||
if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) { | ||
sendMouseEvent(event, id); | ||
} else if (m_tabletEventSupported && pointerType != 0) { | ||
+ int xtilt, ytilt; | ||
+ double tilt = event.getAxisValue(MotionEvent.AXIS_TILT); | ||
+ if (tilt == 0.0) { | ||
+ xtilt = 0; | ||
+ ytilt = 0; | ||
+ } else { | ||
+ double orientation = ((double)event.getOrientation()) - Math.PI / 2.0; | ||
+ double tiltDegrees = Math.toDegrees(tilt); | ||
+ xtilt = (int)Math.round(Math.cos(orientation) * tiltDegrees); | ||
+ ytilt = (int)Math.round(-Math.sin(orientation) * tiltDegrees); | ||
+ } | ||
tabletEvent(id, event.getDeviceId(), event.getEventTime(), event.getAction(), pointerType, | ||
- event.getButtonState(), event.getX(), event.getY(), event.getPressure()); | ||
+ event.getButtonState(), event.getX(), event.getY(), event.getPressure(), | ||
+ xtilt, ytilt); | ||
} else { | ||
touchBegin(id); | ||
for (int i = 0; i < event.getPointerCount(); ++i) { | ||
@@ -1219,7 +1231,7 @@ | ||
|
||
// tablet methods | ||
public static native boolean isTabletEventSupported(); | ||
- public static native void tabletEvent(int winId, int deviceId, long time, int action, int pointerType, int buttonState, float x, float y, float pressure); | ||
+ public static native void tabletEvent(int winId, int deviceId, long time, int action, int pointerType, int buttonState, float x, float y, float pressure, int xtilt, int ytilt); | ||
// tablet methods | ||
|
||
// keyboard methods | ||
--- a/src/plugins/platforms/android/androidjniinput.cpp | ||
+++ b/src/plugins/platforms/android/androidjniinput.cpp | ||
@@ -327,7 +327,8 @@ | ||
} | ||
|
||
static void tabletEvent(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint deviceId, jlong time, jint action, | ||
- jint pointerType, jint buttonState, jfloat x, jfloat y, jfloat pressure) | ||
+ jint pointerType, jint buttonState, jfloat x, jfloat y, jfloat pressure, | ||
+ jint xtilt, jint ytilt) | ||
{ | ||
#if QT_CONFIG(tabletevent) | ||
QPointF globalPosF(x, y); | ||
@@ -365,12 +366,13 @@ | ||
} | ||
|
||
#ifdef QT_DEBUG_ANDROID_STYLUS | ||
- qDebug() << action << pointerType << buttonState << '@' << x << y << "pressure" << pressure << ": buttons" << buttons; | ||
+ qDebug() << action << pointerType << buttonState << '@' << x << y << "pressure" << pressure << "tilt" << xtilt << ytilt << ": buttons" << buttons; | ||
#endif | ||
|
||
QWindowSystemInterface::handleTabletEvent(tlw, ulong(time), | ||
localPos, globalPosF, QTabletEvent::Stylus, pointerType, | ||
- buttons, pressure, 0, 0, 0., 0., 0, deviceId, Qt::NoModifier); | ||
+ buttons, pressure, qBound(-60, xtilt, 60), qBound(-60, ytilt, 60), | ||
+ 0., 0., 0, deviceId, Qt::NoModifier); | ||
#endif // QT_CONFIG(tabletevent) | ||
} | ||
|
||
@@ -875,7 +877,7 @@ | ||
{"mouseWheel", "(IIIFF)V", (void *)mouseWheel}, | ||
{"longPress", "(III)V", (void *)longPress}, | ||
{"isTabletEventSupported", "()Z", (void *)isTabletEventSupported}, | ||
- {"tabletEvent", "(IIJIIIFFF)V", (void *)tabletEvent}, | ||
+ {"tabletEvent", "(IIJIIIFFFII)V", (void *)tabletEvent}, | ||
{"keyDown", "(IIIZ)V", (void *)keyDown}, | ||
{"keyUp", "(IIIZ)V", (void *)keyUp}, | ||
{"keyboardVisibilityChanged", "(Z)V", (void *)keyboardVisibilityChanged}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters