Restored a piece context menu.
This commit is contained in:
parent
2eecf95af9
commit
c7db3de6d8
|
@ -198,20 +198,17 @@ void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event)
|
|||
VPSheet *sheet = layout->GetFocusedSheet();
|
||||
piece->SetSheet(sheet);
|
||||
emit layout->PieceSheetChanged(piece);
|
||||
m_carrousel->Refresh();
|
||||
}
|
||||
else if (selectedAction == deleteAction)
|
||||
{
|
||||
VPSheet *sheet = layout->GetTrashSheet();
|
||||
piece->SetSheet(sheet);
|
||||
emit layout->PieceSheetChanged(piece);
|
||||
m_carrousel->Refresh();
|
||||
}
|
||||
else if (selectedAction == removeAction)
|
||||
{
|
||||
piece->SetSheet(nullptr);
|
||||
emit layout->PieceSheetChanged(piece);
|
||||
m_carrousel->Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -271,7 +271,7 @@ void VPGraphicsPiece::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||
{
|
||||
bool selectionState = isSelected();
|
||||
//perform the default behaviour
|
||||
QGraphicsItem::mousePressEvent(event);
|
||||
QGraphicsObject::mousePressEvent(event);
|
||||
|
||||
// change the cursor when clicking the left button
|
||||
if((event->button() == Qt::LeftButton))
|
||||
|
@ -286,7 +286,6 @@ void VPGraphicsPiece::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// change the selected state when clicking left button
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
|
@ -385,43 +384,40 @@ void VPGraphicsPiece::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPGraphicsPiece::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
||||
{
|
||||
QMenu menu;
|
||||
|
||||
// TODO/FIXME context menu needs to be refactored
|
||||
QList<VPSheet *> sheets = m_piece->Layout()->GetSheets();
|
||||
sheets.removeAll(m_piece->Sheet());
|
||||
|
||||
// QMenu menu;
|
||||
QVector<QAction*> moveToActions;
|
||||
|
||||
// // move to piece list actions -- TODO : To be tested properly when we have several piece lists
|
||||
// QList<VPPieceList*> pieceLists = QList<VPPieceList*>();
|
||||
// for(auto sheet : m_piece->GetPieceList()->GetLayout()->GetSheets())
|
||||
// {
|
||||
// pieceLists.append(sheet->GetPieceList());
|
||||
// }
|
||||
if (not sheets.isEmpty())
|
||||
{
|
||||
QMenu *moveMenu = menu.addMenu(tr("Move to"));
|
||||
|
||||
// pieceLists.removeAll(m_piece->GetPieceList());
|
||||
for (auto *sheet : sheets)
|
||||
{
|
||||
QAction* moveToSheet = moveMenu->addAction(sheet->GetName());
|
||||
moveToSheet->setData(QVariant::fromValue(sheet));
|
||||
moveToActions.append(moveToSheet);
|
||||
}
|
||||
}
|
||||
|
||||
// if(pieceLists.count() > 0)
|
||||
// {
|
||||
// QMenu *moveMenu = menu.addMenu(tr("Move to"));
|
||||
// remove from layout action
|
||||
QAction *removeAction = menu.addAction(tr("Remove from Sheet"));
|
||||
|
||||
// // TODO order in alphabetical order
|
||||
QAction *selectedAction = menu.exec(event->screenPos());
|
||||
|
||||
// for (auto pieceList : pieceLists)
|
||||
// {
|
||||
// QAction* moveToPieceList = moveMenu->addAction(pieceList->GetName());
|
||||
// QVariant data = QVariant::fromValue(pieceList);
|
||||
// moveToPieceList->setData(data);
|
||||
|
||||
// connect(moveToPieceList, &QAction::triggered, this, &VPGraphicsPiece::on_ActionPieceMovedToPieceList);
|
||||
// }
|
||||
// }
|
||||
|
||||
// // remove from layout action
|
||||
// QAction *removeAction = menu.addAction(tr("Remove from Sheet"));
|
||||
// QVariant data = QVariant::fromValue(m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList());
|
||||
// removeAction->setData(data);
|
||||
// connect(removeAction, &QAction::triggered, this, &VPGraphicsPiece::on_ActionPieceMovedToPieceList);
|
||||
|
||||
// menu.exec(event->screenPos());
|
||||
if (moveToActions.contains(selectedAction))
|
||||
{
|
||||
m_piece->SetSheet(qvariant_cast<VPSheet *>(selectedAction->data()));
|
||||
emit m_piece->Layout()->PieceSheetChanged(m_piece);
|
||||
}
|
||||
else if (selectedAction == removeAction)
|
||||
{
|
||||
m_piece->SetSheet(nullptr);
|
||||
emit m_piece->Layout()->PieceSheetChanged(m_piece);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -49,6 +49,9 @@ public:
|
|||
*/
|
||||
auto GetPiece() -> VPPiece*;
|
||||
|
||||
virtual int type() const override {return Type;}
|
||||
enum { Type = UserType + 1};
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief on_PieceSelectionChanged Slot called when the piece selection was changed
|
||||
|
|
|
@ -220,6 +220,13 @@ void VPMainGraphicsView::keyPressEvent(QKeyEvent *event)
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPMainGraphicsView::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
QGraphicsItem *item = itemAt(event->pos());
|
||||
if (item != nullptr && item->type() == VPGraphicsPiece::Type)
|
||||
{
|
||||
VMainGraphicsView::contextMenuEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
QMenu menu;
|
||||
|
||||
VPSheet *sheet = m_layout->GetFocusedSheet();
|
||||
|
@ -258,12 +265,14 @@ void VPMainGraphicsView::on_PieceSheetChanged(VPPiece *piece)
|
|||
}
|
||||
}
|
||||
|
||||
if (piece->Sheet() == nullptr || piece->Sheet() == m_layout->GetTrashSheet()) // remove
|
||||
if (piece->Sheet() == nullptr || piece->Sheet() == m_layout->GetTrashSheet() ||
|
||||
piece->Sheet() != m_layout->GetFocusedSheet()) // remove
|
||||
{
|
||||
if (_graphicsPiece != nullptr)
|
||||
{
|
||||
scene()->removeItem(_graphicsPiece);
|
||||
m_graphicsPieces.removeAll(_graphicsPiece);
|
||||
delete _graphicsPiece;
|
||||
}
|
||||
}
|
||||
else // add
|
||||
|
|
|
@ -736,6 +736,7 @@ void VPMainWindow::InitMainGraphics()
|
|||
connect(m_graphicsView->GetScene(), &VMainGraphicsScene::mouseMove, this, &VPMainWindow::on_MouseMoved);
|
||||
connect(m_carrousel, &VPCarrousel::on_ActiveSheetChanged, m_graphicsView, &VPMainGraphicsView::RefreshPieces);
|
||||
connect(m_graphicsView, &VPMainGraphicsView::on_SheetRemoved, m_carrousel, &VPCarrousel::Refresh);
|
||||
connect(m_layout, &VPLayout::PieceSheetChanged, m_carrousel, &VPCarrousel::Refresh);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue
Block a user