mirror of
https://github.com/leozide/leocad
synced 2025-01-29 20:34:50 +01:00
Added drag and drop to the timeline.
This commit is contained in:
parent
958a7fa383
commit
7cb71e121c
5 changed files with 80 additions and 5 deletions
|
@ -546,6 +546,7 @@ void lcMainWindow::CreateToolBars()
|
|||
mTimelineToolBar = new QDockWidget(tr("Timeline"), this);
|
||||
mTimelineToolBar->setObjectName("TimelineToolbar");
|
||||
mTimelineToolBar->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
||||
mTimelineToolBar->setAcceptDrops(true);
|
||||
|
||||
mTimelineWidget = new lcTimelineWidget(mTimelineToolBar);
|
||||
|
||||
|
|
|
@ -1922,6 +1922,43 @@ void lcModel::ShowSelectedPiecesLater()
|
|||
SaveCheckpoint("Modifying");
|
||||
gMainWindow->UpdateAllViews();
|
||||
UpdateSelection();
|
||||
gMainWindow->UpdateFocusObject(GetFocusObject());
|
||||
}
|
||||
}
|
||||
|
||||
void lcModel::SetPieceSteps(const QList<QPair<lcPiece*, int>>& PieceSteps)
|
||||
{
|
||||
if (PieceSteps.size() != mPieces.GetSize())
|
||||
return;
|
||||
|
||||
bool Modified = false;
|
||||
|
||||
for (int PieceIdx = 0; PieceIdx < PieceSteps.size(); PieceIdx++)
|
||||
{
|
||||
const QPair<lcPiece*, int>& PieceStep = PieceSteps[PieceIdx];
|
||||
lcPiece* Piece = mPieces[PieceIdx];
|
||||
|
||||
if (Piece != PieceStep.first || Piece->GetStepShow() != PieceStep.second)
|
||||
{
|
||||
Piece = PieceStep.first;
|
||||
lcStep Step = PieceStep.second;
|
||||
|
||||
mPieces[PieceIdx] = Piece;
|
||||
Piece->SetStepShow(Step);
|
||||
|
||||
if (Step > mCurrentStep)
|
||||
Piece->SetSelected(false);
|
||||
|
||||
Modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (Modified)
|
||||
{
|
||||
SaveCheckpoint("Modifying");
|
||||
gMainWindow->UpdateAllViews();
|
||||
UpdateSelection();
|
||||
gMainWindow->UpdateFocusObject(GetFocusObject());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -195,6 +195,7 @@ public:
|
|||
void DeleteSelectedObjects();
|
||||
void ShowSelectedPiecesEarlier();
|
||||
void ShowSelectedPiecesLater();
|
||||
void SetPieceSteps(const QList<QPair<lcPiece*, int>>& PieceSteps);
|
||||
|
||||
lcGroup* AddGroup(const char* Prefix, lcGroup* Parent);
|
||||
lcGroup* GetGroup(const char* Name, bool CreateIfMissing);
|
||||
|
|
|
@ -8,7 +8,11 @@
|
|||
lcTimelineWidget::lcTimelineWidget(QWidget* Parent)
|
||||
: QTreeWidget(Parent)
|
||||
{
|
||||
header()->hide();
|
||||
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
setDragEnabled(true);
|
||||
setDragDropMode(QAbstractItemView::InternalMove);
|
||||
setUniformRowHeights(true);
|
||||
setHeaderHidden(true);
|
||||
}
|
||||
|
||||
lcTimelineWidget::~lcTimelineWidget()
|
||||
|
@ -25,19 +29,48 @@ void lcTimelineWidget::Update()
|
|||
return;
|
||||
|
||||
int Steps = Model->GetLastStep();
|
||||
QList<QTreeWidgetItem*> StepItems;
|
||||
StepItems.reserve(Steps);
|
||||
QList<QTreeWidgetItem*> StepItems;
|
||||
StepItems.reserve(Steps);
|
||||
|
||||
for (int Step = 0; Step < Steps; Step++)
|
||||
StepItems.append(new QTreeWidgetItem(this, QStringList(tr("Step %1").arg(Step + 1))));
|
||||
{
|
||||
QTreeWidgetItem* StepItem = new QTreeWidgetItem(this, QStringList(tr("Step %1").arg(Step + 1)));
|
||||
StepItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
|
||||
StepItems.append(StepItem);
|
||||
}
|
||||
|
||||
const lcArray<lcPiece*>& Pieces = Model->GetPieces();
|
||||
|
||||
for (int PieceIdx = 0; PieceIdx < Pieces.GetSize(); PieceIdx++)
|
||||
{
|
||||
lcPiece* Piece = Pieces[PieceIdx];
|
||||
new QTreeWidgetItem(StepItems[Piece->GetStepShow() - 1], QStringList(Piece->mPieceInfo->m_strDescription));
|
||||
QTreeWidgetItem* PieceItem = new QTreeWidgetItem(StepItems[Piece->GetStepShow() - 1], QStringList(Piece->mPieceInfo->m_strDescription));
|
||||
PieceItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);
|
||||
PieceItem->setData(0, Qt::UserRole, qVariantFromValue<uintptr_t>((uintptr_t)Piece));
|
||||
}
|
||||
|
||||
insertTopLevelItems(0, StepItems);
|
||||
expandAll();
|
||||
}
|
||||
|
||||
void lcTimelineWidget::dropEvent(QDropEvent* Event)
|
||||
{
|
||||
QTreeWidget::dropEvent(Event);
|
||||
|
||||
QList<QPair<lcPiece*, int>> PieceSteps;
|
||||
|
||||
for (int TopLevelItemIdx = 0; TopLevelItemIdx < topLevelItemCount(); TopLevelItemIdx++)
|
||||
{
|
||||
QTreeWidgetItem* StepItem = topLevelItem(TopLevelItemIdx);
|
||||
|
||||
for (int PieceItemIdx = 0; PieceItemIdx < StepItem->childCount(); PieceItemIdx++)
|
||||
{
|
||||
QTreeWidgetItem* PieceItem = StepItem->child(PieceItemIdx);
|
||||
lcPiece* Piece = (lcPiece*)PieceItem->data(0, Qt::UserRole).value<uintptr_t>();
|
||||
|
||||
PieceSteps.append(QPair<lcPiece*, int>(Piece, TopLevelItemIdx + 1));
|
||||
}
|
||||
}
|
||||
|
||||
lcGetActiveModel()->SetPieceSteps(PieceSteps);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,9 @@ public:
|
|||
virtual ~lcTimelineWidget();
|
||||
|
||||
void Update();
|
||||
|
||||
protected:
|
||||
virtual void dropEvent(QDropEvent* Event);
|
||||
};
|
||||
|
||||
#endif // _LC_TIMELINEWIDGET_H_
|
||||
|
|
Loading…
Add table
Reference in a new issue