mirror of
https://github.com/leozide/leocad
synced 2024-12-26 21:58:44 +01:00
macOS mouse gestures experiment
This commit is contained in:
parent
7716ffb6e6
commit
8ad29ad99c
4 changed files with 90 additions and 0 deletions
|
@ -2934,3 +2934,31 @@ void lcView::OnMouseWheel(float Direction)
|
|||
|
||||
mModel->Zoom(mCamera, static_cast<int>(Direction * Scale));
|
||||
}
|
||||
|
||||
void lcView::OnZoomNativeGesture(float Value)
|
||||
{
|
||||
float Scale = 10.0f;
|
||||
|
||||
mModel->Zoom(mCamera, static_cast<int>(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));
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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<QNativeGestureEvent *>(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<QWheelEvent *>(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)
|
||||
|
|
|
@ -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<lcView> mView;
|
||||
QSize mPreferredSize;
|
||||
int mWheelAccumulator = 0;
|
||||
float mNativeGestureAccumulator = 0;
|
||||
int mx0 = 0;
|
||||
int my0 = 0;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue