diff --git a/src/app/GUI/keysview.cpp b/src/app/GUI/keysview.cpp index eae769813..af4a1e219 100644 --- a/src/app/GUI/keysview.cpp +++ b/src/app/GUI/keysview.cpp @@ -223,12 +223,33 @@ void KeysView::resizeEvent(QResizeEvent *e) { if(mGraphViewed) graphResizeEvent(e); } -void KeysView::wheelEvent(QWheelEvent *e) { - if(mGraphViewed) { - graphWheelEvent(e); +void KeysView::wheelEvent(QWheelEvent *e) +{ +#ifdef Q_OS_MAC + const bool alt = e->modifiers() & Qt::AltModifier; + const bool ctrl = e->modifiers() & Qt::ControlModifier; + const bool shift = e->modifiers() & Qt::ShiftModifier; + const bool noMod = !alt && !ctrl && !shift; + if (e->phase() != Qt::NoScrollPhase && noMod) { + if (e->phase() == Qt::ScrollBegin) { + mPanEvent = false; + const auto x = e->angleDelta().x(); + const auto y = e->angleDelta().y(); + if (x < 0) { + if (y > 0 || x < y || y == 0 || x == y) { mPanEvent = true; } + } else if (x > 0) { + if (y < 0 || x > y || y == 0 || x == y) { mPanEvent = true; } + } + } else if (e->phase() == Qt::ScrollEnd) { mPanEvent = false; } + //qDebug() << e->angleDelta().x() << e->angleDelta().y() << mPanEvent; + if (mPanEvent) { emit panEventSignal(e); } + } +#endif + if (mGraphViewed) { + if (!mPanEvent) { graphWheelEvent(e); } } else { - emit wheelEventSignal(e); - if(mSelecting) { + if (!mPanEvent) { emit wheelEventSignal(e); } + if (mSelecting) { const QPointF posU = mapFromGlobal(QCursor::pos()) + QPointF(-eSizesUI::widget/2, 0.); mSelectionRect.setBottom(posU.y() + mViewedTop); @@ -485,6 +506,21 @@ bool KeysView::KFT_keyPressEvent(QKeyEvent *event) return true; } +#ifdef Q_OS_MAC +bool KeysView::event(QEvent *e) +{ + if (e->type() == QEvent::NativeGesture) { + auto g = dynamic_cast(e); + if (g->gestureType() == Qt::ZoomNativeGesture || + g->gestureType() == Qt::SmartZoomNativeGesture) { + emit nativeEventSignal(g); + return true; + } + } + return QWidget::event(e); +} +#endif + void KeysView::drawKeys(QPainter * const p, const qreal pixelsPerFrame, const FrameRange &viewedFrameRange) { diff --git a/src/app/GUI/keysview.h b/src/app/GUI/keysview.h index 7a6d3edb6..3cd827c54 100644 --- a/src/app/GUI/keysview.h +++ b/src/app/GUI/keysview.h @@ -122,6 +122,10 @@ class KeysView : public QWidget, public KeyFocusTarget { QPoint mLastMovePos; +#ifdef Q_OS_MAC + bool event(QEvent *e); +#endif + void resizeEvent(QResizeEvent *e); void wheelEvent(QWheelEvent *e); void mousePressEvent(QMouseEvent *e); @@ -142,6 +146,12 @@ class KeysView : public QWidget, public KeyFocusTarget { void changedViewedFrames(FrameRange); void wheelEventSignal(QWheelEvent*); void statusMessage(const QString &message); + +#ifdef Q_OS_MAC + void nativeEventSignal(QNativeGestureEvent *e); + void panEventSignal(QWheelEvent *e); +#endif + public: static QColor sGetAnimatorColor(const int i); @@ -267,6 +277,8 @@ class KeysView : public QWidget, public KeyFocusTarget { int mSavedMinViewedFrame = 0; int mSavedMaxViewedFrame = 0; + bool mPanEvent = false; + // graph bool graph_mValueLinesVisible = true; diff --git a/src/app/GUI/timelinewidget.cpp b/src/app/GUI/timelinewidget.cpp index 63ff004fe..e2ad44269 100644 --- a/src/app/GUI/timelinewidget.cpp +++ b/src/app/GUI/timelinewidget.cpp @@ -284,6 +284,14 @@ TimelineWidget::TimelineWidget(Document &document, this, &TimelineWidget::setViewedFrameRange); connect(mKeysView, &KeysView::wheelEventSignal, mFrameRangeScrollBar, &FrameScrollBar::callWheelEvent); + +#ifdef Q_OS_MAC + connect(mKeysView, &KeysView::panEventSignal, + mFrameRangeScrollBar, &FrameScrollBar::callPanEvent); + connect(mKeysView, &KeysView::nativeEventSignal, + mFrameRangeScrollBar, &FrameScrollBar::callNativeGestures); +#endif + mKeysViewLayout->addWidget(mFrameRangeScrollBar); //mSceneChooser->setCurrentScene(mDocument.fActiveScene); // why? diff --git a/src/ui/widgets/framescrollbar.cpp b/src/ui/widgets/framescrollbar.cpp index 77f4d95ad..19c0d8c30 100644 --- a/src/ui/widgets/framescrollbar.cpp +++ b/src/ui/widgets/framescrollbar.cpp @@ -546,6 +546,48 @@ void FrameScrollBar::callWheelEvent(QWheelEvent *event) update(); } +#ifdef Q_OS_MAC +void FrameScrollBar::callNativeGestures(QNativeGestureEvent *e) +{ + if (!e || !mRange) { return; } + bool triggered = false; + + if (e->gestureType() == Qt::ZoomNativeGesture) { + int newFramesSpan = mViewedFramesSpan; + if (e->value() < 0) { newFramesSpan *= 0.85; } + else { newFramesSpan *= 1.15; } + setFramesSpan(newFramesSpan); + triggered = true; + } else if (e->gestureType() == Qt::SmartZoomNativeGesture) { + setFramesSpan(mFrameRange.EMAX); + triggered = true; + } + + if (!triggered) { return; } + emitTriggeredChange(); + update(); +} + +void FrameScrollBar::callPanEvent(QWheelEvent *e) +{ + if (!e || !mRange) { return; } + bool triggered = false; + + if (e->angleDelta().x() == 0) { return; } + if (e->angleDelta().x() > 0) { + setFirstViewedFrame(mFirstViewedFrame - mViewedFramesSpan / 20); + triggered = true; + } else { + setFirstViewedFrame(mFirstViewedFrame + mViewedFramesSpan / 20); + triggered = true; + } + + if (!triggered) { return; } + emitTriggeredChange(); + update(); +} +#endif + void FrameScrollBar::emitChange() { emit frameRangeChange(getViewedRange()); } diff --git a/src/ui/widgets/framescrollbar.h b/src/ui/widgets/framescrollbar.h index 8d6e84973..02d1bcbe0 100644 --- a/src/ui/widgets/framescrollbar.h +++ b/src/ui/widgets/framescrollbar.h @@ -82,6 +82,11 @@ class UI_EXPORT FrameScrollBar : public QWidget void setCanvasFrameRange(const FrameRange& range); void callWheelEvent(QWheelEvent *event); +#ifdef Q_OS_MAC + void callNativeGestures(QNativeGestureEvent *e); + void callPanEvent(QWheelEvent *e); +#endif + protected: qreal posToFrame(int xPos); void paintEvent(QPaintEvent *);