Backuping some rework on the teacherbar

preferencesAboutTextFull
shibakaneki 13 years ago
parent 81e493ecce
commit b8e1516698
  1. 33
      src/gui/UBTBPageEditWidget.cpp
  2. 3
      src/gui/UBTBPageEditWidget.h
  3. 75
      src/gui/UBTeacherBarPreviewWidget.cpp
  4. 14
      src/gui/UBTeacherBarPreviewWidget.h
  5. 5
      src/gui/UBTeacherBarWidget.cpp

@ -29,7 +29,7 @@ UBTBPageEditWidget::UBTBPageEditWidget(UBTeacherBarDataMgr *pDataMgr, QWidget *p
mUrls.clear(); mUrls.clear();
setAttribute(Qt::WA_StyledBackground, true); setAttribute(Qt::WA_StyledBackground, true);
setStyleSheet(UBApplication::globalStyleSheet()); setStyleSheet(UBApplication::globalStyleSheet());
mClearingFields = false;
mLayout.setContentsMargins(0, 0, 0, 0); mLayout.setContentsMargins(0, 0, 0, 0);
setLayout(&mLayout); setLayout(&mLayout);
@ -120,14 +120,18 @@ UBTBPageEditWidget::~UBTBPageEditWidget()
void UBTBPageEditWidget::onTitleChanged() void UBTBPageEditWidget::onTitleChanged()
{ {
if(!mClearingFields){
mpDataMgr->setPageTitle(mpTitle->text()); mpDataMgr->setPageTitle(mpTitle->text());
emit valueChanged(); emit valueChanged();
}
} }
void UBTBPageEditWidget::onCommentsChanged() void UBTBPageEditWidget::onCommentsChanged()
{ {
if(!mClearingFields){
mpDataMgr->setComments(mpComments->document()->toPlainText()); mpDataMgr->setComments(mpComments->document()->toPlainText());
emit valueChanged(); emit valueChanged();
}
} }
void UBTBPageEditWidget::onActionButton() void UBTBPageEditWidget::onActionButton()
@ -135,6 +139,7 @@ void UBTBPageEditWidget::onActionButton()
UBTeacherStudentAction* pAction = new UBTeacherStudentAction(this); UBTeacherStudentAction* pAction = new UBTeacherStudentAction(this);
mActions << pAction; mActions << pAction;
mpActions->addWidget(pAction); mpActions->addWidget(pAction);
emit valueChanged();
} }
void UBTBPageEditWidget::onLinkButton() void UBTBPageEditWidget::onLinkButton()
@ -142,6 +147,7 @@ void UBTBPageEditWidget::onLinkButton()
UBUrlWidget* pUrl = new UBUrlWidget(this); UBUrlWidget* pUrl = new UBUrlWidget(this);
mUrls << pUrl; mUrls << pUrl;
mpLinks->addWidget(pUrl); mpLinks->addWidget(pUrl);
emit valueChanged();
} }
void UBTBPageEditWidget::onMediaDropped(const QString &url) void UBTBPageEditWidget::onMediaDropped(const QString &url)
@ -149,9 +155,12 @@ void UBTBPageEditWidget::onMediaDropped(const QString &url)
if("" != url){ if("" != url){
QWidget* pMedia = mpMediaContainer->generateMediaWidget(url); QWidget* pMedia = mpMediaContainer->generateMediaWidget(url);
if(NULL != pMedia){ if(NULL != pMedia){
mpDataMgr->medias()->append(pMedia); mMedias << pMedia;
mpDataMgr->addMediaUrl(url); mMediaUrls << url;
//mpDataMgr->medias()->append(pMedia);
//mpDataMgr->addMediaUrl(url);
mpMediaContainer->addWidget(pMedia); mpMediaContainer->addWidget(pMedia);
emit valueChanged();
} }
} }
} }
@ -170,6 +179,8 @@ void UBTBPageEditWidget::saveFields()
{ {
mpDataMgr->actions()->clear(); mpDataMgr->actions()->clear();
mpDataMgr->urls()->clear(); mpDataMgr->urls()->clear();
mpDataMgr->mediaUrls().clear();
mpDataMgr->medias()->clear();
foreach(UBTeacherStudentAction* pAct, mActions){ foreach(UBTeacherStudentAction* pAct, mActions){
sAction action; sAction action;
@ -183,6 +194,12 @@ void UBTBPageEditWidget::saveFields()
link.link = pUrl->url(); link.link = pUrl->url();
mpDataMgr->urls()->append(link); mpDataMgr->urls()->append(link);
} }
foreach(QString url, mMediaUrls){
mpDataMgr->mediaUrls().append(url);
}
foreach(QWidget* pMedia, mMedias){
mpDataMgr->medias()->append(pMedia);
}
} }
void UBTBPageEditWidget::updateFields() void UBTBPageEditWidget::updateFields()
@ -203,7 +220,7 @@ void UBTBPageEditWidget::updateFields()
continue; continue;
QWidget* pWidget = mpMediaContainer->generateMediaWidget(url); QWidget* pWidget = mpMediaContainer->generateMediaWidget(url);
if(pWidget != NULL){ if(pWidget != NULL){
mpDataMgr->medias()->append(pWidget); mMedias << pWidget;
mpMediaContainer->addWidget(pWidget); mpMediaContainer->addWidget(pWidget);
} }
} }
@ -221,6 +238,7 @@ void UBTBPageEditWidget::updateFields()
void UBTBPageEditWidget::clearFields() void UBTBPageEditWidget::clearFields()
{ {
mClearingFields = true;
// Title // Title
mpTitle->setText(""); mpTitle->setText("");
// Actions // Actions
@ -230,13 +248,14 @@ void UBTBPageEditWidget::clearFields()
} }
mActions.clear(); mActions.clear();
// Medias // Medias
foreach(QWidget* pMedia, *mpDataMgr->medias()){ foreach(QWidget* pMedia, mMedias){
if(NULL != pMedia){ if(NULL != pMedia){
mpMediaContainer->removeWidget(pMedia); mpMediaContainer->removeWidget(pMedia);
DELETEPTR(pMedia); DELETEPTR(pMedia);
} }
} }
mpDataMgr->mediaUrls().clear(); mMedias.clear();
mMediaUrls.clear();
// Links // Links
foreach(UBUrlWidget* pLink, mUrls){ foreach(UBUrlWidget* pLink, mUrls){
mpLinks->removeWidget(pLink); mpLinks->removeWidget(pLink);
@ -245,6 +264,8 @@ void UBTBPageEditWidget::clearFields()
mUrls.clear(); mUrls.clear();
// Comments // Comments
mpComments->setText(""); mpComments->setText("");
mClearingFields = false;
} }
// --------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------

@ -133,6 +133,9 @@ private:
QVector<UBTeacherStudentAction*> mActions; QVector<UBTeacherStudentAction*> mActions;
QVector<UBUrlWidget*> mUrls; QVector<UBUrlWidget*> mUrls;
QVector<QWidget*> mMedias;
QStringList mMediaUrls;
bool mClearingFields;
}; };
#endif // UBTBPAGEEDITWIDGET_H #endif // UBTBPAGEEDITWIDGET_H

@ -248,23 +248,13 @@ void UBTeacherBarPreviewWidget::onEdit()
void UBTeacherBarPreviewWidget::updateFields() 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 // Session Title
if("" != mpDataMgr->sessionTitle()){
mpSessionTitle->setText(mpDataMgr->sessionTitle()); mpSessionTitle->setText(mpDataMgr->sessionTitle());
mpSessionTitle->setVisible(true);
}else{
mpSessionTitle->setVisible(false);
}
// Page Title // Page Title
if("" != mpDataMgr->pageTitle()){ if("" != mpDataMgr->pageTitle()){
@ -279,7 +269,7 @@ void UBTeacherBarPreviewWidget::updateFields()
generateActions(); generateActions();
// Media // Media
generateMedias(); //generateMedias();
// Links // Links
generateLinks(); generateLinks();
@ -291,7 +281,20 @@ void UBTeacherBarPreviewWidget::updateFields()
void UBTeacherBarPreviewWidget::clearFields() 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() void UBTeacherBarPreviewWidget::generateActions()
@ -309,10 +312,25 @@ void UBTeacherBarPreviewWidget::generateActions()
void UBTeacherBarPreviewWidget::generateMedias() void UBTeacherBarPreviewWidget::generateMedias()
{ {
foreach(QWidget* pMedia, *mpDataMgr->medias()){ if(isVisible()){
if(NULL != pMedia){ foreach(QString mediaUrl, mpDataMgr->mediaUrls()){
mpContentContainer->addWidget(pMedia); QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(mediaUrl);
mStoredWidgets << pMedia; 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()){ foreach(sLink link, *mpDataMgr->urls()){
mpTmpLink = new QLabel(QString("<a href='%0'>%1</a>").arg(link.link).arg(link.title), this); mpTmpLink = new QLabel(QString("<a href='%0'>%1</a>").arg(link.link).arg(link.title), this);
mpTmpLink->setObjectName("UBLinkPreview"); mpTmpLink->setObjectName("UBLinkPreview");
mpTmpLink->setOpenExternalLinks(true);
mpContentContainer->addWidget(mpTmpLink); mpContentContainer->addWidget(mpTmpLink);
mStoredWidgets << mpTmpLink; mStoredWidgets << mpTmpLink;
} }
@ -340,3 +359,19 @@ void UBTeacherBarPreviewWidget::generateComments()
mStoredWidgets << mpTmpComment; mStoredWidgets << mpTmpComment;
} }
} }
void UBTeacherBarPreviewWidget::showEvent(QShowEvent* ev)
{
//updateFields();
}
// -----------------------------------------------------------------------------------------------------
UBDraggableMedia::UBDraggableMedia(eMediaType type, QWidget *parent, const char *name):UBMediaWidget(type, parent, name)
{
}
UBDraggableMedia::~UBDraggableMedia()
{
}

@ -8,6 +8,7 @@
#include "core/UBPersistenceManager.h" #include "core/UBPersistenceManager.h"
#include "customWidgets/UBWidgetList.h" #include "customWidgets/UBWidgetList.h"
#include "customWidgets/UBMediaWidget.h"
#include "UBTeacherBarDataMgr.h" #include "UBTeacherBarDataMgr.h"
class UBTeacherBarPreviewMedia : public QWidget class UBTeacherBarPreviewMedia : public QWidget
@ -56,6 +57,14 @@ public:
~UBTBPreviewSeparator(); ~UBTBPreviewSeparator();
}; };
class UBDraggableMedia : public UBMediaWidget
{
public:
UBDraggableMedia(eMediaType type = eMediaType_Video, QWidget* parent=0, const char* name="UBDraggableMedia");
~UBDraggableMedia();
};
class UBTeacherBarPreviewWidget : public QWidget class UBTeacherBarPreviewWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -68,6 +77,9 @@ public:
signals: signals:
void showEditMode(); void showEditMode();
protected:
void showEvent(QShowEvent* ev);
private slots: private slots:
void onEdit(); void onEdit();
void onActiveSceneChanged(); void onActiveSceneChanged();
@ -111,6 +123,8 @@ private:
QLabel* mpTmpLink; QLabel* mpTmpLink;
/** A temporary comments field */ /** A temporary comments field */
QTextEdit* mpTmpComment; QTextEdit* mpTmpComment;
/** A temporary media object */
UBDraggableMedia* mTmpMedia;
}; };
#endif // UBTEACHERBARPREVIEWWIDGET_H #endif // UBTEACHERBARPREVIEWWIDGET_H

@ -148,7 +148,7 @@ bool UBTeacherBarWidget::isEmpty()
void UBTeacherBarWidget::onShowEditMode() void UBTeacherBarWidget::onShowEditMode()
{ {
mpStackWidget->setCurrentWidget(mpPageEditWidget); onTBStateChanged(eTeacherBarState_PageEdit);
} }
void UBTeacherBarWidget::onTBStateChanged(eTeacherBarState state) void UBTeacherBarWidget::onTBStateChanged(eTeacherBarState state)
@ -163,10 +163,13 @@ void UBTeacherBarWidget::onTBStateChanged(eTeacherBarState state)
mpStackWidget->setCurrentWidget(mpDocPreviewWidget); mpStackWidget->setCurrentWidget(mpDocPreviewWidget);
break; break;
case eTeacherBarState_PageEdit: case eTeacherBarState_PageEdit:
mpPageEditWidget->clearFields();
mpPageEditWidget->updateFields(); mpPageEditWidget->updateFields();
mpStackWidget->setCurrentWidget(mpPageEditWidget); mpStackWidget->setCurrentWidget(mpPageEditWidget);
break; break;
case eTeacherBarState_PagePreview: case eTeacherBarState_PagePreview:
saveContent();
mpPreview->clearFields();
mpPreview->updateFields(); mpPreview->updateFields();
mpStackWidget->setCurrentWidget(mpPreview); mpStackWidget->setCurrentWidget(mpPreview);
break; break;

Loading…
Cancel
Save