fixed some issue on gui

preferencesAboutTextFull
Claudio Valerio 13 years ago
parent 4a1e71d3c3
commit b98bd2d46f
  1. 73
      src/gui/UBTeacherGuideWidget.cpp
  2. 5
      src/gui/UBTeacherGuideWidget.h
  3. 101
      src/gui/UBTeacherGuideWidgetsTools.cpp
  4. 20
      src/gui/UBTeacherGuideWidgetsTools.h

@ -701,8 +701,11 @@ void UBTeacherGuidePageZeroWidget::fillComboBoxes()
QStringList licences; 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"); 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); 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) void UBTeacherGuidePageZeroWidget::onSchoolLevelChanged(QString schoolLevel)
@ -722,21 +725,64 @@ void UBTeacherGuidePageZeroWidget::onSchoolLevelChanged(QString schoolLevel)
void UBTeacherGuidePageZeroWidget::onActiveSceneChanged() void UBTeacherGuidePageZeroWidget::onActiveSceneChanged()
{ {
UBDocumentProxy* documentProxy = UBApplication::documentController ? UBApplication::documentController->getCurrentDocument() : 0; UBDocumentProxy* documentProxy = UBApplication::boardController->activeDocument();
if(UBApplication::documentController && UBApplication::boardController->currentPage() == 0){ if(documentProxy && UBApplication::boardController->currentPage() == 0){
QDateTime creationDate = documentProxy->documentDate(); 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(); 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) void UBTeacherGuidePageZeroWidget::switchToMode(tUBTGZeroPageMode mode)
{ {
if(mode == tUBTGZeroPageMode_EDITION){ if(mode == tUBTGZeroPageMode_EDITION){
mpModePushButton->hide(); mpModePushButton->hide();
mpSessionTitle->setReadOnly(false); mpSessionTitle->setReadOnly(false);
mpSessionTitle->setObjectName("UBTGEditionModeSessionTitle");
mpAuthors->setReadOnly(false); mpAuthors->setReadOnly(false);
mpGoals->setReadOnly(false); mpGoals->setReadOnly(false);
mpKeywords->setReadOnly(false); mpKeywords->setReadOnly(false);
@ -753,6 +799,7 @@ void UBTeacherGuidePageZeroWidget::switchToMode(tUBTGZeroPageMode mode)
else{ else{
mpModePushButton->show(); mpModePushButton->show();
mpSessionTitle->setReadOnly(true); mpSessionTitle->setReadOnly(true);
mpSessionTitle->setObjectName("UBTGPresentationSessionTitle");
mpAuthors->setReadOnly(true); mpAuthors->setReadOnly(true);
mpGoals->setReadOnly(true); mpGoals->setReadOnly(true);
mpKeywords->setReadOnly(true); mpKeywords->setReadOnly(true);
@ -766,14 +813,14 @@ void UBTeacherGuidePageZeroWidget::switchToMode(tUBTGZeroPageMode mode)
mpSchoolTypeValueLabel->show(); mpSchoolTypeValueLabel->show();
mpSchoolTypeBox->hide(); mpSchoolTypeBox->hide();
mpLicenceValueLabel->setText(mpLicenceBox->currentText()); mpLicenceValueLabel->setText(mpLicenceBox->currentText());
QStringList licenceIconList; QString licenceIconPath = mpLicenceBox->itemData(mpLicenceBox->currentIndex()).toString();
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(!licenceIconPath.isEmpty()){
if(mpLicenceBox->currentIndex() < 6){ mpLicenceIcon->setPixmap(QPixmap(licenceIconPath));
mpLicenceIcon->setPixmap(licenceIconList.at(mpLicenceBox->currentIndex()));
mpLicenceIcon->show(); mpLicenceIcon->show();
} }
mpLicenceValueLabel->show(); mpLicenceValueLabel->show();
mpLicenceBox->hide(); mpLicenceBox->hide();
persistData();
} }
} }
@ -860,6 +907,7 @@ UBTeacherGuideWidget::UBTeacherGuideWidget(QWidget* parent, const char* name): Q
UBTeacherGuideWidget::~UBTeacherGuideWidget() UBTeacherGuideWidget::~UBTeacherGuideWidget()
{ {
DELETEPTR(mpPageZeroWidget);
DELETEPTR(mpEditionWidget); DELETEPTR(mpEditionWidget);
DELETEPTR(mpPresentationWidget); DELETEPTR(mpPresentationWidget);
} }
@ -867,10 +915,11 @@ UBTeacherGuideWidget::~UBTeacherGuideWidget()
void UBTeacherGuideWidget::onActiveSceneChanged() void UBTeacherGuideWidget::onActiveSceneChanged()
{ {
if(UBApplication::boardController->currentPage() == 0) if(UBApplication::boardController->currentPage() == 0){
setCurrentWidget(mpPageZeroWidget); setCurrentWidget(mpPageZeroWidget);
else mpPageZeroWidget->switchToMode(tUBTGZeroPageMode_EDITION);
setCurrentWidget(mpPresentationWidget); }else
setCurrentWidget(mpEditionWidget);
} }

@ -103,7 +103,7 @@ private:
}; };
/*************************************************************************** /***************************************************************************
* class UBTeacherGuidePageZeroPresentationWidget * * class UBTeacherGuidePageZeroWidget *
***************************************************************************/ ***************************************************************************/
class UBTeacherGuidePageZeroWidget : public QWidget class UBTeacherGuidePageZeroWidget : public QWidget
{ {
@ -122,6 +122,8 @@ public slots:
private: private:
void fillComboBoxes(); void fillComboBoxes();
void loadData();
void hideEvent(QHideEvent* event);
QVBoxLayout* mpLayout; QVBoxLayout* mpLayout;
QHBoxLayout* mpButtonTitleLayout; QHBoxLayout* mpButtonTitleLayout;
@ -168,6 +170,7 @@ private:
private slots: private slots:
void onSchoolLevelChanged(QString schoolLevel); void onSchoolLevelChanged(QString schoolLevel);
void persistData();
}; };
/*************************************************************************** /***************************************************************************

@ -21,13 +21,15 @@
#include <QDebug> #include <QDebug>
#include <QUrl> #include <QUrl>
#include <QWebSettings> #include <QWebSettings>
#include <QDomElement>
#include <QDomDocument>
#include <QApplication> #include <QApplication>
#include "UBTeacherGuideWidgetsTools.h" #include "UBTeacherGuideWidgetsTools.h"
#include "UBTGWidgetTreeDelegate.h" #include "UBTGWidgetTreeDelegate.h"
#include "core/UBPersistenceManager.h"
#include "domain/UBW3CWidget.h"
#include "globals/UBGlobals.h" #include "globals/UBGlobals.h"
#include "frameworks/UBFileSystemUtils.h" #include "frameworks/UBFileSystemUtils.h"
@ -110,7 +112,6 @@ UBTGAdaptableText::UBTGAdaptableText(QTreeWidgetItem* widget, QWidget* parent, c
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);
setMinimumHeight(mMinimumHeight);
} }
void UBTGAdaptableText::setPlaceHolderText(QString text) void UBTGAdaptableText::setPlaceHolderText(QString text)
@ -126,6 +127,13 @@ void UBTGAdaptableText::setPlaceHolderText(QString text)
void UBTGAdaptableText::keyPressEvent(QKeyEvent* e) 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){ if(toPlainText() == mPlaceHolderText){
setTextColor(QColor(Qt::black)); setTextColor(QColor(Qt::black));
setPlainText(""); setPlainText("");
@ -161,11 +169,18 @@ QString UBTGAdaptableText::text()
void UBTGAdaptableText::onTextChanged() void UBTGAdaptableText::onTextChanged()
{ {
qreal documentSize = document()->size().height();
if(height() == documentSize + mBottomMargin)
return;
mIsUpdatingSize = true; mIsUpdatingSize = true;
if(document()->size().height() < mMinimumHeight)
if(documentSize < mMinimumHeight)
setFixedHeight(mMinimumHeight); setFixedHeight(mMinimumHeight);
else else
setFixedHeight(document()->size().height()+mBottomMargin); setFixedHeight(documentSize+mBottomMargin);
updateGeometry(); updateGeometry();
//to trig the widget item to resize it //to trig the widget item to resize it
if(mpTreeWidgetItem){ if(mpTreeWidgetItem){
@ -197,7 +212,51 @@ void UBTGAdaptableText::bottomMargin(int newValue)
void UBTGAdaptableText::resizeEvent(QResizeEvent* e) void UBTGAdaptableText::resizeEvent(QResizeEvent* e)
{ {
QTextEdit::resizeEvent(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<QUrl> 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); 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() tUBGEElementNode* UBTGMediaWidget::saveData()
{ {
if(!mpTitle) if(!mpTitle)
@ -279,8 +354,8 @@ void UBTGMediaWidget::dragEnterEvent(QDragEnterEvent *event)
void UBTGMediaWidget::createWorkWidget(QString& path) void UBTGMediaWidget::createWorkWidget(QString& path)
{ {
QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(path); QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(path);
qDebug() << mimeType;
bool setMedia = true; bool setMedia = true;
mRelativePath = path;
if(mimeType.contains("audio") || mimeType.contains("video")){ if(mimeType.contains("audio") || mimeType.contains("video")){
mMediaType = mimeType.contains("audio")? "audio":"movie"; mMediaType = mimeType.contains("audio")? "audio":"movie";
mpMediaWidget = new UBMediaWidget(mimeType.contains("audio")?eMediaType_Audio:eMediaType_Video); mpMediaWidget = new UBMediaWidget(mimeType.contains("audio")?eMediaType_Audio:eMediaType_Video);
@ -296,7 +371,11 @@ void UBTGMediaWidget::createWorkWidget(QString& path)
} }
else if(mimeType.contains("application")){ else if(mimeType.contains("application")){
mMediaType = "w3c"; 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->setAcceptDrops(false);
mpWebView->settings()->setAttribute(QWebSettings::JavaEnabled, true); mpWebView->settings()->setAttribute(QWebSettings::JavaEnabled, true);
mpWebView->settings()->setAttribute(QWebSettings::PluginsEnabled, 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::OfflineStorageDatabaseEnabled, true);
mpWebView->settings()->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true); mpWebView->settings()->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true);
mpWebView->settings()->setAttribute(QWebSettings::DnsPrefetchEnabled, true); mpWebView->settings()->setAttribute(QWebSettings::DnsPrefetchEnabled, true);
mpWebView->load(QUrl(path));
mpWebView->show(); mpWebView->load(QUrl(mRelativePath+"/index.htm"));
} }
else{ else{
qDebug() << "createWorkWidget mime type not handled" << mimeType; qDebug() << "createWorkWidget mime type not handled" << mimeType;
@ -314,7 +393,6 @@ void UBTGMediaWidget::createWorkWidget(QString& path)
} }
if(setMedia){ if(setMedia){
mRelativePath = path;
setAcceptDrops(false); setAcceptDrops(false);
mpWorkWidget = new QWidget(this); mpWorkWidget = new QWidget(this);
mpLayout = new QVBoxLayout(mpWorkWidget); mpLayout = new QVBoxLayout(mpWorkWidget);
@ -336,6 +414,7 @@ void UBTGMediaWidget::createWorkWidget(QString& path)
mpWebView->setMaximumHeight(mpTreeWidgetItem->treeWidget()->size().width()); mpWebView->setMaximumHeight(mpTreeWidgetItem->treeWidget()->size().width());
mpWebView->setParent(mpWorkWidget); mpWebView->setParent(mpWorkWidget);
mpLayout->addWidget(mpWebView); mpLayout->addWidget(mpWebView);
mpWebView->show();
} }
mpWorkWidget->setLayout(mpLayout); mpWorkWidget->setLayout(mpLayout);
addWidget(mpWorkWidget); addWidget(mpWorkWidget);

@ -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 class UBTGMediaWidget : public QStackedWidget , public iUBTGSavableData
{ {
Q_OBJECT Q_OBJECT
@ -124,6 +140,8 @@ protected:
void dragEnterEvent(QDragEnterEvent* event); void dragEnterEvent(QDragEnterEvent* event);
void dropEvent(QDropEvent* event); void dropEvent(QDropEvent* event);
void mousePressEvent(QMouseEvent* event); void mousePressEvent(QMouseEvent* event);
void hideEvent(QHideEvent* event);
void showEvent(QShowEvent* event);
private: private:
void parseMimeData(const QMimeData* pMimeData); void parseMimeData(const QMimeData* pMimeData);
@ -137,7 +155,7 @@ private:
UBTGAdaptableText* mpTitle; UBTGAdaptableText* mpTitle;
QLabel* mpMediaLabelWidget; QLabel* mpMediaLabelWidget;
UBMediaWidget* mpMediaWidget; UBMediaWidget* mpMediaWidget;
QWebView* mpWebView; UBDraggableWeb* mpWebView;
QString mRelativePath; QString mRelativePath;
bool mIsPresentationMode; bool mIsPresentationMode;
QString mMediaType; QString mMediaType;

Loading…
Cancel
Save