From d8e38764fd24bd0bce965a7404a92227d98bbf36 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Tue, 3 Nov 2015 21:17:50 +0100 Subject: Drag and Drop Images Now that we have the possibility to add images without meaningful time stamps to a dive, we should let the user provide that time offset manually. This patch allowed pictures to be dragged from the image list to the profile. Signed-off-by: Robert C. Helling Signed-off-by: Dirk Hohndel --- desktop-widgets/divepicturewidget.cpp | 30 ++++++++++++++++++++++++++++++ desktop-widgets/divepicturewidget.h | 3 +++ 2 files changed, 33 insertions(+) (limited to 'desktop-widgets') 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 #include #include +#include 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(); + + 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); +} diff --git a/desktop-widgets/divepicturewidget.h b/desktop-widgets/divepicturewidget.h index 3dc9767f1..87e8eec33 100644 --- a/desktop-widgets/divepicturewidget.h +++ b/desktop-widgets/divepicturewidget.h @@ -10,6 +10,9 @@ class DivePictureWidget : public QListView { Q_OBJECT public: DivePictureWidget(QWidget *parent); +protected: + void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + signals: void photoDoubleClicked(const QString filePath); private -- cgit v1.2.3-70-g09d2