From bc1027ee9509d4bc5155d0b1e9de83c59e3d5bc3 Mon Sep 17 00:00:00 2001 From: unelsson Date: Sat, 14 Jan 2023 22:49:54 +0200 Subject: [PATCH] First draft of getting the exact drag start location --- apps/opencs/model/world/tablemimedata.hpp | 12 ++++++++++++ apps/opencs/view/tools/reporttable.cpp | 2 +- apps/opencs/view/world/dragrecordtable.cpp | 4 +++- apps/opencs/view/world/dragrecordtable.hpp | 2 +- apps/opencs/view/world/regionmap.cpp | 2 +- apps/opencs/view/world/table.cpp | 2 +- 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/apps/opencs/model/world/tablemimedata.hpp b/apps/opencs/model/world/tablemimedata.hpp index e32a16617d..70d96aa031 100644 --- a/apps/opencs/model/world/tablemimedata.hpp +++ b/apps/opencs/model/world/tablemimedata.hpp @@ -6,6 +6,7 @@ #include #include +#include #include "columnbase.hpp" #include "universalid.hpp" @@ -15,6 +16,11 @@ namespace CSMDoc class Document; } +namespace CSVWorld +{ + class DragRecordTable; +} + namespace CSMWorld { @@ -30,6 +36,8 @@ namespace CSMWorld std::vector mUniversalId; QStringList mObjectsFormats; const CSMDoc::Document& mDocument; + const CSVWorld::DragRecordTable* mTableOfDragStart; + QModelIndex mIndexAtDragStart; public: TableMimeData(UniversalId id, const CSMDoc::Document& document); @@ -55,6 +63,10 @@ namespace CSMWorld const CSMDoc::Document* getDocumentPtr() const; UniversalId returnMatching(CSMWorld::ColumnBase::Display type) const; + + void setIndexAtDragStart(QModelIndex index) {mIndexAtDragStart = index;} + + void setTableOfDragStart(const CSVWorld::DragRecordTable* table) {mTableOfDragStart = table;} static CSMWorld::UniversalId::Type convertEnums(CSMWorld::ColumnBase::Display type); diff --git a/apps/opencs/view/tools/reporttable.cpp b/apps/opencs/view/tools/reporttable.cpp index b7599a272c..7ec55b96b5 100644 --- a/apps/opencs/view/tools/reporttable.cpp +++ b/apps/opencs/view/tools/reporttable.cpp @@ -93,7 +93,7 @@ void CSVTools::ReportTable::contextMenuEvent(QContextMenuEvent* event) void CSVTools::ReportTable::mouseMoveEvent(QMouseEvent* event) { if (event->buttons() & Qt::LeftButton) - startDragFromTable(*this); + startDragFromTable(*this, indexAt(event->pos())); } void CSVTools::ReportTable::mouseDoubleClickEvent(QMouseEvent* event) diff --git a/apps/opencs/view/world/dragrecordtable.cpp b/apps/opencs/view/world/dragrecordtable.cpp index ed95acea8b..1ffcd271dc 100644 --- a/apps/opencs/view/world/dragrecordtable.cpp +++ b/apps/opencs/view/world/dragrecordtable.cpp @@ -16,7 +16,7 @@ #include "dragdroputils.hpp" -void CSVWorld::DragRecordTable::startDragFromTable(const CSVWorld::DragRecordTable& table) +void CSVWorld::DragRecordTable::startDragFromTable(const CSVWorld::DragRecordTable& table, QModelIndex index) { std::vector records = table.getDraggedRecords(); if (records.empty()) @@ -25,6 +25,8 @@ void CSVWorld::DragRecordTable::startDragFromTable(const CSVWorld::DragRecordTab } CSMWorld::TableMimeData* mime = new CSMWorld::TableMimeData(records, mDocument); + mime->setTableOfDragStart(&table); + mime->setIndexAtDragStart(index); QDrag* drag = new QDrag(this); drag->setMimeData(mime); drag->setPixmap(QString::fromUtf8(mime->getIcon().c_str())); diff --git a/apps/opencs/view/world/dragrecordtable.hpp b/apps/opencs/view/world/dragrecordtable.hpp index bbd3ece7ee..614ff5e408 100644 --- a/apps/opencs/view/world/dragrecordtable.hpp +++ b/apps/opencs/view/world/dragrecordtable.hpp @@ -42,7 +42,7 @@ namespace CSVWorld void setEditLock(bool locked); protected: - void startDragFromTable(const DragRecordTable& table); + void startDragFromTable(const DragRecordTable& table, QModelIndex index); void dragEnterEvent(QDragEnterEvent* event) override; diff --git a/apps/opencs/view/world/regionmap.cpp b/apps/opencs/view/world/regionmap.cpp index cf6cdf9104..df5418ba76 100644 --- a/apps/opencs/view/world/regionmap.cpp +++ b/apps/opencs/view/world/regionmap.cpp @@ -338,7 +338,7 @@ void CSVWorld::RegionMap::viewInTable() void CSVWorld::RegionMap::mouseMoveEvent(QMouseEvent* event) { - startDragFromTable(*this); + startDragFromTable(*this, indexAt(event->pos())); } std::vector CSVWorld::RegionMap::getDraggedRecords() const diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index cff16a85f2..fa47ad69e0 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -871,7 +871,7 @@ void CSVWorld::Table::mouseMoveEvent(QMouseEvent* event) { if (event->buttons() & Qt::LeftButton) { - startDragFromTable(*this); + startDragFromTable(*this, indexAt(event->pos())); } }