diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index 3987f615..5e3449f5 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -1059,3 +1059,89 @@ bool UBPersistenceManager::mayHaveWidget(UBDocumentProxy* pDocumentProxy) return widgetDir.exists() && widgetDir.entryInfoList(QDir::Dirs).length() > 0; } +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; +} diff --git a/src/core/UBPersistenceManager.h b/src/core/UBPersistenceManager.h index 9189e38f..3c224f04 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,9 @@ 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/UBTeacherBarWidget.cpp b/src/gui/UBTeacherBarWidget.cpp index 1cc481fe..6df5f793 100644 --- a/src/gui/UBTeacherBarWidget.cpp +++ b/src/gui/UBTeacherBarWidget.cpp @@ -125,7 +125,7 @@ UBTeacherBarWidget::UBTeacherBarWidget(QWidget *parent, const char *name):UBDock connect(mpDuration, SIGNAL(currentIndexChanged(int)), this, SLOT(onValueChanged())); connect(mpEquipment, SIGNAL(textChanged(QString)), this, SLOT(onValueChanged())); connect(mpActivity, SIGNAL(currentIndexChanged(int)), this, SLOT(onValueChanged())); - connect(mpAction1->teacher(), SIGNAL(textChanged()), this, SLOT(onValueChanged())); + connect(mpAction1->teacher(), SIGNAL(textChanged()), dynamic_cast(this), SLOT(onValueChanged())); connect(mpAction1->student(), SIGNAL(textChanged()), this, SLOT(onValueChanged())); connect(mpAction2->teacher(), SIGNAL(textChanged()), this, SLOT(onValueChanged())); connect(mpAction2->student(), SIGNAL(textChanged()), this, SLOT(onValueChanged())); @@ -242,14 +242,17 @@ void UBTeacherBarWidget::populateCombos() QStringList qslPhasis; qslPhasis << tr("") << 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("") << tr("Short") << tr("Middle") << tr("Long"); mpDuration->insertItems(0, qslDuration); + mpDuration->setCurrentIndex(0); QStringList qslActivity; qslActivity << tr("") << tr("Alone") << tr("By Group") << tr("All together"); mpActivity->insertItems(0, qslActivity); + mpActivity->setCurrentIndex(0); } void UBTeacherBarWidget::onValueChanged() @@ -278,6 +281,39 @@ void UBTeacherBarWidget::onValueChanged() UBApplication::boardController->paletteManager()->refreshPalettes(); } +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) , mpActionLabel(NULL) , mpTeacherLabel(NULL) diff --git a/src/gui/UBTeacherBarWidget.h b/src/gui/UBTeacherBarWidget.h index 55fd98d3..555b6ef6 100644 --- a/src/gui/UBTeacherBarWidget.h +++ b/src/gui/UBTeacherBarWidget.h @@ -39,6 +39,7 @@ private: class UBTeacherBarWidget : public UBDockPaletteWidget { + Q_OBJECT public: UBTeacherBarWidget(QWidget* parent=0, const char* name="UBTeacherBarWidget"); ~UBTeacherBarWidget();