lesson pages, presentation mode media titles are draggables

preferencesAboutTextFull
Claudio Valerio 13 years ago
parent 1234e3e670
commit c9180ee097
  1. 21
      src/gui/UBTeacherGuideWidget.cpp
  2. 2
      src/gui/UBTeacherGuideWidget.h
  3. 28
      src/gui/UBTeacherGuideWidgetsTools.cpp
  4. 20
      src/gui/UBTeacherGuideWidgetsTools.h

@ -68,7 +68,7 @@ UBTeacherGuideEditionWidget::UBTeacherGuideEditionWidget(QWidget *parent, const
mpLayout = new QVBoxLayout(this); mpLayout = new QVBoxLayout(this);
mpPageNumberLabel = new QLabel(this); mpPageNumberLabel = new QLabel(this);
mpPageNumberLabel->setAlignment(Qt::AlignRight); mpPageNumberLabel->setAlignment(Qt::AlignRight);
mpPageNumberLabel->setObjectName("UBTGEditionPageNumberLabel"); mpPageNumberLabel->setObjectName("UBTGPageNumberLabel");
mpLayout->addWidget(mpPageNumberLabel); mpLayout->addWidget(mpPageNumberLabel);
// tree basic configuration // tree basic configuration
mpDocumentTitle = new QLabel(this); mpDocumentTitle = new QLabel(this);
@ -195,7 +195,7 @@ QVector<tUBGEElementNode*> UBTeacherGuideEditionWidget::getData()
children << getChildrenList(mpAddALinkItem); children << getChildrenList(mpAddALinkItem);
result << getPageAndCommentData(); result << getPageAndCommentData();
foreach(QTreeWidgetItem* widgetItem, children){ foreach(QTreeWidgetItem* widgetItem, children){
tUBGEElementNode* node = dynamic_cast<iUBTGSavableData*>(mpTreeWidget->itemWidget(widgetItem,0))->saveData(); tUBGEElementNode* node = dynamic_cast<iUBTGSaveData*>(mpTreeWidget->itemWidget(widgetItem,0))->saveData();
if(node) if(node)
result << node; result << node;
} }
@ -205,7 +205,7 @@ QVector<tUBGEElementNode*> UBTeacherGuideEditionWidget::getData()
void UBTeacherGuideEditionWidget::onAddItemClicked(QTreeWidgetItem* widget, int column) void UBTeacherGuideEditionWidget::onAddItemClicked(QTreeWidgetItem* widget, int column)
{ {
int addSubItemWidgetType = widget->data(column,Qt::UserRole).toInt(); int addSubItemWidgetType = widget->data(column,Qt::UserRole).toInt();
if(column == 0 && addSubItemWidgetType != eUBTGAddSubItemWidgetType_None){ if(addSubItemWidgetType != eUBTGAddSubItemWidgetType_None){
QTreeWidgetItem* newWidgetItem = new QTreeWidgetItem(widget); QTreeWidgetItem* newWidgetItem = new QTreeWidgetItem(widget);
newWidgetItem->setData(column,Qt::UserRole,eUBTGAddSubItemWidgetType_None); newWidgetItem->setData(column,Qt::UserRole,eUBTGAddSubItemWidgetType_None);
newWidgetItem->setData(1,Qt::UserRole,eUBTGAddSubItemWidgetType_None); newWidgetItem->setData(1,Qt::UserRole,eUBTGAddSubItemWidgetType_None);
@ -279,7 +279,7 @@ UBTeacherGuidePresentationWidget::UBTeacherGuidePresentationWidget(QWidget *pare
mpPageNumberLabel = new QLabel(this); mpPageNumberLabel = new QLabel(this);
mpPageNumberLabel->setAlignment(Qt::AlignRight); mpPageNumberLabel->setAlignment(Qt::AlignRight);
mpPageNumberLabel->setObjectName("UBTGPresentationPageNumberLabel"); mpPageNumberLabel->setObjectName("UBTGPageNumberLabel");
mpLayout->addWidget(mpPageNumberLabel); mpLayout->addWidget(mpPageNumberLabel);
@ -317,10 +317,11 @@ UBTeacherGuidePresentationWidget::UBTeacherGuidePresentationWidget(QWidget *pare
mpSeparator->setObjectName("UBTGSepartor"); mpSeparator->setObjectName("UBTGSepartor");
mpLayout->addWidget(mpSeparator); mpLayout->addWidget(mpSeparator);
mpTreeWidget = new QTreeWidget(this); mpTreeWidget = new UBTGDraggableTreeItem(this);
mpLayout->addWidget(mpTreeWidget); mpLayout->addWidget(mpTreeWidget);
mpRootWidgetItem = mpTreeWidget->invisibleRootItem(); mpRootWidgetItem = mpTreeWidget->invisibleRootItem();
mpTreeWidget->setDragEnabled(true);
mpTreeWidget->setRootIsDecorated(false); mpTreeWidget->setRootIsDecorated(false);
mpTreeWidget->setIndentation(0); mpTreeWidget->setIndentation(0);
mpTreeWidget->setDropIndicatorShown(false); mpTreeWidget->setDropIndicatorShown(false);
@ -392,6 +393,7 @@ void UBTeacherGuidePresentationWidget::showData(QVector<tUBGEElementNode*> data)
else if(element->type == "action"){ else if(element->type == "action"){
QTreeWidgetItem* newWidgetItem = new QTreeWidgetItem(mpRootWidgetItem); QTreeWidgetItem* newWidgetItem = new QTreeWidgetItem(mpRootWidgetItem);
newWidgetItem->setText(0,element->attributes.value("task")); newWidgetItem->setText(0,element->attributes.value("task"));
newWidgetItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
QString colorString = element->attributes.value("owner").toInt() == 0 ? "red":"green"; QString colorString = element->attributes.value("owner").toInt() == 0 ? "red":"green";
UBTGAdaptableText* textWidget = new UBTGAdaptableText(newWidgetItem,0); UBTGAdaptableText* textWidget = new UBTGAdaptableText(newWidgetItem,0);
textWidget->bottomMargin(14); textWidget->bottomMargin(14);
@ -409,6 +411,8 @@ void UBTeacherGuidePresentationWidget::showData(QVector<tUBGEElementNode*> data)
newWidgetItem->setText(0,element->attributes.value("title")); newWidgetItem->setText(0,element->attributes.value("title"));
newWidgetItem->setData(0,tUBTGTreeWidgetItemRole_HasAnAction,tUBTGActionAssociateOnClickItem_MEDIA); newWidgetItem->setData(0,tUBTGTreeWidgetItemRole_HasAnAction,tUBTGActionAssociateOnClickItem_MEDIA);
newWidgetItem->setData(0,Qt::FontRole, QVariant(QFont(QApplication::font().family(),11))); newWidgetItem->setData(0,Qt::FontRole, QVariant(QFont(QApplication::font().family(),11)));
newWidgetItem->setData(0, TG_USER_ROLE_MIME_TYPE, element->attributes.value("relativePath"));
newWidgetItem->setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
mpRootWidgetItem->addChild(newWidgetItem); mpRootWidgetItem->addChild(newWidgetItem);
QTreeWidgetItem* mediaItem = new QTreeWidgetItem(newWidgetItem); QTreeWidgetItem* mediaItem = new QTreeWidgetItem(newWidgetItem);
@ -425,6 +429,7 @@ void UBTeacherGuidePresentationWidget::showData(QVector<tUBGEElementNode*> data)
newWidgetItem->setData(0,tUBTGTreeWidgetItemRole_HasAnAction,tUBTGActionAssociateOnClickItem_URL); newWidgetItem->setData(0,tUBTGTreeWidgetItemRole_HasAnAction,tUBTGActionAssociateOnClickItem_URL);
newWidgetItem->setData(0,tUBTGTreeWidgetItemRole_HasAnUrl,QVariant(element->attributes.value("url"))); newWidgetItem->setData(0,tUBTGTreeWidgetItemRole_HasAnUrl,QVariant(element->attributes.value("url")));
newWidgetItem->setData(0,Qt::FontRole, QVariant(QFont(QApplication::font().family(),11))); newWidgetItem->setData(0,Qt::FontRole, QVariant(QFont(QApplication::font().family(),11)));
newWidgetItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
mpRootWidgetItem->addChild(newWidgetItem); mpRootWidgetItem->addChild(newWidgetItem);
} }
} }
@ -498,7 +503,7 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons
mpLayout = new QVBoxLayout(this); mpLayout = new QVBoxLayout(this);
mpPageNumberLabel = new QLabel(this); mpPageNumberLabel = new QLabel(this);
mpPageNumberLabel->setAlignment(Qt::AlignRight); mpPageNumberLabel->setAlignment(Qt::AlignRight);
mpPageNumberLabel->setObjectName("UBTGPresentationPageNumberLabel"); mpPageNumberLabel->setObjectName("UBTGPageNumberLabel");
mpPageNumberLabel->setText(tr("Page 0")); mpPageNumberLabel->setText(tr("Page 0"));
mpLayout->addWidget(mpPageNumberLabel); mpLayout->addWidget(mpPageNumberLabel);
@ -510,9 +515,9 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons
mpButtonTitleLayout->addWidget(mpModePushButton); mpButtonTitleLayout->addWidget(mpModePushButton);
connect(mpModePushButton,SIGNAL(clicked()),this,SLOT(switchToMode())); connect(mpModePushButton,SIGNAL(clicked()),this,SLOT(switchToMode()));
mpSessionTitle = new UBTGAdaptableText(0,this); mpSessionTitle = new UBTGAdaptableText(0,this,"UBTGSessionTitle");
mpSessionTitle->setPlaceHolderText(tr("Type session title here ...")); mpSessionTitle->setPlaceHolderText(tr("Type session title here ..."));
mpSessionTitle->setObjectName("UBTGEditionModeSessionTitle"); //mpSessionTitle->setObjectName("UBTGSessionTitle");
mpButtonTitleLayout->addWidget(mpSessionTitle); mpButtonTitleLayout->addWidget(mpSessionTitle);
mpLayout->addLayout(mpButtonTitleLayout); mpLayout->addLayout(mpButtonTitleLayout);

@ -96,7 +96,7 @@ private:
QLabel* mpPageNumberLabel; QLabel* mpPageNumberLabel;
QFrame* mpSeparator; QFrame* mpSeparator;
QPushButton* mpModePushButton; QPushButton* mpModePushButton;
QTreeWidget* mpTreeWidget; UBTGDraggableTreeItem* mpTreeWidget;
QTreeWidgetItem* mpRootWidgetItem; QTreeWidgetItem* mpRootWidgetItem;
QTreeWidgetItem* mpMediaSwitchItem; QTreeWidgetItem* mpMediaSwitchItem;

@ -103,15 +103,18 @@ tUBGEElementNode* UBTGActionWidget::saveData()
UBTGAdaptableText::UBTGAdaptableText(QTreeWidgetItem* widget, QWidget* parent, const char* name):QTextEdit(parent) UBTGAdaptableText::UBTGAdaptableText(QTreeWidgetItem* widget, QWidget* parent, const char* name):QTextEdit(parent)
, mBottomMargin(5) , mBottomMargin(5)
, mpTreeWidgetItem(widget) , mpTreeWidgetItem(widget)
, mMinimumHeight(20) , mMinimumHeight(0)
, mHasPlaceHolder(false) , mHasPlaceHolder(false)
, mIsUpdatingSize(false) , mIsUpdatingSize(false)
{ {
setObjectName(name); setObjectName(name);
setStyleSheet( "QWidget {background: white; border:1 solid #999999; border-radius : 10px; padding: 2px;}");
connect(this,SIGNAL(textChanged()),this,SLOT(onTextChanged())); connect(this,SIGNAL(textChanged()),this,SLOT(onTextChanged()));
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
mMinimumHeight = document()->size().height() + mBottomMargin;
setMinimumHeight(mMinimumHeight);
} }
void UBTGAdaptableText::setPlaceHolderText(QString text) void UBTGAdaptableText::setPlaceHolderText(QString text)
@ -170,7 +173,6 @@ QString UBTGAdaptableText::text()
void UBTGAdaptableText::onTextChanged() void UBTGAdaptableText::onTextChanged()
{ {
qreal documentSize = document()->size().height(); qreal documentSize = document()->size().height();
if(height() == documentSize + mBottomMargin) if(height() == documentSize + mBottomMargin)
return; return;
mIsUpdatingSize = true; mIsUpdatingSize = true;
@ -478,7 +480,7 @@ void UBTGMediaWidget::updateSize()
} }
/*************************************************************************** /***************************************************************************
* class UBTGUrlWdiget * * class UBTGUrlWidget *
***************************************************************************/ ***************************************************************************/
UBTGUrlWidget::UBTGUrlWidget(QWidget* parent, const char* name ):QWidget(parent) UBTGUrlWidget::UBTGUrlWidget(QWidget* parent, const char* name ):QWidget(parent)
, mpLayout(NULL) , mpLayout(NULL)
@ -513,3 +515,21 @@ tUBGEElementNode* UBTGUrlWidget::saveData()
result->attributes.insert("url",mpUrl->text()); result->attributes.insert("url",mpUrl->text());
return result; return result;
} }
/***************************************************************************
* class UBTGDraggableTreeItem *
***************************************************************************/
UBTGDraggableTreeItem::UBTGDraggableTreeItem(QWidget* parent, const char* name) : QTreeWidget(parent)
{
setObjectName(name);
}
QMimeData* UBTGDraggableTreeItem::mimeData(const QList<QTreeWidgetItem *> items) const
{
QMimeData* result = new QMimeData();
QList<QUrl> urls;
urls << QUrl(items.at(0)->data(0,TG_USER_ROLE_MIME_TYPE).toString());
result->setUrls(urls);
return result;
}

@ -29,6 +29,9 @@
#include "customWidgets/UBMediaWidget.h" #include "customWidgets/UBMediaWidget.h"
#define TG_USER_ROLE_MIME_TYPE (Qt::UserRole+50)
class QTreeWidget; class QTreeWidget;
class QVBoxLayout; class QVBoxLayout;
class QComboBox; class QComboBox;
@ -44,7 +47,7 @@ typedef struct
}tUBGEElementNode; }tUBGEElementNode;
class iUBTGSavableData class iUBTGSaveData
{ {
public: public:
virtual tUBGEElementNode* saveData() = 0; virtual tUBGEElementNode* saveData() = 0;
@ -62,7 +65,7 @@ signals:
public slots: public slots:
}; };
class UBTGActionWidget : public QWidget, public iUBTGSavableData class UBTGActionWidget : public QWidget, public iUBTGSaveData
{ {
Q_OBJECT Q_OBJECT
@ -127,7 +130,7 @@ private:
bool mDragStarted; bool mDragStarted;
}; };
class UBTGMediaWidget : public QStackedWidget , public iUBTGSavableData class UBTGMediaWidget : public QStackedWidget , public iUBTGSaveData
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -162,7 +165,7 @@ private:
}; };
class UBTGUrlWidget : public QWidget , public iUBTGSavableData class UBTGUrlWidget : public QWidget , public iUBTGSaveData
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -175,5 +178,14 @@ private:
QLineEdit* mpUrl; QLineEdit* mpUrl;
}; };
class UBTGDraggableTreeItem : public QTreeWidget
{
Q_OBJECT
public:
UBTGDraggableTreeItem(QWidget* parent = 0, const char* name = "UBTGDraggableTreeItem");
private:
QMimeData* mimeData(const QList<QTreeWidgetItem *> items) const;
};
#endif // UBTEACHERGUIDEWIDGETSTOOLS_H #endif // UBTEACHERGUIDEWIDGETSTOOLS_H

Loading…
Cancel
Save