diff --git a/src/app/puzzle/scene/vpgraphicspiece.cpp b/src/app/puzzle/scene/vpgraphicspiece.cpp index 336e2baef..16b7d0b1b 100644 --- a/src/app/puzzle/scene/vpgraphicspiece.cpp +++ b/src/app/puzzle/scene/vpgraphicspiece.cpp @@ -76,11 +76,18 @@ auto VPGraphicsPiece::GetPiece() -> VPPiece* return m_piece; } +//--------------------------------------------------------------------------------------------------------------------- +void VPGraphicsPiece::TranslatePiece(qreal dx, qreal dy) +{ + TranslatePiece(QPointF(dx, dy)); +} + //--------------------------------------------------------------------------------------------------------------------- void VPGraphicsPiece::TranslatePiece(const QPointF &p) { - m_piece->Translate(p); prepareGeometryChange(); + m_piece->Translate(p); + PaintPiece(); // refresh shapes } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/scene/vpgraphicspiece.h b/src/app/puzzle/scene/vpgraphicspiece.h index 5e683c434..f635d9135 100644 --- a/src/app/puzzle/scene/vpgraphicspiece.h +++ b/src/app/puzzle/scene/vpgraphicspiece.h @@ -49,6 +49,7 @@ public: */ auto GetPiece() -> VPPiece*; + void TranslatePiece(qreal dx, qreal dy); void TranslatePiece(const QPointF &p); virtual int type() const override {return Type;} diff --git a/src/app/puzzle/scene/vpmaingraphicsview.cpp b/src/app/puzzle/scene/vpmaingraphicsview.cpp index 140bd6fe4..bb4ef2fba 100644 --- a/src/app/puzzle/scene/vpmaingraphicsview.cpp +++ b/src/app/puzzle/scene/vpmaingraphicsview.cpp @@ -262,9 +262,7 @@ void VPMainGraphicsView::keyPressEvent(QKeyEvent *event) { if(event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete) { - QList tmpGraphicsPieces = m_graphicsPieces; - - for(auto *graphicsPiece : tmpGraphicsPieces) + for(auto *graphicsPiece : m_graphicsPieces) { VPPiece *piece = graphicsPiece->GetPiece(); @@ -272,9 +270,55 @@ void VPMainGraphicsView::keyPressEvent(QKeyEvent *event) { piece->SetSelected(false); piece->SetSheet(nullptr); + m_graphicsPieces.removeAll(graphicsPiece); + delete graphicsPiece; } } } + else if (event->key() == Qt::Key_Left) + { + if((event->modifiers() & Qt::ShiftModifier) != 0U) + { + TranslatePiecesOn(-10, 0); + } + else + { + TranslatePiecesOn(-1, 0); + } + } + else if (event->key() == Qt::Key_Right) + { + if((event->modifiers() & Qt::ShiftModifier) != 0U) + { + TranslatePiecesOn(10, 0); + } + else + { + TranslatePiecesOn(1, 0); + } + } + else if (event->key() == Qt::Key_Up) + { + if((event->modifiers() & Qt::ShiftModifier) != 0U) + { + TranslatePiecesOn(0, -10); + } + else + { + TranslatePiecesOn(0, 1); + } + } + else if (event->key() == Qt::Key_Down) + { + if((event->modifiers() & Qt::ShiftModifier) != 0U) + { + TranslatePiecesOn(0, 10); + } + else + { + TranslatePiecesOn(0, 1); + } + } } //--------------------------------------------------------------------------------------------------------------------- @@ -390,12 +434,6 @@ void VPMainGraphicsView::ConnectPiece(VPGraphicsPiece *piece) //--------------------------------------------------------------------------------------------------------------------- void VPMainGraphicsView::RotatePiecesByAngle(qreal angle) const { - QGraphicsScene *scene = this->scene(); - if (scene == nullptr) - { - return; - } - VPSheet *sheet = m_layout->GetFocusedSheet(); if (sheet == nullptr) { @@ -404,13 +442,25 @@ void VPMainGraphicsView::RotatePiecesByAngle(qreal angle) const VPTransformationOrigon origin = sheet->TransformationOrigin(); - QList list = scene->selectedItems(); - for (auto *item : list) + for(auto *graphicsPiece : m_graphicsPieces) { - if (item->type() == VPGraphicsPiece::Type) + if (graphicsPiece->isSelected()) { - auto *pieceItem = dynamic_cast(item); - pieceItem->on_Rotate(origin.origin, angle); + graphicsPiece->on_Rotate(origin.origin, angle); + m_rotationControls->on_UpdateControls(); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainGraphicsView::TranslatePiecesOn(qreal dx, qreal dy) const +{ + for(auto *graphicsPiece : m_graphicsPieces) + { + if (graphicsPiece->isSelected()) + { + graphicsPiece->TranslatePiece(dx, dy); + m_rotationControls->on_UpdateControls(); } } } diff --git a/src/app/puzzle/scene/vpmaingraphicsview.h b/src/app/puzzle/scene/vpmaingraphicsview.h index 2bdb0b1af..b29631052 100644 --- a/src/app/puzzle/scene/vpmaingraphicsview.h +++ b/src/app/puzzle/scene/vpmaingraphicsview.h @@ -132,6 +132,7 @@ private: void ConnectPiece(VPGraphicsPiece *piece); void RotatePiecesByAngle(qreal angle) const; + void TranslatePiecesOn(qreal dx, qreal dy) const; };