|
64 | 64 |
|
65 | 65 | using namespace Friction::Core; |
66 | 66 |
|
| 67 | +namespace { |
| 68 | +constexpr qreal kDegToRad = static_cast<qreal>(0.017453292519943295769); |
| 69 | +constexpr qreal kRadToDeg = static_cast<qreal>(57.2957795130823208768); |
| 70 | +} |
| 71 | + |
67 | 72 | void Canvas::handleMovePathMousePressEvent(const eMouseEvent& e) |
68 | 73 | { |
69 | 74 | mPressedBox = mCurrentContainer->getBoxAt(e.fPos); |
@@ -212,6 +217,7 @@ void Canvas::handleLeftButtonMousePress(const eMouseEvent& e) |
212 | 217 | //mMovesToSkip = 2; |
213 | 218 | mStartTransform = true; |
214 | 219 | mHasCreationPressPos = false; |
| 220 | + mLastPointMoveBy = QPointF(); |
215 | 221 |
|
216 | 222 | const qreal invScale = 1/e.fScale; |
217 | 223 | const qreal invScaleUi = (qApp ? qApp->devicePixelRatio() : 1.0) * invScale; |
@@ -710,44 +716,72 @@ void Canvas::handleMovePointMouseMove(const eMouseEvent &e) |
710 | 716 | } |
711 | 717 | } |
712 | 718 |
|
| 719 | + QPointF moveBy = getMoveByValueForEvent(e); |
| 720 | + QPointF finalMoveBy = moveBy; |
| 721 | + if ((mods & Qt::ShiftModifier) && mPressedPoint->isCtrlPoint()) { |
| 722 | + const auto ctrlPoint = enve_cast<SmartCtrlPoint*>(mPressedPoint.data()); |
| 723 | + if (ctrlPoint) { |
| 724 | + const auto parentPoint = ctrlPoint->getParentPoint(); |
| 725 | + if (parentPoint) { |
| 726 | + const QPointF parentAbs = parentPoint->getAbsolutePos(); |
| 727 | + const QPointF startAbs = ctrlPoint->getAbsolutePos() - mLastPointMoveBy; |
| 728 | + QPointF targetAbs = startAbs + moveBy; |
| 729 | + const QPointF dir = targetAbs - parentAbs; |
| 730 | + const qreal len = pointToLen(dir); |
| 731 | + if (len > 0.0) { |
| 732 | + constexpr qreal snapStep = 15.0; |
| 733 | + const qreal angleDeg = std::atan2(dir.y(), dir.x()) * kRadToDeg; |
| 734 | + const qreal snappedDeg = std::round(angleDeg / snapStep) * snapStep; |
| 735 | + const qreal snappedRad = snappedDeg * kDegToRad; |
| 736 | + const QPointF snappedVec(len * std::cos(snappedRad), |
| 737 | + len * std::sin(snappedRad)); |
| 738 | + targetAbs = parentAbs + snappedVec; |
| 739 | + finalMoveBy = targetAbs - startAbs; |
| 740 | + } |
| 741 | + } |
| 742 | + } |
| 743 | + } |
| 744 | + |
713 | 745 | if (!mPressedPoint->selectionEnabled()) { |
714 | 746 | if (mStartTransform) { |
715 | 747 | mPressedPoint->startTransform(); |
716 | 748 | mGridMoveStartPivot = mPressedPoint->getAbsolutePos(); |
717 | 749 | } |
718 | | - |
719 | | - auto moveBy = getMoveByValueForEvent(e); |
720 | 750 | if (snappingActive) { |
721 | 751 | const auto snapped = moveBySnapTargets(e.fModifiers, |
722 | | - moveBy, |
| 752 | + finalMoveBy, |
723 | 753 | gridSettings, |
724 | 754 | includeSelectedBounds, |
725 | 755 | false, |
726 | 756 | false); |
727 | | - if (snapped.first) { moveBy = snapped.second; } |
| 757 | + if (snapped.first) { finalMoveBy = snapped.second; } |
728 | 758 | } |
729 | 759 |
|
730 | | - mPressedPoint->moveByAbs(moveBy); |
| 760 | + mPressedPoint->moveByAbs(finalMoveBy); |
| 761 | + mLastPointMoveBy = finalMoveBy; |
731 | 762 | return; |
732 | 763 | } |
733 | | - } |
734 | 764 |
|
735 | | - if (mStartTransform && !mSelectedPoints_d.isEmpty()) { |
736 | | - mGridMoveStartPivot = getSelectedPointsAbsPivotPos(); |
737 | | - } |
| 765 | + if (mStartTransform && !mSelectedPoints_d.isEmpty()) { |
| 766 | + mGridMoveStartPivot = getSelectedPointsAbsPivotPos(); |
| 767 | + } |
| 768 | + if (snappingActive && !mSelectedPoints_d.isEmpty()) { |
| 769 | + const auto snapped = moveBySnapTargets(e.fModifiers, |
| 770 | + finalMoveBy, |
| 771 | + gridSettings, |
| 772 | + includeSelectedBounds, |
| 773 | + false, |
| 774 | + false); |
| 775 | + if (snapped.first) { finalMoveBy = snapped.second; } |
| 776 | + } |
738 | 777 |
|
739 | | - auto moveBy = getMoveByValueForEvent(e); |
740 | | - if (snappingActive && !mSelectedPoints_d.isEmpty()) { |
741 | | - const auto snapped = moveBySnapTargets(e.fModifiers, |
742 | | - moveBy, |
743 | | - gridSettings, |
744 | | - includeSelectedBounds, |
745 | | - false, |
746 | | - false); |
747 | | - if (snapped.first) { moveBy = snapped.second; } |
| 778 | + moveSelectedPointsByAbs(finalMoveBy, mStartTransform); |
| 779 | + mLastPointMoveBy = finalMoveBy; |
| 780 | + } else { |
| 781 | + const QPointF moveBy = getMoveByValueForEvent(e); |
| 782 | + moveSelectedPointsByAbs(moveBy, mStartTransform); |
| 783 | + mLastPointMoveBy = moveBy; |
748 | 784 | } |
749 | | - |
750 | | - moveSelectedPointsByAbs(moveBy, mStartTransform); |
751 | 785 | } |
752 | 786 | } |
753 | 787 |
|
@@ -894,6 +928,7 @@ bool Canvas::prepareRotation(const QPointF &startPos, |
894 | 928 | mTransMode = TransformMode::rotate; |
895 | 929 | mRotHalfCycles = 0; |
896 | 930 | mLastDRot = 0; |
| 931 | + mLastPointMoveBy = QPointF(); |
897 | 932 |
|
898 | 933 | mDoubleClick = false; |
899 | 934 | mStartTransform = true; |
|
0 commit comments