diff options
Diffstat (limited to 'desktop-widgets/divepicturewidget.cpp')
-rw-r--r-- | desktop-widgets/divepicturewidget.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/desktop-widgets/divepicturewidget.cpp b/desktop-widgets/divepicturewidget.cpp index d095929ad..a3a3c7a65 100644 --- a/desktop-widgets/divepicturewidget.cpp +++ b/desktop-widgets/divepicturewidget.cpp @@ -14,6 +14,7 @@ #include <mainwindow.h> #include <qthelper.h> #include <QStandardPaths> +#include <QtWidgets> DivePictureWidget::DivePictureWidget(QWidget *parent) : QListView(parent) { @@ -25,3 +26,32 @@ void DivePictureWidget::doubleClicked(const QModelIndex &index) QString filePath = model()->data(index, Qt::DisplayPropertyRole).toString(); emit photoDoubleClicked(localFilePath(filePath)); } + + +void DivePictureWidget::mousePressEvent(QMouseEvent *event) +{ + + QPixmap pixmap = model()->data(indexAt(event->pos()), Qt::DecorationRole).value<QPixmap>(); + + QString filename = model()->data(indexAt(event->pos()), Qt::DisplayPropertyRole).toString(); + + QByteArray itemData; + QDataStream dataStream(&itemData, QIODevice::WriteOnly); + dataStream << filename << event->pos(); + + QMimeData *mimeData = new QMimeData; + mimeData->setData("application/x-subsurfaceimagedrop", itemData); + + QDrag *drag = new QDrag(this); + drag->setMimeData(mimeData); + drag->setPixmap(pixmap); + drag->setHotSpot(event->pos() - rectForIndex(indexAt(event->pos())).topLeft()); + + QPixmap tempPixmap = pixmap; + QPainter painter; + painter.begin(&tempPixmap); + painter.fillRect(pixmap.rect(), QColor(127, 127, 127, 127)); + painter.end(); + + drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction); +} |