| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef KSNIP_DRAGANDDROPPROCESSOR_H |
| 21 |
#define KSNIP_DRAGANDDROPPROCESSOR_H |
| 22 |
|
| 23 |
#include <QObject> |
| 24 |
#include <QDragEnterEvent> |
| 25 |
#include <QMimeData> |
| 26 |
#include <QGraphicsSceneDragDropEvent> |
| 27 |
#include <QDrag> |
| 28 |
#include <QApplication> |
| 29 |
#include <QPixmap> |
| 30 |
#include <QList> |
| 31 |
#include <QUrl> |
| 32 |
#include <QDir> |
| 33 |
|
| 34 |
#include "IDragContentProvider.h" |
| 35 |
#include "src/common/helper/FileUrlHelper.h" |
| 36 |
#include "src/common/helper/PathHelper.h" |
| 37 |
#include "src/common/provider/ITempFileProvider.h" |
| 38 |
|
| 39 |
class DragAndDropProcessor : public QObject |
| 40 |
{ |
| 41 |
Q_OBJECT |
| 42 |
public: |
| 43 |
explicit DragAndDropProcessor(IDragContentProvider *dragContentProvider, const QSharedPointer<ITempFileProvider> &tempFileProvider); |
| 44 |
~DragAndDropProcessor() override = default; |
| 45 |
bool eventFilter(QObject *object, QEvent *event) override; |
| 46 |
|
| 47 |
signals: |
| 48 |
void fileDropped(const QString &path); |
| 49 |
void imageDropped(const QPixmap &pixmap); |
| 50 |
|
| 51 |
private: |
| 52 |
IDragContentProvider *mDragContentProvider; |
| 53 |
QSharedPointer<ITempFileProvider> mTempFileProvider; |
| 54 |
QPoint mDragStartPosition; |
| 55 |
|
| 56 |
static bool handleDragEnter(QDragEnterEvent *event); |
| 57 |
static bool handleDragEnter(QGraphicsSceneDragDropEvent *event); |
| 58 |
bool handleDrop(QDropEvent *event); |
| 59 |
bool handleDrop(QGraphicsSceneDragDropEvent *event); |
| 60 |
bool handleDragStart(QMouseEvent *event); |
| 61 |
bool handleDragMove(QMouseEvent *event); |
| 62 |
static QStringList getUrlsFromMimeData(const QMimeData *mimeData); |
| 63 |
static bool isDragStarting(const QMouseEvent *event); |
| 64 |
bool isMinDragDistanceReached(const QMouseEvent *event) const; |
| 65 |
void createDrag(const DragContent &dragContent); |
| 66 |
QString getPathToDraggedImage(const DragContent &dragContent); |
| 67 |
void processDroppedImagePaths(const QStringList &paths); |
| 68 |
}; |
| 69 |
|
| 70 |
#endif |