Support drag&drop for setting a custom cover in the properties dialog

This commit is contained in:
Luis Ángel San Martín
2025-05-09 19:58:52 +02:00
parent 28952180ab
commit 8b159c9da6
7 changed files with 115 additions and 5 deletions

View File

@ -111,3 +111,40 @@ QString YACReader::imageFileLoader(QWidget *parent)
return QFileDialog::getOpenFileName(parent, QObject::tr("Select custom cover"), QDir::homePath(), QObject::tr("Images (%1)").arg(supportedImageFormatsString));
}
QString YACReader::imagePathFromMimeData(const QMimeData *mimeData)
{
QString filePath;
// Check for URLs (drag from browser or file explorer)
if (mimeData->hasUrls()) {
QList<QUrl> urlList = mimeData->urls();
// We only handle the first URL for simplicity
if (!urlList.isEmpty()) {
QUrl url = urlList.first();
if (url.isLocalFile()) {
filePath = url.toLocalFile();
// Verify it's an image file using the extension
QFileInfo fileInfo(filePath);
QString extension = fileInfo.suffix().toLower();
QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
bool isSupported = false;
for (const QByteArray &format : supportedFormats) {
if (extension == QString(format).toLower()) {
isSupported = true;
break;
}
}
if (!isSupported) {
filePath.clear(); // Not a supported image format
}
}
}
}
return filePath;
}

View File

@ -113,5 +113,6 @@ QString addExtensionToIconPathInToolbar(const QString &path);
QAction *actionWithCustomIcon(const QIcon &icon, QAction *action);
QPixmap hdpiPixmap(const QString &file, QSize size);
QString imageFileLoader(QWidget *parent);
QString imagePathFromMimeData(const QMimeData *mimeData);
}
#endif