From 191e21ee5d3151e92c5e12ee3f67c2cd33297583 Mon Sep 17 00:00:00 2001 From: shibakaneki Date: Wed, 19 Oct 2011 15:04:03 +0200 Subject: [PATCH] Adding the teacher bar widget --- src/board/UBBoardController.cpp | 1 - src/board/UBBoardController.h | 1 + src/board/UBBoardPaletteManager.cpp | 2 +- src/core/UBPersistenceManager.cpp | 89 ++++++++++++++++++++++++++++- src/core/UBPersistenceManager.h | 19 ++++++ src/gui/UBDocumentNavigator.cpp | 7 ++- src/gui/UBTeacherBarWidget.cpp | 54 +++++++++++++++++ src/gui/UBTeacherBarWidget.h | 7 +++ 8 files changed, 174 insertions(+), 6 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 6efd102d..ad0ec53d 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -1981,4 +1981,3 @@ void UBBoardController::notifyPageChanged() } - diff --git a/src/board/UBBoardController.h b/src/board/UBBoardController.h index ef2564f6..a587b8be 100644 --- a/src/board/UBBoardController.h +++ b/src/board/UBBoardController.h @@ -263,6 +263,7 @@ class UBBoardController : public QObject void pageChanged(); void setDocOnPageNavigator(UBDocumentProxy* doc); void documentReorganized(int index); + void pageWillChange(int page, int nextPage); protected: diff --git a/src/board/UBBoardPaletteManager.cpp b/src/board/UBBoardPaletteManager.cpp index 698a9820..14006a5e 100755 --- a/src/board/UBBoardPaletteManager.cpp +++ b/src/board/UBBoardPaletteManager.cpp @@ -164,7 +164,7 @@ void UBBoardPaletteManager::setupDockPaletteWidgets() mRightPalette->addTabWidget(mpLibWidget); mRightPalette->registerWidget(mpTeacherBarWidget); - //mRightPalette->addTabWidget(mpTeacherBarWidget); + mRightPalette->addTabWidget(mpTeacherBarWidget); mRightPalette->connectSignals(); mLeftPalette->showTabWidget(0); mRightPalette->showTabWidget(0); diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index 3987f615..87f2a340 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -592,7 +592,6 @@ UBGraphicsScene* UBPersistenceManager::loadDocumentScene(UBDocumentProxy* proxy, { if (mSceneCache.contains(proxy, sceneIndex)) { - //qDebug() << "scene" << sceneIndex << "retrieved from cache ..."; return mSceneCache.value(proxy, sceneIndex); } else @@ -618,8 +617,6 @@ void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy, QDir dir(pDocumentProxy->persistencePath()); dir.mkpath(pDocumentProxy->persistencePath()); - qDebug() << "saving page" << pSceneIndex + 1 << pDocumentProxy->persistencePath(); - if (pDocumentProxy->isModified()) UBMetadataDcSubsetAdaptor::persist(pDocumentProxy); @@ -638,6 +635,92 @@ void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy, } +void UBPersistenceManager::persistTeacherBar(UBDocumentProxy* pDocumentProxy, int page, sTeacherBarInfos infos) +{ + if(NULL != pDocumentProxy) + { + QFile f(pDocumentProxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", page + 1)); + if(f.exists()) + { + if(f.open(QIODevice::ReadOnly)) + { + QDomDocument domDoc; + if(domDoc.setContent(f.readAll())) + { + f.close(); + if(f.open(QIODevice::WriteOnly)) + { + QDomElement rootElem = domDoc.documentElement(); + QDomNode teacherBarNode = domDoc.namedItem("teacherBar"); + if(teacherBarNode.isNull()) + { + // Create the element + QDomElement teacherElem = domDoc.createElement("teacherBar"); + rootElem.appendChild(teacherElem); + teacherBarNode = teacherElem; + } + + // Set the element values + QDomElement teacherBarElem = teacherBarNode.toElement(); + teacherBarElem.setAttribute("title", infos.title); + teacherBarElem.setAttribute("phasis", infos.phasis); + teacherBarElem.setAttribute("duration", infos.Duration); + teacherBarElem.setAttribute("equipment", infos.material); + teacherBarElem.setAttribute("activity", infos.activity); + teacherBarElem.setAttribute("action1Teacher", infos.action1Master); + teacherBarElem.setAttribute("action1Student", infos.action1Student); + teacherBarElem.setAttribute("action2Teacher", infos.action2Master); + teacherBarElem.setAttribute("action2Student", infos.action2Student); + teacherBarElem.setAttribute("action3Teacher", infos.action3Master); + teacherBarElem.setAttribute("action3Student", infos.action3Student); + + // Save the file + f.write(domDoc.toString().toAscii()); + f.close(); + } + } + f.close(); + } + } + } +} + +sTeacherBarInfos UBPersistenceManager::getTeacherBarInfos(UBDocumentProxy* pDocumentProxy, int page) +{ + sTeacherBarInfos infos; + + if(NULL != pDocumentProxy) + { + QFile f(pDocumentProxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", page + 1)); + if(f.exists()) + { + if(f.open(QIODevice::ReadWrite)) + { + QDomDocument domDoc; + if(domDoc.setContent(f.readAll())) + { + QDomElement rootElem = domDoc.documentElement(); + QDomNode teacherBarNode = rootElem.namedItem("teacherBar"); + + infos.title = teacherBarNode.toElement().attributeNode("title").value(); + infos.phasis = teacherBarNode.toElement().attributeNode("phasis").value().toInt(); + infos.Duration = teacherBarNode.toElement().attributeNode("duration").value().toInt(); + infos.material = teacherBarNode.toElement().attributeNode("equipment").value(); + infos.activity = teacherBarNode.toElement().attributeNode("activity").value().toInt(); + infos.action1Master = teacherBarNode.toElement().attributeNode("action1Teacher").value(); + infos.action1Student = teacherBarNode.toElement().attributeNode("action1Student").value(); + infos.action2Master = teacherBarNode.toElement().attributeNode("action2Teacher").value(); + infos.action2Student = teacherBarNode.toElement().attributeNode("action2Student").value(); + infos.action3Master = teacherBarNode.toElement().attributeNode("action3Teacher").value(); + infos.action3Student = teacherBarNode.toElement().attributeNode("action3Student").value(); + } + f.close(); + } + } + } + + return infos; +} UBDocumentProxy* UBPersistenceManager::persistDocumentMetadata(UBDocumentProxy* pDocumentProxy) { diff --git a/src/core/UBPersistenceManager.h b/src/core/UBPersistenceManager.h index 9189e38f..b2a41937 100644 --- a/src/core/UBPersistenceManager.h +++ b/src/core/UBPersistenceManager.h @@ -20,6 +20,21 @@ #include "UBSceneCache.h" +struct sTeacherBarInfos +{ + QString title; + int phasis; + int Duration; + QString material; + int activity; + QString action1Master; + QString action1Student; + QString action2Master; + QString action2Student; + QString action3Master; + QString action3Student; +}; + class UBDocument; class UBDocumentProxy; class UBGraphicsScene; @@ -60,6 +75,10 @@ class UBPersistenceManager : public QObject virtual void persistDocumentScene(UBDocumentProxy* pDocumentProxy, UBGraphicsScene* pScene, const int pSceneIndex); + virtual void persistTeacherBar(UBDocumentProxy* pDocumentProxy, int page, sTeacherBarInfos infos); + + sTeacherBarInfos getTeacherBarInfos(UBDocumentProxy* pDocumentProxy, int page); + virtual UBGraphicsScene* createDocumentSceneAt(UBDocumentProxy* pDocumentProxy, int index); virtual void insertDocumentSceneAt(UBDocumentProxy* pDocumentProxy, UBGraphicsScene* scene, int index); diff --git a/src/gui/UBDocumentNavigator.cpp b/src/gui/UBDocumentNavigator.cpp index 74bd3611..730911c8 100644 --- a/src/gui/UBDocumentNavigator.cpp +++ b/src/gui/UBDocumentNavigator.cpp @@ -141,8 +141,13 @@ void UBDocumentNavigator::updateSpecificThumbnail(int iPage) { // Save the current state of the scene pScene->setModified(true); - UBSvgSubsetAdaptor::persistScene(mCrntDoc,pScene, iPage); + if(UBApplication::boardController) + { + UBApplication::boardController->persistCurrentScene(); + } + + // Now, update the thumbnail UBThumbnailAdaptor::persistScene(mCrntDoc->persistencePath(), pScene, iPage); // Load it diff --git a/src/gui/UBTeacherBarWidget.cpp b/src/gui/UBTeacherBarWidget.cpp index cd99a01e..ca505470 100644 --- a/src/gui/UBTeacherBarWidget.cpp +++ b/src/gui/UBTeacherBarWidget.cpp @@ -1,6 +1,12 @@ #include "UBTeacherBarWidget.h" #include "core/UBApplication.h" +#include "core/UBPersistenceManager.h" + +#include "document/UBDocumentController.h" +#include "document/UBDocumentProxy.h" + +#include "board/UBBoardController.h" UBTeacherBarWidget::UBTeacherBarWidget(QWidget *parent, const char *name):UBDockPaletteWidget(parent) , mpLayout(NULL) @@ -110,6 +116,9 @@ UBTeacherBarWidget::UBTeacherBarWidget(QWidget *parent, const char *name):UBDock mpLayout->addWidget(mpAction3); populateCombos(); + + connect(UBApplication::boardController, SIGNAL(activeSceneWillChange()), this, SLOT(saveContent())); + connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(loadContent())); } UBTeacherBarWidget::~UBTeacherBarWidget() @@ -221,14 +230,50 @@ void UBTeacherBarWidget::populateCombos() QStringList qslPhasis; qslPhasis << tr("I discover") << tr("I experiment") << tr("I train myself") << tr("I play") << tr("I memorize"); mpPhasis->insertItems(0, qslPhasis); + mpPhasis->setCurrentIndex(0); QStringList qslDuration; qslDuration << tr("Short") << tr("Middle") << tr("Long"); mpDuration->insertItems(0, qslDuration); + mpDuration->setCurrentIndex(0); QStringList qslActivity; qslActivity << tr("Alone") << tr("By Group") << tr("All together"); mpActivity->insertItems(0, qslActivity); + mpActivity->setCurrentIndex(0); +} + +void UBTeacherBarWidget::saveContent() +{ + sTeacherBarInfos infos; + infos.title = mpTitle->text(); + infos.phasis = mpPhasis->currentIndex(); + infos.Duration = mpDuration->currentIndex(); + infos.material = mpEquipment->text(); + infos.activity = mpActivity->currentIndex(); + infos.action1Master = mpAction1->teacherText(); + infos.action1Student = mpAction1->studentText(); + infos.action2Master = mpAction2->teacherText(); + infos.action2Student = mpAction2->studentText(); + infos.action3Master = mpAction3->teacherText(); + infos.action3Student = mpAction3->studentText(); + UBPersistenceManager::persistenceManager()->persistTeacherBar(UBApplication::boardController->activeDocument(), UBApplication::boardController->activeSceneIndex(), infos); +} + +void UBTeacherBarWidget::loadContent() +{ + sTeacherBarInfos nextInfos = UBPersistenceManager::persistenceManager()->getTeacherBarInfos(UBApplication::boardController->activeDocument(), UBApplication::boardController->activeSceneIndex()); + mpTitle->setText(nextInfos.title); + mpPhasis->setCurrentIndex(nextInfos.phasis); + mpDuration->setCurrentIndex(nextInfos.Duration); + mpEquipment->setText(nextInfos.material); + mpActivity->setCurrentIndex(nextInfos.activity); + mpAction1->setTeacherText(nextInfos.action1Master); + mpAction1->setStudentText(nextInfos.action1Student); + mpAction2->setTeacherText(nextInfos.action2Master); + mpAction2->setStudentText(nextInfos.action2Student); + mpAction3->setTeacherText(nextInfos.action3Master); + mpAction3->setStudentText(nextInfos.action3Student); } UBTeacherStudentAction::UBTeacherStudentAction(int actionNumber, QWidget *parent, const char *name):QWidget(parent) @@ -327,3 +372,12 @@ QString UBTeacherStudentAction::studentText() return mpStudent->document()->toPlainText(); } +void UBTeacherStudentAction::setTeacherText(QString text) +{ + mpTeacher->setText(text); +} + +void UBTeacherStudentAction::setStudentText(QString text) +{ + mpStudent->setText(text); +} diff --git a/src/gui/UBTeacherBarWidget.h b/src/gui/UBTeacherBarWidget.h index d6a816ef..7e2744ec 100644 --- a/src/gui/UBTeacherBarWidget.h +++ b/src/gui/UBTeacherBarWidget.h @@ -20,6 +20,8 @@ public: ~UBTeacherStudentAction(); QString teacherText(); QString studentText(); + void setTeacherText(QString text); + void setStudentText(QString text); private: int mActionNumber; @@ -35,10 +37,15 @@ private: class UBTeacherBarWidget : public UBDockPaletteWidget { + Q_OBJECT public: UBTeacherBarWidget(QWidget* parent=0, const char* name="UBTeacherBarWidget"); ~UBTeacherBarWidget(); +private slots: + void saveContent(); + void loadContent(); + private: void populateCombos();