| 2192 | } // DopeSheetViewPrivate::computeGroupRange |
| 2193 | |
| 2194 | void |
| 2195 | DopeSheetViewPrivate::onMouseLeftButtonDrag(QMouseEvent *e) |
| 2196 | { |
| 2197 | QPointF mouseZoomCoords = zoomContext.toZoomCoordinates( e->x(), e->y() ); |
| 2198 | QPointF lastZoomCoordsOnMousePress = zoomContext.toZoomCoordinates( lastPosOnMousePress.x(), |
| 2199 | lastPosOnMousePress.y() ); |
| 2200 | QPointF lastZoomCoordsOnMouseMove = zoomContext.toZoomCoordinates( lastPosOnMouseMove.x(), |
| 2201 | lastPosOnMouseMove.y() ); |
| 2202 | double currentTime = mouseZoomCoords.x(); |
| 2203 | double dt = clampedMouseOffset(lastZoomCoordsOnMousePress.x(), currentTime); |
| 2204 | double dv = mouseZoomCoords.y() - lastZoomCoordsOnMouseMove.y(); |
| 2205 | |
| 2206 | switch (eventState) { |
| 2207 | case DopeSheetView::esMoveKeyframeSelection: { |
| 2208 | if ( (dt >= 1.0f) || (dt <= -1.0f) ) { |
| 2209 | if (gui) { |
| 2210 | gui->setDraftRenderEnabled(true); |
| 2211 | } |
| 2212 | model->moveSelectedKeysAndNodes(dt); |
| 2213 | } |
| 2214 | |
| 2215 | break; |
| 2216 | } |
| 2217 | case DopeSheetView::esTransformingKeyframesMiddleLeft: |
| 2218 | case DopeSheetView::esTransformingKeyframesMiddleRight: { |
| 2219 | if (gui) { |
| 2220 | gui->setDraftRenderEnabled(true); |
| 2221 | } |
| 2222 | bool shiftHeld = modCASIsShift(e); |
| 2223 | QPointF center; |
| 2224 | if (!shiftHeld) { |
| 2225 | if (eventState == DopeSheetView::esTransformingKeyframesMiddleLeft) { |
| 2226 | center.rx() = selectedKeysBRect.x2; |
| 2227 | } else { |
| 2228 | center.rx() = selectedKeysBRect.x1; |
| 2229 | } |
| 2230 | center.ry() = (selectedKeysBRect.y1 + selectedKeysBRect.y2) / 2.; |
| 2231 | } else { |
| 2232 | center = QPointF( (selectedKeysBRect.x1 + selectedKeysBRect.x2) / 2., (selectedKeysBRect.y1 + selectedKeysBRect.y2) / 2. ); |
| 2233 | } |
| 2234 | |
| 2235 | |
| 2236 | double sx = 1., sy = 1.; |
| 2237 | double tx = 0., ty = 0.; |
| 2238 | double oldX = mouseZoomCoords.x() - dt; |
| 2239 | double oldY = mouseZoomCoords.y() - dv; |
| 2240 | // the scale ratio is the ratio of distances to the center |
| 2241 | double prevDist = ( oldX - center.x() ) * ( oldX - center.x() ) + ( oldY - center.y() ) * ( oldY - center.y() ); |
| 2242 | if (prevDist != 0) { |
| 2243 | double dist = ( mouseZoomCoords.x() - center.x() ) * ( mouseZoomCoords.x() - center.x() ) + ( mouseZoomCoords.y() - center.y() ) * ( mouseZoomCoords.y() - center.y() ); |
| 2244 | double ratio = std::sqrt(dist / prevDist); |
| 2245 | sx *= ratio; |
| 2246 | } |
| 2247 | |
| 2248 | Transform::Matrix3x3 transform = Transform::matTransformCanonical( tx, ty, sx, sy, 0, 0, true, 0, center.x(), center.y() ); |
| 2249 | model->transformSelectedKeys(transform); |
| 2250 | break; |
| 2251 | } |
no test coverage detected