Disable inter-window drag&drop.

This commit is contained in:
Roman Telezhynskyi 2021-09-28 17:12:55 +03:00
parent 74090f7ffd
commit 665101a6c5
8 changed files with 82 additions and 11 deletions

View File

@ -226,6 +226,12 @@ void VPCarrousel::on_ActivePieceListChanged(int index)
RefreshSheetNames(); RefreshSheetNames();
} }
//---------------------------------------------------------------------------------------------------------------------
VPLayoutWeakPtr VPCarrousel::Layout() const
{
return m_layout;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrousel::SetOrientation(Qt::Orientation orientation) void VPCarrousel::SetOrientation(Qt::Orientation orientation)
{ {

View File

@ -76,6 +76,8 @@ public:
*/ */
void Clear(); void Clear();
VPLayoutWeakPtr Layout() const;
public slots: public slots:
/** /**
* @brief Refresh Refreshes the content of the carrousel * @brief Refresh Refreshes the content of the carrousel

View File

@ -137,9 +137,20 @@ void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions)
{ {
auto *pieceItem = static_cast<VPCarrouselPiece *> (_item); auto *pieceItem = static_cast<VPCarrouselPiece *> (_item);
if (m_carrousel == nullptr)
{
return;
}
VPLayoutPtr layout = m_carrousel->Layout().toStrongRef();
if (layout.isNull())
{
return;
}
// starts the dragging // starts the dragging
auto *drag = new QDrag(this); auto *drag = new QDrag(this);
auto *mimeData = new VPMimeDataPiece(); auto *mimeData = new VPMimeDataPiece(layout->Uuid());
VPPiecePtr piece = pieceItem->GetPiece(); VPPiecePtr piece = pieceItem->GetPiece();
mimeData->SetPiecePtr(piece); mimeData->SetPiecePtr(piece);

View File

@ -35,6 +35,11 @@
const QString VPMimeDataPiece::mineFormatPiecePtr = QStringLiteral("application/vnd.puzzle.piece.ptr"); const QString VPMimeDataPiece::mineFormatPiecePtr = QStringLiteral("application/vnd.puzzle.piece.ptr");
//---------------------------------------------------------------------------------------------------------------------
VPMimeDataPiece::VPMimeDataPiece(const QUuid &layoutUuid)
:m_layoutUuid(layoutUuid)
{}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VPMimeDataPiece::formats() const -> QStringList auto VPMimeDataPiece::formats() const -> QStringList
{ {
@ -65,3 +70,9 @@ auto VPMimeDataPiece::DragCursor(const QPixmap &piecePixmap) -> QPixmap
painter.end(); painter.end();
return dragCursor; return dragCursor;
} }
//---------------------------------------------------------------------------------------------------------------------
const QUuid &VPMimeDataPiece::LayoutUuid() const
{
return m_layoutUuid;
}

View File

@ -31,6 +31,7 @@
#include <QMimeData> #include <QMimeData>
#include <QSharedPointer> #include <QSharedPointer>
#include <QUuid>
#include "../layout/layoutdef.h" #include "../layout/layoutdef.h"
@ -39,7 +40,7 @@ class VPMimeDataPiece : public QMimeData
Q_OBJECT Q_OBJECT
public: public:
VPMimeDataPiece() = default; VPMimeDataPiece(const QUuid &layoutUuid);
virtual ~VPMimeDataPiece() = default; virtual ~VPMimeDataPiece() = default;
virtual auto formats() const -> QStringList override; virtual auto formats() const -> QStringList override;
@ -60,10 +61,14 @@ public:
static const QString mineFormatPiecePtr; static const QString mineFormatPiecePtr;
const QUuid &LayoutUuid() const;
private: private:
Q_DISABLE_COPY(VPMimeDataPiece) Q_DISABLE_COPY(VPMimeDataPiece)
VPPieceWeakPtr m_piece{}; VPPieceWeakPtr m_piece{};
QUuid m_layoutUuid;
}; };
#endif // VPMIMEDATAPIECE_H #endif // VPMIMEDATAPIECE_H

View File

@ -119,6 +119,12 @@ void VPLayout::AddPiece(const VPPiecePtr &piece)
} }
} }
//---------------------------------------------------------------------------------------------------------------------
const QUuid &VPLayout::Uuid() const
{
return m_uuid;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPTileFactory *VPLayout::TileFactory() const VPTileFactory *VPLayout::TileFactory() const
{ {

View File

@ -30,6 +30,7 @@
#include <QList> #include <QList>
#include <QMap> #include <QMap>
#include <QUuid>
#include "def.h" #include "def.h"
#include "vplayoutsettings.h" #include "vplayoutsettings.h"
@ -99,6 +100,8 @@ public:
auto IsSheetsUniform() const -> bool; auto IsSheetsUniform() const -> bool;
const QUuid &Uuid() const;
signals: signals:
void PieceSheetChanged(const VPPiecePtr &piece); void PieceSheetChanged(const VPPiecePtr &piece);
void ActiveSheetChanged(const VPSheetPtr &focusedSheet); void ActiveSheetChanged(const VPSheetPtr &focusedSheet);
@ -129,6 +132,8 @@ private:
QUndoStack *m_undoStack; QUndoStack *m_undoStack;
VPTileFactory *m_tileFactory{nullptr}; VPTileFactory *m_tileFactory{nullptr};
QUuid m_uuid{QUuid::createUuid()};
}; };
Q_DECLARE_METATYPE(VPLayoutPtr) Q_DECLARE_METATYPE(VPLayoutPtr)

View File

@ -120,11 +120,21 @@ void VPMainGraphicsView::dragEnterEvent(QDragEnterEvent *event)
const QMimeData *mime = event->mimeData(); const QMimeData *mime = event->mimeData();
if(mime->hasFormat(VPMimeDataPiece::mineFormatPiecePtr)) if(mime->hasFormat(VPMimeDataPiece::mineFormatPiecePtr))
{
VPLayoutPtr layout = m_layout.toStrongRef();
if (layout.isNull())
{
return;
}
const auto *mimePiece = qobject_cast<const VPMimeDataPiece *> (mime);
if (mimePiece != nullptr && mimePiece->LayoutUuid() == layout->Uuid())
{ {
qCDebug(pMainGraphicsView(), "drag enter"); qCDebug(pMainGraphicsView(), "drag enter");
event->acceptProposedAction(); event->acceptProposedAction();
} }
} }
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPMainGraphicsView::dragMoveEvent(QDragMoveEvent *event) void VPMainGraphicsView::dragMoveEvent(QDragMoveEvent *event)
@ -132,10 +142,20 @@ void VPMainGraphicsView::dragMoveEvent(QDragMoveEvent *event)
const QMimeData *mime = event->mimeData(); const QMimeData *mime = event->mimeData();
if(mime->hasFormat(VPMimeDataPiece::mineFormatPiecePtr)) if(mime->hasFormat(VPMimeDataPiece::mineFormatPiecePtr))
{
VPLayoutPtr layout = m_layout.toStrongRef();
if (layout.isNull())
{
return;
}
const auto *mimePiece = qobject_cast<const VPMimeDataPiece *> (mime);
if (mimePiece != nullptr && mimePiece->LayoutUuid() == layout->Uuid())
{ {
event->acceptProposedAction(); event->acceptProposedAction();
} }
} }
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPMainGraphicsView::dragLeaveEvent(QDragLeaveEvent *event) void VPMainGraphicsView::dragLeaveEvent(QDragLeaveEvent *event)
@ -151,11 +171,6 @@ void VPMainGraphicsView::dropEvent(QDropEvent *event)
qCDebug(pMainGraphicsView(), "drop enter , %s", qUtf8Printable(mime->objectName())); qCDebug(pMainGraphicsView(), "drop enter , %s", qUtf8Printable(mime->objectName()));
if(mime->hasFormat(VPMimeDataPiece::mineFormatPiecePtr)) if(mime->hasFormat(VPMimeDataPiece::mineFormatPiecePtr))
{
const auto *mimePiece = qobject_cast<const VPMimeDataPiece *> (mime);
VPPiecePtr piece = mimePiece->GetPiecePtr();
if(not piece.isNull())
{ {
VPLayoutPtr layout = m_layout.toStrongRef(); VPLayoutPtr layout = m_layout.toStrongRef();
if (layout.isNull()) if (layout.isNull())
@ -163,6 +178,16 @@ void VPMainGraphicsView::dropEvent(QDropEvent *event)
return; return;
} }
const auto *mimePiece = qobject_cast<const VPMimeDataPiece *> (mime);
if (mimePiece == nullptr || mimePiece->LayoutUuid() != layout->Uuid())
{
return;
}
VPPiecePtr piece = mimePiece->GetPiecePtr();
if(not piece.isNull())
{
qCDebug(pMainGraphicsView(), "element dropped, %s", qUtf8Printable(piece->GetName())); qCDebug(pMainGraphicsView(), "element dropped, %s", qUtf8Printable(piece->GetName()));
event->acceptProposedAction(); event->acceptProposedAction();