|
|
@ -15,6 +15,7 @@ |
|
|
|
#include "UBBoardView.h" |
|
|
|
#include "UBBoardView.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <QtGui> |
|
|
|
#include <QtGui> |
|
|
|
|
|
|
|
#include <QtXml> |
|
|
|
|
|
|
|
|
|
|
|
#include "UBDrawingController.h" |
|
|
|
#include "UBDrawingController.h" |
|
|
|
|
|
|
|
|
|
|
@ -48,6 +49,24 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include "core/memcheck.h" |
|
|
|
#include "core/memcheck.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Known extentions for files, add if you know more supported
|
|
|
|
|
|
|
|
const QString audioExtentions = ".mp3.wma.ogg"; |
|
|
|
|
|
|
|
const QString videoExtentions = ".avi.flv"; |
|
|
|
|
|
|
|
const QString imageExtentions = ".png.jpg.tif.bmp.tga"; |
|
|
|
|
|
|
|
const QString htmlExtentions = ".htm.html.xhtml"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Allways use aliases instead of const char* itself
|
|
|
|
|
|
|
|
const QString imageAlias = "image"; |
|
|
|
|
|
|
|
const QString videoAlias = "video"; |
|
|
|
|
|
|
|
const QString audioAlias = "audio"; |
|
|
|
|
|
|
|
const QString htmlAlias = "html"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Xml tag names
|
|
|
|
|
|
|
|
const QString tMainSection = "mimedata"; |
|
|
|
|
|
|
|
const QString tType = "type"; |
|
|
|
|
|
|
|
const QString tPath = "path"; |
|
|
|
|
|
|
|
|
|
|
|
UBBoardView::UBBoardView (UBBoardController* pController, QWidget* pParent) |
|
|
|
UBBoardView::UBBoardView (UBBoardController* pController, QWidget* pParent) |
|
|
|
: QGraphicsView (pParent) |
|
|
|
: QGraphicsView (pParent) |
|
|
|
, mController (pController) |
|
|
|
, mController (pController) |
|
|
@ -720,64 +739,93 @@ void UBBoardView::dragMoveEvent (QDragMoveEvent *event) |
|
|
|
UBGraphicsWidgetItem* graphicsWidget = dynamic_cast<UBGraphicsWidgetItem*>(graphicsItemAtPos); |
|
|
|
UBGraphicsWidgetItem* graphicsWidget = dynamic_cast<UBGraphicsWidgetItem*>(graphicsItemAtPos); |
|
|
|
|
|
|
|
|
|
|
|
if (graphicsWidget && graphicsWidget->acceptDrops()){ |
|
|
|
if (graphicsWidget && graphicsWidget->acceptDrops()){ |
|
|
|
|
|
|
|
if (isDropableData(event->mimeData())) { |
|
|
|
QPoint newPoint(graphicsWidget->mapFromScene(mapToScene(event->pos())).toPoint()); |
|
|
|
QPoint newPoint(graphicsWidget->mapFromScene(mapToScene(event->pos())).toPoint()); |
|
|
|
QDragMoveEvent newEvent(newPoint, event->dropAction(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers()); |
|
|
|
QDragMoveEvent newEvent(newPoint, event->dropAction(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers()); |
|
|
|
QApplication::sendEvent(graphicsWidget->widgetWebView(),&newEvent); |
|
|
|
QApplication::sendEvent(graphicsWidget->widgetWebView(),&newEvent); |
|
|
|
return; |
|
|
|
} else { |
|
|
|
|
|
|
|
event->ignore(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
event->acceptProposedAction(); |
|
|
|
event->acceptProposedAction(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QList<QUrl> UBBoardView::processMimeData(const QMimeData* pMimeData) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QList<QUrl> result; |
|
|
|
|
|
|
|
if(pMimeData->hasHtml()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QString qsHtml = pMimeData->html(); |
|
|
|
|
|
|
|
result.append(QUrl(UBApplication::urlFromHtml(qsHtml))); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (pMimeData->hasUrls()) |
|
|
|
QString UBBoardView::processMimeData(const QMimeData *pMimeData, UBGraphicsWidgetItem *widget) |
|
|
|
{ |
|
|
|
{ |
|
|
|
result.append(pMimeData->urls()); |
|
|
|
QString mimeXml; |
|
|
|
return result; |
|
|
|
QXmlStreamWriter writer(&mimeXml); |
|
|
|
} |
|
|
|
writer.setAutoFormatting(true); |
|
|
|
|
|
|
|
writer.writeStartDocument(); |
|
|
|
|
|
|
|
writer.writeStartElement(tMainSection); |
|
|
|
|
|
|
|
|
|
|
|
if (pMimeData->hasImage()) |
|
|
|
if (pMimeData->hasUrls()) { |
|
|
|
{ |
|
|
|
QList<QUrl> urls = pMimeData->urls(); |
|
|
|
qWarning() << "Not supported yet"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (pMimeData->hasText()) |
|
|
|
QString ext = fileExtention(urls.at(0).toLocalFile()); |
|
|
|
{ |
|
|
|
if (ext.isNull()) { |
|
|
|
if("" != pMimeData->text()){ |
|
|
|
qDebug() << "unknown file type"; |
|
|
|
// Sometimes, it is possible to have an URL as text. we check here if it is the case
|
|
|
|
return QString(); |
|
|
|
QString qsTmp = pMimeData->text().remove(QRegExp("[\\0]")); |
|
|
|
|
|
|
|
if(qsTmp.startsWith("http")){ |
|
|
|
|
|
|
|
result.append(QUrl(qsTmp)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else{ |
|
|
|
QString fileType = typeForExtention(ext); |
|
|
|
qWarning() << "what to do with this : " << pMimeData->text(); |
|
|
|
if (fileType.isNull()) { |
|
|
|
//mActiveScene->addText(pMimeData->text(), pPos);
|
|
|
|
qDebug() << "unknown extention"; |
|
|
|
|
|
|
|
return QString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//writing type of element
|
|
|
|
|
|
|
|
writer.writeTextElement(tType, fileType); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString fileName = urls.at(0).toLocalFile(); |
|
|
|
|
|
|
|
QString destName = widget->downloadUrl(fileName, ext); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (destName.isNull()) { |
|
|
|
|
|
|
|
qDebug() << "error at creating destination folder"; |
|
|
|
|
|
|
|
return QString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//writing path to created object
|
|
|
|
|
|
|
|
writer.writeTextElement(tPath, destName); |
|
|
|
} |
|
|
|
} |
|
|
|
else{ |
|
|
|
|
|
|
|
#ifdef Q_WS_MACX |
|
|
|
writer.writeEndElement(); |
|
|
|
// With Safari, in 95% of the drops, the mime datas are hidden in Apple Web Archive pasteboard type.
|
|
|
|
writer.writeEndDocument(); |
|
|
|
// This is due to the way Safari is working so we have to dig into the pasteboard in order to retrieve
|
|
|
|
|
|
|
|
// the data.
|
|
|
|
return mimeXml; |
|
|
|
QString qsUrl = UBPlatformUtils::urlFromClipboard(); |
|
|
|
|
|
|
|
if("" != qsUrl){ |
|
|
|
|
|
|
|
// We finally got the url of the dropped ressource! Let's import it!
|
|
|
|
|
|
|
|
result.append(QUrl(qsUrl)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
QString UBBoardView::fileExtention(const QString &filename) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int pos = filename.lastIndexOf("."); |
|
|
|
|
|
|
|
if (pos != -1) |
|
|
|
|
|
|
|
return filename.right(filename.size() - pos); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return QString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
QString UBBoardView::typeForExtention(const QString &extention) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QString result = QString(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (audioExtentions.contains(extention)) { |
|
|
|
|
|
|
|
result = audioAlias; |
|
|
|
|
|
|
|
} else if (videoExtentions.contains(extention)) { |
|
|
|
|
|
|
|
result = videoAlias; |
|
|
|
|
|
|
|
} else if (imageExtentions.contains(extention)) { |
|
|
|
|
|
|
|
result = imageAlias; |
|
|
|
|
|
|
|
} else if (htmlExtentions.contains(extention)) { |
|
|
|
|
|
|
|
result = htmlAlias; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
bool UBBoardView::isDropableData(const QMimeData *pMimeData) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (pMimeData->hasUrls()) |
|
|
|
|
|
|
|
if (!typeForExtention(fileExtention(pMimeData->urls().at(0).toLocalFile())).isNull()) |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBBoardView::dropEvent (QDropEvent *event) |
|
|
|
void UBBoardView::dropEvent (QDropEvent *event) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -785,21 +833,18 @@ void UBBoardView::dropEvent (QDropEvent *event) |
|
|
|
QGraphicsItem* graphicsItemAtPos = itemAt(event->pos().x(),event->pos().y()); |
|
|
|
QGraphicsItem* graphicsItemAtPos = itemAt(event->pos().x(),event->pos().y()); |
|
|
|
UBGraphicsWidgetItem* graphicsWidget = dynamic_cast<UBGraphicsWidgetItem*>(graphicsItemAtPos); |
|
|
|
UBGraphicsWidgetItem* graphicsWidget = dynamic_cast<UBGraphicsWidgetItem*>(graphicsItemAtPos); |
|
|
|
|
|
|
|
|
|
|
|
bool acceptDrops(false); |
|
|
|
|
|
|
|
if (graphicsWidget) { |
|
|
|
|
|
|
|
acceptDrops = graphicsWidget->acceptDrops(); |
|
|
|
|
|
|
|
graphicsWidget->setAcceptDrops(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (graphicsWidget && graphicsWidget->acceptDrops()){ |
|
|
|
if (graphicsWidget && graphicsWidget->acceptDrops()){ |
|
|
|
// A new event is build to avoid problem related to different way to pass the mime type
|
|
|
|
// A new event is build to avoid problem related to different way to pass the mime type
|
|
|
|
// A parsing is done to try to provide a mimeType with only urls.
|
|
|
|
// A parsing is done to try to provide a mimeType with only urls.
|
|
|
|
QMimeData mimeData; |
|
|
|
QMimeData mimeData; |
|
|
|
mimeData.setData("Text",processMimeData(event->mimeData()).at(0).toString().toAscii()); |
|
|
|
QString str = processMimeData(event->mimeData(), graphicsWidget); |
|
|
|
|
|
|
|
mimeData.setData("text/plain", str.toAscii()); |
|
|
|
QPoint newPoint(graphicsWidget->mapFromScene(mapToScene(event->pos())).toPoint()); |
|
|
|
QPoint newPoint(graphicsWidget->mapFromScene(mapToScene(event->pos())).toPoint()); |
|
|
|
QDropEvent cleanedEvent(newPoint, event->dropAction(), &mimeData, event->mouseButtons(), event->keyboardModifiers()); |
|
|
|
QDropEvent cleanedEvent(newPoint, event->dropAction(), &mimeData, event->mouseButtons(), event->keyboardModifiers()); |
|
|
|
QApplication::sendEvent(graphicsWidget->widgetWebView(),&cleanedEvent); |
|
|
|
QApplication::sendEvent(graphicsWidget->widgetWebView(),&cleanedEvent); |
|
|
|
cleanedEvent.acceptProposedAction(); |
|
|
|
cleanedEvent.acceptProposedAction(); |
|
|
|
event->acceptProposedAction(); |
|
|
|
event->acceptProposedAction(); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if(!event->source() || dynamic_cast<UBThumbnailWidget *>(event->source()) || dynamic_cast<QWebView*>(event->source())) |
|
|
|
if(!event->source() || dynamic_cast<UBThumbnailWidget *>(event->source()) || dynamic_cast<QWebView*>(event->source())) |
|
|
|