mirror of
https://github.com/leozide/leocad
synced 2024-12-27 21:58:37 +01:00
Made the timeline selection match the current model selection.
This commit is contained in:
parent
7cb71e121c
commit
9446e2cde7
3 changed files with 162 additions and 67 deletions
|
@ -1372,6 +1372,8 @@ void lcMainWindow::UpdateFocusObject(lcObject* Focus)
|
|||
|
||||
void lcMainWindow::UpdateSelectedObjects(int Flags, int SelectedCount, lcObject* Focus)
|
||||
{
|
||||
mTimelineWidget->UpdateSelection();
|
||||
|
||||
mActions[LC_EDIT_CUT]->setEnabled(Flags & LC_SEL_SELECTED);
|
||||
mActions[LC_EDIT_COPY]->setEnabled(Flags & LC_SEL_SELECTED);
|
||||
mActions[LC_EDIT_FIND]->setEnabled((Flags & LC_SEL_NO_PIECES) == 0);
|
||||
|
|
|
@ -4,39 +4,68 @@
|
|||
#include "project.h"
|
||||
#include "piece.h"
|
||||
#include "pieceinf.h"
|
||||
#include "lc_mainwindow.h"
|
||||
|
||||
lcTimelineWidget::lcTimelineWidget(QWidget* Parent)
|
||||
: QTreeWidget(Parent)
|
||||
{
|
||||
mIgnoreUpdates = false;
|
||||
|
||||
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
setDragEnabled(true);
|
||||
setDragDropMode(QAbstractItemView::InternalMove);
|
||||
setUniformRowHeights(true);
|
||||
setHeaderHidden(true);
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
connect(this, SIGNAL(itemSelectionChanged()), SLOT(ItemSelectionChanged()));
|
||||
connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(CustomMenuRequested(QPoint)));
|
||||
}
|
||||
|
||||
lcTimelineWidget::~lcTimelineWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void lcTimelineWidget::CustomMenuRequested(QPoint Pos)
|
||||
{
|
||||
QList<QTreeWidgetItem*> SelectedItems = selectedItems();
|
||||
|
||||
if (!SelectedItems.isEmpty())
|
||||
{
|
||||
QMenu* Menu = new QMenu(this);
|
||||
|
||||
Menu->addAction(gMainWindow->mActions[LC_PIECE_HIDE_SELECTED]);
|
||||
Menu->addAction(gMainWindow->mActions[LC_PIECE_HIDE_UNSELECTED]);
|
||||
Menu->addAction(gMainWindow->mActions[LC_PIECE_UNHIDE_ALL]);
|
||||
|
||||
Menu->popup(viewport()->mapToGlobal(Pos));
|
||||
}
|
||||
}
|
||||
|
||||
void lcTimelineWidget::Update()
|
||||
{
|
||||
clear();
|
||||
|
||||
lcModel* Model = lcGetActiveModel();
|
||||
|
||||
if (!Model)
|
||||
{
|
||||
mItems.clear();
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
|
||||
bool Blocked = blockSignals(true);
|
||||
|
||||
int Steps = Model->GetLastStep();
|
||||
QList<QTreeWidgetItem*> StepItems;
|
||||
StepItems.reserve(Steps);
|
||||
|
||||
for (int Step = 0; Step < Steps; Step++)
|
||||
for (int TopLevelItemIdx = Steps; TopLevelItemIdx < topLevelItemCount(); TopLevelItemIdx++)
|
||||
delete topLevelItem(TopLevelItemIdx);
|
||||
|
||||
for (int Step = topLevelItemCount(); Step < Steps; Step++)
|
||||
{
|
||||
QTreeWidgetItem* StepItem = new QTreeWidgetItem(this, QStringList(tr("Step %1").arg(Step + 1)));
|
||||
StepItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
|
||||
StepItems.append(StepItem);
|
||||
addTopLevelItem(StepItem);
|
||||
StepItem->setExpanded(true);
|
||||
}
|
||||
|
||||
const lcArray<lcPiece*>& Pieces = Model->GetPieces();
|
||||
|
@ -44,13 +73,67 @@ void lcTimelineWidget::Update()
|
|||
for (int PieceIdx = 0; PieceIdx < Pieces.GetSize(); PieceIdx++)
|
||||
{
|
||||
lcPiece* Piece = Pieces[PieceIdx];
|
||||
QTreeWidgetItem* PieceItem = new QTreeWidgetItem(StepItems[Piece->GetStepShow() - 1], QStringList(Piece->mPieceInfo->m_strDescription));
|
||||
QTreeWidgetItem* PieceItem = mItems.value(Piece);
|
||||
QTreeWidgetItem* StepItem = topLevelItem(Piece->GetStepShow() - 1);
|
||||
|
||||
if (PieceItem)
|
||||
{
|
||||
if (PieceItem->parent() != StepItem)
|
||||
StepItem->addChild(PieceItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
PieceItem = new QTreeWidgetItem(StepItem, QStringList(Piece->mPieceInfo->m_strDescription));
|
||||
PieceItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);
|
||||
PieceItem->setData(0, Qt::UserRole, qVariantFromValue<uintptr_t>((uintptr_t)Piece));
|
||||
StepItem->addChild(PieceItem);
|
||||
mItems[Piece] = PieceItem;
|
||||
}
|
||||
|
||||
insertTopLevelItems(0, StepItems);
|
||||
expandAll();
|
||||
PieceItem->setSelected(Piece->IsSelected());
|
||||
}
|
||||
|
||||
blockSignals(Blocked);
|
||||
}
|
||||
|
||||
void lcTimelineWidget::UpdateSelection()
|
||||
{
|
||||
if (mIgnoreUpdates)
|
||||
return;
|
||||
|
||||
bool Blocked = blockSignals(true);
|
||||
|
||||
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>();
|
||||
|
||||
PieceItem->setSelected(Piece->IsSelected());
|
||||
}
|
||||
}
|
||||
|
||||
blockSignals(Blocked);
|
||||
}
|
||||
|
||||
void lcTimelineWidget::ItemSelectionChanged()
|
||||
{
|
||||
lcArray<lcObject*> Selection;
|
||||
|
||||
foreach (QTreeWidgetItem* PieceItem, selectedItems())
|
||||
{
|
||||
lcPiece* Piece = (lcPiece*)PieceItem->data(0, Qt::UserRole).value<uintptr_t>();
|
||||
Selection.Add(Piece);
|
||||
}
|
||||
|
||||
bool Blocked = blockSignals(true);
|
||||
mIgnoreUpdates = true;
|
||||
lcGetActiveModel()->SetSelection(Selection);
|
||||
mIgnoreUpdates = false;
|
||||
blockSignals(Blocked);
|
||||
}
|
||||
|
||||
void lcTimelineWidget::dropEvent(QDropEvent* Event)
|
||||
|
|
|
@ -3,14 +3,24 @@
|
|||
|
||||
class lcTimelineWidget : public QTreeWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
lcTimelineWidget(QWidget* Parent);
|
||||
virtual ~lcTimelineWidget();
|
||||
|
||||
void Update();
|
||||
void UpdateSelection();
|
||||
|
||||
public slots:
|
||||
void ItemSelectionChanged();
|
||||
void CustomMenuRequested(QPoint Pos);
|
||||
|
||||
protected:
|
||||
virtual void dropEvent(QDropEvent* Event);
|
||||
|
||||
QMap<lcPiece*, QTreeWidgetItem*> mItems;
|
||||
bool mIgnoreUpdates;
|
||||
};
|
||||
|
||||
#endif // _LC_TIMELINEWIDGET_H_
|
||||
|
|
Loading…
Reference in a new issue