diff --git a/src/gui/UBTeacherGuideWidget.cpp b/src/gui/UBTeacherGuideWidget.cpp index c1ab5023..51cd25b6 100644 --- a/src/gui/UBTeacherGuideWidget.cpp +++ b/src/gui/UBTeacherGuideWidget.cpp @@ -701,8 +701,11 @@ void UBTeacherGuidePageZeroWidget::fillComboBoxes() 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"); - 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)); } void UBTeacherGuidePageZeroWidget::onSchoolLevelChanged(QString schoolLevel) @@ -722,21 +725,64 @@ void UBTeacherGuidePageZeroWidget::onSchoolLevelChanged(QString schoolLevel) void UBTeacherGuidePageZeroWidget::onActiveSceneChanged() { - UBDocumentProxy* documentProxy = UBApplication::documentController ? UBApplication::documentController->getCurrentDocument() : 0; - if(UBApplication::documentController && UBApplication::boardController->currentPage() == 0){ + UBDocumentProxy* documentProxy = UBApplication::boardController->activeDocument(); + if(documentProxy && UBApplication::boardController->currentPage() == 0){ QDateTime creationDate = documentProxy->documentDate(); - mpCreationLabel->setText(tr("Created the:") + creationDate.toString(Qt::SystemLocaleShortDate)); + mpCreationLabel->setText(tr("Created the: ") + creationDate.toString(Qt::SystemLocaleShortDate)); QDateTime updatedDate = documentProxy->lastUpdate(); - mpLastModifiedLabel->setText(tr("Updated the:") + updatedDate.toString(Qt::SystemLocaleShortDate)); + mpLastModifiedLabel->setText(tr("Updated the: ") + updatedDate.toString(Qt::SystemLocaleShortDate)); + persistData(); + loadData(); } } +void UBTeacherGuidePageZeroWidget::hideEvent ( QHideEvent * event ) +{ + persistData(); + QWidget::hideEvent(event); +} + +void UBTeacherGuidePageZeroWidget::loadData() +{ + + UBDocumentProxy* documentProxy = UBApplication::boardController->activeDocument(); + mpSessionTitle->setText(documentProxy->metaData(UBSettings::sessionTitle).toString()); + mpAuthors->setText(documentProxy->metaData(UBSettings::sessionAuthors).toString()); + mpGoals->setText(documentProxy->metaData(UBSettings::sessionGoals).toString()); + mpKeywords->setText(documentProxy->metaData(UBSettings::sessionKeywords).toString()); + + int currentIndex = mpSchoolLevelBox->findText(documentProxy->metaData(UBSettings::sessionGradeLevel).toString()); + mpSchoolLevelBox->setCurrentIndex((currentIndex!=-1) ? currentIndex : 0); + + currentIndex = mpSchoolBranchBox->findText(documentProxy->metaData(UBSettings::sessionBranch).toString()); + mpSchoolBranchBox->setCurrentIndex((currentIndex!=-1) ? currentIndex : 0); + + currentIndex = mpSchoolTypeBox->findText(documentProxy->metaData(UBSettings::sessionType).toString()); + mpSchoolTypeBox->setCurrentIndex((currentIndex!=-1) ? currentIndex : 0); + + currentIndex = mpLicenceBox->findText(documentProxy->metaData(UBSettings::sessionLicence).toString()); + mpLicenceBox->setCurrentIndex((currentIndex!=-1) ? currentIndex : 0); +} + +void UBTeacherGuidePageZeroWidget::persistData() +{ + UBDocumentProxy* documentProxy = UBApplication::boardController->activeDocument(); + documentProxy->setMetaData(UBSettings::sessionTitle,mpSessionTitle->text()); + documentProxy->setMetaData(UBSettings::sessionAuthors, mpAuthors->text()); + documentProxy->setMetaData(UBSettings::sessionGoals,mpGoals->text()); + documentProxy->setMetaData(UBSettings::sessionKeywords,mpKeywords->text()); + documentProxy->setMetaData(UBSettings::sessionGradeLevel,mpSchoolLevelBox->currentText()); + documentProxy->setMetaData(UBSettings::sessionBranch,mpSchoolBranchBox->currentText()); + documentProxy->setMetaData(UBSettings::sessionType,mpSchoolTypeBox->currentText()); + documentProxy->setMetaData(UBSettings::sessionLicence,mpLicenceBox->currentText()); +} void UBTeacherGuidePageZeroWidget::switchToMode(tUBTGZeroPageMode mode) { if(mode == tUBTGZeroPageMode_EDITION){ mpModePushButton->hide(); mpSessionTitle->setReadOnly(false); + mpSessionTitle->setObjectName("UBTGEditionModeSessionTitle"); mpAuthors->setReadOnly(false); mpGoals->setReadOnly(false); mpKeywords->setReadOnly(false); @@ -753,6 +799,7 @@ void UBTeacherGuidePageZeroWidget::switchToMode(tUBTGZeroPageMode mode) else{ mpModePushButton->show(); mpSessionTitle->setReadOnly(true); + mpSessionTitle->setObjectName("UBTGPresentationSessionTitle"); mpAuthors->setReadOnly(true); mpGoals->setReadOnly(true); mpKeywords->setReadOnly(true); @@ -766,14 +813,14 @@ void UBTeacherGuidePageZeroWidget::switchToMode(tUBTGZeroPageMode mode) mpSchoolTypeValueLabel->show(); mpSchoolTypeBox->hide(); mpLicenceValueLabel->setText(mpLicenceBox->currentText()); - 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"; - if(mpLicenceBox->currentIndex() < 6){ - mpLicenceIcon->setPixmap(licenceIconList.at(mpLicenceBox->currentIndex())); + QString licenceIconPath = mpLicenceBox->itemData(mpLicenceBox->currentIndex()).toString(); + if(!licenceIconPath.isEmpty()){ + mpLicenceIcon->setPixmap(QPixmap(licenceIconPath)); mpLicenceIcon->show(); } mpLicenceValueLabel->show(); mpLicenceBox->hide(); + persistData(); } } @@ -860,6 +907,7 @@ UBTeacherGuideWidget::UBTeacherGuideWidget(QWidget* parent, const char* name): Q UBTeacherGuideWidget::~UBTeacherGuideWidget() { + DELETEPTR(mpPageZeroWidget); DELETEPTR(mpEditionWidget); DELETEPTR(mpPresentationWidget); } @@ -867,10 +915,11 @@ UBTeacherGuideWidget::~UBTeacherGuideWidget() void UBTeacherGuideWidget::onActiveSceneChanged() { - if(UBApplication::boardController->currentPage() == 0) + if(UBApplication::boardController->currentPage() == 0){ setCurrentWidget(mpPageZeroWidget); - else - setCurrentWidget(mpPresentationWidget); + mpPageZeroWidget->switchToMode(tUBTGZeroPageMode_EDITION); + }else + setCurrentWidget(mpEditionWidget); } diff --git a/src/gui/UBTeacherGuideWidget.h b/src/gui/UBTeacherGuideWidget.h index cc1e62f3..2e98b429 100644 --- a/src/gui/UBTeacherGuideWidget.h +++ b/src/gui/UBTeacherGuideWidget.h @@ -103,7 +103,7 @@ private: }; /*************************************************************************** - * class UBTeacherGuidePageZeroPresentationWidget * + * class UBTeacherGuidePageZeroWidget * ***************************************************************************/ class UBTeacherGuidePageZeroWidget : public QWidget { @@ -122,6 +122,8 @@ public slots: private: void fillComboBoxes(); + void loadData(); + void hideEvent(QHideEvent* event); QVBoxLayout* mpLayout; QHBoxLayout* mpButtonTitleLayout; @@ -168,6 +170,7 @@ private: private slots: void onSchoolLevelChanged(QString schoolLevel); + void persistData(); }; /*************************************************************************** diff --git a/src/gui/UBTeacherGuideWidgetsTools.cpp b/src/gui/UBTeacherGuideWidgetsTools.cpp index 73b89276..2f2dbba0 100644 --- a/src/gui/UBTeacherGuideWidgetsTools.cpp +++ b/src/gui/UBTeacherGuideWidgetsTools.cpp @@ -21,13 +21,15 @@ #include #include #include -#include -#include #include #include "UBTeacherGuideWidgetsTools.h" #include "UBTGWidgetTreeDelegate.h" +#include "core/UBPersistenceManager.h" + +#include "domain/UBW3CWidget.h" + #include "globals/UBGlobals.h" #include "frameworks/UBFileSystemUtils.h" @@ -110,7 +112,6 @@ UBTGAdaptableText::UBTGAdaptableText(QTreeWidgetItem* widget, QWidget* parent, c connect(this,SIGNAL(textChanged()),this,SLOT(onTextChanged())); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setMinimumHeight(mMinimumHeight); } void UBTGAdaptableText::setPlaceHolderText(QString text) @@ -126,6 +127,13 @@ void UBTGAdaptableText::setPlaceHolderText(QString text) void UBTGAdaptableText::keyPressEvent(QKeyEvent* e) { + if(isReadOnly()){ + // this is important if you set a placeholder. In this case even if the text field is readonly the + // keypressed event came here. So if you don't ignore it you'll have a flick on the text zone + e->ignore(); + return; + } + if(toPlainText() == mPlaceHolderText){ setTextColor(QColor(Qt::black)); setPlainText(""); @@ -161,11 +169,18 @@ QString UBTGAdaptableText::text() void UBTGAdaptableText::onTextChanged() { + qreal documentSize = document()->size().height(); + + if(height() == documentSize + mBottomMargin) + return; mIsUpdatingSize = true; - if(document()->size().height() < mMinimumHeight) + + + if(documentSize < mMinimumHeight) setFixedHeight(mMinimumHeight); else - setFixedHeight(document()->size().height()+mBottomMargin); + setFixedHeight(documentSize+mBottomMargin); + updateGeometry(); //to trig the widget item to resize it if(mpTreeWidgetItem){ @@ -197,7 +212,51 @@ void UBTGAdaptableText::bottomMargin(int newValue) void UBTGAdaptableText::resizeEvent(QResizeEvent* e) { QTextEdit::resizeEvent(e); - QTimer::singleShot(100,this,SLOT(onTextChanged())); + //QTimer::singleShot(100,this,SLOT(onTextChanged())); +} + +/*************************************************************************** + * class UBTGDraggableWeb * + ***************************************************************************/ +UBDraggableWeb::UBDraggableWeb(QString& relativePath, QWidget* parent): QWebView(parent) + , mRelativePath(relativePath) + , mDragStartPosition(QPoint(-1,-1)) + , mDragStarted(false) + +{ + //NOOP +} + +void UBDraggableWeb::mousePressEvent(QMouseEvent* event) +{ + mDragStartPosition = event->pos(); + mDragStarted = true; + QWebView::mousePressEvent(event); +} + +void UBDraggableWeb::mouseReleaseEvent(QMouseEvent* event) +{ + mDragStarted = false; + QWebView::mouseReleaseEvent(event); +} + +void UBDraggableWeb::mouseMoveEvent(QMouseEvent* event) +{ + if(mDragStarted && (event->pos() - mDragStartPosition).manhattanLength() > QApplication::startDragDistance()){ + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + QList urlList; + urlList << QUrl(mRelativePath); + mimeData->setUrls(urlList); + drag->setMimeData(mimeData); + + drag->exec(); + event->accept(); + mDragStarted = false; + } + else + QWebView::mouseMoveEvent(event); + } /*************************************************************************** @@ -259,6 +318,22 @@ UBTGMediaWidget::~UBTGMediaWidget() DELETEPTR(mpWorkWidget); } +void UBTGMediaWidget::hideEvent(QHideEvent* event) +{ + if(mpWebView) + mpWebView->page()->mainFrame()->setContent(UBW3CWidget::freezedWidgetPage().toAscii()); + QWidget::hideEvent(event); +} + +void UBTGMediaWidget::showEvent(QShowEvent* event) +{ + QWidget::showEvent(event); + if(mpWebView){ + qDebug() << mRelativePath; + mpWebView->load(QUrl(mRelativePath + "/index.htm")); + } +} + tUBGEElementNode* UBTGMediaWidget::saveData() { if(!mpTitle) @@ -279,8 +354,8 @@ void UBTGMediaWidget::dragEnterEvent(QDragEnterEvent *event) void UBTGMediaWidget::createWorkWidget(QString& path) { QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(path); - qDebug() << mimeType; bool setMedia = true; + mRelativePath = path; if(mimeType.contains("audio") || mimeType.contains("video")){ mMediaType = mimeType.contains("audio")? "audio":"movie"; mpMediaWidget = new UBMediaWidget(mimeType.contains("audio")?eMediaType_Audio:eMediaType_Video); @@ -296,7 +371,11 @@ void UBTGMediaWidget::createWorkWidget(QString& path) } else if(mimeType.contains("application")){ mMediaType = "w3c"; - mpWebView = new QWebView(0); + if(!mIsPresentationMode){ + QDir baseW3CDirectory("/home/claudio"); + mRelativePath = UBW3CWidget::createNPAPIWrapperInDir(path,baseW3CDirectory,mimeType,QSize(100,100),"flashahaha"); + } + mpWebView = new UBDraggableWeb(mRelativePath); mpWebView->setAcceptDrops(false); mpWebView->settings()->setAttribute(QWebSettings::JavaEnabled, true); mpWebView->settings()->setAttribute(QWebSettings::PluginsEnabled, true); @@ -305,8 +384,8 @@ void UBTGMediaWidget::createWorkWidget(QString& path) mpWebView->settings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true); mpWebView->settings()->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true); mpWebView->settings()->setAttribute(QWebSettings::DnsPrefetchEnabled, true); - mpWebView->load(QUrl(path)); - mpWebView->show(); + + mpWebView->load(QUrl(mRelativePath+"/index.htm")); } else{ qDebug() << "createWorkWidget mime type not handled" << mimeType; @@ -314,7 +393,6 @@ void UBTGMediaWidget::createWorkWidget(QString& path) } if(setMedia){ - mRelativePath = path; setAcceptDrops(false); mpWorkWidget = new QWidget(this); mpLayout = new QVBoxLayout(mpWorkWidget); @@ -336,6 +414,7 @@ void UBTGMediaWidget::createWorkWidget(QString& path) mpWebView->setMaximumHeight(mpTreeWidgetItem->treeWidget()->size().width()); mpWebView->setParent(mpWorkWidget); mpLayout->addWidget(mpWebView); + mpWebView->show(); } mpWorkWidget->setLayout(mpLayout); addWidget(mpWorkWidget); diff --git a/src/gui/UBTeacherGuideWidgetsTools.h b/src/gui/UBTeacherGuideWidgetsTools.h index fe1248d8..c73d15ff 100644 --- a/src/gui/UBTeacherGuideWidgetsTools.h +++ b/src/gui/UBTeacherGuideWidgetsTools.h @@ -111,6 +111,22 @@ private: }; +class UBDraggableWeb : public QWebView +{ + Q_OBJECT +public: + explicit UBDraggableWeb(QString& relativePath, QWidget* parent = 0); + +private: + void mousePressEvent(QMouseEvent* event); + void mouseMoveEvent(QMouseEvent* event); + void mouseReleaseEvent(QMouseEvent* event); + + QString mRelativePath; + QPoint mDragStartPosition; + bool mDragStarted; +}; + class UBTGMediaWidget : public QStackedWidget , public iUBTGSavableData { Q_OBJECT @@ -124,6 +140,8 @@ protected: void dragEnterEvent(QDragEnterEvent* event); void dropEvent(QDropEvent* event); void mousePressEvent(QMouseEvent* event); + void hideEvent(QHideEvent* event); + void showEvent(QShowEvent* event); private: void parseMimeData(const QMimeData* pMimeData); @@ -137,7 +155,7 @@ private: UBTGAdaptableText* mpTitle; QLabel* mpMediaLabelWidget; UBMediaWidget* mpMediaWidget; - QWebView* mpWebView; + UBDraggableWeb* mpWebView; QString mRelativePath; bool mIsPresentationMode; QString mMediaType;