diff --git a/custom_widgets/yacreader_table_view.cpp b/custom_widgets/yacreader_table_view.cpp index 86e83a1e..85a092af 100644 --- a/custom_widgets/yacreader_table_view.cpp +++ b/custom_widgets/yacreader_table_view.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "comic_item.h" @@ -101,6 +102,13 @@ void YACReaderTableView::mouseMoveEvent(QMouseEvent *event) else closeRatingEditor(); + //are we in a drag action?? + if(event->buttons() & Qt::LeftButton) { + int distance = (event->pos() - startDragPos).manhattanLength(); + if (distance >= QApplication::startDragDistance()) + performDrag(); + } + QTableView::mouseMoveEvent(event); } void YACReaderTableView::mousePressEvent(QMouseEvent * event) @@ -126,23 +134,29 @@ void YACReaderTableView::mousePressEvent(QMouseEvent * event) } } + //this could be the origin of a new drag acction if(event->button() == Qt::LeftButton) { - QMimeData *mimeData = new QMimeData; - - mimeData->setText("comic"); //TODO set the right mime data - - QDrag *drag = new QDrag(this); - drag->setMimeData(mimeData); - drag->setPixmap(QPixmap(":/images/openInYACReader.png")); //TODO add better image - - Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction); + startDragPos = event->pos(); } } void YACReaderTableView::leaveEvent(QEvent * event) { closeRatingEditor(); - event->accept(); + event->accept(); +} + +void YACReaderTableView::performDrag() +{ + QMimeData *mimeData = new QMimeData; + + mimeData->setText("comic"); //TODO set the right mime data + + QDrag *drag = new QDrag(this); + drag->setMimeData(mimeData); + drag->setPixmap(QPixmap(":/images/openInYACReader.png")); //TODO add better image + + Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction); } void YACReaderTableView::closeRatingEditor() diff --git a/custom_widgets/yacreader_table_view.h b/custom_widgets/yacreader_table_view.h index 9ce2fc96..e7e4deb5 100644 --- a/custom_widgets/yacreader_table_view.h +++ b/custom_widgets/yacreader_table_view.h @@ -33,10 +33,14 @@ private: void mouseMoveEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent * event); void leaveEvent(QEvent * event); + void performDrag(); bool editing; QModelIndex currentIndexEditing; QWidget * myeditor; + + //drag from here + QPoint startDragPos; }; //---