From c0d36939b9c559249d2d2efcd8e0b80f1a76234a Mon Sep 17 00:00:00 2001 From: Mahmoud Badri Date: Mon, 25 Feb 2019 15:01:56 +0200 Subject: Fix timeline snap issue - Moving a timeline row duration bar or one of its ends while snapping, was offset by duration edge (15px). Fixed. Also changed a timeline row start_x and end_x to start at 0 instead of RULER_EDGE_OFFSET as part of the fix. - Assorted tweaks. Task-number: QT3DS-3102 Change-Id: Id8974ed0dcc05f4b32ffd89e81a36bf1afe65f75 Reviewed-by: Miikka Heikkinen --- .../TimelineGraphicsView/KeyframeManager.cpp | 18 +-- .../TimelineGraphicsView/TimelineGraphicsScene.cpp | 51 ++++----- .../TimelineGraphicsView/TimelineGraphicsScene.h | 2 +- .../TimelineGraphicsView/ui/RowTimeline.cpp | 124 +++++++++++---------- .../Palettes/TimelineGraphicsView/ui/RowTimeline.h | 2 - .../Palettes/TimelineGraphicsView/ui/Ruler.cpp | 13 --- .../Palettes/TimelineGraphicsView/ui/Ruler.h | 2 - 7 files changed, 90 insertions(+), 122 deletions(-) diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.cpp index 57694a29..9a12aab3 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.cpp @@ -30,13 +30,8 @@ #include "RowTree.h" #include "RowTimeline.h" #include "Keyframe.h" -#include "RowTypes.h" -#include "TimelineConstants.h" -#include "Ruler.h" -#include "PlayHead.h" #include "RowManager.h" #include "TimelineGraphicsScene.h" -#include "StudioObjectTypes.h" #include "StudioApp.h" #include "Core.h" #include "Doc.h" @@ -44,20 +39,12 @@ #include "CmdDataModelRemoveKeyframe.h" #include "CmdDataModelInsertKeyframe.h" #include "CmdDataModelChangeKeyframe.h" -#include "Qt3DSDMAnimation.h" #include "ClientDataModelBridge.h" -#include "Bindings/ITimelineItemBinding.h" #include "Bindings/OffsetKeyframesCommandHelper.h" -#include "Bindings/Qt3DSDMTimelineKeyframe.h" +#include "Bindings/PasteKeyframesCommandHelper.h" #include "StudioPreferences.h" -#include "Qt3DSDMAnimation.h" #include "Dialogs.h" #include "TimeEnums.h" -#include "Bindings/PasteKeyframesCommandHelper.h" - -#include -#include -#include using namespace qt3dsdm; @@ -86,9 +73,8 @@ QList KeyframeManager::insertKeyframe(RowTimeline *row, long time, } if (!propRows.empty()) { - Keyframe *keyframe = nullptr; for (const auto &r : qAsConst(propRows)) { - keyframe = new Keyframe(time, r); + Keyframe *keyframe = new Keyframe(time, r); r->insertKeyframe(keyframe); r->parentRow()->insertKeyframe(keyframe); addedKeyframes.append(keyframe); diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp index 6fab4e3e..7f608683 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp @@ -80,16 +80,15 @@ TimelineGraphicsScene::TimelineGraphicsScene(TimelineWidget *timelineWidget) , m_layoutTimeline(new QGraphicsLinearLayout(Qt::Vertical)) , m_ruler(new Ruler) , m_playHead(new PlayHead(m_ruler)) - , m_selectionRect(new SelectionRect()) - , m_rowMover(new RowMover(this)) , m_widgetTimeline(timelineWidget) , m_widgetRoot(new QGraphicsWidget) + , m_rowMover(new RowMover(this)) + , m_selectionRect(new SelectionRect()) , m_rowManager(new RowManager(this, m_layoutTree, m_layoutTimeline)) , m_keyframeManager(new KeyframeManager(this)) , m_pressPos(invalidPoint) , m_pressScreenPos(invalidPoint) , m_timelineControl(new TimelineControl(this)) - , m_currentCursor(-1) { addItem(m_playHead); addItem(m_selectionRect); @@ -164,8 +163,7 @@ TimelineGraphicsScene::TimelineGraphicsScene(TimelineWidget *timelineWidget) } if (m_selectionRect->isActive()) { - p -= QPoint(0, m_widgetTimeline->navigationBar()->height() - + TimelineConstants::ROW_H); + p -= QPoint(0, m_widgetTimeline->navigationBar()->height() + TimelineConstants::ROW_H); const double bottom = timelineContent->contentsRect().height() - scrollBarOffsets.y(); if (m_lastAutoScrollX != p.x() || p.x() <= 0 || p.x() >= right || m_lastAutoScrollY != p.y() || p.y() <= 0 || p.y() >= bottom) { @@ -200,7 +198,7 @@ TimelineGraphicsScene::TimelineGraphicsScene(TimelineWidget *timelineWidget) if (scroll != 0) scroll -= TimelineConstants::TREE_BOUND_W; - double distance = p.x() + scroll; + double distance = p.x() + scroll - TimelineConstants::RULER_EDGE_OFFSET; if (m_clickedTimelineControlType == TimelineControlType::Duration && !m_editedTimelineRow.isNull()) { distance -= m_editedTimelineRow->getDurationMoveOffsetX(); @@ -210,8 +208,7 @@ TimelineGraphicsScene::TimelineGraphicsScene(TimelineWidget *timelineWidget) snap(distance, !m_rulerPressed); if (m_rulerPressed) { - long time = m_ruler->distanceToTime( - distance - TimelineConstants::RULER_EDGE_OFFSET); + long time = m_ruler->distanceToTime(distance); if (time < 0) time = 0; g_StudioApp.GetCore()->GetDoc()->NotifyTimeChanged(time); @@ -223,22 +220,21 @@ TimelineGraphicsScene::TimelineGraphicsScene(TimelineWidget *timelineWidget) if (m_dragging) { if (m_clickedTimelineControlType == TimelineControlType::StartHandle) { - double visiblePtX = distance > TimelineConstants::RULER_EDGE_OFFSET - ? m_editedTimelineRow->getStartX() : 0; + double visiblePtX = distance > 0 ? m_editedTimelineRow->getStartX() : 0; if (distance > m_editedTimelineRow->getEndX()) visiblePtX += TimelineConstants::RULER_EDGE_OFFSET; m_editedTimelineRow->setStartX(distance); m_editedTimelineRow->showToolTip(QCursor::pos()); - timelineContent->ensureVisible(TimelineConstants::TREE_BOUND_W + visiblePtX, + timelineContent->ensureVisible(TimelineConstants::TREE_BOUND_W + + TimelineConstants::RULER_EDGE_OFFSET + + visiblePtX, m_editedTimelineRow->y(), 0, 0, 0, 0); } else if (m_clickedTimelineControlType == TimelineControlType::EndHandle) { - long time = m_ruler->distanceToTime( - distance - TimelineConstants::RULER_EDGE_OFFSET); + long time = m_ruler->distanceToTime(distance); double edgeMargin = 0; if (time > TimelineConstants::MAX_SLIDE_TIME) { - distance = m_ruler->timeToDistance(TimelineConstants::MAX_SLIDE_TIME) - + TimelineConstants::RULER_EDGE_OFFSET; + distance = m_ruler->timeToDistance(TimelineConstants::MAX_SLIDE_TIME); edgeMargin = TimelineConstants::RULER_EDGE_OFFSET; } else if (time < m_editedTimelineRow->getStartTime()) { edgeMargin = -TimelineConstants::RULER_EDGE_OFFSET; @@ -248,18 +244,17 @@ TimelineGraphicsScene::TimelineGraphicsScene(TimelineWidget *timelineWidget) rowManager()->updateRulerDuration(p.x() > right); timelineContent->ensureVisible( TimelineConstants::TREE_BOUND_W + + TimelineConstants::RULER_EDGE_OFFSET + m_editedTimelineRow->getEndX() + edgeMargin, m_editedTimelineRow->y(), 0, 0, 0, 0); } else if (m_clickedTimelineControlType == TimelineControlType::Duration) { - long time = m_ruler->distanceToTime( - distance - TimelineConstants::RULER_EDGE_OFFSET) - + m_editedTimelineRow->getDuration(); // milliseconds + long time = m_ruler->distanceToTime(distance) + + m_editedTimelineRow->getDuration(); // milliseconds double visiblePtX = distance + m_editedTimelineRow->getDurationMoveOffsetX(); if (time > TimelineConstants::MAX_SLIDE_TIME) { distance = m_ruler->timeToDistance(TimelineConstants::MAX_SLIDE_TIME - - m_editedTimelineRow->getDuration()) - + TimelineConstants::RULER_EDGE_OFFSET; + - m_editedTimelineRow->getDuration()); visiblePtX = m_editedTimelineRow->getEndX() + TimelineConstants::RULER_EDGE_OFFSET; } @@ -268,7 +263,8 @@ TimelineGraphicsScene::TimelineGraphicsScene(TimelineWidget *timelineWidget) m_editedTimelineRow->showToolTip(QCursor::pos()); rowManager()->updateRulerDuration(p.x() > right); timelineContent->ensureVisible( - TimelineConstants::TREE_BOUND_W + visiblePtX, + TimelineConstants::TREE_BOUND_W + + TimelineConstants::RULER_EDGE_OFFSET + visiblePtX, m_editedTimelineRow->y(), 0, 0, 0, 0); } } @@ -690,17 +686,15 @@ void TimelineGraphicsScene::stopAutoScroll() { void TimelineGraphicsScene::updateSnapSteps() { m_snapSteps.clear(); - // i = 1 is always the scene row + // i = 1 is always the scene row (or component root) for (int i = 2; i < m_layoutTimeline->count(); i++) { - RowTree *rowTree = static_cast - (m_layoutTree->itemAt(i)->graphicsItem()); + RowTree *rowTree = static_cast(m_layoutTree->itemAt(i)->graphicsItem()); if (rowTree->hasDurationBar() && rowTree->isVisible()) { - auto startX = rowTree->rowTimeline()->getStartX() - - TimelineConstants::RULER_EDGE_OFFSET; + double startX = rowTree->rowTimeline()->getStartX(); if (!m_snapSteps.contains(startX)) m_snapSteps.push_back(startX); - auto endX = rowTree->rowTimeline()->getEndX() - TimelineConstants::RULER_EDGE_OFFSET; + double endX = rowTree->rowTimeline()->getEndX(); if (!m_snapSteps.contains(endX)) m_snapSteps.push_back(endX); @@ -759,7 +753,8 @@ void TimelineGraphicsScene::snap(double &value, bool snapToPlayHead) { // snap to play head if (snapToPlayHead) { - double playHeadX = m_playHead->x() - m_ruler->x(); + double playHeadX = m_playHead->x() - TimelineConstants::TREE_BOUND_W + - TimelineConstants::RULER_EDGE_OFFSET; if (abs(value - playHeadX) < CStudioPreferences::GetSnapRange()) { value = playHeadX; return; diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.h index cfef0bae..8a41ea49 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.h +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.h @@ -142,7 +142,7 @@ private: QPointF m_pressPos; QPointF m_pressScreenPos; QList m_snapSteps; - CMouseCursor::Qt3DSMouseCursor m_currentCursor; + CMouseCursor::Qt3DSMouseCursor m_currentCursor = -1; TimelineControl *m_timelineControl = nullptr; DataInputSelectView *m_dataInputSelector = nullptr; // triggered by context menu but owned by // rowtree diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.cpp index cec42cf2..a0b689f4 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.cpp @@ -125,6 +125,8 @@ void RowTimeline::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio painter->fillRect(0, 0, size().width(), currentHeight, bgColor); } + const double edgeOffset = TimelineConstants::RULER_EDGE_OFFSET; + // Duration. Draw duration bar (for scene/component root) also if it has // datainput controller if (m_rowTree->hasDurationBar() || m_controllerDataInput.size()) { @@ -135,17 +137,17 @@ void RowTimeline::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio painter->setBrush(QBrush(CStudioPreferences::timelineRowColorDurationOff1(), Qt::BDiagPattern)); painter->setPen(Qt::NoPen); - painter->fillRect(QRect(m_startX, 0, m_endX - m_startX, currentHeight), + painter->fillRect(QRect(edgeOffset + m_startX, 0, m_endX - m_startX, currentHeight), CStudioPreferences::timelineRowColorDurationOff2()); - painter->drawRect(QRect(m_startX, 0, m_endX - m_startX, currentHeight)); + painter->drawRect(QRect(edgeOffset + m_startX, 0, m_endX - m_startX, currentHeight)); painter->setPen(QPen(CStudioPreferences::timelineRowColorDurationEdge(), 2)); - painter->drawLine(m_startX, 0, m_startX, currentHeight); - painter->drawLine(m_endX, 0, m_endX, currentHeight); + painter->drawLine(edgeOffset + m_startX, 0, edgeOffset + m_startX, currentHeight); + painter->drawLine(edgeOffset + m_endX, 0, edgeOffset + m_endX, currentHeight); } else { // draw main duration part - double x = qMax(m_startX, m_minStartX); - double w = qMin(m_endX, m_maxEndX) - x; + double x = edgeOffset + qMax(m_startX, m_minStartX); + double w = edgeOffset + qMin(m_endX, m_maxEndX) - x; static const int marginY = 3; painter->setPen(Qt::NoPen); @@ -192,37 +194,40 @@ void RowTimeline::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio Qt::BDiagPattern)); if (m_startX < m_minStartX) { painter->setPen(Qt::NoPen); - painter->fillRect(QRect(m_startX, 0, m_minStartX - m_startX, currentHeight), + painter->fillRect(QRect(edgeOffset + m_startX, 0, m_minStartX - m_startX, + currentHeight), CStudioPreferences::timelineRowColorDurationOff2()); - painter->drawRect(QRect(m_startX, 0, m_minStartX - m_startX, currentHeight)); + painter->drawRect(QRect(edgeOffset + m_startX, 0, m_minStartX - m_startX, + currentHeight)); painter->setPen(CStudioPreferences::timelineRowColorDurationEdge()); - painter->drawLine(m_minStartX, 0, m_minStartX, currentHeight); + painter->drawLine(edgeOffset + m_minStartX, 0, edgeOffset + m_minStartX, + currentHeight); } // draw hashed part after if (m_endX > m_maxEndX) { painter->setPen(Qt::NoPen); - painter->fillRect(QRect(m_maxEndX, 0, m_endX - m_maxEndX, currentHeight), + painter->fillRect(QRect(edgeOffset + m_maxEndX, 0, m_endX - m_maxEndX, + currentHeight), CStudioPreferences::timelineRowColorDurationOff2()); - painter->drawRect(QRect(m_maxEndX, 0, m_endX - m_maxEndX, currentHeight)); + painter->drawRect(QRect(edgeOffset + m_maxEndX, 0, m_endX - m_maxEndX, + currentHeight)); painter->setPen(CStudioPreferences::timelineRowColorDurationEdge()); - painter->drawLine(m_maxEndX, 0, m_maxEndX, currentHeight); + painter->drawLine(edgeOffset + m_maxEndX, 0, edgeOffset + m_maxEndX, currentHeight); } if (m_rowTree->indexInLayout() != 1) { painter->setPen(QPen(CStudioPreferences::timelineRowColorDurationEdge(), 2)); - painter->drawLine(m_startX, 0, m_startX, currentHeight); - painter->drawLine(m_endX, 0, m_endX, currentHeight); + painter->drawLine(edgeOffset + m_startX, 0, edgeOffset + m_startX, currentHeight); + painter->drawLine(edgeOffset + m_endX, 0, edgeOffset + m_endX, currentHeight); } } painter->restore(); } - if (m_propertyGraph) { - // Property graph - QRectF graphRect(TimelineConstants::RULER_EDGE_OFFSET, 0, - widget->width(), currentHeight); + if (m_propertyGraph) { // Property graph + QRectF graphRect(edgeOffset, 0, widget->width(), currentHeight); m_propertyGraph->paintGraphs(painter, graphRect); } @@ -244,14 +249,15 @@ void RowTimeline::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio const qreal oldOpacity = painter->opacity(); painter->setOpacity(0.75); for (const auto time : qAsConst(childKeyframeTimes)) { - const qreal xCoord = timeToX(time) - 2.5; - painter->drawPixmap(QPointF(xCoord, hiddenKeyFrameY), hiResIcons - ? pixKeyframeHidden2x : pixKeyframeHidden); + const qreal xCoord = edgeOffset + m_rowTree->m_scene->ruler()->timeToDistance(time) + - 2.5; + painter->drawPixmap(QPointF(xCoord, hiddenKeyFrameY), hiResIcons ? pixKeyframeHidden2x + : pixKeyframeHidden); } painter->setOpacity(oldOpacity); } - if (m_rowTree->hasPropertyChildren()) { // master keyframes + if (m_rowTree->hasPropertyChildren()) { // object row keyframes static const QPixmap pixKeyframeMasterDisabled = QPixmap(":/images/Keyframe-Master-Disabled.png"); static const QPixmap pixKeyframeMasterNormal @@ -303,18 +309,21 @@ void RowTimeline::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio : pixKeyframeMasterNormal; } } - painter->drawPixmap(QPointF(timeToX(keyframe->time) - keyFrameOffset, keyFrameY), - pixmap); + painter->drawPixmap(QPointF(edgeOffset + m_rowTree->m_scene->ruler() + ->timeToDistance(keyframe->time) - keyFrameOffset, + keyFrameY), pixmap); // highlight the pressed keyframe in a multi-selection (the keyframe that is affected // by snapping, and setting time dialog) if (m_rowTree->m_scene->keyframeManager()->selectedKeyframes().size() > 1 && m_rowTree->m_scene->pressedKeyframe() == keyframe) { painter->setPen(QPen(CStudioPreferences::timelinePressedKeyframeColor(), 1)); - painter->drawArc(timeToX(keyframe->time) - 4, keyFrameY + 4, 9, 9, 0, 5760); + painter->drawArc(edgeOffset + m_rowTree->m_scene->ruler() + ->timeToDistance(keyframe->time) - 4, keyFrameY + 4, 9, 9, 0, + 5760); } } - } else if (m_rowTree->isProperty()) { + } else if (m_rowTree->isProperty()) { // property row keyframes static const QPixmap pixKeyframePropertyDisabled = QPixmap(":/images/Keyframe-Property-Disabled.png"); static const QPixmap pixKeyframePropertyNormal @@ -369,8 +378,9 @@ void RowTimeline::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio : pixKeyframePropertyNormal; } } - painter->drawPixmap(QPointF(timeToX(keyframe->time) - keyFrameOffset, keyFrameY), - pixmap); + painter->drawPixmap(QPointF(edgeOffset + m_rowTree->m_scene->ruler() + ->timeToDistance(keyframe->time) - keyFrameOffset, + keyFrameY), pixmap); } } } @@ -401,7 +411,7 @@ void RowTimeline::drawColorPropertyGradient(QPainter *painter, int width) QLinearGradient bgGradient(0, 0, width, 0); for (auto keyframe : qAsConst(m_keyframes)) { - double xPos = timeToX(keyframe->time); + double xPos = m_rowTree->m_scene->ruler()->timeToDistance(keyframe->time); double gradPos = xPos / width; gradPos = qBound(0.0, gradPos, 1.0); QColor currentColor; @@ -433,7 +443,8 @@ Keyframe *RowTimeline::getClickedKeyframe(const QPointF &scenePos) } for (const auto keyframe : qAsConst(keyframes)) { - x = timeToX(keyframe->time); + x = TimelineConstants::RULER_EDGE_OFFSET + + m_rowTree->m_scene->ruler()->timeToDistance(keyframe->time); if (p.x() > x - 5 && p.x() < x + 5 && p.y() > 3 && p.y() < 16) return keyframe; @@ -451,7 +462,8 @@ QList RowTimeline::getKeyframesInRange(const QRectF &rect) const static const int KF_CENTER_Y = 10; for (auto keyframe : qAsConst(m_keyframes)) { - x = timeToX(keyframe->time); + x = TimelineConstants::RULER_EDGE_OFFSET + + m_rowTree->m_scene->ruler()->timeToDistance(keyframe->time); if (localRect.left() < x && localRect.right() > x && localRect.top() < KF_CENTER_Y && localRect.bottom() > KF_CENTER_Y) { @@ -563,6 +575,8 @@ TimelineControlType RowTimeline::getClickedControl(const QPointF &scenePos) cons if (!m_rowTree->locked()) { QPointF p = mapFromScene(scenePos.x(), scenePos.y()); + p.setX(p.x() - TimelineConstants::RULER_EDGE_OFFSET); + const int halfHandle = TimelineConstants::DURATION_HANDLE_W * .5; // Never choose start handle if end time is zero, as you cannot adjust it in that case bool startHandle = p.x() > m_startX - halfHandle && p.x() < m_startX + halfHandle @@ -625,8 +639,8 @@ void RowTimeline::clearBoundChildren() // move the duration area (start/end x) void RowTimeline::moveDurationBy(double dx) { - if (m_startX + dx < TimelineConstants::RULER_EDGE_OFFSET) - dx = TimelineConstants::RULER_EDGE_OFFSET - m_startX; + if (m_startX + dx < 0) + dx = -m_startX; m_startX += dx; m_endX += dx; @@ -637,8 +651,9 @@ void RowTimeline::moveDurationBy(double dx) m_maxEndX = m_endX; } - m_startTime = xToTime(m_startX); - m_endTime = xToTime(m_endX); + Ruler *ruler = m_rowTree->m_scene->ruler(); + m_startTime = ruler->distanceToTime(m_startX); + m_endTime = ruler->distanceToTime(m_endX); // move keyframes with the row if (!m_rowTree->isProperty()) { // make sure we don't move the keyframes twice @@ -661,8 +676,8 @@ void RowTimeline::moveDurationBy(double dx) void RowTimeline::moveDurationTo(double newX) { - if (newX < TimelineConstants::RULER_EDGE_OFFSET) - newX = TimelineConstants::RULER_EDGE_OFFSET; + if (newX < 0) + newX = 0; double dx = newX - m_startX; double durationX = m_endX - m_startX; @@ -676,13 +691,14 @@ void RowTimeline::moveDurationTo(double newX) m_maxEndX = m_endX; } - m_startTime = xToTime(m_startX); - m_endTime = xToTime(m_endX); + Ruler *ruler = m_rowTree->m_scene->ruler(); + m_startTime = ruler->distanceToTime(m_startX); + m_endTime = ruler->distanceToTime(m_endX); // move keyframes with the row if (!m_rowTree->isProperty()) { // make sure we don't move the keyframes twice for (Keyframe *keyframe : qAsConst(m_keyframes)) - keyframe->time += rowTree()->m_scene->ruler()->distanceToTime(dx); + keyframe->time += ruler->distanceToTime(dx); } update(); @@ -713,20 +729,6 @@ long RowTimeline::getDuration() const return m_endTime - m_startTime; } -// convert time (seconds) values to x -double RowTimeline::timeToX(long time) const -{ - return TimelineConstants::RULER_EDGE_OFFSET + time * TimelineConstants::RULER_MILLI_W - * rowTree()->m_scene->ruler()->timelineScale(); -} - -// convert x values to time (seconds) -long RowTimeline::xToTime(double xPos) const -{ - return (xPos - TimelineConstants::RULER_EDGE_OFFSET) - / (TimelineConstants::RULER_MILLI_W * rowTree()->m_scene->ruler()->timelineScale()); -} - void RowTimeline::collectChildKeyframeTimes(QVector &childKeyframeTimes) { const auto childRows = m_rowTree->childRows(); @@ -749,13 +751,13 @@ void RowTimeline::updatePosition() // Set the position of the start of the row duration void RowTimeline::setStartX(double startX) { - if (startX < TimelineConstants::RULER_EDGE_OFFSET) - startX = TimelineConstants::RULER_EDGE_OFFSET; + if (startX < 0) + startX = 0; else if (startX > m_endX) startX = m_endX; m_startX = startX; - m_startTime = xToTime(startX); + m_startTime = m_rowTree->m_scene->ruler()->distanceToTime(startX); if (!m_rowTree->parentRow() || m_rowTree->parentRow()->rowType() == OBJTYPE_SCENE || m_rowTree->hasComponentAncestor()) { @@ -774,7 +776,7 @@ void RowTimeline::setEndX(double endX) endX = m_startX; m_endX = endX; - m_endTime = xToTime(endX); + m_endTime = m_rowTree->m_scene->ruler()->distanceToTime(endX); if (!m_rowTree->parentRow() || m_rowTree->parentRow()->rowType() == OBJTYPE_SCENE || m_rowTree->hasComponentAncestor()) { @@ -894,7 +896,7 @@ void RowTimeline::updateCommentItemPos() void RowTimeline::setStartTime(long startTime) { m_startTime = startTime; - m_startX = timeToX(startTime); + m_startX = m_rowTree->m_scene->ruler()->timeToDistance(startTime); if (!m_rowTree->parentRow() || m_rowTree->parentRow()->rowType() == OBJTYPE_SCENE || m_rowTree->hasComponentAncestor()) { @@ -909,7 +911,7 @@ void RowTimeline::setStartTime(long startTime) void RowTimeline::setEndTime(long endTime) { m_endTime = endTime; - m_endX = timeToX(endTime); + m_endX = m_rowTree->m_scene->ruler()->timeToDistance(endTime); if (!m_rowTree->parentRow() || m_rowTree->parentRow()->rowType() == OBJTYPE_SCENE || m_rowTree->hasComponentAncestor()) { @@ -921,11 +923,13 @@ void RowTimeline::setEndTime(long endTime) update(); } +// duration start x in local space (x=0 at time=0) double RowTimeline::getStartX() const { return m_startX; } +// duration end x in local space double RowTimeline::getEndX() const { return m_endX; diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.h index 0a0f3537..00c81696 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.h +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimeline.h @@ -100,8 +100,6 @@ private: void drawColorPropertyGradient(QPainter *painter, int width); bool isColorProperty() const; QString formatTime(long millis) const; - double timeToX(long time) const; - long xToTime(double xPos) const; void collectChildKeyframeTimes(QVector &childKeyframeTimes); RowTree *m_rowTree; diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.cpp index fa01651c..62c6de01 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.cpp @@ -32,7 +32,6 @@ #include #include -#include Ruler::Ruler(TimelineItem *parent) : TimelineItem(parent) { @@ -134,18 +133,6 @@ double Ruler::timeToDistance(long time) const return time * TimelineConstants::RULER_MILLI_W * m_timeScale; } -// x position of ruler value 0 -double Ruler::durationStartX() const -{ - return x() + TimelineConstants::RULER_EDGE_OFFSET; -} - -// x position of ruler max value (duration) -double Ruler::durationEndX() const -{ - return durationStartX() + timeToDistance(m_duration); -} - double Ruler::timelineScale() const { return m_timeScale; diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.h index 272adc12..005a23c3 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.h +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.h @@ -44,8 +44,6 @@ public: void setTimelineScale(double scl); long distanceToTime(double distance) const; double timeToDistance(long time) const; - double durationStartX() const; - double durationEndX() const; double timelineScale() const; long duration() const; long maxDuration() const; -- cgit v1.2.3