Mercurial > hg > svgui
changeset 312:6de6f78b13a1
* 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.
author | Chris Cannam |
---|---|
date | Wed, 10 Oct 2007 15:18:02 +0000 |
parents | fee76aa923d8 |
children | 1517c76cd678 |
files | layer/ImageLayer.cpp layer/ImageLayer.h view/Pane.cpp view/Pane.h view/PaneStack.cpp view/PaneStack.h |
diffstat | 6 files changed, 104 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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 {
--- 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();
--- 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 <QPaintEvent> #include <QPainter> #include <QBitmap> +#include <QDragEnterEvent> +#include <QDropEvent> #include <QCursor> #include <iostream> #include <cmath> @@ -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) {
--- 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 &);
--- 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<Pane *>(sender()); + emit dropAccepted(pane, uriList); +} + +void +PaneStack::paneDropAccepted(QString text) +{ + Pane *pane = dynamic_cast<Pane *>(sender()); + emit dropAccepted(pane, text); +}
--- 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;