Restore adding pieces on sheet.
This commit is contained in:
parent
ec6c1cad23
commit
5242b4ed54
|
@ -110,7 +110,7 @@ void VPCarrouselPieceList::mousePressEvent(QMouseEvent *event)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VPCarrouselPieceList::mouseMoveEvent(QMouseEvent *event)
|
void VPCarrouselPieceList::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (((event->buttons() & Qt::LeftButton) != 0u) &&
|
if (((event->buttons() & Qt::LeftButton) != 0U) &&
|
||||||
((event->pos() - m_dragStart).manhattanLength() >= QApplication::startDragDistance()) &&
|
((event->pos() - m_dragStart).manhattanLength() >= QApplication::startDragDistance()) &&
|
||||||
(selectedItems().count() > 0) &&
|
(selectedItems().count() > 0) &&
|
||||||
(not m_pieceList.isEmpty() && m_pieceList.first()->Sheet() == nullptr)) // only if it's from unplaced pieces
|
(not m_pieceList.isEmpty() && m_pieceList.first()->Sheet() == nullptr)) // only if it's from unplaced pieces
|
||||||
|
@ -123,7 +123,6 @@ void VPCarrouselPieceList::mouseMoveEvent(QMouseEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions)
|
void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions)
|
||||||
{
|
{
|
||||||
|
@ -139,7 +138,6 @@ void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions)
|
||||||
auto *mimeData = new VPMimeDataPiece();
|
auto *mimeData = new VPMimeDataPiece();
|
||||||
VPPiece* piece = pieceItem->GetPiece();
|
VPPiece* piece = pieceItem->GetPiece();
|
||||||
mimeData->SetPiecePtr(piece);
|
mimeData->SetPiecePtr(piece);
|
||||||
mimeData->setObjectName("piecePointer");
|
|
||||||
|
|
||||||
QPixmap pixmap = pieceItem->CreatePieceIcon(QSize(120,120), true).pixmap(QSize(120,120));
|
QPixmap pixmap = pieceItem->CreatePieceIcon(QSize(120,120), true).pixmap(QSize(120,120));
|
||||||
|
|
||||||
|
@ -147,8 +145,7 @@ void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions)
|
||||||
drag->setMimeData(mimeData);
|
drag->setMimeData(mimeData);
|
||||||
if(drag->exec() == Qt::MoveAction)
|
if(drag->exec() == Qt::MoveAction)
|
||||||
{
|
{
|
||||||
delete takeItem(row(_item));
|
m_carrousel->Refresh();
|
||||||
clearSelection();
|
|
||||||
piece->SetIsSelected(true);
|
piece->SetIsSelected(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,19 +190,28 @@ void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event)
|
||||||
|
|
||||||
QAction *selectedAction = menu.exec(event->globalPos());
|
QAction *selectedAction = menu.exec(event->globalPos());
|
||||||
|
|
||||||
|
VPPiece *piece = pieceItem->GetPiece();
|
||||||
|
VPLayout *layout = piece->Layout();
|
||||||
|
|
||||||
if (selectedAction == moveAction)
|
if (selectedAction == moveAction)
|
||||||
{
|
{
|
||||||
VPSheet *sheet = pieceItem->GetPiece()->Layout()->GetFocusedSheet();
|
VPSheet *sheet = layout->GetFocusedSheet();
|
||||||
pieceItem->GetPiece()->SetSheet(sheet);
|
piece->SetSheet(sheet);
|
||||||
|
emit layout->PieceSheetChanged(piece);
|
||||||
|
m_carrousel->Refresh();
|
||||||
}
|
}
|
||||||
else if (selectedAction == deleteAction)
|
else if (selectedAction == deleteAction)
|
||||||
{
|
{
|
||||||
VPSheet *sheet = pieceItem->GetPiece()->Layout()->GetTrashSheet();
|
VPSheet *sheet = layout->GetTrashSheet();
|
||||||
pieceItem->GetPiece()->SetSheet(sheet);
|
piece->SetSheet(sheet);
|
||||||
|
emit layout->PieceSheetChanged(piece);
|
||||||
|
m_carrousel->Refresh();
|
||||||
}
|
}
|
||||||
else if (selectedAction == removeAction)
|
else if (selectedAction == removeAction)
|
||||||
{
|
{
|
||||||
pieceItem->GetPiece()->SetSheet(nullptr);
|
piece->SetSheet(nullptr);
|
||||||
|
emit layout->PieceSheetChanged(piece);
|
||||||
|
m_carrousel->Refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,6 +146,10 @@ void VPGraphicsPiece::Init()
|
||||||
// TODO : initialises the text labels
|
// TODO : initialises the text labels
|
||||||
|
|
||||||
|
|
||||||
|
// Init position
|
||||||
|
on_PiecePositionChanged();
|
||||||
|
on_PieceRotationChanged();
|
||||||
|
on_PieceSelectionChanged();
|
||||||
|
|
||||||
// Initialises the connectors
|
// Initialises the connectors
|
||||||
connect(m_piece, &VPPiece::SelectionChanged, this, &VPGraphicsPiece::on_PieceSelectionChanged);
|
connect(m_piece, &VPPiece::SelectionChanged, this, &VPGraphicsPiece::on_PieceSelectionChanged);
|
||||||
|
|
|
@ -72,6 +72,9 @@ public:
|
||||||
|
|
||||||
auto PiecesForSheet(const VPSheet* sheet) const -> QList<VPPiece *>;
|
auto PiecesForSheet(const VPSheet* sheet) const -> QList<VPPiece *>;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void PieceSheetChanged(VPPiece *piece);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(VPLayout)
|
Q_DISABLE_COPY(VPLayout)
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ VPMainGraphicsView::VPMainGraphicsView(VPLayout *layout, VPTileFactory *tileFact
|
||||||
VMainGraphicsView(parent),
|
VMainGraphicsView(parent),
|
||||||
m_layout(layout)
|
m_layout(layout)
|
||||||
{
|
{
|
||||||
|
SCASSERT(m_layout != nullptr)
|
||||||
// TODO : list of scenes
|
// TODO : list of scenes
|
||||||
m_scene = new VMainGraphicsScene(this);
|
m_scene = new VMainGraphicsScene(this);
|
||||||
setScene(m_scene);
|
setScene(m_scene);
|
||||||
|
@ -60,6 +61,9 @@ VPMainGraphicsView::VPMainGraphicsView(VPLayout *layout, VPTileFactory *tileFact
|
||||||
|
|
||||||
m_graphicsTileGrid = new VPGraphicsTileGrid(layout, tileFactory);
|
m_graphicsTileGrid = new VPGraphicsTileGrid(layout, tileFactory);
|
||||||
m_scene->addItem(m_graphicsTileGrid);
|
m_scene->addItem(m_graphicsTileGrid);
|
||||||
|
|
||||||
|
// add the connections
|
||||||
|
connect(m_layout, &VPLayout::PieceSheetChanged, this, &VPMainGraphicsView::on_PieceSheetChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -80,7 +84,6 @@ VMainGraphicsScene* VPMainGraphicsView::GetScene()
|
||||||
return m_scene;
|
return m_scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VPMainGraphicsView::PrepareForExport()
|
void VPMainGraphicsView::PrepareForExport()
|
||||||
{
|
{
|
||||||
|
@ -114,7 +117,7 @@ void VPMainGraphicsView::dragEnterEvent(QDragEnterEvent *event)
|
||||||
{
|
{
|
||||||
const QMimeData *mime = event->mimeData();
|
const QMimeData *mime = event->mimeData();
|
||||||
|
|
||||||
if(mime->objectName() == "piecePointer")
|
if(mime->hasFormat(VPMimeDataPiece::mineFormatPiecePtr))
|
||||||
{
|
{
|
||||||
qCDebug(pMainGraphicsView(), "drag enter");
|
qCDebug(pMainGraphicsView(), "drag enter");
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
|
@ -126,7 +129,7 @@ void VPMainGraphicsView::dragMoveEvent(QDragMoveEvent *event)
|
||||||
{
|
{
|
||||||
const QMimeData *mime = event->mimeData();
|
const QMimeData *mime = event->mimeData();
|
||||||
|
|
||||||
if(mime->objectName() == "piecePointer")
|
if(mime->hasFormat(VPMimeDataPiece::mineFormatPiecePtr))
|
||||||
{
|
{
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
}
|
}
|
||||||
|
@ -145,9 +148,9 @@ void VPMainGraphicsView::dropEvent(QDropEvent *event)
|
||||||
|
|
||||||
qCDebug(pMainGraphicsView(), "drop enter , %s", qUtf8Printable(mime->objectName()));
|
qCDebug(pMainGraphicsView(), "drop enter , %s", qUtf8Printable(mime->objectName()));
|
||||||
|
|
||||||
if(mime->objectName() == "piecePointer")
|
if(mime->hasFormat(VPMimeDataPiece::mineFormatPiecePtr))
|
||||||
{
|
{
|
||||||
const VPMimeDataPiece *mimePiece = qobject_cast<const VPMimeDataPiece *> (mime);
|
const auto *mimePiece = qobject_cast<const VPMimeDataPiece *> (mime);
|
||||||
|
|
||||||
VPPiece *piece = mimePiece->GetPiecePtr();
|
VPPiece *piece = mimePiece->GetPiecePtr();
|
||||||
if(piece != nullptr)
|
if(piece != nullptr)
|
||||||
|
@ -157,9 +160,17 @@ void VPMainGraphicsView::dropEvent(QDropEvent *event)
|
||||||
|
|
||||||
QPoint point = event->pos();
|
QPoint point = event->pos();
|
||||||
piece->SetPosition(mapToScene(point));
|
piece->SetPosition(mapToScene(point));
|
||||||
|
piece->SetRotation(0);
|
||||||
|
|
||||||
// change the piecelist of the piece
|
// change the piecelist of the piece
|
||||||
piece->SetSheet(m_layout->GetFocusedSheet());
|
piece->SetSheet(m_layout->GetFocusedSheet());
|
||||||
|
|
||||||
|
auto *graphicsPiece = new VPGraphicsPiece(piece);
|
||||||
|
m_graphicsPieces.append(graphicsPiece);
|
||||||
|
|
||||||
|
scene()->addItem(graphicsPiece);
|
||||||
|
|
||||||
|
event->acceptProposedAction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,7 +182,7 @@ void VPMainGraphicsView::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
QList<VPGraphicsPiece*> tmpGraphicsPieces = m_graphicsPieces;
|
QList<VPGraphicsPiece*> tmpGraphicsPieces = m_graphicsPieces;
|
||||||
|
|
||||||
for(auto graphicsPiece : tmpGraphicsPieces)
|
for(auto *graphicsPiece : tmpGraphicsPieces)
|
||||||
{
|
{
|
||||||
VPPiece *piece = graphicsPiece->GetPiece();
|
VPPiece *piece = graphicsPiece->GetPiece();
|
||||||
|
|
||||||
|
@ -183,3 +194,34 @@ void VPMainGraphicsView::keyPressEvent(QKeyEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPMainGraphicsView::on_PieceSheetChanged(VPPiece *piece)
|
||||||
|
{
|
||||||
|
VPGraphicsPiece *_graphicsPiece = nullptr;
|
||||||
|
for(auto *graphicPiece : m_graphicsPieces)
|
||||||
|
{
|
||||||
|
if(graphicPiece->GetPiece() == piece)
|
||||||
|
{
|
||||||
|
_graphicsPiece = graphicPiece;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (piece->Sheet() == nullptr || piece->Sheet() == m_layout->GetTrashSheet()) // remove
|
||||||
|
{
|
||||||
|
if (_graphicsPiece != nullptr)
|
||||||
|
{
|
||||||
|
scene()->removeItem(_graphicsPiece);
|
||||||
|
m_graphicsPieces.removeAll(_graphicsPiece);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // add
|
||||||
|
{
|
||||||
|
if(_graphicsPiece == nullptr)
|
||||||
|
{
|
||||||
|
_graphicsPiece = new VPGraphicsPiece(piece);
|
||||||
|
m_graphicsPieces.append(_graphicsPiece);
|
||||||
|
}
|
||||||
|
scene()->addItem(_graphicsPiece);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -68,6 +68,14 @@ public:
|
||||||
*/
|
*/
|
||||||
void CleanAfterExport();
|
void CleanAfterExport();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
/**
|
||||||
|
* @brief on_PieceSheetChanged The slot is called when the given piece was moved from the given piece list to
|
||||||
|
* the other given piece list
|
||||||
|
* @param piece the piece that was moved
|
||||||
|
*/
|
||||||
|
void on_PieceSheetChanged(VPPiece *piece);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||||
void dragMoveEvent(QDragMoveEvent *event) override;
|
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||||
|
@ -81,13 +89,13 @@ protected:
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(VPMainGraphicsView)
|
Q_DISABLE_COPY(VPMainGraphicsView)
|
||||||
|
|
||||||
VMainGraphicsScene *m_scene{nullptr};
|
VMainGraphicsScene *m_scene;
|
||||||
|
|
||||||
VPGraphicsSheet *m_graphicsSheet{nullptr};
|
VPGraphicsSheet *m_graphicsSheet{nullptr};
|
||||||
|
|
||||||
VPGraphicsTileGrid *m_graphicsTileGrid{nullptr};
|
VPGraphicsTileGrid *m_graphicsTileGrid{nullptr};
|
||||||
|
|
||||||
VPLayout *m_layout{nullptr};
|
VPLayout *m_layout;
|
||||||
|
|
||||||
QList<VPGraphicsPiece*> m_graphicsPieces{};
|
QList<VPGraphicsPiece*> m_graphicsPieces{};
|
||||||
|
|
||||||
|
|
|
@ -28,20 +28,16 @@
|
||||||
|
|
||||||
#include "vpmimedatapiece.h"
|
#include "vpmimedatapiece.h"
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
const QString VPMimeDataPiece::mineFormatPiecePtr = QStringLiteral("application/vnd.puzzle.piece.ptr");
|
||||||
VPMimeDataPiece::VPMimeDataPiece()
|
|
||||||
{
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
auto VPMimeDataPiece::formats() const -> QStringList
|
||||||
|
{
|
||||||
|
return {mineFormatPiecePtr};
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VPMimeDataPiece::~VPMimeDataPiece()
|
auto VPMimeDataPiece::GetPiecePtr() const -> VPPiece*
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
VPPiece* VPMimeDataPiece::GetPiecePtr() const
|
|
||||||
{
|
{
|
||||||
return m_piece;
|
return m_piece;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,15 +38,16 @@ class VPMimeDataPiece : public QMimeData
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
VPMimeDataPiece() = default;
|
||||||
|
virtual ~VPMimeDataPiece() = default;
|
||||||
|
|
||||||
VPMimeDataPiece();
|
virtual auto formats() const -> QStringList override;
|
||||||
~VPMimeDataPiece();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief GetPiecePtr Returns the piece pointer of the mime data
|
* @brief GetPiecePtr Returns the piece pointer of the mime data
|
||||||
* @return piece pointer
|
* @return piece pointer
|
||||||
*/
|
*/
|
||||||
VPPiece* GetPiecePtr() const;
|
auto GetPiecePtr() const -> VPPiece*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SetPiecePtr sets the piece pointer to the given value
|
* @brief SetPiecePtr sets the piece pointer to the given value
|
||||||
|
@ -54,11 +55,12 @@ public:
|
||||||
*/
|
*/
|
||||||
void SetPiecePtr(VPPiece* piece);
|
void SetPiecePtr(VPPiece* piece);
|
||||||
|
|
||||||
|
static const QString mineFormatPiecePtr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(VPMimeDataPiece)
|
Q_DISABLE_COPY(VPMimeDataPiece)
|
||||||
|
|
||||||
VPPiece *m_piece{nullptr};
|
VPPiece *m_piece{nullptr};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user