Context-menu on a piece in the carrousel should be the same as the context menu of a piece in the sheet

This commit is contained in:
Roman Telezhynskyi 2021-09-28 16:34:25 +03:00
parent 72a2300bef
commit 05b884a632

View file

@ -176,8 +176,39 @@ void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event)
{
auto *pieceItem = static_cast<VPCarrouselPiece *> (_item);
VPPiecePtr piece = pieceItem->GetPiece();
VPLayoutPtr layout = piece->Layout();
if (piece.isNull() || layout.isNull())
{
return;
}
QMenu menu;
QVector<QAction*> moveToActions;
if (not piece->Sheet().isNull())
{
QList<VPSheetPtr> sheets = layout->GetSheets();
sheets.removeAll(piece->Sheet());
if (not sheets.isEmpty())
{
QMenu *moveMenu = menu.addMenu(tr("Move to"));
for (const auto &sheet : sheets)
{
if (not sheet.isNull())
{
QAction* moveToSheet = moveMenu->addAction(sheet->GetName());
moveToSheet->setData(QVariant::fromValue(sheet));
moveToActions.append(moveToSheet);
}
}
}
}
QAction *moveAction = menu.addAction(tr("Move to Sheet"));
moveAction->setVisible(false);
@ -200,14 +231,6 @@ void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event)
QAction *selectedAction = menu.exec(event->globalPos());
VPPiecePtr piece = pieceItem->GetPiece();
VPLayoutPtr layout = piece->Layout();
if (piece.isNull() || layout.isNull())
{
return;
}
if (selectedAction == moveAction)
{
VPSheetPtr sheet = layout->GetFocusedSheet();
@ -230,6 +253,11 @@ void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event)
auto *command = new VPUndoMovePieceOnSheet(VPSheetPtr(), piece);
layout->UndoStack()->push(command);
}
else if (moveToActions.contains(selectedAction))
{
auto *command = new VPUndoMovePieceOnSheet(qvariant_cast<VPSheetPtr>(selectedAction->data()), piece);
layout->UndoStack()->push(command);
}
}
}