2024-10-23 04:36:53 +08:00
|
|
|
#include "droppableitem.h"
|
|
|
|
|
|
|
|
#include <QDragEnterEvent>
|
|
|
|
#include <QDragLeaveEvent>
|
|
|
|
#include <QDropEvent>
|
|
|
|
#include <QMimeData>
|
|
|
|
#include <qsizepolicy.h>
|
|
|
|
|
|
|
|
DroppableItem::DroppableItem(const QString& text, QWidget* parent)
|
|
|
|
: QPushButton(text, parent)
|
|
|
|
{
|
|
|
|
setAcceptDrops(true);
|
|
|
|
setSizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Expanding);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DroppableItem::dragEnterEvent(QDragEnterEvent* event)
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasText())
|
|
|
|
{
|
|
|
|
event->acceptProposedAction();
|
|
|
|
setCursor(Qt::DragMoveCursor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DroppableItem::dragLeaveEvent(QDragLeaveEvent* event)
|
|
|
|
{
|
2024-10-28 22:40:32 +08:00
|
|
|
Q_UNUSED(event);
|
2024-10-23 04:36:53 +08:00
|
|
|
unsetCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DroppableItem::dropEvent(QDropEvent* event)
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasText())
|
|
|
|
{
|
|
|
|
event->acceptProposedAction();
|
|
|
|
setText(event->mimeData()->text());
|
|
|
|
}
|
|
|
|
}
|