diff options
author | Kaj Grönholm <kaj.gronholm@qt.io> | 2018-05-30 12:59:42 +0300 |
---|---|---|
committer | Kaj Grönholm <kaj.gronholm@qt.io> | 2018-05-30 10:40:03 +0000 |
commit | ccff8bd00512a399d309edfd892334f32df75439 (patch) | |
tree | be7ec6db3b7653ac68303ff839023575b94f3768 | |
parent | c3f191efb4676140cc07796ee8a6fe00bfb145bf (diff) |
Improve timeline timebars adjusting
- Allow updating duration and maxDuration separately. Max duration
is not updated during manual duration movement to avoid buggy behavior
when adjusting right-most duration.
- Draw ruler up to maxDuration and with active color up to duration.
- Fix ruler update after undo/redo.
Task-number: QT3DS-1789
Change-Id: I66e45aeda7e9aa5e91e7de6092d05a1d52f1c89b
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
6 files changed, 40 insertions, 16 deletions
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.cpp index cf6aa893..479fed20 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.cpp @@ -260,7 +260,10 @@ void RowManager::clearSelection() m_selectedRows.clear(); } -void RowManager::updateRulerDuration() +// Updates duration of ruler +// When you don't want to update max duration (so width of timeline, scrollbar) +// set updateMaxDuration to false. +void RowManager::updateRulerDuration(bool updateMaxDuration) { double duration = 0; double maxDuration = 0; // for setting correct size for the view so scrollbars appear correctly @@ -279,7 +282,9 @@ void RowManager::updateRulerDuration() } } - m_scene->ruler()->setDuration(duration, maxDuration); + m_scene->ruler()->setDuration(duration); + if (updateMaxDuration) + m_scene->ruler()->setMaxDuration(maxDuration); } void RowManager::updateFiltering(RowTree *row) diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.h index 56021889..e39bafa8 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.h +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.h @@ -55,7 +55,7 @@ public: void clearSelection(); void updateFiltering(RowTree *rowTree = nullptr); void recreateRowsFromBinding(ITimelineItemBinding *rootBinding); - void updateRulerDuration(); + void updateRulerDuration(bool updateMaxDuration = true); void collapseAllPropertyRows(); int getChildIndex(RowTree *parentRow, RowTree *childRow); int getRowIndex(RowTree *row, int startAt = 1); diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp index 59f4c2af..9cc82328 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp @@ -468,7 +468,7 @@ void TimelineGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) snap(distance); m_editedTimelineRow->setEndX(distance); m_editedTimelineRow->showToolTip(event->screenPos()); - rowManager()->updateRulerDuration(); + rowManager()->updateRulerDuration(false); } else if (m_clickedTimelineControlType == TimelineControlType::Duration && qAbs(event->scenePos().x() - event->lastScenePos().x()) < 50) { // moving row timeline duration @@ -478,7 +478,7 @@ void TimelineGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) snap(newX); m_editedTimelineRow->moveDurationTo(newX); m_editedTimelineRow->showToolTip(event->screenPos()); - rowManager()->updateRulerDuration(); + rowManager()->updateRulerDuration(false); } else if (m_selectionRect->isActive()) { // resizing keyframe selection rect m_selectionRect->updateSize(event->scenePos()); @@ -648,6 +648,7 @@ void TimelineGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) timebar->CommitTimeChange(); updateSnapSteps(); } else if (m_clickedTimelineControlType == TimelineControlType::EndHandle) { + rowManager()->updateRulerDuration(); ITimelineTimebar *timebar = m_editedTimelineRow->rowTree()->getBinding() ->GetTimelineItem()->GetTimebar(); timebar->ChangeTime(m_editedTimelineRow->getEndTime() * 1000, false); @@ -656,6 +657,7 @@ void TimelineGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) if (m_playHead->time() > ruler()->duration()) g_StudioApp.GetCore()->GetDoc()->NotifyTimeChanged(ruler()->duration() * 1000); } else if (m_dragging && m_clickedTimelineControlType == TimelineControlType::Duration) { + rowManager()->updateRulerDuration(); ITimelineTimebar *timebar = m_editedTimelineRow->rowTree()->getBinding() ->GetTimelineItem()->GetTimebar(); timebar->OffsetTime(m_editedTimelineRow->getDurationMoveTime() * 1000); diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineWidget.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineWidget.cpp index c040f3f1..97a39690 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineWidget.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineWidget.cpp @@ -312,7 +312,7 @@ TimelineWidget::TimelineWidget(const QSize &preferredSize, QWidget *parent) m_graphicsScene->setTimelineScale(scale); }); - connect(m_graphicsScene->ruler(), &Ruler::durationChanged, this, [this]() { + connect(m_graphicsScene->ruler(), &Ruler::maxDurationChanged, this, [this]() { m_graphicsScene->updateTimelineLayoutWidth(); }); @@ -742,8 +742,10 @@ void TimelineWidget::onAsyncUpdate() if (binding) { RowTree *row = binding->getRowTree(); if (row) { - if (timeProperty) + if (timeProperty) { row->rowTimeline()->updateDurationFromBinding(); + m_graphicsScene->rowManager()->updateRulerDuration(); + } if (filterProperty) { row->updateFromBinding(); m_graphicsScene->rowManager()->updateFiltering(row); diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.cpp index 81eadbf1..4379ea96 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.cpp @@ -43,8 +43,10 @@ void Ruler::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi Q_UNUSED(option) double xStep = TimelineConstants::RULER_SEC_W / TimelineConstants::RULER_SEC_DIV * m_timeScale; - double totalSegmentsWidth = TimelineConstants::RULER_EDGE_OFFSET + double activeSegmentsWidth = TimelineConstants::RULER_EDGE_OFFSET + m_duration * xStep * TimelineConstants::RULER_SEC_DIV; + double totalSegmentsWidth = TimelineConstants::RULER_EDGE_OFFSET + + m_maxDuration * xStep * TimelineConstants::RULER_SEC_DIV; // Ruler painted width to be at least widget width double minRulerWidth = widget->width(); @@ -59,7 +61,7 @@ void Ruler::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi painter->setPen(QColor(TimelineConstants::RULER_COLOR)); painter->drawLine(TimelineConstants::RULER_EDGE_OFFSET, TimelineConstants::RULER_BASE_Y, - totalSegmentsWidth, + activeSegmentsWidth, TimelineConstants::RULER_BASE_Y); QFont font = painter->font(); @@ -81,7 +83,7 @@ void Ruler::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi i % secDiv == secDiv * 0.5 ? TimelineConstants::RULER_DIV_H2 : TimelineConstants::RULER_DIV_H3; - if (!useDisabledColor && rowX > totalSegmentsWidth) { + if (!useDisabledColor && rowX > activeSegmentsWidth) { painter->setPen(QColor(TimelineConstants::RULER_COLOR_DISABLED)); useDisabledColor = true; } @@ -148,24 +150,36 @@ double Ruler::timelineScale() const return m_timeScale; } +// Returns end of right-most layer/component row. +// Active color of ruler is used up to this point. +// Slide plays up to this point. double Ruler::duration() const { return m_duration; } +// Returns end of right-most row. +// Ruler steps & labels are drawn up to this point. +// Timeline scrollbar allows scrolling up to this point. double Ruler::maxDuration() const { return m_maxDuration; } -void Ruler::setDuration(double duration, double maxDuration) +void Ruler::setDuration(double duration) { - if (m_duration != duration || m_maxDuration != maxDuration) { + if (m_duration != duration) { m_duration = duration; - m_maxDuration = maxDuration; update(); + } +} - emit durationChanged(duration); +void Ruler::setMaxDuration(double maxDuration) +{ + if (m_maxDuration != maxDuration) { + m_maxDuration = maxDuration; + update(); + emit maxDurationChanged(m_maxDuration); } } diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.h index c4e05cc9..8715d1d4 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.h +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/Ruler.h @@ -49,7 +49,8 @@ public: double timelineScale() const; double duration() const; double maxDuration() const; - void setDuration(double duration, double maxDuration); + void setDuration(double duration); + void setMaxDuration(double maxDuration); void setViewportX(int viewportX); int type() const; @@ -58,7 +59,7 @@ protected: QWidget *widget = nullptr) override; signals: - void durationChanged(double duration); + void maxDurationChanged(double maxDuration); private: const QString timestampString(int timeMs); |