From 78382b5c97ad15edb68612dac7e52284e301fceb Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 30 Jul 2021 18:03:20 +0300 Subject: [PATCH] Fix issue with drag pixmap. It disappears if move cursor far enough. Instead draw a cursor which will include a piece pixmap. --- src/app/puzzle/main.cpp | 1 + src/app/puzzle/puzzle.pro | 1 + src/app/puzzle/share/resources/cursor.qrc | 6 ++++++ .../puzzle/share/resources/cursor/collect.png | Bin 0 -> 294 bytes .../share/resources/cursor/collect@2x.png | Bin 0 -> 547 bytes src/app/puzzle/vpcarrouselpiecelist.cpp | 4 ++-- src/app/puzzle/vpmimedatapiece.cpp | 16 ++++++++++++++++ src/app/puzzle/vpmimedatapiece.h | 2 ++ 8 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/app/puzzle/share/resources/cursor.qrc create mode 100644 src/app/puzzle/share/resources/cursor/collect.png create mode 100644 src/app/puzzle/share/resources/cursor/collect@2x.png diff --git a/src/app/puzzle/main.cpp b/src/app/puzzle/main.cpp index d282fe43a..13353f3c6 100644 --- a/src/app/puzzle/main.cpp +++ b/src/app/puzzle/main.cpp @@ -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 diff --git a/src/app/puzzle/puzzle.pro b/src/app/puzzle/puzzle.pro index 71ccbcc54..d416415e7 100644 --- a/src/app/puzzle/puzzle.pro +++ b/src/app/puzzle/puzzle.pro @@ -60,6 +60,7 @@ UI_DIR = uic include(puzzle.pri) RESOURCES += \ + share/resources/cursor.qrc \ share/resources/puzzleicon.qrc include(../translations.pri) diff --git a/src/app/puzzle/share/resources/cursor.qrc b/src/app/puzzle/share/resources/cursor.qrc new file mode 100644 index 000000000..740bdbf6a --- /dev/null +++ b/src/app/puzzle/share/resources/cursor.qrc @@ -0,0 +1,6 @@ + + + cursor/collect.png + cursor/collect@2x.png + + diff --git a/src/app/puzzle/share/resources/cursor/collect.png b/src/app/puzzle/share/resources/cursor/collect.png new file mode 100644 index 0000000000000000000000000000000000000000..674392d9bbb9ce41bc9e89d608a53fb75595ac61 GIT binary patch literal 294 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7l!{JxM1({$v~0Yo-U3d z5v^~hJMtY;5OAG8>r2eNQ%iRU7drp|Q( z-l^Meu}V2Guiz|r5d5?5>+kb@uNOXb4B?%wu&VXALRaf-9{cojNxTiAd-4OeWox)Kf<&^0h@vI6h8*0QC?hkJJQF@kZQXBV6<$KD4db|m7%2ibd7RDW%6Ke9D z&^-yC&}N4hQ;i6wkgx?&=EeT~aomVD+pEcY3zAI$oYe_2X1UbVj4^sJX`oUGHX q=SLNbX8BxwobjKP_klgbtb1Bc%}*q+eLDm6CWEJ|pUXO@geCyV3wlcc literal 0 HcmV?d00001 diff --git a/src/app/puzzle/share/resources/cursor/collect@2x.png b/src/app/puzzle/share/resources/cursor/collect@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..57967c82c7f0b59fc4f1eb43da62ed44c03cc420 GIT binary patch literal 547 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=Y)RhkE)4%caKYZ?lNlHoZ+N;m zhE&XXJKHwsuz^5pyv8Kw0#^@jPcJ_=r_^^zX)g>~b&qj)UyHK$7yEs7g+j{Q+IX4h zODgPB(l`9G6R7&}u3sj)9oFe?Jl|Uy&)KK=?0!AV5|2a7 zk8AC=Se|kX=u)vUxOdCSf3Bo#!{WyhSMReqt2xet#Y;r~(l*y>vT2c=bK zzMi`sVlJANlXhda*3rZ^^E0X<>aIVyFTK?fRln-j_vF{a)zcs8#2%Sp?d|&U?&;an z1&o&FhBc+w-JjE<+dVT)<;a>RW%`OojmowQ1+9Cy**l>o{QkVXFWGetPiece(); 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) { diff --git a/src/app/puzzle/vpmimedatapiece.cpp b/src/app/puzzle/vpmimedatapiece.cpp index c348dc1c0..912aed437 100644 --- a/src/app/puzzle/vpmimedatapiece.cpp +++ b/src/app/puzzle/vpmimedatapiece.cpp @@ -28,6 +28,9 @@ #include "vpmimedatapiece.h" +#include +#include + 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; +} diff --git a/src/app/puzzle/vpmimedatapiece.h b/src/app/puzzle/vpmimedatapiece.h index 87f280938..207273663 100644 --- a/src/app/puzzle/vpmimedatapiece.h +++ b/src/app/puzzle/vpmimedatapiece.h @@ -55,6 +55,8 @@ public: */ void SetPiecePtr(VPPiece* piece); + static auto DragCursor(const QPixmap &piecePixmap) -> QPixmap; + static const QString mineFormatPiecePtr; private: