diff --git a/src/app/puzzle/vpuzzlelayer.cpp b/src/app/puzzle/vpuzzlelayer.cpp index 37a8cdec8..efe1ce0dd 100644 --- a/src/app/puzzle/vpuzzlelayer.cpp +++ b/src/app/puzzle/vpuzzlelayer.cpp @@ -58,6 +58,16 @@ QList VPuzzleLayer::GetPieces() return m_pieces; } + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzleLayer::ClearSelection() +{ + for (auto piece: m_pieces) + { + piece->SetIsSelected(false); + } +} + //--------------------------------------------------------------------------------------------------------------------- void VPuzzleLayer::AddPiece(VPuzzlePiece *piece) { diff --git a/src/app/puzzle/vpuzzlelayer.h b/src/app/puzzle/vpuzzlelayer.h index b35e9d669..435701eff 100644 --- a/src/app/puzzle/vpuzzlelayer.h +++ b/src/app/puzzle/vpuzzlelayer.h @@ -59,6 +59,11 @@ public: */ VPuzzleLayout* GetLayout(); + /** + * @brief ClearSelection Clears the selection of the pieces in this layer + */ + void ClearSelection(); + signals: /** * @brief PieceAdded The signal is emited when a piece was added diff --git a/src/app/puzzle/vpuzzlelayout.cpp b/src/app/puzzle/vpuzzlelayout.cpp index 9f18a10d7..9020f3dac 100644 --- a/src/app/puzzle/vpuzzlelayout.cpp +++ b/src/app/puzzle/vpuzzlelayout.cpp @@ -275,9 +275,11 @@ bool VPuzzleLayout::GetStickyEdges() const //--------------------------------------------------------------------------------------------------------------------- void VPuzzleLayout::ClearSelection() { - for(auto piece : GetSelectedPieces()) + m_unplacedPiecesLayer->ClearSelection(); + + for (auto layer : m_layers) { - piece->SetIsSelected(false); + layer->ClearSelection(); } } diff --git a/src/app/puzzle/vpuzzlemaingraphicsview.cpp b/src/app/puzzle/vpuzzlemaingraphicsview.cpp index 75d68e14f..b8406469a 100644 --- a/src/app/puzzle/vpuzzlemaingraphicsview.cpp +++ b/src/app/puzzle/vpuzzlemaingraphicsview.cpp @@ -59,6 +59,7 @@ VPuzzleMainGraphicsView::VPuzzleMainGraphicsView(VPuzzleLayout *layout, QWidget // add the connections connect(m_layout, &VPuzzleLayout::PieceMovedToLayer, this, &VPuzzleMainGraphicsView::on_PieceMovedToLayer); + connect(m_scene, &VPuzzleMainGraphicsScene::selectionChanged, this, &VPuzzleMainGraphicsView::on_SceneSelectionChanged); } //--------------------------------------------------------------------------------------------------------------------- @@ -143,12 +144,15 @@ void VPuzzleMainGraphicsView::keyPressEvent(QKeyEvent *event) { if(event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete) { - for(auto graphicsPiece : m_graphicsPieces) + QList tmpGraphicsPieces = m_graphicsPieces; + + for(auto graphicsPiece : tmpGraphicsPieces) { VPuzzlePiece *piece = graphicsPiece->GetPiece(); if(piece->GetIsSelected()) { + piece->SetIsSelected(false); m_layout->MovePieceToLayer(piece, m_layout->GetUnplacedPiecesLayer()); } } @@ -188,3 +192,13 @@ void VPuzzleMainGraphicsView::on_PieceMovedToLayer(VPuzzlePiece *piece, VPuzzleL _graphicsPiece->update(); } } + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzleMainGraphicsView::on_SceneSelectionChanged() +{ + // most of the selection behaviour taks place automatically + // but we need to make sure that the unplaced pieces are unselected when the scene selection has changed + // because as they are not part of the scene, they are not updated + + m_layout->GetUnplacedPiecesLayer()->ClearSelection(); +} diff --git a/src/app/puzzle/vpuzzlemaingraphicsview.h b/src/app/puzzle/vpuzzlemaingraphicsview.h index 623e47d13..fea0d7947 100644 --- a/src/app/puzzle/vpuzzlemaingraphicsview.h +++ b/src/app/puzzle/vpuzzlemaingraphicsview.h @@ -67,6 +67,11 @@ private slots: */ void on_PieceMovedToLayer(VPuzzlePiece *piece, VPuzzleLayer *layerBefore, VPuzzleLayer *layerAfter); + /** + * @brief on_SceneSelectionChanged Slot is called when the scene selection has changed + */ + void on_SceneSelectionChanged(); + private: Q_DISABLE_COPY(VPuzzleMainGraphicsView)