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();
|
VPSheet *sheet = layout->GetFocusedSheet();
|
||||||
piece->SetSheet(sheet);
|
piece->SetSheet(sheet);
|
||||||
emit layout->PieceSheetChanged(piece);
|
emit layout->PieceSheetChanged(piece);
|
||||||
m_carrousel->Refresh();
|
|
||||||
}
|
}
|
||||||
else if (selectedAction == deleteAction)
|
else if (selectedAction == deleteAction)
|
||||||
{
|
{
|
||||||
VPSheet *sheet = layout->GetTrashSheet();
|
VPSheet *sheet = layout->GetTrashSheet();
|
||||||
piece->SetSheet(sheet);
|
piece->SetSheet(sheet);
|
||||||
emit layout->PieceSheetChanged(piece);
|
emit layout->PieceSheetChanged(piece);
|
||||||
m_carrousel->Refresh();
|
|
||||||
}
|
}
|
||||||
else if (selectedAction == removeAction)
|
else if (selectedAction == removeAction)
|
||||||
{
|
{
|
||||||
piece->SetSheet(nullptr);
|
piece->SetSheet(nullptr);
|
||||||
emit layout->PieceSheetChanged(piece);
|
emit layout->PieceSheetChanged(piece);
|
||||||
m_carrousel->Refresh();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,7 +271,7 @@ void VPGraphicsPiece::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
bool selectionState = isSelected();
|
bool selectionState = isSelected();
|
||||||
//perform the default behaviour
|
//perform the default behaviour
|
||||||
QGraphicsItem::mousePressEvent(event);
|
QGraphicsObject::mousePressEvent(event);
|
||||||
|
|
||||||
// change the cursor when clicking the left button
|
// change the cursor when clicking the left button
|
||||||
if((event->button() == Qt::LeftButton))
|
if((event->button() == Qt::LeftButton))
|
||||||
|
@ -286,7 +286,6 @@ void VPGraphicsPiece::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// change the selected state when clicking left button
|
// change the selected state when clicking left button
|
||||||
if (event->button() == Qt::LeftButton)
|
if (event->button() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
|
@ -385,43 +384,40 @@ void VPGraphicsPiece::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VPGraphicsPiece::contextMenuEvent(QGraphicsSceneContextMenuEvent *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
|
if (not sheets.isEmpty())
|
||||||
// QList<VPPieceList*> pieceLists = QList<VPPieceList*>();
|
{
|
||||||
// for(auto sheet : m_piece->GetPieceList()->GetLayout()->GetSheets())
|
QMenu *moveMenu = menu.addMenu(tr("Move to"));
|
||||||
// {
|
|
||||||
// pieceLists.append(sheet->GetPieceList());
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 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)
|
// remove from layout action
|
||||||
// {
|
QAction *removeAction = menu.addAction(tr("Remove from Sheet"));
|
||||||
// QMenu *moveMenu = menu.addMenu(tr("Move to"));
|
|
||||||
|
|
||||||
// // TODO order in alphabetical order
|
QAction *selectedAction = menu.exec(event->screenPos());
|
||||||
|
|
||||||
// for (auto pieceList : pieceLists)
|
if (moveToActions.contains(selectedAction))
|
||||||
// {
|
{
|
||||||
// QAction* moveToPieceList = moveMenu->addAction(pieceList->GetName());
|
m_piece->SetSheet(qvariant_cast<VPSheet *>(selectedAction->data()));
|
||||||
// QVariant data = QVariant::fromValue(pieceList);
|
emit m_piece->Layout()->PieceSheetChanged(m_piece);
|
||||||
// moveToPieceList->setData(data);
|
}
|
||||||
|
else if (selectedAction == removeAction)
|
||||||
// connect(moveToPieceList, &QAction::triggered, this, &VPGraphicsPiece::on_ActionPieceMovedToPieceList);
|
{
|
||||||
// }
|
m_piece->SetSheet(nullptr);
|
||||||
// }
|
emit m_piece->Layout()->PieceSheetChanged(m_piece);
|
||||||
|
}
|
||||||
// // 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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -49,6 +49,9 @@ public:
|
||||||
*/
|
*/
|
||||||
auto GetPiece() -> VPPiece*;
|
auto GetPiece() -> VPPiece*;
|
||||||
|
|
||||||
|
virtual int type() const override {return Type;}
|
||||||
|
enum { Type = UserType + 1};
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/**
|
/**
|
||||||
* @brief on_PieceSelectionChanged Slot called when the piece selection was changed
|
* @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)
|
void VPMainGraphicsView::contextMenuEvent(QContextMenuEvent *event)
|
||||||
{
|
{
|
||||||
|
QGraphicsItem *item = itemAt(event->pos());
|
||||||
|
if (item != nullptr && item->type() == VPGraphicsPiece::Type)
|
||||||
|
{
|
||||||
|
VMainGraphicsView::contextMenuEvent(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QMenu menu;
|
QMenu menu;
|
||||||
|
|
||||||
VPSheet *sheet = m_layout->GetFocusedSheet();
|
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)
|
if (_graphicsPiece != nullptr)
|
||||||
{
|
{
|
||||||
scene()->removeItem(_graphicsPiece);
|
scene()->removeItem(_graphicsPiece);
|
||||||
m_graphicsPieces.removeAll(_graphicsPiece);
|
m_graphicsPieces.removeAll(_graphicsPiece);
|
||||||
|
delete _graphicsPiece;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // add
|
else // add
|
||||||
|
|
|
@ -736,6 +736,7 @@ void VPMainWindow::InitMainGraphics()
|
||||||
connect(m_graphicsView->GetScene(), &VMainGraphicsScene::mouseMove, this, &VPMainWindow::on_MouseMoved);
|
connect(m_graphicsView->GetScene(), &VMainGraphicsScene::mouseMove, this, &VPMainWindow::on_MouseMoved);
|
||||||
connect(m_carrousel, &VPCarrousel::on_ActiveSheetChanged, m_graphicsView, &VPMainGraphicsView::RefreshPieces);
|
connect(m_carrousel, &VPCarrousel::on_ActiveSheetChanged, m_graphicsView, &VPMainGraphicsView::RefreshPieces);
|
||||||
connect(m_graphicsView, &VPMainGraphicsView::on_SheetRemoved, m_carrousel, &VPCarrousel::Refresh);
|
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