Handle empty piece icon when drag it on sheet.

This commit is contained in:
Roman Telezhynskyi 2023-11-10 12:02:38 +02:00
parent 23fd31ca08
commit 7e9222dabe
2 changed files with 21 additions and 9 deletions

View File

@ -184,7 +184,12 @@ void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions)
VPPiecePtr piece = pieceItem->GetPiece();
mimeData->SetPiecePtr(piece);
QPixmap pixmap = pieceItem->CreatePieceIcon(QSize(120, 120), true).pixmap(QSize(120, 120));
QIcon pieceIcon = pieceItem->CreatePieceIcon(QSize(120, 120), true);
QPixmap pixmap;
if (!pieceIcon.isNull())
{
pieceIcon.pixmap(QSize(120, 120));
}
drag->setDragCursor(VPMimeDataPiece::DragCursor(pixmap), Qt::MoveAction);
drag->setMimeData(mimeData);

View File

@ -62,18 +62,25 @@ void VPMimeDataPiece::SetPiecePtr(const VPPiecePtr &piece)
//---------------------------------------------------------------------------------------------------------------------
auto VPMimeDataPiece::DragCursor(const QPixmap &piecePixmap) -> QPixmap
{
QPixmap cursor(QStringLiteral("://puzzlecursor/collect.png"));
if (!piecePixmap.isNull())
{
QPixmap dragCursor(piecePixmap.width() * 2, piecePixmap.height() * 2);
dragCursor.fill(Qt::transparent);
QPainter painter(&dragCursor);
painter.drawPixmap(dragCursor.width() / 2, dragCursor.height() / 2, piecePixmap);
QPixmap cursor(QStringLiteral("://puzzlecursor/collect.png"));
painter.drawPixmap(dragCursor.width() / 2 - cursor.width() / 2, dragCursor.height() / 2 - cursor.height() / 2,
cursor);
painter.end();
return dragCursor;
}
return cursor;
}
//---------------------------------------------------------------------------------------------------------------------
auto VPMimeDataPiece::LayoutUuid() const -> const QUuid &
{