mirror of
https://github.com/YACReader/yacreader
synced 2025-07-19 05:24:57 -04:00
Support drag&drop for setting a custom cover in the properties dialog
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user