From d15d5805f7fc3ddc2cf68f83f348ab283eb4e5af Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Thu, 26 Jul 2012 09:37:55 +0200 Subject: [PATCH] fixed issue 663 --- .../teacherGuide/indexingParameters.xml | 7 + src/adaptors/UBSvgSubsetAdaptor.cpp | 6 +- src/board/UBBoardController.cpp | 10 +- src/board/UBBoardPaletteManager.h | 2 + src/core/UBApplicationController.cpp | 4 +- src/core/UBPersistenceManager.cpp | 14 +- src/gui/UBDockTeacherGuideWidget.cpp | 5 + src/gui/UBDockTeacherGuideWidget.h | 2 + src/gui/UBTeacherGuideWidget.cpp | 494 ++++++++++-------- src/gui/UBTeacherGuideWidget.h | 5 + 10 files changed, 316 insertions(+), 233 deletions(-) diff --git a/resources/customizations/teacherGuide/indexingParameters.xml b/resources/customizations/teacherGuide/indexingParameters.xml index 09c4917a..2a194515 100644 --- a/resources/customizations/teacherGuide/indexingParameters.xml +++ b/resources/customizations/teacherGuide/indexingParameters.xml @@ -1,6 +1,7 @@ + @@ -22,6 +23,7 @@ + @@ -29,6 +31,7 @@ + @@ -50,6 +53,7 @@ + @@ -80,6 +84,7 @@ + @@ -125,6 +130,7 @@ + @@ -169,6 +175,7 @@ + diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index a56fd342..a9a325e8 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -45,6 +45,7 @@ #include "board/UBBoardView.h" #include "board/UBBoardController.h" #include "board/UBDrawingController.h" +#include "board/UBBoardPaletteManager.h" #include "frameworks/UBFileSystemUtils.h" #include "frameworks/UBStringUtils.h" @@ -54,6 +55,9 @@ #include "core/UBPersistenceManager.h" #include "core/UBApplication.h" +#include "gui/UBTeacherGuideWidget.h" +#include "gui/UBDockTeacherGuideWidget.h" + #include "interfaces/IDataStorage.h" #include "document/UBDocumentContainer.h" @@ -1142,7 +1146,7 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::writeSvgElement() bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex) { - if (mScene->isModified()) + if (mScene->isModified() || (UBApplication::boardController->paletteManager()->teacherGuideDockWidget() && UBApplication::boardController->paletteManager()->teacherGuideDockWidget()->teacherGuideWidget()->isModified())) { //Creating dom structure to store information diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index d7c333a7..db95ad67 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -38,6 +38,9 @@ #include "gui/UBToolWidget.h" #include "gui/UBKeyboardPalette.h" #include "gui/UBMagnifer.h" +#include "gui/UBDockPaletteWidget.h" +#include "gui/UBDockTeacherGuideWidget.h" +#include "gui/UBTeacherGuideWidget.h" #include "domain/UBGraphicsPixmapItem.h" #include "domain/UBGraphicsItemUndoCommand.h" @@ -1464,7 +1467,10 @@ void UBBoardController::lastWindowClosed() { if (!mCleanupDone) { - if (selectedDocument()->pageCount() == 1 && (!mActiveScene || mActiveScene->isEmpty())) + bool teacherGuideModified = false; + if(UBApplication::boardController->paletteManager()->teacherGuideDockWidget()) + teacherGuideModified = UBApplication::boardController->paletteManager()->teacherGuideDockWidget()->teacherGuideWidget()->isModified(); + if (selectedDocument()->pageCount() == 1 && (!mActiveScene || mActiveScene->isEmpty()) && !teacherGuideModified) { UBPersistenceManager::persistenceManager()->deleteDocument(selectedDocument()); } @@ -1591,7 +1597,7 @@ void UBBoardController::persistCurrentScene() if(UBPersistenceManager::persistenceManager() && selectedDocument() && mActiveScene && (mActiveSceneIndex >= 0) - && mActiveScene->isModified()) + && (mActiveScene->isModified() || (UBApplication::boardController->paletteManager()->teacherGuideDockWidget() && UBApplication::boardController->paletteManager()->teacherGuideDockWidget()->teacherGuideWidget()->isModified()))) { emit activeSceneWillBePersisted(); diff --git a/src/board/UBBoardPaletteManager.h b/src/board/UBBoardPaletteManager.h index 31f3dd92..b924a03a 100644 --- a/src/board/UBBoardPaletteManager.h +++ b/src/board/UBBoardPaletteManager.h @@ -69,6 +69,8 @@ class UBBoardPaletteManager : public QObject void setCurrentWebToolsPalette(UBWebToolsPalette *palette) {mWebToolsCurrentPalette = palette;} UBWebToolsPalette* mWebToolsCurrentPalette; + UBDockTeacherGuideWidget* teacherGuideDockWidget() { return mpTeacherGuideWidget;} + void processPalettersWidget(UBDockPalette *paletter, eUBDockPaletteWidgetMode mode); void changeMode(eUBDockPaletteWidgetMode newMode, bool isInit = false); void startDownloads(); diff --git a/src/core/UBApplicationController.cpp b/src/core/UBApplicationController.cpp index ad2a19ae..0598e490 100644 --- a/src/core/UBApplicationController.cpp +++ b/src/core/UBApplicationController.cpp @@ -40,6 +40,8 @@ #include "gui/UBScreenMirror.h" #include "gui/UBMainWindow.h" +#include "gui/UBDockTeacherGuideWidget.h" +#include "gui/UBTeacherGuideWidget.h" #include "domain/UBGraphicsPixmapItem.h" #include "domain/UBW3CWidget.h" @@ -419,7 +421,7 @@ void UBApplicationController::showDocument() if (UBApplication::boardController) { - if (UBApplication::boardController->activeScene()->isModified()) + if (UBApplication::boardController->activeScene()->isModified() || (UBApplication::boardController->paletteManager()->teacherGuideDockWidget() && UBApplication::boardController->paletteManager()->teacherGuideDockWidget()->teacherGuideWidget()->isModified())) UBApplication::boardController->persistCurrentScene(); UBApplication::boardController->hide(); } diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index a279ab4c..bc90fc52 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -25,6 +25,9 @@ #include "core/UBSettings.h" #include "core/UBSetting.h" +#include "gui/UBDockTeacherGuideWidget.h" +#include "gui/UBTeacherGuideWidget.h" + #include "document/UBDocumentProxy.h" #include "adaptors/UBExportPDF.h" @@ -33,6 +36,7 @@ #include "adaptors/UBMetadataDcSubsetAdaptor.h" #include "board/UBBoardController.h" +#include "board/UBBoardPaletteManager.h" #include "interfaces/IDataStorage.h" @@ -591,7 +595,6 @@ UBGraphicsScene* UBPersistenceManager::loadDocumentScene(UBDocumentProxy* proxy, } } - void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy, UBGraphicsScene* pScene, const int pSceneIndex) { checkIfDocumentRepositoryExists(); @@ -603,10 +606,15 @@ void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy, QDir dir(pDocumentProxy->persistencePath()); dir.mkpath(pDocumentProxy->persistencePath()); - if (pDocumentProxy->isModified()) + UBBoardPaletteManager* paletteManager = UBApplication::boardController->paletteManager(); + bool teacherGuideModified = false; + if(paletteManager->teacherGuideDockWidget()) + teacherGuideModified = paletteManager->teacherGuideDockWidget()->teacherGuideWidget()->isModified(); + + if (pDocumentProxy->isModified() || teacherGuideModified) UBMetadataDcSubsetAdaptor::persist(pDocumentProxy); - if (pScene->isModified()) + if (pScene->isModified() || teacherGuideModified) { UBSvgSubsetAdaptor::persistScene(pDocumentProxy, pScene, pSceneIndex); diff --git a/src/gui/UBDockTeacherGuideWidget.cpp b/src/gui/UBDockTeacherGuideWidget.cpp index 522d0052..cb84751b 100644 --- a/src/gui/UBDockTeacherGuideWidget.cpp +++ b/src/gui/UBDockTeacherGuideWidget.cpp @@ -44,3 +44,8 @@ UBDockTeacherGuideWidget::~UBDockTeacherGuideWidget() DELETEPTR(mpTeacherGuideWidget); DELETEPTR(mpLayout); } + +UBTeacherGuideWidget* UBDockTeacherGuideWidget::teacherGuideWidget() +{ + return mpTeacherGuideWidget; +} diff --git a/src/gui/UBDockTeacherGuideWidget.h b/src/gui/UBDockTeacherGuideWidget.h index 250b0381..8edea3ca 100644 --- a/src/gui/UBDockTeacherGuideWidget.h +++ b/src/gui/UBDockTeacherGuideWidget.h @@ -31,6 +31,8 @@ public: bool visibleInMode(eUBDockPaletteWidgetMode mode){ return mode == eUBDockPaletteWidget_BOARD; } + UBTeacherGuideWidget* teacherGuideWidget(); + private: QVBoxLayout* mpLayout; UBTeacherGuideWidget* mpTeacherGuideWidget; diff --git a/src/gui/UBTeacherGuideWidget.cpp b/src/gui/UBTeacherGuideWidget.cpp index 193a8dfa..3d5241fa 100644 --- a/src/gui/UBTeacherGuideWidget.cpp +++ b/src/gui/UBTeacherGuideWidget.cpp @@ -49,15 +49,12 @@ #define UBTG_SEPARATOR_FIXED_HEIGHT 3 -typedef enum -{ +typedef enum { eUBTGAddSubItemWidgetType_None, - eUBTGAddSubItemWidgetType_Action , + eUBTGAddSubItemWidgetType_Action, eUBTGAddSubItemWidgetType_Media, eUBTGAddSubItemWidgetType_Url -}eUBTGAddSubItemWidgetType; - - +} eUBTGAddSubItemWidgetType; /*************************************************************************** * class UBTeacherGuideEditionWidget * @@ -86,18 +83,18 @@ UBTeacherGuideEditionWidget::UBTeacherGuideEditionWidget(QWidget *parent, const mpLayout->addWidget(mpPageNumberLabel); // tree basic configuration - if(UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool()){ + if (UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool()) { mpDocumentTitle = new QLabel(this); mpDocumentTitle->setObjectName("UBTGPresentationDocumentTitle"); mpLayout->addWidget(mpDocumentTitle); } - mpPageTitle = new UBTGAdaptableText(0,this); + mpPageTitle = new UBTGAdaptableText(0, this); mpPageTitle->setObjectName("UBTGEditionPageTitle"); mpPageTitle->setPlaceHolderText(tr("Type title here ...")); mpLayout->addWidget(mpPageTitle); - mpComment = new UBTGAdaptableText(0,this); + mpComment = new UBTGAdaptableText(0, this); mpComment->setObjectName("UBTGEditionComment"); mpComment->setPlaceHolderText(tr("Type comment here ...")); mpLayout->addWidget(mpComment); @@ -122,20 +119,20 @@ UBTeacherGuideEditionWidget::UBTeacherGuideEditionWidget(QWidget *parent, const mpTreeWidget->header()->setResizeMode(1, QHeaderView::Fixed); mpTreeWidget->header()->setDefaultSectionSize(18); - connect(mpTreeWidget,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(onAddItemClicked(QTreeWidgetItem*,int))); - connect(UBApplication::boardController,SIGNAL(activeSceneChanged()),this,SLOT(onActiveSceneChanged())); + connect(mpTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(onAddItemClicked(QTreeWidgetItem*,int))); + connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(onActiveSceneChanged())); - mpAddAnActionItem = new UBAddItem(tr("Add an action"),eUBTGAddSubItemWidgetType_Action,mpTreeWidget); - mpAddAMediaItem = new UBAddItem(tr("Add a media"),eUBTGAddSubItemWidgetType_Media,mpTreeWidget); - mpAddALinkItem = new UBAddItem(tr("Add a link"),eUBTGAddSubItemWidgetType_Url,mpTreeWidget); + mpAddAnActionItem = new UBAddItem(tr("Add an action"), eUBTGAddSubItemWidgetType_Action, mpTreeWidget); + mpAddAMediaItem = new UBAddItem(tr("Add a media"), eUBTGAddSubItemWidgetType_Media, mpTreeWidget); + mpAddALinkItem = new UBAddItem(tr("Add a link"), eUBTGAddSubItemWidgetType_Url, mpTreeWidget); mpRootWidgetItem->addChild(mpAddAnActionItem); mpRootWidgetItem->addChild(mpAddAMediaItem); mpRootWidgetItem->addChild(mpAddALinkItem); - if(UBSettings::settings()->teacherGuideLessonPagesActivated->get().toBool()){ - UBSvgSubsetAdaptor::addElementToBeStored(QString("teacherGuide"),this); - connect(UBApplication::boardController,SIGNAL(documentSet(UBDocumentProxy*)),this,SLOT(onActiveDocumentChanged())); + if (UBSettings::settings()->teacherGuideLessonPagesActivated->get().toBool()) { + UBSvgSubsetAdaptor::addElementToBeStored(QString("teacherGuide"), this); + connect(UBApplication::boardController, SIGNAL(documentSet(UBDocumentProxy*)), this, SLOT(onActiveDocumentChanged())); } } @@ -149,7 +146,7 @@ UBTeacherGuideEditionWidget::~UBTeacherGuideEditionWidget() DELETEPTR(mpAddAnActionItem); DELETEPTR(mpAddAMediaItem); DELETEPTR(mpAddALinkItem); - DELETEPTR(mpTreeWidget) + DELETEPTR(mpTreeWidget); DELETEPTR(mpLayout); } @@ -162,7 +159,7 @@ void UBTeacherGuideEditionWidget::showEvent(QShowEvent* event) void UBTeacherGuideEditionWidget::onActiveDocumentChanged() { int activeSceneIndex = UBApplication::boardController->activeSceneIndex(); - if(UBApplication::boardController->pageFromSceneIndex(activeSceneIndex) != 0) + if (UBApplication::boardController->pageFromSceneIndex(activeSceneIndex) != 0) load(UBSvgSubsetAdaptor::readTeacherGuideNode(activeSceneIndex)); } @@ -172,61 +169,62 @@ void UBTeacherGuideEditionWidget::load(QString element) QDomDocument doc("TeacherGuide"); doc.setContent(element); - for(QDomElement element = doc.documentElement().firstChildElement(); !element.isNull(); element = element.nextSiblingElement()) { + for (QDomElement element = doc.documentElement().firstChildElement(); + !element.isNull(); element = element.nextSiblingElement()) { QString tagName = element.tagName(); - if(tagName == "title") + if (tagName == "title") mpPageTitle->setInitialText(element.attribute("value")); - else if(tagName == "comment") + 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); + else if (tagName == "media") + onAddItemClicked(mpAddAMediaItem, 0, &element); + else if (tagName == "link") + onAddItemClicked(mpAddALinkItem, 0, &element); + else if (tagName == "action") + onAddItemClicked(mpAddAnActionItem, 0, &element); } } - - QVector UBTeacherGuideEditionWidget::save(int pageIndex) { QVector result; - if(pageIndex != UBApplication::boardController->currentPage()) + if (pageIndex != UBApplication::boardController->currentPage()) return result; tIDataStorage* data = new tIDataStorage(); data->name = "teacherGuide"; data->type = eElementType_START; - data->attributes.insert("version","2.00"); + data->attributes.insert("version", "2.00"); result << data; data = new tIDataStorage(); data->name = "title"; data->type = eElementType_UNIQUE; - data->attributes.insert("value",mpPageTitle->text()); - if(mpPageTitle->text().length()){ + data->attributes.insert("value", mpPageTitle->text()); + if (mpPageTitle->text().length()) result << data; - } data = new tIDataStorage(); data->name = "comment"; data->type = eElementType_UNIQUE; - data->attributes.insert("value",mpComment->text()); - if(mpComment->text().length()) + data->attributes.insert("value", mpComment->text()); + if (mpComment->text().length()) result << data; QList children = getChildrenList(mpAddAnActionItem); children << getChildrenList(mpAddAMediaItem); children << getChildrenList(mpAddALinkItem); - foreach(QTreeWidgetItem* widgetItem, children){ - tUBGEElementNode* node = dynamic_cast(mpTreeWidget->itemWidget(widgetItem,0))->saveData(); - if(node){ + foreach(QTreeWidgetItem* widgetItem, children) { + tUBGEElementNode* node = + dynamic_cast(mpTreeWidget->itemWidget( + widgetItem, 0))->saveData(); + if (node) { data = new tIDataStorage(); data->name = node->name; data->type = eElementType_UNIQUE; foreach(QString currentKey, node->attributes.keys()) - data->attributes.insert(currentKey,node->attributes.value(currentKey)); + data->attributes.insert(currentKey, + node->attributes.value(currentKey)); result << data; } } @@ -241,12 +239,12 @@ QVector UBTeacherGuideEditionWidget::save(int pageIndex) void UBTeacherGuideEditionWidget::onActiveSceneChanged() { int currentPage = UBApplication::boardController->currentPage(); - if(currentPage > 0){ + if (currentPage > 0) { cleanData(); - load(UBSvgSubsetAdaptor::readTeacherGuideNode(UBApplication::boardController->activeSceneIndex())); + load( UBSvgSubsetAdaptor::readTeacherGuideNode( UBApplication::boardController->activeSceneIndex())); mpPageNumberLabel->setText(tr("Page: %0").arg(currentPage)); UBDocumentProxy* documentProxy = UBApplication::boardController->selectedDocument(); - if(mpDocumentTitle) + if (mpDocumentTitle) mpDocumentTitle->setText(documentProxy->metaData(UBSettings::sessionTitle).toString()); } } @@ -259,44 +257,46 @@ void UBTeacherGuideEditionWidget::cleanData() children << mpAddAMediaItem->takeChildren(); children << mpAddALinkItem->takeChildren(); - foreach(QTreeWidgetItem* item, children){ + foreach(QTreeWidgetItem* item, children) { DELETEPTR(item); } } -QList UBTeacherGuideEditionWidget::getChildrenList(QTreeWidgetItem* widgetItem) +QList UBTeacherGuideEditionWidget::getChildrenList( QTreeWidgetItem* widgetItem) { - QListresult; - for(int i=0;ichildCount();i+=1) + QList result; + for (int i = 0; i < widgetItem->childCount(); i += 1) result << widgetItem->child(i); return result; } QVector UBTeacherGuideEditionWidget::getPageAndCommentData() { - QVectorresult; + QVector result; tUBGEElementNode* pageTitle = new tUBGEElementNode(); pageTitle->name = "pageTitle"; - pageTitle->attributes.insert("value",mpPageTitle->text()); + pageTitle->attributes.insert("value", mpPageTitle->text()); result << pageTitle; tUBGEElementNode* comment = new tUBGEElementNode(); comment->name = "comment"; - comment->attributes.insert("value",mpComment->text()); + comment->attributes.insert("value", mpComment->text()); result << comment; return result; } QVector UBTeacherGuideEditionWidget::getData() { - QVectorresult; + QVector result; QList children = getChildrenList(mpAddAnActionItem); children << getChildrenList(mpAddAMediaItem); children << getChildrenList(mpAddALinkItem); result << getPageAndCommentData(); - foreach(QTreeWidgetItem* widgetItem, children){ - tUBGEElementNode* node = dynamic_cast(mpTreeWidget->itemWidget(widgetItem,0))->saveData(); - if(node) + foreach(QTreeWidgetItem* widgetItem, children) { + tUBGEElementNode* node = + dynamic_cast(mpTreeWidget->itemWidget( + widgetItem, 0))->saveData(); + if (node) result << node; } return result; @@ -304,31 +304,33 @@ QVector UBTeacherGuideEditionWidget::getData() void UBTeacherGuideEditionWidget::onAddItemClicked(QTreeWidgetItem* widget, int column, QDomElement *element) { - int addSubItemWidgetType = widget->data(column,Qt::UserRole).toInt(); - if(addSubItemWidgetType != eUBTGAddSubItemWidgetType_None){ + int addSubItemWidgetType = widget->data(column, Qt::UserRole).toInt(); + if (addSubItemWidgetType != eUBTGAddSubItemWidgetType_None) { QTreeWidgetItem* newWidgetItem = new QTreeWidgetItem(widget); - newWidgetItem->setData(column,Qt::UserRole,eUBTGAddSubItemWidgetType_None); - newWidgetItem->setData(1,Qt::UserRole,eUBTGAddSubItemWidgetType_None); - newWidgetItem->setIcon(1,QIcon(":images/close.svg")); + newWidgetItem->setData(column, Qt::UserRole, eUBTGAddSubItemWidgetType_None); + newWidgetItem->setData(1, Qt::UserRole, eUBTGAddSubItemWidgetType_None); + newWidgetItem->setIcon(1, QIcon(":images/close.svg")); - switch(addSubItemWidgetType) - { - case eUBTGAddSubItemWidgetType_Action:{ + switch (addSubItemWidgetType) { + case eUBTGAddSubItemWidgetType_Action: { UBTGActionWidget* actionWidget = new UBTGActionWidget(widget); - if(element) actionWidget->initializeWithDom(*element); - mpTreeWidget->setItemWidget(newWidgetItem,0,actionWidget); + if (element) + actionWidget->initializeWithDom(*element); + mpTreeWidget->setItemWidget(newWidgetItem, 0, actionWidget); break; } - case eUBTGAddSubItemWidgetType_Media:{ + case eUBTGAddSubItemWidgetType_Media: { UBTGMediaWidget* mediaWidget = new UBTGMediaWidget(widget); - if(element) mediaWidget->initializeWithDom(*element); - mpTreeWidget->setItemWidget(newWidgetItem,0,mediaWidget); + if (element) + mediaWidget->initializeWithDom(*element); + mpTreeWidget->setItemWidget(newWidgetItem, 0, mediaWidget); break; } - case eUBTGAddSubItemWidgetType_Url:{ + case eUBTGAddSubItemWidgetType_Url: { UBTGUrlWidget* urlWidget = new UBTGUrlWidget(); - if(element) urlWidget->initializeWithDom(*element); - mpTreeWidget->setItemWidget(newWidgetItem,0,urlWidget); + if (element) + urlWidget->initializeWithDom(*element); + mpTreeWidget->setItemWidget(newWidgetItem, 0, urlWidget); break; } default: @@ -337,42 +339,53 @@ void UBTeacherGuideEditionWidget::onAddItemClicked(QTreeWidgetItem* widget, int return; } - if(addSubItemWidgetType != eUBTGAddSubItemWidgetType_None && !widget->isExpanded() ) + if (addSubItemWidgetType != eUBTGAddSubItemWidgetType_None && !widget->isExpanded()) widget->setExpanded(true); - else{ + else { //to update the tree and subtrees widget->setExpanded(false); widget->setExpanded(true); } - } - else if(column == 1 && addSubItemWidgetType == eUBTGAddSubItemWidgetType_None){ - UBTGMediaWidget* media = dynamic_cast(mpTreeWidget->itemWidget(widget,0)); - if(media) media->removeSource(); + } else if (column == 1 + && addSubItemWidgetType == eUBTGAddSubItemWidgetType_None) { + UBTGMediaWidget* media = dynamic_cast(mpTreeWidget->itemWidget(widget, 0)); + if (media) + media->removeSource(); int index = mpTreeWidget->currentIndex().row(); - QTreeWidgetItem* toBeDeletedWidgetItem = widget->parent()->takeChild(index); + QTreeWidgetItem* toBeDeletedWidgetItem = widget->parent()->takeChild( + index); delete toBeDeletedWidgetItem; } } +bool UBTeacherGuideEditionWidget::isModified() +{ + bool result = false; + result |= mpPageTitle->text().length() > 0; + result |= mpComment->text().length() > 0; + result |= mpAddAnActionItem->childCount() > 0; + result |= mpAddAMediaItem->childCount() > 0; + result |= mpAddALinkItem->childCount() > 0; + return result; +} + /*************************************************************************** * class UBTeacherGuidePresentationWidget * ***************************************************************************/ -typedef enum -{ +typedef enum { tUBTGActionAssociateOnClickItem_NONE, tUBTGActionAssociateOnClickItem_URL, tUBTGActionAssociateOnClickItem_MEDIA, tUBTGActionAssociateOnClickItem_EXPAND -}tUBTGActionAssociateOnClickItem; +} tUBTGActionAssociateOnClickItem; -typedef enum -{ +typedef enum { tUBTGTreeWidgetItemRole_HasAnAction = Qt::UserRole, tUBTGTreeWidgetItemRole_HasAnUrl -}tUBTGTreeWidgetItemRole; - +} tUBTGTreeWidgetItemRole; -UBTeacherGuidePresentationWidget::UBTeacherGuidePresentationWidget(QWidget *parent, const char *name) : QWidget(parent) +UBTeacherGuidePresentationWidget::UBTeacherGuidePresentationWidget(QWidget *parent, const char *name) : + QWidget(parent) , mpPageTitle(NULL) , mpComment(NULL) , mpLayout(NULL) @@ -402,10 +415,10 @@ UBTeacherGuidePresentationWidget::UBTeacherGuidePresentationWidget(QWidget *pare mpModePushButton->setMaximumWidth(32); mpModePushButton->installEventFilter(this); - connect(mpModePushButton,SIGNAL(clicked()),parentWidget(),SLOT(changeMode())); + connect(mpModePushButton, SIGNAL(clicked()), parentWidget(), SLOT(changeMode())); mpButtonTitleLayout->addWidget(mpModePushButton); - if(UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool()){ + if (UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool()) { mpDocumentTitle = new QLabel(this); mpDocumentTitle->setObjectName("UBTGPresentationDocumentTitle"); mpButtonTitleLayout->addWidget(mpDocumentTitle); @@ -413,13 +426,13 @@ UBTeacherGuidePresentationWidget::UBTeacherGuidePresentationWidget(QWidget *pare mpLayout->addLayout(mpButtonTitleLayout); - mpPageTitle = new UBTGAdaptableText(0,this); + mpPageTitle = new UBTGAdaptableText(0, this); mpPageTitle->setObjectName("UBTGPresentationPageTitle"); mpPageTitle->setReadOnly(true); mpPageTitle->setStyleSheet("background-color:transparent"); mpLayout->addWidget(mpPageTitle); - mpComment = new UBTGAdaptableText(0,this); + mpComment = new UBTGAdaptableText(0, this); mpComment->setObjectName("UBTGPresentationComment"); mpComment->setReadOnly(true); mpComment->setStyleSheet("background-color:transparent"); @@ -440,8 +453,8 @@ UBTeacherGuidePresentationWidget::UBTeacherGuidePresentationWidget(QWidget *pare mpTreeWidget->setDropIndicatorShown(false); mpTreeWidget->header()->close(); mpTreeWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - connect(mpTreeWidget,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(onAddItemClicked(QTreeWidgetItem*,int))); - connect(UBApplication::boardController,SIGNAL(activeSceneChanged()),this,SLOT(onActiveSceneChanged())); + connect(mpTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(onAddItemClicked(QTreeWidgetItem*,int))); + connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(onActiveSceneChanged())); } UBTeacherGuidePresentationWidget::~UBTeacherGuidePresentationWidget() @@ -461,7 +474,7 @@ UBTeacherGuidePresentationWidget::~UBTeacherGuidePresentationWidget() bool UBTeacherGuidePresentationWidget::eventFilter(QObject* object, QEvent* event) { Q_UNUSED(object); - if(event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverMove || event->type() == QEvent::HoverLeave) + if (event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverMove || event->type() == QEvent::HoverLeave) return true; return false; } @@ -472,7 +485,7 @@ void UBTeacherGuidePresentationWidget::cleanData() mpComment->showText(""); //tree clean QList itemToRemove = mpRootWidgetItem->takeChildren(); - foreach(QTreeWidgetItem* eachItem, itemToRemove){ + foreach(QTreeWidgetItem* eachItem, itemToRemove) { DELETEPTR(eachItem); } // the mpMediaSwitchItem is deleted by the previous loop but the pointer is not set to zero @@ -482,81 +495,81 @@ void UBTeacherGuidePresentationWidget::cleanData() void UBTeacherGuidePresentationWidget::onActiveSceneChanged() { cleanData(); - mpPageNumberLabel->setText(tr("Page: %0").arg(UBApplication::boardController->currentPage())); + mpPageNumberLabel->setText( tr("Page: %0").arg(UBApplication::boardController->currentPage())); UBDocumentProxy* documentProxy = UBApplication::boardController->selectedDocument(); - if(mpDocumentTitle) - mpDocumentTitle->setText(documentProxy->metaData(UBSettings::sessionTitle).toString()); + if (mpDocumentTitle) + mpDocumentTitle->setText( documentProxy->metaData(UBSettings::sessionTitle).toString()); } void UBTeacherGuidePresentationWidget::createMediaButtonItem() { - if(!mpMediaSwitchItem){ + if (!mpMediaSwitchItem) { mpMediaSwitchItem = new QTreeWidgetItem(mpRootWidgetItem); - mpMediaSwitchItem->setText(0,"+"); + mpMediaSwitchItem->setText(0, "+"); mpMediaSwitchItem->setExpanded(false); - mpMediaSwitchItem->setData(0,tUBTGTreeWidgetItemRole_HasAnAction,tUBTGActionAssociateOnClickItem_EXPAND); - mpMediaSwitchItem->setData(0,Qt::BackgroundRole,QVariant(QColor(200,200,200))); - mpMediaSwitchItem->setData(0,Qt::FontRole, QVariant(QFont(QApplication::font().family(),16))); - mpMediaSwitchItem->setData(0,Qt::TextAlignmentRole,QVariant(Qt::AlignCenter)); + mpMediaSwitchItem->setData(0, tUBTGTreeWidgetItemRole_HasAnAction, tUBTGActionAssociateOnClickItem_EXPAND); + mpMediaSwitchItem->setData(0, Qt::BackgroundRole, QVariant(QColor(200, 200, 200))); + mpMediaSwitchItem->setData(0, Qt::FontRole, QVariant(QFont(QApplication::font().family(), 16))); + mpMediaSwitchItem->setData(0, Qt::TextAlignmentRole, QVariant(Qt::AlignCenter)); mpRootWidgetItem->addChild(mpMediaSwitchItem); } } - -void UBTeacherGuidePresentationWidget::showData(QVector data) +void UBTeacherGuidePresentationWidget::showData( QVector data) { cleanData(); - foreach(tUBGEElementNode* element, data){ - if(element->name == "pageTitle") + foreach(tUBGEElementNode* element, data) { + if (element->name == "pageTitle") mpPageTitle->showText(element->attributes.value("value")); else if (element->name == "comment") mpComment->showText(element->attributes.value("value")); - else if(element->name == "action"){ - QTreeWidgetItem* newWidgetItem = new QTreeWidgetItem(mpRootWidgetItem); - newWidgetItem->setText(0,element->attributes.value("task")); + else if (element->name == "action") { + QTreeWidgetItem* newWidgetItem = new QTreeWidgetItem( mpRootWidgetItem); + newWidgetItem->setText(0, element->attributes.value("task")); newWidgetItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); - QString colorString = element->attributes.value("owner").toInt() == 0 ? "red":"green"; - UBTGAdaptableText* textWidget = new UBTGAdaptableText(newWidgetItem,0); + QString colorString = element->attributes.value("owner").toInt() == 0 ? "red" : "green"; + UBTGAdaptableText* textWidget = new UBTGAdaptableText(newWidgetItem, + 0); textWidget->bottomMargin(14); - textWidget->setStyleSheet("QWidget {background: #EEEEEE; border:none; color:" + colorString + ";}"); + textWidget->setStyleSheet( "QWidget {background: #EEEEEE; border:none; color:" + colorString + ";}"); textWidget->showText(element->attributes.value("task")); - textWidget->document()->setDefaultFont(QFont(QApplication::font().family(),11)); - mpTreeWidget->setItemWidget(newWidgetItem,0,textWidget); + textWidget->document()->setDefaultFont( QFont(QApplication::font().family(), 11)); + mpTreeWidget->setItemWidget(newWidgetItem, 0, textWidget); mpRootWidgetItem->addChild(newWidgetItem); } - else if(element->name == "media"){ + else if (element->name == "media") { createMediaButtonItem(); - QTreeWidgetItem* newWidgetItem = new QTreeWidgetItem(mpMediaSwitchItem); - newWidgetItem->setIcon(0,QIcon(":images/teacherGuide/"+ element->attributes.value("mediaType") +".png")); - newWidgetItem->setText(0,element->attributes.value("title")); - newWidgetItem->setData(0,tUBTGTreeWidgetItemRole_HasAnAction,tUBTGActionAssociateOnClickItem_MEDIA); - newWidgetItem->setData(0,Qt::FontRole, QVariant(QFont(QApplication::font().family(),11))); - QString mimeTypeString; + QTreeWidgetItem* newWidgetItem = new QTreeWidgetItem( mpMediaSwitchItem); + newWidgetItem->setIcon(0, QIcon( ":images/teacherGuide/" + element->attributes.value("mediaType") + ".png")); + newWidgetItem->setText(0, element->attributes.value("title")); + newWidgetItem->setData(0, tUBTGTreeWidgetItemRole_HasAnAction, tUBTGActionAssociateOnClickItem_MEDIA); + newWidgetItem->setData(0, Qt::FontRole, QVariant(QFont(QApplication::font().family(), 11))); + QString mimeTypeString; #ifdef Q_WS_WIN - mimeTypeString = QUrl::fromLocalFile(UBApplication::boardController->selectedDocument()->persistencePath()+ "/" + element->attributes.value("relativePath")).toString(); + mimeTypeString = QUrl::fromLocalFile(UBApplication::boardController->selectedDocument()->persistencePath()+ "/" + element->attributes.value("relativePath")).toString(); #else - mimeTypeString = UBApplication::boardController->selectedDocument()->persistencePath()+ "/" + element->attributes.value("relativePath"); + mimeTypeString = UBApplication::boardController->selectedDocument()->persistencePath() + "/" + element->attributes.value("relativePath"); #endif newWidgetItem->setData(0, TG_USER_ROLE_MIME_TYPE, mimeTypeString); - newWidgetItem->setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + newWidgetItem->setFlags( Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable); mpRootWidgetItem->addChild(newWidgetItem); QTreeWidgetItem* mediaItem = new QTreeWidgetItem(newWidgetItem); - mediaItem->setData(0,tUBTGTreeWidgetItemRole_HasAnAction,tUBTGActionAssociateOnClickItem_NONE); - UBTGMediaWidget* mediaWidget = new UBTGMediaWidget(element->attributes.value("relativePath"),newWidgetItem); + mediaItem->setData(0, tUBTGTreeWidgetItemRole_HasAnAction, tUBTGActionAssociateOnClickItem_NONE); + UBTGMediaWidget* mediaWidget = new UBTGMediaWidget(element->attributes.value("relativePath"), newWidgetItem); newWidgetItem->setExpanded(false); - mpTreeWidget->setItemWidget(mediaItem,0,mediaWidget); + mpTreeWidget->setItemWidget(mediaItem, 0, mediaWidget); } - else if(element->name == "link"){ + else if (element->name == "link") { createMediaButtonItem(); - QTreeWidgetItem* newWidgetItem = new QTreeWidgetItem(mpMediaSwitchItem); - newWidgetItem->setIcon(0,QIcon(":images/teacherGuide/link.png")); - newWidgetItem->setText(0,element->attributes.value("title")); - newWidgetItem->setData(0,tUBTGTreeWidgetItemRole_HasAnAction,tUBTGActionAssociateOnClickItem_URL); - newWidgetItem->setData(0,tUBTGTreeWidgetItemRole_HasAnUrl,QVariant(element->attributes.value("url"))); - newWidgetItem->setData(0,Qt::FontRole, QVariant(QFont(QApplication::font().family(),11))); + QTreeWidgetItem* newWidgetItem = new QTreeWidgetItem( mpMediaSwitchItem); + newWidgetItem->setIcon(0, QIcon(":images/teacherGuide/link.png")); + newWidgetItem->setText(0, element->attributes.value("title")); + newWidgetItem->setData(0, tUBTGTreeWidgetItemRole_HasAnAction, tUBTGActionAssociateOnClickItem_URL); + newWidgetItem->setData(0, tUBTGTreeWidgetItemRole_HasAnUrl, QVariant(element->attributes.value("url"))); + newWidgetItem->setData(0, Qt::FontRole, QVariant(QFont(QApplication::font().family(), 11))); newWidgetItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); mpRootWidgetItem->addChild(newWidgetItem); } @@ -565,20 +578,20 @@ void UBTeacherGuidePresentationWidget::showData(QVector data) void UBTeacherGuidePresentationWidget::onAddItemClicked(QTreeWidgetItem* widget, int column) { - int associateAction = widget->data(column,tUBTGTreeWidgetItemRole_HasAnAction).toInt(); - if(column == 0 && associateAction != tUBTGActionAssociateOnClickItem_NONE){ - switch(associateAction) - { + int associateAction = widget->data(column, + tUBTGTreeWidgetItemRole_HasAnAction).toInt(); + if (column == 0 && associateAction != tUBTGActionAssociateOnClickItem_NONE) { + switch (associateAction) { case tUBTGActionAssociateOnClickItem_EXPAND: widget->setExpanded(!widget->isExpanded()); - if(widget->isExpanded()) - mpMediaSwitchItem->setText(0,"-"); + if (widget->isExpanded()) + mpMediaSwitchItem->setText(0, "-"); else - mpMediaSwitchItem->setText(0,"+"); + mpMediaSwitchItem->setText(0, "+"); break; case tUBTGActionAssociateOnClickItem_URL: - widget->data(column,tUBTGTreeWidgetItemRole_HasAnUrl).toString(); - UBApplication::webController->loadUrl(QUrl(widget->data(column,tUBTGTreeWidgetItemRole_HasAnUrl).toString())); + widget->data(column, tUBTGTreeWidgetItemRole_HasAnUrl).toString(); + UBApplication::webController->loadUrl( QUrl( widget->data(column, tUBTGTreeWidgetItemRole_HasAnUrl).toString())); break; case tUBTGActionAssociateOnClickItem_MEDIA: widget->setExpanded(!widget->isExpanded()); @@ -589,11 +602,11 @@ void UBTeacherGuidePresentationWidget::onAddItemClicked(QTreeWidgetItem* widget, } } - /*************************************************************************** - * class UBTeacherGuidePageZeroEditionWidget * + * class UBTeacherGuidePageZeroWidget * ***************************************************************************/ -UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, const char* name): QWidget(parent) +UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, const char* name) : + QWidget(parent) , mpLayout(NULL) , mpButtonTitleLayout(NULL) , mpModePushButton(NULL) @@ -622,7 +635,7 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons , mpSchoolTypeValueLabel(NULL) , mpSeparatorIndex(NULL) , mpLicenceLabel(NULL) - , mpLicenceBox(NULL) + , mpLicenceBox( NULL) , mpLicenceIcon(NULL) , mpLicenceLayout(NULL) , mpSceneItemSessionTitle(NULL) @@ -644,9 +657,9 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpModePushButton->setMaximumWidth(32); mpModePushButton->installEventFilter(this); mpButtonTitleLayout->addWidget(mpModePushButton); - connect(mpModePushButton,SIGNAL(clicked()),this,SLOT(switchToMode())); + connect(mpModePushButton, SIGNAL(clicked()), this, SLOT(switchToMode())); - mpSessionTitle = new UBTGAdaptableText(0,this,"UBTGSessionTitle"); + mpSessionTitle = new UBTGAdaptableText(0, this, "UBTGSessionTitle"); mpSessionTitle->setPlaceHolderText(tr("Type session title here ...")); mpButtonTitleLayout->addWidget(mpSessionTitle); @@ -663,7 +676,7 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpAuthorsLabel->setStyleSheet(chapterStyle); mpLayout->addWidget(mpAuthorsLabel); - mpAuthors = new UBTGAdaptableText(0,this); + mpAuthors = new UBTGAdaptableText(0, this); mpAuthors->setObjectName("UBTGZeroPageInputText"); mpAuthors->setPlaceHolderText(tr("Type authors here ...")); mpLayout->addWidget(mpAuthors); @@ -687,7 +700,7 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpObjectivesLabel->setStyleSheet(chapterStyle); mpLayout->addWidget(mpObjectivesLabel); - mpObjectives = new UBTGAdaptableText(0,this); + mpObjectives = new UBTGAdaptableText(0, this); mpObjectives->setObjectName("UBTGZeroPageInputText"); mpObjectives->setPlaceHolderText(tr("Type objectives here...")); mpLayout->addWidget(mpObjectives); @@ -708,7 +721,7 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpKeywordsLabel->setText(tr("Keywords:")); mpKeywordsLabel->setStyleSheet(chapterStyle); mpLayout->addWidget(mpKeywordsLabel); - mpKeywords = new UBTGAdaptableText(0,this); + mpKeywords = new UBTGAdaptableText(0, this); mpKeywords->setPlaceHolderText(tr("Type keywords here ...")); mpLayout->addWidget(mpKeywords); @@ -720,7 +733,7 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpSchoolLevelBox = new QComboBox(this); mpSchoolLevelBox->setMinimumHeight(22); mpSchoolLevelBox->setObjectName("DockPaletteWidgetComboBox"); - connect(mpSchoolLevelBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(onSchoolLevelChanged(QString))); + connect(mpSchoolLevelBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(onSchoolLevelChanged(QString))); mpLayout->addWidget(mpSchoolLevelBox); mpSchoolLevelValueLabel = new QLabel(this); mpLayout->addWidget(mpSchoolLevelValueLabel); @@ -771,8 +784,7 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpLayout->addLayout(mpLicenceLayout); mpLayout->addStretch(1); - - connect(UBApplication::boardController,SIGNAL(activeSceneChanged()), this, SLOT(onActiveSceneChanged())); + connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(onActiveSceneChanged())); fillComboBoxes(); } @@ -812,7 +824,7 @@ UBTeacherGuidePageZeroWidget::~UBTeacherGuidePageZeroWidget() bool UBTeacherGuidePageZeroWidget::eventFilter(QObject* object, QEvent* event) { Q_UNUSED(object); - if(event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverMove || event->type() == QEvent::HoverLeave) + if (event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverMove || event->type() == QEvent::HoverLeave) return true; return false; } @@ -821,7 +833,7 @@ void UBTeacherGuidePageZeroWidget::fillComboBoxes() { QString parametersConfigFilePath = UBSettings::settings()->applicationCustomizationDirectory() + "/teacherGuide/indexingParameters.xml"; QFile parametersFile(parametersConfigFilePath); - if(!parametersFile.exists()){ + if (!parametersFile.exists()) { qCritical() << "UBTeacherGuidePageZeroEditionWidget fillComboBoxes file not found " << parametersConfigFilePath; return; } @@ -833,48 +845,54 @@ void UBTeacherGuidePageZeroWidget::fillComboBoxes() QDomElement rootElement = doc.elementsByTagName("teacherGuide").at(0).toElement(); QDomNodeList subjects = rootElement.elementsByTagName("subjects"); - for(int baseLevelCounter = 0; baseLevelCounter < subjects.count(); baseLevelCounter += 1){ + for (int baseLevelCounter = 0; baseLevelCounter < subjects.count(); baseLevelCounter += 1) { QDomNode subjectsForBaseLevel = subjects.at(baseLevelCounter); QDomNodeList subjectsList = subjectsForBaseLevel.childNodes(); QStringList subjectsRelatedToBaseLevel; - for(int j = 0; j < subjectsList.count(); j += 1){ + for (int j = 0; j < subjectsList.count(); j += 1) { subjectsRelatedToBaseLevel.append(subjectsList.at(j).toElement().attribute("label")); } - mSubjects.insert(subjectsForBaseLevel.toElement().attribute("baseLevel"),subjectsRelatedToBaseLevel); + mSubjects.insert( subjectsForBaseLevel.toElement().attribute("baseLevel"), subjectsRelatedToBaseLevel); } QDomNodeList gradeLevels = rootElement.elementsByTagName("gradeLevels").at(0).childNodes(); - for(int i=0; iaddItem(gradeLevels.at(i).toElement().attribute("label")); + for (int i = 0; i < gradeLevels.count(); i += 1) { + mGradeLevelsMap.insert(gradeLevels.at(i).toElement().attribute("label"), gradeLevels.at(i).toElement().attribute("baseLevel")); + mpSchoolLevelBox->addItem( gradeLevels.at(i).toElement().attribute("label")); } - QDomNodeList types = rootElement.elementsByTagName("types").at(0).childNodes(); - for(int i=0; iaddItem(types.at(i).toElement().attribute("label")); parametersFile.close(); QStringList licences; - licences << tr("Attribution CC BY") << tr("Attribution-NoDerivs CC BY-ND") << tr("Attribution-ShareAlike CC BY-SA") << tr("Attribution-NonCommercial CC BY-NC") << tr("Attribution-NonCommercial-NoDerivs CC BY-NC-ND") << tr("Attribution-NonCommercial-ShareAlike CC BY-NC-SA") << tr("Public domain") << tr("Copyright"); + licences << tr("Attribution CC BY") << tr("Attribution-NoDerivs CC BY-ND") + << tr("Attribution-ShareAlike CC BY-SA") + << tr("Attribution-NonCommercial CC BY-NC") + << tr("Attribution-NonCommercial-NoDerivs CC BY-NC-ND") + << tr("Attribution-NonCommercial-ShareAlike CC BY-NC-SA") + << tr("Public domain") << tr("Copyright"); mpLicenceBox->addItems(licences); QStringList licenceIconList; - licenceIconList << ":images/licenses/ccby.png" << ":images/licenses/ccbynd.png" << ":images/licenses/ccbysa.png" << ":images/licenses/ccbync.png" << ":images/licenses/ccbyncnd.png" << ":images/licenses/ccbyncsa.png"; - for(int i = 0; i < licenceIconList.count(); i+=1) - mpLicenceBox->setItemData(i,licenceIconList.at(i)); + licenceIconList << ":images/licenses/ccby.png" + << ":images/licenses/ccbynd.png" << ":images/licenses/ccbysa.png" + << ":images/licenses/ccbync.png" << ":images/licenses/ccbyncnd.png" + << ":images/licenses/ccbyncsa.png"; + for (int i = 0; i < licenceIconList.count(); i += 1) + mpLicenceBox->setItemData(i, licenceIconList.at(i)); } void UBTeacherGuidePageZeroWidget::onSchoolLevelChanged(QString schoolLevel) { QStringList subjects = mSubjects.value(mGradeLevelsMap.value(schoolLevel)); mpSchoolSubjectsBox->clear(); - if(subjects.count()){ + if (subjects.count()) { mpSchoolSubjectsItemLabel->setEnabled(true); mpSchoolSubjectsBox->setEnabled(true); mpSchoolSubjectsBox->addItems(subjects); - } - else{ + } else { mpSchoolSubjectsItemLabel->setDisabled(true); mpSchoolSubjectsBox->setDisabled(true); } @@ -883,17 +901,17 @@ void UBTeacherGuidePageZeroWidget::onSchoolLevelChanged(QString schoolLevel) void UBTeacherGuidePageZeroWidget::onActiveSceneChanged() { UBDocumentProxy* documentProxy = UBApplication::boardController->selectedDocument(); - if(documentProxy && UBApplication::boardController->currentPage() == 0){ + if (documentProxy && UBApplication::boardController->currentPage() == 0) { QDateTime creationDate = documentProxy->documentDate(); - mpCreationLabel->setText(tr("Created the:\n") + creationDate.toString(Qt::DefaultLocaleShortDate)); + mpCreationLabel->setText( tr("Created the:\n") + creationDate.toString(Qt::DefaultLocaleShortDate)); QDateTime updatedDate = documentProxy->lastUpdate(); - mpLastModifiedLabel->setText(tr("Updated the:\n") + updatedDate.toString(Qt::DefaultLocaleShortDate)); + mpLastModifiedLabel->setText( tr("Updated the:\n") + updatedDate.toString(Qt::DefaultLocaleShortDate)); loadData(); updateSceneTitle(); } } -void UBTeacherGuidePageZeroWidget::hideEvent ( QHideEvent * event ) +void UBTeacherGuidePageZeroWidget::hideEvent(QHideEvent * event) { persistData(); QWidget::hideEvent(event); @@ -902,56 +920,56 @@ void UBTeacherGuidePageZeroWidget::hideEvent ( QHideEvent * event ) void UBTeacherGuidePageZeroWidget::loadData() { UBDocumentProxy* documentProxy = UBApplication::boardController->selectedDocument(); - mpSessionTitle->setText(documentProxy->metaData(UBSettings::sessionTitle).toString()); - mpAuthors->setText(documentProxy->metaData(UBSettings::sessionAuthors).toString()); - mpObjectives->setText(documentProxy->metaData(UBSettings::sessionObjectives).toString()); - mpKeywords->setText(documentProxy->metaData(UBSettings::sessionKeywords).toString()); + mpSessionTitle->setText( documentProxy->metaData(UBSettings::sessionTitle).toString()); + mpAuthors->setText( documentProxy->metaData(UBSettings::sessionAuthors).toString()); + mpObjectives->setText( documentProxy->metaData(UBSettings::sessionObjectives).toString()); + mpKeywords->setText( documentProxy->metaData(UBSettings::sessionKeywords).toString()); int currentIndex = mpSchoolLevelBox->findText(documentProxy->metaData(UBSettings::sessionGradeLevel).toString()); - mpSchoolLevelBox->setCurrentIndex((currentIndex!=-1) ? currentIndex : 0); + mpSchoolLevelBox->setCurrentIndex((currentIndex != -1) ? currentIndex : 0); currentIndex = mpSchoolSubjectsBox->findText(documentProxy->metaData(UBSettings::sessionSubjects).toString()); - mpSchoolSubjectsBox->setCurrentIndex((currentIndex!=-1) ? currentIndex : 0); + mpSchoolSubjectsBox->setCurrentIndex((currentIndex != -1) ? currentIndex : 0); currentIndex = mpSchoolTypeBox->findText(documentProxy->metaData(UBSettings::sessionType).toString()); - mpSchoolTypeBox->setCurrentIndex((currentIndex!=-1) ? currentIndex : 0); + mpSchoolTypeBox->setCurrentIndex((currentIndex != -1) ? currentIndex : 0); currentIndex = mpLicenceBox->findText(documentProxy->metaData(UBSettings::sessionLicence).toString()); - mpLicenceBox->setCurrentIndex((currentIndex!=-1) ? currentIndex : 0); + mpLicenceBox->setCurrentIndex((currentIndex != -1) ? currentIndex : 0); } void UBTeacherGuidePageZeroWidget::persistData() { // check necessary because at document closing hide event is send after boardcontroller set // to NULL - if(UBApplication::boardController){ + if (UBApplication::boardController) { UBDocumentProxy* documentProxy = UBApplication::boardController->selectedDocument(); - documentProxy->setMetaData(UBSettings::sessionTitle,mpSessionTitle->text()); + documentProxy->setMetaData(UBSettings::sessionTitle, mpSessionTitle->text()); documentProxy->setMetaData(UBSettings::sessionAuthors, mpAuthors->text()); - documentProxy->setMetaData(UBSettings::sessionObjectives,mpObjectives->text()); - documentProxy->setMetaData(UBSettings::sessionKeywords,mpKeywords->text()); - documentProxy->setMetaData(UBSettings::sessionGradeLevel,mpSchoolLevelBox->currentText()); - documentProxy->setMetaData(UBSettings::sessionSubjects,mpSchoolSubjectsBox->currentText()); - documentProxy->setMetaData(UBSettings::sessionType,mpSchoolTypeBox->currentText()); - documentProxy->setMetaData(UBSettings::sessionLicence,mpLicenceBox->currentText()); + documentProxy->setMetaData(UBSettings::sessionObjectives, mpObjectives->text()); + documentProxy->setMetaData(UBSettings::sessionKeywords, mpKeywords->text()); + documentProxy->setMetaData(UBSettings::sessionGradeLevel, mpSchoolLevelBox->currentText()); + documentProxy->setMetaData(UBSettings::sessionSubjects, mpSchoolSubjectsBox->currentText()); + documentProxy->setMetaData(UBSettings::sessionType, mpSchoolTypeBox->currentText()); + documentProxy->setMetaData(UBSettings::sessionLicence, mpLicenceBox->currentText()); } } void UBTeacherGuidePageZeroWidget::updateSceneTitle() { QString sessionTitle = mpSessionTitle->text(); - if(!sessionTitle.isEmpty()) + if (!sessionTitle.isEmpty()) UBApplication::boardController->activeScene()->textForObjectName(mpSessionTitle->text()); } void UBTeacherGuidePageZeroWidget::switchToMode(tUBTGZeroPageMode mode) { - if(mode == tUBTGZeroPageMode_EDITION){ + if (mode == tUBTGZeroPageMode_EDITION) { QString inputStyleSheet("QTextEdit { background: white; border-radius: 10px; border: 2px;}"); mpModePushButton->hide(); mpSessionTitle->setReadOnly(false); mpSessionTitle->setStyleSheet(inputStyleSheet); - QFont titleFont(QApplication::font().family(),11,-1); + QFont titleFont(QApplication::font().family(), 11, -1); mpSessionTitle->document()->setDefaultFont(titleFont); mpAuthors->setReadOnly(false); mpAuthors->setStyleSheet(inputStyleSheet); @@ -969,13 +987,13 @@ void UBTeacherGuidePageZeroWidget::switchToMode(tUBTGZeroPageMode mode) mpLicenceValueLabel->hide(); mpLicenceBox->show(); } - else{ - QString inputStyleSheet("QTextEdit { background: transparent; border: none;}"); + else { + QString inputStyleSheet( "QTextEdit { background: transparent; border: none;}"); mpModePushButton->show(); mpSessionTitle->showText(mpSessionTitle->text()); mpSessionTitle->setStyleSheet(inputStyleSheet); updateSceneTitle(); - QFont titleFont(QApplication::font().family(),14,1); + QFont titleFont(QApplication::font().family(), 14, 1); mpSessionTitle->document()->setDefaultFont(titleFont); mpAuthors->setStyleSheet(inputStyleSheet); mpAuthors->setTextColor(QColor(Qt::black)); @@ -997,7 +1015,7 @@ void UBTeacherGuidePageZeroWidget::switchToMode(tUBTGZeroPageMode mode) mpSchoolTypeBox->hide(); mpLicenceValueLabel->setText(mpLicenceBox->currentText()); QString licenceIconPath = mpLicenceBox->itemData(mpLicenceBox->currentIndex()).toString(); - if(!licenceIconPath.isEmpty()){ + if (!licenceIconPath.isEmpty()) { mpLicenceIcon->setPixmap(QPixmap(licenceIconPath)); mpLicenceIcon->show(); } @@ -1010,85 +1028,101 @@ void UBTeacherGuidePageZeroWidget::switchToMode(tUBTGZeroPageMode mode) QVector UBTeacherGuidePageZeroWidget::getData() { - QVectorresult; + QVector result; tUBGEElementNode* elementNode = new tUBGEElementNode(); elementNode->name = "sessionTitle"; - elementNode->attributes.insert("value",mpSessionTitle->text()); + elementNode->attributes.insert("value", mpSessionTitle->text()); result << elementNode; elementNode = new tUBGEElementNode(); elementNode->name = "authors"; - elementNode->attributes.insert("value",mpAuthors->text()); + elementNode->attributes.insert("value", mpAuthors->text()); result << elementNode; elementNode = new tUBGEElementNode(); elementNode->name = "creationDate"; - elementNode->attributes.insert("value",mpCreationLabel->text()); + elementNode->attributes.insert("value", mpCreationLabel->text()); result << elementNode; elementNode = new tUBGEElementNode(); elementNode->name = "lastModifiedDate"; - elementNode->attributes.insert("value",mpLastModifiedLabel->text()); + elementNode->attributes.insert("value", mpLastModifiedLabel->text()); result << elementNode; elementNode = new tUBGEElementNode(); elementNode->name = "goals"; - elementNode->attributes.insert("value",mpObjectives->text()); + elementNode->attributes.insert("value", mpObjectives->text()); result << elementNode; elementNode = new tUBGEElementNode(); elementNode->name = "keywords"; - elementNode->attributes.insert("value",mpKeywords->text()); + elementNode->attributes.insert("value", mpKeywords->text()); result << elementNode; elementNode = new tUBGEElementNode(); elementNode->name = "schoolLevel"; - elementNode->attributes.insert("value",mpSchoolLevelBox->currentText()); + elementNode->attributes.insert("value", mpSchoolLevelBox->currentText()); result << elementNode; elementNode = new tUBGEElementNode(); elementNode->name = "schoolBranch"; - elementNode->attributes.insert("value",mpSchoolSubjectsBox->currentText()); + elementNode->attributes.insert("value", mpSchoolSubjectsBox->currentText()); result << elementNode; elementNode = new tUBGEElementNode(); elementNode->name = "schoolType"; - elementNode->attributes.insert("value",mpSchoolTypeBox->currentText()); + elementNode->attributes.insert("value", mpSchoolTypeBox->currentText()); result << elementNode; elementNode = new tUBGEElementNode(); elementNode->name = "licence"; - elementNode->attributes.insert("value",mpLicenceBox->currentText()); + elementNode->attributes.insert("value", mpLicenceBox->currentText()); result << elementNode; return result; } +bool UBTeacherGuidePageZeroWidget::isModified() +{ + bool result = false; + result |= mpSessionTitle->text().length() > 0; + result |= mpAuthors->text().length() > 0; + result |= mpObjectives->text().length() > 0; + result |= mpKeywords->text().length() > 0; + result |= mpSchoolLevelBox->currentIndex() > 0; + result |= mpSchoolSubjectsBox->currentIndex() > 0; + result |= mpSchoolTypeBox->currentIndex() > 0; + result |= mpLicenceBox->currentIndex() > 0; + return result; +} + /*************************************************************************** * class UBTeacherGuideWidget * ***************************************************************************/ -UBTeacherGuideWidget::UBTeacherGuideWidget(QWidget* parent, const char* name): QStackedWidget(parent) +UBTeacherGuideWidget::UBTeacherGuideWidget(QWidget* parent, const char* name) : + QStackedWidget(parent) , mpPageZeroWidget(NULL) , mpEditionWidget(NULL) , mpPresentationWidget(NULL) { setObjectName(name); - if(UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool()){ + if (UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool()) { mpPageZeroWidget = new UBTeacherGuidePageZeroWidget(this); addWidget(mpPageZeroWidget); } - if(UBSettings::settings()->teacherGuideLessonPagesActivated->get().toBool()){ + if (UBSettings::settings()->teacherGuideLessonPagesActivated->get().toBool()) { mpEditionWidget = new UBTeacherGuideEditionWidget(this); addWidget(mpEditionWidget); mpPresentationWidget = new UBTeacherGuidePresentationWidget(this); addWidget(mpPresentationWidget); } - connect(UBApplication::boardController->controlView(),SIGNAL(clickOnBoard()),this,SLOT(showPresentationMode())); + connect(UBApplication::boardController->controlView(), + SIGNAL(clickOnBoard()), this, SLOT(showPresentationMode())); connectToStylusPalette(); - connect(UBApplication::boardController,SIGNAL(activeSceneChanged()),this,SLOT(onActiveSceneChanged())); + connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, + SLOT(onActiveSceneChanged())); } - UBTeacherGuideWidget::~UBTeacherGuideWidget() { DELETEPTR(mpPageZeroWidget); @@ -1096,32 +1130,32 @@ UBTeacherGuideWidget::~UBTeacherGuideWidget() DELETEPTR(mpPresentationWidget); } - void UBTeacherGuideWidget::onActiveSceneChanged() { - if(UBApplication::boardController->currentPage() == 0){ + if (UBApplication::boardController->currentPage() == 0) { setCurrentWidget(mpPageZeroWidget); mpPageZeroWidget->switchToMode(tUBTGZeroPageMode_EDITION); - }else + } + else setCurrentWidget(mpEditionWidget); } void UBTeacherGuideWidget::connectToStylusPalette() { - if(UBApplication::boardController->paletteManager()) - connect(UBApplication::boardController->paletteManager()->stylusPalette(),SIGNAL(itemOnActionPaletteChanged()),this,SLOT(showPresentationMode())); + if (UBApplication::boardController->paletteManager()) + connect( UBApplication::boardController->paletteManager()->stylusPalette(), SIGNAL(itemOnActionPaletteChanged()), this, SLOT(showPresentationMode())); else - QTimer::singleShot(100,this,SLOT(connectToStylusPalette())); + QTimer::singleShot(100, this, SLOT(connectToStylusPalette())); } void UBTeacherGuideWidget::showPresentationMode() { - if(currentWidget()==mpPageZeroWidget){ + if (currentWidget() == mpPageZeroWidget) { mCurrentData = mpPageZeroWidget->getData(); mpPageZeroWidget->switchToMode(tUBTGZeroPageMode_PRESENTATION); } - else if(currentWidget()==mpEditionWidget){ + else if (currentWidget() == mpEditionWidget) { mCurrentData = mpEditionWidget->getData(); mpPresentationWidget->showData(mCurrentData); setCurrentWidget(mpPresentationWidget); @@ -1130,9 +1164,17 @@ void UBTeacherGuideWidget::showPresentationMode() void UBTeacherGuideWidget::changeMode() { - if(currentWidget() == mpEditionWidget) + if (currentWidget() == mpEditionWidget) setCurrentWidget(mpPresentationWidget); else setCurrentWidget(mpEditionWidget); } + +bool UBTeacherGuideWidget::isModified() +{ + if (currentWidget() == mpPageZeroWidget) + return mpPageZeroWidget->isModified(); + else + return mpEditionWidget->isModified(); +} diff --git a/src/gui/UBTeacherGuideWidget.h b/src/gui/UBTeacherGuideWidget.h index ecd22084..16ac64e5 100644 --- a/src/gui/UBTeacherGuideWidget.h +++ b/src/gui/UBTeacherGuideWidget.h @@ -50,6 +50,8 @@ public: void load(QString element); QVector save(int pageIndex); + bool isModified(); + public slots: void onAddItemClicked(QTreeWidgetItem* widget, int column, QDomElement* element = 0); void onActiveSceneChanged(); @@ -124,6 +126,7 @@ public: ~UBTeacherGuidePageZeroWidget(); QVector getData(); + bool isModified(); public slots: @@ -198,6 +201,8 @@ public: explicit UBTeacherGuideWidget(QWidget* parent = 0, const char* name="UBTeacherGuideWidget"); ~UBTeacherGuideWidget(); + bool isModified(); + public slots: void changeMode(); void showPresentationMode();