diff --git a/common/lc_view.cpp b/common/lc_view.cpp index 8dd6f2e0..f418d53a 100644 --- a/common/lc_view.cpp +++ b/common/lc_view.cpp @@ -2934,3 +2934,31 @@ void lcView::OnMouseWheel(float Direction) mModel->Zoom(mCamera, static_cast(Direction * Scale)); } + +void lcView::OnZoomNativeGesture(float Value) +{ + float Scale = 10.0f; + + mModel->Zoom(mCamera, static_cast(Value * Scale)); +} + + +void lcView::OnRotateNativeGesture(float Value) +{ + lcModel* ActiveModel = GetActiveModel(); + + if (!ActiveModel) + return; + + ActiveModel->UpdateRollTool(mCamera, Value * LC_DTOR); +} + +void lcView::OnWheel(int x, int y) +{ + lcModel* ActiveModel = GetActiveModel(); + + if (!ActiveModel) + return; + + ActiveModel->UpdatePanTool(mCamera, lcVector3(x, y, 0)); +} diff --git a/common/lc_view.h b/common/lc_view.h index 7d86453b..78ff581a 100644 --- a/common/lc_view.h +++ b/common/lc_view.h @@ -223,6 +223,9 @@ public: void OnForwardButtonUp(); void OnMouseMove(); void OnMouseWheel(float Direction); + void OnZoomNativeGesture(float Value); + void OnRotateNativeGesture(float Value); + void OnWheel(int x, int y); void BeginDrag(lcDragState DragState); void EndDrag(bool Accept); diff --git a/common/lc_viewwidget.cpp b/common/lc_viewwidget.cpp index 41c88b66..d5384f0b 100644 --- a/common/lc_viewwidget.cpp +++ b/common/lc_viewwidget.cpp @@ -215,6 +215,61 @@ void lcViewWidget::mouseMoveEvent(QMouseEvent* MouseEvent) mView->OnMouseMove(); } +bool lcViewWidget::event(QEvent *event) +{ + qDebug() << "event: " << event; + QNativeGestureEvent *nativeGesture; + QWheelEvent *wheelEvent; + QPoint point; + switch (event->type()) + { + case QEvent::NativeGesture: + nativeGesture = static_cast(event); + switch (nativeGesture->gestureType()) { + case Qt::BeginNativeGesture: + mNativeGestureAccumulator = 0.0f; + break; + case Qt::ZoomNativeGesture: + mView->OnZoomNativeGesture(nativeGesture->value() * 8); + break; + case Qt::RotateNativeGesture: + qDebug() << "nativeGesture: " << nativeGesture; + mNativeGestureAccumulator += nativeGesture->value(); + mView->OnRotateNativeGesture(mNativeGestureAccumulator); + break; + case Qt::SwipeNativeGesture: + case Qt::PanNativeGesture: + case Qt::EndNativeGesture: + case Qt::SmartZoomNativeGesture: + break; + } + return true; + case QEvent::Wheel: + wheelEvent = static_cast(event); + switch (wheelEvent->phase()) + { + case Qt::ScrollBegin: + mx0 = 0; + my0 = 0; + break; + case Qt::ScrollUpdate: + case Qt::ScrollMomentum: + point = wheelEvent->pixelDelta(); + mx0 += point.x(); + my0 += point.y(); + mView->OnWheel(mx0, my0); + break; + case Qt::ScrollEnd: + case Qt::NoScrollPhase: + break; + } + return true; + + default: + return QWidget::event(event); + } +} + void lcViewWidget::wheelEvent(QWheelEvent* WheelEvent) { if (WheelEvent->angleDelta().y() == 0) diff --git a/common/lc_viewwidget.h b/common/lc_viewwidget.h index b8e849bc..3152a2f9 100644 --- a/common/lc_viewwidget.h +++ b/common/lc_viewwidget.h @@ -35,6 +35,7 @@ protected: void mouseDoubleClickEvent(QMouseEvent* MouseEvent) override; void mouseMoveEvent(QMouseEvent* MouseEvent) override; void wheelEvent(QWheelEvent* WheelEvent) override; + bool event(QEvent* event) override; void dragEnterEvent(QDragEnterEvent* DragEnterEvent) override; void dragLeaveEvent(QDragLeaveEvent* DragLeaveEvent) override; void dragMoveEvent(QDragMoveEvent* DragMoveEvent) override; @@ -43,4 +44,7 @@ protected: std::unique_ptr mView; QSize mPreferredSize; int mWheelAccumulator = 0; + float mNativeGestureAccumulator = 0; + int mx0 = 0; + int my0 = 0; };