summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2020-12-28 15:20:37 +0100
committerMikaël Capelle <capelle.mikael@gmail.com>2021-01-02 15:38:15 +0100
commit9d8c64dccbdb5144c6496cbd9ef4eb636f6b4ace (patch)
tree695c1bcbc442e648b844ff04655e655b786e2148 /src
parent9db6a9d7931edbb08e74cd1e110794f47d46df3e (diff)
Do not set Qt::ItemIsDropEnabled all the time.
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cpp2
-rw-r--r--src/modlist.cpp18
-rw-r--r--src/modlist.h3
-rw-r--r--src/modlistview.cpp6
-rw-r--r--src/modlistview.h5
5 files changed, 28 insertions, 6 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 65ab368d..48a935ae 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -578,6 +578,8 @@ void MainWindow::setupModList()
ui->modList->sortByColumn(ModList::COL_PRIORITY, Qt::AscendingOrder);
+ connect(ui->modList, &ModListView::dragEntered, m_OrganizerCore.modList(), &ModList::onDragEnter);
+
connect(
ui->modList->header(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)),
this, SLOT(modListSortIndicatorChanged(int,Qt::SortOrder)));
diff --git a/src/modlist.cpp b/src/modlist.cpp
index a058e71c..79dbf815 100644
--- a/src/modlist.cpp
+++ b/src/modlist.cpp
@@ -664,7 +664,6 @@ QVariant ModList::headerData(int section, Qt::Orientation orientation,
return QAbstractItemModel::headerData(section, orientation, role);
}
-
Qt::ItemFlags ModList::flags(const QModelIndex &modelIndex) const
{
Qt::ItemFlags result = QAbstractItemModel::flags(modelIndex);
@@ -688,10 +687,15 @@ Qt::ItemFlags ModList::flags(const QModelIndex &modelIndex) const
result |= Qt::ItemIsEditable;
}
}
+ if (modInfo->isSeparator() || m_DropOnMod) {
+ result |= Qt::ItemIsDropEnabled;
+ }
+ }
+ else if (!m_DropOnMod) {
+ result |= Qt::ItemIsDropEnabled;
}
- // drop check is handled by canDropMimeData
- return result | Qt::ItemIsDropEnabled;
+ return result;
}
@@ -1241,6 +1245,11 @@ bool ModList::dropArchive(const QMimeData* mimeData, int row, const QModelIndex&
return false;
}
+void ModList::onDragEnter(const QMimeData* mimeData)
+{
+ m_DropOnMod = mimeData->hasUrls();
+}
+
bool ModList::canDropMimeData(const QMimeData* mimeData, Qt::DropAction action, int row, int column, const QModelIndex& parent) const
{
if (action == Qt::IgnoreAction) {
@@ -1261,8 +1270,7 @@ bool ModList::canDropMimeData(const QMimeData* mimeData, Qt::DropAction action,
else if (mimeData->hasText()) {
// drop on item
if (row == -1 && parent.isValid()) {
- ModInfo::Ptr modInfo = ModInfo::getByIndex(parent.row());
- return modInfo->isSeparator();
+ return true;
}
else if (hasIndex(row, column, parent)) {
ModInfo::Ptr modInfo = ModInfo::getByIndex(row);
diff --git a/src/modlist.h b/src/modlist.h
index eebb1105..4e50c959 100644
--- a/src/modlist.h
+++ b/src/modlist.h
@@ -215,7 +215,7 @@ public: // implementation of virtual functions of QAbstractItemModel
public slots:
-
+ void onDragEnter(const QMimeData* data);
void enableSelected(const QItemSelectionModel *selectionModel);
void disableSelected(const QItemSelectionModel *selectionModel);
@@ -399,6 +399,7 @@ private:
mutable bool m_Modified;
bool m_InNotifyChange;
+ bool m_DropOnMod = false;
QFontMetrics m_FontMetrics;
diff --git a/src/modlistview.cpp b/src/modlistview.cpp
index 27e23417..91bdced3 100644
--- a/src/modlistview.cpp
+++ b/src/modlistview.cpp
@@ -18,6 +18,12 @@ void ModListView::setModel(QAbstractItemModel *model)
setVerticalScrollBar(new ViewMarkingScrollBar(model, this));
}
+void ModListView::dragEnterEvent(QDragEnterEvent* event)
+{
+ emit dragEntered(event->mimeData());
+ QTreeView::dragEnterEvent(event);
+}
+
void ModListView::dragMoveEvent(QDragMoveEvent* event)
{
if (autoExpandDelay() >= 0) {
diff --git a/src/modlistview.h b/src/modlistview.h
index bc5654ce..9546321e 100644
--- a/src/modlistview.h
+++ b/src/modlistview.h
@@ -12,6 +12,10 @@ public:
explicit ModListView(QWidget *parent = 0);
void setModel(QAbstractItemModel *model) override;
+signals:
+
+ void dragEntered(const QMimeData* mimeData);
+
protected:
// replace the auto-expand timer from QTreeView to avoid
@@ -19,6 +23,7 @@ protected:
QBasicTimer openTimer;
void timerEvent(QTimerEvent* event) override;
+ void dragEnterEvent(QDragEnterEvent* event) override;
void dragMoveEvent(QDragMoveEvent* event) override;
private: