parent
e82d5d880d
commit
93f69f80aa
@ -1,39 +0,0 @@ |
|||||||
#include <QMimeData> |
|
||||||
#include <QDrag> |
|
||||||
#include <QUrl> |
|
||||||
|
|
||||||
#include "UBDraggableLabel.h" |
|
||||||
|
|
||||||
|
|
||||||
UBDraggableLabel::UBDraggableLabel(QWidget *parent) : |
|
||||||
QLabel(parent) |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
UBDraggableLabel::~UBDraggableLabel() |
|
||||||
{ |
|
||||||
//NOOP
|
|
||||||
} |
|
||||||
|
|
||||||
void UBDraggableLabel::loadImage(QString imagePath) |
|
||||||
{ |
|
||||||
mSourcePath = imagePath; |
|
||||||
QPixmap pix = QPixmap(mSourcePath); |
|
||||||
setPixmap(pix); |
|
||||||
setScaledContents(true); |
|
||||||
} |
|
||||||
|
|
||||||
void UBDraggableLabel::mousePressEvent(QMouseEvent *event) |
|
||||||
{ |
|
||||||
Q_UNUSED(event); |
|
||||||
QMimeData *mimeData = new QMimeData; |
|
||||||
QList<QUrl> urls; |
|
||||||
urls << QUrl::fromLocalFile(mSourcePath); |
|
||||||
mimeData->setUrls(urls); |
|
||||||
mimeData->setText(mSourcePath); |
|
||||||
|
|
||||||
|
|
||||||
QDrag *drag = new QDrag(this); |
|
||||||
drag->setMimeData(mimeData); |
|
||||||
drag->start(); |
|
||||||
} |
|
@ -1,23 +0,0 @@ |
|||||||
#ifndef UBDRAGGABLELABEL_H |
|
||||||
#define UBDRAGGABLELABEL_H |
|
||||||
|
|
||||||
#include <QLabel> |
|
||||||
|
|
||||||
class UBDraggableLabel : public QLabel |
|
||||||
{ |
|
||||||
Q_OBJECT |
|
||||||
public: |
|
||||||
UBDraggableLabel(QWidget *parent = 0); |
|
||||||
~UBDraggableLabel(); |
|
||||||
void loadImage(QString imagePath); |
|
||||||
signals: |
|
||||||
|
|
||||||
public slots: |
|
||||||
|
|
||||||
protected: |
|
||||||
QString mSourcePath; |
|
||||||
void mousePressEvent(QMouseEvent *event); |
|
||||||
|
|
||||||
}; |
|
||||||
|
|
||||||
#endif // UBDRAGGABLELABEL_H
|
|
@ -1,42 +0,0 @@ |
|||||||
#include <QApplication> |
|
||||||
#include <QUrl> |
|
||||||
|
|
||||||
#include "UBDraggableMedia.h" |
|
||||||
|
|
||||||
UBDraggableMedia::UBDraggableMedia(eMediaType type, QWidget *parent, const char *name):UBMediaWidget(type, parent, name) |
|
||||||
{ |
|
||||||
removeAllActions(); |
|
||||||
} |
|
||||||
|
|
||||||
UBDraggableMedia::~UBDraggableMedia() |
|
||||||
{ |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
void UBDraggableMedia::mousePressEvent(QMouseEvent* ev) |
|
||||||
{ |
|
||||||
if(Qt::LeftButton == ev->button()){ |
|
||||||
mDragStartPos = ev->pos(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void UBDraggableMedia::mouseMoveEvent(QMouseEvent* ev) |
|
||||||
{ |
|
||||||
if(!(ev->buttons() & Qt::LeftButton)){ |
|
||||||
return; |
|
||||||
} |
|
||||||
if((ev->pos() - mDragStartPos).manhattanLength() < QApplication::startDragDistance()){ |
|
||||||
return; |
|
||||||
} |
|
||||||
QDrag *drag = new QDrag(this); |
|
||||||
QMimeData *mimeData = new QMimeData; |
|
||||||
|
|
||||||
QList<QUrl> urls; |
|
||||||
urls << QUrl(mFilePath); |
|
||||||
mimeData->setText(mFilePath); |
|
||||||
mimeData->setUrls(urls); |
|
||||||
|
|
||||||
drag->setMimeData(mimeData); |
|
||||||
|
|
||||||
drag->exec(Qt::CopyAction | Qt::MoveAction); |
|
||||||
} |
|
@ -1,19 +0,0 @@ |
|||||||
#ifndef UBDRAGGABLEMEDIA_H |
|
||||||
#define UBDRAGGABLEMEDIA_H |
|
||||||
|
|
||||||
#include "UBMediaWidget.h" |
|
||||||
|
|
||||||
class UBDraggableMedia : public UBMediaWidget |
|
||||||
{ |
|
||||||
public: |
|
||||||
UBDraggableMedia(eMediaType type = eMediaType_Video, QWidget* parent=0, const char* name="UBDraggableMedia"); |
|
||||||
~UBDraggableMedia(); |
|
||||||
protected: |
|
||||||
void mousePressEvent(QMouseEvent* ev); |
|
||||||
void mouseMoveEvent(QMouseEvent* ev); |
|
||||||
|
|
||||||
private: |
|
||||||
QPoint mDragStartPos; |
|
||||||
}; |
|
||||||
|
|
||||||
#endif // UBDRAGGABLEMEDIA_H
|
|
@ -1,13 +1,8 @@ |
|||||||
|
|
||||||
HEADERS += src/customWidgets/UBWidgetList.h \ |
HEADERS += src/customWidgets/UBWidgetList.h \ |
||||||
src/customWidgets/UBDraggableLabel.h \ |
|
||||||
src/customWidgets/UBMediaWidget.h \ |
src/customWidgets/UBMediaWidget.h \ |
||||||
src/globals/UBGlobals.h \ |
|
||||||
src/customWidgets/UBDraggableMedia.h \ |
|
||||||
src/customWidgets/UBActionableWidget.h |
src/customWidgets/UBActionableWidget.h |
||||||
|
|
||||||
SOURCES += src/customWidgets/UBWidgetList.cpp \ |
SOURCES += src/customWidgets/UBWidgetList.cpp \ |
||||||
src/customWidgets/UBDraggableLabel.cpp \ |
|
||||||
src/customWidgets/UBMediaWidget.cpp \ |
src/customWidgets/UBMediaWidget.cpp \ |
||||||
src/customWidgets/UBDraggableMedia.cpp \ |
|
||||||
src/customWidgets/UBActionableWidget.cpp |
src/customWidgets/UBActionableWidget.cpp |
||||||
|
@ -0,0 +1,45 @@ |
|||||||
|
/*
|
||||||
|
* This program is free software: you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU General Public License as published by |
||||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||||
|
* (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/ |
||||||
|
|
||||||
|
#include "core/UBApplication.h" |
||||||
|
#include "globals/UBGlobals.h" |
||||||
|
|
||||||
|
#include "UBDockTeacherGuideWidget.h" |
||||||
|
#include "UBTeacherGuideWidget.h" |
||||||
|
|
||||||
|
|
||||||
|
UBDockTeacherGuideWidget::UBDockTeacherGuideWidget(QWidget* parent, const char* name): |
||||||
|
UBDockPaletteWidget(parent,name) |
||||||
|
, mpTeacherGuideWidget(NULL) |
||||||
|
{ |
||||||
|
mName = "TeacherGuide"; |
||||||
|
|
||||||
|
setAttribute(Qt::WA_StyledBackground, true); |
||||||
|
setStyleSheet(UBApplication::globalStyleSheet()); |
||||||
|
|
||||||
|
mIconToLeft = QPixmap(":images/teacher_open.png"); |
||||||
|
mIconToRight = QPixmap(":images/teacher_close.png"); |
||||||
|
|
||||||
|
mpLayout = new QVBoxLayout(this); |
||||||
|
setLayout(mpLayout); |
||||||
|
mpTeacherGuideWidget = new UBTeacherGuideWidget(this); |
||||||
|
mpLayout->addWidget(mpTeacherGuideWidget); |
||||||
|
} |
||||||
|
|
||||||
|
UBDockTeacherGuideWidget::~UBDockTeacherGuideWidget() |
||||||
|
{ |
||||||
|
DELETEPTR(mpTeacherGuideWidget); |
||||||
|
DELETEPTR(mpLayout); |
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
/*
|
||||||
|
* This program is free software: you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU General Public License as published by |
||||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||||
|
* (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef UBDOCKTEACHERGUIDEWIDGET_H |
||||||
|
#define UBDOCKTEACHERGUIDEWIDGET_H |
||||||
|
|
||||||
|
class QVBoxLayout; |
||||||
|
class UBTeacherGuideWidget; |
||||||
|
|
||||||
|
#include "UBDockPaletteWidget.h" |
||||||
|
|
||||||
|
|
||||||
|
class UBDockTeacherGuideWidget : public UBDockPaletteWidget |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
public: |
||||||
|
UBDockTeacherGuideWidget(QWidget* parent=0, const char* name="UBDockTeacherGuideWidget"); |
||||||
|
~UBDockTeacherGuideWidget(); |
||||||
|
|
||||||
|
bool visibleInMode(eUBDockPaletteWidgetMode mode){ return mode == eUBDockPaletteWidget_BOARD; } |
||||||
|
|
||||||
|
private: |
||||||
|
QVBoxLayout* mpLayout; |
||||||
|
UBTeacherGuideWidget* mpTeacherGuideWidget; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif // UBDOCKTEACHERGUIDEWIDGET_H
|
@ -0,0 +1,5 @@ |
|||||||
|
#include "UBTeacherGuideDelegate.h" |
||||||
|
|
||||||
|
UBTeacherGuideDelegate::UBTeacherGuideDelegate() |
||||||
|
{ |
||||||
|
} |
@ -0,0 +1,10 @@ |
|||||||
|
#ifndef UBTEACHERGUIDEDELEGATE_H |
||||||
|
#define UBTEACHERGUIDEDELEGATE_H |
||||||
|
|
||||||
|
class UBTeacherGuideDelegate |
||||||
|
{ |
||||||
|
public: |
||||||
|
UBTeacherGuideDelegate(); |
||||||
|
}; |
||||||
|
|
||||||
|
#endif // UBTEACHERGUIDEDELEGATE_H
|
@ -0,0 +1,404 @@ |
|||||||
|
/*
|
||||||
|
* This program is free software: you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU General Public License as published by |
||||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||||
|
* (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/ |
||||||
|
|
||||||
|
#include <QDebug> |
||||||
|
#include <QLabel> |
||||||
|
#include <QVBoxLayout> |
||||||
|
#include <QHeaderView> |
||||||
|
#include <QTreeWidget> |
||||||
|
#include <QPushButton> |
||||||
|
|
||||||
|
#include "UBTeacherGuideWidget.h" |
||||||
|
|
||||||
|
#include "core/UBApplication.h" |
||||||
|
|
||||||
|
#include "globals/UBGlobals.h" |
||||||
|
|
||||||
|
#include "board/UBBoardController.h" |
||||||
|
#include "board/UBBoardView.h" |
||||||
|
#include "board/UBBoardPaletteManager.h" |
||||||
|
|
||||||
|
#include "gui/UBStylusPalette.h" |
||||||
|
#include "gui/UBActionPalette.h" |
||||||
|
|
||||||
|
#include "web/UBWebController.h" |
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{ |
||||||
|
eUBTGAddSubItemWidgetType_None, |
||||||
|
eUBTGAddSubItemWidgetType_Action , |
||||||
|
eUBTGAddSubItemWidgetType_Media, |
||||||
|
eUBTGAddSubItemWidgetType_Url |
||||||
|
}eUBTGAddSubItemWidgetType; |
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* class UBTeacherGuideEditionWidget * |
||||||
|
***************************************************************************/ |
||||||
|
|
||||||
|
UBTeacherGuideEditionWidget::UBTeacherGuideEditionWidget(QWidget *parent, const char* name) : |
||||||
|
QWidget(parent) |
||||||
|
, mpLayout(NULL) |
||||||
|
, mpDocumentTitle(NULL) |
||||||
|
, mpPageTitle(NULL) |
||||||
|
, mpComment(NULL) |
||||||
|
, mpTreeWidget(NULL) |
||||||
|
, mpRootWidgetItem(NULL) |
||||||
|
, mpAddAnActionItem(NULL) |
||||||
|
, mpAddAMediaItem(NULL) |
||||||
|
, mpAddALinkItem(NULL) |
||||||
|
{ |
||||||
|
setObjectName(name); |
||||||
|
|
||||||
|
mpLayout = new QVBoxLayout(this); |
||||||
|
// tree basic configuration
|
||||||
|
mpDocumentTitle = new QLabel(this); |
||||||
|
mpDocumentTitle->setText("title document"); |
||||||
|
mpDocumentTitle->setStyleSheet( "QWidget {background-color: white}"); |
||||||
|
mpLayout->addWidget(mpDocumentTitle); |
||||||
|
|
||||||
|
mpPageTitle = new UBTGAdaptableText(0,this); |
||||||
|
mpLayout->addWidget(mpPageTitle); |
||||||
|
|
||||||
|
mpComment = new UBTGAdaptableText(0,this); |
||||||
|
mpLayout->addWidget(mpComment); |
||||||
|
|
||||||
|
mpTreeWidget = new QTreeWidget(this); |
||||||
|
mpLayout->addWidget(mpTreeWidget); |
||||||
|
|
||||||
|
mpRootWidgetItem = mpTreeWidget->invisibleRootItem(); |
||||||
|
mpTreeWidget->setRootIsDecorated(false); |
||||||
|
mpTreeWidget->setIndentation(0); |
||||||
|
mpTreeWidget->setDropIndicatorShown(false); |
||||||
|
mpTreeWidget->header()->close(); |
||||||
|
mpTreeWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
||||||
|
connect(mpTreeWidget,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(onAddItemClicked(QTreeWidgetItem*,int))); |
||||||
|
|
||||||
|
mpAddAnActionItem = new UBAddItem(tr("Add an action"),eUBTGAddSubItemWidgetType_Action,mpTreeWidget); |
||||||
|
mpAddAMediaItem = new UBAddItem(tr("Add a media"),eUBTGAddSubItemWidgetType_Media,mpTreeWidget); |
||||||
|
mpAddALinkItem = new UBAddItem(tr("Add a link"),eUBTGAddSubItemWidgetType_Url,mpTreeWidget); |
||||||
|
|
||||||
|
mpRootWidgetItem->addChild(mpAddAnActionItem); |
||||||
|
mpRootWidgetItem->addChild(mpAddAMediaItem); |
||||||
|
mpRootWidgetItem->addChild(mpAddALinkItem); |
||||||
|
} |
||||||
|
|
||||||
|
UBTeacherGuideEditionWidget::~UBTeacherGuideEditionWidget() |
||||||
|
{ |
||||||
|
|
||||||
|
DELETEPTR(mpDocumentTitle); |
||||||
|
DELETEPTR(mpPageTitle); |
||||||
|
DELETEPTR(mpComment); |
||||||
|
DELETEPTR(mpAddAnActionItem); |
||||||
|
DELETEPTR(mpAddAMediaItem); |
||||||
|
DELETEPTR(mpAddALinkItem); |
||||||
|
DELETEPTR(mpTreeWidget) |
||||||
|
DELETEPTR(mpLayout); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
void UBTeacherGuideEditionWidget::cleanData() |
||||||
|
{ |
||||||
|
mpPageTitle->setText(""); |
||||||
|
mpComment->setText(""); |
||||||
|
QList<QTreeWidgetItem*> children = mpAddAnActionItem->takeChildren(); |
||||||
|
children << mpAddAMediaItem->takeChildren(); |
||||||
|
children << mpAddALinkItem->takeChildren(); |
||||||
|
|
||||||
|
foreach(QTreeWidgetItem* item, children){ |
||||||
|
DELETEPTR(item); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
QList<QTreeWidgetItem*> UBTeacherGuideEditionWidget::getChildrenList(QTreeWidgetItem* widgetItem) |
||||||
|
{ |
||||||
|
QList<QTreeWidgetItem*>result; |
||||||
|
for(int i=0;i<widgetItem->childCount();i+=1) |
||||||
|
result << widgetItem->child(i); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
QVector<tUBGEElementNode*> UBTeacherGuideEditionWidget::getPageAndCommentData() |
||||||
|
{ |
||||||
|
QVector<tUBGEElementNode*>result; |
||||||
|
tUBGEElementNode* pageTitle = new tUBGEElementNode(); |
||||||
|
pageTitle->type = "pageTitle"; |
||||||
|
pageTitle->attributes.insert("value",mpPageTitle->toPlainText()); |
||||||
|
result << pageTitle; |
||||||
|
|
||||||
|
tUBGEElementNode* comment = new tUBGEElementNode(); |
||||||
|
comment->type = "comment"; |
||||||
|
comment->attributes.insert("value",mpComment->toPlainText()); |
||||||
|
result << comment; |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
QVector<tUBGEElementNode*> UBTeacherGuideEditionWidget::getData() |
||||||
|
{ |
||||||
|
QVector<tUBGEElementNode*>result; |
||||||
|
QList<QTreeWidgetItem*> children = getChildrenList(mpAddAnActionItem); |
||||||
|
children << getChildrenList(mpAddAMediaItem); |
||||||
|
children << getChildrenList(mpAddALinkItem); |
||||||
|
result << getPageAndCommentData(); |
||||||
|
foreach(QTreeWidgetItem* widgetItem, children){ |
||||||
|
result << dynamic_cast<iUBTGSavableData*>(mpTreeWidget->itemWidget(widgetItem,0))->saveData(); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
void UBTeacherGuideEditionWidget::onAddItemClicked(QTreeWidgetItem* widget, int column) |
||||||
|
{ |
||||||
|
int addSubItemWidgetType = widget->data(column,Qt::UserRole).toInt(); |
||||||
|
if(column == 0 && addSubItemWidgetType != eUBTGAddSubItemWidgetType_None){ |
||||||
|
QTreeWidgetItem* newWidgetItem = new QTreeWidgetItem(widget); |
||||||
|
newWidgetItem->setData(column,Qt::UserRole,eUBTGAddSubItemWidgetType_None); |
||||||
|
switch(addSubItemWidgetType) |
||||||
|
{ |
||||||
|
case eUBTGAddSubItemWidgetType_Action: |
||||||
|
mpTreeWidget->setItemWidget(newWidgetItem,0,new UBTGActionWidget(widget)); |
||||||
|
break; |
||||||
|
case eUBTGAddSubItemWidgetType_Media: |
||||||
|
mpTreeWidget->setItemWidget(newWidgetItem,0,new UBTGMediaWidget(widget)); |
||||||
|
break; |
||||||
|
case eUBTGAddSubItemWidgetType_Url: |
||||||
|
mpTreeWidget->setItemWidget(newWidgetItem,0,new UBTGUrlWidget()); |
||||||
|
break; |
||||||
|
default: |
||||||
|
qDebug() << "onAddItemClicked no action set"; |
||||||
|
} |
||||||
|
|
||||||
|
if(addSubItemWidgetType != eUBTGAddSubItemWidgetType_None && !widget->isExpanded() ) |
||||||
|
widget->setExpanded(true); |
||||||
|
else{ |
||||||
|
//to update the tree and subtrees
|
||||||
|
widget->setExpanded(false); |
||||||
|
widget->setExpanded(true); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* class UBTeacherGuidePresentationWidget * |
||||||
|
***************************************************************************/ |
||||||
|
typedef enum
|
||||||
|
{ |
||||||
|
tUBTGActionAssociateOnClickItem_NONE, |
||||||
|
tUBTGActionAssociateOnClickItem_URL, |
||||||
|
tUBTGActionAssociateOnClickItem_MEDIA, |
||||||
|
tUBTGActionAssociateOnClickItem_EXPAND |
||||||
|
}tUBTGActionAssociateOnClickItem; |
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{ |
||||||
|
tUBTGTreeWidgetItemRole_HasAnAction = Qt::UserRole, |
||||||
|
tUBTGTreeWidgetItemRole_HasAnUrl |
||||||
|
}tUBTGTreeWidgetItemRole; |
||||||
|
|
||||||
|
|
||||||
|
UBTeacherGuidePresentationWidget::UBTeacherGuidePresentationWidget(QWidget *parent, const char *name) : QWidget(parent) |
||||||
|
, mpPageTitle(NULL) |
||||||
|
, mpComment(NULL) |
||||||
|
, mpLayout(NULL) |
||||||
|
, mpButtonTitleLayout(NULL) |
||||||
|
, mpDocumentTile(NULL) |
||||||
|
, mpModePushButton(NULL) |
||||||
|
, mpTreeWidget(NULL) |
||||||
|
, mpRootWidgetItem(NULL) |
||||||
|
, mpMediaSwitchItem(NULL) |
||||||
|
{ |
||||||
|
setObjectName(name); |
||||||
|
mpLayout = new QVBoxLayout(this); |
||||||
|
mpButtonTitleLayout = new QHBoxLayout(0); |
||||||
|
|
||||||
|
mpModePushButton = new QPushButton(this); |
||||||
|
mpModePushButton->setIcon(QIcon(":images/pencil.svg")); |
||||||
|
connect(mpModePushButton,SIGNAL(clicked()),parentWidget(),SLOT(changeMode())); |
||||||
|
|
||||||
|
mpDocumentTile = new QLabel(this); |
||||||
|
mpDocumentTile->setText("Document title"); |
||||||
|
|
||||||
|
mpButtonTitleLayout->addWidget(mpModePushButton); |
||||||
|
mpButtonTitleLayout->addWidget(mpDocumentTile); |
||||||
|
|
||||||
|
mpLayout->addLayout(mpButtonTitleLayout); |
||||||
|
|
||||||
|
mpPageTitle = new UBTGAdaptableText(0,this); |
||||||
|
mpPageTitle->setReadOnly(true); |
||||||
|
mpLayout->addWidget(mpPageTitle); |
||||||
|
|
||||||
|
mpComment = new UBTGAdaptableText(0,this); |
||||||
|
mpComment->setReadOnly(true); |
||||||
|
mpLayout->addWidget(mpComment); |
||||||
|
|
||||||
|
mpTreeWidget = new QTreeWidget(this); |
||||||
|
mpLayout->addWidget(mpTreeWidget); |
||||||
|
|
||||||
|
mpRootWidgetItem = mpTreeWidget->invisibleRootItem(); |
||||||
|
mpTreeWidget->setRootIsDecorated(false); |
||||||
|
mpTreeWidget->setIndentation(0); |
||||||
|
mpTreeWidget->setDropIndicatorShown(false); |
||||||
|
mpTreeWidget->header()->close(); |
||||||
|
mpTreeWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
||||||
|
connect(mpTreeWidget,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(onAddItemClicked(QTreeWidgetItem*,int))); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
UBTeacherGuidePresentationWidget::~UBTeacherGuidePresentationWidget() |
||||||
|
{ |
||||||
|
DELETEPTR(mpComment); |
||||||
|
DELETEPTR(mpPageTitle); |
||||||
|
DELETEPTR(mpMediaSwitchItem); |
||||||
|
DELETEPTR(mpModePushButton); |
||||||
|
DELETEPTR(mpDocumentTile); |
||||||
|
DELETEPTR(mpButtonTitleLayout); |
||||||
|
DELETEPTR(mpTreeWidget); |
||||||
|
DELETEPTR(mpLayout); |
||||||
|
} |
||||||
|
|
||||||
|
void UBTeacherGuidePresentationWidget::createMediaButtonItem() |
||||||
|
{ |
||||||
|
if(!mpMediaSwitchItem){ |
||||||
|
//create the media button
|
||||||
|
mpMediaSwitchItem = new QTreeWidgetItem(mpRootWidgetItem); |
||||||
|
mpMediaSwitchItem->setIcon(0,QIcon(":images/plus.svg")); |
||||||
|
mpMediaSwitchItem->setExpanded(false); |
||||||
|
mpMediaSwitchItem->setData(0,tUBTGTreeWidgetItemRole_HasAnAction,tUBTGActionAssociateOnClickItem_EXPAND); |
||||||
|
mpRootWidgetItem->addChild(mpMediaSwitchItem); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
void UBTeacherGuidePresentationWidget::showData(QVector<tUBGEElementNode*> data) |
||||||
|
{ |
||||||
|
//tree clean
|
||||||
|
QList<QTreeWidgetItem*> itemToRemove = mpRootWidgetItem->takeChildren(); |
||||||
|
foreach(QTreeWidgetItem* eachItem, itemToRemove){ |
||||||
|
DELETEPTR(eachItem); |
||||||
|
} |
||||||
|
// the mpMediaSwitchItem is deleted by the previous loop but the pointer is not set to zero
|
||||||
|
mpMediaSwitchItem = NULL; |
||||||
|
|
||||||
|
foreach(tUBGEElementNode* element, data){ |
||||||
|
if(element->type == "pageTitle") |
||||||
|
mpPageTitle->showText(element->attributes.value("value")); |
||||||
|
else if (element->type == "comment") |
||||||
|
mpComment->showText(element->attributes.value("value")); |
||||||
|
else if(element->type == "action"){ |
||||||
|
QTreeWidgetItem* newWidgetItem = new QTreeWidgetItem(mpRootWidgetItem); |
||||||
|
newWidgetItem->setText(0,element->attributes.value("task")); |
||||||
|
QColor color = element->attributes.value("owner").toInt()?QColor().red():QColor().green(); |
||||||
|
newWidgetItem->setTextColor(0,color); |
||||||
|
newWidgetItem->setData(0,tUBTGTreeWidgetItemRole_HasAnAction,tUBTGActionAssociateOnClickItem_NONE); |
||||||
|
mpRootWidgetItem->addChild(newWidgetItem); |
||||||
|
} |
||||||
|
else if(element->type == "media"){ |
||||||
|
createMediaButtonItem(); |
||||||
|
QTreeWidgetItem* newWidgetItem = new QTreeWidgetItem(mpMediaSwitchItem); |
||||||
|
newWidgetItem->setText(0,element->attributes.value("title")); |
||||||
|
newWidgetItem->setData(0,tUBTGTreeWidgetItemRole_HasAnAction,tUBTGActionAssociateOnClickItem_MEDIA); |
||||||
|
mpRootWidgetItem->addChild(newWidgetItem); |
||||||
|
|
||||||
|
QTreeWidgetItem* mediaItem = new QTreeWidgetItem(newWidgetItem); |
||||||
|
mediaItem->setText(0,element->attributes.value("title")); |
||||||
|
mediaItem->setData(0,tUBTGTreeWidgetItemRole_HasAnAction,tUBTGActionAssociateOnClickItem_NONE); |
||||||
|
UBTGMediaWidget* mediaWidget = new UBTGMediaWidget(element->attributes.value("relativePath"),newWidgetItem); |
||||||
|
newWidgetItem->setExpanded(false); |
||||||
|
mpTreeWidget->setItemWidget(mediaItem,0,mediaWidget); |
||||||
|
} |
||||||
|
else if(element->type == "link"){ |
||||||
|
createMediaButtonItem(); |
||||||
|
QTreeWidgetItem* newWidgetItem = new QTreeWidgetItem(mpMediaSwitchItem); |
||||||
|
newWidgetItem->setText(0,element->attributes.value("title")); |
||||||
|
newWidgetItem->setData(0,tUBTGTreeWidgetItemRole_HasAnAction,tUBTGActionAssociateOnClickItem_URL); |
||||||
|
newWidgetItem->setData(0,tUBTGTreeWidgetItemRole_HasAnUrl,QVariant(element->attributes.value("url"))); |
||||||
|
mpRootWidgetItem->addChild(newWidgetItem); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
void UBTeacherGuidePresentationWidget::onAddItemClicked(QTreeWidgetItem* widget, int column) |
||||||
|
{ |
||||||
|
int associateAction = widget->data(column,tUBTGTreeWidgetItemRole_HasAnAction).toInt(); |
||||||
|
if(column == 0 && associateAction != tUBTGActionAssociateOnClickItem_NONE){ |
||||||
|
switch(associateAction) |
||||||
|
{ |
||||||
|
case tUBTGActionAssociateOnClickItem_EXPAND: |
||||||
|
widget->setExpanded(!widget->isExpanded()); |
||||||
|
break; |
||||||
|
case tUBTGActionAssociateOnClickItem_URL: |
||||||
|
widget->data(column,tUBTGTreeWidgetItemRole_HasAnUrl).toString(); |
||||||
|
UBApplication::webController->loadUrl(QUrl(widget->data(column,tUBTGTreeWidgetItemRole_HasAnUrl).toString())); |
||||||
|
break; |
||||||
|
case tUBTGActionAssociateOnClickItem_MEDIA: |
||||||
|
widget->setExpanded(!widget->isExpanded()); |
||||||
|
break; |
||||||
|
default: |
||||||
|
qDebug() << "associateAction no action set " << associateAction; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* class UBTeacherGuideWidget * |
||||||
|
***************************************************************************/ |
||||||
|
UBTeacherGuideWidget::UBTeacherGuideWidget(QWidget *parent, const char *name): QStackedWidget(parent) |
||||||
|
, mpEditionWidget(NULL) |
||||||
|
, mpPresentationWidget(NULL) |
||||||
|
{ |
||||||
|
setObjectName(name); |
||||||
|
mpEditionWidget = new UBTeacherGuideEditionWidget(this); |
||||||
|
addWidget(mpEditionWidget); |
||||||
|
mpPresentationWidget = new UBTeacherGuidePresentationWidget(this); |
||||||
|
addWidget(mpPresentationWidget); |
||||||
|
|
||||||
|
setCurrentWidget(mpEditionWidget); |
||||||
|
connect(UBApplication::boardController->controlView(),SIGNAL(clickOnBoard()),this,SLOT(showPresentationMode())); |
||||||
|
connectToStylusPalette(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
UBTeacherGuideWidget::~UBTeacherGuideWidget() |
||||||
|
{ |
||||||
|
DELETEPTR(mpEditionWidget); |
||||||
|
DELETEPTR(mpPresentationWidget); |
||||||
|
} |
||||||
|
|
||||||
|
void UBTeacherGuideWidget::connectToStylusPalette() |
||||||
|
{ |
||||||
|
if(UBApplication::boardController->paletteManager()) |
||||||
|
connect(UBApplication::boardController->paletteManager()->stylusPalette(),SIGNAL(itemOnActionPaletteChanged()),this,SLOT(showPresentationMode())); |
||||||
|
else |
||||||
|
QTimer::singleShot(500,this,SLOT(connectToStylusPalette())); |
||||||
|
} |
||||||
|
|
||||||
|
void UBTeacherGuideWidget::showPresentationMode() |
||||||
|
{ |
||||||
|
if(currentWidget()!=mpPresentationWidget){ |
||||||
|
currentData = mpEditionWidget->getData(); |
||||||
|
mpPresentationWidget->showData(currentData); |
||||||
|
setCurrentWidget(mpPresentationWidget); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void UBTeacherGuideWidget::changeMode() |
||||||
|
{ |
||||||
|
if(currentWidget() == mpEditionWidget) |
||||||
|
setCurrentWidget(mpPresentationWidget); |
||||||
|
else |
||||||
|
setCurrentWidget(mpEditionWidget); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,114 @@ |
|||||||
|
/*
|
||||||
|
* This program is free software: you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU General Public License as published by |
||||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||||
|
* (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef UBTEACHERGUIDEWIDGET_H |
||||||
|
#define UBTEACHERGUIDEWIDGET_H |
||||||
|
|
||||||
|
class QTreeWidget; |
||||||
|
class QHeaderView; |
||||||
|
class QLabel; |
||||||
|
class QVBoxLayout; |
||||||
|
class QPushButton; |
||||||
|
|
||||||
|
#include "UBTeacherGuideWidgetsTools.h" |
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* class UBTeacherGuideEditionWidget * |
||||||
|
***************************************************************************/ |
||||||
|
class UBTeacherGuideEditionWidget : public QWidget |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
public: |
||||||
|
explicit UBTeacherGuideEditionWidget(QWidget* parent = 0, const char* name="UBTeacherGuideEditionWidget"); |
||||||
|
~UBTeacherGuideEditionWidget(); |
||||||
|
void cleanData(); |
||||||
|
QVector<tUBGEElementNode*> getData(); |
||||||
|
|
||||||
|
public slots: |
||||||
|
void onAddItemClicked(QTreeWidgetItem* widget, int column); |
||||||
|
|
||||||
|
private: |
||||||
|
QList<QTreeWidgetItem*> getChildrenList(QTreeWidgetItem* widgetItem); |
||||||
|
QVector<tUBGEElementNode*> getPageAndCommentData(); |
||||||
|
|
||||||
|
QVBoxLayout* mpLayout; |
||||||
|
QLabel* mpDocumentTitle; |
||||||
|
UBTGAdaptableText* mpPageTitle; |
||||||
|
UBTGAdaptableText* mpComment; |
||||||
|
QTreeWidget* mpTreeWidget; |
||||||
|
QTreeWidgetItem* mpRootWidgetItem; |
||||||
|
UBAddItem* mpAddAnActionItem; |
||||||
|
UBAddItem* mpAddAMediaItem; |
||||||
|
UBAddItem* mpAddALinkItem; |
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* class UBTeacherGuidePresentationWidget * |
||||||
|
***************************************************************************/ |
||||||
|
class UBTeacherGuidePresentationWidget : public QWidget |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
public: |
||||||
|
explicit UBTeacherGuidePresentationWidget(QWidget* parent, const char* name = "UBTeacherGuidePresentationName"); |
||||||
|
~UBTeacherGuidePresentationWidget(); |
||||||
|
void showData(QVector<tUBGEElementNode*>data); |
||||||
|
|
||||||
|
public slots: |
||||||
|
void onAddItemClicked(QTreeWidgetItem* widget, int column); |
||||||
|
|
||||||
|
private: |
||||||
|
void createMediaButtonItem(); |
||||||
|
|
||||||
|
UBTGAdaptableText* mpPageTitle; |
||||||
|
UBTGAdaptableText* mpComment; |
||||||
|
QVBoxLayout* mpLayout; |
||||||
|
QHBoxLayout* mpButtonTitleLayout; |
||||||
|
QLabel* mpDocumentTile; |
||||||
|
QPushButton* mpModePushButton; |
||||||
|
QTreeWidget* mpTreeWidget; |
||||||
|
QTreeWidgetItem* mpRootWidgetItem; |
||||||
|
QTreeWidgetItem* mpMediaSwitchItem; |
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* class UBTeacherGuideWidget * |
||||||
|
***************************************************************************/ |
||||||
|
|
||||||
|
class UBTeacherGuideWidget : public QStackedWidget |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
public: |
||||||
|
explicit UBTeacherGuideWidget(QWidget* parent = 0, const char* name="UBTeacherGuideWidget"); |
||||||
|
~UBTeacherGuideWidget(); |
||||||
|
|
||||||
|
public slots: |
||||||
|
void changeMode(); |
||||||
|
void showPresentationMode(); |
||||||
|
void connectToStylusPalette(); |
||||||
|
|
||||||
|
private: |
||||||
|
UBTeacherGuideEditionWidget* mpEditionWidget; |
||||||
|
UBTeacherGuidePresentationWidget* mpPresentationWidget; |
||||||
|
QVector<tUBGEElementNode*>currentData; |
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
#endif // UBTEACHERGUIDEWIDGET_H
|
@ -0,0 +1,361 @@ |
|||||||
|
/*
|
||||||
|
* This program is free software: you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU General Public License as published by |
||||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||||
|
* (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/ |
||||||
|
|
||||||
|
#include <QTreeWidget> |
||||||
|
#include <QVBoxLayout> |
||||||
|
#include <QComboBox> |
||||||
|
#include <QColor> |
||||||
|
#include <QLabel> |
||||||
|
#include <QDebug> |
||||||
|
#include <QUrl> |
||||||
|
#include <QWebSettings> |
||||||
|
#include <QDomElement> |
||||||
|
#include <QDomDocument> |
||||||
|
|
||||||
|
#include "UBTeacherGuideWidgetsTools.h" |
||||||
|
|
||||||
|
#include "globals/UBGlobals.h" |
||||||
|
|
||||||
|
#include "frameworks/UBFileSystemUtils.h" |
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* class UBAddItem * |
||||||
|
***************************************************************************/ |
||||||
|
UBAddItem::UBAddItem(const QString &string, int addSubItemWidgetType, QTreeWidget* parent): QTreeWidgetItem(parent) |
||||||
|
{ |
||||||
|
setIcon(0,QIcon(":images/increase.svg")); |
||||||
|
setText(0,string); |
||||||
|
setData(0,Qt::UserRole,QVariant(addSubItemWidgetType)); |
||||||
|
} |
||||||
|
|
||||||
|
UBAddItem::~UBAddItem() |
||||||
|
{ |
||||||
|
//NOOP
|
||||||
|
} |
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* class UBTGActionWidget * |
||||||
|
***************************************************************************/ |
||||||
|
UBTGActionWidget::UBTGActionWidget(QTreeWidgetItem* widget, QWidget* parent, const char* name) : QWidget(parent) |
||||||
|
, mpLayout(NULL) |
||||||
|
, mpOwner(NULL) |
||||||
|
, mpTask(NULL) |
||||||
|
{ |
||||||
|
setObjectName(name); |
||||||
|
mpLayout = new QVBoxLayout(this); |
||||||
|
mpOwner = new QComboBox(this); |
||||||
|
QStringList qslOwner; |
||||||
|
qslOwner << tr("Teacher") << tr("Student"); |
||||||
|
mpOwner->insertItems(0,qslOwner); |
||||||
|
mpOwner->setCurrentIndex(0); |
||||||
|
connect(mpOwner,SIGNAL(currentIndexChanged(int)),this,SLOT(onOwnerChange(int))); |
||||||
|
mpTask = new UBTGAdaptableText(widget,this); |
||||||
|
mpTask->setAcceptRichText(true); |
||||||
|
mpTask->setTextColor(QColor().green()); |
||||||
|
mpTask->setObjectName("ActionWidgetTaskTextEdit"); |
||||||
|
mpLayout->addWidget(mpOwner,0); |
||||||
|
mpLayout->addWidget(mpTask,1); |
||||||
|
setStyleSheet( "QWidget {background-color: white}"); |
||||||
|
} |
||||||
|
|
||||||
|
UBTGActionWidget::~UBTGActionWidget() |
||||||
|
{ |
||||||
|
DELETEPTR(mpOwner); |
||||||
|
DELETEPTR(mpTask); |
||||||
|
DELETEPTR(mpLayout); |
||||||
|
} |
||||||
|
|
||||||
|
void UBTGActionWidget::onOwnerChange(int ownerId) |
||||||
|
{ |
||||||
|
if(ownerId == 0) |
||||||
|
mpTask->setTextColor(QColor().red()); |
||||||
|
else |
||||||
|
mpTask->setTextColor(QColor().green()); |
||||||
|
} |
||||||
|
|
||||||
|
tUBGEElementNode* UBTGActionWidget::saveData() |
||||||
|
{ |
||||||
|
tUBGEElementNode* result = new tUBGEElementNode(); |
||||||
|
result->type = "action"; |
||||||
|
result->attributes.insert("owner",QString(mpOwner->currentIndex())); |
||||||
|
result->attributes.insert("task",mpTask->toPlainText()); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* class UBTGAdaptableText * |
||||||
|
***************************************************************************/ |
||||||
|
UBTGAdaptableText::UBTGAdaptableText(QTreeWidgetItem* widget, QWidget* parent, const char* name):QTextEdit(parent) |
||||||
|
, mBottomMargin(5) |
||||||
|
, mpTreeWidgetItem(widget) |
||||||
|
{ |
||||||
|
setObjectName(name); |
||||||
|
setStyleSheet( "QWidget {background-color: white}"); |
||||||
|
connect(this,SIGNAL(textChanged()),this,SLOT(onTextChanged())); |
||||||
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
||||||
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
||||||
|
} |
||||||
|
|
||||||
|
void UBTGAdaptableText::onTextChanged() |
||||||
|
{ |
||||||
|
setFixedHeight(document()->size().height()+mBottomMargin); |
||||||
|
updateGeometry(); |
||||||
|
//to trig the widget item to resize it
|
||||||
|
if(mpTreeWidgetItem){ |
||||||
|
mpTreeWidgetItem->setExpanded(false); |
||||||
|
mpTreeWidgetItem->setExpanded(true); |
||||||
|
setFocus(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
void UBTGAdaptableText::showText(const QString & text) |
||||||
|
{ |
||||||
|
setText(text); |
||||||
|
//A first rendering has to be done to calculate the text's size.
|
||||||
|
show(); |
||||||
|
hide(); |
||||||
|
setReadOnly(true); |
||||||
|
onTextChanged(); |
||||||
|
} |
||||||
|
|
||||||
|
void UBTGAdaptableText::bottomMargin(int newValue) |
||||||
|
{ |
||||||
|
mBottomMargin = newValue; |
||||||
|
onTextChanged(); |
||||||
|
} |
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* class UBTGMediaWidget * |
||||||
|
***************************************************************************/ |
||||||
|
UBTGMediaWidget::UBTGMediaWidget(QTreeWidgetItem* widget, QWidget* parent,const char* name): QStackedWidget(parent) |
||||||
|
, mpTreeWidgetItem(widget) |
||||||
|
, mpDropMeWidget(NULL) |
||||||
|
, mpWorkWidget(NULL) |
||||||
|
, mpLayout(NULL) |
||||||
|
, mpTitle(NULL) |
||||||
|
, mpMediaLabelWidget(NULL) |
||||||
|
, mpMediaWidget(NULL) |
||||||
|
, mpWebView(NULL) |
||||||
|
, mRelativePath(QString("")) |
||||||
|
, mIsPresentationMode(false) |
||||||
|
{ |
||||||
|
setObjectName(name); |
||||||
|
setStyleSheet( "QWidget {background-color: white}"); |
||||||
|
mpDropMeWidget = new QLabel(); |
||||||
|
mpDropMeWidget->setText(tr("drop media here ...")); |
||||||
|
mpDropMeWidget->setAlignment(Qt::AlignCenter); |
||||||
|
setAcceptDrops(true); |
||||||
|
addWidget(mpDropMeWidget); |
||||||
|
|
||||||
|
setMinimumHeight(40); |
||||||
|
} |
||||||
|
|
||||||
|
UBTGMediaWidget::UBTGMediaWidget(QString relativePath, QTreeWidgetItem* widget, QWidget* parent,const char* name): QStackedWidget(parent) |
||||||
|
, mpTreeWidgetItem(widget) |
||||||
|
, mpDropMeWidget(NULL) |
||||||
|
, mpWorkWidget(NULL) |
||||||
|
, mpLayout(NULL) |
||||||
|
, mpTitle(NULL) |
||||||
|
, mpMediaLabelWidget(NULL) |
||||||
|
, mpMediaWidget(NULL) |
||||||
|
, mpWebView(NULL) |
||||||
|
, mRelativePath(relativePath) |
||||||
|
, mIsPresentationMode(true) |
||||||
|
{ |
||||||
|
setObjectName(name); |
||||||
|
setAcceptDrops(false); |
||||||
|
createWorkWidget(mRelativePath); |
||||||
|
} |
||||||
|
|
||||||
|
UBTGMediaWidget::~UBTGMediaWidget() |
||||||
|
{ |
||||||
|
DELETEPTR(mpTitle); |
||||||
|
DELETEPTR(mpMediaLabelWidget); |
||||||
|
DELETEPTR(mpMediaWidget); |
||||||
|
DELETEPTR(mpWebView); |
||||||
|
DELETEPTR(mpLayout); |
||||||
|
|
||||||
|
removeWidget(mpDropMeWidget); |
||||||
|
DELETEPTR(mpDropMeWidget); |
||||||
|
removeWidget(mpWorkWidget); |
||||||
|
DELETEPTR(mpWorkWidget); |
||||||
|
} |
||||||
|
|
||||||
|
tUBGEElementNode* UBTGMediaWidget::saveData() |
||||||
|
{ |
||||||
|
tUBGEElementNode* result = new tUBGEElementNode(); |
||||||
|
result->type = "media"; |
||||||
|
result->attributes.insert("title",mpTitle->toPlainText()); |
||||||
|
result->attributes.insert("relativePath",mRelativePath); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
void UBTGMediaWidget::dragEnterEvent(QDragEnterEvent *event) |
||||||
|
{ |
||||||
|
event->accept(); |
||||||
|
} |
||||||
|
|
||||||
|
void UBTGMediaWidget::createWorkWidget(QString& path) |
||||||
|
{ |
||||||
|
QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(path); |
||||||
|
qDebug() << mimeType; |
||||||
|
bool setMedia = true; |
||||||
|
if(mimeType.contains("audio") || mimeType.contains("video")){ |
||||||
|
mpMediaWidget = new UBMediaWidget(mimeType.contains("audio")?eMediaType_Audio:eMediaType_Video); |
||||||
|
mpMediaWidget->setFile(path); |
||||||
|
} |
||||||
|
else if(mimeType.contains("image")){ |
||||||
|
mpMediaLabelWidget = new QLabel(); |
||||||
|
mpMediaLabelWidget->setPixmap(QPixmap(QUrl(path).toLocalFile())); |
||||||
|
mpMediaLabelWidget->setScaledContents(true); |
||||||
|
} |
||||||
|
else if(mimeType.contains("application")){ |
||||||
|
mpWebView = new QWebView(0); |
||||||
|
mpWebView->setAcceptDrops(false); |
||||||
|
mpWebView->settings()->setAttribute(QWebSettings::JavaEnabled, true); |
||||||
|
mpWebView->settings()->setAttribute(QWebSettings::PluginsEnabled, true); |
||||||
|
mpWebView->settings()->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, true); |
||||||
|
mpWebView->settings()->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true); |
||||||
|
mpWebView->settings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true); |
||||||
|
mpWebView->settings()->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true); |
||||||
|
mpWebView->settings()->setAttribute(QWebSettings::DnsPrefetchEnabled, true); |
||||||
|
mpWebView->load(QUrl(path)); |
||||||
|
mpWebView->show(); |
||||||
|
} |
||||||
|
else{ |
||||||
|
qDebug() << "createWorkWidget mime type not handled" << mimeType; |
||||||
|
setMedia=false; |
||||||
|
} |
||||||
|
|
||||||
|
if(setMedia){ |
||||||
|
mRelativePath = path; |
||||||
|
setAcceptDrops(false); |
||||||
|
mpWorkWidget = new QWidget(this); |
||||||
|
mpLayout = new QVBoxLayout(mpWorkWidget); |
||||||
|
if(!mIsPresentationMode){ |
||||||
|
mpTitle = new UBTGAdaptableText(mpTreeWidgetItem,mpWorkWidget); |
||||||
|
mpLayout->addWidget(mpTitle); |
||||||
|
} |
||||||
|
if(mpMediaLabelWidget){ |
||||||
|
mpMediaLabelWidget->setParent(mpWorkWidget); |
||||||
|
mpLayout->addWidget(mpMediaLabelWidget); |
||||||
|
} |
||||||
|
else if (mpMediaWidget){ |
||||||
|
mpMediaWidget->setParent(mpWorkWidget); |
||||||
|
mpLayout->addWidget(mpMediaWidget); |
||||||
|
} |
||||||
|
else if (mpWebView){ |
||||||
|
mpWebView->setParent(mpWorkWidget); |
||||||
|
mpLayout->addWidget(mpWebView); |
||||||
|
} |
||||||
|
addWidget(mpWorkWidget); |
||||||
|
setCurrentWidget(mpWorkWidget); |
||||||
|
updateSize(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void UBTGMediaWidget::parseMimeData(const QMimeData* pMimeData) |
||||||
|
{ |
||||||
|
QString path; |
||||||
|
if(pMimeData){ |
||||||
|
if(pMimeData->hasText()){ |
||||||
|
path = QUrl::fromLocalFile(pMimeData->text()).toString(); |
||||||
|
} |
||||||
|
else if(pMimeData->hasUrls()){ |
||||||
|
path = pMimeData->urls().at(0).toString(); |
||||||
|
} |
||||||
|
else if(pMimeData->hasImage()){ |
||||||
|
qDebug() << "Not yet implemented"; |
||||||
|
} |
||||||
|
} |
||||||
|
else |
||||||
|
qDebug() << "No mime data present"; |
||||||
|
|
||||||
|
createWorkWidget(path); |
||||||
|
QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(path); |
||||||
|
qDebug() << mimeType; |
||||||
|
} |
||||||
|
|
||||||
|
void UBTGMediaWidget::dropEvent(QDropEvent* event) |
||||||
|
{ |
||||||
|
parseMimeData(event->mimeData()); |
||||||
|
event->accept(); |
||||||
|
} |
||||||
|
|
||||||
|
void UBTGMediaWidget::mousePressEvent(QMouseEvent *event) |
||||||
|
{ |
||||||
|
if (!mIsPresentationMode) |
||||||
|
event->ignore(); |
||||||
|
else{ |
||||||
|
|
||||||
|
QDrag *drag = new QDrag(this); |
||||||
|
QMimeData *mimeData = new QMimeData; |
||||||
|
QList<QUrl> urlList; |
||||||
|
urlList << QUrl::fromLocalFile(mRelativePath); |
||||||
|
mimeData->setUrls(urlList); |
||||||
|
drag->setMimeData(mimeData); |
||||||
|
|
||||||
|
drag->exec(); |
||||||
|
event->accept(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void UBTGMediaWidget::updateSize() |
||||||
|
{ |
||||||
|
if(mpTreeWidgetItem){ |
||||||
|
mpTreeWidgetItem->setExpanded(false); |
||||||
|
mpTreeWidgetItem->setExpanded(true); |
||||||
|
if(!mIsPresentationMode) |
||||||
|
mpTitle->setFocus(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* class UBTGUrlWdiget * |
||||||
|
***************************************************************************/ |
||||||
|
UBTGUrlWidget::UBTGUrlWidget(QWidget* parent, const char* name ):QWidget(parent) |
||||||
|
, mpLayout(NULL) |
||||||
|
, mpTitle(NULL) |
||||||
|
, mpUrl(NULL) |
||||||
|
{ |
||||||
|
setObjectName(name); |
||||||
|
setStyleSheet( "QWidget {background-color: white}"); |
||||||
|
|
||||||
|
mpLayout = new QVBoxLayout(this); |
||||||
|
mpTitle = new QLineEdit("title",this); |
||||||
|
mpUrl = new QLineEdit("url",this); |
||||||
|
|
||||||
|
mpLayout->addWidget(mpTitle); |
||||||
|
mpLayout->addWidget(mpUrl); |
||||||
|
} |
||||||
|
|
||||||
|
UBTGUrlWidget::~UBTGUrlWidget() |
||||||
|
{ |
||||||
|
DELETEPTR(mpTitle); |
||||||
|
DELETEPTR(mpUrl); |
||||||
|
DELETEPTR(mpLayout); |
||||||
|
} |
||||||
|
|
||||||
|
tUBGEElementNode* UBTGUrlWidget::saveData() |
||||||
|
{ |
||||||
|
tUBGEElementNode* result = new tUBGEElementNode(); |
||||||
|
result->type = "link"; |
||||||
|
result->attributes.insert("title",mpTitle->text()); |
||||||
|
result->attributes.insert("url",mpUrl->text()); |
||||||
|
return result; |
||||||
|
} |
@ -0,0 +1,144 @@ |
|||||||
|
/*
|
||||||
|
* This program is free software: you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU General Public License as published by |
||||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||||
|
* (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef UBTEACHERGUIDEWIDGETSTOOLS_H |
||||||
|
#define UBTEACHERGUIDEWIDGETSTOOLS_H |
||||||
|
|
||||||
|
#include <QObject> |
||||||
|
#include <QTreeWidgetItem> |
||||||
|
#include <QTextEdit> |
||||||
|
#include <QLabel> |
||||||
|
#include <QDragEnterEvent> |
||||||
|
#include <QDropEvent> |
||||||
|
#include <QLineEdit> |
||||||
|
#include <QMimeData> |
||||||
|
#include <QStackedWidget> |
||||||
|
#include <QWebView> |
||||||
|
|
||||||
|
#include "customWidgets/UBMediaWidget.h" |
||||||
|
|
||||||
|
class QTreeWidget; |
||||||
|
class QVBoxLayout; |
||||||
|
class QComboBox; |
||||||
|
class QTextEdit; |
||||||
|
class QWidget; |
||||||
|
class UBTGAdaptableText; |
||||||
|
class QDomElement; |
||||||
|
|
||||||
|
typedef struct |
||||||
|
{ |
||||||
|
QString type; |
||||||
|
QMap<QString,QString> attributes; |
||||||
|
}tUBGEElementNode; |
||||||
|
|
||||||
|
|
||||||
|
class iUBTGSavableData |
||||||
|
{ |
||||||
|
public: |
||||||
|
virtual tUBGEElementNode* saveData() = 0; |
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
class UBAddItem : public QTreeWidgetItem |
||||||
|
{ |
||||||
|
public: |
||||||
|
explicit UBAddItem(const QString &strings, int addSubItemWidgetType, QTreeWidget* parent = 0); |
||||||
|
~UBAddItem(); |
||||||
|
|
||||||
|
signals: |
||||||
|
|
||||||
|
public slots: |
||||||
|
}; |
||||||
|
|
||||||
|
class UBTGActionWidget : public QWidget, public iUBTGSavableData |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
public: |
||||||
|
explicit UBTGActionWidget(QTreeWidgetItem* widget, QWidget* parent = 0,const char* name = "UBActionWidget"); |
||||||
|
~UBTGActionWidget(); |
||||||
|
void update(); |
||||||
|
tUBGEElementNode* saveData(); |
||||||
|
public slots: |
||||||
|
void onOwnerChange(int ownerId); |
||||||
|
private: |
||||||
|
QVBoxLayout* mpLayout; |
||||||
|
QComboBox* mpOwner; |
||||||
|
UBTGAdaptableText* mpTask; |
||||||
|
protected: |
||||||
|
QTreeWidgetItem* mpTreeWidgetItem; |
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
class UBTGAdaptableText : public QTextEdit |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
public: |
||||||
|
explicit UBTGAdaptableText(QTreeWidgetItem* widget = 0, QWidget *parent = 0, const char* name = "UBTGAdaptableText"); |
||||||
|
void showText(const QString & text); |
||||||
|
void bottomMargin(int newValue); |
||||||
|
signals: |
||||||
|
|
||||||
|
public slots: |
||||||
|
void onTextChanged(); |
||||||
|
private: |
||||||
|
int mBottomMargin; |
||||||
|
QTreeWidgetItem* mpTreeWidgetItem; |
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
class UBTGMediaWidget : public QStackedWidget , public iUBTGSavableData |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
public: |
||||||
|
UBTGMediaWidget(QTreeWidgetItem* widget = 0, QWidget* parent = 0, const char* name = "UBTGMediaWidget"); |
||||||
|
UBTGMediaWidget(QString relativePath, QTreeWidgetItem* widget = 0, QWidget* parent = 0, const char* name = "UBTGMediaWidget"); |
||||||
|
~UBTGMediaWidget(); |
||||||
|
tUBGEElementNode* saveData(); |
||||||
|
protected: |
||||||
|
void dragEnterEvent(QDragEnterEvent* event); |
||||||
|
void dropEvent(QDropEvent* event); |
||||||
|
void mousePressEvent(QMouseEvent* event); |
||||||
|
private: |
||||||
|
void parseMimeData(const QMimeData* pMimeData); |
||||||
|
void createWorkWidget(QString& path); |
||||||
|
void updateSize(); |
||||||
|
|
||||||
|
QTreeWidgetItem* mpTreeWidgetItem; |
||||||
|
QLabel* mpDropMeWidget; |
||||||
|
QWidget* mpWorkWidget; |
||||||
|
QVBoxLayout* mpLayout; |
||||||
|
UBTGAdaptableText* mpTitle; |
||||||
|
QLabel* mpMediaLabelWidget; |
||||||
|
UBMediaWidget* mpMediaWidget; |
||||||
|
QWebView* mpWebView; |
||||||
|
QString mRelativePath; |
||||||
|
bool mIsPresentationMode; |
||||||
|
}; |
||||||
|
|
||||||
|
class UBTGUrlWidget : public QWidget , public iUBTGSavableData |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
public: |
||||||
|
UBTGUrlWidget(QWidget* parent = 0, const char* name = "UBTGUrlWidget"); |
||||||
|
~UBTGUrlWidget(); |
||||||
|
tUBGEElementNode* saveData(); |
||||||
|
private: |
||||||
|
QVBoxLayout* mpLayout; |
||||||
|
QLineEdit* mpTitle; |
||||||
|
QLineEdit* mpUrl; |
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
#endif // UBTEACHERGUIDEWIDGETSTOOLS_H
|
Loading…
Reference in new issue