forked from qt-creator/qt-creator
Snap duration bar handles movement
When dragging a timeline's duration bar start, end, or center handle while shift is down, snap the movement. Task-number: QDS-1068 Change-Id: I713e27167ce358ba3e1e468b779363dd9f17b2ae Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -987,7 +987,12 @@ void TimelineBarItem::dragInit(const QRectF &rect, const QPointF &pos)
|
|||||||
void TimelineBarItem::dragCenter(QRectF rect, const QPointF &pos, qreal min, qreal max)
|
void TimelineBarItem::dragCenter(QRectF rect, const QPointF &pos, qreal min, qreal max)
|
||||||
{
|
{
|
||||||
if (validateBounds(pos.x() - rect.topLeft().x())) {
|
if (validateBounds(pos.x() - rect.topLeft().x())) {
|
||||||
rect.moveLeft(pos.x() - m_pivot);
|
qreal targetX = pos.x() - m_pivot;
|
||||||
|
if (QApplication::keyboardModifiers() & Qt::ShiftModifier) { // snapping
|
||||||
|
qreal snappedTargetFrame = timelineScene()->snap(mapFromSceneToFrame(targetX));
|
||||||
|
targetX = mapFromFrameToScene(snappedTargetFrame);
|
||||||
|
}
|
||||||
|
rect.moveLeft(targetX);
|
||||||
if (rect.topLeft().x() < min) {
|
if (rect.topLeft().x() < min) {
|
||||||
rect.moveLeft(min);
|
rect.moveLeft(min);
|
||||||
setOutOfBounds(Location::Left);
|
setOutOfBounds(Location::Left);
|
||||||
@@ -1006,7 +1011,12 @@ void TimelineBarItem::dragHandle(QRectF rect, const QPointF &pos, qreal min, qre
|
|||||||
|
|
||||||
if (isActiveHandle(Location::Left)) {
|
if (isActiveHandle(Location::Left)) {
|
||||||
if (validateBounds(pos.x() - left.topLeft().x())) {
|
if (validateBounds(pos.x() - left.topLeft().x())) {
|
||||||
rect.setLeft(pos.x() - m_pivot);
|
qreal targetX = pos.x() - m_pivot;
|
||||||
|
if (QApplication::keyboardModifiers() & Qt::ShiftModifier) { // snapping
|
||||||
|
qreal snappedTargetFrame = timelineScene()->snap(mapFromSceneToFrame(targetX));
|
||||||
|
targetX = mapFromFrameToScene(snappedTargetFrame);
|
||||||
|
}
|
||||||
|
rect.setLeft(targetX);
|
||||||
if (rect.left() < min) {
|
if (rect.left() < min) {
|
||||||
rect.setLeft(min);
|
rect.setLeft(min);
|
||||||
setOutOfBounds(Location::Left);
|
setOutOfBounds(Location::Left);
|
||||||
@@ -1017,7 +1027,12 @@ void TimelineBarItem::dragHandle(QRectF rect, const QPointF &pos, qreal min, qre
|
|||||||
}
|
}
|
||||||
} else if (isActiveHandle(Location::Right)) {
|
} else if (isActiveHandle(Location::Right)) {
|
||||||
if (validateBounds(pos.x() - right.topRight().x())) {
|
if (validateBounds(pos.x() - right.topRight().x())) {
|
||||||
rect.setRight(pos.x() - m_pivot);
|
qreal targetX = pos.x() - m_pivot;
|
||||||
|
if (QApplication::keyboardModifiers() & Qt::ShiftModifier) { // snapping
|
||||||
|
qreal snappedTargetFrame = timelineScene()->snap(mapFromSceneToFrame(targetX));
|
||||||
|
targetX = mapFromFrameToScene(snappedTargetFrame);
|
||||||
|
}
|
||||||
|
rect.setRight(targetX);
|
||||||
if (rect.right() > max) {
|
if (rect.right() > max) {
|
||||||
rect.setRight(max);
|
rect.setRight(max);
|
||||||
setOutOfBounds(Location::Right);
|
setOutOfBounds(Location::Right);
|
||||||
|
Reference in New Issue
Block a user