diff options
author | Shawn Rutledge <shawn.rutledge@digia.com> | 2015-03-06 16:05:20 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@digia.com> | 2015-05-21 05:17:38 +0000 |
commit | 01d78ba86a631386a4d47b7c12d2a359da28f517 (patch) | |
tree | bc50b60ff60a7d4d10b4da141e2c518812e9c240 /src/plugins/platforms/android | |
parent | e227b8ecf686bb2ace31be62e683bd76591ad7b1 (diff) |
Android: generate QTabletEvents for stylus devices such as the S Pen
For example the Galaxy Note series of devices. This makes possible
drawing applications which handle stylus events differently from touch
or mouse. As on any other platform, if the application does not accept
the QTabletEvent, a QMouseEvent will be synthesized.
Also fix the tablet manual test to show larger circles on hidpi devices.
[ChangeLog][Android] stylus devices such as the S Pen generate
QTabletEvents
Task-number: QTBUG-38379
Change-Id: Ib594f453b8403cc06aa4e440a76f07afa3bac38c
Reviewed-by: Paul Olav Tvete <paul.tvete@theqtcompany.com>
Diffstat (limited to 'src/plugins/platforms/android')
-rw-r--r-- | src/plugins/platforms/android/androidjniinput.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/plugins/platforms/android/androidjniinput.cpp b/src/plugins/platforms/android/androidjniinput.cpp index 8ee3ff88d1..be5e969d2b 100644 --- a/src/plugins/platforms/android/androidjniinput.cpp +++ b/src/plugins/platforms/android/androidjniinput.cpp @@ -238,6 +238,52 @@ namespace QtAndroidInput QWindowSystemInterface::handleTouchEvent(window, touchDevice, m_touchPoints); } + 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) + { + QPointF globalPosF(x, y); + QPoint globalPos((int)x, (int)y); + QWindow *tlw = topLevelWindowAt(globalPos); + QPointF localPos = tlw ? (globalPosF - tlw->position()) : globalPosF; + + // Galaxy Note with plain Android: + // 0 1 0 stylus press + // 2 1 0 stylus drag + // 1 1 0 stylus release + // 0 1 2 stylus press with side-button held + // 2 1 2 stylus drag with side-button held + // 1 1 2 stylus release with side-button held + // Galaxy Note 4 with Samsung firmware: + // 0 1 0 stylus press + // 2 1 0 stylus drag + // 1 1 0 stylus release + // 211 1 2 stylus press with side-button held + // 213 1 2 stylus drag with side-button held + // 212 1 2 stylus release with side-button held + // when action == ACTION_UP (1) it's a release; otherwise we say which button is pressed + Qt::MouseButtons buttons = Qt::NoButton; + switch (action) { + case 1: // ACTION_UP + case 212: // stylus release while side-button held on Galaxy Note 4 + buttons = Qt::NoButton; + break; + default: // action is press or drag + if (buttonState == 0) + buttons = Qt::LeftButton; + else // 2 means RightButton + buttons = Qt::MouseButtons(buttonState); + break; + } + +#ifdef QT_DEBUG_ANDROID_STYLUS + qDebug() << action << pointerType << buttonState << "@" << x << y << "pressure" << pressure << ": buttons" << buttons; +#endif + + QWindowSystemInterface::handleTabletEvent(tlw, ulong(time), + localPos, globalPosF, QTabletEvent::Stylus, pointerType, + buttons, pressure, 0, 0, 0., 0., 0, deviceId, Qt::NoModifier); + } + static int mapAndroidKey(int key) { // 0--9 0x00000007 -- 0x00000010 @@ -702,6 +748,7 @@ namespace QtAndroidInput {"mouseUp", "(III)V", (void *)mouseUp}, {"mouseMove", "(III)V", (void *)mouseMove}, {"longPress", "(III)V", (void *)longPress}, + {"tabletEvent", "(IIJIIIFFF)V", (void *)tabletEvent}, {"keyDown", "(IIIZ)V", (void *)keyDown}, {"keyUp", "(IIIZ)V", (void *)keyUp}, {"keyboardVisibilityChanged", "(Z)V", (void *)keyboardVisibilityChanged} |