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 <mainwindow.h>
|
||||||
#include <qthelper.h>
|
#include <qthelper.h>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
#include <QtWidgets>
|
||||||
|
|
||||||
DivePictureWidget::DivePictureWidget(QWidget *parent) : QListView(parent)
|
DivePictureWidget::DivePictureWidget(QWidget *parent) : QListView(parent)
|
||||||
{
|
{
|
||||||
|
@ -25,3 +26,32 @@ void DivePictureWidget::doubleClicked(const QModelIndex &index)
|
||||||
QString filePath = model()->data(index, Qt::DisplayPropertyRole).toString();
|
QString filePath = model()->data(index, Qt::DisplayPropertyRole).toString();
|
||||||
emit photoDoubleClicked(localFilePath(filePath));
|
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
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DivePictureWidget(QWidget *parent);
|
DivePictureWidget(QWidget *parent);
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void photoDoubleClicked(const QString filePath);
|
void photoDoubleClicked(const QString filePath);
|
||||||
private
|
private
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "diveplannermodel.h"
|
#include "diveplannermodel.h"
|
||||||
#include "models.h"
|
#include "models.h"
|
||||||
#include "divepicturemodel.h"
|
#include "divepicturemodel.h"
|
||||||
|
#include "divelist.h"
|
||||||
#ifndef SUBSURFACE_MOBILE
|
#ifndef SUBSURFACE_MOBILE
|
||||||
#include "diveplanner.h"
|
#include "diveplanner.h"
|
||||||
#include "simplewidgets.h"
|
#include "simplewidgets.h"
|
||||||
|
@ -33,6 +34,7 @@
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
#endif
|
#endif
|
||||||
#include "preferences/preferencesdialog.h"
|
#include "preferences/preferencesdialog.h"
|
||||||
|
#include <QtWidgets>
|
||||||
|
|
||||||
// a couple of helpers we need
|
// a couple of helpers we need
|
||||||
extern bool haveFilesOnCommandLine();
|
extern bool haveFilesOnCommandLine();
|
||||||
|
@ -129,6 +131,8 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent),
|
||||||
scene()->installEventFilter(this);
|
scene()->installEventFilter(this);
|
||||||
#ifndef SUBSURFACE_MOBILE
|
#ifndef SUBSURFACE_MOBILE
|
||||||
QAction *action = NULL;
|
QAction *action = NULL;
|
||||||
|
setAcceptDrops(true);
|
||||||
|
|
||||||
#define ADD_ACTION(SHORTCUT, Slot) \
|
#define ADD_ACTION(SHORTCUT, Slot) \
|
||||||
action = new QAction(this); \
|
action = new QAction(this); \
|
||||||
action->setShortcut(SHORTCUT); \
|
action->setShortcut(SHORTCUT); \
|
||||||
|
@ -1874,3 +1878,65 @@ void ProfileWidget2::plotPictures()
|
||||||
pictures.push_back(item);
|
pictures.push_back(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProfileWidget2::dropEvent(QDropEvent *event)
|
||||||
|
{
|
||||||
|
if (event->mimeData()->hasFormat("application/x-subsurfaceimagedrop")) {
|
||||||
|
QByteArray itemData = event->mimeData()->data("application/x-subsurfaceimagedrop");
|
||||||
|
QDataStream dataStream(&itemData, QIODevice::ReadOnly);
|
||||||
|
|
||||||
|
QString filename;
|
||||||
|
QPoint offset;
|
||||||
|
dataStream >> filename >> offset;
|
||||||
|
|
||||||
|
QPointF mappedPos = mapToScene(event->pos());
|
||||||
|
|
||||||
|
FOR_EACH_PICTURE(current_dive) {
|
||||||
|
if (QString(picture->filename) == filename) {
|
||||||
|
picture->offset.seconds = timeAxis->valueAt(mappedPos);
|
||||||
|
mark_divelist_changed(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
copy_dive(current_dive, &displayed_dive);
|
||||||
|
DivePictureModel::instance()->updateDivePictures();
|
||||||
|
|
||||||
|
|
||||||
|
if (event->source() == this) {
|
||||||
|
event->setDropAction(Qt::MoveAction);
|
||||||
|
event->accept();
|
||||||
|
} else {
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
event->ignore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProfileWidget2::dragEnterEvent(QDragEnterEvent *event)
|
||||||
|
{
|
||||||
|
if (event->mimeData()->hasFormat("application/x-subsurfaceimagedrop")) {
|
||||||
|
if (event->source() == this) {
|
||||||
|
event->setDropAction(Qt::MoveAction);
|
||||||
|
event->accept();
|
||||||
|
} else {
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
event->ignore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProfileWidget2::dragMoveEvent(QDragMoveEvent *event)
|
||||||
|
{
|
||||||
|
if (event->mimeData()->hasFormat("application/x-subsurfaceimagedrop")) {
|
||||||
|
if (event->source() == this) {
|
||||||
|
event->setDropAction(Qt::MoveAction);
|
||||||
|
event->accept();
|
||||||
|
} else {
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
event->ignore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -149,6 +149,10 @@ protected:
|
||||||
virtual void mouseDoubleClickEvent(QMouseEvent *event);
|
virtual void mouseDoubleClickEvent(QMouseEvent *event);
|
||||||
virtual void mousePressEvent(QMouseEvent *event);
|
virtual void mousePressEvent(QMouseEvent *event);
|
||||||
virtual void mouseReleaseEvent(QMouseEvent *event);
|
virtual void mouseReleaseEvent(QMouseEvent *event);
|
||||||
|
void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
|
||||||
private: /*methods*/
|
private: /*methods*/
|
||||||
void fixBackgroundPos();
|
void fixBackgroundPos();
|
||||||
|
|
Loading…
Add table
Reference in a new issue