From 05b884a6328d8bc3797e4b8d192bd549164c7428 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 28 Sep 2021 16:34:25 +0300 Subject: [PATCH] Context-menu on a piece in the carrousel should be the same as the context menu of a piece in the sheet --- .../puzzle/carousel/vpcarrouselpiecelist.cpp | 44 +++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/src/app/puzzle/carousel/vpcarrouselpiecelist.cpp b/src/app/puzzle/carousel/vpcarrouselpiecelist.cpp index b4538f0a7..8d56e384d 100644 --- a/src/app/puzzle/carousel/vpcarrouselpiecelist.cpp +++ b/src/app/puzzle/carousel/vpcarrouselpiecelist.cpp @@ -176,8 +176,39 @@ void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event) { auto *pieceItem = static_cast (_item); + VPPiecePtr piece = pieceItem->GetPiece(); + VPLayoutPtr layout = piece->Layout(); + + if (piece.isNull() || layout.isNull()) + { + return; + } + QMenu menu; + QVector moveToActions; + + if (not piece->Sheet().isNull()) + { + QList 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(selectedAction->data()), piece); + layout->UndoStack()->push(command); + } } }