mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-14 02:27:09 -07:00
Add drag support to torrent content widget
Now qbt supports dragging items from torrent content widget to another app. Closes #5860. PR #21569.
This commit is contained in:
parent
6418033cc8
commit
c4eeb4a14a
3 changed files with 49 additions and 1 deletions
|
@ -34,8 +34,10 @@
|
|||
#include <QFileIconProvider>
|
||||
#include <QFileInfo>
|
||||
#include <QIcon>
|
||||
#include <QMimeData>
|
||||
#include <QPointer>
|
||||
#include <QScopeGuard>
|
||||
#include <QUrl>
|
||||
|
||||
#if defined(Q_OS_MACOS)
|
||||
#define QBT_PIXMAP_CACHE_FOR_FILE_ICONS
|
||||
|
@ -434,7 +436,7 @@ Qt::ItemFlags TorrentContentModel::flags(const QModelIndex &index) const
|
|||
if (!index.isValid())
|
||||
return Qt::NoItemFlags;
|
||||
|
||||
Qt::ItemFlags flags {Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable};
|
||||
Qt::ItemFlags flags {Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable};
|
||||
if (itemType(index) == TorrentContentModelItem::FolderType)
|
||||
flags |= Qt::ItemIsAutoTristate;
|
||||
if (index.column() == TorrentContentModelItem::COL_PRIO)
|
||||
|
@ -515,6 +517,47 @@ int TorrentContentModel::rowCount(const QModelIndex &parent) const
|
|||
return parentItem ? parentItem->childCount() : 0;
|
||||
}
|
||||
|
||||
QMimeData *TorrentContentModel::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
if (indexes.isEmpty())
|
||||
return nullptr;
|
||||
|
||||
const Path storagePath = contentHandler()->actualStorageLocation();
|
||||
|
||||
QList<QUrl> paths;
|
||||
paths.reserve(indexes.size());
|
||||
|
||||
for (const QModelIndex &index : indexes)
|
||||
{
|
||||
if (!index.isValid())
|
||||
continue;
|
||||
if (index.column() != TorrentContentModelItem::COL_NAME)
|
||||
continue;
|
||||
|
||||
if (itemType(index) == TorrentContentModelItem::FileType)
|
||||
{
|
||||
const int idx = getFileIndex(index);
|
||||
const Path fullPath = storagePath / contentHandler()->actualFilePath(idx);
|
||||
paths.append(QUrl::fromLocalFile(fullPath.data()));
|
||||
}
|
||||
else // folder type
|
||||
{
|
||||
const Path fullPath = storagePath / getItemPath(index);
|
||||
paths.append(QUrl::fromLocalFile(fullPath.data()));
|
||||
}
|
||||
}
|
||||
|
||||
auto *mimeData = new QMimeData; // lifetime will be handled by Qt
|
||||
mimeData->setUrls(paths);
|
||||
|
||||
return mimeData;
|
||||
}
|
||||
|
||||
QStringList TorrentContentModel::mimeTypes() const
|
||||
{
|
||||
return {u"text/uri-list"_s};
|
||||
}
|
||||
|
||||
void TorrentContentModel::populate()
|
||||
{
|
||||
Q_ASSERT(m_contentHandler && m_contentHandler->hasMetadata());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue