From 66db92929071c6fd3dd7260bdb31686e663a2581 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Fri, 4 May 2012 21:07:28 +0200 Subject: [PATCH] add import for lessons pages --- src/adaptors/UBSvgSubsetAdaptor.cpp | 84 +++++++++++++++------ src/adaptors/UBSvgSubsetAdaptor.h | 13 +++- src/gui/UBTeacherGuideWidget.cpp | 100 +++++++++++++++++++------ src/gui/UBTeacherGuideWidget.h | 13 +++- src/gui/UBTeacherGuideWidgetsTools.cpp | 89 +++++++++++++++------- src/gui/UBTeacherGuideWidgetsTools.h | 11 ++- src/interfaces/IDataStorage.h | 8 ++ 7 files changed, 240 insertions(+), 78 deletions(-) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 86ade4c9..c9af3e92 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -53,6 +53,8 @@ #include "core/UBPersistenceManager.h" #include "core/UBApplication.h" +#include "interfaces/IDataStorage.h" + #include "pdf/PDFRenderer.h" #include "core/memcheck.h" @@ -68,6 +70,15 @@ const QString UBSvgSubsetAdaptor::sPixelUnit = "px"; const QString UBSvgSubsetAdaptor::sFontWeightPrefix = "font-weight:"; const QString UBSvgSubsetAdaptor::sFontStylePrefix = "font-style:"; const QString UBSvgSubsetAdaptor::sFormerUniboardDocumentNamespaceUri = "http://www.mnemis.com/uniboard"; +QMap UBSvgSubsetAdaptor::additionalElementToStore; + +// Why using such a string? +// Media file path are relative to the current document. So if we are reading the +// first page of a document the document path has not been updated. +// Concatenate relative media path with the old document path leads to mess +// This string is so used only for activeDocumentChanged signal +QString UBSvgSubsetAdaptor::sTeacherGuideNode = ""; + @@ -133,8 +144,7 @@ void UBSvgSubsetAdaptor::upgradeScene(UBDocumentProxy* proxy, const int pageInde QDomDocument UBSvgSubsetAdaptor::loadSceneDocument(UBDocumentProxy* proxy, const int pPageIndex) { - QString fileName = proxy->persistencePath() + - UBFileSystemUtils::digitFileFormat("/page%1.svg", pPageIndex + 1); + QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", UBApplication::boardController->pageFromSceneIndex(pPageIndex)); QFile file(fileName); QDomDocument doc("page"); @@ -157,8 +167,7 @@ QDomDocument UBSvgSubsetAdaptor::loadSceneDocument(UBDocumentProxy* proxy, const void UBSvgSubsetAdaptor::setSceneUuid(UBDocumentProxy* proxy, const int pageIndex, QUuid pUuid) { - QString fileName = proxy->persistencePath() + - UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex + 1); + QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", UBApplication::boardController->pageFromSceneIndex(pageIndex)); QFile file(fileName); @@ -207,6 +216,16 @@ void UBSvgSubsetAdaptor::setSceneUuid(UBDocumentProxy* proxy, const int pageInde } } +bool UBSvgSubsetAdaptor::addElementToBeStored(QString domName, IDataStorage *dataStorageClass) +{ + if(domName.isEmpty() || additionalElementToStore.contains(domName)){ + qWarning() << "Error adding the element that should persist"; + return false; + } + + additionalElementToStore.insert(domName,dataStorageClass); + return true; +} QString UBSvgSubsetAdaptor::uniboardDocumentNamespaceUriFromVersion(int mFileVersion) { @@ -216,8 +235,7 @@ QString UBSvgSubsetAdaptor::uniboardDocumentNamespaceUriFromVersion(int mFileVer UBGraphicsScene* UBSvgSubsetAdaptor::loadScene(UBDocumentProxy* proxy, const int pageIndex) { - QString fileName = proxy->persistencePath() + - UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex + 1); + QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", UBApplication::boardController->pageFromSceneIndex(pageIndex)); QFile file(fileName); @@ -243,7 +261,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::loadScene(UBDocumentProxy* proxy, const int QUuid UBSvgSubsetAdaptor::sceneUuid(UBDocumentProxy* proxy, const int pageIndex) { QString fileName = proxy->persistencePath() + - UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex + 1); + UBFileSystemUtils::digitFileFormat("/page%1.svg", UBApplication::boardController->pageFromSceneIndex(pageIndex)); QFile file(fileName); @@ -429,13 +447,13 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() else if (mXmlReader.name() == "g") { // Create new stroke, if its NULL or already has polygons - if (annotationGroup) - { - if (!annotationGroup->polygons().empty()) - annotationGroup = new UBGraphicsStroke(); - } - else - annotationGroup = new UBGraphicsStroke(); + if (annotationGroup) + { + if (!annotationGroup->polygons().empty()) + annotationGroup = new UBGraphicsStroke(); + } + else + annotationGroup = new UBGraphicsStroke(); if(eDrawingMode_Vector == dc->drawingMode()){ strokesGroup = new UBGraphicsStrokesGroup(); @@ -709,7 +727,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() UBGraphicsItem::assignZValue(triangle, zFromSvg); } } - else if(mXmlReader.name() == "cache") + else if (mXmlReader.name() == "cache") { UBGraphicsCache* cache = cacheFromSvg(); if(cache) @@ -830,6 +848,18 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() currentWidget->setDatastoreEntry(key, value); } + else if (mXmlReader.name() == "teacherBar" || mXmlReader.name() == "teacherGuide"){ + sTeacherGuideNode.clear(); + sTeacherGuideNode += ""; + sTeacherGuideNode += "\n"; + } + else if (mXmlReader.name() == "media" || mXmlReader.name() == "link" || mXmlReader.name() == "title" || mXmlReader.name() == "comment" || mXmlReader.name() == "action") + { + sTeacherGuideNode += "<" + mXmlReader.name().toString() + " "; + foreach(QXmlStreamAttribute attribute, mXmlReader.attributes()) + sTeacherGuideNode += attribute.name().toString() + "=\"" + attribute.value().toString() + "\" "; + sTeacherGuideNode += " />\n"; + } else { // NOOP @@ -844,15 +874,23 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() //graphicsItemFromSvg(strokesGroup); } - if (annotationGroup) - { - if (!annotationGroup->polygons().empty()) - annotationGroup = 0; - } + if (annotationGroup) + { + if (!annotationGroup->polygons().empty()) + annotationGroup = 0; + } mGroupHasInfo = false; mGroupDarkBackgroundColor = QColor(); mGroupLightBackgroundColor = QColor(); } + else if (mXmlReader.name() == "teacherBar" || mXmlReader.name() == "teacherGuide"){ + sTeacherGuideNode += ""; + QMap elements = getAdditionalElementToStore(); + IDataStorage* storageClass = elements.value("teacherGuide"); + if(storageClass){ + storageClass->load(sTeacherGuideNode); + } + } } } @@ -1152,7 +1190,7 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene() } mXmlWriter.writeEndDocument(); - QString fileName = mDocumentPath + UBFileSystemUtils::digitFileFormat("/page%1.svg", mPageIndex + 1); + QString fileName = mDocumentPath + UBFileSystemUtils::digitFileFormat("/page%1.svg", UBApplication::boardController->pageFromSceneIndex(mPageIndex)); QFile file(fileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) @@ -1167,7 +1205,7 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene() } else { - qDebug() << "ignoring unmodified page" << mPageIndex + 1; + qDebug() << "ignoring unmodified page" << UBApplication::boardController->pageFromSceneIndex(mPageIndex); } return true; @@ -2504,7 +2542,7 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::curtainItemToSvg(UBGraphicsCurtainIt mXmlWriter.writeAttribute("width", QString("%1").arg(curtainItem->boundingRect().width())); mXmlWriter.writeAttribute("height", QString("%1").arg(curtainItem->boundingRect().height())); mXmlWriter.writeAttribute("transform", toSvgTransform(curtainItem->sceneMatrix())); - + //graphicsItemToSvg(curtainItem); QString zs; zs.setNum(curtainItem->zValue(), 'f'); // 'f' keeps precision diff --git a/src/adaptors/UBSvgSubsetAdaptor.h b/src/adaptors/UBSvgSubsetAdaptor.h index 188bba2f..37eacb07 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.h +++ b/src/adaptors/UBSvgSubsetAdaptor.h @@ -41,6 +41,7 @@ class UBGraphicsStroke; class UBPersistenceManager; class UBGraphicsTriangle; class UBGraphicsCache; +class IDataStorage; class UBSvgSubsetAdaptor { @@ -58,9 +59,14 @@ class UBSvgSubsetAdaptor static QUuid sceneUuid(UBDocumentProxy* proxy, const int pageIndex); static void setSceneUuid(UBDocumentProxy* proxy, const int pageIndex, QUuid pUuid); + static bool addElementToBeStored(QString domName,IDataStorage* dataStorageClass); + static void convertPDFObjectsToImages(UBDocumentProxy* proxy); static void convertSvgImagesToImages(UBDocumentProxy* proxy); + static QMap getAdditionalElementToStore() { return additionalElementToStore;} + static QString sTeacherGuideNode; + static const QString nsSvg; static const QString nsXLink; static const QString nsXHtml; @@ -86,6 +92,9 @@ class UBSvgSubsetAdaptor static QString toSvgTransform(const QMatrix& matrix); static QMatrix fromSvgTransform(const QString& transform); + static QMap additionalElementToStore; + + class UBSvgSubsetReader { public: @@ -188,9 +197,9 @@ class UBSvgSubsetAdaptor QLocale loc(QLocale::C); sBuf = sBuf.arg(loc.toFloat(temp1)).arg(loc.toFloat(temp2)); - + svgPoints.insert(length, sBuf); - length += sBuf.length(); + length += sBuf.length(); } return svgPoints; } diff --git a/src/gui/UBTeacherGuideWidget.cpp b/src/gui/UBTeacherGuideWidget.cpp index a5ce6280..51c4017d 100644 --- a/src/gui/UBTeacherGuideWidget.cpp +++ b/src/gui/UBTeacherGuideWidget.cpp @@ -23,6 +23,8 @@ #include "UBTeacherGuideWidget.h" +#include "adaptors/UBSvgSubsetAdaptor.h" + #include "core/UBApplication.h" #include "core/UBPersistenceManager.h" #include "core/UBSettings.h" @@ -79,10 +81,12 @@ UBTeacherGuideEditionWidget::UBTeacherGuideEditionWidget(QWidget *parent, const mpPageNumberLabel->setObjectName("UBTGPageNumberLabel"); mpLayout->addWidget(mpPageNumberLabel); // tree basic configuration - mpDocumentTitle = new QLabel(this); - mpDocumentTitle->setText("Document title"); - mpDocumentTitle->setObjectName("UBTGEditionDocumentTitle"); - mpLayout->addWidget(mpDocumentTitle); + + if(UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool()){ + mpDocumentTitle = new QLabel(this); + mpDocumentTitle->setObjectName("UBTGPresentationDocumentTitle"); + mpLayout->addWidget(mpDocumentTitle); + } mpPageTitle = new UBTGAdaptableText(0,this); mpPageTitle->setObjectName("UBTGEditionPageTitle"); @@ -124,6 +128,11 @@ UBTeacherGuideEditionWidget::UBTeacherGuideEditionWidget(QWidget *parent, const mpRootWidgetItem->addChild(mpAddAnActionItem); mpRootWidgetItem->addChild(mpAddAMediaItem); mpRootWidgetItem->addChild(mpAddALinkItem); + + if(UBSettings::settings()->teacherGuideLessonPagesActivated->get().toBool()){ + UBSvgSubsetAdaptor::addElementToBeStored(QString("teacherGuide"),this); + connect(UBApplication::boardController,SIGNAL(activeDocumentChanged()),this,SLOT(onActiveDocumentChanged())); + } } UBTeacherGuideEditionWidget::~UBTeacherGuideEditionWidget() @@ -142,16 +151,52 @@ UBTeacherGuideEditionWidget::~UBTeacherGuideEditionWidget() void UBTeacherGuideEditionWidget::showEvent(QShowEvent* event) { - mpPageTitle->setFocus(); - mpComment->setFocus(); +// mpPageTitle->setFocus(); +// mpComment->setFocus(); setFocus(); QWidget::showEvent(event); } -void UBTeacherGuideEditionWidget::onActiveSceneChanged() +void UBTeacherGuideEditionWidget::onActiveDocumentChanged() +{ + load(UBSvgSubsetAdaptor::sTeacherGuideNode); +} + +void UBTeacherGuideEditionWidget::load(QString element) { cleanData(); + QDomDocument doc("TeacherGuide"); + doc.setContent(element); + + for(QDomElement element = doc.documentElement().firstChildElement(); !element.isNull(); element = element.nextSiblingElement()) { + QString tagName = element.tagName(); + if(tagName == "title") + mpPageTitle->setInitialText(element.attribute("value")); + else if(tagName == "comment") + mpComment->setInitialText(element.attribute("value")); + else if(tagName == "media") + onAddItemClicked(mpAddAMediaItem,0,&element); + else if(tagName == "link") + onAddItemClicked(mpAddALinkItem,0,&element); + else if(tagName == "action") + onAddItemClicked(mpAddAnActionItem,0,&element); + } +} + + + +QDomElement* UBTeacherGuideEditionWidget::save(QDomElement* parentElement) +{ + qDebug() << parentElement; + return 0; +} + +void UBTeacherGuideEditionWidget::onActiveSceneChanged() +{ mpPageNumberLabel->setText(tr("Page: %0").arg(UBApplication::boardController->currentPage())); + UBDocumentProxy* documentProxy = UBApplication::boardController->activeDocument(); + if(mpDocumentTitle) + mpDocumentTitle->setText(documentProxy->metaData(UBSettings::sessionTitle).toString()); } void UBTeacherGuideEditionWidget::cleanData() @@ -165,7 +210,6 @@ void UBTeacherGuideEditionWidget::cleanData() foreach(QTreeWidgetItem* item, children){ DELETEPTR(item); } - } QList UBTeacherGuideEditionWidget::getChildrenList(QTreeWidgetItem* widgetItem) @@ -206,7 +250,7 @@ QVector UBTeacherGuideEditionWidget::getData() return result; } -void UBTeacherGuideEditionWidget::onAddItemClicked(QTreeWidgetItem* widget, int column) +void UBTeacherGuideEditionWidget::onAddItemClicked(QTreeWidgetItem* widget, int column, QDomElement *element) { int addSubItemWidgetType = widget->data(column,Qt::UserRole).toInt(); if(addSubItemWidgetType != eUBTGAddSubItemWidgetType_None){ @@ -217,15 +261,24 @@ void UBTeacherGuideEditionWidget::onAddItemClicked(QTreeWidgetItem* widget, int switch(addSubItemWidgetType) { - case eUBTGAddSubItemWidgetType_Action: - mpTreeWidget->setItemWidget(newWidgetItem,0,new UBTGActionWidget(widget)); + case eUBTGAddSubItemWidgetType_Action:{ + UBTGActionWidget* actionWidget = new UBTGActionWidget(widget); + if(element) actionWidget->initializeWithDom(*element); + mpTreeWidget->setItemWidget(newWidgetItem,0,actionWidget); break; - case eUBTGAddSubItemWidgetType_Media: - mpTreeWidget->setItemWidget(newWidgetItem,0,new UBTGMediaWidget(widget)); + } + case eUBTGAddSubItemWidgetType_Media:{ + UBTGMediaWidget* mediaWidget = new UBTGMediaWidget(widget); + if(element) mediaWidget->initializeWithDom(*element); + mpTreeWidget->setItemWidget(newWidgetItem,0,mediaWidget); break; - case eUBTGAddSubItemWidgetType_Url: - mpTreeWidget->setItemWidget(newWidgetItem,0,new UBTGUrlWidget()); + } + case eUBTGAddSubItemWidgetType_Url:{ + UBTGUrlWidget* urlWidget = new UBTGUrlWidget(); + if(element) urlWidget->initializeWithDom(*element); + mpTreeWidget->setItemWidget(newWidgetItem,0,urlWidget); break; + } default: delete newWidgetItem; qCritical() << "onAddItemClicked no action set"; @@ -296,13 +349,13 @@ UBTeacherGuidePresentationWidget::UBTeacherGuidePresentationWidget(QWidget *pare mpModePushButton->installEventFilter(this); connect(mpModePushButton,SIGNAL(clicked()),parentWidget(),SLOT(changeMode())); - - mpDocumentTitle = new QLabel(this); - mpDocumentTitle->setObjectName("UBTGPresentationDocumentTitle"); - mpDocumentTitle->setText(tr("Document title")); - mpButtonTitleLayout->addWidget(mpModePushButton); - mpButtonTitleLayout->addWidget(mpDocumentTitle); + + if(UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool()){ + mpDocumentTitle = new QLabel(this); + mpDocumentTitle->setObjectName("UBTGPresentationDocumentTitle"); + mpButtonTitleLayout->addWidget(mpDocumentTitle); + } mpLayout->addLayout(mpButtonTitleLayout); @@ -376,14 +429,15 @@ void UBTeacherGuidePresentationWidget::onActiveSceneChanged() { cleanData(); mpPageNumberLabel->setText(tr("Page: %0").arg(UBApplication::boardController->currentPage())); + UBDocumentProxy* documentProxy = UBApplication::boardController->activeDocument(); + if(mpDocumentTitle) + mpDocumentTitle->setText(documentProxy->metaData(UBSettings::sessionTitle).toString()); } void UBTeacherGuidePresentationWidget::createMediaButtonItem() { if(!mpMediaSwitchItem){ - //create the media button mpMediaSwitchItem = new QTreeWidgetItem(mpRootWidgetItem); - //mpMediaSwitchItem->setIcon(0,QIcon(":images/plus.svg")); mpMediaSwitchItem->setText(0,"+"); mpMediaSwitchItem->setExpanded(false); mpMediaSwitchItem->setData(0,tUBTGTreeWidgetItemRole_HasAnAction,tUBTGActionAssociateOnClickItem_EXPAND); diff --git a/src/gui/UBTeacherGuideWidget.h b/src/gui/UBTeacherGuideWidget.h index 9f67440c..bd43b8b2 100644 --- a/src/gui/UBTeacherGuideWidget.h +++ b/src/gui/UBTeacherGuideWidget.h @@ -23,8 +23,11 @@ class QVBoxLayout; class QPushButton; class UBDocumentProxy; + #include "UBTeacherGuideWidgetsTools.h" +#include "interfaces/IDataStorage.h" + typedef enum { tUBTGZeroPageMode_EDITION, @@ -34,7 +37,7 @@ typedef enum /*************************************************************************** * class UBTeacherGuideEditionWidget * ***************************************************************************/ -class UBTeacherGuideEditionWidget : public QWidget +class UBTeacherGuideEditionWidget : public QWidget , public IDataStorage { Q_OBJECT public: @@ -43,8 +46,11 @@ public: void cleanData(); QVector getData(); + void load(QString element); + QDomElement* save(QDomElement* parentElement); + public slots: - void onAddItemClicked(QTreeWidgetItem* widget, int column); + void onAddItemClicked(QTreeWidgetItem* widget, int column, QDomElement* element = 0); void onActiveSceneChanged(); void showEvent(QShowEvent* event); @@ -64,6 +70,9 @@ private: UBAddItem* mpAddAMediaItem; UBAddItem* mpAddALinkItem; +private slots: + void onActiveDocumentChanged(); + }; diff --git a/src/gui/UBTeacherGuideWidgetsTools.cpp b/src/gui/UBTeacherGuideWidgetsTools.cpp index 2083b1d2..e5c6d657 100644 --- a/src/gui/UBTeacherGuideWidgetsTools.cpp +++ b/src/gui/UBTeacherGuideWidgetsTools.cpp @@ -26,6 +26,9 @@ #include "UBTeacherGuideWidgetsTools.h" #include "core/UBPersistenceManager.h" +#include "core/UBApplication.h" + +#include "board/UBBoardController.h" #include "domain/UBW3CWidget.h" @@ -87,6 +90,11 @@ UBTGActionWidget::~UBTGActionWidget() DELETEPTR(mpLayout); } +void UBTGActionWidget::initializeWithDom(QDomElement element) +{ + mpOwner->setCurrentIndex(element.attribute("owner").toInt()); + mpTask->setInitialText(element.attribute("task")); +} tUBGEElementNode* UBTGActionWidget::saveData() { @@ -195,6 +203,12 @@ void UBTGAdaptableText::onTextChanged() } mIsUpdatingSize = false; } +void UBTGAdaptableText::setInitialText(const QString& text) +{ + setText(text); + setReadOnly(false); + onTextChanged(); +} void UBTGAdaptableText::showText(const QString & text) { @@ -266,8 +280,9 @@ UBTGMediaWidget::UBTGMediaWidget(QTreeWidgetItem* widget, QWidget* parent,const , mpMediaLabelWidget(NULL) , mpMediaWidget(NULL) , mpWebView(NULL) - , mRelativePath(QString("")) + , mMediaPath(QString("")) , mIsPresentationMode(false) + , mIsInitializationMode(false) { setObjectName(name); mpDropMeWidget = new QLabel(); @@ -280,7 +295,7 @@ UBTGMediaWidget::UBTGMediaWidget(QTreeWidgetItem* widget, QWidget* parent,const setMinimumHeight(250); } -UBTGMediaWidget::UBTGMediaWidget(QString relativePath, QTreeWidgetItem* widget, QWidget* parent,const char* name): QStackedWidget(parent) +UBTGMediaWidget::UBTGMediaWidget(QString mediaPath, QTreeWidgetItem* widget, QWidget* parent,const char* name): QStackedWidget(parent) , mpTreeWidgetItem(widget) , mpDropMeWidget(NULL) , mpWorkWidget(NULL) @@ -289,13 +304,14 @@ UBTGMediaWidget::UBTGMediaWidget(QString relativePath, QTreeWidgetItem* widget, , mpMediaLabelWidget(NULL) , mpMediaWidget(NULL) , mpWebView(NULL) - , mRelativePath(relativePath) + , mMediaPath(mediaPath) , mIsPresentationMode(true) , mMediaType("") + , mIsInitializationMode(false) { setObjectName(name); setAcceptDrops(false); - createWorkWidget(mRelativePath); + createWorkWidget(); setFixedHeight(200); } @@ -313,6 +329,17 @@ UBTGMediaWidget::~UBTGMediaWidget() DELETEPTR(mpWorkWidget); } +void UBTGMediaWidget::initializeWithDom(QDomElement element) +{ + mIsInitializationMode = true; + setAcceptDrops(false); + mMediaPath = UBApplication::boardController->activeDocument()->persistencePath() + "/" + element.attribute("relativePath"); + createWorkWidget(); + setFixedHeight(200); + mpTitle->setInitialText(element.attribute("title")); + mIsInitializationMode = false; +} + void UBTGMediaWidget::hideEvent(QHideEvent* event) { if(mpWebView) @@ -323,10 +350,8 @@ void UBTGMediaWidget::hideEvent(QHideEvent* event) void UBTGMediaWidget::showEvent(QShowEvent* event) { QWidget::showEvent(event); - if(mpWebView){ - qDebug() << mRelativePath; - mpWebView->load(QUrl(mRelativePath + "/index.htm")); - } + if(mpWebView) + mpWebView->load(QUrl(mMediaPath + "/index.htm")); } tUBGEElementNode* UBTGMediaWidget::saveData() @@ -336,7 +361,7 @@ tUBGEElementNode* UBTGMediaWidget::saveData() tUBGEElementNode* result = new tUBGEElementNode(); result->type = "media"; result->attributes.insert("title",mpTitle->text()); - result->attributes.insert("relativePath",mRelativePath); + result->attributes.insert("relativePath",mMediaPath); result->attributes.insert("mediaType",mMediaType); return result; } @@ -346,31 +371,40 @@ void UBTGMediaWidget::dragEnterEvent(QDragEnterEvent *event) event->accept(); } -void UBTGMediaWidget::createWorkWidget(QString& path) +void UBTGMediaWidget::createWorkWidget() { - QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(path); + QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(mMediaPath); bool setMedia = true; - mRelativePath = path; + UBDocumentProxy* proxyDocument = UBApplication::boardController->activeDocument(); if(mimeType.contains("audio") || mimeType.contains("video")){ mMediaType = mimeType.contains("audio")? "audio":"movie"; mpMediaWidget = new UBMediaWidget(mimeType.contains("audio")?eMediaType_Audio:eMediaType_Video); - mpMediaWidget->setFile(path); + if(mIsPresentationMode || mIsInitializationMode){ + mpMediaWidget->setFile(mMediaPath); + } + else{ + mMediaPath = UBPersistenceManager::persistenceManager()->addObjectToTeacherGuideDirectory(proxyDocument, mMediaPath); + mpMediaWidget->setFile(mMediaPath); + } } else if(mimeType.contains("image")){ mMediaType = "image"; + if(!(mIsPresentationMode || mIsInitializationMode)) + mMediaPath = UBPersistenceManager::persistenceManager()->addObjectToTeacherGuideDirectory(proxyDocument, mMediaPath); + mpMediaLabelWidget = new QLabel(); - QPixmap pixmap = QPixmap(QUrl(path).toLocalFile()); + QPixmap pixmap = QPixmap(mMediaPath); pixmap = pixmap.scaledToWidth(mpTreeWidgetItem->treeWidget()->size().width()); mpMediaLabelWidget->setPixmap(pixmap); mpMediaLabelWidget->setScaledContents(true); } else if(mimeType.contains("application")){ mMediaType = "w3c"; - if(!mIsPresentationMode){ - QDir baseW3CDirectory("/home/claudio"); - mRelativePath = UBW3CWidget::createNPAPIWrapperInDir(path,baseW3CDirectory,mimeType,QSize(100,100),"flashahaha"); + if(!(mIsPresentationMode || mIsInitializationMode)){ + QDir baseW3CDirectory(UBPersistenceManager::persistenceManager()->teacherGuideAbsoluteObjectPath(proxyDocument)); + mMediaPath = UBW3CWidget::createNPAPIWrapperInDir(mMediaPath,baseW3CDirectory,mimeType,QSize(100,100),QUuid::createUuid()); } - mpWebView = new UBDraggableWeb(mRelativePath); + mpWebView = new UBDraggableWeb(mMediaPath); mpWebView->setAcceptDrops(false); mpWebView->settings()->setAttribute(QWebSettings::JavaEnabled, true); mpWebView->settings()->setAttribute(QWebSettings::PluginsEnabled, true); @@ -380,7 +414,7 @@ void UBTGMediaWidget::createWorkWidget(QString& path) mpWebView->settings()->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true); mpWebView->settings()->setAttribute(QWebSettings::DnsPrefetchEnabled, true); - mpWebView->load(QUrl(mRelativePath+"/index.htm")); + mpWebView->load(QUrl(mMediaPath+"/index.htm")); } else{ qDebug() << "createWorkWidget mime type not handled" << mimeType; @@ -420,13 +454,12 @@ void UBTGMediaWidget::createWorkWidget(QString& path) void UBTGMediaWidget::parseMimeData(const QMimeData* pMimeData) { - QString path; if(pMimeData){ if(pMimeData->hasText()){ - path = QUrl::fromLocalFile(pMimeData->text()).toString(); + mMediaPath = QUrl::fromLocalFile(pMimeData->text()).toString(); } else if(pMimeData->hasUrls()){ - path = pMimeData->urls().at(0).toString(); + mMediaPath = pMimeData->urls().at(0).toString(); } else if(pMimeData->hasImage()){ qDebug() << "Not yet implemented"; @@ -435,7 +468,7 @@ void UBTGMediaWidget::parseMimeData(const QMimeData* pMimeData) else qDebug() << "No mime data present"; - createWorkWidget(path); + createWorkWidget(); } void UBTGMediaWidget::dropEvent(QDropEvent* event) @@ -451,9 +484,9 @@ void UBTGMediaWidget::mousePressEvent(QMouseEvent *event) else{ QDrag *drag = new QDrag(this); - QMimeData *mimeData = new QMimeData; + QMimeData *mimeData = new QMimeData(); QList urlList; - urlList << QUrl(mRelativePath); + urlList << QUrl(mMediaPath); mimeData->setUrls(urlList); drag->setMimeData(mimeData); @@ -490,6 +523,12 @@ UBTGUrlWidget::~UBTGUrlWidget() DELETEPTR(mpLayout); } +void UBTGUrlWidget::initializeWithDom(QDomElement element) +{ + mpTitle->setText(element.attribute("title")); + mpUrl->setText(element.attribute("url")); +} + tUBGEElementNode* UBTGUrlWidget::saveData() { tUBGEElementNode* result = new tUBGEElementNode(); diff --git a/src/gui/UBTeacherGuideWidgetsTools.h b/src/gui/UBTeacherGuideWidgetsTools.h index b21fa0e7..b15c2cfc 100644 --- a/src/gui/UBTeacherGuideWidgetsTools.h +++ b/src/gui/UBTeacherGuideWidgetsTools.h @@ -74,6 +74,7 @@ public: ~UBTGActionWidget(); void update(); tUBGEElementNode* saveData(); + void initializeWithDom(QDomElement element); private: QVBoxLayout* mpLayout; @@ -94,6 +95,7 @@ public: void bottomMargin(int newValue); void setPlaceHolderText(QString text); QString text(); + void setInitialText(const QString& text); public slots: void onTextChanged(); @@ -134,9 +136,10 @@ class UBTGMediaWidget : public QStackedWidget , public iUBTGSaveData Q_OBJECT public: UBTGMediaWidget(QTreeWidgetItem* widget = 0, QWidget* parent = 0, const char* name = "UBTGMediaWidget"); - UBTGMediaWidget(QString relativePath, QTreeWidgetItem* widget = 0, QWidget* parent = 0, const char* name = "UBTGMediaWidget"); + UBTGMediaWidget(QString mediaPath, QTreeWidgetItem* widget = 0, QWidget* parent = 0, const char* name = "UBTGMediaWidget"); ~UBTGMediaWidget(); tUBGEElementNode* saveData(); + void initializeWithDom(QDomElement element); protected: void dragEnterEvent(QDragEnterEvent* event); @@ -147,7 +150,7 @@ protected: private: void parseMimeData(const QMimeData* pMimeData); - void createWorkWidget(QString& path); + void createWorkWidget(); void updateSize(); QTreeWidgetItem* mpTreeWidgetItem; @@ -158,9 +161,10 @@ private: QLabel* mpMediaLabelWidget; UBMediaWidget* mpMediaWidget; UBDraggableWeb* mpWebView; - QString mRelativePath; + QString mMediaPath; bool mIsPresentationMode; QString mMediaType; + bool mIsInitializationMode; }; @@ -171,6 +175,7 @@ public: UBTGUrlWidget(QWidget* parent = 0, const char* name = "UBTGUrlWidget"); ~UBTGUrlWidget(); tUBGEElementNode* saveData(); + void initializeWithDom(QDomElement element); private: QVBoxLayout* mpLayout; QLineEdit* mpTitle; diff --git a/src/interfaces/IDataStorage.h b/src/interfaces/IDataStorage.h index c3795773..02695707 100644 --- a/src/interfaces/IDataStorage.h +++ b/src/interfaces/IDataStorage.h @@ -16,4 +16,12 @@ #ifndef IDATASTORAGE_H #define IDATASTORAGE_H +class QDomElement; + +class IDataStorage +{ +public: + virtual void load(QString element) = 0; + virtual QDomElement* save(QDomElement* parentElement) = 0 ; +}; #endif // IDATASTORAGE_H