From 0dabe0d43533aedf1263cfdbf7e0d9e5286b24ac Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sat, 4 Feb 2017 18:40:46 -0800 Subject: [PATCH] Added SetCurrentStep and MoveSelection to Timeline context menu. --- common/lc_commands.cpp | 34 ++++++++++++++-- common/lc_commands.h | 4 ++ common/lc_mainwindow.cpp | 17 ++++++++ common/lc_timelinewidget.cpp | 78 ++++++++++++++++++++++++++++++++++-- common/lc_timelinewidget.h | 7 +++- qt/lc_qpreferencesdialog.cpp | 3 ++ 6 files changed, 135 insertions(+), 8 deletions(-) diff --git a/common/lc_commands.cpp b/common/lc_commands.cpp index 37463720..7bcfc0aa 100644 --- a/common/lc_commands.cpp +++ b/common/lc_commands.cpp @@ -868,15 +868,15 @@ lcCommand gCommands[LC_NUM_COMMANDS] = // LC_VIEW_TIME_INSERT { QT_TRANSLATE_NOOP("Action", "View.Time.Insert"), - QT_TRANSLATE_NOOP("Menu", "Insert"), + QT_TRANSLATE_NOOP("Menu", "Insert Step"), QT_TRANSLATE_NOOP("Status", "Insert new step"), QT_TRANSLATE_NOOP("Shortcut", "") }, // LC_VIEW_TIME_DELETE { QT_TRANSLATE_NOOP("Action", "View.Time.Delete"), - QT_TRANSLATE_NOOP("Menu", "Delete"), - QT_TRANSLATE_NOOP("Status", "Delete current step"), + QT_TRANSLATE_NOOP("Menu", "Remove Step"), + QT_TRANSLATE_NOOP("Status", "Remove current step"), QT_TRANSLATE_NOOP("Shortcut", "") }, // LC_VIEW_TIME_ADD_KEYS @@ -1389,6 +1389,34 @@ lcCommand gCommands[LC_NUM_COMMANDS] = QT_TRANSLATE_NOOP("Menu", "&About..."), QT_TRANSLATE_NOOP("Status", "Display program version number and system information"), QT_TRANSLATE_NOOP("Shortcut", "") + }, + // LC_TIMELINE_INSERT + { + "", + QT_TRANSLATE_NOOP("Menu", "Insert Step"), + QT_TRANSLATE_NOOP("Status", "Insert new step"), + "" + }, + // LC_TIMELINE_DELETE + { + "", + QT_TRANSLATE_NOOP("Menu", "Remove Step"), + QT_TRANSLATE_NOOP("Status", "Remove current step"), + "" + }, + // LC_TIMELINE_MOVE_SELECTION + { + "", + QT_TRANSLATE_NOOP("Menu", "Move Selection Here"), + QT_TRANSLATE_NOOP("Status", "Move the selected parts into this step"), + "" + }, + // LC_TIMELINE_SET_CURRENT + { + "", + QT_TRANSLATE_NOOP("Menu", "Set Current Step"), + QT_TRANSLATE_NOOP("Status", "View the model at this point in the timeline"), + "" } }; diff --git a/common/lc_commands.h b/common/lc_commands.h index d4716248..2050306f 100644 --- a/common/lc_commands.h +++ b/common/lc_commands.h @@ -211,6 +211,10 @@ enum lcCommandId LC_HELP_EMAIL, LC_HELP_UPDATES, LC_HELP_ABOUT, + LC_TIMELINE_INSERT, + LC_TIMELINE_DELETE, + LC_TIMELINE_MOVE_SELECTION, + LC_TIMELINE_SET_CURRENT, LC_NUM_COMMANDS }; diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index 24224929..7d8ff734 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -1489,6 +1489,7 @@ void lcMainWindow::UpdateSelectedObjects(bool SelectionChanged) mActions[LC_PIECE_GROUP_EDIT]->setEnabled((Flags & LC_SEL_NO_PIECES) == 0); 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); } mPropertiesWidget->Update(Selection, Focus); @@ -2543,6 +2544,22 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId) ActiveView->CancelTrackingOrClearSelection(); break; + case LC_TIMELINE_INSERT: + mTimelineWidget->InsertStep(); + break; + + case LC_TIMELINE_DELETE: + mTimelineWidget->RemoveStep(); + break; + + case LC_TIMELINE_MOVE_SELECTION: + mTimelineWidget->MoveSelection(); + break; + + case LC_TIMELINE_SET_CURRENT: + mTimelineWidget->SetCurrentStep(); + break; + case LC_NUM_COMMANDS: break; } diff --git a/common/lc_timelinewidget.cpp b/common/lc_timelinewidget.cpp index 695ea66d..dc5dc993 100644 --- a/common/lc_timelinewidget.cpp +++ b/common/lc_timelinewidget.cpp @@ -45,10 +45,11 @@ void lcTimelineWidget::CustomMenuRequested(QPoint Pos) } } - QAction* InsertStepAction = Menu->addAction(gMainWindow->mActions[LC_VIEW_TIME_INSERT]->text(), this, SLOT(InsertStep())); - InsertStepAction->setStatusTip(gMainWindow->mActions[LC_VIEW_TIME_INSERT]->statusTip()); - QAction* RemoveStepAction = Menu->addAction(gMainWindow->mActions[LC_VIEW_TIME_DELETE]->text(), this, SLOT(RemoveStep())); - RemoveStepAction->setStatusTip(gMainWindow->mActions[LC_VIEW_TIME_DELETE]->statusTip()); + Menu->addAction(gMainWindow->mActions[LC_TIMELINE_SET_CURRENT]); + Menu->addAction(gMainWindow->mActions[LC_TIMELINE_INSERT]); + Menu->addAction(gMainWindow->mActions[LC_TIMELINE_DELETE]); + Menu->addAction(gMainWindow->mActions[LC_TIMELINE_MOVE_SELECTION]); + Menu->addSeparator(); Menu->addAction(gMainWindow->mActions[LC_PIECE_HIDE_SELECTED]); @@ -292,6 +293,55 @@ void lcTimelineWidget::RemoveStep() lcGetActiveModel()->RemoveStep(Step + 1); } +void lcTimelineWidget::MoveSelection() +{ + QTreeWidgetItem* CurrentItem = currentItem(); + + if (!CurrentItem) + return; + + if (CurrentItem->parent()) + CurrentItem = CurrentItem->parent(); + + int Step = indexOfTopLevelItem(CurrentItem); + + if (Step == -1) + return; + + QList SelectedItems = selectedItems(); + + foreach(QTreeWidgetItem* PieceItem, SelectedItems) + { + QTreeWidgetItem* Parent = PieceItem->parent(); + + if (!Parent) + continue; + + int ChildIndex = Parent->indexOfChild(PieceItem); + CurrentItem->addChild(Parent->takeChild(ChildIndex)); + } + + UpdateModel(); +} + +void lcTimelineWidget::SetCurrentStep() +{ + QTreeWidgetItem* CurrentItem = currentItem(); + + if (!CurrentItem) + return; + + if (CurrentItem->parent()) + CurrentItem = CurrentItem->parent(); + + int Step = indexOfTopLevelItem(CurrentItem); + + if (Step == -1) + return; + + lcGetActiveModel()->SetCurrentStep(Step + 1); +} + void lcTimelineWidget::ItemSelectionChanged() { lcArray Selection; @@ -322,7 +372,27 @@ void lcTimelineWidget::ItemSelectionChanged() void lcTimelineWidget::dropEvent(QDropEvent* Event) { QTreeWidget::dropEvent(Event); + UpdateModel(); +} +void lcTimelineWidget::mousePressEvent(QMouseEvent* Event) +{ + if (Event->button() == Qt::RightButton) + { + QItemSelection Selection = selectionModel()->selection(); + + bool Blocked = blockSignals(true); + QTreeWidget::mousePressEvent(Event); + blockSignals(Blocked); + + selectionModel()->select(Selection, QItemSelectionModel::ClearAndSelect); + } + else + QTreeWidget::mousePressEvent(Event); +} + +void lcTimelineWidget::UpdateModel() +{ QList> PieceSteps; for (int TopLevelItemIdx = 0; TopLevelItemIdx < topLevelItemCount(); TopLevelItemIdx++) diff --git a/common/lc_timelinewidget.h b/common/lc_timelinewidget.h index 04ee2ddc..4c4bac47 100644 --- a/common/lc_timelinewidget.h +++ b/common/lc_timelinewidget.h @@ -12,14 +12,19 @@ public: void Update(bool Clear, bool UpdateItems); void UpdateSelection(); -public slots: void InsertStep(); void RemoveStep(); + void MoveSelection(); + void SetCurrentStep(); + +public slots: void ItemSelectionChanged(); void CustomMenuRequested(QPoint Pos); protected: virtual void dropEvent(QDropEvent* Event); + virtual void mousePressEvent(QMouseEvent* Event); + void UpdateModel(); QMap mIcons; QMap mItems; diff --git a/qt/lc_qpreferencesdialog.cpp b/qt/lc_qpreferencesdialog.cpp index dfcae579..78fdf778 100644 --- a/qt/lc_qpreferencesdialog.cpp +++ b/qt/lc_qpreferencesdialog.cpp @@ -431,6 +431,9 @@ void lcQPreferencesDialog::updateCommandList() for (int actionIdx = 0; actionIdx < LC_NUM_COMMANDS; actionIdx++) { + if (!gCommands[actionIdx].ID[0]) + continue; + const QString identifier = tr(gCommands[actionIdx].ID); int pos = identifier.indexOf(QLatin1Char('.'));