-
Notifications
You must be signed in to change notification settings - Fork 142
/
LVGLWidgetListView.cpp
40 lines (32 loc) · 1023 Bytes
/
LVGLWidgetListView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "LVGLWidgetListView.h"
#include "LVGLWidgetModel.h"
#include <QMimeData>
#include <QDrag>
#include "LVGLCore.h"
LVGLWidgetListView::LVGLWidgetListView(QWidget *parent) : QListView(parent)
{
setDragEnabled(true);
setDragDropMode(QAbstractItemView::DragOnly);
}
void LVGLWidgetListView::startDrag(Qt::DropActions supportedActions)
{
const QModelIndexList indexes = selectedIndexes();
QMimeData *mimeData = model()->mimeData(indexes);
if (!mimeData->hasFormat("application/x-widget"))
return QListView::startDrag(supportedActions);
LVGLWidgetCast cast;
QByteArray encoded = mimeData->data("application/x-widget");
QDataStream stream(&encoded, QIODevice::ReadOnly);
stream >> cast.i;
LVGLWidget *widgetClass = cast.ptr;
QPixmap preview = widgetClass->preview();
if (!preview.isNull()) {
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setPixmap(preview);
drag->setHotSpot({0, 0});
drag->exec(supportedActions);
} else {
QListView::startDrag(supportedActions);
}
}