Fix issue with drag pixmap.

It disappears if move cursor far enough. Instead draw a cursor which will include a piece pixmap.
This commit is contained in:
Roman Telezhynskyi 2021-07-30 18:03:20 +03:00
parent 5242b4ed54
commit 78382b5c97
8 changed files with 28 additions and 2 deletions

View File

@ -58,6 +58,7 @@ int main(int argc, char *argv[])
Q_INIT_RESOURCE(schema);
Q_INIT_RESOURCE(flags);
Q_INIT_RESOURCE(style);
Q_INIT_RESOURCE(cursor);
QT_REQUIRE_VERSION(argc, argv, "5.4.0")// clazy:exclude=qstring-arg,qstring-allocations

View File

@ -60,6 +60,7 @@ UI_DIR = uic
include(puzzle.pri)
RESOURCES += \
share/resources/cursor.qrc \
share/resources/puzzleicon.qrc
include(../translations.pri)

View File

@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/">
<file>cursor/collect.png</file>
<file>cursor/collect@2x.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 547 B

View File

@ -139,9 +139,9 @@ void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions)
VPPiece* piece = pieceItem->GetPiece();
mimeData->SetPiecePtr(piece);
QPixmap pixmap = pieceItem->CreatePieceIcon(QSize(120,120), true).pixmap(QSize(120,120));
QPixmap pixmap = pieceItem->CreatePieceIcon(QSize(120, 120), true).pixmap(QSize(120, 120));
drag->setPixmap(pixmap);
drag->setDragCursor(VPMimeDataPiece::DragCursor(pixmap), Qt::MoveAction);
drag->setMimeData(mimeData);
if(drag->exec() == Qt::MoveAction)
{

View File

@ -28,6 +28,9 @@
#include "vpmimedatapiece.h"
#include <QPainter>
#include <QPixmap>
const QString VPMimeDataPiece::mineFormatPiecePtr = QStringLiteral("application/vnd.puzzle.piece.ptr");
//---------------------------------------------------------------------------------------------------------------------
@ -47,3 +50,16 @@ void VPMimeDataPiece::SetPiecePtr(VPPiece* piece)
{
m_piece = piece;
}
//---------------------------------------------------------------------------------------------------------------------
auto VPMimeDataPiece::DragCursor(const QPixmap &piecePixmap) -> QPixmap
{
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 = QPixmap("://cursor/collect.png");
painter.drawPixmap(dragCursor.width()/2 - cursor.width()/2, dragCursor.height()/2 - cursor.height()/2, cursor);
painter.end();
return dragCursor;
}

View File

@ -55,6 +55,8 @@ public:
*/
void SetPiecePtr(VPPiece* piece);
static auto DragCursor(const QPixmap &piecePixmap) -> QPixmap;
static const QString mineFormatPiecePtr;
private: