From 35526b53f957f9fa09423871ee850c363a66ecae Mon Sep 17 00:00:00 2001 From: leia uwu Date: Fri, 3 Apr 2026 12:21:38 -0300 Subject: [PATCH] Add back drag and dropping to screenshots page Fixes #4548 And #1503 was technically fixed when drag and drop was disabled but can also be closed as this does not reintroduce the issue Signed-off-by: leia uwu --- .../ui/pages/instance/ScreenshotsPage.cpp | 19 ++++++++++++++++++- launcher/ui/pages/instance/ScreenshotsPage.h | 5 +++-- launcher/ui/pages/instance/ScreenshotsPage.ui | 10 +++++----- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/launcher/ui/pages/instance/ScreenshotsPage.cpp b/launcher/ui/pages/instance/ScreenshotsPage.cpp index e926974ea..70647bed7 100644 --- a/launcher/ui/pages/instance/ScreenshotsPage.cpp +++ b/launcher/ui/pages/instance/ScreenshotsPage.cpp @@ -69,6 +69,23 @@ #include #include "RWStorage.h" +class ScreenshotsFSModel : public QFileSystemModel { + bool canDropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) const override + { + QUrl root = QUrl::fromLocalFile(rootPath()); + // this disables reordering items inside the model + // by rejecting drops if the file is already inside the folder + if (data->hasUrls()) { + for (auto& url : data->urls()) { + if (root.isParentOf(url)) { + return false; + } + } + } + return QFileSystemModel::canDropMimeData(data, action, row, column, parent); + } +}; + using SharedIconCache = RWStorage; using SharedIconCachePtr = std::shared_ptr; @@ -237,7 +254,7 @@ class CenteredEditingDelegate : public QStyledItemDelegate { ScreenshotsPage::ScreenshotsPage(QString path, QWidget* parent) : QMainWindow(parent), ui(new Ui::ScreenshotsPage) { - m_model.reset(new QFileSystemModel()); + m_model.reset(new ScreenshotsFSModel()); m_filterModel.reset(new FilterModel()); m_filterModel->setSourceModel(m_model.get()); m_model->setFilter(QDir::Files); diff --git a/launcher/ui/pages/instance/ScreenshotsPage.h b/launcher/ui/pages/instance/ScreenshotsPage.h index b9c750a1f..0b068aa0a 100644 --- a/launcher/ui/pages/instance/ScreenshotsPage.h +++ b/launcher/ui/pages/instance/ScreenshotsPage.h @@ -41,13 +41,14 @@ #include "settings/Setting.h" -class QFileSystemModel; class QIdentityProxyModel; class QItemSelection; namespace Ui { class ScreenshotsPage; } +class ScreenshotsFSModel; + struct ScreenShot; class ScreenshotList; class ImgurAlbumCreation; @@ -88,7 +89,7 @@ class ScreenshotsPage : public QMainWindow, public BasePage { private: Ui::ScreenshotsPage* ui; - std::shared_ptr m_model; + std::shared_ptr m_model; std::shared_ptr m_filterModel; QString m_folder; bool m_valid = false; diff --git a/launcher/ui/pages/instance/ScreenshotsPage.ui b/launcher/ui/pages/instance/ScreenshotsPage.ui index c5b6bbc5f..4ed92c4b6 100644 --- a/launcher/ui/pages/instance/ScreenshotsPage.ui +++ b/launcher/ui/pages/instance/ScreenshotsPage.ui @@ -33,13 +33,13 @@ QAbstractItemView::SelectionMode::ExtendedSelection - QAbstractItemView::SelectionBehavior::SelectRows - - - QListView::Movement::Static + QAbstractItemView::SelectionBehavior::SelectItems - QAbstractItemView::ScrollPerPixel + QAbstractItemView::ScrollMode::ScrollPerPixel + + + QListView::Movement::Snap