From 5b6ed8e51284ec0eee6dbebf5b54efe2300607de Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Fri, 17 Aug 2012 15:40:58 +0200 Subject: [PATCH 01/15] fixed customizations issue on linux build --- buildDebianPackage | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/buildDebianPackage b/buildDebianPackage index 0306a2c9..7efb17f7 100755 --- a/buildDebianPackage +++ b/buildDebianPackage @@ -107,7 +107,11 @@ buildWithStandardQt(){ STANDARD_QT_USED=true QMAKE_PATH=$STANDARD_QT LRELEASES=`which lrelease` - QT_PATH="/usr/lib/`arch`-linux-gnu" + if [ "`arch`" == "i686" ]; then + QT_PATH="/usr/lib/i386-linux-gnu" + else + QT_PATH="/usr/lib/`arch`-linux-gnu" + fi PLUGINS_PATH="$QT_PATH/qt4/plugins" fi fi @@ -189,6 +193,9 @@ cp -R resources/linux/qtlinux/* $PRODUCT_PATH/ notifyProgress "QT" "Coping plugins and library ..." cp -R $PLUGINS_PATH $PRODUCT_PATH/ +# copying customization +cp -R resources/customizations $PRODUCT_PATH/ + if [ $STANDARD_QT_USED == false ]; then #copying custom qt library mkdir -p $QT_LIBRARY_DEST_PATH From b8f006d1ca4a58dc3f2fa5436162ba4681015beb Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Sat, 18 Aug 2012 15:54:27 +0300 Subject: [PATCH 02/15] Import procedure, improving of code, insertion of objects into existing document errors fix --- src/adaptors/UBCFFSubsetAdaptor.cpp | 29 +++- src/adaptors/UBImportAdaptor.cpp | 20 ++- src/adaptors/UBImportAdaptor.h | 32 +++- src/adaptors/UBImportCFF.cpp | 6 +- src/adaptors/UBImportCFF.h | 7 +- src/adaptors/UBImportDocument.cpp | 6 +- src/adaptors/UBImportDocument.h | 4 +- src/adaptors/UBImportImage.cpp | 39 ++++- src/adaptors/UBImportImage.h | 6 +- src/adaptors/UBImportPDF.cpp | 44 +++++- src/adaptors/UBImportPDF.h | 6 +- src/board/UBBoardController.cpp | 73 +++++++-- src/core/UBDocumentManager.cpp | 207 +++++++++++++------------- src/core/UBDocumentManager.h | 4 +- src/core/UBPersistenceManager.cpp | 182 ++++++---------------- src/core/UBPersistenceManager.h | 8 +- src/document/UBDocumentController.cpp | 7 +- 17 files changed, 392 insertions(+), 288 deletions(-) diff --git a/src/adaptors/UBCFFSubsetAdaptor.cpp b/src/adaptors/UBCFFSubsetAdaptor.cpp index f86477c5..7eb667b5 100644 --- a/src/adaptors/UBCFFSubsetAdaptor.cpp +++ b/src/adaptors/UBCFFSubsetAdaptor.cpp @@ -869,8 +869,18 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgAudio(const QDomElement &ele QUuid uuid = QUuid::createUuid(); - concreteUrl = QUrl::fromLocalFile(UBPersistenceManager::persistenceManager() - ->addAudioFileToDocument(mCurrentScene->document(), concreteUrl.toLocalFile(), uuid)); + QString destFile; + bool b = UBPersistenceManager::persistenceManager()->addFileToDocument( + mCurrentScene->document(), + concreteUrl.toLocalFile(), + UBPersistenceManager::audioDirectory, + uuid, + destFile); + if (!b) + { + return false; + } + concreteUrl = QUrl::fromLocalFile(destFile); UBGraphicsMediaItem *audioItem = mCurrentScene->addAudio(concreteUrl, false); QTransform transform; @@ -912,8 +922,19 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgVideo(const QDomElement &ele QUuid uuid = QUuid::createUuid(); - concreteUrl = QUrl::fromLocalFile(UBPersistenceManager::persistenceManager() - ->addVideoFileToDocument(mCurrentScene->document(), concreteUrl.toLocalFile(), uuid)); + + QString destFile; + bool b = UBPersistenceManager::persistenceManager()->addFileToDocument( + mCurrentScene->document(), + concreteUrl.toLocalFile(), + UBPersistenceManager::videoDirectory, + uuid, + destFile); + if (!b) + { + return false; + } + concreteUrl = QUrl::fromLocalFile(destFile); UBGraphicsMediaItem *videoItem = mCurrentScene->addVideo(concreteUrl, false); QTransform transform; diff --git a/src/adaptors/UBImportAdaptor.cpp b/src/adaptors/UBImportAdaptor.cpp index f9cce78a..143b6244 100644 --- a/src/adaptors/UBImportAdaptor.cpp +++ b/src/adaptors/UBImportAdaptor.cpp @@ -22,8 +22,9 @@ #include "core/memcheck.h" -UBImportAdaptor::UBImportAdaptor(QObject *parent) - :QObject(parent) +UBImportAdaptor::UBImportAdaptor(bool _documentBased, QObject *parent) + :QObject(parent), + documentBased(_documentBased) { // NOOP } @@ -33,6 +34,20 @@ UBImportAdaptor::~UBImportAdaptor() // NOOP } +UBPageBasedImportAdaptor::UBPageBasedImportAdaptor(QObject *parent) + :UBImportAdaptor(false, parent) +{ + // NOOP +} + +UBDocumentBasedImportAdaptor::UBDocumentBasedImportAdaptor(QObject *parent) + :UBImportAdaptor(true, parent) +{ + // NOOP +} + + +/* UBDocumentProxy* UBImportAdaptor::importFile(const QFile& pFile, const QString& pGroup) { QString documentName = QFileInfo(pFile.fileName()).completeBaseName(); @@ -53,3 +68,4 @@ UBDocumentProxy* UBImportAdaptor::importFile(const QFile& pFile, const QString& return newDocument; } +*/ \ No newline at end of file diff --git a/src/adaptors/UBImportAdaptor.h b/src/adaptors/UBImportAdaptor.h index 4dcdf9e0..6a29a3cd 100644 --- a/src/adaptors/UBImportAdaptor.h +++ b/src/adaptors/UBImportAdaptor.h @@ -18,6 +18,8 @@ #include +class UBGraphicsItem; +class UBGraphicsScene; class UBDocumentProxy; class UBImportAdaptor : public QObject @@ -25,15 +27,39 @@ class UBImportAdaptor : public QObject Q_OBJECT; protected: - UBImportAdaptor(QObject *parent = 0); + UBImportAdaptor(bool _documentBased, QObject *parent = 0); virtual ~UBImportAdaptor(); public: virtual QStringList supportedExtentions() = 0; virtual QString importFileFilter() = 0; - virtual UBDocumentProxy* importFile(const QFile& pFile, const QString& pGroup); - virtual bool addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) = 0; + + bool isDocumentBased(){return documentBased;} + private: + bool documentBased; + +}; + +class UBPageBasedImportAdaptor : public UBImportAdaptor +{ +protected: + UBPageBasedImportAdaptor(QObject *parent = 0); + +public: + virtual QList import(const QUuid& uuid, const QString& filePath) = 0; + virtual void placeImportedItemToScene(UBGraphicsScene* scene, UBGraphicsItem* item) = 0; + virtual const QString& folderToCopy() = 0; }; +class UBDocumentBasedImportAdaptor : public UBImportAdaptor +{ +protected: + UBDocumentBasedImportAdaptor(QObject *parent = 0); +public: + virtual UBDocumentProxy* importFile(const QFile& pFile, const QString& pGroup) = 0; + virtual bool addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) = 0; +}; + + #endif /* UBIMPORTADAPTOR_H_ */ diff --git a/src/adaptors/UBImportCFF.cpp b/src/adaptors/UBImportCFF.cpp index f8c8ebee..4ff7f7a9 100644 --- a/src/adaptors/UBImportCFF.cpp +++ b/src/adaptors/UBImportCFF.cpp @@ -14,6 +14,7 @@ */ #include +#include #include "core/UBApplication.h" #include "core/UBPersistenceManager.h" @@ -38,7 +39,7 @@ THIRD_PARTY_WARNINGS_ENABLE #include "core/memcheck.h" UBImportCFF::UBImportCFF(QObject *parent) - : UBImportAdaptor(parent) + : UBDocumentBasedImportAdaptor(parent) { // NOOP } @@ -77,7 +78,6 @@ QString UBImportCFF::importFileFilter() return filter; } - bool UBImportCFF::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) { QFileInfo fi(pFile); @@ -220,6 +220,7 @@ QString UBImportCFF::expandFileToDir(const QFile& pZipFile, const QString& pDir) return documentRootFolder; } + UBDocumentProxy* UBImportCFF::importFile(const QFile& pFile, const QString& pGroup) { Q_UNUSED(pGroup); // group is defined in the imported file @@ -277,4 +278,3 @@ UBDocumentProxy* UBImportCFF::importFile(const QFile& pFile, const QString& pGro return newDocument; } } - diff --git a/src/adaptors/UBImportCFF.h b/src/adaptors/UBImportCFF.h index b31666ab..749c67bf 100644 --- a/src/adaptors/UBImportCFF.h +++ b/src/adaptors/UBImportCFF.h @@ -21,7 +21,7 @@ class UBDocumentProxy; -class UBImportCFF : public UBImportAdaptor +class UBImportCFF : public UBDocumentBasedImportAdaptor { Q_OBJECT; @@ -33,13 +33,10 @@ class UBImportCFF : public UBImportAdaptor virtual QString importFileFilter(); virtual bool addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile); - - //base class method override virtual UBDocumentProxy* importFile(const QFile& pFile, const QString& pGroup); private: - - virtual QString expandFileToDir(const QFile& pZipFile, const QString& pDir); + QString expandFileToDir(const QFile& pZipFile, const QString& pDir); }; #endif // UBIMPORTCFF_H diff --git a/src/adaptors/UBImportDocument.cpp b/src/adaptors/UBImportDocument.cpp index 5e546856..a306285d 100644 --- a/src/adaptors/UBImportDocument.cpp +++ b/src/adaptors/UBImportDocument.cpp @@ -33,7 +33,7 @@ THIRD_PARTY_WARNINGS_ENABLE #include "core/memcheck.h" UBImportDocument::UBImportDocument(QObject *parent) - :UBImportAdaptor(parent) + :UBDocumentBasedImportAdaptor(parent) { // NOOP } @@ -173,7 +173,6 @@ QString UBImportDocument::expandFileToDir(const QFile& pZipFile, const QString& return documentRootFolder; } - UBDocumentProxy* UBImportDocument::importFile(const QFile& pFile, const QString& pGroup) { Q_UNUSED(pGroup); // group is defined in the imported file @@ -197,7 +196,6 @@ UBDocumentProxy* UBImportDocument::importFile(const QFile& pFile, const QString& } } - bool UBImportDocument::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) { QFileInfo fi(pFile); @@ -215,3 +213,5 @@ bool UBImportDocument::addFileToDocument(UBDocumentProxy* pDocument, const QFile return true; } + + diff --git a/src/adaptors/UBImportDocument.h b/src/adaptors/UBImportDocument.h index 8038808a..a7530200 100644 --- a/src/adaptors/UBImportDocument.h +++ b/src/adaptors/UBImportDocument.h @@ -21,7 +21,7 @@ class UBDocumentProxy; -class UBImportDocument : public UBImportAdaptor +class UBImportDocument : public UBDocumentBasedImportAdaptor { Q_OBJECT; @@ -37,7 +37,7 @@ class UBImportDocument : public UBImportAdaptor virtual bool addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile); private: - virtual QString expandFileToDir(const QFile& pZipFile, const QString& pDir); + QString expandFileToDir(const QFile& pZipFile, const QString& pDir); }; #endif /* UBIMPORTDOCUMENT_H_ */ diff --git a/src/adaptors/UBImportImage.cpp b/src/adaptors/UBImportImage.cpp index 312c1df3..c85ba342 100644 --- a/src/adaptors/UBImportImage.cpp +++ b/src/adaptors/UBImportImage.cpp @@ -21,14 +21,14 @@ #include "core/UBPersistenceManager.h" #include "core/UBDocumentManager.h" -#include "domain/UBGraphicsPDFItem.h" +#include "domain/UBGraphicsPixmapItem.h" #include "pdf/PDFRenderer.h" #include "core/memcheck.h" UBImportImage::UBImportImage(QObject *parent) - : UBImportAdaptor(parent) + : UBPageBasedImportAdaptor(parent) { // NOOP } @@ -74,7 +74,7 @@ QString UBImportImage::importFileFilter() return filter; } - +/* bool UBImportImage::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) { int res = UBDocumentManager::documentManager()->addImageAsPageToDocument(QStringList(QFileInfo(pFile).absoluteFilePath()), pDocument); @@ -89,3 +89,36 @@ bool UBImportImage::addFileToDocument(UBDocumentProxy* pDocument, const QFile& p return true; } } +*/ + + +QList UBImportImage::import(const QUuid& uuid, const QString& filePath) +{ + QList result; + + QPixmap pix(filePath); + if (pix.isNull()) + return result; + + UBGraphicsPixmapItem* pixmapItem = new UBGraphicsPixmapItem(); + pixmapItem->setPixmap(pix); + result << pixmapItem; + return result; +} + +void UBImportImage::placeImportedItemToScene(UBGraphicsScene* scene, UBGraphicsItem* item) +{ + UBGraphicsPixmapItem* pixmapItem = (UBGraphicsPixmapItem*)item; + + UBGraphicsPixmapItem* sceneItem = scene->addPixmap(pixmapItem->pixmap(), NULL, QPointF(0, 0)); + scene->setAsBackgroundObject(sceneItem, true); + + // Only stored pixmap, should be deleted now + delete pixmapItem; +} + +const QString& UBImportImage::folderToCopy() +{ + static QString f(""); + return f; +} diff --git a/src/adaptors/UBImportImage.h b/src/adaptors/UBImportImage.h index 07a6a0b2..55c470fd 100644 --- a/src/adaptors/UBImportImage.h +++ b/src/adaptors/UBImportImage.h @@ -21,7 +21,7 @@ class UBDocumentProxy; -class UBImportImage : public UBImportAdaptor +class UBImportImage : public UBPageBasedImportAdaptor { Q_OBJECT; @@ -32,7 +32,9 @@ class UBImportImage : public UBImportAdaptor virtual QStringList supportedExtentions(); virtual QString importFileFilter(); - virtual bool addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile); + virtual QList import(const QUuid& uuid, const QString& filePath); + virtual void placeImportedItemToScene(UBGraphicsScene* scene, UBGraphicsItem* item); + virtual const QString& folderToCopy(); }; #endif /* UBIMPORTIMAGE_H_ */ diff --git a/src/adaptors/UBImportPDF.cpp b/src/adaptors/UBImportPDF.cpp index 1457ce18..a1971118 100644 --- a/src/adaptors/UBImportPDF.cpp +++ b/src/adaptors/UBImportPDF.cpp @@ -27,7 +27,7 @@ #include "core/memcheck.h" UBImportPDF::UBImportPDF(QObject *parent) - : UBImportAdaptor(parent) + : UBPageBasedImportAdaptor(parent) { QDesktopWidget* desktop = UBApplication::desktop(); this->dpi = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2; @@ -52,6 +52,47 @@ QString UBImportPDF::importFileFilter() } +QList UBImportPDF::import(const QUuid& uuid, const QString& filePath) +{ + QList result; + + PDFRenderer *pdfRenderer = PDFRenderer::rendererForUuid(uuid, filePath, true); // renderer is automatically deleted when not used anymore + + if (!pdfRenderer->isValid()) + { + UBApplication::showMessage(tr("PDF import failed.")); + return result; + } + pdfRenderer->setDPI(this->dpi); + + int pdfPageCount = pdfRenderer->pageCount(); + + for(int pdfPageNumber = 1; pdfPageNumber <= pdfPageCount; pdfPageNumber++) + { + UBApplication::showMessage(tr("Importing page %1 of %2").arg(pdfPageNumber).arg(pdfPageCount), true); + + result << new UBGraphicsPDFItem(pdfRenderer, pdfPageNumber); // deleted by the scene + } + return result; +} + +void UBImportPDF::placeImportedItemToScene(UBGraphicsScene* scene, UBGraphicsItem* item) +{ + UBGraphicsPDFItem *pdfItem = (UBGraphicsPDFItem*)item; + + pdfItem->setPos(-pdfItem->boundingRect().width() / 2, -pdfItem->boundingRect().height() / 2); + + scene->setAsBackgroundObject(pdfItem, false, false); + + scene->setNominalSize(pdfItem->boundingRect().width(), pdfItem->boundingRect().height()); +} + +const QString& UBImportPDF::folderToCopy() +{ + return UBPersistenceManager::objectDirectory; +} + +/* bool UBImportPDF::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) { QString documentName = QFileInfo(pFile.fileName()).completeBaseName(); @@ -112,3 +153,4 @@ bool UBImportPDF::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFi return true; } +*/ \ No newline at end of file diff --git a/src/adaptors/UBImportPDF.h b/src/adaptors/UBImportPDF.h index fa035adc..93e937e0 100644 --- a/src/adaptors/UBImportPDF.h +++ b/src/adaptors/UBImportPDF.h @@ -21,7 +21,7 @@ class UBDocumentProxy; -class UBImportPDF : public UBImportAdaptor +class UBImportPDF : public UBPageBasedImportAdaptor { Q_OBJECT; @@ -32,7 +32,9 @@ class UBImportPDF : public UBImportAdaptor virtual QStringList supportedExtentions(); virtual QString importFileFilter(); - virtual bool addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile); + virtual QList import(const QUuid& uuid, const QString& filePath); + virtual void placeImportedItemToScene(UBGraphicsScene* scene, UBGraphicsItem* item); + virtual const QString& folderToCopy(); private: int dpi; diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 24581b06..eb39b204 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -1074,8 +1074,20 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri { QUuid uuid = QUuid::createUuid(); - QUrl url = QUrl::fromLocalFile(UBPersistenceManager::persistenceManager() - ->addVideoFileToDocument(selectedDocument(), sourceUrl, pData, uuid)); + QString destFile; + bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(), + "", + UBPersistenceManager::videoDirectory, + uuid, + destFile, + &pData); + if (!b) + { + showMessage(tr("Add file operation failed: file copying error")); + return NULL; + } + + QUrl url = QUrl::fromLocalFile(destFile); mediaVideoItem = mActiveScene->addMedia(url, false, pPos); @@ -1105,8 +1117,20 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri { QUuid uuid = QUuid::createUuid(); - QUrl url = QUrl::fromLocalFile(UBPersistenceManager::persistenceManager() - ->addAudioFileToDocument(selectedDocument(), sourceUrl, pData, uuid)); + QString destFile; + bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(), + "", + UBPersistenceManager::audioDirectory, + uuid, + destFile, + &pData); + if (!b) + { + showMessage(tr("Add file operation failed: file copying error")); + return NULL; + } + + QUrl url = QUrl::fromLocalFile(destFile); audioMediaItem = mActiveScene->addMedia(url, false, pPos); @@ -1186,15 +1210,18 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri qDebug() << "sourceurl : " + sourceUrl.toString(); int result = 0; if(!sourceUrl.isEmpty()){ - QFile sourceFile(sourceUrl.toLocalFile()); - result = UBDocumentManager::documentManager()->addFileToDocument(selectedDocument(), sourceFile); + QStringList fileNames; + fileNames << sourceUrl.toLocalFile(); + result = UBDocumentManager::documentManager()->addFilesToDocument(selectedDocument(), fileNames); } else if(pData.size()){ QTemporaryFile pdfFile("XXXXXX.pdf"); if (pdfFile.open()) { pdfFile.write(pData); - result = UBDocumentManager::documentManager()->addFileToDocument(selectedDocument(), pdfFile); + QStringList fileNames; + fileNames << pdfFile.fileName(); + result = UBDocumentManager::documentManager()->addFilesToDocument(selectedDocument(), fileNames); pdfFile.close(); } } @@ -1904,7 +1931,18 @@ UBGraphicsMediaItem* UBBoardController::addVideo(const QUrl& pSourceUrl, bool st QUuid uuid = QUuid::createUuid(); QUrl concreteUrl = pSourceUrl; - concreteUrl = QUrl::fromLocalFile(UBPersistenceManager::persistenceManager()->addVideoFileToDocument(selectedDocument(), pSourceUrl.toLocalFile(), uuid)); + QString destFile; + bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(), + pSourceUrl.toLocalFile(), + UBPersistenceManager::videoDirectory, + uuid, + destFile); + if (!b) + { + showMessage(tr("Add file operation failed: file copying error")); + return NULL; + } + concreteUrl = QUrl::fromLocalFile(destFile); UBGraphicsMediaItem* vi = mActiveScene->addMedia(concreteUrl, startPlay, pos); selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); @@ -1923,7 +1961,18 @@ UBGraphicsMediaItem* UBBoardController::addAudio(const QUrl& pSourceUrl, bool st QUuid uuid = QUuid::createUuid(); QUrl concreteUrl = pSourceUrl; - concreteUrl = QUrl::fromLocalFile(UBPersistenceManager::persistenceManager()->addAudioFileToDocument(selectedDocument(), pSourceUrl.toLocalFile(), uuid)); + QString destFile; + bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(), + pSourceUrl.toLocalFile(), + UBPersistenceManager::audioDirectory, + uuid, + destFile); + if (!b) + { + showMessage(tr("Add file operation failed: file copying error")); + return NULL; + } + concreteUrl = QUrl::fromLocalFile(destFile); UBGraphicsMediaItem* ai = mActiveScene->addMedia(concreteUrl, startPlay, pos); selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); @@ -1942,9 +1991,11 @@ UBGraphicsWidgetItem *UBBoardController::addW3cWidget(const QUrl &pUrl, const QP UBGraphicsWidgetItem* w3cWidgetItem = 0; QUuid uuid = QUuid::createUuid(); - QUrl newUrl = pUrl; - newUrl = QUrl::fromLocalFile(UBPersistenceManager::persistenceManager()->addGraphicsWidgteToDocument(selectedDocument(), pUrl.toLocalFile(), uuid)); + QString destPath; + if (!UBPersistenceManager::persistenceManager()->addGraphicsWidgteToDocument(selectedDocument(), pUrl.toLocalFile(), uuid, destPath)) + return NULL; + QUrl newUrl = QUrl::fromLocalFile(destPath); w3cWidgetItem = mActiveScene->addW3CWidget(newUrl, pos); diff --git a/src/core/UBDocumentManager.cpp b/src/core/UBDocumentManager.cpp index 1b6ad22a..9db3dbe0 100644 --- a/src/core/UBDocumentManager.cpp +++ b/src/core/UBDocumentManager.cpp @@ -128,36 +128,124 @@ UBDocumentProxy* UBDocumentManager::importFile(const QFile& pFile, const QString { QFileInfo fileInfo(pFile); - UBDocumentProxy* document = 0; - - foreach (UBImportAdaptor *importAdaptor, mImportAdaptors) + foreach (UBImportAdaptor *adaptor, mImportAdaptors) { - if (importAdaptor->supportedExtentions().lastIndexOf(fileInfo.suffix().toLower()) != -1) + if (adaptor->supportedExtentions().lastIndexOf(fileInfo.suffix().toLower()) != -1) { + UBDocumentProxy* document; UBApplication::setDisabled(true); - document = importAdaptor->importFile(pFile, pGroup); + + if (adaptor->isDocumentBased()) + { + UBDocumentBasedImportAdaptor* importAdaptor = (UBDocumentBasedImportAdaptor*)adaptor; + + document = importAdaptor->importFile(pFile, pGroup); + + } + else + { + UBPageBasedImportAdaptor* importAdaptor = (UBPageBasedImportAdaptor*)adaptor; + + // Document import procedure..... + QString documentName = QFileInfo(pFile.fileName()).completeBaseName(); + document = UBPersistenceManager::persistenceManager()->createDocument(pGroup, documentName); + + QUuid uuid = QUuid::createUuid(); + QString filepath = pFile.fileName(); + if (importAdaptor->folderToCopy() != "") + { + bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(document, pFile.fileName(), importAdaptor->folderToCopy() , uuid, filepath); + if (!b) + { + UBPersistenceManager::persistenceManager()->deleteDocument(document); + UBApplication::setDisabled(false); + return NULL; + } + } + + QList pages = importAdaptor->import(uuid, filepath); + int nPage = 0; + foreach(UBGraphicsItem* page, pages) + { + UBApplication::showMessage(tr("Inserting page %1 of %2").arg(++nPage).arg(pages.size()), true); + int pageIndex = document->pageCount(); + UBGraphicsScene* scene = UBPersistenceManager::persistenceManager()->createDocumentSceneAt(document, pageIndex); + importAdaptor->placeImportedItemToScene(scene, page); + UBPersistenceManager::persistenceManager()->persistDocumentScene(document, scene, pageIndex); + } + + UBPersistenceManager::persistenceManager()->persistDocumentMetadata(document); + UBApplication::showMessage(tr("Import successful.")); + } + UBApplication::setDisabled(false); + return document; } - } - return document; + } + return NULL; } -bool UBDocumentManager::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) +int UBDocumentManager::addFilesToDocument(UBDocumentProxy* document, QStringList fileNames) { - QFileInfo fileInfo(pFile); - foreach (UBImportAdaptor *importAdaptor, mImportAdaptors) + int nImportedDocuments = 0; + foreach(const QString& fileName, fileNames) { - if (importAdaptor->supportedExtentions().lastIndexOf(fileInfo.suffix().toLower()) != -1) + UBApplication::showMessage(tr("Importing file").arg(fileName)); + + QFile file(fileName); + QFileInfo fileInfo(file); + + foreach (UBImportAdaptor *adaptor, mImportAdaptors) { - UBApplication::setDisabled(true); - bool result = importAdaptor->addFileToDocument(pDocument, pFile); - UBApplication::setDisabled(false); - return result; + if (adaptor->supportedExtentions().lastIndexOf(fileInfo.suffix().toLower()) != -1) + { + UBApplication::setDisabled(true); + + if (adaptor->isDocumentBased()) + { + UBDocumentBasedImportAdaptor* importAdaptor = (UBDocumentBasedImportAdaptor*)adaptor; + + if (importAdaptor->addFileToDocument(document, file)) + nImportedDocuments++; + } + else + { + UBPageBasedImportAdaptor* importAdaptor = (UBPageBasedImportAdaptor*)adaptor; + + QUuid uuid = QUuid::createUuid(); + QString filepath = file.fileName(); + if (importAdaptor->folderToCopy() != "") + { + bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(document, file.fileName(), importAdaptor->folderToCopy() , uuid, filepath); + if (!b) + { + continue; + } + } + + QList pages = importAdaptor->import(uuid, filepath); + int nPage = 0; + foreach(UBGraphicsItem* page, pages) + { + UBApplication::showMessage(tr("Inserting page %1 of %2").arg(++nPage).arg(pages.size()), true); + int pageIndex = document->pageCount(); + UBGraphicsScene* scene = UBPersistenceManager::persistenceManager()->createDocumentSceneAt(document, pageIndex); + importAdaptor->placeImportedItemToScene(scene, page); + UBPersistenceManager::persistenceManager()->persistDocumentScene(document, scene, pageIndex); + } + + UBPersistenceManager::persistenceManager()->persistDocumentMetadata(document); + UBApplication::showMessage(tr("Import of file %1 successful.").arg(file.fileName())); + nImportedDocuments++; + } + + UBApplication::setDisabled(false); + } } } - return false; + return nImportedDocuments; } @@ -167,14 +255,14 @@ int UBDocumentManager::addImageDirToDocument(const QDir& pDir, UBDocumentProxy* filenames = UBStringUtils::sortByLastDigit(filenames); - QStringList fullPathFilenames; + QStringList fileNames; foreach(QString f, filenames) { - fullPathFilenames << pDir.absolutePath() + "/" + f; + fileNames << pDir.absolutePath() + "/" + f; } - return addImageAsPageToDocument(fullPathFilenames, pDocument); + return addFilesToDocument(pDocument, fileNames); } @@ -209,87 +297,6 @@ QList UBDocumentManager::supportedExportAdaptors() return mExportAdaptors; } -int UBDocumentManager::addImageAsPageToDocument(const QStringList& filenames, UBDocumentProxy* pDocument) -{ - - int result = 0; - - if (filenames.size() > 0) - { - QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - - QApplication::processEvents(); - - int pageIndex = pDocument->pageCount(); - - if (pageIndex == 1 && UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocument, 0)->isEmpty()) - { - pageIndex = 0; - } - - int expectedPageCount = filenames.size(); - - for(int i = 0; i < filenames.size(); i ++) - { - UBApplication::showMessage(tr("Importing page %1 of %2").arg(i + 1).arg(expectedPageCount)); - - UBGraphicsScene* scene = 0; - - QString fullPath = filenames.at(i); - - QGraphicsItem *gi = 0; - - if (pageIndex == 0) - { - scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocument, pageIndex); - } - else - { - scene = UBPersistenceManager::persistenceManager()->createDocumentSceneAt(pDocument, pageIndex); - } - - scene->setBackground(false, false); - - if (fullPath.endsWith(".svg") || fullPath.endsWith(".svgz")) - { - gi = scene->addSvg(QUrl::fromLocalFile(fullPath), QPointF(0, 0)); - } - else - { - QPixmap pix(fullPath); - - if (pix.isNull()) - { - UBApplication::showMessage(tr("Erronous image data, skipping file %1").arg(filenames.at(i))); - expectedPageCount--; - continue; - } - else - { - gi = scene->addPixmap(pix, NULL, QPointF(0, 0)); - } - } - - if (gi) - { - scene->setAsBackgroundObject(gi, true); - - UBPersistenceManager::persistenceManager()->persistDocumentScene(pDocument, scene, pageIndex); - - pageIndex++; - } - - } - - result = expectedPageCount; - - QApplication::restoreOverrideCursor(); - - } - - return result; - -} void UBDocumentManager::emitDocumentUpdated(UBDocumentProxy* pDocument) { diff --git a/src/core/UBDocumentManager.h b/src/core/UBDocumentManager.h index eca7e2ba..006eede9 100644 --- a/src/core/UBDocumentManager.h +++ b/src/core/UBDocumentManager.h @@ -36,13 +36,11 @@ class UBDocumentManager : public QObject UBDocumentProxy* importFile(const QFile& pFile, const QString& pGroup); - bool addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile); + int addFilesToDocument(UBDocumentProxy* pDocument, QStringList fileNames); UBDocumentProxy* importDir(const QDir& pDir, const QString& pGroup); int addImageDirToDocument(const QDir& pDir, UBDocumentProxy* pDocument); - int addImageAsPageToDocument(const QStringList& images, UBDocumentProxy* document); - QList supportedExportAdaptors(); void emitDocumentUpdated(UBDocumentProxy* pDocument); diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index bc90fc52..954af5b5 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -878,170 +878,82 @@ QString UBPersistenceManager::addObjectToTeacherGuideDirectory(UBDocumentProxy* return destPath; } - -QString UBPersistenceManager::addVideoFileToDocument(UBDocumentProxy* pDocumentProxy, QString path, QUuid objectUuid) +bool UBPersistenceManager::addFileToDocument(UBDocumentProxy* pDocumentProxy, + QString path, + const QString& subdir, + QUuid objectUuid, + QString& destinationPath, + QByteArray* data) { QFileInfo fi(path); - if (!fi.exists() || !pDocumentProxy || objectUuid.isNull()) - return ""; - - QString fileName = UBPersistenceManager::videoDirectory + "/" + objectUuid.toString() + "." + fi.suffix(); - - QString destPath = pDocumentProxy->persistencePath() + "/" + fileName; - - if (!QFile::exists(destPath)) - { - QDir dir; - dir.mkdir(pDocumentProxy->persistencePath() + "/" + UBPersistenceManager::videoDirectory); - - QFile source(path); - - source.copy(destPath); - - } - - return destPath; - -} - - -QString UBPersistenceManager::addVideoFileToDocument(UBDocumentProxy* pDocumentProxy, QUrl sourceUrl, QByteArray pPayload, QUuid objectUuid) -{ if (!pDocumentProxy || objectUuid.isNull()) - return ""; + return false; + if (data == NULL && !fi.exists()) + return false; - QString urlPath = sourceUrl.path(); - int lastDot = urlPath.lastIndexOf("."); - QString suffix = urlPath.right(urlPath.length() - lastDot - 1); + QString fileName = subdir + "/" + objectUuid.toString() + "." + fi.suffix(); - QString fileName = UBPersistenceManager::videoDirectory + "/" + objectUuid.toString() + "." + suffix; - QString destPath = pDocumentProxy->persistencePath() + "/" + fileName; + destinationPath = pDocumentProxy->persistencePath() + "/" + fileName; - if (!QFile::exists(destPath)) + if (!QFile::exists(destinationPath)) { QDir dir; - dir.mkdir(pDocumentProxy->persistencePath() + "/" + UBPersistenceManager::videoDirectory); + dir.mkdir(pDocumentProxy->persistencePath() + "/" + subdir); + if (!QFile::exists(pDocumentProxy->persistencePath() + "/" + subdir)) + return false; - QFile newFile(destPath); - - if (newFile.open(QIODevice::WriteOnly)) + if (data == NULL) { - newFile.write(pPayload); - newFile.flush(); - newFile.close(); + QFile source(path); + return source.copy(destinationPath); } - } - - return destPath; - -} - - - -QString UBPersistenceManager::addAudioFileToDocument(UBDocumentProxy* pDocumentProxy, QString path, QUuid objectUuid) -{ - QFileInfo fi(path); - - if (!fi.exists() || !pDocumentProxy || objectUuid.isNull()) - return ""; - - QString fileName = UBPersistenceManager::audioDirectory + "/" + objectUuid.toString() + "." + fi.suffix(); - - QString destPath = pDocumentProxy->persistencePath() + "/" + fileName; - - if (!QFile::exists(destPath)) - { - QDir dir; - dir.mkdir(pDocumentProxy->persistencePath() + "/" + UBPersistenceManager::audioDirectory); - - QFile source(path); - - source.copy(destPath); - - } - - return destPath; - -} - - -QString UBPersistenceManager::addAudioFileToDocument(UBDocumentProxy* pDocumentProxy, QUrl sourceUrl, QByteArray pPayload, QUuid objectUuid) -{ - if (!pDocumentProxy || objectUuid.isNull()) - return ""; - - QString urlPath = sourceUrl.path(); - int lastDot = urlPath.lastIndexOf("."); - QString suffix = urlPath.right(urlPath.length() - lastDot - 1); - - QString fileName = UBPersistenceManager::audioDirectory + "/" + objectUuid.toString() + "." + suffix; - QString destPath = pDocumentProxy->persistencePath() + "/" + fileName; - - if (!QFile::exists(destPath)) - { - QDir dir; - dir.mkdir(pDocumentProxy->persistencePath() + "/" + UBPersistenceManager::audioDirectory); - - QFile newFile(destPath); - - if (newFile.open(QIODevice::WriteOnly)) + else { - newFile.write(pPayload); - newFile.flush(); - newFile.close(); + QFile newFile(destinationPath); + + if (newFile.open(QIODevice::WriteOnly)) + { + qint64 n = newFile.write(*data); + newFile.flush(); + newFile.close(); + return n == data->size(); + } + else + { + return false; + } } } - - //return fileName; - return destPath; - -} - - -QString UBPersistenceManager::addPdfFileToDocument(UBDocumentProxy* pDocumentProxy, QString path, QUuid objectUuid) -{ - QFileInfo fi(path); - - if (!fi.exists() || !pDocumentProxy || objectUuid.isNull()) - return ""; - - QString fileName = UBPersistenceManager::objectDirectory + "/" + objectUuid.toString() + "." + fi.suffix(); - QString destPath = pDocumentProxy->persistencePath() + "/" + fileName; - - if (!QFile::exists(destPath)) + else { - QDir dir; - dir.mkpath(pDocumentProxy->persistencePath() + "/" + UBPersistenceManager::objectDirectory); - - QFile source(path); - source.copy(destPath); + return false; } - - return fileName; } -QString UBPersistenceManager::addGraphicsWidgteToDocument(UBDocumentProxy *pDocumentProxy, QString path, QUuid objectUuid) + +bool UBPersistenceManager::addGraphicsWidgteToDocument(UBDocumentProxy *pDocumentProxy, + QString path, + QUuid objectUuid, + QString& destinationPath) { QFileInfo fi(path); if (!fi.exists() || !pDocumentProxy || objectUuid.isNull()) - return ""; + return false; QString widgetRootDir = path; QString extension = QFileInfo(widgetRootDir).suffix(); - QString widgetTargetDir = pDocumentProxy->persistencePath() + "/" + widgetDirectory + "/" + objectUuid.toString() + "." + extension; + destinationPath = pDocumentProxy->persistencePath() + "/" + widgetDirectory + "/" + objectUuid.toString() + "." + extension; - if (!QFile::exists(widgetTargetDir)) { + if (!QFile::exists(destinationPath)) { QDir dir; - dir.mkpath(widgetTargetDir); - UBFileSystemUtils::copyDir(widgetRootDir, widgetTargetDir); + if (!dir.mkpath(destinationPath)) + return false; + return UBFileSystemUtils::copyDir(widgetRootDir, destinationPath); } - - if (!QFile::exists(widgetTargetDir)) - widgetTargetDir = QString(); - - return widgetTargetDir; + else + return false; } diff --git a/src/core/UBPersistenceManager.h b/src/core/UBPersistenceManager.h index 14b339f6..9ea21db3 100644 --- a/src/core/UBPersistenceManager.h +++ b/src/core/UBPersistenceManager.h @@ -100,12 +100,8 @@ class UBPersistenceManager : public QObject virtual bool isEmpty(UBDocumentProxy* pDocumentProxy); virtual void purgeEmptyDocuments(); - virtual QString addVideoFileToDocument(UBDocumentProxy* pDocumentProxy, QString path, QUuid objectUuid); - virtual QString addVideoFileToDocument(UBDocumentProxy* pDocumentProxy, QUrl sourceUrl, QByteArray pPayload, QUuid objectUuid); - virtual QString addAudioFileToDocument(UBDocumentProxy* pDocumentProxy, QString path, QUuid objectUuid); - virtual QString addAudioFileToDocument(UBDocumentProxy* pDocumentProxy, QUrl sourceUrl, QByteArray pPayload, QUuid objectUuid); - virtual QString addPdfFileToDocument(UBDocumentProxy* pDocumentProxy, QString path, QUuid objectUuid); - virtual QString addGraphicsWidgteToDocument(UBDocumentProxy *mDocumentProxy, QString path, QUuid objectUuid); + bool addGraphicsWidgteToDocument(UBDocumentProxy *mDocumentProxy, QString path, QUuid objectUuid, QString& destinationPath); + bool addFileToDocument(UBDocumentProxy* pDocumentProxy, QString path, const QString& subdir, QUuid objectUuid, QString& destinationPath, QByteArray* data = NULL); bool mayHaveVideo(UBDocumentProxy* pDocumentProxy); bool mayHaveAudio(UBDocumentProxy* pDocumentProxy); diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index 1fe4763c..d7a5b6d3 100755 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -1006,11 +1006,12 @@ bool UBDocumentController::addFileToDocument(UBDocumentProxy* document) if (filePath.length() > 0) { QApplication::processEvents(); - QFile selectedFile(filePath); showMessage(tr("Importing file %1...").arg(fileInfo.baseName()), true); - success = UBDocumentManager::documentManager()->addFileToDocument(document, selectedFile); + QStringList fileNames; + fileNames << filePath; + success = UBDocumentManager::documentManager()->addFilesToDocument(document, fileNames); if (success) { @@ -1438,7 +1439,7 @@ void UBDocumentController::addImages() UBSettings::settings()->lastImportFolderPath->set(QVariant(firstImage.absoluteDir().absolutePath())); int importedImageNumber - = UBDocumentManager::documentManager()->addImageAsPageToDocument(images, document); + = UBDocumentManager::documentManager()->addFilesToDocument(document, images); if (importedImageNumber == 0) { From c33a10579a775594e53a38e3fa0311bfd1416480 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Sat, 18 Aug 2012 16:45:54 +0300 Subject: [PATCH 03/15] Document mode: title page selection --- src/document/UBDocumentContainer.cpp | 8 +++++++- src/document/UBDocumentContainer.h | 2 +- src/document/UBDocumentController.cpp | 11 ++++++----- src/gui/UBThumbnailWidget.cpp | 17 +++++++++++------ 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/document/UBDocumentContainer.cpp b/src/document/UBDocumentContainer.cpp index a8d806f0..4f08cd46 100644 --- a/src/document/UBDocumentContainer.cpp +++ b/src/document/UBDocumentContainer.cpp @@ -52,12 +52,18 @@ void UBDocumentContainer::duplicatePages(QList& pageIndexes) emit documentThumbnailsUpdated(this); } -void UBDocumentContainer::movePageToIndex(int source, int target) +bool UBDocumentContainer::movePageToIndex(int source, int target) { + if (source==0) + { + // Title page - cant be moved + return false; + } UBPersistenceManager::persistenceManager()->moveSceneToIndex(mCurrentDocument, source, target); deleteThumbPage(source); insertThumbPage(target); emit documentThumbnailsUpdated(this); + return true; } void UBDocumentContainer::deletePages(QList& pageIndexes) diff --git a/src/document/UBDocumentContainer.h b/src/document/UBDocumentContainer.h index 54e95f37..6e969b83 100644 --- a/src/document/UBDocumentContainer.h +++ b/src/document/UBDocumentContainer.h @@ -37,7 +37,7 @@ class UBDocumentContainer : public QObject static int sceneIndexFromPage(int sceneIndex); void duplicatePages(QList& pageIndexes); - void movePageToIndex(int source, int target); + bool movePageToIndex(int source, int target); void deletePages(QList& pageIndexes); void addPage(int index); void updatePage(int index); diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index d7a5b6d3..3ed2ed2d 100755 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -1032,12 +1032,13 @@ bool UBDocumentController::addFileToDocument(UBDocumentProxy* document) void UBDocumentController::moveSceneToIndex(UBDocumentProxy* proxy, int source, int target) { - UBDocumentContainer::movePageToIndex(source, target); - - proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); - UBMetadataDcSubsetAdaptor::persist(proxy); + if (UBDocumentContainer::movePageToIndex(source, target)) + { + proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); + UBMetadataDcSubsetAdaptor::persist(proxy); - mDocumentUI->thumbnailWidget->hightlightItem(target); + mDocumentUI->thumbnailWidget->hightlightItem(target); + } } diff --git a/src/gui/UBThumbnailWidget.cpp b/src/gui/UBThumbnailWidget.cpp index bf2f69f5..24f7442f 100644 --- a/src/gui/UBThumbnailWidget.cpp +++ b/src/gui/UBThumbnailWidget.cpp @@ -210,13 +210,18 @@ void UBThumbnailWidget::mousePressEvent(QMouseEvent *event) mMousePressPos = event->pos(); UBSceneThumbnailPixmap* sceneItem = dynamic_cast(itemAt(mMousePressPos)); - if(sceneItem){ - int pageIndex = UBDocumentContainer::pageFromSceneIndex(sceneItem->sceneIndex()); - if(pageIndex == 0){ - event->ignore(); - return; - } + if(sceneItem==NULL) + { + event->ignore(); + return; } + //if(sceneItem){ + // int pageIndex = UBDocumentContainer::pageFromSceneIndex(sceneItem->sceneIndex()); + // if(pageIndex == 0){ + // event->ignore(); + // return; + // } + //} mMousePressScenePos = mapToScene(mMousePressPos); QGraphicsItem* underlyingItem = itemAt(mMousePressPos); From 58746c87e5b682475bc0c05e30a3599859a42c86 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Sat, 18 Aug 2012 16:53:07 +0300 Subject: [PATCH 04/15] Board mode: delete page message --- src/board/UBBoardController.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index eb39b204..9ccd5bba 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -628,6 +628,7 @@ void UBBoardController::deleteScene(int nIndex) { QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); persistCurrentScene(); + showMessage(tr("Delete page %1 from document").arg(nIndex), true); QList scIndexes; scIndexes << nIndex; @@ -638,6 +639,7 @@ void UBBoardController::deleteScene(int nIndex) if (nIndex >= pageCount()) nIndex = pageCount()-1; setActiveDocumentScene(nIndex); + showMessage(tr("Page %1 deleted").arg(nIndex)); QApplication::restoreOverrideCursor(); } } From 098998991554cc8d12019399717dbc1d1aca31d3 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 20 Aug 2012 10:34:06 +0300 Subject: [PATCH 05/15] Fixed behavior of Tool-Widgets. Removed memory leak. --- src/board/UBBoardView.cpp | 3 ++- src/gui/UBToolWidget.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 7597d81e..48108361 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -989,7 +989,8 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event) { if (QGraphicsSvgItem::Type != movingItem->type() && UBGraphicsDelegateFrame::Type != movingItem->type() && - UBToolWidget::Type != movingItem->type()) + UBToolWidget::Type != movingItem->type() && + QGraphicsWidget::Type != movingItem->type()) { bReleaseIsNeed = false; if (movingItem->isSelected() && mMultipleSelectionIsEnabled) diff --git a/src/gui/UBToolWidget.cpp b/src/gui/UBToolWidget.cpp index 44587da9..41a78e1a 100644 --- a/src/gui/UBToolWidget.cpp +++ b/src/gui/UBToolWidget.cpp @@ -76,7 +76,7 @@ void UBToolWidget::initialize() if(!sUnpinPixmap) sUnpinPixmap = new QPixmap(":/images/unpin.svg"); - QGraphicsLinearLayout *graphicsLayout = new QGraphicsLinearLayout(Qt::Vertical); + QGraphicsLinearLayout *graphicsLayout = new QGraphicsLinearLayout(Qt::Vertical, this); mFrameWidth = UBSettings::settings()->objectFrameWidth; mContentMargin = sClosePixmap->width() / 2 + mFrameWidth; From a05c266ca0221e6da226925b05eac3c8ad8d15ec Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Mon, 20 Aug 2012 10:39:34 +0200 Subject: [PATCH 06/15] fixed issue 875 --- resources/style.qss | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/resources/style.qss b/resources/style.qss index 46b8dff4..4f3eb2c1 100644 --- a/resources/style.qss +++ b/resources/style.qss @@ -70,11 +70,10 @@ QLabel#UBTGMediaDropMeLabel padding: 2px; } +QTextEdit, +QLineEdit, QComboBox#DockPaletteWidgetComboBox QAbstractItemView { - background-color: white; - color: black; - selection-background-color: lightgreen; selection-color: black; } From 13163fef304b9a7c70e1961703ec1826c9b42d52 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 20 Aug 2012 11:47:55 +0300 Subject: [PATCH 07/15] Frame size doesn't depends on zoom. --- src/domain/UBGraphicsItemDelegate.cpp | 7 +++++++ src/domain/UBGraphicsItemDelegate.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index f26d5ed1..962121a9 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -115,6 +115,7 @@ UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObjec , mToolBarUsed(useToolBar) { // NOOP + connect(UBApplication::boardController, SIGNAL(zoomChanged(qreal)), this, SLOT(onZoomChanged())); } void UBGraphicsItemDelegate::init() @@ -535,6 +536,12 @@ void UBGraphicsItemDelegate::commitUndoStep() } } +void UBGraphicsItemDelegate::onZoomChanged() +{ + mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom()); + + positionHandles(); +} void UBGraphicsItemDelegate::buildButtons() { diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index c45fd8be..fc5c460c 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -259,6 +259,8 @@ class UBGraphicsItemDelegate : public QObject void increaseZlevelTop(); void increaseZlevelBottom(); + void onZoomChanged(); + protected: virtual void buildButtons(); virtual void decorateMenu(QMenu *menu); From 61626ecd285dcca42a57cd8ee572ad1cdab0b374 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 20 Aug 2012 13:22:40 +0300 Subject: [PATCH 08/15] Improved compatibility with Sankore 1.30 text format. Improved performance of loading text from old format. --- src/adaptors/UBSvgSubsetAdaptor.cpp | 6 ++++++ src/domain/UBGraphicsTextItemDelegate.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index e40e164d..370b3240 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -2769,6 +2769,12 @@ UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg() } } + QTextCursor curCursor = textItem->textCursor(); + QTextCharFormat format; + + format.setFont(font); + curCursor.mergeCharFormat(format); + textItem->setTextCursor(curCursor); textItem->setFont(font); QStringRef fill = mXmlReader.attributes().value("color"); diff --git a/src/domain/UBGraphicsTextItemDelegate.cpp b/src/domain/UBGraphicsTextItemDelegate.cpp index 3ab8f973..30ef6f3a 100644 --- a/src/domain/UBGraphicsTextItemDelegate.cpp +++ b/src/domain/UBGraphicsTextItemDelegate.cpp @@ -322,6 +322,12 @@ void UBGraphicsTextItemDelegate::positionHandles() void UBGraphicsTextItemDelegate::ChangeTextSize(qreal factor, textChangeMode changeMode) { + if (scaleSize == changeMode) + { + if (1 == factor) + return; + } + else if (0 == factor) return; From 9a5cc5b8d2129f0f54846fdc65baec744f0797a4 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Mon, 20 Aug 2012 13:32:52 +0300 Subject: [PATCH 09/15] SANKORE-909 Write text : Select the text --- src/domain/UBGraphicsTextItemDelegate.cpp | 17 +++++++++++++++++ src/domain/UBGraphicsTextItemDelegate.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/domain/UBGraphicsTextItemDelegate.cpp b/src/domain/UBGraphicsTextItemDelegate.cpp index 3ab8f973..03efa958 100644 --- a/src/domain/UBGraphicsTextItemDelegate.cpp +++ b/src/domain/UBGraphicsTextItemDelegate.cpp @@ -403,3 +403,20 @@ void UBGraphicsTextItemDelegate::scaleTextSize(qreal multiplyer) { ChangeTextSize(multiplyer, scaleSize); } + +QVariant UBGraphicsTextItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) +{ + if (change == QGraphicsItem::ItemSelectedChange) + { + if (delegated()->isSelected()) + { + QTextCursor c = delegated()->textCursor(); + if (c.hasSelection()) + { + c.clearSelection(); + delegated()->setTextCursor(c); + } + } + } + return UBGraphicsItemDelegate::itemChange(change, value); +} \ No newline at end of file diff --git a/src/domain/UBGraphicsTextItemDelegate.h b/src/domain/UBGraphicsTextItemDelegate.h index b01df4e2..26b3ba9b 100644 --- a/src/domain/UBGraphicsTextItemDelegate.h +++ b/src/domain/UBGraphicsTextItemDelegate.h @@ -40,6 +40,8 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate virtual ~UBGraphicsTextItemDelegate(); bool isEditable(); void scaleTextSize(qreal multiplyer); + virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value); + public slots: void contentsChanged(); From 5796ccb468e7822dee1788431a004114cd7c5b18 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Mon, 20 Aug 2012 15:01:07 +0300 Subject: [PATCH 10/15] Unneccessary comments removed --- src/adaptors/UBImportImage.cpp | 18 --------- src/adaptors/UBImportPDF.cpp | 63 ----------------------------- src/adaptors/UBThumbnailAdaptor.cpp | 3 -- 3 files changed, 84 deletions(-) diff --git a/src/adaptors/UBImportImage.cpp b/src/adaptors/UBImportImage.cpp index c85ba342..64a42fc1 100644 --- a/src/adaptors/UBImportImage.cpp +++ b/src/adaptors/UBImportImage.cpp @@ -74,24 +74,6 @@ QString UBImportImage::importFileFilter() return filter; } -/* -bool UBImportImage::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) -{ - int res = UBDocumentManager::documentManager()->addImageAsPageToDocument(QStringList(QFileInfo(pFile).absoluteFilePath()), pDocument); - if (res == 0) - { - UBApplication::showMessage(tr("Image import failed.")); - return false; - } - else - { - UBApplication::showMessage(tr("Image import successful.")); - return true; - } -} -*/ - - QList UBImportImage::import(const QUuid& uuid, const QString& filePath) { QList result; diff --git a/src/adaptors/UBImportPDF.cpp b/src/adaptors/UBImportPDF.cpp index a1971118..fd9dc16b 100644 --- a/src/adaptors/UBImportPDF.cpp +++ b/src/adaptors/UBImportPDF.cpp @@ -91,66 +91,3 @@ const QString& UBImportPDF::folderToCopy() { return UBPersistenceManager::objectDirectory; } - -/* -bool UBImportPDF::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) -{ - QString documentName = QFileInfo(pFile.fileName()).completeBaseName(); - - QUuid uuid = QUuid::createUuid(); - - QString filepath = UBPersistenceManager::persistenceManager()->addPdfFileToDocument(pDocument, pFile.fileName(), uuid); - - PDFRenderer *pdfRenderer = PDFRenderer::rendererForUuid(uuid, pDocument->persistencePath() + "/" + filepath, true); // renderer is automatically deleted when not used anymore - - if (!pdfRenderer->isValid()) - { - UBApplication::showMessage(tr("PDF import failed.")); - return false; - } - pdfRenderer->setDPI(this->dpi); - - int documentPageCount = pDocument->pageCount(); - - if (documentPageCount == 1 && UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocument, 0)->isEmpty()) - { - documentPageCount = 0; - } - - int pdfPageCount = pdfRenderer->pageCount(); - - for(int pdfPageNumber = 1; pdfPageNumber <= pdfPageCount; pdfPageNumber++) - { - int pageIndex = documentPageCount + pdfPageNumber; - UBApplication::showMessage(tr("Importing page %1 of %2").arg(pdfPageNumber).arg(pdfPageCount), true); - - UBGraphicsScene* scene = 0; - - if (pageIndex == 0) - { - scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocument, pageIndex); - } - else - { - scene = UBPersistenceManager::persistenceManager()->createDocumentSceneAt(pDocument, pageIndex); - } - - scene->setBackground(false, false); - UBGraphicsPDFItem *pdfItem = new UBGraphicsPDFItem(pdfRenderer, pdfPageNumber); // deleted by the scene - scene->addItem(pdfItem); - - pdfItem->setPos(-pdfItem->boundingRect().width() / 2, -pdfItem->boundingRect().height() / 2); - - scene->setAsBackgroundObject(pdfItem, false, false); - - scene->setNominalSize(pdfItem->boundingRect().width(), pdfItem->boundingRect().height()); - - - UBPersistenceManager::persistenceManager()->persistDocumentScene(pDocument, scene, pageIndex); - } - - UBApplication::showMessage(tr("PDF import successful.")); - - return true; -} -*/ \ No newline at end of file diff --git a/src/adaptors/UBThumbnailAdaptor.cpp b/src/adaptors/UBThumbnailAdaptor.cpp index 057cf991..5feaccd8 100644 --- a/src/adaptors/UBThumbnailAdaptor.cpp +++ b/src/adaptors/UBThumbnailAdaptor.cpp @@ -117,9 +117,6 @@ void UBThumbnailAdaptor::load(UBDocumentProxy* proxy, QList& lis void UBThumbnailAdaptor::persistScene(UBDocumentProxy* proxy, UBGraphicsScene* pScene, int pageIndex, bool overrideModified) { - - qDebug() << "Persist scene on path " << proxy->persistencePath() << ", index " << pageIndex; - QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex); QFile thumbFile(fileName); From e0324211a96591cd0bb7ab6e1ed97e7f289a1ae3 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Mon, 20 Aug 2012 14:04:58 +0200 Subject: [PATCH 11/15] fixed issue 882 --- src/gui/UBDockPalette.cpp | 13 ++++++++++++- src/gui/UBDockPalette.h | 3 +++ src/gui/UBLeftPalette.cpp | 8 ++++++++ src/gui/UBLeftPalette.h | 3 +++ src/gui/UBTeacherGuideWidget.cpp | 1 - 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/gui/UBDockPalette.cpp b/src/gui/UBDockPalette.cpp index a302d847..38f375be 100644 --- a/src/gui/UBDockPalette.cpp +++ b/src/gui/UBDockPalette.cpp @@ -17,12 +17,16 @@ #include #include "UBDockPalette.h" -#include "core/UBSettings.h" + #include "frameworks/UBPlatformUtils.h" + +#include "core/UBSettings.h" #include "core/UBApplication.h" #include "core/UBPreferencesController.h" #include "core/UBDownloadManager.h" +#include "board/UBBoardController.h" + #include "core/memcheck.h" /** @@ -79,6 +83,8 @@ UBDockPalette::UBDockPalette(eUBDockPaletteType paletteType, QWidget *parent, co onToolbarPosUpdated(); connect(UBSettings::settings()->appToolBarPositionedAtTop, SIGNAL(changed(QVariant)), this, SLOT(onToolbarPosUpdated())); connect(UBDownloadManager::downloadManager(), SIGNAL(allDownloadsFinished()), this, SLOT(onAllDownloadsFinished())); + + connect(UBApplication::boardController,SIGNAL(documentSet(UBDocumentProxy*)),this,SLOT(onDocumentSet(UBDocumentProxy*))); } /** @@ -98,6 +104,11 @@ UBDockPalette::~UBDockPalette() } } +void UBDockPalette::onDocumentSet(UBDocumentProxy* documentProxy) +{ + Q_UNUSED(documentProxy); +} + /** * \brief Get the current orientation * @return the current orientation diff --git a/src/gui/UBDockPalette.h b/src/gui/UBDockPalette.h index f1c6f323..2dac9e08 100644 --- a/src/gui/UBDockPalette.h +++ b/src/gui/UBDockPalette.h @@ -15,6 +15,8 @@ #ifndef UBDOCKPALETTE_H #define UBDOCKPALETTE_H +class UBDocumentProxy; + #include #include #include @@ -131,6 +133,7 @@ public slots: void onShowTabWidget(UBDockPaletteWidget* widget); void onHideTabWidget(UBDockPaletteWidget* widget); void onAllDownloadsFinished(); + virtual void onDocumentSet(UBDocumentProxy* documentProxy); protected: virtual int border(); diff --git a/src/gui/UBLeftPalette.cpp b/src/gui/UBLeftPalette.cpp index 7f79ff18..ffb93f90 100644 --- a/src/gui/UBLeftPalette.cpp +++ b/src/gui/UBLeftPalette.cpp @@ -51,6 +51,14 @@ UBLeftPalette::~UBLeftPalette() } + +void UBLeftPalette::onDocumentSet(UBDocumentProxy* documentProxy) +{ + //This is necessary to force the teacher guide to be showed in priority each time a document is set + if(documentProxy && UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool()) + mLastOpenedTabForMode.insert(eUBDockPaletteWidget_BOARD, 1); +} + /** * \brief Update the maximum width */ diff --git a/src/gui/UBLeftPalette.h b/src/gui/UBLeftPalette.h index 43f472ab..72e4fc1a 100644 --- a/src/gui/UBLeftPalette.h +++ b/src/gui/UBLeftPalette.h @@ -25,6 +25,9 @@ public: bool switchMode(eUBDockPaletteWidgetMode mode); +public slots: + void onDocumentSet(UBDocumentProxy* documentProxy); + protected: void updateMaxWidth(); void resizeEvent(QResizeEvent *event); diff --git a/src/gui/UBTeacherGuideWidget.cpp b/src/gui/UBTeacherGuideWidget.cpp index cb2b912d..ee81836e 100644 --- a/src/gui/UBTeacherGuideWidget.cpp +++ b/src/gui/UBTeacherGuideWidget.cpp @@ -1149,7 +1149,6 @@ void UBTeacherGuideWidget::onActiveSceneChanged() mpPageZeroWidget->switchToMode(tUBTGZeroPageMode_EDITION); setCurrentWidget(mpPageZeroWidget); - } else{ if(mpEditionWidget->isModified()){ From d9cc7b6ecd34d762e2aefd367ebba312535ccd25 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 20 Aug 2012 15:08:05 +0300 Subject: [PATCH 12/15] Only selector tool can create and remove groups. --- src/domain/UBGraphicsScene.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 4c53593c..19a7e851 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -317,6 +317,11 @@ void UBGraphicsScene::selectionChangedProcessing() void UBGraphicsScene::updateGroupButtonState() { + + UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool(); + if (UBStylusTool::Selector != currentTool) + return; + QAction *groupAction = UBApplication::mainWindow->actionGroupItems; QList selItems = selectedItems(); int selCount = selItems.count(); From 7c14893b3032a127a7579f33d5eb5000821c14af Mon Sep 17 00:00:00 2001 From: Yimgo Date: Mon, 20 Aug 2012 15:02:48 +0200 Subject: [PATCH 13/15] Fixed drag and drop in widget items. --- src/api/UBWidgetUniboardAPI.cpp | 22 ++++++------ src/api/UBWidgetUniboardAPI.h | 4 +-- src/board/UBBoardView.cpp | 50 +++++--------------------- src/domain/UBGraphicsWebView.cpp | 4 +-- src/domain/UBGraphicsWebView.h | 2 +- src/domain/UBGraphicsWidgetItem.cpp | 54 ++++++++++++++--------------- src/domain/UBGraphicsWidgetItem.h | 5 +-- 7 files changed, 53 insertions(+), 88 deletions(-) diff --git a/src/api/UBWidgetUniboardAPI.cpp b/src/api/UBWidgetUniboardAPI.cpp index 73ecbfae..0e2a54f1 100644 --- a/src/api/UBWidgetUniboardAPI.cpp +++ b/src/api/UBWidgetUniboardAPI.cpp @@ -476,7 +476,7 @@ void UBWidgetUniboardAPI::enableDropOnWidget(bool enable) } } -void UBWidgetUniboardAPI::ProcessDropEvent(QDropEvent *event) +void UBWidgetUniboardAPI::ProcessDropEvent(QGraphicsSceneDragDropEvent *event) { const QMimeData *pMimeData = event->mimeData(); @@ -485,11 +485,12 @@ void UBWidgetUniboardAPI::ProcessDropEvent(QDropEvent *event) bool downloaded = false; QGraphicsView *tmpView = mGraphicsWidget->scene()->views().at(0); - QPoint dropPoint(mGraphicsWidget->mapFromScene(tmpView->mapToScene(event->pos())).toPoint()); - Qt::DropActions dropActions = event->dropAction(); - Qt::MouseButtons dropMouseButtons = event->mouseButtons(); - Qt::KeyboardModifiers dropModifiers = event->keyboardModifiers(); - QMimeData dropMimeData; + QPoint dropPoint(mGraphicsWidget->mapFromScene(tmpView->mapToScene(event->pos().toPoint())).toPoint()); + Qt::DropActions dropActions = event->possibleActions(); + Qt::MouseButtons dropMouseButtons = event->buttons(); + Qt::KeyboardModifiers dropModifiers = event->modifiers(); + QMimeData *dropMimeData = new QMimeData; + qDebug() << event->possibleActions(); if (pMimeData->hasHtml()) { //Dropping element from web browser @@ -510,7 +511,7 @@ void UBWidgetUniboardAPI::ProcessDropEvent(QDropEvent *event) desc.name = QFileInfo(url).fileName(); desc.totalSize = 0; // The total size will be retrieved during the download - desc.dropPoint = event->pos(); //Passing pure event point. No modifications + desc.dropPoint = event->pos().toPoint(); //Passing pure event point. No modifications desc.dropActions = dropActions; desc.dropMouseButtons = dropMouseButtons; desc.dropModifiers = dropModifiers; @@ -542,12 +543,9 @@ void UBWidgetUniboardAPI::ProcessDropEvent(QDropEvent *event) } qDebug() << destFileName; QString mimeText = createMimeText(downloaded, contentType, destFileName); - dropMimeData.setData(tMimeText, mimeText.toAscii()); + dropMimeData->setData(tMimeText, mimeText.toAscii()); - QDropEvent readyEvent(dropPoint, dropActions, &dropMimeData, dropMouseButtons, dropModifiers); - //sending event to destination either it had been downloaded or not - QApplication::sendEvent(mGraphicsWidget,&readyEvent); - readyEvent.acceptProposedAction(); + event->setMimeData(dropMimeData); } void UBWidgetUniboardAPI::onDownloadFinished(bool pSuccess, sDownloadFileDesc desc, QByteArray pData) diff --git a/src/api/UBWidgetUniboardAPI.h b/src/api/UBWidgetUniboardAPI.h index 385f9417..a1bef6ce 100644 --- a/src/api/UBWidgetUniboardAPI.h +++ b/src/api/UBWidgetUniboardAPI.h @@ -16,7 +16,7 @@ #define UBWIDGETAPI_H #include -#include +#include #include "UBW3CWidgetAPI.h" #include "core/UBDownloadManager.h" @@ -246,7 +246,7 @@ class UBWidgetUniboardAPI : public QObject * When an object is dropped on a widget, this one send us the informations to download it locally. * this method download the object on the widget directory and return the path of the downloaded object */ - void ProcessDropEvent(QDropEvent *); + void ProcessDropEvent(QGraphicsSceneDragDropEvent *); bool isDropableData(const QMimeData *pMimeData) const; private slots: diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 7597d81e..7bbbd219 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -1202,56 +1202,22 @@ UBBoardView::drawItems (QPainter *painter, int numItems, } -void UBBoardView::dragMoveEvent (QDragMoveEvent *event) +void UBBoardView::dragMoveEvent(QDragMoveEvent *event) { - QGraphicsItem* graphicsItemAtPos = itemAt(event->pos().x(),event->pos().y()); - UBGraphicsWidgetItem* graphicsWidget = dynamic_cast(graphicsItemAtPos); - - if (graphicsWidget) { - if (graphicsWidget->acceptDrops()) { - if (!mOkOnWidget) { - if (!graphicsWidget->isDropableData(event->mimeData())) { - mOkOnWidget = false; - event->ignore(); - return; - } else { - mOkOnWidget = true; - } - } - QPoint newPoint(graphicsWidget->mapFromScene(mapToScene(event->pos())).toPoint()); - QDragMoveEvent newEvent(newPoint, event->dropAction(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers()); - QApplication::sendEvent(graphicsWidget,&newEvent); - } else { - mOkOnWidget = false; - event->ignore(); - } - } else { - event->acceptProposedAction(); - mOkOnWidget = false; - } + QGraphicsView::dragMoveEvent(event); + event->acceptProposedAction(); } void UBBoardView::dropEvent (QDropEvent *event) { - mOkOnWidget = false; - QGraphicsItem* graphicsItemAtPos = itemAt(event->pos().x(),event->pos().y()); - UBGraphicsWidgetItem* graphicsWidget = dynamic_cast(graphicsItemAtPos); - - if (graphicsWidget && graphicsWidget->acceptDrops()) { - - graphicsWidget->processDropEvent(event); - event->acceptProposedAction(); - - } else if (!event->source() - || dynamic_cast(event->source()) - || dynamic_cast(event->source()) - || dynamic_cast(event->source()) - || dynamic_cast(event->source()) - || dynamic_cast(event->source())) { - + if (!itemAt(event->pos().x(),event->pos().y())) { + if (!event->source() || dynamic_cast(event->source()) || dynamic_cast(event->source()) || dynamic_cast(event->source()) || dynamic_cast(event->source()) || dynamic_cast(event->source())) { mController->processMimeData (event->mimeData (), mapToScene (event->pos ())); event->acceptProposedAction(); } + } + else + QGraphicsView::dropEvent(event); } void diff --git a/src/domain/UBGraphicsWebView.cpp b/src/domain/UBGraphicsWebView.cpp index ea6a66ad..79b0d3f7 100644 --- a/src/domain/UBGraphicsWebView.cpp +++ b/src/domain/UBGraphicsWebView.cpp @@ -151,10 +151,10 @@ void UBGraphicsWebView::remove() mDelegate->remove(true); } -bool UBGraphicsWebView::event(QEvent *event) +/*bool UBGraphicsWebView::event(QEvent *event) { if (event->type() == QEvent::ShortcutOverride) event->accept(); return QGraphicsWebView::event(event); -} +}*/ diff --git a/src/domain/UBGraphicsWebView.h b/src/domain/UBGraphicsWebView.h index 988c4cbd..767a99c2 100644 --- a/src/domain/UBGraphicsWebView.h +++ b/src/domain/UBGraphicsWebView.h @@ -54,7 +54,7 @@ class UBGraphicsWebView: public QGraphicsWebView, public UBItem, public UBResiza virtual void wheelEvent(QGraphicsSceneWheelEvent *event); virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); - virtual bool event(QEvent *event); + //virtual bool event(QEvent *event); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); }; diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index 662cc947..0f056860 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -97,7 +97,6 @@ UBGraphicsWidgetItem::~UBGraphicsWidgetItem() void UBGraphicsWidgetItem::initialize() { - installEventFilter(this); UBGraphicsWebView::setMinimumSize(nominalSize()); setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); // Necessary to set if we want z value to be assigned correctly @@ -277,9 +276,9 @@ void UBGraphicsWidgetItem::removeScript() page()->mainFrame()->evaluateJavaScript("if(widget && widget.onremove) { widget.onremove();}"); } -void UBGraphicsWidgetItem::processDropEvent(QDropEvent *event) +void UBGraphicsWidgetItem::processDropEvent(QGraphicsSceneDragDropEvent *event) { - return mUniboardAPI->ProcessDropEvent(event); + mUniboardAPI->ProcessDropEvent(event); } bool UBGraphicsWidgetItem::isDropableData(const QMimeData *data) const { @@ -486,6 +485,31 @@ void UBGraphicsWidgetItem::unFreeze() mIsFrozen = false; } +bool UBGraphicsWidgetItem::event(QEvent *event) +{ + if (mShouldMoveWidget && event->type() == QEvent::MouseMove) { + QMouseEvent *mouseMoveEvent = static_cast(event); + if (mouseMoveEvent->buttons() & Qt::LeftButton) { + QPointF scenePos = mapToScene(mouseMoveEvent->pos()); + QPointF newPos = pos() + scenePos - mLastMousePos; + setPos(newPos); + mLastMousePos = scenePos; + event->accept(); + return true; + } + } + else if (event->type() == QEvent::ShortcutOverride) + event->accept(); + + return UBGraphicsWebView::event(event); +} + +void UBGraphicsWidgetItem::dropEvent(QGraphicsSceneDragDropEvent *event) +{ + processDropEvent(event); + QGraphicsWebView::dropEvent(event); +} + void UBGraphicsWidgetItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { UBGraphicsWebView::mousePressEvent(event); @@ -522,30 +546,6 @@ void UBGraphicsWidgetItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) UBGraphicsWebView::hoverMoveEvent(event); } -bool UBGraphicsWidgetItem::eventFilter(QObject *obj, QEvent *event) -{ - if (mShouldMoveWidget && obj == this && event->type() == QEvent::MouseMove) { - QMouseEvent *mouseMoveEvent = static_cast(event); - - if (mouseMoveEvent->buttons() & Qt::LeftButton) { - QPointF scenePos = mapToScene(mouseMoveEvent->pos()); - - QPointF newPos = pos() + scenePos - mLastMousePos; - - setPos(newPos); - - mLastMousePos = scenePos; - - event->accept(); - - return true; - } - } - - /* standard event processing */ - return QObject::eventFilter(obj, event); -} - void UBGraphicsWidgetItem::sendJSEnterEvent() { if (page() && page()->mainFrame()) diff --git a/src/domain/UBGraphicsWidgetItem.h b/src/domain/UBGraphicsWidgetItem.h index 08399603..18fbe1cc 100644 --- a/src/domain/UBGraphicsWidgetItem.h +++ b/src/domain/UBGraphicsWidgetItem.h @@ -76,7 +76,7 @@ class UBGraphicsWidgetItem : public UBGraphicsWebView virtual void remove(); void removeScript(); - void processDropEvent(QDropEvent *event); + void processDropEvent(QGraphicsSceneDragDropEvent *event); bool isDropableData(const QMimeData *data) const; virtual QUrl getOwnFolder() const; @@ -136,12 +136,13 @@ class UBGraphicsWidgetItem : public UBGraphicsWebView QMap mDatastore; QMap mPreferences; + virtual bool event(QEvent *event); + virtual void dropEvent(QGraphicsSceneDragDropEvent *event); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); - virtual bool eventFilter(QObject *obj, QEvent *event); virtual void sendJSEnterEvent(); virtual void sendJSLeaveEvent(); virtual void injectInlineJavaScript(); From 9d18db6d37e8abec1d918e1fdfcbe0e256e5092c Mon Sep 17 00:00:00 2001 From: Yimgo Date: Mon, 20 Aug 2012 15:07:41 +0200 Subject: [PATCH 14/15] Removed unnecessary comments. --- src/domain/UBGraphicsWebView.cpp | 8 -------- src/domain/UBGraphicsWebView.h | 1 - 2 files changed, 9 deletions(-) diff --git a/src/domain/UBGraphicsWebView.cpp b/src/domain/UBGraphicsWebView.cpp index 79b0d3f7..cfc92dc3 100644 --- a/src/domain/UBGraphicsWebView.cpp +++ b/src/domain/UBGraphicsWebView.cpp @@ -150,11 +150,3 @@ void UBGraphicsWebView::remove() if (mDelegate) mDelegate->remove(true); } - -/*bool UBGraphicsWebView::event(QEvent *event) -{ - if (event->type() == QEvent::ShortcutOverride) - event->accept(); - - return QGraphicsWebView::event(event); -}*/ diff --git a/src/domain/UBGraphicsWebView.h b/src/domain/UBGraphicsWebView.h index 767a99c2..45a2db7a 100644 --- a/src/domain/UBGraphicsWebView.h +++ b/src/domain/UBGraphicsWebView.h @@ -54,7 +54,6 @@ class UBGraphicsWebView: public QGraphicsWebView, public UBItem, public UBResiza virtual void wheelEvent(QGraphicsSceneWheelEvent *event); virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); - //virtual bool event(QEvent *event); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); }; From c60d4992bc8a2b5597c8ed8b587e293d6113893e Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 20 Aug 2012 16:14:34 +0300 Subject: [PATCH 15/15] Grouped strokes reads from UBZ fine. it is grouped after reading now. --- src/adaptors/UBSvgSubsetAdaptor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 370b3240..f557ff8a 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -1194,6 +1194,7 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex) UBGraphicsStrokesGroup* strokesGroupItem = qgraphicsitem_cast(item); if(strokesGroupItem && strokesGroupItem->isVisible()){ mXmlWriter.writeStartElement("g"); + mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "uuid", UBStringUtils::toCanonicalUuid(strokesGroupItem->uuid())); QMatrix matrix = item->sceneMatrix(); if (!matrix.isIdentity()){ mXmlWriter.writeAttribute("transform", toSvgTransform(matrix));