Migrate touch detection to use QInputDevice instead of QTouchDevice which no longer exists

This commit is contained in:
Kovid Goyal 2021-11-19 19:54:13 +05:30
parent 985283c4d0
commit f622d1e13c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -5,7 +5,7 @@
import os import os
from functools import lru_cache from functools import lru_cache
from qt.core import ( from qt.core import (
QApplication, QEvent, QMouseEvent, QObject, QPointF, QScroller, Qt, QTouchDevice, QApplication, QEvent, QMouseEvent, QObject, QPointF, QScroller, Qt, QInputDevice,
pyqtSignal pyqtSignal
) )
@ -13,16 +13,6 @@ from calibre.utils.monotonic import monotonic
from polyglot.builtins import itervalues from polyglot.builtins import itervalues
@lru_cache(maxsize=2)
def touch_supported():
if 'CALIBRE_NO_TOUCH' in os.environ:
return False
for dev in QTouchDevice.devices():
if dev.type() == QTouchDevice.DeviceType.TouchScreen:
return True
return False
HOLD_THRESHOLD = 1.0 # seconds HOLD_THRESHOLD = 1.0 # seconds
TAP_THRESHOLD = 50 # manhattan pixels TAP_THRESHOLD = 50 # manhattan pixels
@ -30,6 +20,16 @@ Tap, TapAndHold, Flick = 'Tap', 'TapAndHold', 'Flick'
Left, Right, Up, Down = 'Left', 'Right', 'Up', 'Down' Left, Right, Up, Down = 'Left', 'Right', 'Up', 'Down'
@lru_cache(maxsize=2)
def touch_supported():
if 'CALIBRE_NO_TOUCH' in os.environ:
return False
for dev in QInputDevice.devices():
if dev.type() == QInputDevice.DeviceType.TouchScreen:
return True
return False
class TouchPoint: class TouchPoint:
def __init__(self, tp): def __init__(self, tp):
@ -184,7 +184,7 @@ class GestureManager(QObject):
ev.ignore() ev.ignore()
return False return False
boundary = self.evmap.get(etype, None) boundary = self.evmap.get(etype, None)
if boundary is None or ev.device().type() != QTouchDevice.DeviceType.TouchScreen: if boundary is None or ev.deviceType() != QInputDevice.DeviceType.TouchScreen:
return return
self.state.update(ev, boundary=boundary) self.state.update(ev, boundary=boundary)
ev.accept() ev.accept()