From 4493b90224f575e5570afeb1ec181be5c4e74b09 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Tue, 2 Feb 2021 12:23:23 +0200 Subject: [PATCH] Android: fix compiler warnings for Android input QPointingDevice requires using the constructor to set its settings in Qt 6. Replace + with | operator and return QKeyCombination instead of int. Change-Id: Id3da469cc13b34ec7b55afa751dbc04601880df6 Reviewed-by: Volker Hilsheimer --- .../platforms/android/androidjniinput.cpp | 64 ++++++++++--------- .../platforms/android/androidjniinput.h | 3 +- .../android/qandroidinputcontext.cpp | 6 +- .../android/qandroidplatformintegration.cpp | 36 +++++++---- 4 files changed, 61 insertions(+), 48 deletions(-) diff --git a/src/plugins/platforms/android/androidjniinput.cpp b/src/plugins/platforms/android/androidjniinput.cpp index a72682dd23..1de25b2857 100644 --- a/src/plugins/platforms/android/androidjniinput.cpp +++ b/src/plugins/platforms/android/androidjniinput.cpp @@ -274,13 +274,15 @@ namespace QtAndroidInput return; QPointingDevice *touchDevice = platformIntegration->touchDevice(); - if (touchDevice == 0) { - touchDevice = new QPointingDevice; // TODO fill out the constructor args - touchDevice->setType(QInputDevice::DeviceType::TouchScreen); - touchDevice->setCapabilities(QPointingDevice::Capability::Position - | QPointingDevice::Capability::Area - | QPointingDevice::Capability::Pressure - | QPointingDevice::Capability::NormalizedPosition); + if (!touchDevice) { + touchDevice = new QPointingDevice("Android touchscreen", 1, + QInputDevice::DeviceType::TouchScreen, + QPointingDevice::PointerType::Finger, + QPointingDevice::Capability::Position + | QPointingDevice::Capability::Area + | QPointingDevice::Capability::Pressure + | QPointingDevice::Capability::NormalizedPosition, + 10, 0); QWindowSystemInterface::registerInputDevice(touchDevice); platformIntegration->setTouchDevice(touchDevice); } @@ -346,23 +348,23 @@ namespace QtAndroidInput #endif // QT_CONFIG(tabletevent) } - static int mapAndroidKey(int key) + static QKeyCombination mapAndroidKey(int key) { // 0--9 0x00000007 -- 0x00000010 if (key >= 0x00000007 && key <= 0x00000010) - return Qt::Key_0 + key - 0x00000007; + return QKeyCombination::fromCombined(Qt::Key_0 + key - 0x00000007); // A--Z 0x0000001d -- 0x00000036 if (key >= 0x0000001d && key <= 0x00000036) - return Qt::Key_A + key - 0x0000001d; + return QKeyCombination::fromCombined(Qt::Key_A + key - 0x0000001d); // F1--F12 0x00000083 -- 0x0000008e if (key >= 0x00000083 && key <= 0x0000008e) - return Qt::Key_F1 + key - 0x00000083; + return QKeyCombination::fromCombined(Qt::Key_F1 + key - 0x00000083); // NUMPAD_0--NUMPAD_9 0x00000090 -- 0x00000099 if (key >= 0x00000090 && key <= 0x00000099) - return Qt::KeypadModifier + Qt::Key_0 + key - 0x00000090; + return QKeyCombination::fromCombined(Qt::KeypadModifier | Qt::Key_0 + key - 0x00000090); // BUTTON_1--KEYCODE_BUTTON_16 0x000000bc -- 0x000000cb @@ -496,7 +498,7 @@ namespace QtAndroidInput return Qt::Key_Alt; case 0x0000004f: // KEYCODE_HEADSETHOOK - return 0; + return QKeyCombination::fromCombined(0); case 0x00000050: // KEYCODE_FOCUS return Qt::Key_CameraFocus; @@ -508,7 +510,7 @@ namespace QtAndroidInput return Qt::Key_Menu; case 0x00000053: // KEYCODE_NOTIFICATION - return 0; + return QKeyCombination::fromCombined(0); case 0x00000054: // KEYCODE_SEARCH return Qt::Key_Search; @@ -541,7 +543,7 @@ namespace QtAndroidInput return Qt::Key_PageDown; case 0x0000005e: // KEYCODE_PICTSYMBOLS - return 0; + return QKeyCombination::fromCombined(0); case 0x00000060: // KEYCODE_BUTTON_A case 0x00000061: // KEYCODE_BUTTON_B @@ -558,7 +560,7 @@ namespace QtAndroidInput case 0x0000006c: // KEYCODE_BUTTON_START case 0x0000006d: // KEYCODE_BUTTON_SELECT case 0x0000006e: // KEYCODE_BUTTON_MODE - return 0; + return QKeyCombination::fromCombined(0); case 0x0000006f: // KEYCODE_ESCAPE return Qt::Key_Escape; @@ -581,7 +583,7 @@ namespace QtAndroidInput return Qt::Key_Meta; case 0x00000077: // KEYCODE_FUNCTION - return 0; + return QKeyCombination::fromCombined(0); case 0x00000078: // KEYCODE_SYSRQ return Qt::Key_Print; @@ -622,28 +624,28 @@ namespace QtAndroidInput // NUMPAD_0--NUMPAD_9 0x00000090 -- 0x00000099 case 0x0000009a: // KEYCODE_NUMPAD_DIVIDE - return Qt::KeypadModifier + Qt::Key_Slash; + return Qt::KeypadModifier | Qt::Key_Slash; case 0x0000009b: // KEYCODE_NUMPAD_MULTIPLY - return Qt::KeypadModifier + Qt::Key_Asterisk; + return Qt::KeypadModifier | Qt::Key_Asterisk; case 0x0000009c: // KEYCODE_NUMPAD_SUBTRACT - return Qt::KeypadModifier + Qt::Key_Minus; + return Qt::KeypadModifier | Qt::Key_Minus; case 0x0000009d: // KEYCODE_NUMPAD_ADD - return Qt::KeypadModifier + Qt::Key_Plus; + return Qt::KeypadModifier | Qt::Key_Plus; case 0x0000009e: // KEYCODE_NUMPAD_DOT - return Qt::KeypadModifier + Qt::Key_Period; + return Qt::KeypadModifier | Qt::Key_Period; case 0x0000009f: // KEYCODE_NUMPAD_COMMA - return Qt::KeypadModifier + Qt::Key_Comma; + return Qt::KeypadModifier | Qt::Key_Comma; case 0x000000a0: // KEYCODE_NUMPAD_ENTER return Qt::Key_Enter; case 0x000000a1: // KEYCODE_NUMPAD_EQUALS - return Qt::KeypadModifier + Qt::Key_Equal; + return Qt::KeypadModifier | Qt::Key_Equal; case 0x000000a2: // KEYCODE_NUMPAD_LEFT_PAREN return Qt::Key_ParenLeft; @@ -671,13 +673,13 @@ namespace QtAndroidInput case 0x000000aa: // KEYCODE_TV case 0x000000ab: // KEYCODE_WINDOW - return 0; + return QKeyCombination::fromCombined(0); case 0x000000ac: // KEYCODE_GUIDE return Qt::Key_Guide; case 0x000000ad: // KEYCODE_DVR - return 0; + return QKeyCombination::fromCombined(0); case 0x000000ae: // KEYCODE_BOOKMARK return Qt::Key_AddFavorite; @@ -694,7 +696,7 @@ namespace QtAndroidInput case 0x000000b4: // KEYCODE_STB_INPUT case 0x000000b5: // KEYCODE_AVR_POWER case 0x000000b6: // KEYCODE_AVR_INPUT - return 0; + return QKeyCombination::fromCombined(0); case 0x000000b7: // KEYCODE_PROG_RED return Qt::Key_Red; @@ -716,7 +718,7 @@ namespace QtAndroidInput case 0x000000cd: // KEYCODE_MANNER_MODE do we need such a thing? case 0x000000ce: // KEYCODE_3D_MODE case 0x000000cf: // KEYCODE_CONTACTS - return 0; + return QKeyCombination::fromCombined(0); case 0x000000d0: // KEYCODE_CALENDAR return Qt::Key_Calendar; @@ -742,7 +744,7 @@ namespace QtAndroidInput default: qWarning() << "Unhandled key code " << key << '!'; - return 0; + return QKeyCombination::fromCombined(0); } } @@ -775,7 +777,7 @@ namespace QtAndroidInput { QWindowSystemInterface::handleKeyEvent(0, QEvent::KeyPress, - mapAndroidKey(key), + mapAndroidKey(key).toCombined(), mapAndroidModifiers(modifier), toString(unicode), autoRepeat); @@ -785,7 +787,7 @@ namespace QtAndroidInput { QWindowSystemInterface::handleKeyEvent(0, QEvent::KeyRelease, - mapAndroidKey(key), + mapAndroidKey(key).toCombined(), mapAndroidModifiers(modifier), toString(unicode), autoRepeat); diff --git a/src/plugins/platforms/android/androidjniinput.h b/src/plugins/platforms/android/androidjniinput.h index cc3070c4aa..9e75f43a83 100644 --- a/src/plugins/platforms/android/androidjniinput.h +++ b/src/plugins/platforms/android/androidjniinput.h @@ -58,7 +58,8 @@ namespace QtAndroidInput // Software keyboard support // cursor/selection handles - void updateHandles(int handleCount, QPoint editMenuPos = QPoint(), uint32_t editButtons = 0, QPoint cursor = QPoint(), QPoint anchor = QPoint(), bool rtl = false); + void updateHandles(int handleCount, QPoint editMenuPos = QPoint(), uint32_t editButtons = 0, + QPoint cursor = QPoint(), QPoint anchor = QPoint(), bool rtl = false); bool registerNatives(JNIEnv *env); } diff --git a/src/plugins/platforms/android/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp index 211f0e4d95..1169452629 100644 --- a/src/plugins/platforms/android/qandroidinputcontext.cpp +++ b/src/plugins/platforms/android/qandroidinputcontext.cpp @@ -1659,9 +1659,9 @@ jboolean QAndroidInputContext::paste() void QAndroidInputContext::sendShortcut(const QKeySequence &sequence) { for (int i = 0; i < sequence.count(); ++i) { - const int keys = sequence[i]; - Qt::Key key = Qt::Key(keys & ~Qt::KeyboardModifierMask); - Qt::KeyboardModifiers mod = Qt::KeyboardModifiers(keys & Qt::KeyboardModifierMask); + const QKeyCombination keys = sequence[i]; + Qt::Key key = Qt::Key(keys.toCombined() & ~Qt::KeyboardModifierMask); + Qt::KeyboardModifiers mod = Qt::KeyboardModifiers(keys.toCombined() & Qt::KeyboardModifierMask); QKeyEvent pressEvent(QEvent::KeyPress, key, mod); QKeyEvent releaseEvent(QEvent::KeyRelease, key, mod); diff --git a/src/plugins/platforms/android/qandroidplatformintegration.cpp b/src/plugins/platforms/android/qandroidplatformintegration.cpp index 1468343831..5f90a05648 100644 --- a/src/plugins/platforms/android/qandroidplatformintegration.cpp +++ b/src/plugins/platforms/android/qandroidplatformintegration.cpp @@ -212,25 +212,35 @@ QAndroidPlatformIntegration::QAndroidPlatformIntegration(const QStringList ¶ if (touchScreen == QJniObject::getStaticField("android/content/res/Configuration", "TOUCHSCREEN_FINGER") || touchScreen == QJniObject::getStaticField("android/content/res/Configuration", "TOUCHSCREEN_STYLUS")) { - m_touchDevice = new QPointingDevice; - m_touchDevice->setType(QInputDevice::DeviceType::TouchScreen); - m_touchDevice->setCapabilities(QPointingDevice::Capability::Position - | QPointingDevice::Capability::Area - | QPointingDevice::Capability::Pressure - | QPointingDevice::Capability::NormalizedPosition); - QJniObject pm = javaActivity.callObjectMethod("getPackageManager", "()Landroid/content/pm/PackageManager;"); Q_ASSERT(pm.isValid()); + int maxTouchPoints = 1; if (pm.callMethod("hasSystemFeature","(Ljava/lang/String;)Z", - QJniObject::getStaticObjectField("android/content/pm/PackageManager", "FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND", "Ljava/lang/String;").object())) { - m_touchDevice->setMaximumTouchPoints(10); + QJniObject::getStaticObjectField("android/content/pm/PackageManager", + "FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND", + "Ljava/lang/String;").object())) { + maxTouchPoints = 10; } else if (pm.callMethod("hasSystemFeature","(Ljava/lang/String;)Z", - QJniObject::getStaticObjectField("android/content/pm/PackageManager", "FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT", "Ljava/lang/String;").object())) { - m_touchDevice->setMaximumTouchPoints(4); + QJniObject::getStaticObjectField("android/content/pm/PackageManager", + "FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT", + "Ljava/lang/String;").object())) { + maxTouchPoints = 4; } else if (pm.callMethod("hasSystemFeature","(Ljava/lang/String;)Z", - QJniObject::getStaticObjectField("android/content/pm/PackageManager", "FEATURE_TOUCHSCREEN_MULTITOUCH", "Ljava/lang/String;").object())) { - m_touchDevice->setMaximumTouchPoints(2); + QJniObject::getStaticObjectField("android/content/pm/PackageManager", + "FEATURE_TOUCHSCREEN_MULTITOUCH", + "Ljava/lang/String;").object())) { + maxTouchPoints = 2; } + + m_touchDevice = new QPointingDevice("Android touchscreen", 1, + QInputDevice::DeviceType::TouchScreen, + QPointingDevice::PointerType::Finger, + QPointingDevice::Capability::Position + | QPointingDevice::Capability::Area + | QPointingDevice::Capability::Pressure + | QPointingDevice::Capability::NormalizedPosition, + maxTouchPoints, + 0); QWindowSystemInterface::registerInputDevice(m_touchDevice); }