From a18f55913bcabe739321e50d84f547bbfc2e7080 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sun, 8 Jan 2023 17:22:54 -0800 Subject: [PATCH] Added new timeline option to move selection to a new step. --- common/lc_commands.cpp | 14 ++++++ common/lc_commands.h | 2 + common/lc_mainwindow.cpp | 10 ++++ common/lc_timelinewidget.cpp | 95 ++++++++++++++++++++++++++++++++++-- common/lc_timelinewidget.h | 2 + 5 files changed, 120 insertions(+), 3 deletions(-) diff --git a/common/lc_commands.cpp b/common/lc_commands.cpp index 963d911a..8fcdc45d 100644 --- a/common/lc_commands.cpp +++ b/common/lc_commands.cpp @@ -1816,6 +1816,20 @@ const lcCommand gCommands[] = QT_TRANSLATE_NOOP("Status", "Move the selected parts into this step"), "" }, + // LC_TIMELINE_MOVE_SELECTION_BEFORE + { + "", + QT_TRANSLATE_NOOP("Menu", "Move Selection Before"), + QT_TRANSLATE_NOOP("Status", "Move the selected parts into a new step before this"), + "" + }, + // LC_TIMELINE_MOVE_SELECTION_AFTER + { + "", + QT_TRANSLATE_NOOP("Menu", "Move Selection After"), + QT_TRANSLATE_NOOP("Status", "Move the selected parts into a new step after this"), + "" + }, // LC_TIMELINE_SET_CURRENT { "", diff --git a/common/lc_commands.h b/common/lc_commands.h index 31951fe0..9dec3cef 100644 --- a/common/lc_commands.h +++ b/common/lc_commands.h @@ -277,6 +277,8 @@ enum lcCommandId LC_TIMELINE_INSERT_AFTER, LC_TIMELINE_DELETE, LC_TIMELINE_MOVE_SELECTION, + LC_TIMELINE_MOVE_SELECTION_BEFORE, + LC_TIMELINE_MOVE_SELECTION_AFTER, LC_TIMELINE_SET_CURRENT, LC_NUM_COMMANDS }; diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index 622da8f2..429c1ff3 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -1971,6 +1971,8 @@ void lcMainWindow::UpdateSelectedObjects(bool SelectionChanged) mActions[LC_PIECE_SHOW_EARLIER]->setEnabled(Flags & LC_SEL_PIECE); // FIXME: disable if current step is 1 mActions[LC_PIECE_SHOW_LATER]->setEnabled(Flags & LC_SEL_PIECE); mActions[LC_TIMELINE_MOVE_SELECTION]->setEnabled(Flags & LC_SEL_PIECE); + mActions[LC_TIMELINE_MOVE_SELECTION_BEFORE]->setEnabled(Flags & LC_SEL_PIECE); + mActions[LC_TIMELINE_MOVE_SELECTION_AFTER]->setEnabled(Flags & LC_SEL_PIECE); mActions[LC_PIECE_EDIT_END_SUBMODEL]->setEnabled(GetCurrentTabModel() != ActiveModel); } @@ -3413,6 +3415,14 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId) mTimelineWidget->MoveSelection(); break; + case LC_TIMELINE_MOVE_SELECTION_BEFORE: + mTimelineWidget->MoveSelectionBefore(); + break; + + case LC_TIMELINE_MOVE_SELECTION_AFTER: + mTimelineWidget->MoveSelectionAfter(); + break; + case LC_TIMELINE_SET_CURRENT: mTimelineWidget->SetCurrentStep(); break; diff --git a/common/lc_timelinewidget.cpp b/common/lc_timelinewidget.cpp index 1e60130c..aecd7833 100644 --- a/common/lc_timelinewidget.cpp +++ b/common/lc_timelinewidget.cpp @@ -54,7 +54,12 @@ void lcTimelineWidget::CustomMenuRequested(QPoint Pos) Menu->addAction(gMainWindow->mActions[LC_TIMELINE_INSERT_BEFORE]); Menu->addAction(gMainWindow->mActions[LC_TIMELINE_INSERT_AFTER]); Menu->addAction(gMainWindow->mActions[LC_TIMELINE_DELETE]); + + Menu->addSeparator(); + Menu->addAction(gMainWindow->mActions[LC_TIMELINE_MOVE_SELECTION]); + Menu->addAction(gMainWindow->mActions[LC_TIMELINE_MOVE_SELECTION_BEFORE]); + Menu->addAction(gMainWindow->mActions[LC_TIMELINE_MOVE_SELECTION_AFTER]); Menu->addSeparator(); @@ -398,6 +403,90 @@ void lcTimelineWidget::MoveSelection() Model->SetCurrentStep(Step); } +void lcTimelineWidget::MoveSelectionBefore() +{ + QTreeWidgetItem* CurrentItem = currentItem(); + + if (!CurrentItem) + return; + + if (CurrentItem->parent()) + CurrentItem = CurrentItem->parent(); + + int Step = indexOfTopLevelItem(CurrentItem); + + if (Step == -1) + return; + + Step++; + + QList SelectedItems = selectedItems(); + + gMainWindow->GetActiveModel()->InsertStep(Step); + + CurrentItem = topLevelItem(Step - 1); + + for (QTreeWidgetItem* PieceItem : SelectedItems) + { + QTreeWidgetItem* Parent = PieceItem->parent(); + + if (!Parent) + continue; + + int ChildIndex = Parent->indexOfChild(PieceItem); + CurrentItem->addChild(Parent->takeChild(ChildIndex)); + } + + UpdateModel(); + + lcModel* Model = gMainWindow->GetActiveModel(); + + if (Step > static_cast(Model->GetCurrentStep())) + Model->SetCurrentStep(Step); +} + +void lcTimelineWidget::MoveSelectionAfter() +{ + QTreeWidgetItem* CurrentItem = currentItem(); + + if (!CurrentItem) + return; + + if (CurrentItem->parent()) + CurrentItem = CurrentItem->parent(); + + int Step = indexOfTopLevelItem(CurrentItem); + + if (Step == -1) + return; + + Step += 2; + + QList SelectedItems = selectedItems(); + + gMainWindow->GetActiveModel()->InsertStep(Step); + + CurrentItem = topLevelItem(Step - 1); + + for (QTreeWidgetItem* PieceItem : SelectedItems) + { + QTreeWidgetItem* Parent = PieceItem->parent(); + + if (!Parent) + continue; + + int ChildIndex = Parent->indexOfChild(PieceItem); + CurrentItem->addChild(Parent->takeChild(ChildIndex)); + } + + UpdateModel(); + + lcModel* Model = gMainWindow->GetActiveModel(); + + if (Step > static_cast(Model->GetCurrentStep())) + Model->SetCurrentStep(Step); +} + void lcTimelineWidget::SetCurrentStep() { QTreeWidgetItem* CurrentItem = currentItem(); @@ -463,6 +552,9 @@ void lcTimelineWidget::dropEvent(QDropEvent* Event) QTreeWidgetItem* DropItem = itemAt(Event->pos()); lcModel* Model = gMainWindow->GetActiveModel(); + QList SelectedItems = selectedItems(); + clearSelection(); + if (DropItem) { QTreeWidgetItem* ParentItem = DropItem->parent(); @@ -472,9 +564,6 @@ void lcTimelineWidget::dropEvent(QDropEvent* Event) Model->SetCurrentStep(Step); } - QList SelectedItems = selectedItems(); - clearSelection(); - auto SortItems = [this](QTreeWidgetItem* Item1, QTreeWidgetItem* Item2) { QTreeWidgetItem* StepItem1 = Item1->parent(); diff --git a/common/lc_timelinewidget.h b/common/lc_timelinewidget.h index 6163221b..d7fb3bf3 100644 --- a/common/lc_timelinewidget.h +++ b/common/lc_timelinewidget.h @@ -15,6 +15,8 @@ public: void InsertStepAfter(); void RemoveStep(); void MoveSelection(); + void MoveSelectionBefore(); + void MoveSelectionAfter(); void SetCurrentStep(); public slots: