refactor: Move sketch mode camera animations to Camera class
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
108
src/Camera.cpp
108
src/Camera.cpp
@@ -1,6 +1,9 @@
|
||||
#include "Camera.h"
|
||||
#include "ViewportWidget.h"
|
||||
#include <QApplication>
|
||||
#include <QWheelEvent>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QParallelAnimationGroup>
|
||||
|
||||
Camera::Camera(QObject *parent) : QObject(parent)
|
||||
{
|
||||
@@ -109,3 +112,108 @@ void Camera::restoreState()
|
||||
setPanY(m_savedPanY);
|
||||
setZoom(m_savedZoom);
|
||||
}
|
||||
|
||||
void Camera::animateToPlaneView(int plane)
|
||||
{
|
||||
float targetXRot = xRotation();
|
||||
float targetYRot = yRotation();
|
||||
switch (static_cast<ViewportWidget::SketchPlane>(plane)) {
|
||||
case ViewportWidget::SketchPlane::XY: // Top view
|
||||
targetXRot = 90 * 16;
|
||||
targetYRot = 0;
|
||||
break;
|
||||
case ViewportWidget::SketchPlane::XZ: // Front view
|
||||
targetXRot = 0;
|
||||
targetYRot = 0;
|
||||
break;
|
||||
case ViewportWidget::SketchPlane::YZ: // Right view
|
||||
targetXRot = 0;
|
||||
targetYRot = -90 * 16;
|
||||
break;
|
||||
case ViewportWidget::SketchPlane::NONE:
|
||||
break;
|
||||
}
|
||||
|
||||
auto* animGroup = new QParallelAnimationGroup(this);
|
||||
|
||||
auto* xRotAnim = new QPropertyAnimation(this, "xRotation");
|
||||
xRotAnim->setDuration(300);
|
||||
xRotAnim->setStartValue(xRotation());
|
||||
xRotAnim->setEndValue(targetXRot);
|
||||
xRotAnim->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
animGroup->addAnimation(xRotAnim);
|
||||
|
||||
auto* yRotAnim = new QPropertyAnimation(this, "yRotation");
|
||||
yRotAnim->setDuration(300);
|
||||
yRotAnim->setStartValue(yRotation());
|
||||
yRotAnim->setEndValue(targetYRot);
|
||||
yRotAnim->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
animGroup->addAnimation(yRotAnim);
|
||||
|
||||
auto* panXAnim = new QPropertyAnimation(this, "panX");
|
||||
panXAnim->setDuration(300);
|
||||
panXAnim->setStartValue(panX());
|
||||
panXAnim->setEndValue(0.0f);
|
||||
panXAnim->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
animGroup->addAnimation(panXAnim);
|
||||
|
||||
auto* panYAnim = new QPropertyAnimation(this, "panY");
|
||||
panYAnim->setDuration(300);
|
||||
panYAnim->setStartValue(panY());
|
||||
panYAnim->setEndValue(0.0f);
|
||||
panYAnim->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
animGroup->addAnimation(panYAnim);
|
||||
|
||||
auto* zoomAnim = new QPropertyAnimation(this, "zoom");
|
||||
zoomAnim->setDuration(300);
|
||||
zoomAnim->setStartValue(zoom());
|
||||
zoomAnim->setEndValue(-20.0f);
|
||||
zoomAnim->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
animGroup->addAnimation(zoomAnim);
|
||||
|
||||
animGroup->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
}
|
||||
|
||||
void Camera::animateRestoreState()
|
||||
{
|
||||
auto* animGroup = new QParallelAnimationGroup(this);
|
||||
|
||||
auto* xRotAnim = new QPropertyAnimation(this, "xRotation");
|
||||
xRotAnim->setDuration(300);
|
||||
xRotAnim->setStartValue(xRotation());
|
||||
xRotAnim->setEndValue(savedXRot());
|
||||
xRotAnim->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
animGroup->addAnimation(xRotAnim);
|
||||
|
||||
auto* yRotAnim = new QPropertyAnimation(this, "yRotation");
|
||||
yRotAnim->setDuration(300);
|
||||
yRotAnim->setStartValue(yRotation());
|
||||
yRotAnim->setEndValue(savedYRot());
|
||||
yRotAnim->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
animGroup->addAnimation(yRotAnim);
|
||||
|
||||
auto* panXAnim = new QPropertyAnimation(this, "panX");
|
||||
panXAnim->setDuration(300);
|
||||
panXAnim->setStartValue(panX());
|
||||
panXAnim->setEndValue(savedPanX());
|
||||
panXAnim->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
animGroup->addAnimation(panXAnim);
|
||||
|
||||
auto* panYAnim = new QPropertyAnimation(this, "panY");
|
||||
panYAnim->setDuration(300);
|
||||
panYAnim->setStartValue(panY());
|
||||
panYAnim->setEndValue(savedPanY());
|
||||
panYAnim->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
animGroup->addAnimation(panYAnim);
|
||||
|
||||
auto* zoomAnim = new QPropertyAnimation(this, "zoom");
|
||||
zoomAnim->setDuration(300);
|
||||
zoomAnim->setStartValue(zoom());
|
||||
zoomAnim->setEndValue(savedZoom());
|
||||
zoomAnim->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
animGroup->addAnimation(zoomAnim);
|
||||
|
||||
connect(animGroup, &QParallelAnimationGroup::finished, this, &Camera::restoreStateAnimationFinished);
|
||||
|
||||
animGroup->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user