allow cover image to be added via Drag & Drop
This commit is contained in:
parent
95a5fe093e
commit
019740d815
|
@ -230,24 +230,16 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event)
|
|||
case QEvent::DragEnter:
|
||||
case QEvent::Drop:
|
||||
if(QDropEvent *dropEvent = static_cast<QDropEvent *>(event)) {
|
||||
QString data;
|
||||
const QMimeData *mimeData = dropEvent->mimeData();
|
||||
if(mimeData->hasUrls()) {
|
||||
const QUrl url = mimeData->urls().front();
|
||||
for(const auto &url : dropEvent->mimeData()->urls()) {
|
||||
if(url.scheme() == QLatin1String("file")) {
|
||||
data = url.path();
|
||||
}
|
||||
} else if(mimeData->hasText()) {
|
||||
data = mimeData->text();
|
||||
}
|
||||
if(!data.isEmpty()) {
|
||||
event->accept();
|
||||
if(event->type() == QEvent::Drop) {
|
||||
startParsing(data, true);
|
||||
}
|
||||
startParsing(url.path(), true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
#include <QFileDialog>
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QDropEvent>
|
||||
#include <QMimeData>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <functional>
|
||||
|
@ -51,12 +54,13 @@ PicturePreviewSelection::PicturePreviewSelection(Tag *tag, KnownField field, QWi
|
|||
m_currentTypeIndex(0)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
connect(m_ui->addButton, &QPushButton::clicked, this, &PicturePreviewSelection::addOfSelectedType);
|
||||
connect(m_ui->addButton, &QPushButton::clicked, this, static_cast<void (PicturePreviewSelection::*)(void)>(&PicturePreviewSelection::addOfSelectedType));
|
||||
connect(m_ui->removeButton, &QPushButton::clicked, this, &PicturePreviewSelection::removeSelected);
|
||||
connect(m_ui->extractButton, &QPushButton::clicked, this, &PicturePreviewSelection::extractSelected);
|
||||
connect(m_ui->displayButton, &QPushButton::clicked, this, &PicturePreviewSelection::displaySelected);
|
||||
connect(m_ui->restoreButton, &QPushButton::clicked, std::bind(&PicturePreviewSelection::setup, this, PreviousValueHandling::Clear));
|
||||
setup();
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -279,6 +283,18 @@ void PicturePreviewSelection::addOfSelectedType()
|
|||
if(m_currentTypeIndex < static_cast<unsigned int>(m_values.count())) {
|
||||
QString path = QFileDialog::getOpenFileName(this, tr("Select a picture to add as cover"));
|
||||
if(!path.isEmpty()) {
|
||||
addOfSelectedType(path);
|
||||
}
|
||||
} else {
|
||||
throw logic_error("Invalid type selected (no corresponding value assigned).");
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds the picture from the specified \a path of the selected type.
|
||||
*/
|
||||
void PicturePreviewSelection::addOfSelectedType(const QString &path)
|
||||
{
|
||||
TagValue &selectedCover = m_values[m_currentTypeIndex];
|
||||
try {
|
||||
MediaFileInfo fileInfo(path.toLocal8Bit().constData());
|
||||
|
@ -304,10 +320,6 @@ void PicturePreviewSelection::addOfSelectedType()
|
|||
QMessageBox::critical(this, QApplication::applicationName(), tr("Unable to parse specified cover file."));
|
||||
}
|
||||
updatePreview(m_currentTypeIndex);
|
||||
}
|
||||
} else {
|
||||
throw logic_error("Invalid type selected (no corresponding value assigned).");
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -423,6 +435,35 @@ void PicturePreviewSelection::resizeEvent(QResizeEvent *)
|
|||
}
|
||||
}
|
||||
|
||||
void PicturePreviewSelection::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
const auto *mimeData = event->mimeData();
|
||||
if(mimeData->hasUrls()) {
|
||||
for(const auto &url : mimeData->urls()) {
|
||||
if(url.scheme() == QLatin1String("file")) {
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void PicturePreviewSelection::dropEvent(QDropEvent *event)
|
||||
{
|
||||
const auto *mimeData = event->mimeData();
|
||||
if(mimeData->hasUrls()) {
|
||||
for(const auto &url : mimeData->urls()) {
|
||||
if(url.scheme() == QLatin1String("file")) {
|
||||
addOfSelectedType(url.path());
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Handles selected type being switched.
|
||||
*/
|
||||
|
|
|
@ -9,13 +9,11 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QEvent;
|
||||
class QGraphicsScene;
|
||||
class QGraphicsTextItem;
|
||||
class QGraphicsPixmapItem;
|
||||
class QGraphicsRectItem;
|
||||
QT_END_NAMESPACE
|
||||
QT_FORWARD_DECLARE_CLASS(QEvent)
|
||||
QT_FORWARD_DECLARE_CLASS(QGraphicsScene)
|
||||
QT_FORWARD_DECLARE_CLASS(QGraphicsTextItem)
|
||||
QT_FORWARD_DECLARE_CLASS(QGraphicsPixmapItem)
|
||||
QT_FORWARD_DECLARE_CLASS(QGraphicsRectItem)
|
||||
|
||||
namespace Media {
|
||||
class Tag;
|
||||
|
@ -48,6 +46,7 @@ public slots:
|
|||
void apply();
|
||||
void clear();
|
||||
void addOfSelectedType();
|
||||
void addOfSelectedType(const QString &path);
|
||||
void removeSelected();
|
||||
void extractSelected();
|
||||
void displaySelected();
|
||||
|
@ -58,6 +57,8 @@ signals:
|
|||
protected:
|
||||
void changeEvent(QEvent *event);
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
void dropEvent(QDropEvent *event);
|
||||
|
||||
private slots:
|
||||
void typeSwitched(int index);
|
||||
|
|
Loading…
Reference in New Issue