From b8e15166984256f7f6af131e9df89fc31a21628d Mon Sep 17 00:00:00 2001 From: shibakaneki Date: Wed, 25 Jan 2012 14:18:20 +0100 Subject: [PATCH] Backuping some rework on the teacherbar --- src/gui/UBTBPageEditWidget.cpp | 41 ++++++++++---- src/gui/UBTBPageEditWidget.h | 3 ++ src/gui/UBTeacherBarPreviewWidget.cpp | 77 +++++++++++++++++++-------- src/gui/UBTeacherBarPreviewWidget.h | 14 +++++ src/gui/UBTeacherBarWidget.cpp | 5 +- 5 files changed, 108 insertions(+), 32 deletions(-) diff --git a/src/gui/UBTBPageEditWidget.cpp b/src/gui/UBTBPageEditWidget.cpp index 4abda81d..4173aba1 100644 --- a/src/gui/UBTBPageEditWidget.cpp +++ b/src/gui/UBTBPageEditWidget.cpp @@ -29,7 +29,7 @@ UBTBPageEditWidget::UBTBPageEditWidget(UBTeacherBarDataMgr *pDataMgr, QWidget *p mUrls.clear(); setAttribute(Qt::WA_StyledBackground, true); setStyleSheet(UBApplication::globalStyleSheet()); - + mClearingFields = false; mLayout.setContentsMargins(0, 0, 0, 0); setLayout(&mLayout); @@ -120,14 +120,18 @@ UBTBPageEditWidget::~UBTBPageEditWidget() void UBTBPageEditWidget::onTitleChanged() { - mpDataMgr->setPageTitle(mpTitle->text()); - emit valueChanged(); + if(!mClearingFields){ + mpDataMgr->setPageTitle(mpTitle->text()); + emit valueChanged(); + } } void UBTBPageEditWidget::onCommentsChanged() { - mpDataMgr->setComments(mpComments->document()->toPlainText()); - emit valueChanged(); + if(!mClearingFields){ + mpDataMgr->setComments(mpComments->document()->toPlainText()); + emit valueChanged(); + } } void UBTBPageEditWidget::onActionButton() @@ -135,6 +139,7 @@ void UBTBPageEditWidget::onActionButton() UBTeacherStudentAction* pAction = new UBTeacherStudentAction(this); mActions << pAction; mpActions->addWidget(pAction); + emit valueChanged(); } void UBTBPageEditWidget::onLinkButton() @@ -142,6 +147,7 @@ void UBTBPageEditWidget::onLinkButton() UBUrlWidget* pUrl = new UBUrlWidget(this); mUrls << pUrl; mpLinks->addWidget(pUrl); + emit valueChanged(); } void UBTBPageEditWidget::onMediaDropped(const QString &url) @@ -149,9 +155,12 @@ void UBTBPageEditWidget::onMediaDropped(const QString &url) if("" != url){ QWidget* pMedia = mpMediaContainer->generateMediaWidget(url); if(NULL != pMedia){ - mpDataMgr->medias()->append(pMedia); - mpDataMgr->addMediaUrl(url); + mMedias << pMedia; + mMediaUrls << url; + //mpDataMgr->medias()->append(pMedia); + //mpDataMgr->addMediaUrl(url); mpMediaContainer->addWidget(pMedia); + emit valueChanged(); } } } @@ -170,6 +179,8 @@ void UBTBPageEditWidget::saveFields() { mpDataMgr->actions()->clear(); mpDataMgr->urls()->clear(); + mpDataMgr->mediaUrls().clear(); + mpDataMgr->medias()->clear(); foreach(UBTeacherStudentAction* pAct, mActions){ sAction action; @@ -183,6 +194,12 @@ void UBTBPageEditWidget::saveFields() link.link = pUrl->url(); mpDataMgr->urls()->append(link); } + foreach(QString url, mMediaUrls){ + mpDataMgr->mediaUrls().append(url); + } + foreach(QWidget* pMedia, mMedias){ + mpDataMgr->medias()->append(pMedia); + } } void UBTBPageEditWidget::updateFields() @@ -203,7 +220,7 @@ void UBTBPageEditWidget::updateFields() continue; QWidget* pWidget = mpMediaContainer->generateMediaWidget(url); if(pWidget != NULL){ - mpDataMgr->medias()->append(pWidget); + mMedias << pWidget; mpMediaContainer->addWidget(pWidget); } } @@ -221,6 +238,7 @@ void UBTBPageEditWidget::updateFields() void UBTBPageEditWidget::clearFields() { + mClearingFields = true; // Title mpTitle->setText(""); // Actions @@ -230,13 +248,14 @@ void UBTBPageEditWidget::clearFields() } mActions.clear(); // Medias - foreach(QWidget* pMedia, *mpDataMgr->medias()){ + foreach(QWidget* pMedia, mMedias){ if(NULL != pMedia){ mpMediaContainer->removeWidget(pMedia); DELETEPTR(pMedia); } } - mpDataMgr->mediaUrls().clear(); + mMedias.clear(); + mMediaUrls.clear(); // Links foreach(UBUrlWidget* pLink, mUrls){ mpLinks->removeWidget(pLink); @@ -245,6 +264,8 @@ void UBTBPageEditWidget::clearFields() mUrls.clear(); // Comments mpComments->setText(""); + + mClearingFields = false; } // --------------------------------------------------------------------------------------------- diff --git a/src/gui/UBTBPageEditWidget.h b/src/gui/UBTBPageEditWidget.h index fa56047d..0f3c61b9 100644 --- a/src/gui/UBTBPageEditWidget.h +++ b/src/gui/UBTBPageEditWidget.h @@ -133,6 +133,9 @@ private: QVector mActions; QVector mUrls; + QVector mMedias; + QStringList mMediaUrls; + bool mClearingFields; }; #endif // UBTBPAGEEDITWIDGET_H diff --git a/src/gui/UBTeacherBarPreviewWidget.cpp b/src/gui/UBTeacherBarPreviewWidget.cpp index 7d2ad585..9b7b136f 100644 --- a/src/gui/UBTeacherBarPreviewWidget.cpp +++ b/src/gui/UBTeacherBarPreviewWidget.cpp @@ -248,23 +248,13 @@ void UBTeacherBarPreviewWidget::onEdit() void UBTeacherBarPreviewWidget::updateFields() { - // First, remove the previous elements - if(!mStoredWidgets.empty()){ - foreach(QWidget* pW, mStoredWidgets){ - mpContentContainer->removeWidget(pW); - if( pW->objectName() == "UBActionPreview" || - pW->objectName() == "UBLinkPreview" || - pW->objectName() == "UBCommentsPreview"){ - // Here we delete all preview widget excepting the media because they are handled by the data manager - delete pW; - pW = NULL; - } - } - mStoredWidgets.clear(); - } - // Session Title - mpSessionTitle->setText(mpDataMgr->sessionTitle()); + if("" != mpDataMgr->sessionTitle()){ + mpSessionTitle->setText(mpDataMgr->sessionTitle()); + mpSessionTitle->setVisible(true); + }else{ + mpSessionTitle->setVisible(false); + } // Page Title if("" != mpDataMgr->pageTitle()){ @@ -279,7 +269,7 @@ void UBTeacherBarPreviewWidget::updateFields() generateActions(); // Media - generateMedias(); + //generateMedias(); // Links generateLinks(); @@ -291,7 +281,20 @@ void UBTeacherBarPreviewWidget::updateFields() void UBTeacherBarPreviewWidget::clearFields() { + // Session Title + mpSessionTitle->setText(""); + + // Page Title + mpTitle->setText(""); + // Medias + if(!mStoredWidgets.empty()){ + foreach(QWidget* pW, mStoredWidgets){ + mpContentContainer->removeWidget(pW); + DELETEPTR(pW); + } + mStoredWidgets.clear(); + } } void UBTeacherBarPreviewWidget::generateActions() @@ -309,10 +312,25 @@ void UBTeacherBarPreviewWidget::generateActions() void UBTeacherBarPreviewWidget::generateMedias() { - foreach(QWidget* pMedia, *mpDataMgr->medias()){ - if(NULL != pMedia){ - mpContentContainer->addWidget(pMedia); - mStoredWidgets << pMedia; + if(isVisible()){ + foreach(QString mediaUrl, mpDataMgr->mediaUrls()){ + QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(mediaUrl); + if(mimeType.contains("image")){ + QPixmap pix = QPixmap(mediaUrl); + QLabel* label = new QLabel(); + pix.scaledToWidth(label->width()); + label->resize(pix.width(), pix.height()); + label->setPixmap(pix); + label->setScaledContents(true); + mStoredWidgets << label; + mpContentContainer->addWidget(label); + } + else if(mimeType.contains("video") || mimeType.contains("audio")){ + UBMediaWidget* mediaPlayer = new UBMediaWidget(mimeType.contains("audio")?eMediaType_Audio:eMediaType_Video); + mediaPlayer->setFile(mediaUrl); + mStoredWidgets << mediaPlayer; + mpContentContainer->addWidget(mediaPlayer); + } } } } @@ -323,6 +341,7 @@ void UBTeacherBarPreviewWidget::generateLinks() foreach(sLink link, *mpDataMgr->urls()){ mpTmpLink = new QLabel(QString("%1").arg(link.link).arg(link.title), this); mpTmpLink->setObjectName("UBLinkPreview"); + mpTmpLink->setOpenExternalLinks(true); mpContentContainer->addWidget(mpTmpLink); mStoredWidgets << mpTmpLink; } @@ -340,3 +359,19 @@ void UBTeacherBarPreviewWidget::generateComments() mStoredWidgets << mpTmpComment; } } + +void UBTeacherBarPreviewWidget::showEvent(QShowEvent* ev) +{ + //updateFields(); +} + +// ----------------------------------------------------------------------------------------------------- +UBDraggableMedia::UBDraggableMedia(eMediaType type, QWidget *parent, const char *name):UBMediaWidget(type, parent, name) +{ + +} + +UBDraggableMedia::~UBDraggableMedia() +{ + +} diff --git a/src/gui/UBTeacherBarPreviewWidget.h b/src/gui/UBTeacherBarPreviewWidget.h index 882bfc01..36b75f38 100644 --- a/src/gui/UBTeacherBarPreviewWidget.h +++ b/src/gui/UBTeacherBarPreviewWidget.h @@ -8,6 +8,7 @@ #include "core/UBPersistenceManager.h" #include "customWidgets/UBWidgetList.h" +#include "customWidgets/UBMediaWidget.h" #include "UBTeacherBarDataMgr.h" class UBTeacherBarPreviewMedia : public QWidget @@ -56,6 +57,14 @@ public: ~UBTBPreviewSeparator(); }; +class UBDraggableMedia : public UBMediaWidget +{ +public: + UBDraggableMedia(eMediaType type = eMediaType_Video, QWidget* parent=0, const char* name="UBDraggableMedia"); + ~UBDraggableMedia(); + +}; + class UBTeacherBarPreviewWidget : public QWidget { Q_OBJECT @@ -68,6 +77,9 @@ public: signals: void showEditMode(); +protected: + void showEvent(QShowEvent* ev); + private slots: void onEdit(); void onActiveSceneChanged(); @@ -111,6 +123,8 @@ private: QLabel* mpTmpLink; /** A temporary comments field */ QTextEdit* mpTmpComment; + /** A temporary media object */ + UBDraggableMedia* mTmpMedia; }; #endif // UBTEACHERBARPREVIEWWIDGET_H diff --git a/src/gui/UBTeacherBarWidget.cpp b/src/gui/UBTeacherBarWidget.cpp index 322b3f91..1198fdd9 100644 --- a/src/gui/UBTeacherBarWidget.cpp +++ b/src/gui/UBTeacherBarWidget.cpp @@ -148,7 +148,7 @@ bool UBTeacherBarWidget::isEmpty() void UBTeacherBarWidget::onShowEditMode() { - mpStackWidget->setCurrentWidget(mpPageEditWidget); + onTBStateChanged(eTeacherBarState_PageEdit); } void UBTeacherBarWidget::onTBStateChanged(eTeacherBarState state) @@ -163,10 +163,13 @@ void UBTeacherBarWidget::onTBStateChanged(eTeacherBarState state) mpStackWidget->setCurrentWidget(mpDocPreviewWidget); break; case eTeacherBarState_PageEdit: + mpPageEditWidget->clearFields(); mpPageEditWidget->updateFields(); mpStackWidget->setCurrentWidget(mpPageEditWidget); break; case eTeacherBarState_PagePreview: + saveContent(); + mpPreview->clearFields(); mpPreview->updateFields(); mpStackWidget->setCurrentWidget(mpPreview); break;