From b0d671fede5adfadad2b465fb4c8ae50b40516f3 Mon Sep 17 00:00:00 2001 From: Arno Date: Thu, 10 Apr 2014 16:14:32 +0200 Subject: Implement Drag and Drop in Movie Archive Well, this was actually a bit of a drag. You have read the docs very carefully to get it right. For one, don't construct the drag object in mousePressEvent if you also want a double click, otherwise you end up with very weird behavior. Same goes for the receiving end. Differentiate between dragEnterEvent and dragMoveEvent, otherwise you'll only be able to drop items if you hit the right row on entering. There are some artefacts during the drag, but I guess that's a Qt bug. Didn't bother to look into it. --- archiveview.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'archiveview.h') diff --git a/archiveview.h b/archiveview.h index f1b9029..dbe0e8f 100644 --- a/archiveview.h +++ b/archiveview.h @@ -33,6 +33,8 @@ class QCompleter; class QStandardItemModel; class QSpinBox; class QToolBar; +class QMouseEvent; +class QDragEnterEvent; class ArchiveView : public QWidget { Q_OBJECT @@ -96,6 +98,11 @@ class ArchiveTree : public SmTreeView { void deleteFromTree(); void newPart(); + protected: + virtual void dragEnterEvent(QDragEnterEvent *e); + virtual void dragMoveEvent(QDragMoveEvent *e); + virtual void dropEvent(QDropEvent *e); + private: void impossible(const QString msg = tr("Unable to perform function!")); QModelIndex firstSelected(); @@ -106,6 +113,13 @@ class ArchiveTree : public SmTreeView { class ArchiveFiles : public SmTreeView { public: explicit ArchiveFiles(const QString &headerSettings = "afilesheaders", QWidget *parent = 0); + + protected: + virtual void mousePressEvent(QMouseEvent *e); + virtual void mouseMoveEvent(QMouseEvent *e); + + private: + QPoint mDragStartPos; }; class ArchiveProxy : public QSortFilterProxyModel { -- cgit v1.2.3-70-g09d2