# HG changeset patch # User Chris Cannam # Date 1192029482 0 # Node ID 6de6f78b13a16282f0e40a915086849119641234 # Parent fee76aa923d8aa50f391226a3850b8b363097ba5 * Make it possible to drop audio files, layer files, session files and images onto SV panes. Need to do a bit more work on where we expect the dropped file to go, particularly in the case of audio files -- at the moment they're always opened in new panes, but it may be better to by default replace whatever is in the target pane. diff -r fee76aa923d8 -r 6de6f78b13a1 layer/ImageLayer.cpp --- a/layer/ImageLayer.cpp Wed Oct 10 10:22:34 2007 +0000 +++ b/layer/ImageLayer.cpp Wed Oct 10 15:18:02 2007 +0000 @@ -632,6 +632,24 @@ m_editing = false; } +bool +ImageLayer::addImage(long frame, QString url) +{ + QImage image(getLocalFilename(url)); + if (image.isNull()) { + delete m_remoteFiles[url]; + m_remoteFiles.erase(url); + return false; + } + + ImageModel::Point point(frame, url, ""); + ImageModel::EditCommand *command = + new ImageModel::EditCommand(m_model, "Add Image"); + command->addPoint(point); + command->finish(); + return true; +} + void ImageLayer::editStart(View *v, QMouseEvent *e) { @@ -855,7 +873,9 @@ { if (m_remoteFiles.find(img) == m_remoteFiles.end()) { checkAddRemote(img); - return img; + if (m_remoteFiles.find(img) == m_remoteFiles.end()) { + return img; + } } return m_remoteFiles[img]->getLocalFilename(); } @@ -865,6 +885,8 @@ { if (RemoteFile::isRemote(img)) { + std::cerr << "ImageLayer::checkAddRemote(" << img.toStdString() << "): yes, trying..." << std::endl; + if (m_remoteFiles.find(img) != m_remoteFiles.end()) { return; } @@ -873,6 +895,7 @@ if (RemoteFile::canHandleScheme(url)) { RemoteFile *rf = new RemoteFile(url); if (rf->isOK()) { + std::cerr << "ok, adding it (local filename = " << rf->getLocalFilename().toStdString() << ")" << std::endl; m_remoteFiles[img] = rf; connect(rf, SIGNAL(ready()), this, SLOT(remoteFileReady())); } else { diff -r fee76aa923d8 -r 6de6f78b13a1 layer/ImageLayer.h --- a/layer/ImageLayer.h Wed Oct 10 10:22:34 2007 +0000 +++ b/layer/ImageLayer.h Wed Oct 10 15:18:02 2007 +0000 @@ -96,6 +96,8 @@ void setProperties(const QXmlAttributes &attributes); + virtual bool addImage(long frame, QString url); // using a command + protected slots: void checkAddRemotes(); void remoteFileReady(); diff -r fee76aa923d8 -r 6de6f78b13a1 view/Pane.cpp --- a/view/Pane.cpp Wed Oct 10 10:22:34 2007 +0000 +++ b/view/Pane.cpp Wed Oct 10 15:18:02 2007 +0000 @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include #include #include @@ -67,6 +69,7 @@ { setObjectName("Pane"); setMouseTracking(true); + setAcceptDrops(true); updateHeadsUpDisplay(); } @@ -1893,6 +1896,55 @@ } } +void +Pane::dragEnterEvent(QDragEnterEvent *e) +{ + QStringList formats(e->mimeData()->formats()); + std::cerr << "dragEnterEvent: format: " + << formats.join(",").toStdString() + << ", possibleActions: " << e->possibleActions() + << ", proposedAction: " << e->proposedAction() << std::endl; + + if (e->provides("text/uri-list") || e->provides("text/plain")) { + + if (e->proposedAction() & Qt::CopyAction) { + e->acceptProposedAction(); + } else { + e->setDropAction(Qt::CopyAction); + e->accept(); + } + } +} + +void +Pane::dropEvent(QDropEvent *e) +{ + std::cerr << "dropEvent: text: \"" << e->mimeData()->text().toStdString() + << "\"" << std::endl; + + if (e->provides("text/uri-list") || e->provides("text/plain")) { + + if (e->proposedAction() & Qt::CopyAction) { + e->acceptProposedAction(); + } else { + e->setDropAction(Qt::CopyAction); + e->accept(); + } + + if (e->provides("text/uri-list")) { + + std::cerr << "accepting... data is \"" << e->encodedData("text/uri-list").data() << "\"" << std::endl; + emit dropAccepted(QString::fromLocal8Bit + (e->encodedData("text/uri-list").data()) + .split(QRegExp("[\\r\\n]+"), + QString::SkipEmptyParts)); + } else { + emit dropAccepted(QString::fromLocal8Bit + (e->encodedData("text/plain").data())); + } + } +} + bool Pane::editSelectionStart(QMouseEvent *e) { diff -r fee76aa923d8 -r 6de6f78b13a1 view/Pane.h --- a/view/Pane.h Wed Oct 10 10:22:34 2007 +0000 +++ b/view/Pane.h Wed Oct 10 15:18:02 2007 +0000 @@ -66,6 +66,8 @@ signals: void paneInteractedWith(); void rightButtonMenuRequested(QPoint position); + void dropAccepted(QStringList uriList); + void dropAccepted(QString text); public slots: virtual void toolModeChanged(); @@ -93,6 +95,8 @@ virtual void leaveEvent(QEvent *e); virtual void wheelEvent(QWheelEvent *e); virtual void resizeEvent(QResizeEvent *e); + virtual void dragEnterEvent(QDragEnterEvent *e); + virtual void dropEvent(QDropEvent *e); void drawVerticalScale(QRect r, Layer *, QPainter &); void drawFeatureDescription(Layer *, QPainter &); diff -r fee76aa923d8 -r 6de6f78b13a1 view/PaneStack.cpp --- a/view/PaneStack.cpp Wed Oct 10 10:22:34 2007 +0000 +++ b/view/PaneStack.cpp Wed Oct 10 15:18:02 2007 +0000 @@ -114,6 +114,10 @@ this, SLOT(paneInteractedWith())); connect(pane, SIGNAL(rightButtonMenuRequested(QPoint)), this, SLOT(rightButtonMenuRequested(QPoint))); + connect(pane, SIGNAL(dropAccepted(QStringList)), + this, SLOT(paneDropAccepted(QStringList))); + connect(pane, SIGNAL(dropAccepted(QString)), + this, SLOT(paneDropAccepted(QString))); emit paneAdded(pane); emit paneAdded(); @@ -483,4 +487,17 @@ emit propertyStacksResized(); } +void +PaneStack::paneDropAccepted(QStringList uriList) +{ + Pane *pane = dynamic_cast(sender()); + emit dropAccepted(pane, uriList); +} + +void +PaneStack::paneDropAccepted(QString text) +{ + Pane *pane = dynamic_cast(sender()); + emit dropAccepted(pane, text); +} diff -r fee76aa923d8 -r 6de6f78b13a1 view/PaneStack.h --- a/view/PaneStack.h Wed Oct 10 10:22:34 2007 +0000 +++ b/view/PaneStack.h Wed Oct 10 15:18:02 2007 +0000 @@ -78,6 +78,9 @@ void paneAboutToBeDeleted(Pane *pane); void paneDeleted(); + void dropAccepted(Pane *pane, QStringList uriList); + void dropAccepted(Pane *pane, QString text); + public slots: void propertyContainerAdded(PropertyContainer *); void propertyContainerRemoved(PropertyContainer *); @@ -85,6 +88,8 @@ void viewSelected(View *v); void paneInteractedWith(); void rightButtonMenuRequested(QPoint); + void paneDropAccepted(QStringList); + void paneDropAccepted(QString); protected: Pane *m_currentPane;