diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index cae29ac5..61d3fd02 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -2105,7 +2105,6 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::graphicsWidgetToSvg(UBGraphicsWidget startFileUrl = widgetRootUrl.toString() + "/" + item->widgetWebView()->mainHtmlFileName(); mXmlWriter.writeAttribute("src", startFileUrl); - mXmlWriter.writeEndElement(); //iFrame //persists widget state diff --git a/src/api/UBWidgetUniboardAPI.cpp b/src/api/UBWidgetUniboardAPI.cpp index 02859033..c9df1375 100644 --- a/src/api/UBWidgetUniboardAPI.cpp +++ b/src/api/UBWidgetUniboardAPI.cpp @@ -439,7 +439,7 @@ void UBWidgetUniboardAPI::enableDropOnWidget() QString UBWidgetUniboardAPI::downloadUrl(const QString &objectUrl, const QString &extention) { QString result; - QUrl widgetUrl = mGraphicsWidget->widgetWebView()->widgetUrl(); + QUrl widgetUrl = mGraphicsWidget->getOwnFolder(); QString destFileName =widgetUrl.toLocalFile() + "/objects/" + QUuid::createUuid().toString() + extention; if (UBFileSystemUtils::copyFile(objectUrl, destFileName)) { diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 46ebf85b..72987070 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -871,9 +871,7 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString widgetUrl = expandWidgetToTempDir(pData); } - UBGraphicsWidgetItem* w3cWidgetItem = mActiveScene->addW3CWidget(widgetUrl, pPos); - - w3cWidgetItem->setSourceUrl(sourceUrl); + UBGraphicsWidgetItem *w3cWidgetItem = addW3cWidget(widgetUrl, pPos); if (isBackground) { @@ -1647,10 +1645,8 @@ void UBBoardController::updateBackgroundState() { newBackgroundStyle ="QWidget {background-color: #F1F1F1}"; } - } - void UBBoardController::stylusToolChanged(int tool) { if (UBPlatformUtils::hasVirtualKeyboard() && mPaletteManager->mKeyboardPalette) @@ -1784,6 +1780,34 @@ UBGraphicsAudioItem* UBBoardController::addAudio(const QUrl& pSourceUrl, bool st } +UBGraphicsWidgetItem *UBBoardController::addW3cWidget(const QUrl &pUrl, const QPointF &pos) +{ + UBGraphicsWidgetItem* w3cWidgetItem = 0; + + QUuid uuid = QUuid::createUuid(); + QUrl newUrl = pUrl; + + newUrl = QUrl::fromLocalFile(UBPersistenceManager::persistenceManager()->addGraphicsWidgteToDocument(mActiveDocument, pUrl.toLocalFile(), uuid)); + + w3cWidgetItem = mActiveScene->addW3CWidget(pUrl, pos); + + if (w3cWidgetItem) { + w3cWidgetItem->setUuid(uuid); + w3cWidgetItem->setOwnFolder(newUrl); + w3cWidgetItem->setSourceUrl(pUrl); + + QString struuid = UBStringUtils::toCanonicalUuid(uuid); + QString snapshotPath = mActiveDocument->persistencePath() + "/" + UBPersistenceManager::widgetDirectory + "/" + struuid + ".png"; + UBGraphicsWidgetItem *tmpItem = dynamic_cast(w3cWidgetItem); + if (tmpItem) + tmpItem->widgetWebView()->takeSnapshot().save(snapshotPath, "PNG"); + + } + + return 0; + + +} void UBBoardController::cut() { diff --git a/src/board/UBBoardController.h b/src/board/UBBoardController.h index 7d722152..a15e8add 100644 --- a/src/board/UBBoardController.h +++ b/src/board/UBBoardController.h @@ -200,6 +200,8 @@ class UBBoardController : public QObject void controlViewShown(); UBGraphicsVideoItem* addVideo(const QUrl& pUrl, bool startPlay, const QPointF& pos); UBGraphicsAudioItem* addAudio(const QUrl& pUrl, bool startPlay, const QPointF& pos); + UBGraphicsWidgetItem *addW3cWidget(const QUrl& pUrl, const QPointF& pos); + void cut(); void copy(); void paste(); diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index 9ac5d13a..34ec2e6f 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -987,7 +987,29 @@ QString UBPersistenceManager::addPdfFileToDocument(UBDocumentProxy* pDocumentPro return fileName; } +QString UBPersistenceManager::addGraphicsWidgteToDocument(UBDocumentProxy *pDocumentProxy, QString path, QUuid objectUuid) +{ + QFileInfo fi(path); + + if (!fi.exists() || !pDocumentProxy || objectUuid.isNull()) + return ""; + + QString widgetRootDir = path; + QString extension = QFileInfo(widgetRootDir).suffix(); + QString widgetTargetDir = pDocumentProxy->persistencePath() + "/" + widgetDirectory + "/" + objectUuid.toString() + "." + extension; + + if (!QFile::exists(widgetTargetDir)) { + QDir dir; + dir.mkpath(widgetTargetDir); + UBFileSystemUtils::copyDir(widgetRootDir, widgetTargetDir); + } + + if (!QFile::exists(widgetTargetDir)) + widgetTargetDir = QString(); + + return widgetTargetDir; +} void UBPersistenceManager::documentRepositoryChanged(const QString& path) diff --git a/src/core/UBPersistenceManager.h b/src/core/UBPersistenceManager.h index 74a3ab7c..3891f186 100644 --- a/src/core/UBPersistenceManager.h +++ b/src/core/UBPersistenceManager.h @@ -120,6 +120,7 @@ class UBPersistenceManager : public QObject virtual QString addAudioFileToDocument(UBDocumentProxy* pDocumentProxy, QString path, QUuid objectUuid); virtual QString addAudioFileToDocument(UBDocumentProxy* pDocumentProxy, QUrl sourceUrl, QByteArray pPayload, QUuid objectUuid); virtual QString addPdfFileToDocument(UBDocumentProxy* pDocumentProxy, QString path, QUuid objectUuid); + virtual QString addGraphicsWidgteToDocument(UBDocumentProxy *mDocumentProxy, QString path, QUuid objectUuid); bool mayHaveVideo(UBDocumentProxy* pDocumentProxy); bool mayHaveAudio(UBDocumentProxy* pDocumentProxy); diff --git a/src/domain/UBGraphicsWidgetItem.h b/src/domain/UBGraphicsWidgetItem.h index 6b79244a..62dd35d1 100644 --- a/src/domain/UBGraphicsWidgetItem.h +++ b/src/domain/UBGraphicsWidgetItem.h @@ -68,6 +68,9 @@ class UBGraphicsWidgetItem : public UBGraphicsProxyWidget void removeScript(); QString downloadUrl(const QString &fileUrl, const QString &extention); + virtual void setOwnFolder(const QUrl &newFolder) {ownFolder = newFolder;} + virtual QUrl getOwnFolder() const {return ownFolder;} + virtual void clearSource(){;} @@ -91,6 +94,7 @@ class UBGraphicsWidgetItem : public UBGraphicsProxyWidget QPointF mLastMousePos; bool mShouldMoveWidget; UBWidgetUniboardAPI* mUniboardAPI; + QUrl ownFolder; }; class UBGraphicsAppleWidgetItem : public UBGraphicsWidgetItem