Merge branch 'develop' of github.com:Sankore/Sankore-3.1 into develop

preferencesAboutTextFull
Claudio Valerio 12 years ago
commit e181f05439
  1. 86
      src/adaptors/UBImportDocument.cpp
  2. 2
      src/adaptors/UBImportDocument.h
  3. 6
      src/board/UBBoardController.cpp
  4. 1
      src/board/UBBoardController.h
  5. 10
      src/core/UBDocumentManager.cpp
  6. 43
      src/core/UBPersistenceManager.cpp
  7. 7
      src/core/UBPersistenceManager.h
  8. 6
      src/domain/UBGraphicsScene.cpp
  9. 3
      src/frameworks/UBFileSystemUtils.cpp
  10. 2
      src/gui/UBTeacherGuideWidget.cpp
  11. 50
      src/gui/UBTeacherGuideWidgetsTools.cpp
  12. 2
      src/gui/UBTeacherGuideWidgetsTools.h

@ -56,7 +56,7 @@ QString UBImportDocument::importFileFilter()
} }
QString UBImportDocument::expandFileToDir(const QFile& pZipFile, const QString& pDir) bool UBImportDocument::extractFileToDir(const QFile& pZipFile, const QString& pDir, QString& documentRoot)
{ {
QDir rootDir(pDir); QDir rootDir(pDir);
@ -65,63 +65,45 @@ QString UBImportDocument::expandFileToDir(const QFile& pZipFile, const QString&
if(!zip.open(QuaZip::mdUnzip)) if(!zip.open(QuaZip::mdUnzip))
{ {
qWarning() << "Import failed. Cause zip.open(): " << zip.getZipError(); qWarning() << "Import failed. Cause zip.open(): " << zip.getZipError();
return ""; return false;
} }
zip.setFileNameCodec("UTF-8"); zip.setFileNameCodec("UTF-8");
QuaZipFileInfo info; QuaZipFileInfo info;
QuaZipFile file(&zip); QuaZipFile file(&zip);
// TODO UB 4.x implement a mechanism that can replace an existing
// document based on the UID of the document.
bool createNewDocument = true;
QString documentRootFolder;
// first we search the metadata.rdf to check the document properties
for(bool more = zip.goToFirstFile(); more; more = zip.goToNextFile())
{
if(!zip.getCurrentFileInfo(&info))
{
qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError();
return "";
}
QFileInfo currentFileInfo(pDir + "/" + file.getActualFileName());
}
if (createNewDocument)
documentRootFolder = UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath();
QFile out; QFile out;
char c; char c;
documentRoot = UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath(pDir);
for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile())
{ {
if(!zip.getCurrentFileInfo(&info)) if(!zip.getCurrentFileInfo(&info))
{ {
//TOD UB 4.3 O display error to user or use crash reporter //TOD UB 4.3 O display error to user or use crash reporter
qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError(); qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError();
return ""; return false;
} }
if(!file.open(QIODevice::ReadOnly)) if(!file.open(QIODevice::ReadOnly))
{ {
qWarning() << "Import failed. Cause: file.open(): " << zip.getZipError(); qWarning() << "Import failed. Cause: file.open(): " << zip.getZipError();
return ""; return false;
} }
if(file.getZipError()!= UNZ_OK) if(file.getZipError()!= UNZ_OK)
{ {
qWarning() << "Import failed. Cause: file.getFileName(): " << zip.getZipError(); qWarning() << "Import failed. Cause: file.getFileName(): " << zip.getZipError();
return ""; return false;
} }
QString newFileName = documentRootFolder + "/" + file.getActualFileName(); QString newFileName = documentRoot + "/" + file.getActualFileName();
QFileInfo newFileInfo(newFileName); QFileInfo newFileInfo(newFileName);
rootDir.mkpath(newFileInfo.absolutePath()); if (!rootDir.mkpath(newFileInfo.absolutePath()))
return false;
out.setFileName(newFileName); out.setFileName(newFileName);
out.open(QIODevice::WriteOnly); if (!out.open(QIODevice::WriteOnly))
return false;
// Slow like hell (on GNU/Linux at least), but it is not my fault. // Slow like hell (on GNU/Linux at least), but it is not my fault.
// Not ZIP/UNZIP package's fault either. // Not ZIP/UNZIP package's fault either.
@ -131,7 +113,7 @@ QString UBImportDocument::expandFileToDir(const QFile& pZipFile, const QString&
{ {
qWarning() << "Import failed. Cause: Unable to write file"; qWarning() << "Import failed. Cause: Unable to write file";
out.close(); out.close();
return ""; return false;
} }
while(file.getChar(&c)) while(file.getChar(&c))
@ -142,13 +124,13 @@ QString UBImportDocument::expandFileToDir(const QFile& pZipFile, const QString&
if(file.getZipError()!=UNZ_OK) if(file.getZipError()!=UNZ_OK)
{ {
qWarning() << "Import failed. Cause: " << zip.getZipError(); qWarning() << "Import failed. Cause: " << zip.getZipError();
return ""; return false;
} }
if(!file.atEnd()) if(!file.atEnd())
{ {
qWarning() << "Import failed. Cause: read all but not EOF"; qWarning() << "Import failed. Cause: read all but not EOF";
return ""; return false;
} }
file.close(); file.close();
@ -156,7 +138,7 @@ QString UBImportDocument::expandFileToDir(const QFile& pZipFile, const QString&
if(file.getZipError()!=UNZ_OK) if(file.getZipError()!=UNZ_OK)
{ {
qWarning() << "Import failed. Cause: file.close(): " << file.getZipError(); qWarning() << "Import failed. Cause: file.close(): " << file.getZipError();
return ""; return false;
} }
} }
@ -166,11 +148,10 @@ QString UBImportDocument::expandFileToDir(const QFile& pZipFile, const QString&
if(zip.getZipError()!=UNZ_OK) if(zip.getZipError()!=UNZ_OK)
{ {
qWarning() << "Import failed. Cause: zip.close(): " << zip.getZipError(); qWarning() << "Import failed. Cause: zip.close(): " << zip.getZipError();
return ""; return false;
} }
return true;
return documentRootFolder;
} }
UBDocumentProxy* UBImportDocument::importFile(const QFile& pFile, const QString& pGroup) UBDocumentProxy* UBImportDocument::importFile(const QFile& pFile, const QString& pGroup)
@ -183,17 +164,17 @@ UBDocumentProxy* UBImportDocument::importFile(const QFile& pFile, const QString&
// first unzip the file to the correct place // first unzip the file to the correct place
QString path = UBSettings::userDocumentDirectory(); QString path = UBSettings::userDocumentDirectory();
QString documentRootFolder = expandFileToDir(pFile, path); QString documentRootFolder;
if(!documentRootFolder.length()){ if(!extractFileToDir(pFile, path, documentRootFolder)){
UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName())); UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName()));
return 0; return NULL;
}
else{
UBDocumentProxy* newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(documentRootFolder, pGroup);
UBApplication::showMessage(tr("Import successful."));
return newDocument;
} }
UBDocumentProxy* newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(documentRootFolder, pGroup);
UBApplication::showMessage(tr("Import successful."));
return newDocument;
} }
bool UBImportDocument::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) bool UBImportDocument::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile)
@ -203,9 +184,18 @@ bool UBImportDocument::addFileToDocument(UBDocumentProxy* pDocument, const QFile
QString path = UBFileSystemUtils::createTempDir(); QString path = UBFileSystemUtils::createTempDir();
QString documentRootFolder = expandFileToDir(pFile, path); QString documentRootFolder;
if (!extractFileToDir(pFile, path, documentRootFolder))
UBPersistenceManager::persistenceManager()->addDirectoryContentToDocument(documentRootFolder, pDocument); {
UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName()));
return false;
}
if (!UBPersistenceManager::persistenceManager()->addDirectoryContentToDocument(documentRootFolder, pDocument))
{
UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName()));
return false;
}
UBFileSystemUtils::deleteDir(path); UBFileSystemUtils::deleteDir(path);

@ -37,7 +37,7 @@ class UBImportDocument : public UBDocumentBasedImportAdaptor
virtual bool addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile); virtual bool addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile);
private: private:
QString expandFileToDir(const QFile& pZipFile, const QString& pDir); bool extractFileToDir(const QFile& pZipFile, const QString& pDir, QString& documentRoot);
}; };
#endif /* UBIMPORTDOCUMENT_H_ */ #endif /* UBIMPORTDOCUMENT_H_ */

@ -94,6 +94,7 @@ UBBoardController::UBBoardController(UBMainWindow* mainWindow)
, mSystemScaleFactor(1.0) , mSystemScaleFactor(1.0)
, mCleanupDone(false) , mCleanupDone(false)
, mCacheWidgetIsEnabled(false) , mCacheWidgetIsEnabled(false)
, mDeletingSceneIndex(-1)
{ {
mZoomFactor = UBSettings::settings()->boardZoomFactor->get().toDouble(); mZoomFactor = UBSettings::settings()->boardZoomFactor->get().toDouble();
@ -679,6 +680,7 @@ void UBBoardController::deleteScene(int nIndex)
{ {
if (selectedDocument()->pageCount()>=2) if (selectedDocument()->pageCount()>=2)
{ {
mDeletingSceneIndex = nIndex;
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
persistCurrentScene(); persistCurrentScene();
showMessage(tr("Delete page %1 from document").arg(nIndex), true); showMessage(tr("Delete page %1 from document").arg(nIndex), true);
@ -688,12 +690,12 @@ void UBBoardController::deleteScene(int nIndex)
deletePages(scIndexes); deletePages(scIndexes);
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
if (nIndex >= pageCount()) if (nIndex >= pageCount())
nIndex = pageCount()-1; nIndex = pageCount()-1;
setActiveDocumentScene(nIndex); setActiveDocumentScene(nIndex);
showMessage(tr("Page %1 deleted").arg(nIndex)); showMessage(tr("Page %1 deleted").arg(nIndex));
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
mDeletingSceneIndex = -1;
} }
} }
@ -1790,7 +1792,7 @@ void UBBoardController::show()
void UBBoardController::persistCurrentScene() void UBBoardController::persistCurrentScene()
{ {
if(UBPersistenceManager::persistenceManager() if(UBPersistenceManager::persistenceManager()
&& selectedDocument() && mActiveScene && selectedDocument() && mActiveScene && mActiveSceneIndex != mDeletingSceneIndex
&& (mActiveSceneIndex >= 0) && (mActiveSceneIndex >= 0)
&& (mActiveScene->isModified() || (UBApplication::boardController->paletteManager()->teacherGuideDockWidget() && UBApplication::boardController->paletteManager()->teacherGuideDockWidget()->teacherGuideWidget()->isModified()))) && (mActiveScene->isModified() || (UBApplication::boardController->paletteManager()->teacherGuideDockWidget() && UBApplication::boardController->paletteManager()->teacherGuideDockWidget()->teacherGuideWidget()->isModified())))
{ {

@ -281,6 +281,7 @@ class UBBoardController : public UBDocumentContainer
QMap<QAction*, QPair<QString, QString> > mActionTexts; QMap<QAction*, QPair<QString, QString> > mActionTexts;
bool mCacheWidgetIsEnabled; bool mCacheWidgetIsEnabled;
QGraphicsItem* mLastCreatedItem; QGraphicsItem* mLastCreatedItem;
int mDeletingSceneIndex;
private slots: private slots:
void stylusToolDoubleClicked(int tool); void stylusToolDoubleClicked(int tool);

@ -66,15 +66,15 @@ UBDocumentManager::UBDocumentManager(QObject *parent)
QString dummyWidgets = tr("widgets"); QString dummyWidgets = tr("widgets");
UBExportCFF* cffExporter = new UBExportCFF(this); UBExportCFF* cffExporter = new UBExportCFF(this);
mExportAdaptors.append(cffExporter);
UBExportFullPDF* exportFullPdf = new UBExportFullPDF(this); UBExportFullPDF* exportFullPdf = new UBExportFullPDF(this);
mExportAdaptors.append(exportFullPdf);
UBExportDocument* exportDocument = new UBExportDocument(this); UBExportDocument* exportDocument = new UBExportDocument(this);
UBWebPublisher* webPublished = new UBWebPublisher(this);
mExportAdaptors.append(exportDocument); mExportAdaptors.append(exportDocument);
mExportAdaptors.append(webPublished);
mExportAdaptors.append(exportFullPdf);
mExportAdaptors.append(cffExporter);
// UBExportWeb* exportWeb = new UBExportWeb(this); // UBExportWeb* exportWeb = new UBExportWeb(this);
// mExportAdaptors.append(exportWeb); // mExportAdaptors.append(exportWeb);
UBWebPublisher* webPublished = new UBWebPublisher(this);
mExportAdaptors.append(webPublished);
UBImportDocument* documentImport = new UBImportDocument(this); UBImportDocument* documentImport = new UBImportDocument(this);
mImportAdaptors.append(documentImport); mImportAdaptors.append(documentImport);
@ -194,7 +194,7 @@ int UBDocumentManager::addFilesToDocument(UBDocumentProxy* document, QStringList
int nImportedDocuments = 0; int nImportedDocuments = 0;
foreach(const QString& fileName, fileNames) foreach(const QString& fileName, fileNames)
{ {
UBApplication::showMessage(tr("Importing file").arg(fileName)); UBApplication::showMessage(tr("Importing file %1").arg(fileName));
QFile file(fileName); QFile file(fileName);
QFileInfo fileInfo(file); QFileInfo fileInfo(file);

@ -667,11 +667,8 @@ void UBPersistenceManager::copyPage(UBDocumentProxy* pDocumentProxy, const int s
int UBPersistenceManager::sceneCount(const UBDocumentProxy* proxy) int UBPersistenceManager::sceneCount(const UBDocumentProxy* proxy)
{ {
return sceneCountInDir(proxy->persistencePath()); const QString pPath = proxy->persistencePath();
}
int UBPersistenceManager::sceneCountInDir(const QString& pPath)
{
int pageIndex = 0; int pageIndex = 0;
bool moreToProcess = true; bool moreToProcess = true;
bool addedMissingZeroPage = false; bool addedMissingZeroPage = false;
@ -709,15 +706,23 @@ int UBPersistenceManager::sceneCountInDir(const QString& pPath)
return pageIndex; return pageIndex;
} }
QStringList UBPersistenceManager::getSceneFileNames(const QString& folder)
QString UBPersistenceManager::generateUniqueDocumentPath()
{ {
QString ubPath = UBSettings::userDocumentDirectory(); QDir dir(folder, "page???.svg", QDir::Name, QDir::Files);
return dir.entryList();
}
QString UBPersistenceManager::generateUniqueDocumentPath(const QString& baseFolder)
{
QDateTime now = QDateTime::currentDateTime(); QDateTime now = QDateTime::currentDateTime();
QString dirName = now.toString("yyyy-MM-dd hh-mm-ss.zzz"); QString dirName = now.toString("yyyy-MM-dd hh-mm-ss.zzz");
return ubPath + QString("/Sankore Document %1").arg(dirName); return baseFolder + QString("/Sankore Document %1").arg(dirName);
}
QString UBPersistenceManager::generateUniqueDocumentPath()
{
return generateUniqueDocumentPath(UBSettings::userDocumentDirectory());
} }
@ -730,34 +735,42 @@ void UBPersistenceManager::generatePathIfNeeded(UBDocumentProxy* pDocumentProxy)
} }
void UBPersistenceManager::addDirectoryContentToDocument(const QString& documentRootFolder, UBDocumentProxy* pDocument) bool UBPersistenceManager::addDirectoryContentToDocument(const QString& documentRootFolder, UBDocumentProxy* pDocument)
{ {
int sourcePageCount = sceneCountInDir(documentRootFolder); QStringList sourceScenes = getSceneFileNames(documentRootFolder);
if (sourceScenes.empty())
return false;
int targetPageCount = pDocument->pageCount(); int targetPageCount = pDocument->pageCount();
for(int sourceIndex = 0 ; sourceIndex < sourcePageCount; sourceIndex++) for(int sourceIndex = 0 ; sourceIndex < sourceScenes.size(); sourceIndex++)
{ {
int targetIndex = targetPageCount + sourceIndex; int targetIndex = targetPageCount + sourceIndex;
QFile svg(documentRootFolder + UBFileSystemUtils::digitFileFormat("/page%1.svg", sourceIndex)); QFile svg(documentRootFolder + "/" + sourceScenes[sourceIndex]);
svg.copy(pDocument->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", targetIndex)); if (!svg.copy(pDocument->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", targetIndex)))
return false;
UBSvgSubsetAdaptor::setSceneUuid(pDocument, targetIndex, QUuid::createUuid()); UBSvgSubsetAdaptor::setSceneUuid(pDocument, targetIndex, QUuid::createUuid());
QFile thumb(documentRootFolder + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", sourceIndex)); QFile thumb(documentRootFolder + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", sourceIndex));
// We can ignore error in this case, thumbnail will be genarated
thumb.copy(pDocument->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", targetIndex)); thumb.copy(pDocument->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", targetIndex));
} }
foreach(QString dir, mDocumentSubDirectories) foreach(QString dir, mDocumentSubDirectories)
{ {
qDebug() << "copying " << documentRootFolder << "/" << dir << " to " << pDocument->persistencePath() << "/" + dir; qDebug() << "copying " << documentRootFolder << "/" << dir << " to " << pDocument->persistencePath() << "/" + dir;
UBFileSystemUtils::copyDir(documentRootFolder + "/" + dir, pDocument->persistencePath() + "/" + dir); QDir srcDir(documentRootFolder + "/" + dir);
if (srcDir.exists())
if (!UBFileSystemUtils::copyDir(documentRootFolder + "/" + dir, pDocument->persistencePath() + "/" + dir))
return false;
} }
pDocument->setPageCount(sceneCount(pDocument)); pDocument->setPageCount(sceneCount(pDocument));
return false;
} }

@ -79,13 +79,14 @@ class UBPersistenceManager : public QObject
virtual QStringList allVideos(const QDir& dir); virtual QStringList allVideos(const QDir& dir);
virtual QStringList allWidgets(const QDir& dir); virtual QStringList allWidgets(const QDir& dir);
virtual QString generateUniqueDocumentPath(); QString generateUniqueDocumentPath();
QString generateUniqueDocumentPath(const QString& baseFolder);
QString teacherGuideAbsoluteObjectPath(UBDocumentProxy* pDocumentProxy); QString teacherGuideAbsoluteObjectPath(UBDocumentProxy* pDocumentProxy);
QString addObjectToTeacherGuideDirectory(UBDocumentProxy* proxy, QString pPath); QString addObjectToTeacherGuideDirectory(UBDocumentProxy* proxy, QString pPath);
QString addWidgetToTeacherGuideDirectory(UBDocumentProxy* pDocumentProxy, QString pPath); QString addWidgetToTeacherGuideDirectory(UBDocumentProxy* pDocumentProxy, QString pPath);
virtual void addDirectoryContentToDocument(const QString& documentRootFolder, UBDocumentProxy* pDocument); bool addDirectoryContentToDocument(const QString& documentRootFolder, UBDocumentProxy* pDocument);
virtual void upgradeDocumentIfNeeded(UBDocumentProxy* pDocumentProxy); virtual void upgradeDocumentIfNeeded(UBDocumentProxy* pDocumentProxy);
@ -128,7 +129,7 @@ class UBPersistenceManager : public QObject
int sceneCount(const UBDocumentProxy* pDocumentProxy); int sceneCount(const UBDocumentProxy* pDocumentProxy);
int sceneCountInDir(const QString& pPath); static QStringList getSceneFileNames(const QString& folder);
QList<QPointer<UBDocumentProxy> > allDocumentProxies(); QList<QPointer<UBDocumentProxy> > allDocumentProxies();

@ -1095,8 +1095,10 @@ void UBGraphicsScene::clearContent(clearCase pCase)
switch (pCase) { switch (pCase) {
case clearBackground : case clearBackground :
removeItem(mBackgroundObject); if(mBackgroundObject){
removedItems << mBackgroundObject; removeItem(mBackgroundObject);
removedItems << mBackgroundObject;
}
break; break;
case clearItemsAndAnnotations : case clearItemsAndAnnotations :

@ -273,7 +273,8 @@ bool UBFileSystemUtils::copyDir(const QString& pSourceDirPath, const QString& pT
QDir dirSource(pSourceDirPath); QDir dirSource(pSourceDirPath);
QDir dirTarget(pTargetDirPath); QDir dirTarget(pTargetDirPath);
dirTarget.mkpath(pTargetDirPath); if (!dirTarget.mkpath(pTargetDirPath))
return false;
bool successSoFar = true; bool successSoFar = true;

@ -554,7 +554,7 @@ void UBTeacherGuidePresentationWidget::showData( QVector<tUBGEElementNode*> data
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); newWidgetItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
QString colorString = element->attributes.value("owner").toInt() == 0 ? "red" : "green"; QString colorString = element->attributes.value("owner").toInt() == 0 ? "blue" : "green";
UBTGAdaptableText* textWidget = new UBTGAdaptableText(newWidgetItem, 0); UBTGAdaptableText* textWidget = new UBTGAdaptableText(newWidgetItem, 0);
textWidget->bottomMargin(14); textWidget->bottomMargin(14);
textWidget->setStyleSheet( "QWidget {background: #EEEEEE; border:none; color:" + colorString + ";}"); textWidget->setStyleSheet( "QWidget {background: #EEEEEE; border:none; color:" + colorString + ";}");

@ -86,7 +86,6 @@ UBTGActionWidget::UBTGActionWidget(QTreeWidgetItem* widget, QWidget* parent, con
mpTask = new UBTGAdaptableText(widget,this); mpTask = new UBTGAdaptableText(widget,this);
mpTask->setPlaceHolderText(tr("Type task here ...")); mpTask->setPlaceHolderText(tr("Type task here ..."));
mpTask->setAcceptRichText(true); mpTask->setAcceptRichText(true);
mpTask->setTextColor(QColor().green());
mpTask->setObjectName("ActionWidgetTaskTextEdit"); mpTask->setObjectName("ActionWidgetTaskTextEdit");
mpLayout->addWidget(mpOwner); mpLayout->addWidget(mpOwner);
mpLayout->addWidget(mpTask); mpLayout->addWidget(mpTask);
@ -147,7 +146,6 @@ void UBTGAdaptableText::setPlaceHolderText(QString text)
// the space addition is to make this string unique and check against it to know // the space addition is to make this string unique and check against it to know
// if we are talking about a typed string or the placeholder string // if we are talking about a typed string or the placeholder string
mPlaceHolderText = text + " "; mPlaceHolderText = text + " ";
setTextColor(QColor(Qt::lightGray));
setPlainText(mPlaceHolderText); setPlainText(mPlaceHolderText);
} }
@ -230,9 +228,12 @@ void UBTGAdaptableText::bottomMargin(int newValue)
onTextChanged(); onTextChanged();
} }
void UBTGAdaptableText::focusInEvent(QFocusEvent* e){ void UBTGAdaptableText::focusInEvent(QFocusEvent* e)
{
qDebug() << "pippa";
if(isReadOnly()){ if(isReadOnly()){
e->ignore(); e->ignore();
qDebug() << "ignored";
} }
managePlaceholder(true); managePlaceholder(true);
QTextEdit::focusInEvent(e); QTextEdit::focusInEvent(e);
@ -246,11 +247,13 @@ void UBTGAdaptableText::focusOutEvent(QFocusEvent* e){
void UBTGAdaptableText::managePlaceholder(bool focus){ void UBTGAdaptableText::managePlaceholder(bool focus){
if(focus){ if(focus){
if(toPlainText() == mPlaceHolderText){ if(toPlainText() == mPlaceHolderText){
qDebug() << "Place holder found";
setTextColor(QColor(Qt::black)); setTextColor(QColor(Qt::black));
setPlainText(""); setPlainText("");
} }
setCursorToTheEnd(); setCursorToTheEnd();
}else{ }
else{
if(toPlainText().isEmpty()){ if(toPlainText().isEmpty()){
setTextColor(QColor(Qt::lightGray)); setTextColor(QColor(Qt::lightGray));
setPlainText(mPlaceHolderText); setPlainText(mPlaceHolderText);
@ -323,6 +326,7 @@ UBTGMediaWidget::UBTGMediaWidget(QTreeWidgetItem* widget, QWidget* parent,const
, mpDropMeWidget(NULL) , mpDropMeWidget(NULL)
, mpWorkWidget(NULL) , mpWorkWidget(NULL)
, mpLayout(NULL) , mpLayout(NULL)
, mpMediaLayout(NULL)
, mpTitle(NULL) , mpTitle(NULL)
, mpMediaLabelWidget(NULL) , mpMediaLabelWidget(NULL)
, mpMediaWidget(NULL) , mpMediaWidget(NULL)
@ -330,6 +334,7 @@ UBTGMediaWidget::UBTGMediaWidget(QTreeWidgetItem* widget, QWidget* parent,const
, mMediaPath(QString("")) , mMediaPath(QString(""))
, mIsPresentationMode(false) , mIsPresentationMode(false)
, mIsInitializationMode(false) , mIsInitializationMode(false)
, mMediaWidgetHeight(150)
{ {
setObjectName(name); setObjectName(name);
mpDropMeWidget = new QLabel(); mpDropMeWidget = new QLabel();
@ -347,6 +352,7 @@ UBTGMediaWidget::UBTGMediaWidget(QString mediaPath, QTreeWidgetItem* widget, QWi
, mpDropMeWidget(NULL) , mpDropMeWidget(NULL)
, mpWorkWidget(NULL) , mpWorkWidget(NULL)
, mpLayout(NULL) , mpLayout(NULL)
, mpMediaLayout(NULL)
, mpTitle(NULL) , mpTitle(NULL)
, mpMediaLabelWidget(NULL) , mpMediaLabelWidget(NULL)
, mpMediaWidget(NULL) , mpMediaWidget(NULL)
@ -354,6 +360,7 @@ UBTGMediaWidget::UBTGMediaWidget(QString mediaPath, QTreeWidgetItem* widget, QWi
, mIsPresentationMode(true) , mIsPresentationMode(true)
, mMediaType("") , mMediaType("")
, mIsInitializationMode(false) , mIsInitializationMode(false)
, mMediaWidgetHeight(150)
{ {
setObjectName(name); setObjectName(name);
mMediaPath = UBApplication::boardController->selectedDocument()->persistencePath()+ "/" + mediaPath; mMediaPath = UBApplication::boardController->selectedDocument()->persistencePath()+ "/" + mediaPath;
@ -368,6 +375,7 @@ UBTGMediaWidget::~UBTGMediaWidget()
DELETEPTR(mpMediaLabelWidget); DELETEPTR(mpMediaLabelWidget);
DELETEPTR(mpMediaWidget); DELETEPTR(mpMediaWidget);
DELETEPTR(mpWebView); DELETEPTR(mpWebView);
DELETEPTR(mpMediaLayout);
DELETEPTR(mpLayout); DELETEPTR(mpLayout);
removeWidget(mpDropMeWidget); removeWidget(mpDropMeWidget);
@ -456,9 +464,8 @@ void UBTGMediaWidget::createWorkWidget(bool forceFlashMediaType)
mpMediaLabelWidget = new QLabel(); mpMediaLabelWidget = new QLabel();
QPixmap pixmap = QPixmap(mMediaPath); QPixmap pixmap = QPixmap(mMediaPath);
pixmap = pixmap.scaledToWidth(mpTreeWidgetItem->treeWidget()->size().width()); pixmap = pixmap.scaledToHeight(mMediaWidgetHeight);
mpMediaLabelWidget->setPixmap(pixmap); mpMediaLabelWidget->setPixmap(pixmap);
mpMediaLabelWidget->setScaledContents(true);
} }
else if(mimeType.contains("widget") && !forceFlashMediaType){ else if(mimeType.contains("widget") && !forceFlashMediaType){
mMediaType = "w3c"; mMediaType = "w3c";
@ -508,31 +515,43 @@ void UBTGMediaWidget::createWorkWidget(bool forceFlashMediaType)
if(setMedia){ if(setMedia){
setAcceptDrops(false); setAcceptDrops(false);
mpWorkWidget = new QWidget(this); mpWorkWidget = new QWidget(this);
mpLayout = new QVBoxLayout(mpWorkWidget);
if(!mIsPresentationMode){ if(!mIsPresentationMode){
mpLayout = new QVBoxLayout(mpWorkWidget);
mpTitle = new UBTGAdaptableText(mpTreeWidgetItem,mpWorkWidget); mpTitle = new UBTGAdaptableText(mpTreeWidgetItem,mpWorkWidget);
mpTitle->setPlaceHolderText(tr("Type title here...")); mpTitle->setPlaceHolderText(tr("Type title here..."));
mpLayout->addWidget(mpTitle); mpLayout->addWidget(mpTitle);
mpMediaLayout = new QHBoxLayout;
mpLayout->addLayout(mpMediaLayout);
mpWorkWidget->setLayout(mpLayout);
}
else{
mpMediaLayout = new QHBoxLayout(mpWorkWidget);
mpWorkWidget->setLayout(mpMediaLayout);
} }
mpMediaLayout->addStretch(1);
if(mpMediaLabelWidget){ if(mpMediaLabelWidget){
mpMediaLabelWidget->setMaximumHeight(width()); mpMediaLabelWidget->setFixedHeight(mMediaWidgetHeight);
mpMediaLabelWidget->setParent(mpWorkWidget); mpMediaLabelWidget->setParent(mpWorkWidget);
mpLayout->addWidget(mpMediaLabelWidget); mpMediaLayout->addWidget(mpMediaLabelWidget);
} }
else if (mpMediaWidget){ else if (mpMediaWidget){
mpMediaWidget->setMaximumHeight(width()); mpMediaWidget->setFixedHeight(mMediaWidgetHeight);
mpMediaWidget->setParent(mpWorkWidget); mpMediaWidget->setParent(mpWorkWidget);
mpLayout->addWidget(mpMediaWidget); mpMediaLayout->addWidget(mpMediaWidget);
} }
else if (mpWebView){ else if (mpWebView){
mpWebView->setMaximumHeight(width()); mpWebView->setFixedHeight(mMediaWidgetHeight);
mpWebView->setParent(mpWorkWidget); mpWebView->setParent(mpWorkWidget);
mpLayout->addWidget(mpWebView); mpMediaLayout->addWidget(mpWebView);
mpWebView->show(); mpWebView->show();
} }
mpWorkWidget->setLayout(mpLayout); mpMediaLayout->addStretch(1);
addWidget(mpWorkWidget); addWidget(mpWorkWidget);
setCurrentWidget(mpWorkWidget); setCurrentWidget(mpWorkWidget);
mpWorkWidget->show();
} }
} }
@ -565,8 +584,7 @@ void UBTGMediaWidget::mousePressEvent(QMouseEvent *event)
{ {
if (!mIsPresentationMode) if (!mIsPresentationMode)
event->ignore(); event->ignore();
else{ else{
QDrag *drag = new QDrag(this); QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData(); QMimeData *mimeData = new QMimeData();
QList<QUrl> urlList; QList<QUrl> urlList;

@ -166,6 +166,7 @@ private:
QLabel* mpDropMeWidget; QLabel* mpDropMeWidget;
QWidget* mpWorkWidget; QWidget* mpWorkWidget;
QVBoxLayout* mpLayout; QVBoxLayout* mpLayout;
QHBoxLayout* mpMediaLayout;
UBTGAdaptableText* mpTitle; UBTGAdaptableText* mpTitle;
QLabel* mpMediaLabelWidget; QLabel* mpMediaLabelWidget;
UBMediaWidget* mpMediaWidget; UBMediaWidget* mpMediaWidget;
@ -174,6 +175,7 @@ private:
bool mIsPresentationMode; bool mIsPresentationMode;
QString mMediaType; QString mMediaType;
bool mIsInitializationMode; bool mIsInitializationMode;
int mMediaWidgetHeight;
}; };

Loading…
Cancel
Save