mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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 <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
350f6aa2fd
commit
d8e38764fd
4 changed files with 103 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue