diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index 1c782d54..4ff35713 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -1359,7 +1359,6 @@ void lcMainWindow::RemoveRecentFile(int FileIndex) void lcMainWindow::UpdateFocusObject(lcObject* Focus) { - UpdateTimeline(); mPropertiesWidget->updateFocusObject(Focus); lcVector3 Position; diff --git a/common/lc_model.cpp b/common/lc_model.cpp index 6569165a..4c15ad90 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -849,6 +849,8 @@ void lcModel::Merge(lcModel* Other) Other->mGroups.RemoveAll(); delete Other; + + gMainWindow->UpdateTimeline(); } void lcModel::Cut() @@ -857,6 +859,7 @@ void lcModel::Cut() if (RemoveSelectedObjects()) { + gMainWindow->UpdateTimeline(); gMainWindow->UpdateFocusObject(NULL); UpdateSelection(); gMainWindow->UpdateAllViews(); @@ -890,9 +893,10 @@ void lcModel::Paste() Merge(Model); SaveCheckpoint(tr("Pasting")); - SetSelection((lcArray&)PastedPieces); + SetSelectionAndFocus((lcArray&)PastedPieces, NULL, 0); CalculateStep(mCurrentStep); + gMainWindow->UpdateTimeline(); gMainWindow->UpdateAllViews(); } @@ -1219,6 +1223,7 @@ void lcModel::LoadCheckPoint(lcModelHistoryEntry* CheckPoint) Buffer.open(QIODevice::ReadOnly); LoadLDraw(Buffer, lcGetActiveProject()); + gMainWindow->UpdateTimeline(); gMainWindow->UpdateFocusObject(GetFocusObject()); gMainWindow->UpdateCameraMenu(); UpdateSelection(); @@ -1355,6 +1360,7 @@ void lcModel::InsertStep() SaveCheckpoint(tr("Inserting Step")); CalculateStep(mCurrentStep); + gMainWindow->UpdateTimeline(); gMainWindow->UpdateFocusObject(GetFocusObject()); gMainWindow->UpdateAllViews(); UpdateSelection(); @@ -1378,6 +1384,7 @@ void lcModel::RemoveStep() SaveCheckpoint(tr("Removing Step")); CalculateStep(mCurrentStep); + gMainWindow->UpdateTimeline(); gMainWindow->UpdateFocusObject(GetFocusObject()); gMainWindow->UpdateAllViews(); UpdateSelection(); @@ -1835,6 +1842,7 @@ void lcModel::AddPiece() Piece->Initialize(WorldMatrix, mCurrentStep); Piece->SetColorIndex(gMainWindow->mColorIndex); AddPiece(Piece); + gMainWindow->UpdateTimeline(); ClearSelectionAndSetFocus(Piece, LC_PIECE_SECTION_POSITION); SaveCheckpoint("Adding Piece"); @@ -1871,6 +1879,7 @@ void lcModel::DeleteSelectedObjects() { if (RemoveSelectedObjects()) { + gMainWindow->UpdateTimeline(); gMainWindow->UpdateFocusObject(NULL); UpdateSelection(); gMainWindow->UpdateAllViews(); @@ -1989,6 +1998,7 @@ void lcModel::SetPieceSteps(const QList>& PieceSteps) SaveCheckpoint("Modifying"); gMainWindow->UpdateAllViews(); UpdateSelection(); + gMainWindow->UpdateTimeline(); gMainWindow->UpdateFocusObject(GetFocusObject()); } } @@ -2450,6 +2460,7 @@ void lcModel::SetObjectProperty(lcObject* Object, lcObjectPropertyType ObjectPro if (!CheckPointString.isEmpty()) { SaveCheckpoint(CheckPointString); + gMainWindow->UpdateTimeline(); gMainWindow->UpdateFocusObject(GetFocusObject()); gMainWindow->UpdateAllViews(); } @@ -2930,10 +2941,19 @@ void lcModel::ClearSelectionAndSetFocus(const lcObjectSection& ObjectSection) ClearSelectionAndSetFocus(ObjectSection.Object, ObjectSection.Section); } -void lcModel::SetSelection(const lcArray& Objects) +void lcModel::SetSelectionAndFocus(const lcArray& Selection, lcObject* Focus, lcuint32 Section) { ClearSelection(false); - AddToSelection(Objects); + + if (Focus) + { + Focus->SetFocused(Section, true); + + if (Focus->IsPiece()) + SelectGroup(((lcPiece*)Focus)->GetTopGroup(), true); + } + + AddToSelection(Selection); } void lcModel::AddToSelection(const lcArray& Objects) @@ -3186,6 +3206,7 @@ void lcModel::InsertPieceToolClicked(const lcMatrix44& WorldMatrix) Piece->UpdatePosition(mCurrentStep); AddPiece(Piece); + gMainWindow->UpdateTimeline(); ClearSelectionAndSetFocus(Piece, LC_PIECE_SECTION_POSITION); SaveCheckpoint(tr("Insert")); @@ -3306,6 +3327,7 @@ void lcModel::EraserToolClicked(lcObject* Object) } delete Object; + gMainWindow->UpdateTimeline(); gMainWindow->UpdateFocusObject(GetFocusObject()); UpdateSelection(); gMainWindow->UpdateAllViews(); @@ -3471,7 +3493,7 @@ void lcModel::ShowSelectByNameDialog() if (!gMainWindow->DoDialog(LC_DIALOG_SELECT_BY_NAME, &Options)) return; - SetSelection(Options.Objects); + SetSelectionAndFocus(Options.Objects, NULL, 0); } void lcModel::ShowArrayDialog() @@ -3550,6 +3572,7 @@ void lcModel::ShowArrayDialog() } AddToSelection(NewPieces); + gMainWindow->UpdateTimeline(); SaveCheckpoint(tr("Array")); } @@ -3581,7 +3604,8 @@ void lcModel::ShowMinifigDialog() Pieces.Add(Piece); } - SetSelection(Pieces); + SetSelectionAndFocus(Pieces, NULL, 0); + gMainWindow->UpdateTimeline(); SaveCheckpoint(tr("Minifig")); } diff --git a/common/lc_model.h b/common/lc_model.h index d41956c1..11bd2249 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -251,7 +251,7 @@ public: void ClearSelection(bool UpdateInterface); void ClearSelectionAndSetFocus(lcObject* Object, lcuint32 Section); void ClearSelectionAndSetFocus(const lcObjectSection& ObjectSection); - void SetSelection(const lcArray& Objects); + void SetSelectionAndFocus(const lcArray& Selection, lcObject* Focus, lcuint32 Section); void AddToSelection(const lcArray& Objects); void SelectAllPieces(); void InvertSelection(); diff --git a/common/lc_timelinewidget.cpp b/common/lc_timelinewidget.cpp index 7af90d2c..b3f73825 100644 --- a/common/lc_timelinewidget.cpp +++ b/common/lc_timelinewidget.cpp @@ -39,6 +39,9 @@ void lcTimelineWidget::CustomMenuRequested(QPoint Pos) void lcTimelineWidget::Update() { + if (mIgnoreUpdates) + return; + lcModel* Model = lcGetActiveModel(); if (!Model) @@ -67,9 +70,9 @@ void lcTimelineWidget::Update() delete StepItem; } - for (int Step = topLevelItemCount(); Step < Steps; Step++) + for (int TopLevelItemIdx = topLevelItemCount(); TopLevelItemIdx < Steps; TopLevelItemIdx++) { - QTreeWidgetItem* StepItem = new QTreeWidgetItem(this, QStringList(tr("Step %1").arg(Step + 1))); + QTreeWidgetItem* StepItem = new QTreeWidgetItem(this, QStringList(tr("Step %1").arg(TopLevelItemIdx + 1))); StepItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDropEnabled); addTopLevelItem(StepItem); StepItem->setExpanded(true); @@ -78,13 +81,13 @@ void lcTimelineWidget::Update() const lcArray& Pieces = Model->GetPieces(); QTreeWidgetItem* StepItem = NULL; int PieceItemIndex = 0; - int Step = -1; + int Step = 0; for (int PieceIdx = 0; PieceIdx != Pieces.GetSize(); PieceIdx++) { lcPiece* Piece = Pieces[PieceIdx]; - if (Step != Piece->GetStepShow()) + while (Step != Piece->GetStepShow()) { if (StepItem) { @@ -106,7 +109,7 @@ void lcTimelineWidget::Update() } } - Step = Piece->GetStepShow(); + Step++; StepItem = topLevelItem(Step - 1); PieceItemIndex = 0; } @@ -184,9 +187,14 @@ void lcTimelineWidget::ItemSelectionChanged() Selection.Add(Piece); } + lcPiece* CurrentPiece = NULL; + QTreeWidgetItem* CurrentItem = currentItem(); + if (CurrentItem && CurrentItem->isSelected()) + CurrentPiece = (lcPiece*)CurrentItem->data(0, Qt::UserRole).value(); + bool Blocked = blockSignals(true); mIgnoreUpdates = true; - lcGetActiveModel()->SetSelection(Selection); + lcGetActiveModel()->SetSelectionAndFocus(Selection, CurrentPiece, LC_PIECE_SECTION_POSITION); mIgnoreUpdates = false; blockSignals(Blocked); } @@ -210,5 +218,7 @@ void lcTimelineWidget::dropEvent(QDropEvent* Event) } } + mIgnoreUpdates = true; lcGetActiveModel()->SetPieceSteps(PieceSteps); + mIgnoreUpdates = false; } diff --git a/common/view.cpp b/common/view.cpp index 4579e8d8..03e8d73e 100644 --- a/common/view.cpp +++ b/common/view.cpp @@ -1921,7 +1921,7 @@ void View::StopTracking(bool Accept) if (mInputState.Control) mModel->AddToSelection(Objects); else - mModel->SetSelection(Objects); + mModel->SetSelectionAndFocus(Objects, NULL, 0); } break;