fix: Trackpad unable for scrolling and zooming well on MacOS

This commit is contained in:
dreamsourcelabTAI 2023-07-04 17:21:06 +08:00
parent 001ec8dd49
commit 0edc9d26c0

View File

@ -1256,25 +1256,29 @@ void Viewport::wheelEvent(QWheelEvent *event)
} }
else if (_type == TIME_VIEW) else if (_type == TIME_VIEW)
{ {
static bool bLstTime = false;
if (isVertical) if (isVertical)
{ {
// Vertical scrolling is interpreted as zooming in/out // Vertical scrolling is interpreted as zooming in/out
#ifdef Q_OS_DARWIN #ifdef Q_OS_DARWIN
static bool active = true;
static int64_t last_time; static int64_t last_time;
if (event->source() == Qt::MouseEventSynthesizedBySystem) if (event->source() == Qt::MouseEventSynthesizedBySystem)
{ {
if (active) if (!bLstTime)
{ {
last_time = QDateTime::currentMSecsSinceEpoch(); last_time = QDateTime::currentMSecsSinceEpoch();
const double scale = delta > 1.5 ? 1 : (delta < -1.5 ? -1 : 0); bLstTime = true;
_view.zoom(scale, x);
} }
else{
int64_t cur_time = QDateTime::currentMSecsSinceEpoch(); int64_t cur_time = QDateTime::currentMSecsSinceEpoch();
if (cur_time - last_time > 50) if (cur_time - last_time > 50){
active = true; double scale = delta > 1.5 ? 1 : (delta < -1.5 ? -1 : 0);
else _view.zoom(scale, x);
active = false; last_time = QDateTime::currentMSecsSinceEpoch();
}
}
} }
else else
{ {
@ -1286,6 +1290,9 @@ void Viewport::wheelEvent(QWheelEvent *event)
} }
else else
{ {
bLstTime = false;
(void)bLstTime;
// Horizontal scrolling is interpreted as moving left/right // Horizontal scrolling is interpreted as moving left/right
if (!(event->modifiers() & Qt::ShiftModifier)) if (!(event->modifiers() & Qt::ShiftModifier))
_view.set_scale_offset(_view.scale(), _view.offset() - delta); _view.set_scale_offset(_view.scale(), _view.offset() - delta);