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();
}
//---------------------------------------------------------------------------------------------------------------------
VPLayoutWeakPtr VPCarrousel::Layout() const
{
return m_layout;
}
//---------------------------------------------------------------------------------------------------------------------
void VPCarrousel::SetOrientation(Qt::Orientation orientation)
{

View File

@ -76,6 +76,8 @@ public:
*/
void Clear();
VPLayoutWeakPtr Layout() const;
public slots:
/**
* @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);
if (m_carrousel == nullptr)
{
return;
}
VPLayoutPtr layout = m_carrousel->Layout().toStrongRef();
if (layout.isNull())
{
return;
}
// starts the dragging
auto *drag = new QDrag(this);
auto *mimeData = new VPMimeDataPiece();
auto *mimeData = new VPMimeDataPiece(layout->Uuid());
VPPiecePtr piece = pieceItem->GetPiece();
mimeData->SetPiecePtr(piece);

View File

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

View File

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

View File

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

View File

@ -121,8 +121,18 @@ void VPMainGraphicsView::dragEnterEvent(QDragEnterEvent *event)
if(mime->hasFormat(VPMimeDataPiece::mineFormatPiecePtr))
{
qCDebug(pMainGraphicsView(), "drag enter");
event->acceptProposedAction();
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");
event->acceptProposedAction();
}
}
}
@ -133,7 +143,17 @@ void VPMainGraphicsView::dragMoveEvent(QDragMoveEvent *event)
if(mime->hasFormat(VPMimeDataPiece::mineFormatPiecePtr))
{
event->acceptProposedAction();
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();
}
}
}
@ -152,17 +172,22 @@ void VPMainGraphicsView::dropEvent(QDropEvent *event)
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())
{
return;
}
VPPiecePtr piece = mimePiece->GetPiecePtr();
if(not piece.isNull())
{
VPLayoutPtr layout = m_layout.toStrongRef();
if (layout.isNull())
{
return;
}
qCDebug(pMainGraphicsView(), "element dropped, %s", qUtf8Printable(piece->GetName()));
event->acceptProposedAction();