add import for lessons pages

preferencesAboutTextFull
Claudio Valerio 13 years ago
parent 201bcc33dd
commit 66db929290
  1. 84
      src/adaptors/UBSvgSubsetAdaptor.cpp
  2. 13
      src/adaptors/UBSvgSubsetAdaptor.h
  3. 100
      src/gui/UBTeacherGuideWidget.cpp
  4. 13
      src/gui/UBTeacherGuideWidget.h
  5. 89
      src/gui/UBTeacherGuideWidgetsTools.cpp
  6. 11
      src/gui/UBTeacherGuideWidgetsTools.h
  7. 8
      src/interfaces/IDataStorage.h

@ -53,6 +53,8 @@
#include "core/UBPersistenceManager.h" #include "core/UBPersistenceManager.h"
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "interfaces/IDataStorage.h"
#include "pdf/PDFRenderer.h" #include "pdf/PDFRenderer.h"
#include "core/memcheck.h" #include "core/memcheck.h"
@ -68,6 +70,15 @@ const QString UBSvgSubsetAdaptor::sPixelUnit = "px";
const QString UBSvgSubsetAdaptor::sFontWeightPrefix = "font-weight:"; const QString UBSvgSubsetAdaptor::sFontWeightPrefix = "font-weight:";
const QString UBSvgSubsetAdaptor::sFontStylePrefix = "font-style:"; const QString UBSvgSubsetAdaptor::sFontStylePrefix = "font-style:";
const QString UBSvgSubsetAdaptor::sFormerUniboardDocumentNamespaceUri = "http://www.mnemis.com/uniboard"; const QString UBSvgSubsetAdaptor::sFormerUniboardDocumentNamespaceUri = "http://www.mnemis.com/uniboard";
QMap<QString,IDataStorage*> 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) QDomDocument UBSvgSubsetAdaptor::loadSceneDocument(UBDocumentProxy* proxy, const int pPageIndex)
{ {
QString fileName = proxy->persistencePath() + QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", UBApplication::boardController->pageFromSceneIndex(pPageIndex));
UBFileSystemUtils::digitFileFormat("/page%1.svg", pPageIndex + 1);
QFile file(fileName); QFile file(fileName);
QDomDocument doc("page"); QDomDocument doc("page");
@ -157,8 +167,7 @@ QDomDocument UBSvgSubsetAdaptor::loadSceneDocument(UBDocumentProxy* proxy, const
void UBSvgSubsetAdaptor::setSceneUuid(UBDocumentProxy* proxy, const int pageIndex, QUuid pUuid) void UBSvgSubsetAdaptor::setSceneUuid(UBDocumentProxy* proxy, const int pageIndex, QUuid pUuid)
{ {
QString fileName = proxy->persistencePath() + QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", UBApplication::boardController->pageFromSceneIndex(pageIndex));
UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex + 1);
QFile file(fileName); 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) QString UBSvgSubsetAdaptor::uniboardDocumentNamespaceUriFromVersion(int mFileVersion)
{ {
@ -216,8 +235,7 @@ QString UBSvgSubsetAdaptor::uniboardDocumentNamespaceUriFromVersion(int mFileVer
UBGraphicsScene* UBSvgSubsetAdaptor::loadScene(UBDocumentProxy* proxy, const int pageIndex) UBGraphicsScene* UBSvgSubsetAdaptor::loadScene(UBDocumentProxy* proxy, const int pageIndex)
{ {
QString fileName = proxy->persistencePath() + QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", UBApplication::boardController->pageFromSceneIndex(pageIndex));
UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex + 1);
QFile file(fileName); QFile file(fileName);
@ -243,7 +261,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::loadScene(UBDocumentProxy* proxy, const int
QUuid UBSvgSubsetAdaptor::sceneUuid(UBDocumentProxy* proxy, const int pageIndex) QUuid UBSvgSubsetAdaptor::sceneUuid(UBDocumentProxy* proxy, const int pageIndex)
{ {
QString fileName = proxy->persistencePath() + QString fileName = proxy->persistencePath() +
UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex + 1); UBFileSystemUtils::digitFileFormat("/page%1.svg", UBApplication::boardController->pageFromSceneIndex(pageIndex));
QFile file(fileName); QFile file(fileName);
@ -429,13 +447,13 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
else if (mXmlReader.name() == "g") else if (mXmlReader.name() == "g")
{ {
// Create new stroke, if its NULL or already has polygons // Create new stroke, if its NULL or already has polygons
if (annotationGroup) if (annotationGroup)
{ {
if (!annotationGroup->polygons().empty()) if (!annotationGroup->polygons().empty())
annotationGroup = new UBGraphicsStroke(); annotationGroup = new UBGraphicsStroke();
} }
else else
annotationGroup = new UBGraphicsStroke(); annotationGroup = new UBGraphicsStroke();
if(eDrawingMode_Vector == dc->drawingMode()){ if(eDrawingMode_Vector == dc->drawingMode()){
strokesGroup = new UBGraphicsStrokesGroup(); strokesGroup = new UBGraphicsStrokesGroup();
@ -709,7 +727,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
UBGraphicsItem::assignZValue(triangle, zFromSvg); UBGraphicsItem::assignZValue(triangle, zFromSvg);
} }
} }
else if(mXmlReader.name() == "cache") else if (mXmlReader.name() == "cache")
{ {
UBGraphicsCache* cache = cacheFromSvg(); UBGraphicsCache* cache = cacheFromSvg();
if(cache) if(cache)
@ -830,6 +848,18 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
currentWidget->setDatastoreEntry(key, value); currentWidget->setDatastoreEntry(key, value);
} }
else if (mXmlReader.name() == "teacherBar" || mXmlReader.name() == "teacherGuide"){
sTeacherGuideNode.clear();
sTeacherGuideNode += "<teacherGuide version=\"" + mXmlReader.attributes().value("version").toString() + "\">";
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 else
{ {
// NOOP // NOOP
@ -844,15 +874,23 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
//graphicsItemFromSvg(strokesGroup); //graphicsItemFromSvg(strokesGroup);
} }
if (annotationGroup) if (annotationGroup)
{ {
if (!annotationGroup->polygons().empty()) if (!annotationGroup->polygons().empty())
annotationGroup = 0; annotationGroup = 0;
} }
mGroupHasInfo = false; mGroupHasInfo = false;
mGroupDarkBackgroundColor = QColor(); mGroupDarkBackgroundColor = QColor();
mGroupLightBackgroundColor = QColor(); mGroupLightBackgroundColor = QColor();
} }
else if (mXmlReader.name() == "teacherBar" || mXmlReader.name() == "teacherGuide"){
sTeacherGuideNode += "</teacherGuide>";
QMap<QString,IDataStorage*> elements = getAdditionalElementToStore();
IDataStorage* storageClass = elements.value("teacherGuide");
if(storageClass){
storageClass->load(sTeacherGuideNode);
}
}
} }
} }
@ -1152,7 +1190,7 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene()
} }
mXmlWriter.writeEndDocument(); 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); QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
@ -1167,7 +1205,7 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene()
} }
else else
{ {
qDebug() << "ignoring unmodified page" << mPageIndex + 1; qDebug() << "ignoring unmodified page" << UBApplication::boardController->pageFromSceneIndex(mPageIndex);
} }
return true; return true;
@ -2504,7 +2542,7 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::curtainItemToSvg(UBGraphicsCurtainIt
mXmlWriter.writeAttribute("width", QString("%1").arg(curtainItem->boundingRect().width())); mXmlWriter.writeAttribute("width", QString("%1").arg(curtainItem->boundingRect().width()));
mXmlWriter.writeAttribute("height", QString("%1").arg(curtainItem->boundingRect().height())); mXmlWriter.writeAttribute("height", QString("%1").arg(curtainItem->boundingRect().height()));
mXmlWriter.writeAttribute("transform", toSvgTransform(curtainItem->sceneMatrix())); mXmlWriter.writeAttribute("transform", toSvgTransform(curtainItem->sceneMatrix()));
//graphicsItemToSvg(curtainItem); //graphicsItemToSvg(curtainItem);
QString zs; QString zs;
zs.setNum(curtainItem->zValue(), 'f'); // 'f' keeps precision zs.setNum(curtainItem->zValue(), 'f'); // 'f' keeps precision

@ -41,6 +41,7 @@ class UBGraphicsStroke;
class UBPersistenceManager; class UBPersistenceManager;
class UBGraphicsTriangle; class UBGraphicsTriangle;
class UBGraphicsCache; class UBGraphicsCache;
class IDataStorage;
class UBSvgSubsetAdaptor class UBSvgSubsetAdaptor
{ {
@ -58,9 +59,14 @@ class UBSvgSubsetAdaptor
static QUuid sceneUuid(UBDocumentProxy* proxy, const int pageIndex); static QUuid sceneUuid(UBDocumentProxy* proxy, const int pageIndex);
static void setSceneUuid(UBDocumentProxy* proxy, const int pageIndex, QUuid pUuid); static void setSceneUuid(UBDocumentProxy* proxy, const int pageIndex, QUuid pUuid);
static bool addElementToBeStored(QString domName,IDataStorage* dataStorageClass);
static void convertPDFObjectsToImages(UBDocumentProxy* proxy); static void convertPDFObjectsToImages(UBDocumentProxy* proxy);
static void convertSvgImagesToImages(UBDocumentProxy* proxy); static void convertSvgImagesToImages(UBDocumentProxy* proxy);
static QMap<QString,IDataStorage*> getAdditionalElementToStore() { return additionalElementToStore;}
static QString sTeacherGuideNode;
static const QString nsSvg; static const QString nsSvg;
static const QString nsXLink; static const QString nsXLink;
static const QString nsXHtml; static const QString nsXHtml;
@ -86,6 +92,9 @@ class UBSvgSubsetAdaptor
static QString toSvgTransform(const QMatrix& matrix); static QString toSvgTransform(const QMatrix& matrix);
static QMatrix fromSvgTransform(const QString& transform); static QMatrix fromSvgTransform(const QString& transform);
static QMap<QString,IDataStorage*> additionalElementToStore;
class UBSvgSubsetReader class UBSvgSubsetReader
{ {
public: public:
@ -188,9 +197,9 @@ class UBSvgSubsetAdaptor
QLocale loc(QLocale::C); QLocale loc(QLocale::C);
sBuf = sBuf.arg(loc.toFloat(temp1)).arg(loc.toFloat(temp2)); sBuf = sBuf.arg(loc.toFloat(temp1)).arg(loc.toFloat(temp2));
svgPoints.insert(length, sBuf); svgPoints.insert(length, sBuf);
length += sBuf.length(); length += sBuf.length();
} }
return svgPoints; return svgPoints;
} }

@ -23,6 +23,8 @@
#include "UBTeacherGuideWidget.h" #include "UBTeacherGuideWidget.h"
#include "adaptors/UBSvgSubsetAdaptor.h"
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "core/UBPersistenceManager.h" #include "core/UBPersistenceManager.h"
#include "core/UBSettings.h" #include "core/UBSettings.h"
@ -79,10 +81,12 @@ UBTeacherGuideEditionWidget::UBTeacherGuideEditionWidget(QWidget *parent, const
mpPageNumberLabel->setObjectName("UBTGPageNumberLabel"); mpPageNumberLabel->setObjectName("UBTGPageNumberLabel");
mpLayout->addWidget(mpPageNumberLabel); mpLayout->addWidget(mpPageNumberLabel);
// tree basic configuration // tree basic configuration
mpDocumentTitle = new QLabel(this);
mpDocumentTitle->setText("Document title"); if(UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool()){
mpDocumentTitle->setObjectName("UBTGEditionDocumentTitle"); mpDocumentTitle = new QLabel(this);
mpLayout->addWidget(mpDocumentTitle); mpDocumentTitle->setObjectName("UBTGPresentationDocumentTitle");
mpLayout->addWidget(mpDocumentTitle);
}
mpPageTitle = new UBTGAdaptableText(0,this); mpPageTitle = new UBTGAdaptableText(0,this);
mpPageTitle->setObjectName("UBTGEditionPageTitle"); mpPageTitle->setObjectName("UBTGEditionPageTitle");
@ -124,6 +128,11 @@ UBTeacherGuideEditionWidget::UBTeacherGuideEditionWidget(QWidget *parent, const
mpRootWidgetItem->addChild(mpAddAnActionItem); mpRootWidgetItem->addChild(mpAddAnActionItem);
mpRootWidgetItem->addChild(mpAddAMediaItem); mpRootWidgetItem->addChild(mpAddAMediaItem);
mpRootWidgetItem->addChild(mpAddALinkItem); mpRootWidgetItem->addChild(mpAddALinkItem);
if(UBSettings::settings()->teacherGuideLessonPagesActivated->get().toBool()){
UBSvgSubsetAdaptor::addElementToBeStored(QString("teacherGuide"),this);
connect(UBApplication::boardController,SIGNAL(activeDocumentChanged()),this,SLOT(onActiveDocumentChanged()));
}
} }
UBTeacherGuideEditionWidget::~UBTeacherGuideEditionWidget() UBTeacherGuideEditionWidget::~UBTeacherGuideEditionWidget()
@ -142,16 +151,52 @@ UBTeacherGuideEditionWidget::~UBTeacherGuideEditionWidget()
void UBTeacherGuideEditionWidget::showEvent(QShowEvent* event) void UBTeacherGuideEditionWidget::showEvent(QShowEvent* event)
{ {
mpPageTitle->setFocus(); // mpPageTitle->setFocus();
mpComment->setFocus(); // mpComment->setFocus();
setFocus(); setFocus();
QWidget::showEvent(event); QWidget::showEvent(event);
} }
void UBTeacherGuideEditionWidget::onActiveSceneChanged() void UBTeacherGuideEditionWidget::onActiveDocumentChanged()
{
load(UBSvgSubsetAdaptor::sTeacherGuideNode);
}
void UBTeacherGuideEditionWidget::load(QString element)
{ {
cleanData(); 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())); 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() void UBTeacherGuideEditionWidget::cleanData()
@ -165,7 +210,6 @@ void UBTeacherGuideEditionWidget::cleanData()
foreach(QTreeWidgetItem* item, children){ foreach(QTreeWidgetItem* item, children){
DELETEPTR(item); DELETEPTR(item);
} }
} }
QList<QTreeWidgetItem*> UBTeacherGuideEditionWidget::getChildrenList(QTreeWidgetItem* widgetItem) QList<QTreeWidgetItem*> UBTeacherGuideEditionWidget::getChildrenList(QTreeWidgetItem* widgetItem)
@ -206,7 +250,7 @@ QVector<tUBGEElementNode*> UBTeacherGuideEditionWidget::getData()
return result; 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(); int addSubItemWidgetType = widget->data(column,Qt::UserRole).toInt();
if(addSubItemWidgetType != eUBTGAddSubItemWidgetType_None){ if(addSubItemWidgetType != eUBTGAddSubItemWidgetType_None){
@ -217,15 +261,24 @@ void UBTeacherGuideEditionWidget::onAddItemClicked(QTreeWidgetItem* widget, int
switch(addSubItemWidgetType) switch(addSubItemWidgetType)
{ {
case eUBTGAddSubItemWidgetType_Action: case eUBTGAddSubItemWidgetType_Action:{
mpTreeWidget->setItemWidget(newWidgetItem,0,new UBTGActionWidget(widget)); UBTGActionWidget* actionWidget = new UBTGActionWidget(widget);
if(element) actionWidget->initializeWithDom(*element);
mpTreeWidget->setItemWidget(newWidgetItem,0,actionWidget);
break; 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; 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; break;
}
default: default:
delete newWidgetItem; delete newWidgetItem;
qCritical() << "onAddItemClicked no action set"; qCritical() << "onAddItemClicked no action set";
@ -296,13 +349,13 @@ UBTeacherGuidePresentationWidget::UBTeacherGuidePresentationWidget(QWidget *pare
mpModePushButton->installEventFilter(this); mpModePushButton->installEventFilter(this);
connect(mpModePushButton,SIGNAL(clicked()),parentWidget(),SLOT(changeMode())); connect(mpModePushButton,SIGNAL(clicked()),parentWidget(),SLOT(changeMode()));
mpDocumentTitle = new QLabel(this);
mpDocumentTitle->setObjectName("UBTGPresentationDocumentTitle");
mpDocumentTitle->setText(tr("Document title"));
mpButtonTitleLayout->addWidget(mpModePushButton); 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); mpLayout->addLayout(mpButtonTitleLayout);
@ -376,14 +429,15 @@ void UBTeacherGuidePresentationWidget::onActiveSceneChanged()
{ {
cleanData(); cleanData();
mpPageNumberLabel->setText(tr("Page: %0").arg(UBApplication::boardController->currentPage())); 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() void UBTeacherGuidePresentationWidget::createMediaButtonItem()
{ {
if(!mpMediaSwitchItem){ if(!mpMediaSwitchItem){
//create the media button
mpMediaSwitchItem = new QTreeWidgetItem(mpRootWidgetItem); mpMediaSwitchItem = new QTreeWidgetItem(mpRootWidgetItem);
//mpMediaSwitchItem->setIcon(0,QIcon(":images/plus.svg"));
mpMediaSwitchItem->setText(0,"+"); mpMediaSwitchItem->setText(0,"+");
mpMediaSwitchItem->setExpanded(false); mpMediaSwitchItem->setExpanded(false);
mpMediaSwitchItem->setData(0,tUBTGTreeWidgetItemRole_HasAnAction,tUBTGActionAssociateOnClickItem_EXPAND); mpMediaSwitchItem->setData(0,tUBTGTreeWidgetItemRole_HasAnAction,tUBTGActionAssociateOnClickItem_EXPAND);

@ -23,8 +23,11 @@ class QVBoxLayout;
class QPushButton; class QPushButton;
class UBDocumentProxy; class UBDocumentProxy;
#include "UBTeacherGuideWidgetsTools.h" #include "UBTeacherGuideWidgetsTools.h"
#include "interfaces/IDataStorage.h"
typedef enum typedef enum
{ {
tUBTGZeroPageMode_EDITION, tUBTGZeroPageMode_EDITION,
@ -34,7 +37,7 @@ typedef enum
/*************************************************************************** /***************************************************************************
* class UBTeacherGuideEditionWidget * * class UBTeacherGuideEditionWidget *
***************************************************************************/ ***************************************************************************/
class UBTeacherGuideEditionWidget : public QWidget class UBTeacherGuideEditionWidget : public QWidget , public IDataStorage
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -43,8 +46,11 @@ public:
void cleanData(); void cleanData();
QVector<tUBGEElementNode*> getData(); QVector<tUBGEElementNode*> getData();
void load(QString element);
QDomElement* save(QDomElement* parentElement);
public slots: public slots:
void onAddItemClicked(QTreeWidgetItem* widget, int column); void onAddItemClicked(QTreeWidgetItem* widget, int column, QDomElement* element = 0);
void onActiveSceneChanged(); void onActiveSceneChanged();
void showEvent(QShowEvent* event); void showEvent(QShowEvent* event);
@ -64,6 +70,9 @@ private:
UBAddItem* mpAddAMediaItem; UBAddItem* mpAddAMediaItem;
UBAddItem* mpAddALinkItem; UBAddItem* mpAddALinkItem;
private slots:
void onActiveDocumentChanged();
}; };

@ -26,6 +26,9 @@
#include "UBTeacherGuideWidgetsTools.h" #include "UBTeacherGuideWidgetsTools.h"
#include "core/UBPersistenceManager.h" #include "core/UBPersistenceManager.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "domain/UBW3CWidget.h" #include "domain/UBW3CWidget.h"
@ -87,6 +90,11 @@ UBTGActionWidget::~UBTGActionWidget()
DELETEPTR(mpLayout); DELETEPTR(mpLayout);
} }
void UBTGActionWidget::initializeWithDom(QDomElement element)
{
mpOwner->setCurrentIndex(element.attribute("owner").toInt());
mpTask->setInitialText(element.attribute("task"));
}
tUBGEElementNode* UBTGActionWidget::saveData() tUBGEElementNode* UBTGActionWidget::saveData()
{ {
@ -195,6 +203,12 @@ void UBTGAdaptableText::onTextChanged()
} }
mIsUpdatingSize = false; mIsUpdatingSize = false;
} }
void UBTGAdaptableText::setInitialText(const QString& text)
{
setText(text);
setReadOnly(false);
onTextChanged();
}
void UBTGAdaptableText::showText(const QString & text) void UBTGAdaptableText::showText(const QString & text)
{ {
@ -266,8 +280,9 @@ UBTGMediaWidget::UBTGMediaWidget(QTreeWidgetItem* widget, QWidget* parent,const
, mpMediaLabelWidget(NULL) , mpMediaLabelWidget(NULL)
, mpMediaWidget(NULL) , mpMediaWidget(NULL)
, mpWebView(NULL) , mpWebView(NULL)
, mRelativePath(QString("")) , mMediaPath(QString(""))
, mIsPresentationMode(false) , mIsPresentationMode(false)
, mIsInitializationMode(false)
{ {
setObjectName(name); setObjectName(name);
mpDropMeWidget = new QLabel(); mpDropMeWidget = new QLabel();
@ -280,7 +295,7 @@ UBTGMediaWidget::UBTGMediaWidget(QTreeWidgetItem* widget, QWidget* parent,const
setMinimumHeight(250); 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) , mpTreeWidgetItem(widget)
, mpDropMeWidget(NULL) , mpDropMeWidget(NULL)
, mpWorkWidget(NULL) , mpWorkWidget(NULL)
@ -289,13 +304,14 @@ UBTGMediaWidget::UBTGMediaWidget(QString relativePath, QTreeWidgetItem* widget,
, mpMediaLabelWidget(NULL) , mpMediaLabelWidget(NULL)
, mpMediaWidget(NULL) , mpMediaWidget(NULL)
, mpWebView(NULL) , mpWebView(NULL)
, mRelativePath(relativePath) , mMediaPath(mediaPath)
, mIsPresentationMode(true) , mIsPresentationMode(true)
, mMediaType("") , mMediaType("")
, mIsInitializationMode(false)
{ {
setObjectName(name); setObjectName(name);
setAcceptDrops(false); setAcceptDrops(false);
createWorkWidget(mRelativePath); createWorkWidget();
setFixedHeight(200); setFixedHeight(200);
} }
@ -313,6 +329,17 @@ UBTGMediaWidget::~UBTGMediaWidget()
DELETEPTR(mpWorkWidget); 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) void UBTGMediaWidget::hideEvent(QHideEvent* event)
{ {
if(mpWebView) if(mpWebView)
@ -323,10 +350,8 @@ void UBTGMediaWidget::hideEvent(QHideEvent* event)
void UBTGMediaWidget::showEvent(QShowEvent* event) void UBTGMediaWidget::showEvent(QShowEvent* event)
{ {
QWidget::showEvent(event); QWidget::showEvent(event);
if(mpWebView){ if(mpWebView)
qDebug() << mRelativePath; mpWebView->load(QUrl(mMediaPath + "/index.htm"));
mpWebView->load(QUrl(mRelativePath + "/index.htm"));
}
} }
tUBGEElementNode* UBTGMediaWidget::saveData() tUBGEElementNode* UBTGMediaWidget::saveData()
@ -336,7 +361,7 @@ tUBGEElementNode* UBTGMediaWidget::saveData()
tUBGEElementNode* result = new tUBGEElementNode(); tUBGEElementNode* result = new tUBGEElementNode();
result->type = "media"; result->type = "media";
result->attributes.insert("title",mpTitle->text()); result->attributes.insert("title",mpTitle->text());
result->attributes.insert("relativePath",mRelativePath); result->attributes.insert("relativePath",mMediaPath);
result->attributes.insert("mediaType",mMediaType); result->attributes.insert("mediaType",mMediaType);
return result; return result;
} }
@ -346,31 +371,40 @@ void UBTGMediaWidget::dragEnterEvent(QDragEnterEvent *event)
event->accept(); event->accept();
} }
void UBTGMediaWidget::createWorkWidget(QString& path) void UBTGMediaWidget::createWorkWidget()
{ {
QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(path); QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(mMediaPath);
bool setMedia = true; bool setMedia = true;
mRelativePath = path; UBDocumentProxy* proxyDocument = UBApplication::boardController->activeDocument();
if(mimeType.contains("audio") || mimeType.contains("video")){ if(mimeType.contains("audio") || mimeType.contains("video")){
mMediaType = mimeType.contains("audio")? "audio":"movie"; mMediaType = mimeType.contains("audio")? "audio":"movie";
mpMediaWidget = new UBMediaWidget(mimeType.contains("audio")?eMediaType_Audio:eMediaType_Video); 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")){ else if(mimeType.contains("image")){
mMediaType = "image"; mMediaType = "image";
if(!(mIsPresentationMode || mIsInitializationMode))
mMediaPath = UBPersistenceManager::persistenceManager()->addObjectToTeacherGuideDirectory(proxyDocument, mMediaPath);
mpMediaLabelWidget = new QLabel(); mpMediaLabelWidget = new QLabel();
QPixmap pixmap = QPixmap(QUrl(path).toLocalFile()); QPixmap pixmap = QPixmap(mMediaPath);
pixmap = pixmap.scaledToWidth(mpTreeWidgetItem->treeWidget()->size().width()); pixmap = pixmap.scaledToWidth(mpTreeWidgetItem->treeWidget()->size().width());
mpMediaLabelWidget->setPixmap(pixmap); mpMediaLabelWidget->setPixmap(pixmap);
mpMediaLabelWidget->setScaledContents(true); mpMediaLabelWidget->setScaledContents(true);
} }
else if(mimeType.contains("application")){ else if(mimeType.contains("application")){
mMediaType = "w3c"; mMediaType = "w3c";
if(!mIsPresentationMode){ if(!(mIsPresentationMode || mIsInitializationMode)){
QDir baseW3CDirectory("/home/claudio"); QDir baseW3CDirectory(UBPersistenceManager::persistenceManager()->teacherGuideAbsoluteObjectPath(proxyDocument));
mRelativePath = UBW3CWidget::createNPAPIWrapperInDir(path,baseW3CDirectory,mimeType,QSize(100,100),"flashahaha"); mMediaPath = UBW3CWidget::createNPAPIWrapperInDir(mMediaPath,baseW3CDirectory,mimeType,QSize(100,100),QUuid::createUuid());
} }
mpWebView = new UBDraggableWeb(mRelativePath); mpWebView = new UBDraggableWeb(mMediaPath);
mpWebView->setAcceptDrops(false); mpWebView->setAcceptDrops(false);
mpWebView->settings()->setAttribute(QWebSettings::JavaEnabled, true); mpWebView->settings()->setAttribute(QWebSettings::JavaEnabled, true);
mpWebView->settings()->setAttribute(QWebSettings::PluginsEnabled, 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::JavascriptCanAccessClipboard, true);
mpWebView->settings()->setAttribute(QWebSettings::DnsPrefetchEnabled, true); mpWebView->settings()->setAttribute(QWebSettings::DnsPrefetchEnabled, true);
mpWebView->load(QUrl(mRelativePath+"/index.htm")); mpWebView->load(QUrl(mMediaPath+"/index.htm"));
} }
else{ else{
qDebug() << "createWorkWidget mime type not handled" << mimeType; qDebug() << "createWorkWidget mime type not handled" << mimeType;
@ -420,13 +454,12 @@ void UBTGMediaWidget::createWorkWidget(QString& path)
void UBTGMediaWidget::parseMimeData(const QMimeData* pMimeData) void UBTGMediaWidget::parseMimeData(const QMimeData* pMimeData)
{ {
QString path;
if(pMimeData){ if(pMimeData){
if(pMimeData->hasText()){ if(pMimeData->hasText()){
path = QUrl::fromLocalFile(pMimeData->text()).toString(); mMediaPath = QUrl::fromLocalFile(pMimeData->text()).toString();
} }
else if(pMimeData->hasUrls()){ else if(pMimeData->hasUrls()){
path = pMimeData->urls().at(0).toString(); mMediaPath = pMimeData->urls().at(0).toString();
} }
else if(pMimeData->hasImage()){ else if(pMimeData->hasImage()){
qDebug() << "Not yet implemented"; qDebug() << "Not yet implemented";
@ -435,7 +468,7 @@ void UBTGMediaWidget::parseMimeData(const QMimeData* pMimeData)
else else
qDebug() << "No mime data present"; qDebug() << "No mime data present";
createWorkWidget(path); createWorkWidget();
} }
void UBTGMediaWidget::dropEvent(QDropEvent* event) void UBTGMediaWidget::dropEvent(QDropEvent* event)
@ -451,9 +484,9 @@ void UBTGMediaWidget::mousePressEvent(QMouseEvent *event)
else{ else{
QDrag *drag = new QDrag(this); QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData; QMimeData *mimeData = new QMimeData();
QList<QUrl> urlList; QList<QUrl> urlList;
urlList << QUrl(mRelativePath); urlList << QUrl(mMediaPath);
mimeData->setUrls(urlList); mimeData->setUrls(urlList);
drag->setMimeData(mimeData); drag->setMimeData(mimeData);
@ -490,6 +523,12 @@ UBTGUrlWidget::~UBTGUrlWidget()
DELETEPTR(mpLayout); DELETEPTR(mpLayout);
} }
void UBTGUrlWidget::initializeWithDom(QDomElement element)
{
mpTitle->setText(element.attribute("title"));
mpUrl->setText(element.attribute("url"));
}
tUBGEElementNode* UBTGUrlWidget::saveData() tUBGEElementNode* UBTGUrlWidget::saveData()
{ {
tUBGEElementNode* result = new tUBGEElementNode(); tUBGEElementNode* result = new tUBGEElementNode();

@ -74,6 +74,7 @@ public:
~UBTGActionWidget(); ~UBTGActionWidget();
void update(); void update();
tUBGEElementNode* saveData(); tUBGEElementNode* saveData();
void initializeWithDom(QDomElement element);
private: private:
QVBoxLayout* mpLayout; QVBoxLayout* mpLayout;
@ -94,6 +95,7 @@ public:
void bottomMargin(int newValue); void bottomMargin(int newValue);
void setPlaceHolderText(QString text); void setPlaceHolderText(QString text);
QString text(); QString text();
void setInitialText(const QString& text);
public slots: public slots:
void onTextChanged(); void onTextChanged();
@ -134,9 +136,10 @@ class UBTGMediaWidget : public QStackedWidget , public iUBTGSaveData
Q_OBJECT Q_OBJECT
public: public:
UBTGMediaWidget(QTreeWidgetItem* widget = 0, QWidget* parent = 0, const char* name = "UBTGMediaWidget"); 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(); ~UBTGMediaWidget();
tUBGEElementNode* saveData(); tUBGEElementNode* saveData();
void initializeWithDom(QDomElement element);
protected: protected:
void dragEnterEvent(QDragEnterEvent* event); void dragEnterEvent(QDragEnterEvent* event);
@ -147,7 +150,7 @@ protected:
private: private:
void parseMimeData(const QMimeData* pMimeData); void parseMimeData(const QMimeData* pMimeData);
void createWorkWidget(QString& path); void createWorkWidget();
void updateSize(); void updateSize();
QTreeWidgetItem* mpTreeWidgetItem; QTreeWidgetItem* mpTreeWidgetItem;
@ -158,9 +161,10 @@ private:
QLabel* mpMediaLabelWidget; QLabel* mpMediaLabelWidget;
UBMediaWidget* mpMediaWidget; UBMediaWidget* mpMediaWidget;
UBDraggableWeb* mpWebView; UBDraggableWeb* mpWebView;
QString mRelativePath; QString mMediaPath;
bool mIsPresentationMode; bool mIsPresentationMode;
QString mMediaType; QString mMediaType;
bool mIsInitializationMode;
}; };
@ -171,6 +175,7 @@ public:
UBTGUrlWidget(QWidget* parent = 0, const char* name = "UBTGUrlWidget"); UBTGUrlWidget(QWidget* parent = 0, const char* name = "UBTGUrlWidget");
~UBTGUrlWidget(); ~UBTGUrlWidget();
tUBGEElementNode* saveData(); tUBGEElementNode* saveData();
void initializeWithDom(QDomElement element);
private: private:
QVBoxLayout* mpLayout; QVBoxLayout* mpLayout;
QLineEdit* mpTitle; QLineEdit* mpTitle;

@ -16,4 +16,12 @@
#ifndef IDATASTORAGE_H #ifndef IDATASTORAGE_H
#define 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 #endif // IDATASTORAGE_H

Loading…
Cancel
Save