diff --git a/JournalDesModifications.pdf b/JournalDesModifications.pdf index cb4a07e9..bd93ac88 100644 Binary files a/JournalDesModifications.pdf and b/JournalDesModifications.pdf differ diff --git a/ReleaseNotes.pdf b/ReleaseNotes.pdf index 26bc0207..4541a954 100644 Binary files a/ReleaseNotes.pdf and b/ReleaseNotes.pdf differ diff --git a/Sankore_3.1.pro b/Sankore_3.1.pro index b885459b..73ddad26 100644 --- a/Sankore_3.1.pro +++ b/Sankore_3.1.pro @@ -11,7 +11,7 @@ CONFIG += debug_and_release \ VERSION_MAJ = 2 VERSION_MIN = 00 VERSION_TYPE = b # a = alpha, b = beta, r = release, other => error -VERSION_PATCH = 02 +VERSION_PATCH = 03 VERSION = "$${VERSION_MAJ}.$${VERSION_MIN}.$${VERSION_TYPE}.$${VERSION_PATCH}" VERSION = $$replace(VERSION, "\\.r", "") diff --git a/resources/style.qss b/resources/style.qss index cc6740aa..a754c544 100644 --- a/resources/style.qss +++ b/resources/style.qss @@ -5,15 +5,21 @@ QWidget#UBLibNavigatorWidget, QWidget#UBLibItemProperties, QWidget#UBDownloadWidget, QWidget#UBTeacherGuideWidget, -QWidget#UBFeatureProperties, QWidget#UBFeaturesNavigatorWidget, -QWidget#PathList +QWidget#PathList, +QWidget#UBFeaturesCentralWidget { background: #EEEEEE; border-radius: 10px; border: 2px solid #999999; } +QWidget#mAdditionalDataContainer +{ + border-radius: 10px; + border: 2px solid #999999; +} + QWidget#UBMediaVideoContainer { background: #000000; @@ -30,15 +36,12 @@ QWidget#UBLibWebView QListView { - border: 0px; + border: 0px; } - -QWidget#UBFeaturesWebView +QWidget#UBFeatureProperties { - background: #EEEEEE; - border-radius : 10px; - border: 2px solid #999999; + border: 2px; } QWebView#SearchEngineView diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 0d23d9f9..88f98768 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -53,6 +53,7 @@ #include "domain/UBGraphicsTextItem.h" #include "domain/UBPageSizeUndoCommand.h" #include "domain/UBGraphicsGroupContainerItem.h" +#include "domain/UBItem.h" #include "tools/UBToolsManager.h" @@ -529,6 +530,92 @@ void UBBoardController::duplicateScene() duplicateScene(mActiveSceneIndex); } +void UBBoardController::duplicateItem(UBItem *item) +{ + if (!item) + return; + + QUrl sourceUrl; + QByteArray pData; + + //common parameters for any item + QPointF itemPos; + QSizeF itemSize; + + QGraphicsItem *commonItem = dynamic_cast(item); + if (commonItem) + { + itemPos = commonItem->pos(); + itemSize = commonItem->boundingRect().size(); + } + + QString contentTypeHeader = UBFileSystemUtils::mimeTypeFromFileName(item->sourceUrl().toLocalFile()); + + UBMimeType::Enum itemMimeType = UBFileSystemUtils::mimeTypeFromString(contentTypeHeader); + + switch(static_cast(itemMimeType)) + { + case UBMimeType::AppleWidget: + case UBMimeType::W3CWidget: + { + UBGraphicsWidgetItem *witem = dynamic_cast(item); + if (witem) + { + sourceUrl = witem->getOwnFolder(); + } + }break; + + case UBMimeType::Video: + case UBMimeType::Audio: + { + UBGraphicsMediaItem *mitem = dynamic_cast(item); + if (mitem) + { + sourceUrl = mitem->mediaFileUrl(); + } + }break; + + case UBMimeType::VectorImage: + { + UBGraphicsSvgItem *viitem = dynamic_cast(item); + if (viitem) + { + pData = viitem->fileData(); + sourceUrl = item->sourceUrl(); + } + }break; + + case UBMimeType::RasterImage: + { + UBGraphicsPixmapItem *pixitem = dynamic_cast(item); + if (pixitem) + { + QBuffer buffer(&pData); + buffer.open(QIODevice::WriteOnly); + QString format = UBFileSystemUtils::extension(item->sourceUrl().toLocalFile()); + pixitem->pixmap().save(&buffer, format.toLatin1()); + } + }break; + case UBMimeType::UNKNOWN: + { + QGraphicsItem *gitem = dynamic_cast(item->deepCopy()); + if (gitem) + { + mActiveScene->addItem(gitem); + gitem->setPos(itemPos); + } + return; + }break; + } + + UBItem *createdItem = downloadFinished(true, sourceUrl, contentTypeHeader, pData, itemPos, QSize(itemSize.width(), itemSize.height()), false); + if (createdItem) + { + createdItem->setSourceUrl(item->sourceUrl()); + item->copyItemParameters(createdItem); + } +} + void UBBoardController::deleteScene(int nIndex) { if (selectedDocument()->pageCount()>2) @@ -854,7 +941,7 @@ void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const } -void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground) +UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground) { QString mimeType = pContentTypeHeader; @@ -869,7 +956,7 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString if (!pSuccess) { UBApplication::showMessage(tr("Downloading content %1 failed").arg(sourceUrl.toString())); - return; + return NULL; } if (!sourceUrl.toString().startsWith("file://") && !sourceUrl.toString().startsWith("uniboardTool://")) @@ -897,12 +984,14 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString pixItem->setSelected(true); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); } + + return pixItem; } else if (UBMimeType::VectorImage == itemMimeType) { qDebug() << "accepting mime type" << mimeType << "as vecto image"; - UBGraphicsSvgItem* svgItem = mActiveScene->addSvg(sourceUrl, pPos); + UBGraphicsSvgItem* svgItem = mActiveScene->addSvg(sourceUrl, pPos, pData); svgItem->setSourceUrl(sourceUrl); if (isBackground) @@ -915,6 +1004,8 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString svgItem->setSelected(true); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); } + + return svgItem; } else if (UBMimeType::AppleWidget == itemMimeType) //mime type invented by us :-( { @@ -939,6 +1030,8 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString { UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); } + + return appleWidgetItem; } else if (UBMimeType::W3CWidget == itemMimeType) { @@ -960,6 +1053,8 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString { UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); } + + return w3cWidgetItem; } else if (UBMimeType::Video == itemMimeType) { @@ -989,6 +1084,8 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString } UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); + + return mediaVideoItem; } else if (UBMimeType::Audio == itemMimeType) { @@ -1018,6 +1115,8 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString } UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); + + return audioMediaItem; } else if (UBMimeType::Flash == itemMimeType) @@ -1061,6 +1160,8 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString widgetItem->setSourceUrl(sourceUrl); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); + + return widgetItem; } if (eduMediaFile) @@ -1182,6 +1283,8 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString widgetItem->setSourceUrl(sourceUrl); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); + + return widgetItem; } } } @@ -1193,6 +1296,8 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString UBApplication::showMessage(tr("Unknown content type %1").arg(pContentTypeHeader)); qWarning() << "ignoring mime type" << pContentTypeHeader ; } + + return NULL; } void UBBoardController::setActiveDocumentScene(int pSceneIndex) @@ -1902,7 +2007,7 @@ UBGraphicsWidgetItem *UBBoardController::addW3cWidget(const QUrl &pUrl, const QP } - return 0; + return w3cWidgetItem; } void UBBoardController::cut() @@ -1957,7 +2062,11 @@ void UBBoardController::copy() UBItem* ubItem = dynamic_cast(gi); if (ubItem && !mActiveScene->tools().contains(gi)) - selected << ubItem->deepCopy(); + { + UBItem *itemCopy = ubItem->deepCopy(); + if (itemCopy) + selected << itemCopy; + } } if (selected.size() > 0) @@ -2014,13 +2123,7 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint { foreach(UBItem* item, mimeData->items()) { - QGraphicsItem* gi = dynamic_cast(item->deepCopy()); - - if (gi) - { - mActiveScene->addItem(gi); - gi->setPos(gi->pos() + QPointF(50, 50)); - } + duplicateItem(item); } return; diff --git a/src/board/UBBoardController.h b/src/board/UBBoardController.h index d5f2b0f6..e2fd4dfe 100644 --- a/src/board/UBBoardController.h +++ b/src/board/UBBoardController.h @@ -39,6 +39,7 @@ class UBGraphicsVideoItem; class UBGraphicsAudioItem; class UBGraphicsWidgetItem; class UBBoardPaletteManager; +class UBItem; class UBBoardController : public UBDocumentContainer @@ -157,6 +158,7 @@ class UBBoardController : public UBDocumentContainer void moveSceneToIndex(int source, int target); void duplicateScene(int index); + void duplicateItem(UBItem *item); void deleteScene(int index); bool cacheIsVisible() {return mCacheWidgetIsEnabled;} @@ -188,7 +190,7 @@ class UBBoardController : public UBDocumentContainer void lastScene(); void groupButtonClicked(); void downloadURL(const QUrl& url, const QPointF& pPos = QPointF(0.0, 0.0), const QSize& pSize = QSize(), bool isBackground = false); - void downloadFinished(bool pSuccess, QUrl sourceUrl, QString pHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground = false); + UBItem *downloadFinished(bool pSuccess, QUrl sourceUrl, QString pHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground = false); void changeBackground(bool isDark, bool isCrossed); void setToolCursor(int tool); void showMessage(const QString& message, bool showSpinningWheel); diff --git a/src/board/UBBoardPaletteManager.cpp b/src/board/UBBoardPaletteManager.cpp index 3cfcd5a1..3b910bc8 100644 --- a/src/board/UBBoardPaletteManager.cpp +++ b/src/board/UBBoardPaletteManager.cpp @@ -665,11 +665,8 @@ void UBBoardPaletteManager::addItem(const QUrl& pUrl) mAddItemPalette->show(); mAddItemPalette->adjustSizeAndPosition(); - QRect controlGeo = UBApplication::applicationController->displayManager()->controlGeometry(); - - mAddItemPalette->move(controlGeo.x() + ((controlGeo.width() - mAddItemPalette->geometry().width()) / 2), - (controlGeo.y() + (controlGeo.height() - mAddItemPalette->geometry().height()) / 5)); - + mAddItemPalette->move((mContainer->width() - mAddItemPalette->width()) / 2, + (mContainer->height() - mAddItemPalette->height()) / 5); } void UBBoardPaletteManager::changeMode(eUBDockPaletteWidgetMode newMode, bool isInit) @@ -835,13 +832,11 @@ void UBBoardPaletteManager::addItem(const QPixmap& pPixmap, const QPointF& pos, mPos = pos; mScaleFactor = scaleFactor; - QRect controlGeo = UBApplication::applicationController->displayManager()->controlGeometry(); - mAddItemPalette->show(); mAddItemPalette->adjustSizeAndPosition(); - mAddItemPalette->move(controlGeo.x() + ((controlGeo.width() - mAddItemPalette->geometry().width()) / 2), - (controlGeo.y() + (controlGeo.height() - mAddItemPalette->geometry().height()) / 5)); + mAddItemPalette->move((mContainer->width() - mAddItemPalette->width()) / 2, + (mContainer->height() - mAddItemPalette->height()) / 5); } diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp index c45ebffd..a0bac9dd 100644 --- a/src/board/UBFeaturesController.cpp +++ b/src/board/UBFeaturesController.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "core/UBApplication.h" #include "board/UBBoardController.h" @@ -9,7 +10,6 @@ #include "frameworks/UBFileSystemUtils.h" #include "frameworks/UBPlatformUtils.h" - #include "core/UBDownloadManager.h" #include "domain/UBAbstractWidget.h" #include "domain/UBGraphicsScene.h" @@ -22,20 +22,168 @@ const QString UBFeaturesController::virtualRootName = "root"; -UBFeature::UBFeature(const QString &url, const QPixmap &icon, const QString &name, const QUrl &realPath, UBFeatureElementType type) -: virtualDir(url), mThumbnail(icon), mName(name), mPath(realPath), elementType(type) +void UBFeaturesComputingThread::scanFS(const QUrl & currentPath, const QString & currVirtualPath) { + Q_ASSERT(QFileInfo(currentPath.toLocalFile()).exists()); + + QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(currentPath.toLocalFile()); + + QFileInfoList::iterator fileInfo; + for ( fileInfo = fileInfoList.begin(); fileInfo != fileInfoList.end(); fileInfo += 1) { + if (abort) { + return; + } + + QString fullFileName = fileInfo->absoluteFilePath(); + UBFeatureElementType featureType = UBFeaturesController::fileTypeFromUrl(fullFileName); + QString fileName = fileInfo->fileName(); + + QImage icon = UBFeaturesController::getIcon(fullFileName, featureType); + + if ( fullFileName.contains(".thumbnail.")) + continue; + + UBFeature testFeature(currVirtualPath, icon, fileName, QUrl::fromLocalFile(fullFileName), featureType); + + emit sendFeature(testFeature); + emit featureSent(); + +// featuresList->append(testFeature); + +// if ( favoriteSet->find( QUrl::fromLocalFile( fullFileName ) ) != favoriteSet->end() ) { +// featuresList->append( UBFeature( favoritePath, icon, fileName, QUrl::fromLocalFile( fullFileName ), featureType ) ); +// } + + if (featureType == FEATURE_FOLDER) { + scanFS(QUrl::fromLocalFile(fullFileName), currVirtualPath + "/" + fileName); + } + } } -UBFeature::~UBFeature() +void UBFeaturesComputingThread::scanAll(QList > pScanningData) { - for (int i = 0; i < mChildren.count(); i++) { - delete mChildren[i]; + for (int i = 0; i < pScanningData.count(); i++) { + if (abort) { + return; + } + QPair curPair = pScanningData.at(i); + scanFS(curPair.first, curPair.second); } +} - for (int i = 0; i < mParents.count(); i++) { - mParents[i]->mChildren.removeAll(this); +int UBFeaturesComputingThread::featuresCount(const QUrl &pPath) +{ + int noItems = 0; + + QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(pPath.toLocalFile()); + + QFileInfoList::iterator fileInfo; + for ( fileInfo = fileInfoList.begin(); fileInfo != fileInfoList.end(); fileInfo += 1) { + QString fullFileName = fileInfo->absoluteFilePath(); + UBFeatureElementType featureType = UBFeaturesController::fileTypeFromUrl(fullFileName); + + if (featureType != FEATURE_INVALID && !fullFileName.contains(".thumbnail.")) { + noItems++; + } else { + continue; + } + + if (featureType == FEATURE_FOLDER) { + noItems += featuresCount(QUrl::fromLocalFile(fullFileName)); + } + } + + return noItems; +} + +int UBFeaturesComputingThread::featuresCountAll(QList > pScanningData) +{ + int noItems = 0; + for (int i = 0; i < pScanningData.count(); i++) { + QPair curPair = pScanningData.at(i); + noItems += featuresCount(curPair.first); } + + return noItems; +} + +UBFeaturesComputingThread::UBFeaturesComputingThread(QObject *parent) : +QThread(parent) +{ + restart = false; + abort = false; +} + +void UBFeaturesComputingThread::compute(const QList > &pScanningData) +{ + QMutexLocker curLocker(&mMutex); + + mScanningData = pScanningData; + + if (!isRunning()) { + start(LowPriority); + } else { + restart = true; + mWaitCondition.wakeOne(); + } +} + +void UBFeaturesComputingThread::run() +{ + forever { + qDebug() << "Custom thread started execution"; + + mMutex.lock(); + QList > searchData = mScanningData; + mMutex.unlock(); + + if (abort) { + return; + } + if (restart) { + break; + } + + QTime curTime = QTime::currentTime(); + int fsCnt = featuresCountAll(searchData); + int msecsto = curTime.msecsTo(QTime::currentTime()); + qDebug() << "time on evaluation" << msecsto; + + emit maxFilesCountEvaluated(fsCnt); + + emit scanStarted(); + scanAll(searchData); + emit scanFinished(); + + mMutex.lock(); + if (!restart) { + mWaitCondition.wait(&mMutex); + } + restart = false; + mMutex.unlock(); + + } +} + +UBFeaturesComputingThread::~UBFeaturesComputingThread() +{ + qDebug() << "thread destructor catched"; + + mMutex.lock(); + abort = true; + mWaitCondition.wakeOne(); + mMutex.unlock(); + + wait(); +} + +UBFeature::UBFeature(const QString &url, const QImage &icon, const QString &name, const QUrl &realPath, UBFeatureElementType type) +: virtualDir(url), mThumbnail(icon), mName(name), mPath(realPath), elementType(type) +{ +} + +UBFeature::~UBFeature() +{ } QString UBFeature::getUrl() const @@ -108,18 +256,18 @@ UBFeaturesController::UBFeaturesController(QWidget *pParentWidget) : mLibSearchDirectoryPath =QUrl::fromLocalFile(UBSettings::settings()->userSearchDirectory()); trashDirectoryPath = QUrl::fromLocalFile(UBSettings::userTrashDirPath()); - rootElement = UBFeature(QString(), QPixmap( ":images/libpalette/home.png" ), "root", QUrl()); - audiosElement = UBFeature( rootPath, QPixmap(":images/libpalette/AudiosCategory.svg"), "Audios" , mUserAudioDirectoryPath, FEATURE_CATEGORY); - moviesElement = UBFeature( rootPath, QPixmap(":images/libpalette/MoviesCategory.svg"), "Movies" , mUserVideoDirectoryPath, FEATURE_CATEGORY); - picturesElement = UBFeature( rootPath, QPixmap(":images/libpalette/PicturesCategory.svg"), "Pictures" , mUserPicturesDirectoryPath, FEATURE_CATEGORY); - flashElement = UBFeature( rootPath, QPixmap(":images/libpalette/FlashCategory.svg"), "Animations" , mUserAnimationDirectoryPath, FEATURE_CATEGORY); - interactElement = UBFeature( rootPath, QPixmap(":images/libpalette/InteractivesCategory.svg"), "Interactivities" , mLibInteractiveDirectoryPath, FEATURE_CATEGORY); - applicationsElement = UBFeature( rootPath, QPixmap(":images/libpalette/ApplicationsCategory.svg"), "Applications" , mUserInteractiveDirectoryPath, FEATURE_CATEGORY); - shapesElement = UBFeature( rootPath, QPixmap(":images/libpalette/ShapesCategory.svg"), "Shapes" , mLibShapesDirectoryPath, FEATURE_CATEGORY ); - favoriteElement = UBFeature( rootPath, QPixmap(":images/libpalette/FavoritesCategory.svg"), "Favorites", QUrl("favorites"), FEATURE_FAVORITE ); - webSearchElement = UBFeature( rootPath, QPixmap(":images/libpalette/WebSearchCategory.svg"), "Web search", mLibSearchDirectoryPath, FEATURE_CATEGORY); + rootElement = UBFeature(QString(), QImage( ":images/libpalette/home.png" ), "root", QUrl()); + audiosElement = UBFeature( rootPath, QImage(":images/libpalette/AudiosCategory.svg"), "Audios" , mUserAudioDirectoryPath, FEATURE_CATEGORY); + moviesElement = UBFeature( rootPath, QImage(":images/libpalette/MoviesCategory.svg"), "Movies" , mUserVideoDirectoryPath, FEATURE_CATEGORY); + picturesElement = UBFeature( rootPath, QImage(":images/libpalette/PicturesCategory.svg"), "Pictures" , mUserPicturesDirectoryPath, FEATURE_CATEGORY); + flashElement = UBFeature( rootPath, QImage(":images/libpalette/FlashCategory.svg"), "Animations" , mUserAnimationDirectoryPath, FEATURE_CATEGORY); + interactElement = UBFeature( rootPath, QImage(":images/libpalette/InteractivesCategory.svg"), "Interactivities" , mLibInteractiveDirectoryPath, FEATURE_CATEGORY); + applicationsElement = UBFeature( rootPath, QImage(":images/libpalette/ApplicationsCategory.svg"), "Applications" , mUserInteractiveDirectoryPath, FEATURE_CATEGORY); + shapesElement = UBFeature( rootPath, QImage(":images/libpalette/ShapesCategory.svg"), "Shapes" , mLibShapesDirectoryPath, FEATURE_CATEGORY ); + favoriteElement = UBFeature( rootPath, QImage(":images/libpalette/FavoritesCategory.svg"), "Favorites", QUrl("favorites"), FEATURE_FAVORITE ); + webSearchElement = UBFeature( rootPath, QImage(":images/libpalette/WebSearchCategory.svg"), "Web search", mLibSearchDirectoryPath, FEATURE_CATEGORY); - trashElement = UBFeature( rootPath, QPixmap(":images/libpalette/TrashCategory.svg"), "Trash", trashDirectoryPath, FEATURE_TRASH ); + trashElement = UBFeature( rootPath, QImage(":images/libpalette/TrashCategory.svg"), "Trash", trashDirectoryPath, FEATURE_TRASH ); featuresList = new QList (); @@ -142,7 +290,40 @@ UBFeaturesController::UBFeaturesController(QWidget *pParentWidget) : featuresPathModel->setSourceModel(featuresModel); connect(featuresModel, SIGNAL(dataRestructured()), featuresProxyModel, SLOT(invalidate())); + connect(&mCThread, SIGNAL(sendFeature(UBFeature)), featuresModel, SLOT(addItem(UBFeature))); + connect(&mCThread, SIGNAL(featureSent()), this, SIGNAL(featureAddedFromThread())); + connect(&mCThread, SIGNAL(scanStarted()), this, SIGNAL(scanStarted())); + connect(&mCThread, SIGNAL(scanFinished()), this, SIGNAL(scanFinished())); + connect(&mCThread, SIGNAL(maxFilesCountEvaluated(int)), this, SIGNAL(maxFilesCountEvaluated(int))); + //Very unsafe function. Considering using deleteLater() instead +// connect(qApp, SIGNAL(aboutToQuit()), &mCThread, SLOT(terminate())); + + QTimer::singleShot(0, this, SLOT(startThread())); +// startThread(); +} + +void UBFeaturesController::startThread() +{ + QList > computingData; + + computingData << QPair(mLibAudiosDirectoryPath, audiosPath) + << QPair(mLibVideosDirectoryPath, moviesPath) + << QPair(mLibAnimationsDirectoryPath, flashPath) + << QPair(mLibPicturesDirectoryPath, picturesPath) + + << QPair(mUserInteractiveDirectoryPath, appPath) + << QPair(mUserAudioDirectoryPath, audiosPath) + << QPair(mUserPicturesDirectoryPath, picturesPath) + << QPair(mUserVideoDirectoryPath, moviesPath) + << QPair(mUserAnimationDirectoryPath, flashPath) + + << QPair(mLibApplicationsDirectoryPath, appPath) + << QPair(mLibShapesDirectoryPath, shapesPath) + << QPair(mLibInteractiveDirectoryPath, interactPath) + << QPair(trashDirectoryPath, trashPath) + << QPair(mLibSearchDirectoryPath, rootPath + "/" + "Web search" ); + mCThread.compute(computingData); } void UBFeaturesController::scanFS() @@ -166,29 +347,55 @@ void UBFeaturesController::scanFS() QList tools = UBToolsManager::manager()->allTools(); foreach (UBToolsManager::UBToolDescriptor tool, tools) { - featuresList->append(UBFeature(appPath, tool.icon, tool.label, QUrl(tool.id), FEATURE_INTERNAL)); + featuresList->append(UBFeature(appPath, tool.icon.toImage(), tool.label, QUrl(tool.id), FEATURE_INTERNAL)); if (favoriteSet->find(QUrl(tool.id)) != favoriteSet->end()) { - featuresList->append(UBFeature(favoritePath, tool.icon, tool.label, QUrl(tool.id), FEATURE_INTERNAL)); + featuresList->append(UBFeature(favoritePath, tool.icon.toImage(), tool.label, QUrl(tool.id), FEATURE_INTERNAL)); } } + QTime time = QTime::currentTime(); //Claudio: // don't change the order of the scans - fileSystemScan( mLibAudiosDirectoryPath, audiosPath); - fileSystemScan( mLibVideosDirectoryPath, moviesPath); - fileSystemScan( mLibAnimationsDirectoryPath, flashPath); - fileSystemScan( mLibPicturesDirectoryPath, picturesPath ); +// fileSystemScan( mLibAudiosDirectoryPath, audiosPath); +// fileSystemScan( mLibVideosDirectoryPath, moviesPath); +// fileSystemScan( mLibAnimationsDirectoryPath, flashPath); +// fileSystemScan( mLibPicturesDirectoryPath, picturesPath ); - fileSystemScan( mUserInteractiveDirectoryPath, appPath ); - fileSystemScan( mUserAudioDirectoryPath, audiosPath ); - fileSystemScan( mUserPicturesDirectoryPath, picturesPath ); - fileSystemScan( mUserVideoDirectoryPath, moviesPath ); - fileSystemScan( mUserAnimationDirectoryPath, flashPath ); +// fileSystemScan( mUserInteractiveDirectoryPath, appPath ); +// fileSystemScan( mUserAudioDirectoryPath, audiosPath ); +// fileSystemScan( mUserPicturesDirectoryPath, picturesPath ); +// fileSystemScan( mUserVideoDirectoryPath, moviesPath ); +// fileSystemScan( mUserAnimationDirectoryPath, flashPath ); - fileSystemScan( mLibApplicationsDirectoryPath, appPath ); - fileSystemScan( mLibShapesDirectoryPath, shapesPath ); - fileSystemScan( mLibInteractiveDirectoryPath, interactPath ); - fileSystemScan( trashDirectoryPath, trashPath ); - fileSystemScan( mLibSearchDirectoryPath, rootPath + "/" + "Web search" ); +// fileSystemScan( mLibApplicationsDirectoryPath, appPath ); +// fileSystemScan( mLibShapesDirectoryPath, shapesPath ); +// fileSystemScan( mLibInteractiveDirectoryPath, interactPath ); +// fileSystemScan( trashDirectoryPath, trashPath ); +// fileSystemScan( mLibSearchDirectoryPath, rootPath + "/" + "Web search" ); + + int i =0; + + i += featuresCount(mLibAudiosDirectoryPath); + i += featuresCount(mLibVideosDirectoryPath); + i += featuresCount(mLibAnimationsDirectoryPath); + i += featuresCount(mLibPicturesDirectoryPath); + + i += featuresCount(mUserInteractiveDirectoryPath); + i += featuresCount(mUserAudioDirectoryPath); + i += featuresCount(mUserPicturesDirectoryPath); + i += featuresCount(mUserVideoDirectoryPath); + i += featuresCount(mUserAnimationDirectoryPath); + + i += featuresCount(mLibApplicationsDirectoryPath); + i += featuresCount(mLibShapesDirectoryPath); + i += featuresCount(mLibInteractiveDirectoryPath); + i += featuresCount(trashDirectoryPath); + i += featuresCount(mLibSearchDirectoryPath); + + int msecs = QTime(time).msecsTo(QTime::currentTime()); + qDebug() << "Loading library" << msecs << "msecs\nNumber of elements" << i; + +// emit TopIndexingLimitSet(i); +// emit indexingProgressValueChanged(i / 4); } void UBFeaturesController::fileSystemScan(const QUrl & currentPath, const QString & currVirtualPath) @@ -201,7 +408,7 @@ void UBFeaturesController::fileSystemScan(const QUrl & currentPath, const QStrin UBFeatureElementType featureType = fileTypeFromUrl(fullFileName); QString fileName = fileInfo->fileName(); - QPixmap icon(getIcon(fullFileName, featureType)); + QImage icon = getIcon(fullFileName, featureType); if ( fullFileName.contains(".thumbnail.")) continue; @@ -220,6 +427,31 @@ void UBFeaturesController::fileSystemScan(const QUrl & currentPath, const QStrin } } +int UBFeaturesController::featuresCount(const QUrl &currPath) +{ + int noItems = 0; + + QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(currPath.toLocalFile()); + + QFileInfoList::iterator fileInfo; + for ( fileInfo = fileInfoList.begin(); fileInfo != fileInfoList.end(); fileInfo += 1) { + QString fullFileName = fileInfo->absoluteFilePath(); + UBFeatureElementType featureType = fileTypeFromUrl(fullFileName); + + if (featureType != FEATURE_INVALID && !fullFileName.contains(".thumbnail.")) { + noItems++; + } else { + continue; + } + + if (featureType == FEATURE_FOLDER) { + noItems += featuresCount(QUrl::fromLocalFile(fullFileName)); + } + } + + return noItems; +} + void UBFeaturesController::loadFavoriteList() { favoriteSet = new QSet(); @@ -260,7 +492,7 @@ void UBFeaturesController::addToFavorite( const QUrl &path ) { QFileInfo fileInfo( filePath ); QString fileName = fileInfo.fileName(); - UBFeature elem( favoritePath, getIcon( filePath, FEATURE_CATEGORY ), fileName, path, fileTypeFromUrl(filePath) ); + UBFeature elem(favoritePath, getIcon( filePath, FEATURE_CATEGORY ), fileName, path, fileTypeFromUrl(filePath) ); favoriteSet->insert( path ); saveFavoriteList(); @@ -318,33 +550,30 @@ UBFeatureElementType UBFeaturesController::fileTypeFromUrl( const QString &path return fileType; } -QPixmap UBFeaturesController::getIcon(const QString &path, UBFeatureElementType pFType = FEATURE_INVALID) +QImage UBFeaturesController::getIcon(const QString &path, UBFeatureElementType pFType = FEATURE_INVALID) { - if ( pFType == FEATURE_FOLDER ) - { - return QPixmap(":images/libpalette/folder.svg"); - } - else if ( pFType == FEATURE_INTERACTIVE ) - { - return QPixmap( UBAbstractWidget::iconFilePath( QUrl::fromLocalFile(path) ) ); + if (pFType == FEATURE_FOLDER) { + return QImage(":images/libpalette/folder.svg"); + + } else if (pFType == FEATURE_INTERACTIVE) { + return QImage(UBAbstractWidget::iconFilePath(QUrl::fromLocalFile(path))); } - if ( path.contains("uniboardTool://") ) - { - return QPixmap( UBToolsManager::manager()->iconFromToolId(path) ); - } - if ( UBFileSystemUtils::mimeTypeFromFileName(path).contains("application") ) - { - return QPixmap( UBAbstractWidget::iconFilePath( QUrl::fromLocalFile(path) ) ); + if ( path.contains("uniboardTool://") ) { + return QImage( UBToolsManager::manager()->iconFromToolId(path) ); + + } if ( UBFileSystemUtils::mimeTypeFromFileName(path).contains("application")) { + return QImage( UBAbstractWidget::iconFilePath( QUrl::fromLocalFile(path) ) ); } - QPixmap thumb; - QString thumbnailPath = UBFileSystemUtils::thumbnailPath( path ); + QImage thumb; + QString thumbnailPath = UBFileSystemUtils::thumbnailPath(path); if ( QFileInfo( thumbnailPath ).exists() ) - thumb = QPixmap( thumbnailPath ); + thumb = QImage( thumbnailPath ); else thumb = createThumbnail( path ); + return thumb; } @@ -354,12 +583,11 @@ bool UBFeaturesController::isDeletable( const QUrl &url ) return type == FEATURE_ITEM; } -QPixmap UBFeaturesController::createThumbnail(const QString &path) +QImage UBFeaturesController::createThumbnail(const QString &path) { QString thumbnailPath = UBFileSystemUtils::thumbnailPath(path); QString mimetype = UBFileSystemUtils::mimeTypeFromFileName(path); QString extension = QFileInfo(path).completeSuffix(); - //UBApplication::showMessage(tr("Creating image thumbnail for %1.").arg(pElement->name())); if ( mimetype.contains("audio" )) thumbnailPath = ":images/libpalette/soundIcon.svg"; @@ -373,7 +601,7 @@ QPixmap UBFeaturesController::createThumbnail(const QString &path) } else { - QPixmap pix(path); + QImage pix(path); if (!pix.isNull()) { pix = pix.scaledToWidth(qMin(UBSettings::maxThumbnailWidth, pix.width()), Qt::SmoothTransformation); @@ -386,7 +614,7 @@ QPixmap UBFeaturesController::createThumbnail(const QString &path) } } - return QPixmap(thumbnailPath); + return QImage(thumbnailPath); } void UBFeaturesController::importImage(const QImage &image, const QString &fileName) @@ -394,6 +622,7 @@ void UBFeaturesController::importImage(const QImage &image, const QString &fileN importImage(image, currentElement, fileName); } + void UBFeaturesController::importImage( const QImage &image, const UBFeature &destination, const QString &fileName ) { QString mFileName = fileName; @@ -412,7 +641,7 @@ void UBFeaturesController::importImage( const QImage &image, const UBFeature &de QString filePath = dest.getFullPath().toLocalFile() + "/" + mFileName; image.save(filePath); - QPixmap thumb = createThumbnail( filePath ); + QImage thumb = createThumbnail( filePath ); UBFeature resultItem = UBFeature( dest.getFullVirtualPath(), thumb, mFileName, QUrl::fromLocalFile( filePath ), FEATURE_ITEM ); @@ -420,7 +649,28 @@ void UBFeaturesController::importImage( const QImage &image, const UBFeature &de } -void UBFeaturesController::addNewFolder(const QString &name) +QStringList UBFeaturesController::getFileNamesInFolders() +{ + QStringList strList; + + Q_ASSERT(curListModel); + + for (int i = 0; i < curListModel->rowCount(QModelIndex()); i++) { + QModelIndex ind = curListModel->index(i, 0); + if (!ind.isValid()) { + qDebug() << "incorrect model index catched"; + continue; + } + UBFeature curFeature = curListModel->data(ind, Qt::UserRole + 1).value(); + if (curFeature.getType() == FEATURE_FOLDER) { + strList << QFileInfo(curFeature.getFullPath().toLocalFile()).fileName(); + } + } + + return strList; +} + +void UBFeaturesController::addNewFolder(QString name) { QString path = currentElement.getFullPath().toLocalFile() + "/" + name; @@ -432,7 +682,7 @@ void UBFeaturesController::addNewFolder(const QString &name) if(!QFileInfo(path).exists()) { QDir().mkpath(path); } - UBFeature newFeatureFolder = UBFeature( currentElement.getFullVirtualPath(), QPixmap(":images/libpalette/folder.svg"), + UBFeature newFeatureFolder = UBFeature( currentElement.getFullVirtualPath(), QImage(":images/libpalette/folder.svg"), name, QUrl::fromLocalFile( path ), FEATURE_FOLDER ); featuresModel->addItem( newFeatureFolder ); @@ -523,7 +773,7 @@ UBFeature UBFeaturesController::moveItemToFolder( const QUrl &url, const UBFeatu deleteItem( url ); } - QPixmap thumb = getIcon( newFullPath ); + QImage thumb = getIcon( newFullPath ); UBFeatureElementType type = FEATURE_ITEM; if ( UBFileSystemUtils::mimeTypeFromFileName( newFullPath ).contains("application") ) @@ -550,9 +800,24 @@ void UBFeaturesController::siftElements(const QString &pSiftValue) featuresPathModel->invalidate(); } -UBFeature UBFeaturesController::getFeature(const QModelIndex &index, QListView *pOnView) +UBFeature UBFeaturesController::getFeature(const QModelIndex &index, const QString &listName) { - return qobject_cast(pOnView->model())->data(index, Qt::UserRole + 1).value(); +// QSortFilterProxyModel *model = qobject_cast(pOnView->model()); + QAbstractItemModel *model = 0; + if (listName == UBFeaturesWidget::objNamePathList) { + model = featuresPathModel; + } else if (listName == UBFeaturesWidget::objNameFeatureList) { + model = curListModel; + } + + if (model) { + return model->data(index, Qt::UserRole + 1).value(); + } + + return UBFeature(); + + +// return pOnView->model()->data(index, Qt::UserRole + 1).value(); /*featuresSearchModel->data(index, Qt::UserRole + 1).value()*/; } void UBFeaturesController::searchStarted(const QString &pattern, QListView *pOnView) @@ -561,11 +826,13 @@ void UBFeaturesController::searchStarted(const QString &pattern, QListView *pOnV pOnView->setModel(featuresProxyModel); featuresProxyModel->invalidate(); - } else if ( pattern.size() > 2 ) { + curListModel = featuresProxyModel; + } else if ( pattern.size() > 1 ) { featuresSearchModel->setFilterWildcard( "*" + pattern + "*" ); pOnView->setModel(featuresSearchModel ); featuresSearchModel->invalidate(); + curListModel = featuresSearchModel; } } @@ -599,7 +866,7 @@ UBFeature UBFeaturesController::copyItemToFolder( const QUrl &url, const UBFeatu if (!sourcePath.compare(newFullPath, Qt::CaseInsensitive)) QFile(sourcePath).copy(newFullPath); - QPixmap thumb = getIcon(newFullPath); + QImage thumb = getIcon(newFullPath); UBFeatureElementType type = FEATURE_ITEM; if (UBFileSystemUtils::mimeTypeFromFileName(newFullPath).contains("application")) @@ -641,7 +908,7 @@ void UBFeaturesController::moveExternalData(const QUrl &url, const UBFeature &de Q_ASSERT(QFileInfo(newFullPath).exists()); - QPixmap thumb = getIcon(newFullPath, type); + QImage thumb = getIcon(newFullPath, type); UBFeature newElement(destVirtualPath, thumb, name, QUrl::fromLocalFile(newFullPath), type); featuresModel->addItem(newElement); @@ -710,6 +977,7 @@ void UBFeaturesController::assignFeaturesListVeiw(UBFeaturesListView *pList) pList->setItemDelegate(itemDelegate); pList->setModel(featuresProxyModel); + curListModel = featuresProxyModel; } void UBFeaturesController::assignPathListView(UBFeaturesListView *pList) diff --git a/src/board/UBFeaturesController.h b/src/board/UBFeaturesController.h index 61d86d02..64bbd5cc 100644 --- a/src/board/UBFeaturesController.h +++ b/src/board/UBFeaturesController.h @@ -12,6 +12,10 @@ #include #include #include +#include +#include +#include +#include class UBFeaturesModel; class UBFeaturesItemDelegate; @@ -20,8 +24,45 @@ class UBFeaturesProxyModel; class UBFeaturesSearchProxyModel; class UBFeaturesPathProxyModel; class UBFeaturesListView; +class UBFeature; + + +class UBFeaturesComputingThread : public QThread +{ + Q_OBJECT +public: + explicit UBFeaturesComputingThread(QObject *parent = 0); + virtual ~UBFeaturesComputingThread(); + void compute(const QList > &pScanningData); + +protected: + void run(); + +signals: + void sendFeature(UBFeature pFeature); + void featureSent(); + void scanStarted(); + void scanFinished(); + void maxFilesCountEvaluated(int max); + +public slots: + +private: + void scanFS(const QUrl & currentPath, const QString & currVirtualPath); + void scanAll(QList > pScanningData); + int featuresCount(const QUrl &pPath); + int featuresCountAll(QList > pScanningData); + +private: + QMutex mMutex; + QWaitCondition mWaitCondition; + QUrl mScanningPath; + QString mScanningVirtualPath; + QList > mScanningData; + bool restart; + bool abort; +}; -//#include "UBDockPaletteWidget.h" enum UBFeatureElementType { @@ -41,12 +82,12 @@ class UBFeature { public: UBFeature() {;} - //UBFeature(const UBFeature &f); - UBFeature(const QString &url, const QPixmap &icon, const QString &name, const QUrl &realPath, UBFeatureElementType type = FEATURE_CATEGORY); +// UBFeature(const UBFeature &f); + UBFeature(const QString &url, const QImage &icon, const QString &name, const QUrl &realPath, UBFeatureElementType type = FEATURE_CATEGORY); // UBFeature(); virtual ~UBFeature(); QString getName() const { return mName; } - QPixmap getThumbnail() const {return mThumbnail;} + QImage getThumbnail() const {return mThumbnail;} QString getVirtualPath() const { return virtualDir; } //QString getPath() const { return mPath; }; QUrl getFullPath() const { return mPath; } @@ -64,20 +105,13 @@ public: const QMap & getMetadata() const { return metadata; } void setMetadata( const QMap &data ) { metadata = data; } - bool hasChildren() const {return mChildren.count();} - bool hasParents() const {return mParents.count();} - bool hasRelationships() const {return mChildren.count() && mParents.count();} - private: QString virtualDir; - QPixmap mThumbnail; + QImage mThumbnail; QString mName; QUrl mPath; UBFeatureElementType elementType; QMap metadata; - - QList mChildren; - QList mParents; }; Q_DECLARE_METATYPE( UBFeature ) @@ -111,7 +145,7 @@ public: void rescanModel(); void siftElements(const QString &pSiftValue); //TODO make less complicated for betteer maintainence - UBFeature getFeature(const QModelIndex &index, QListView *pOnView); + UBFeature getFeature(const QModelIndex &index, const QString &listName); void searchStarted(const QString &pattern, QListView *pOnView); void refreshModels(); @@ -119,18 +153,18 @@ public: void deleteItem(const UBFeature &pFeature); bool isTrash( const QUrl &url ); void moveToTrash(UBFeature feature, bool deleteManualy = false); - void addNewFolder(const QString &name); void addToFavorite( const QUrl &path ); void removeFromFavorite(const QUrl &path, bool deleteManualy = false); void importImage(const QImage &image, const QString &fileName = QString()); void importImage( const QImage &image, const UBFeature &destination, const QString &fileName = QString() ); + QStringList getFileNamesInFolders(); void fileSystemScan(const QUrl &currPath, const QString & currVirtualPath); + int featuresCount(const QUrl &currPath); static UBFeatureElementType fileTypeFromUrl( const QString &path ); - static QString fileNameFromUrl( const QUrl &url ); - static QPixmap getIcon( const QString &path, UBFeatureElementType pFType ); + static QImage getIcon( const QString &path, UBFeatureElementType pFType ); static bool isDeletable( const QUrl &url ); static char featureTypeSplitter() {return ':';} @@ -139,6 +173,16 @@ public: void assignFeaturesListVeiw(UBFeaturesListView *pList); void assignPathListView(UBFeaturesListView *pList); +signals: + void maxFilesCountEvaluated(int pLimit); + void scanStarted(); + void scanFinished(); + void featureAddedFromThread(); + +private slots: + void addNewFolder(QString name); + void startThread(); + private: UBFeaturesItemDelegate *itemDelegate; @@ -149,16 +193,16 @@ private: UBFeaturesSearchProxyModel *featuresSearchModel; UBFeaturesPathProxyModel *featuresPathModel; + QAbstractItemModel *curListModel; + UBFeaturesComputingThread mCThread; private: - static QPixmap createThumbnail(const QString &path); + static QImage createThumbnail(const QString &path); //void addImageToCurrentPage( const QString &path ); void loadFavoriteList(); void saveFavoriteList(); - - QList *featuresList; QUrl mUserAudioDirectoryPath; diff --git a/src/domain/UBGraphicsGroupContainerItem.cpp b/src/domain/UBGraphicsGroupContainerItem.cpp index 09461236..b35cbdbf 100644 --- a/src/domain/UBGraphicsGroupContainerItem.cpp +++ b/src/domain/UBGraphicsGroupContainerItem.cpp @@ -157,18 +157,29 @@ UBGraphicsGroupContainerItem *UBGraphicsGroupContainerItem::deepCopy() const UBGraphicsGroupContainerItem *copy = new UBGraphicsGroupContainerItem(parentItem()); - copy->setPos(this->pos()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); - copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); copy->setUuid(this->uuid()); // this is OK for now as long as Widgets are imutable + copyItemParameters(copy); + // copy->resize(this->size()); return copy; } + +void UBGraphicsGroupContainerItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsGroupContainerItem *cp = dynamic_cast(copy); + if (cp) + { + cp->setPos(this->pos()); + cp->setTransform(this->transform()); + cp->setFlag(QGraphicsItem::ItemIsMovable, true); + cp->setFlag(QGraphicsItem::ItemIsSelectable, true); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + cp->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + } +} + void UBGraphicsGroupContainerItem::remove() { if (mDelegate) diff --git a/src/domain/UBGraphicsGroupContainerItem.h b/src/domain/UBGraphicsGroupContainerItem.h index 6c08f05f..1eca384a 100644 --- a/src/domain/UBGraphicsGroupContainerItem.h +++ b/src/domain/UBGraphicsGroupContainerItem.h @@ -24,6 +24,8 @@ public: virtual UBGraphicsScene* scene(); virtual UBGraphicsGroupContainerItem *deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; + virtual void remove(); enum { Type = UBGraphicsItemType::groupContainerType }; diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 0781bfc5..387ffda1 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -410,6 +410,7 @@ void UBGraphicsItemDelegate::duplicate() UBApplication::boardController->copy(); UBApplication::boardController->paste(); + UBApplication::boardController->duplicateItem(dynamic_cast(delegated())); } void UBGraphicsItemDelegate::increaseZLevelUp() @@ -727,7 +728,11 @@ void UBGraphicsToolBarItem::paint(QPainter *painter, const QStyleOptionGraphicsI } MediaTimer::MediaTimer(QGraphicsItem * parent): QGraphicsRectItem(parent) -{} +{ + val = 0; + smallPoint = false; + setNumDigits(4); +} MediaTimer::~MediaTimer() {} @@ -810,9 +815,7 @@ void MediaTimer::drawDigit(const QPoint &pos, QPainter &p, int segLen, } } -char* MediaTimer::getSegments(char ch) // gets list of segments for ch -{ - char segments[30][8] = +char MediaTimer::segments [][8] = { { 0, 1, 2, 4, 5, 6,99, 0}, // 0 0 { 2, 5,99, 0, 0, 0, 0, 0}, // 1 1 @@ -827,16 +830,17 @@ char* MediaTimer::getSegments(char ch) // gets list of segments fo { 8, 9,99, 0, 0, 0, 0, 0}, // 10 : {99, 0, 0, 0, 0, 0, 0, 0} // 11 empty }; - - int n; + +const char* MediaTimer::getSegments(char ch) // gets list of segments for ch +{ if (ch >= '0' && ch <= '9') return segments[ch - '0']; if (ch == ':') - n = 10; + return segments[10]; if (ch == ' ') - n = 11; + return segments[11]; - return segments[n]; + return NULL; } void MediaTimer::drawSegment(const QPoint &pos, char segmentNo, QPainter &p, @@ -1058,13 +1062,6 @@ void MediaTimer::internalSetString(const QString& s) update(); } -void MediaTimer::init() -{ - val = 0; - smallPoint = false; - setNumDigits(4); -} - void MediaTimer::display(const QString &s) { val = 0; @@ -1132,7 +1129,6 @@ DelegateMediaControl::DelegateMediaControl(UBGraphicsMediaItem* pDelegated, QGra setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); lcdTimer = new MediaTimer(this); - lcdTimer->init(); update(); } @@ -1185,6 +1181,8 @@ void DelegateMediaControl::positionHandles() mLCDTimerArea.setHeight(parentItem()->boundingRect().height()); lcdTimer->setRect(mLCDTimerArea); lcdTimer->setPos(mSeecArea.width()-mLCDTimerArea.width(),0); + //lcdTimer->setRect(mLCDTimerArea); + //lcdTimer->setPos(mSeecArea.width()-mLCDTimerArea.width(),0); mSeecArea.setWidth(rect().width()-mLCDTimerArea.width()); @@ -1193,6 +1191,7 @@ void DelegateMediaControl::positionHandles() setRect(selfRect); lcdTimer->setPos(rect().width() - mLCDTimerArea.width(), 0); + //lcdTimer->setPos(rect().width() - mLCDTimerArea.width(), 0); } @@ -1201,6 +1200,7 @@ void DelegateMediaControl::update() QTime t; t = t.addMSecs(mCurrentTimeInMs < 0 ? 0 : mCurrentTimeInMs); lcdTimer->display(t.toString("m:ss")); + //lcdTimer->display(t.toString("m:ss")); QGraphicsRectItem::update(); } @@ -1253,6 +1253,7 @@ void DelegateMediaControl::seekToMousePos(QPointF mousePos) minX = frameWidth; length = mSeecArea.width() - lcdTimer->rect().width(); + length = mSeecArea.width() /*- lcdTimer->rect().width()*/; qreal mouseX = mousePos.x(); if (mouseX >= (mSeecArea.width() - mSeecArea.height()/2)) diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index 68c9e35e..f135f66b 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -71,33 +71,40 @@ class DelegateButton: public QGraphicsSvgItem }; +/* + Code of this class is copied from QT QLCDNumber class sources + See src\gui\widgets\qlcdnumber.cpp for original code +*/ class MediaTimer: public QGraphicsRectItem { public: MediaTimer(QGraphicsItem * parent = 0); ~MediaTimer(); - char* getSegments(char); - void addPoint(QPolygon&, const QPoint&); - void init(); - void internalSetString(const QString& s); - void drawString(const QString& s, QPainter &, QBitArray * = 0, bool = true); - void drawDigit(const QPoint &, QPainter &, int, char, char = ' '); - void drawSegment(const QPoint &, char, QPainter &, int, bool = false); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + void display(const QString &str); - void setNumDigits(int nDigits); private: + + static const char* getSegments(char); + void drawString(const QString& s, QPainter &, QBitArray * = 0, bool = true); + void drawDigit(const QPoint &, QPainter &, int, char, char = ' '); + void drawSegment(const QPoint &, char, QPainter &, int, bool = false); + void addPoint(QPolygon&, const QPoint&); + void internalSetString(const QString& s); + void setNumDigits(int nDigits); + + static char segments [][8]; + int ndigits; QString digitStr; QBitArray points; double val; -uint shadow : 1; -uint smallPoint : 1; - + uint shadow : 1; + uint smallPoint : 1; }; class DelegateMediaControl: public QObject, public QGraphicsRectItem diff --git a/src/domain/UBGraphicsMediaItem.cpp b/src/domain/UBGraphicsMediaItem.cpp index 4b3dbc7c..e14aac6f 100644 --- a/src/domain/UBGraphicsMediaItem.cpp +++ b/src/domain/UBGraphicsMediaItem.cpp @@ -241,26 +241,34 @@ void UBGraphicsMediaItem::showOnDisplayChanged(bool shown) UBItem* UBGraphicsMediaItem::deepCopy() const { QUrl url = this->mediaFileUrl(); - UBGraphicsMediaItem *copy; - - copy = new UBGraphicsMediaItem(url, parentItem()); + UBGraphicsMediaItem *copy = new UBGraphicsMediaItem(url, parentItem()); - copy->setPos(this->pos()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); - copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); - copy->setUuid(this->uuid()); // this is OK as long as Videos are imutable - copy->setSourceUrl(this->sourceUrl()); - copy->resize(this->size()); + copy->setUuid(this->uuid()); // this is OK for now as long as Widgets are imutable - connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), copy, SLOT(activeSceneChanged())); - // TODO UB 4.7 complete all members + copyItemParameters(copy); return copy; } +void UBGraphicsMediaItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsMediaItem *cp = dynamic_cast(copy); + if (cp) + { + cp->setPos(this->pos()); + cp->setTransform(this->transform()); + cp->setFlag(QGraphicsItem::ItemIsMovable, true); + cp->setFlag(QGraphicsItem::ItemIsSelectable, true); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + cp->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + cp->setSourceUrl(this->sourceUrl()); + cp->resize(this->size()); + + connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), cp, SLOT(activeSceneChanged())); + // TODO UB 4.7 complete all members + } +} + void UBGraphicsMediaItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (mDelegate) diff --git a/src/domain/UBGraphicsMediaItem.h b/src/domain/UBGraphicsMediaItem.h index 8a226795..e646129d 100644 --- a/src/domain/UBGraphicsMediaItem.h +++ b/src/domain/UBGraphicsMediaItem.h @@ -95,6 +95,8 @@ public: virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; + virtual void setSourceUrl(const QUrl &pSourceUrl) { UBAudioPresentationWidget* pAudioWidget = dynamic_cast(mAudioWidget); diff --git a/src/domain/UBGraphicsPDFItem.cpp b/src/domain/UBGraphicsPDFItem.cpp index 2383c82c..f918b3d2 100644 --- a/src/domain/UBGraphicsPDFItem.cpp +++ b/src/domain/UBGraphicsPDFItem.cpp @@ -89,17 +89,26 @@ UBItem* UBGraphicsPDFItem::deepCopy() const { UBGraphicsPDFItem *copy = new UBGraphicsPDFItem(mRenderer, mPageNumber, parentItem()); - copy->setPos(this->pos()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); - copy->setUuid(this->uuid()); // this is OK for now as long as PDF are imutable - copy->setSourceUrl(this->sourceUrl()); + copy->setUuid(this->uuid()); // this is OK for now as long as Widgets are imutable + + copyItemParameters(copy); return copy; } +void UBGraphicsPDFItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsPDFItem *cp = dynamic_cast(copy); + if (cp) + { + cp->setPos(this->pos()); + cp->setTransform(this->transform()); + cp->setFlag(QGraphicsItem::ItemIsMovable, true); + cp->setFlag(QGraphicsItem::ItemIsSelectable, true); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + cp->setSourceUrl(this->sourceUrl()); + } +} void UBGraphicsPDFItem::setRenderingQuality(RenderingQuality pRenderingQuality) { diff --git a/src/domain/UBGraphicsPDFItem.h b/src/domain/UBGraphicsPDFItem.h index 85778865..ac55190e 100644 --- a/src/domain/UBGraphicsPDFItem.h +++ b/src/domain/UBGraphicsPDFItem.h @@ -41,6 +41,8 @@ class UBGraphicsPDFItem: public GraphicsPDFItem, public UBItem, public UBGraphic virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; + virtual void setRenderingQuality(RenderingQuality pRenderingQuality); virtual UBGraphicsScene* scene(); diff --git a/src/domain/UBGraphicsPixmapItem.cpp b/src/domain/UBGraphicsPixmapItem.cpp index 634a150f..936b9195 100644 --- a/src/domain/UBGraphicsPixmapItem.cpp +++ b/src/domain/UBGraphicsPixmapItem.cpp @@ -114,22 +114,30 @@ UBItem* UBGraphicsPixmapItem::deepCopy() const { UBGraphicsPixmapItem* copy = new UBGraphicsPixmapItem(); - copy->setPixmap(this->pixmap()); - copy->setPos(this->pos()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); - copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + copy->setUuid(this->uuid()); // this is OK for now as long as Widgets are imutable - copy->setUuid(this->uuid()); // This is OK for now, as long as pixmaps are immutable - - copy->setSourceUrl(this->sourceUrl()); + copyItemParameters(copy); // TODO UB 4.7 ... complete all members ? return copy; } +void UBGraphicsPixmapItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsPixmapItem *cp = dynamic_cast(copy); + if (cp) + { + cp->setPixmap(this->pixmap()); + cp->setPos(this->pos()); + cp->setTransform(this->transform()); + cp->setFlag(QGraphicsItem::ItemIsMovable, true); + cp->setFlag(QGraphicsItem::ItemIsSelectable, true); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + cp->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + cp->setSourceUrl(this->sourceUrl()); + } +} UBGraphicsScene* UBGraphicsPixmapItem::scene() { diff --git a/src/domain/UBGraphicsPixmapItem.h b/src/domain/UBGraphicsPixmapItem.h index 9e9bb05c..787f28eb 100644 --- a/src/domain/UBGraphicsPixmapItem.h +++ b/src/domain/UBGraphicsPixmapItem.h @@ -40,6 +40,8 @@ class UBGraphicsPixmapItem : public QObject, public QGraphicsPixmapItem, public } virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; + virtual UBGraphicsScene* scene(); virtual void remove(); diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index 0fd59189..256f8143 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -156,29 +156,37 @@ UBGraphicsPolygonItem* UBGraphicsPolygonItem::deepCopy(const QPolygonF& pol) con { UBGraphicsPolygonItem* copy = new UBGraphicsPolygonItem(pol); - copy->mOriginalLine = QLineF(); - copy->mOriginalWidth = -1; - copy->mIsNominalLine = false; + copyItemParameters(copy); - copy->setStroke(this->stroke()); - copy->setStrokesGroup(this->strokesGroup()); - copy->setBrush(this->brush()); - copy->setPen(this->pen()); - copy->mHasAlpha = this->mHasAlpha; + // TODO UB 4.7 ... complete all members ? + return copy; - copy->setColorOnDarkBackground(this->colorOnDarkBackground()); - copy->setColorOnLightBackground(this->colorOnLightBackground()); +} + +void UBGraphicsPolygonItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsPolygonItem *cp = dynamic_cast(copy); + if (cp) + { + cp->mOriginalLine = QLineF(); + cp->mOriginalWidth = -1; + cp->mIsNominalLine = false; - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + cp->setStroke(this->stroke()); + cp->setStrokesGroup(this->strokesGroup()); + cp->setBrush(this->brush()); + cp->setPen(this->pen()); + cp->mHasAlpha = this->mHasAlpha; - // TODO UB 4.7 ... complete all members ? - return copy; + cp->setColorOnDarkBackground(this->colorOnDarkBackground()); + cp->setColorOnLightBackground(this->colorOnLightBackground()); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + } } - void UBGraphicsPolygonItem::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { if(mHasAlpha && scene() && scene()->isLightBackground()) diff --git a/src/domain/UBGraphicsPolygonItem.h b/src/domain/UBGraphicsPolygonItem.h index 6aa189ac..6ee1cc7e 100644 --- a/src/domain/UBGraphicsPolygonItem.h +++ b/src/domain/UBGraphicsPolygonItem.h @@ -88,6 +88,7 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem // optimisation (eraser) UBGraphicsPolygonItem* deepCopy(const QPolygonF& pol) const; + virtual void copyItemParameters(UBItem *copy) const; QLineF originalLine() { return mOriginalLine;} qreal originalWidth() { return mOriginalWidth;} diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 25f94c03..1c45145f 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1539,11 +1539,15 @@ void UBGraphicsScene::addGroup(UBGraphicsGroupContainerItem *groupItem) setDocumentUpdated(); } -UBGraphicsSvgItem* UBGraphicsScene::addSvg(const QUrl& pSvgFileUrl, const QPointF& pPos) +UBGraphicsSvgItem* UBGraphicsScene::addSvg(const QUrl& pSvgFileUrl, const QPointF& pPos, const QByteArray pData) { QString path = pSvgFileUrl.toLocalFile(); - UBGraphicsSvgItem *svgItem = new UBGraphicsSvgItem(path); + UBGraphicsSvgItem *svgItem; + if (pData.isNull()) + svgItem = new UBGraphicsSvgItem(path); + else + svgItem = new UBGraphicsSvgItem(pData); svgItem->setFlag(QGraphicsItem::ItemIsMovable, true); svgItem->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index b8cdb7b7..7433cde9 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -109,6 +109,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const {Q_UNUSED(copy);} + UBGraphicsScene* sceneDeepCopy() const; void clearItemsAndAnnotations(); @@ -136,7 +138,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem UBGraphicsMediaItem* addMedia(const QUrl& pMediaFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); UBGraphicsMediaItem* addVideo(const QUrl& pVideoFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); UBGraphicsMediaItem* addAudio(const QUrl& pAudioFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); - UBGraphicsSvgItem* addSvg(const QUrl& pSvgFileUrl, const QPointF& pPos = QPointF(0, 0)); + UBGraphicsSvgItem* addSvg(const QUrl& pSvgFileUrl, const QPointF& pPos = QPointF(0, 0), const QByteArray pData = QByteArray()); UBGraphicsTextItem* addText(const QString& pString, const QPointF& pTopLeft = QPointF(0, 0)); UBGraphicsTextItem* textForObjectName(const QString& pString, const QString &objectName = "UBTGZeroPageSessionTitle"); diff --git a/src/domain/UBGraphicsStrokesGroup.cpp b/src/domain/UBGraphicsStrokesGroup.cpp index 7fdbd1a7..bff2dd5e 100644 --- a/src/domain/UBGraphicsStrokesGroup.cpp +++ b/src/domain/UBGraphicsStrokesGroup.cpp @@ -63,16 +63,25 @@ UBItem* UBGraphicsStrokesGroup::deepCopy() const { UBGraphicsStrokesGroup* copy = new UBGraphicsStrokesGroup(); - copy->setPos(this->pos()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); - copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + copyItemParameters(copy); return copy; } +void UBGraphicsStrokesGroup::copyItemParameters(UBItem *copy) const +{ + UBGraphicsStrokesGroup *cp = dynamic_cast(copy); + { + cp->setPos(this->pos()); + + cp->setTransform(this->transform()); + cp->setFlag(QGraphicsItem::ItemIsMovable, true); + cp->setFlag(QGraphicsItem::ItemIsSelectable, true); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + cp->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + } +} + void UBGraphicsStrokesGroup::remove() { if (mDelegate) diff --git a/src/domain/UBGraphicsStrokesGroup.h b/src/domain/UBGraphicsStrokesGroup.h index 55b33653..8339e1c2 100644 --- a/src/domain/UBGraphicsStrokesGroup.h +++ b/src/domain/UBGraphicsStrokesGroup.h @@ -14,6 +14,7 @@ public: UBGraphicsStrokesGroup(QGraphicsItem* parent = 0); ~UBGraphicsStrokesGroup(); virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; virtual void remove(); virtual UBGraphicsItemDelegate* Delegate() const {return mDelegate;} enum { Type = UBGraphicsItemType::StrokeItemType }; diff --git a/src/domain/UBGraphicsSvgItem.cpp b/src/domain/UBGraphicsSvgItem.cpp index 31386bcb..b9976ae9 100644 --- a/src/domain/UBGraphicsSvgItem.cpp +++ b/src/domain/UBGraphicsSvgItem.cpp @@ -135,14 +135,9 @@ UBItem* UBGraphicsSvgItem::deepCopy() const { UBGraphicsSvgItem* copy = new UBGraphicsSvgItem(this->fileData()); - copy->setPos(this->pos()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); - copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); - copy->setUuid(this->uuid()); // this is OK for now as long as SVG are imutable - copy->setSourceUrl(this->sourceUrl()); + copy->setUuid(this->uuid()); // this is OK for now as long as Widgets are imutable + + copyItemParameters(copy); // TODO UB 4.7... complete all members ? @@ -150,6 +145,20 @@ UBItem* UBGraphicsSvgItem::deepCopy() const } +void UBGraphicsSvgItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsSvgItem *cp = dynamic_cast(copy); + if (cp) + { + cp->setPos(this->pos()); + cp->setTransform(this->transform()); + cp->setFlag(QGraphicsItem::ItemIsMovable, true); + cp->setFlag(QGraphicsItem::ItemIsSelectable, true); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + cp->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + cp->setSourceUrl(this->sourceUrl()); + } +} void UBGraphicsSvgItem::setRenderingQuality(RenderingQuality pRenderingQuality) { diff --git a/src/domain/UBGraphicsSvgItem.h b/src/domain/UBGraphicsSvgItem.h index f02025af..95b9d536 100644 --- a/src/domain/UBGraphicsSvgItem.h +++ b/src/domain/UBGraphicsSvgItem.h @@ -52,6 +52,8 @@ class UBGraphicsSvgItem: public QGraphicsSvgItem, public UBItem, public UBGraphi virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; + virtual void setRenderingQuality(RenderingQuality pRenderingQuality); virtual UBGraphicsScene* scene(); diff --git a/src/domain/UBGraphicsTextItem.cpp b/src/domain/UBGraphicsTextItem.cpp index 80625045..eb93f975 100644 --- a/src/domain/UBGraphicsTextItem.cpp +++ b/src/domain/UBGraphicsTextItem.cpp @@ -201,28 +201,36 @@ UBItem* UBGraphicsTextItem::deepCopy() const { UBGraphicsTextItem* copy = new UBGraphicsTextItem(); - copy->setHtml(toHtml()); - copy->setPos(this->pos()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); - copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); - copy->setData(UBGraphicsItemData::ItemEditable, data(UBGraphicsItemData::ItemEditable).toBool()); -// copy->setDefaultTextColor(this->defaultTextColor()); -// copy->setFont(this->font()); -// copy->setColorOnDarkBackground(this->colorOnDarkBackground()); -// copy->setColorOnLightBackground(this->colorOnLightBackground()); - copy->setTextWidth(this->textWidth()); - copy->setTextHeight(this->textHeight()); - - copy->setSourceUrl(this->sourceUrl()); + copyItemParameters(copy); // TODO UB 4.7 ... complete all members ? return copy; } +void UBGraphicsTextItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsTextItem *cp = dynamic_cast(copy); + if (cp) + { + cp->setHtml(toHtml()); + cp->setPos(this->pos()); + cp->setTransform(this->transform()); + cp->setFlag(QGraphicsItem::ItemIsMovable, true); + cp->setFlag(QGraphicsItem::ItemIsSelectable, true); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + cp->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + cp->setData(UBGraphicsItemData::ItemEditable, data(UBGraphicsItemData::ItemEditable).toBool()); + // cp->setDefaultTextColor(this->defaultTextColor()); + // cp->setFont(this->font()); + // cp->setColorOnDarkBackground(this->colorOnDarkBackground()); + // cp->setColorOnLightBackground(this->colorOnLightBackground()); + cp->setTextWidth(this->textWidth()); + cp->setTextHeight(this->textHeight()); + + cp->setSourceUrl(this->sourceUrl()); + } +} QRectF UBGraphicsTextItem::boundingRect() const { diff --git a/src/domain/UBGraphicsTextItem.h b/src/domain/UBGraphicsTextItem.h index 8bbe3df5..c7dc5c95 100644 --- a/src/domain/UBGraphicsTextItem.h +++ b/src/domain/UBGraphicsTextItem.h @@ -40,6 +40,9 @@ class UBGraphicsTextItem : public QGraphicsTextItem, public UBItem, public UBRes } virtual UBItem* deepCopy() const; + + virtual void copyItemParameters(UBItem *copy) const; + virtual UBGraphicsScene* scene(); virtual QRectF boundingRect() const; diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index 835a7e0e..8ef47b33 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -330,19 +330,29 @@ UBItem* UBGraphicsAppleWidgetItem::deepCopy() const { UBGraphicsAppleWidgetItem *appleWidget = new UBGraphicsAppleWidgetItem(mWebKitWidget->widgetUrl(), parentItem()); - foreach(QString key, mPreferences.keys()) - { - appleWidget->setPreference(key, mPreferences.value(key)); - } + copyItemParameters(appleWidget); + + return appleWidget; - foreach(QString key, mDatastore.keys()) +} + +void UBGraphicsAppleWidgetItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsAppleWidgetItem *cp = dynamic_cast(copy); + if (cp) { - appleWidget->setDatastoreEntry(key, mDatastore.value(key)); - } + foreach(QString key, mPreferences.keys()) + { + cp->setPreference(key, mPreferences.value(key)); + } - appleWidget->setSourceUrl(this->sourceUrl()); + foreach(QString key, mDatastore.keys()) + { + cp->setDatastoreEntry(key, mDatastore.value(key)); + } - return appleWidget; + cp->setSourceUrl(this->sourceUrl()); + } } void UBGraphicsAppleWidgetItem::setUuid(const QUuid &pUuid) @@ -431,27 +441,35 @@ UBW3CWidget* UBGraphicsW3CWidgetItem::w3cWidget() const UBItem* UBGraphicsW3CWidgetItem::deepCopy() const { UBGraphicsW3CWidgetItem *copy = new UBGraphicsW3CWidgetItem(mWebKitWidget->widgetUrl(), parentItem()); - - copy->setPos(this->pos()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); - copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); copy->setUuid(this->uuid()); // this is OK for now as long as Widgets are imutable - copy->setSourceUrl(this->sourceUrl()); + copyItemParameters(copy); - copy->resize(this->size()); + return copy; +} - foreach(QString key, mPreferences.keys()) +void UBGraphicsW3CWidgetItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsW3CWidgetItem *cp = dynamic_cast(copy); + if (cp) { - copy->setPreference(key, mPreferences.value(key)); - } + cp->setPos(this->pos()); + cp->setTransform(this->transform()); + cp->setFlag(QGraphicsItem::ItemIsMovable, true); + cp->setFlag(QGraphicsItem::ItemIsSelectable, true); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + cp->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + cp->setSourceUrl(this->sourceUrl()); - foreach(QString key, mDatastore.keys()) - { - copy->setDatastoreEntry(key, mDatastore.value(key)); - } + cp->resize(this->size()); - return copy; -} + foreach(QString key, mPreferences.keys()) + { + cp->setPreference(key, mPreferences.value(key)); + } + + foreach(QString key, mDatastore.keys()) + { + cp->setDatastoreEntry(key, mDatastore.value(key)); + } + } +} \ No newline at end of file diff --git a/src/domain/UBGraphicsWidgetItem.h b/src/domain/UBGraphicsWidgetItem.h index ae71955d..d3728b00 100644 --- a/src/domain/UBGraphicsWidgetItem.h +++ b/src/domain/UBGraphicsWidgetItem.h @@ -130,6 +130,9 @@ class UBGraphicsAppleWidgetItem : public UBGraphicsWidgetItem } virtual UBItem* deepCopy() const; + + virtual void copyItemParameters(UBItem *copy) const; + virtual void setUuid(const QUuid &pUuid); }; @@ -152,6 +155,8 @@ class UBGraphicsW3CWidgetItem : public UBGraphicsWidgetItem virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; + UBW3CWidget::Metadata metadatas() const; UBW3CWidget* w3cWidget() const; diff --git a/src/domain/UBItem.h b/src/domain/UBItem.h index e9bd5df2..21519a1b 100644 --- a/src/domain/UBItem.h +++ b/src/domain/UBItem.h @@ -20,6 +20,7 @@ #include "core/UB.h" class UBGraphicsScene; +class UBGraphicsItem; class UBItem { @@ -58,6 +59,8 @@ class UBItem virtual UBItem* deepCopy() const = 0; + virtual void copyItemParameters(UBItem *copy) const = 0; + virtual UBGraphicsScene* scene() // TODO UB 4.x should be pure virtual ... { return 0; diff --git a/src/gui/UBFeaturesActionBar.cpp b/src/gui/UBFeaturesActionBar.cpp index 4bdc8fb9..65ee920f 100644 --- a/src/gui/UBFeaturesActionBar.cpp +++ b/src/gui/UBFeaturesActionBar.cpp @@ -53,6 +53,7 @@ UBFeaturesActionBar::UBFeaturesActionBar( UBFeaturesController *controller, QWid //mpSearchBtn = new UBActionButton(this, mpSearchAction); mpRescanModelBtn = new UBActionButton(this, mpRescanModelAction); + mpRescanModelBtn->hide(); mpDeleteBtn = new UBActionButton(this, mpDeleteAction); mpCloseBtn = new UBActionButton(this, mpCloseAction); @@ -124,7 +125,7 @@ void UBFeaturesActionBar::setButtons() mpNewFolderBtn->show(); mpNewFolderBtn->setEnabled(true); mpDeleteBtn->setEnabled(true); - mpRescanModelBtn->show(); +// mpRescanModelBtn->show(); break; case IN_ROOT: mpFavoriteBtn->show(); @@ -136,7 +137,7 @@ void UBFeaturesActionBar::setButtons() mpNewFolderBtn->show(); mpNewFolderBtn->setEnabled(false); mpDeleteBtn->setEnabled(false); - mpRescanModelBtn->show(); +// mpRescanModelBtn->show(); break; case IN_PROPERTIES: mpFavoriteBtn->show(); @@ -147,7 +148,7 @@ void UBFeaturesActionBar::setButtons() mpCloseBtn->hide(); mpRemoveFavoriteBtn->hide(); mpNewFolderBtn->hide(); - mpRescanModelBtn->hide(); +// mpRescanModelBtn->hide(); break; case IN_FAVORITE: mpFavoriteBtn->hide(); @@ -158,7 +159,7 @@ void UBFeaturesActionBar::setButtons() mpCloseBtn->hide(); mpRemoveFavoriteBtn->show(); mpNewFolderBtn->hide(); - mpRescanModelBtn->hide(); +// mpRescanModelBtn->hide(); break; case IN_TRASH: mpFavoriteBtn->hide(); @@ -171,7 +172,7 @@ void UBFeaturesActionBar::setButtons() mpCloseBtn->hide(); //mpRemoveFavoriteBtn->show(); mpNewFolderBtn->hide(); - mpRescanModelBtn->hide(); +// mpRescanModelBtn->hide(); break; default: break; @@ -208,6 +209,16 @@ void UBFeaturesActionBar::onActionRescanModel() emit rescanModel(); } +void UBFeaturesActionBar::lockIt() +{ + setEnabled(false); +} + +void UBFeaturesActionBar::unlockIt() +{ + setEnabled(true); +} + void UBFeaturesActionBar::dragEnterEvent( QDragEnterEvent *event ) { const UBFeaturesMimeData *fMimeData = qobject_cast(event->mimeData()); diff --git a/src/gui/UBFeaturesActionBar.h b/src/gui/UBFeaturesActionBar.h index 71b6fdc0..b3a406e6 100644 --- a/src/gui/UBFeaturesActionBar.h +++ b/src/gui/UBFeaturesActionBar.h @@ -45,6 +45,8 @@ private slots: void onActionRemoveFavorite(); void onActionTrash(); void onActionRescanModel(); + void lockIt(); + void unlockIt(); protected: void dragEnterEvent( QDragEnterEvent *event ); diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index f43584f2..5cc7b27a 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -1,5 +1,4 @@ #include - #include "UBFeaturesWidget.h" #include "domain/UBAbstractWidget.h" #include "gui/UBThumbnailWidget.h" @@ -8,9 +7,14 @@ #include "core/UBDownloadManager.h" #include "globals/UBGlobals.h" #include "board/UBBoardController.h" +#include "globals/UBGlobals.h" + +const char *UBFeaturesWidget::objNamePathList = "PathList"; +const char *UBFeaturesWidget::objNameFeatureList = "FeatureList"; -const char *objNamePathList = "PathList"; -const char *objNameFeatureList = "FeatureList"; +const QString UBFeaturesNewFolderDialog::acceptText = tr("Accept"); +const QString UBFeaturesNewFolderDialog::cancelText = tr("Cancel"); +const QString UBFeaturesNewFolderDialog::labelText = tr("Enter a new folder name"); const QMargins FeatureListMargins(0, 0, 0, 30); const int FeatureListBorderOffset = 10; @@ -43,39 +47,20 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name) pathListView = new UBFeaturesListView(this, objNamePathList); controller->assignPathListView(pathListView); - //Maintains the view of the main part of the palette. Consists of - //mNavigator - //featureProperties - //webVeiw - stackedWidget = new QStackedWidget(this); - - //Main features icon view with QSlider on the bottom - mNavigator = new UBFeaturesNavigatorWidget(this); - controller->assignFeaturesListVeiw(mNavigator->listView()); - mNavigator->setSliderPosition(UBSettings::settings()->featureSliderPosition->get().toInt()); - - //Specifies the properties of a standalone element - featureProperties = new UBFeatureProperties(this); - - //Used to show search bar on the search widget - webView = new UBFeaturesWebView(this); - - //filling stackwidget - stackedWidget->addWidget(mNavigator); - stackedWidget->addWidget(featureProperties); - stackedWidget->addWidget(webView); - stackedWidget->setCurrentIndex(ID_LISTVIEW); - currentStackedWidget = ID_LISTVIEW; + centralWidget = new UBFeaturesCentralWidget(this); + controller->assignFeaturesListVeiw(centralWidget->listView()); + centralWidget->setSliderPosition(UBSettings::settings()->featureSliderPosition->get().toInt()); //Bottom actionbar for DnD, quick search etc mActionBar = new UBFeaturesActionBar(controller, this); //Filling main layout layout->addWidget(pathListView); - layout->addWidget(stackedWidget); + layout->addWidget(centralWidget); layout->addWidget(mActionBar); - connect(mNavigator->listView(), SIGNAL(clicked(const QModelIndex &)), this, SLOT(currentSelected(const QModelIndex &))); + connect(centralWidget->listView(), SIGNAL(clicked(const QModelIndex &)), this, SLOT(currentSelected(const QModelIndex &))); + connect(this, SIGNAL(sendFileNameList(QStringList)), centralWidget, SIGNAL(sendFileNameList(QStringList))); connect(mActionBar, SIGNAL(searchElement(const QString &)), this, SLOT( searchStarted(const QString &))); connect(mActionBar, SIGNAL(newFolderToCreate()), this, SLOT(createNewFolder())); connect(mActionBar, SIGNAL(deleteElements(const UBFeaturesMimeData *)), this, SLOT(deleteElements(const UBFeaturesMimeData *))); @@ -90,6 +75,14 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name) connect(UBApplication::boardController, SIGNAL(displayMetadata(QMap)), this, SLOT(onDisplayMetadata( QMap))); connect(UBDownloadManager::downloadManager(), SIGNAL( addDownloadedFileToLibrary( bool, QUrl, QString, QByteArray)) , this, SLOT(onAddDownloadedFileToLibrary(bool, QUrl, QString,QByteArray))); + connect(centralWidget, SIGNAL(lockMainWidget(bool)), this, SLOT(lockIt(bool))); + connect(centralWidget, SIGNAL(createNewFolderSignal(QString)), controller, SLOT(addNewFolder(QString))); + connect(controller, SIGNAL(scanStarted()), centralWidget, SLOT(scanStarted())); + connect(controller, SIGNAL(scanFinished()), centralWidget, SLOT(scanFinished())); + connect(controller, SIGNAL(scanStarted()), mActionBar, SLOT(lockIt())); + connect(controller, SIGNAL(scanFinished()), mActionBar, SLOT(unlockIt())); + connect(controller, SIGNAL(maxFilesCountEvaluated(int)), centralWidget, SIGNAL(maxFilesCountEvaluated(int))); + connect(controller, SIGNAL(featureAddedFromThread()), centralWidget, SLOT(increaseStatusBarValue())); } UBFeaturesWidget::~UBFeaturesWidget() @@ -100,7 +93,7 @@ UBFeaturesWidget::~UBFeaturesWidget() void UBFeaturesWidget::searchStarted(const QString &pattern) { - controller->searchStarted(pattern, mNavigator->listView()); + controller->searchStarted(pattern, centralWidget->listView()); } void UBFeaturesWidget::currentSelected(const QModelIndex ¤t) @@ -110,25 +103,16 @@ void UBFeaturesWidget::currentSelected(const QModelIndex ¤t) return; } - //Calling to reset the model for listView. Maybe separate function needed - controller->searchStarted("", mNavigator->listView()); - QString objName = sender()->objectName(); if (objName.isEmpty()) { qWarning() << "incorrrect sender"; + } else if (objName == objNamePathList) { + //Calling to reset the model for listView. Maybe separate function needed + controller->searchStarted("", centralWidget->listView()); } - QListView *calledList = 0; - if (objName == objNamePathList) { - calledList = pathListView; - } else if (objName == objNameFeatureList) { - calledList = mNavigator->listView(); - } - - UBFeature feature = controller->getFeature(current, calledList); -// QSortFilterProxyModel *model = dynamic_cast( mNavigator->listView()->model() ); -// UBFeature feature = model->data(current, Qt::UserRole + 1).value(); + UBFeature feature = controller->getFeature(current, objName); if ( feature.isFolder() ) { QString newPath = feature.getFullVirtualPath(); @@ -136,7 +120,7 @@ void UBFeaturesWidget::currentSelected(const QModelIndex ¤t) controller->setCurrentElement(feature); controller->siftElements(newPath); - switchToListView(); + centralWidget->switchTo(UBFeaturesCentralWidget::MainList); if ( feature.getType() == FEATURE_FAVORITE ) { mActionBar->setCurrentState( IN_FAVORITE ); @@ -145,35 +129,25 @@ void UBFeaturesWidget::currentSelected(const QModelIndex ¤t) mActionBar->setCurrentState( IN_ROOT ); } else if (feature.getType() == FEATURE_TRASH) { - mActionBar->setCurrentState( IN_TRASH ); + mActionBar->setCurrentState(IN_TRASH); } else { - mActionBar->setCurrentState( IN_FOLDER ); + mActionBar->setCurrentState(IN_FOLDER); } - } else if ( feature.getType() == FEATURE_SEARCH ) { - webView->showElement( feature ); - switchToWebView(); + } else if (feature.getType() == FEATURE_SEARCH) { + centralWidget->showElement(feature, UBFeaturesCentralWidget::FeaturesWebView); } else { - featureProperties->showElement( feature ); - switchToProperties(); + centralWidget->showElement(feature, UBFeaturesCentralWidget::FeaturePropertiesList); mActionBar->setCurrentState( IN_PROPERTIES ); } } void UBFeaturesWidget::createNewFolder() { - if (!mkFolderDlg) - { - mkFolderDlg = new UBNewFolderDlg(this); - connect (mkFolderDlg, SIGNAL(accepted()), this, SLOT(addFolder())); - } - - mkFolderDlg->setWindowFlags(Qt::WindowStaysOnTopHint); - mkFolderDlg->resize(this->size().width()-20 ,80); - mkFolderDlg->move(5,this->size().height()-200); - mkFolderDlg->show(); + centralWidget->showAdditionalData(UBFeaturesCentralWidget::NewFolderDialog, UBFeaturesCentralWidget::Modal); + emit sendFileNameList(controller->getFileNamesInFolders()); } void UBFeaturesWidget::addFolder() @@ -203,7 +177,7 @@ void UBFeaturesWidget::deleteElements( const UBFeaturesMimeData * mimeData ) void UBFeaturesWidget::deleteSelectedElements() { - QModelIndexList selected = mNavigator->listView()->selectionModel()->selectedIndexes(); + QModelIndexList selected = centralWidget->listView()->selectionModel()->selectedIndexes(); foreach ( QModelIndex sel, selected ) { @@ -224,6 +198,14 @@ void UBFeaturesWidget::rescanModel() controller->rescanModel(); } +void UBFeaturesWidget::lockIt(bool pLock) +{ + mActionBar->setEnabled(!pLock); + pathListView->setEnabled(!pLock); + centralWidget->setLockedExcludingAdditional(pLock); +// pathListView->setLocked(true); +} + void UBFeaturesWidget::addToFavorite( const UBFeaturesMimeData * mimeData ) { if ( !mimeData->hasUrls() ) @@ -253,7 +235,7 @@ void UBFeaturesWidget::onDisplayMetadata( QMap metadata ) { QString previewImageUrl; - switch (UBFileSystemUtils::mimeTypeFromUrl(QUrl(metadata["Url"]))) + switch (static_cast(UBFileSystemUtils::mimeTypeFromUrl(QUrl(metadata["Url"])))) { case UBMimeType::RasterImage: case UBMimeType::VectorImage: @@ -282,11 +264,10 @@ void UBFeaturesWidget::onDisplayMetadata( QMap metadata ) }break; } - UBFeature feature( QString(), QPixmap(previewImageUrl), QString(), metadata["Url"], FEATURE_ITEM ); + UBFeature feature( QString(), QImage(previewImageUrl), QString(), metadata["Url"], FEATURE_ITEM ); feature.setMetadata( metadata ); - featureProperties->showElement( feature ); - switchToProperties(); + centralWidget->showElement(feature, UBFeaturesCentralWidget::FeaturePropertiesList); mActionBar->setCurrentState( IN_PROPERTIES ); } @@ -298,12 +279,14 @@ void UBFeaturesWidget::onPreviewLoaded(int id, bool pSuccess, QUrl sourceUrl, QS Q_UNUSED(isBackground); Q_UNUSED(pSize); Q_UNUSED(pPos); + Q_UNUSED(sourceUrl); + Q_UNUSED(pContentTypeHeader) QImage img; img.loadFromData(pData); QPixmap pix = QPixmap::fromImage(img); - featureProperties->setOrigPixmap(pix); - featureProperties->setThumbnail(pix); + centralWidget->setPropertiesPixmap(pix); + centralWidget->setPropertiesThumbnail(pix); } void UBFeaturesWidget::onAddDownloadedFileToLibrary(bool pSuccess, QUrl sourceUrl, QString pContentHeader, QByteArray pData) @@ -318,14 +301,14 @@ void UBFeaturesWidget::onAddDownloadedFileToLibrary(bool pSuccess, QUrl sourceUr void UBFeaturesWidget::addElementsToFavorite() { - if ( currentStackedWidget == ID_PROPERTIES ) { - UBFeature feature = featureProperties->getCurrentElement(); + if ( centralWidget->currentView() == UBFeaturesCentralWidget::FeaturePropertiesList ) { + UBFeature feature = centralWidget->getCurElementFromProperties(); if ( feature != UBFeature() && !UBApplication::isFromWeb(feature.getFullPath().toString())) { controller->addToFavorite( feature.getFullPath() ); } - } else if ( currentStackedWidget == ID_LISTVIEW ) { - QModelIndexList selected = mNavigator->listView()->selectionModel()->selectedIndexes(); + } else if ( centralWidget->currentView() == UBFeaturesCentralWidget::MainList ) { + QModelIndexList selected = centralWidget->listView()->selectionModel()->selectedIndexes(); for ( int i = 0; i < selected.size(); ++i ) { UBFeature feature = selected.at(i).data( Qt::UserRole + 1 ).value(); controller->addToFavorite(feature.getFullPath()); @@ -337,7 +320,7 @@ void UBFeaturesWidget::addElementsToFavorite() void UBFeaturesWidget::removeElementsFromFavorite() { - QModelIndexList selected = mNavigator->listView()->selectionModel()->selectedIndexes(); + QModelIndexList selected = centralWidget->listView()->selectionModel()->selectedIndexes(); QList items; for ( int i = 0; i < selected.size(); ++i ) { UBFeature feature = selected.at(i).data( Qt::UserRole + 1 ).value(); @@ -363,20 +346,20 @@ void UBFeaturesWidget::resizeEvent(QResizeEvent *event) void UBFeaturesWidget::switchToListView() { - stackedWidget->setCurrentIndex(ID_LISTVIEW); - currentStackedWidget = ID_LISTVIEW; +// stackedWidget->setCurrentIndex(ID_LISTVIEW); +// currentStackedWidget = ID_LISTVIEW; } void UBFeaturesWidget::switchToProperties() { - stackedWidget->setCurrentIndex(ID_PROPERTIES); - currentStackedWidget = ID_PROPERTIES; +// stackedWidget->setCurrentIndex(ID_PROPERTIES); +// currentStackedWidget = ID_PROPERTIES; } void UBFeaturesWidget::switchToWebView() { - stackedWidget->setCurrentIndex(ID_WEBVIEW); - currentStackedWidget = ID_WEBVIEW; +// stackedWidget->setCurrentIndex(ID_WEBVIEW); +// currentStackedWidget = ID_WEBVIEW; } QStringList UBFeaturesMimeData::formats() const @@ -390,9 +373,9 @@ void UBFeaturesWidget::importImage(const QImage &image, const QString &fileName) } UBFeaturesListView::UBFeaturesListView( QWidget* parent, const char* name ) -: QListView(parent) + : QListView(parent) { - setObjectName(name); + setObjectName(name); } void UBFeaturesListView::dragEnterEvent( QDragEnterEvent *event ) @@ -423,7 +406,7 @@ void UBFeaturesListView::dragMoveEvent( QDragMoveEvent *event ) void UBFeaturesListView::dropEvent( QDropEvent *event ) { QWidget *eventSource = event->source(); - if (eventSource && eventSource->objectName() == objNameFeatureList) { + if (eventSource && eventSource->objectName() == UBFeaturesWidget::objNameFeatureList) { event->setDropAction( Qt::MoveAction ); } @@ -445,9 +428,9 @@ UBFeaturesNavigatorWidget::UBFeaturesNavigatorWidget(QWidget *parent, const char name = "UBFeaturesNavigatorWidget"; setObjectName(name); - SET_STYLE_SHEET() +// SET_STYLE_SHEET() - mListView = new UBFeaturesListView(this, objNameFeatureList); + mListView = new UBFeaturesListView(this, UBFeaturesWidget::objNameFeatureList); mListSlder = new QSlider(Qt::Horizontal, this); @@ -461,7 +444,7 @@ UBFeaturesNavigatorWidget::UBFeaturesNavigatorWidget(QWidget *parent, const char mainLayer->addWidget(mListView, 1); mainLayer->addWidget(mListSlder, 0); - + mainLayer->setMargin(0); connect(mListSlder, SIGNAL(valueChanged(int)), mListView, SLOT(thumbnailSizeChanged(int))); } @@ -471,6 +454,229 @@ void UBFeaturesNavigatorWidget::setSliderPosition(int pValue) mListSlder->setValue(pValue); } +UBFeaturesCentralWidget::UBFeaturesCentralWidget(QWidget *parent) : QWidget(parent) +{ + setObjectName("UBFeaturesCentralWidget"); + SET_STYLE_SHEET(); + + QVBoxLayout *mLayout = new QVBoxLayout(this); + setLayout(mLayout); + + //Maintains the view of the main part of the palette. Consists of + //mNavigator + //featureProperties + //webVeiw + mStackedWidget = new QStackedWidget(this); + + //Main features icon view with QSlider on the bottom + mNavigator = new UBFeaturesNavigatorWidget(this); + + //Specifies the properties of a standalone element + mFeatureProperties = new UBFeatureProperties(this); + + //Used to show search bar on the search widget + webView = new UBFeaturesWebView(this); + + //filling stackwidget + mStackedWidget->addWidget(mNavigator); + mStackedWidget->addWidget(mFeatureProperties); + mStackedWidget->addWidget(webView); + mStackedWidget->setCurrentIndex(MainList); + mStackedWidget->setContentsMargins(0, 0, 0, 0); + + + mAdditionalDataContainer = new QStackedWidget(this); + mAdditionalDataContainer->setObjectName("mAdditionalDataContainer"); + + //New folder dialog + UBFeaturesNewFolderDialog *dlg = new UBFeaturesNewFolderDialog(mAdditionalDataContainer); + mAdditionalDataContainer->addWidget(dlg); + mAdditionalDataContainer->setCurrentIndex(NewFolderDialog); + + connect(dlg, SIGNAL(createNewFolder(QString)), this, SLOT(createNewFolderSlot(QString))); + connect(dlg, SIGNAL(closeDialog()), this, SLOT(hideAdditionalData())); + connect(this, SIGNAL(sendFileNameList(QStringList)), dlg, SLOT(setFileNameList(QStringList))); + + //Progress bar to show scanning progress + QProgressBar *progressBar = new QProgressBar(); + mAdditionalDataContainer->addWidget(progressBar); + mAdditionalDataContainer->setCurrentIndex(ProgressBarWidget); + progressBar->setMinimum(0); + progressBar->setValue(0); + progressBar->setMaximum(10000); + + + connect(this, SIGNAL(maxFilesCountEvaluated(int)), progressBar, SLOT(setMaximum(int))); + + mLayout->addWidget(mStackedWidget, 1); + mLayout->addWidget(mAdditionalDataContainer, 0); + + mAdditionalDataContainer->hide(); +} + +void UBFeaturesCentralWidget::showElement(const UBFeature &feature, StackElement pView) +{ + if (pView == FeaturesWebView) { + webView->showElement(feature); + mStackedWidget->setCurrentIndex(FeaturesWebView); + } else if (pView == FeaturePropertiesList) { + mFeatureProperties->showElement(feature); + mStackedWidget->setCurrentIndex(FeaturePropertiesList); + } +} + +void UBFeaturesCentralWidget::switchTo(StackElement pView) +{ + mStackedWidget->setCurrentIndex(pView); +} + +void UBFeaturesCentralWidget::setPropertiesPixmap(const QPixmap &pix) +{ + mFeatureProperties->setOrigPixmap(pix); +} + +void UBFeaturesCentralWidget::setPropertiesThumbnail(const QPixmap &pix) +{ + mFeatureProperties->setThumbnail(pix); +} + +UBFeature UBFeaturesCentralWidget::getCurElementFromProperties() +{ + return mFeatureProperties->getCurrentElement(); +} + +void UBFeaturesCentralWidget::showAdditionalData(AddWidget pWidgetType, AddWidgetState pState) +{ + mAdditionalDataContainer->setMaximumHeight(mAdditionalDataContainer->widget(pWidgetType)->sizeHint().height()); + + mAdditionalDataContainer->setCurrentIndex(pWidgetType); + mAdditionalDataContainer->show(); + emit lockMainWidget(pState == Modal ? true : false); +} + +void UBFeaturesCentralWidget::setLockedExcludingAdditional(bool pLock) +{ +// Lock all the members excluding mAdditionalDataContainer + mStackedWidget->setEnabled(!pLock); +} + +void UBFeaturesCentralWidget::createNewFolderSlot(QString pStr) +{ + emit createNewFolderSignal(pStr); + hideAdditionalData(); +} + +void UBFeaturesCentralWidget::hideAdditionalData() +{ + emit lockMainWidget(false); + mAdditionalDataContainer->hide(); +} + +void UBFeaturesCentralWidget::scanStarted() +{ + if (!mAdditionalDataContainer->widget(ProgressBarWidget)) { + return; + } + QProgressBar *progressBar = qobject_cast(mAdditionalDataContainer->widget(ProgressBarWidget)); + if (progressBar && !progressBar->isVisible()) { + showAdditionalData((AddWidget)1); + } +} + +void UBFeaturesCentralWidget::scanFinished() +{ + if (!mAdditionalDataContainer->widget(ProgressBarWidget)) { + return; + } + QProgressBar *progressBar = qobject_cast(mAdditionalDataContainer->widget(ProgressBarWidget)); + if (progressBar && progressBar->isVisible()) { + hideAdditionalData(); + qDebug() << "progressBar max value is " << progressBar->maximum(); + } +} + +void UBFeaturesCentralWidget::increaseStatusBarValue() +{ + if (!mAdditionalDataContainer->widget(ProgressBarWidget)) { + return; + } + QProgressBar *progressBar = qobject_cast(mAdditionalDataContainer->widget(ProgressBarWidget)); + if (progressBar) { + progressBar->setValue(progressBar->value() + 1); + } +} + +UBFeaturesNewFolderDialog::UBFeaturesNewFolderDialog(QWidget *parent) : QWidget(parent) +{ + this->setStyleSheet("background:white;"); + + QVBoxLayout *mainLayout = new QVBoxLayout(); + setLayout(mainLayout); + + QVBoxLayout *labelLayout = new QVBoxLayout(this); + + QLabel *mLabel = new QLabel(labelText, this); + mLineEdit = new QLineEdit(this); + + mValidator = new QRegExpValidator(QRegExp("[^\\/\\:\\?\\*\\|\\<\\>\\\"]{2,}"), this); + mLineEdit->setValidator(mValidator); + labelLayout->addWidget(mLabel); + labelLayout->addWidget(mLineEdit); + + QHBoxLayout *buttonLayout = new QHBoxLayout(this); + + acceptButton = new QPushButton(acceptText, this); + QPushButton *cancelButton = new QPushButton(cancelText, this); + buttonLayout->addWidget(acceptButton); + buttonLayout->addWidget(cancelButton); + + mainLayout->addLayout(labelLayout); + mainLayout->addLayout(buttonLayout); + + acceptButton->setEnabled(false); + + connect(acceptButton, SIGNAL(clicked()), this, SLOT(accept())); + connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); + connect(mLineEdit, SIGNAL(textEdited(QString)), this, SLOT(reactOnTextChanged(QString))); + + reactOnTextChanged(QString()); +} + +void UBFeaturesNewFolderDialog::setRegexp(const QRegExp pRegExp) +{ + mValidator->setRegExp(pRegExp); +} +bool UBFeaturesNewFolderDialog::validString(const QString &pStr) +{ + return mLineEdit->hasAcceptableInput() && !mFileNameList.contains(pStr, Qt::CaseSensitive); +} + +void UBFeaturesNewFolderDialog::accept() +{ +// Setting all the constraints we need + emit createNewFolder(mLineEdit->text()); + mLineEdit->clear(); +} +void UBFeaturesNewFolderDialog::reject() +{ + mLineEdit->clear(); + emit closeDialog(); +} +void UBFeaturesNewFolderDialog::setFileNameList(const QStringList &pLst) +{ + mFileNameList = pLst; +} +void UBFeaturesNewFolderDialog::reactOnTextChanged(const QString &pStr) +{ + if (validString(pStr)) { + acceptButton->setEnabled(true); + mLineEdit->setStyleSheet("background:white;"); + } else { + acceptButton->setEnabled(false); + mLineEdit->setStyleSheet("background:#FFB3C8;"); + } +} + UBFeaturesWebView::UBFeaturesWebView(QWidget* parent, const char* name):QWidget(parent) , mpView(NULL) , mpWebSettings(NULL) @@ -499,6 +705,7 @@ UBFeaturesWebView::UBFeaturesWebView(QWidget* parent, const char* name):QWidget( mpWebSettings->setAttribute(QWebSettings::DnsPrefetchEnabled, true); mpLayout->addWidget(mpView); + mpLayout->setMargin(0); connect(mpView, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); } @@ -578,8 +785,6 @@ UBFeatureProperties::UBFeatureProperties( QWidget *parent, const char *name ) : { setObjectName(name); - SET_STYLE_SHEET(); - // Create the GUI mpLayout = new QVBoxLayout(this); setLayout(mpLayout); @@ -625,6 +830,7 @@ UBFeatureProperties::UBFeatureProperties( QWidget *parent, const char *name ) : mpObjInfos->setObjectName("DockPaletteWidgetBox"); mpObjInfos->setStyleSheet("background:white;"); mpLayout->addWidget(mpObjInfos, 1); + mpLayout->setMargin(0); connect( mpAddPageButton, SIGNAL(clicked()), this, SLOT(onAddToPage()) ); connect( mpSetAsBackgroundButton, SIGNAL( clicked() ), this, SLOT( onSetAsBackground() ) ); @@ -700,7 +906,7 @@ UBFeature UBFeatureProperties::getCurrentElement() const return UBFeature(); } -void UBFeatureProperties::setOrigPixmap(QPixmap &pix) +void UBFeatureProperties::setOrigPixmap(const QPixmap &pix) { if (mpOrigPixmap) @@ -709,7 +915,7 @@ void UBFeatureProperties::setOrigPixmap(QPixmap &pix) mpOrigPixmap = new QPixmap(pix); } -void UBFeatureProperties::setThumbnail(QPixmap &pix) +void UBFeatureProperties::setThumbnail(const QPixmap &pix) { mpThumbnail->setPixmap(pix.scaledToWidth(THUMBNAIL_WIDTH)); adaptSize(); @@ -730,7 +936,7 @@ void UBFeatureProperties::adaptSize() } } -void UBFeatureProperties::showElement( const UBFeature &elem ) +void UBFeatureProperties::showElement(const UBFeature &elem) { if ( mpOrigPixmap ) { @@ -742,9 +948,9 @@ void UBFeatureProperties::showElement( const UBFeature &elem ) delete mpElement; mpElement = NULL; } - mpElement = new UBFeature( elem ); - mpOrigPixmap = new QPixmap( elem.getThumbnail() ); - mpThumbnail->setPixmap(elem.getThumbnail().scaledToWidth(THUMBNAIL_WIDTH)); + mpElement = new UBFeature(elem); + mpOrigPixmap = new QPixmap(QPixmap::fromImage(elem.getThumbnail())); + mpThumbnail->setPixmap(QPixmap::fromImage(elem.getThumbnail()).scaledToWidth(THUMBNAIL_WIDTH)); populateMetadata(); if ( UBApplication::isFromWeb( elem.getFullPath().toString() ) ) @@ -794,8 +1000,8 @@ void UBFeatureProperties::populateMetadata() void UBFeatureProperties::onAddToPage() { - QWidget *w = parentWidget()->parentWidget(); - UBFeaturesWidget* featuresWidget = dynamic_cast( w ); + QWidget *w = parentWidget()->parentWidget()->parentWidget(); + UBFeaturesWidget* featuresWidget = qobject_cast( w ); if (featuresWidget) featuresWidget->getFeaturesController()->addItemToPage( *mpElement ); } @@ -818,8 +1024,8 @@ void UBFeatureProperties::onAddToLib() void UBFeatureProperties::onSetAsBackground() { - QWidget *w = parentWidget()->parentWidget(); - UBFeaturesWidget* featuresWidget = dynamic_cast( w ); + QWidget *w = parentWidget()->parentWidget()->parentWidget(); + UBFeaturesWidget* featuresWidget = qobject_cast( w ); featuresWidget->getFeaturesController()->addItemAsBackground( *mpElement ); } @@ -845,7 +1051,7 @@ QVariant UBFeaturesModel::data(const QModelIndex &index, int role) const } else if (role == Qt::DecorationRole) { - return QIcon( featuresList->at(index.row()).getThumbnail() ); + return QIcon( QPixmap::fromImage(featuresList->at(index.row()).getThumbnail())); } else if (role == Qt::UserRole) { return featuresList->at(index.row()).getVirtualPath(); @@ -1017,7 +1223,7 @@ void UBFeaturesModel::moveData(const UBFeature &source, const UBFeature &destina QString sourceVirtualPath = source.getVirtualPath(); UBFeatureElementType sourceType = source.getType(); - QPixmap sourceIcon = source.getThumbnail(); + QImage sourceIcon = source.getThumbnail(); Q_ASSERT( QFileInfo( sourcePath ).exists() ); @@ -1183,7 +1389,7 @@ void UBFeaturesPathItemDelegate::paint( QPainter *painter, const QStyleOptionVie { painter->drawPixmap( rect.left() - 10, rect.center().y() - 5, *arrowPixmap ); } - painter->drawPixmap( rect.left() + 5, rect.center().y() - 5, feature.getThumbnail().scaledToHeight( 30, Qt::SmoothTransformation ) ); + painter->drawImage( rect.left() + 5, rect.center().y() - 5, feature.getThumbnail().scaledToHeight( 30, Qt::SmoothTransformation ) ); } UBFeaturesPathItemDelegate::~UBFeaturesPathItemDelegate() diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index 65c34db7..788de51b 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -43,6 +43,8 @@ class UBFeaturesListView; class UBFeaturesWebView; class UBFeaturesNavigatorWidget; class UBFeaturesMimeData; +class UBFeaturesCentralWidget; +class UBFeaturesNewFolderDialog; class UBFeaturesWidget : public UBDockPaletteWidget { @@ -63,10 +65,16 @@ public: static const int maxThumbnailSize = 100; static const int defaultThumbnailSize = 40; + static const char *objNamePathList; + static const char *objNameFeatureList; + public: int scrollbarHorisontalPadding() const { return 10;} int scrollbarVerticalIndent() const { return 0;} +signals: + void sendFileNameList(const QStringList lst); + private slots: void onPreviewLoaded(int id, bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground); void currentSelected( const QModelIndex & ); @@ -82,6 +90,7 @@ private slots: void removeElementsFromFavorite(); void deleteSelectedElements(); void rescanModel(); + void lockIt(bool pLock); private: void resizeEvent(QResizeEvent *event); @@ -91,17 +100,12 @@ private: private: UBFeaturesController *controller; - UBFeaturesNavigatorWidget *mNavigator; UBFeaturesListView *pathListView; QVBoxLayout *layout; UBFeaturesActionBar *mActionBar; - UBFeatureProperties *featureProperties; - UBFeaturesWebView *webView; - QStackedWidget *stackedWidget; - int currentStackedWidget; UBDownloadHttpFile* imageGatherer; UBNewFolderDlg *mkFolderDlg; - + UBFeaturesCentralWidget *centralWidget; }; @@ -128,12 +132,13 @@ public: virtual ~UBFeaturesListView() {;} protected: - virtual void dragEnterEvent( QDragEnterEvent *event ); + virtual void dragEnterEvent( QDragEnterEvent *event ); virtual void dropEvent( QDropEvent *event ); virtual void dragMoveEvent( QDragMoveEvent *event ); private slots: void thumbnailSizeChanged(int); + }; @@ -153,6 +158,99 @@ private: }; +class UBFeaturesCentralWidget : public QWidget +{ + Q_OBJECT + +public: + enum StackElement{ + MainList = 0, + FeaturePropertiesList, + FeaturesWebView + }; + + enum AddWidget { + NewFolderDialog = 0, + ProgressBarWidget + }; + + enum AddWidgetState { + NonModal = 0, + Modal + }; + + UBFeaturesCentralWidget(QWidget *parent = 0); + void setSliderPosition(int pValue) {mNavigator->setSliderPosition(pValue);} + + UBFeaturesListView *listView() {return mNavigator->listView();} + void showElement(const UBFeature &feature, StackElement pView); + void switchTo(StackElement pView); + void setPropertiesPixmap(const QPixmap &pix); + void setPropertiesThumbnail(const QPixmap &pix); + StackElement currentView() const {return static_cast(mStackedWidget->currentIndex());} + UBFeature getCurElementFromProperties(); + void showAdditionalData(AddWidget pWidgetType, AddWidgetState pState = NonModal); + + void setLockedExcludingAdditional(bool pLock); + + QStackedWidget *mStackedWidget; + UBFeaturesNavigatorWidget *mNavigator; + UBFeatureProperties *mFeatureProperties; + UBFeaturesWebView *webView; + + QStackedWidget *mAdditionalDataContainer; + +signals: + void lockMainWidget(bool pLock); + void createNewFolderSignal(QString pStr); + void sendFileNameList(const QStringList lst); + +// progressbar widget related signals + void maxFilesCountEvaluated(int pValue); + +private slots: + void createNewFolderSlot(QString pStr); + void hideAdditionalData(); + + void scanStarted(); + void scanFinished(); + void increaseStatusBarValue(); + +private: + +}; + +class UBFeaturesNewFolderDialog : public QWidget +{ + Q_OBJECT + +public: + static const QString acceptText; + static const QString cancelText; + static const QString labelText; + + UBFeaturesNewFolderDialog(QWidget *parent = 0); + void setRegexp(const QRegExp pRegExp); + bool validString(const QString &pStr); + +signals: + void createNewFolder(QString str); + void closeDialog(); + +private slots: + void accept(); + void reject(); + void setFileNameList(const QStringList &pLst); + void reactOnTextChanged(const QString &pStr); + + +private: + QLineEdit *mLineEdit; + QRegExpValidator *mValidator; + QStringList mFileNameList; + QPushButton *acceptButton; + +}; class UBFeaturesWebView : public QWidget { @@ -182,8 +280,8 @@ public: void showElement(const UBFeature &elem); UBFeature getCurrentElement() const; - void setOrigPixmap(QPixmap &pix); - void setThumbnail(QPixmap &pix); + void setOrigPixmap(const QPixmap &pix); + void setThumbnail(const QPixmap &pix); protected: void resizeEvent(QResizeEvent *event); @@ -231,7 +329,6 @@ public: UBFeaturesModel(QList *pFeaturesList, QObject *parent = 0) : QAbstractListModel(parent), featuresList(pFeaturesList) {;} virtual ~UBFeaturesModel(){;} - void addItem( const UBFeature &item ); void deleteFavoriteItem( const QString &path ); void deleteItem( const QString &path ); void deleteItem(const UBFeature &feature); @@ -251,6 +348,9 @@ public: Qt::DropActions supportedDropActions() const { return Qt::MoveAction | Qt::CopyAction; } // void setFeaturesList(QList *flist ) { featuresList = flist; } +public slots: + void addItem( const UBFeature &item ); + private: QList *featuresList; }; @@ -314,4 +414,5 @@ private: QPixmap *arrowPixmap; }; + #endif // UBFEATURESWIDGET_H diff --git a/src/tools/UBGraphicsCache.cpp b/src/tools/UBGraphicsCache.cpp index eff63b59..7a89c534 100644 --- a/src/tools/UBGraphicsCache.cpp +++ b/src/tools/UBGraphicsCache.cpp @@ -45,15 +45,24 @@ UBItem* UBGraphicsCache::deepCopy() const { UBGraphicsCache* copy = new UBGraphicsCache(); - copy->setPos(this->pos()); - copy->setRect(this->rect()); - copy->setTransform(this->transform()); + copyItemParameters(copy); // TODO UB 4.7 ... complete all members ? return copy; } +void UBGraphicsCache::copyItemParameters(UBItem *copy) const +{ + UBGraphicsCache *cp = dynamic_cast(copy); + if (cp) + { + cp->setPos(this->pos()); + cp->setRect(this->rect()); + cp->setTransform(this->transform()); + } +} + QColor UBGraphicsCache::maskColor() { return mMaskColor; diff --git a/src/tools/UBGraphicsCache.h b/src/tools/UBGraphicsCache.h index d1ad25ae..9ca07d0d 100644 --- a/src/tools/UBGraphicsCache.h +++ b/src/tools/UBGraphicsCache.h @@ -39,6 +39,8 @@ public: virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; + QColor maskColor(); void setMaskColor(QColor color); eMaskShape maskshape(); diff --git a/src/tools/UBGraphicsCompass.cpp b/src/tools/UBGraphicsCompass.cpp index 08e44d48..183d9ea3 100644 --- a/src/tools/UBGraphicsCompass.cpp +++ b/src/tools/UBGraphicsCompass.cpp @@ -86,15 +86,24 @@ UBItem* UBGraphicsCompass::deepCopy() const { UBGraphicsCompass* copy = new UBGraphicsCompass(); - copy->setPos(this->pos()); - copy->setRect(this->rect()); - copy->setTransform(this->transform()); + copyItemParameters(copy); // TODO UB 4.7 ... complete all members ? return copy; } +void UBGraphicsCompass::copyItemParameters(UBItem *copy) const +{ + UBGraphicsCompass *cp = dynamic_cast(copy); + if (cp) + { + cp->setPos(this->pos()); + cp->setRect(this->rect()); + cp->setTransform(this->transform()); + } +} + void UBGraphicsCompass::paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget) { Q_UNUSED(styleOption); diff --git a/src/tools/UBGraphicsCompass.h b/src/tools/UBGraphicsCompass.h index d7b6fea2..6ed90429 100644 --- a/src/tools/UBGraphicsCompass.h +++ b/src/tools/UBGraphicsCompass.h @@ -41,6 +41,8 @@ class UBGraphicsCompass: public QObject, public QGraphicsRectItem, public UBItem virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; + signals: void hidden(); diff --git a/src/tools/UBGraphicsCurtainItem.cpp b/src/tools/UBGraphicsCurtainItem.cpp index 390b2f7e..746ed5c6 100644 --- a/src/tools/UBGraphicsCurtainItem.cpp +++ b/src/tools/UBGraphicsCurtainItem.cpp @@ -133,20 +133,28 @@ UBItem* UBGraphicsCurtainItem::deepCopy() const { UBGraphicsCurtainItem* copy = new UBGraphicsCurtainItem(); - copy->setRect(this->rect()); - copy->setPos(this->pos()); - copy->setBrush(this->brush()); - copy->setPen(this->pen()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + copyItemParameters(copy); // TODO UB 4.7 ... complete all members ? return copy; } +void UBGraphicsCurtainItem::copyItemParameters(UBItem *copy) const +{ + UBGraphicsCurtainItem *cp = dynamic_cast(copy); + if (cp) + { + cp->setRect(this->rect()); + cp->setPos(this->pos()); + cp->setBrush(this->brush()); + cp->setPen(this->pen()); + cp->setTransform(this->transform()); + cp->setFlag(QGraphicsItem::ItemIsMovable, true); + cp->setFlag(QGraphicsItem::ItemIsSelectable, true); + cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + } +} QColor UBGraphicsCurtainItem::drawColor() const { diff --git a/src/tools/UBGraphicsCurtainItem.h b/src/tools/UBGraphicsCurtainItem.h index 516e8bd1..afef3960 100644 --- a/src/tools/UBGraphicsCurtainItem.h +++ b/src/tools/UBGraphicsCurtainItem.h @@ -42,6 +42,7 @@ class UBGraphicsCurtainItem : public QObject, public QGraphicsRectItem, public U } virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; virtual void remove(); diff --git a/src/tools/UBGraphicsProtractor.cpp b/src/tools/UBGraphicsProtractor.cpp index 23505e80..c46a678f 100644 --- a/src/tools/UBGraphicsProtractor.cpp +++ b/src/tools/UBGraphicsProtractor.cpp @@ -579,20 +579,27 @@ UBItem* UBGraphicsProtractor::deepCopy() const { UBGraphicsProtractor* copy = new UBGraphicsProtractor(); - copy->setPos(this->pos()); - copy->setRect(this->rect()); - copy->setTransform(this->transform()); - - copy->mCurrentAngle = this->mCurrentAngle; - copy->mSpan = this->mSpan; - copy->mStartAngle = this->mStartAngle; - copy->mScaleFactor = this->mScaleFactor; + copyItemParameters(copy); // TODO UB 4.7 ... complete all members ? return copy; } - +void UBGraphicsProtractor::copyItemParameters(UBItem *copy) const +{ + UBGraphicsProtractor *cp = dynamic_cast(copy); + if (cp) + { + cp->setPos(this->pos()); + cp->setRect(this->rect()); + cp->setTransform(this->transform()); + + cp->mCurrentAngle = this->mCurrentAngle; + cp->mSpan = this->mSpan; + cp->mStartAngle = this->mStartAngle; + cp->mScaleFactor = this->mScaleFactor; + } +} void UBGraphicsProtractor::rotateAroundCenter(qreal angle) { diff --git a/src/tools/UBGraphicsProtractor.h b/src/tools/UBGraphicsProtractor.h index e6a7ecac..0af790de 100644 --- a/src/tools/UBGraphicsProtractor.h +++ b/src/tools/UBGraphicsProtractor.h @@ -40,6 +40,7 @@ class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipse void setMarkerAngle (qreal angle) { mCurrentAngle = angle; } virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; enum { Type = UBGraphicsItemType::ProtractorItemType }; diff --git a/src/tools/UBGraphicsRuler.cpp b/src/tools/UBGraphicsRuler.cpp index 4a1a74d6..2542bdec 100644 --- a/src/tools/UBGraphicsRuler.cpp +++ b/src/tools/UBGraphicsRuler.cpp @@ -75,15 +75,24 @@ UBItem* UBGraphicsRuler::deepCopy() const { UBGraphicsRuler* copy = new UBGraphicsRuler(); - copy->setPos(this->pos()); - copy->setRect(this->rect()); - copy->setTransform(this->transform()); + copyItemParameters(copy); // TODO UB 4.7 ... complete all members ? return copy; } +void UBGraphicsRuler::copyItemParameters(UBItem *copy) const +{ + UBGraphicsRuler *cp = dynamic_cast(copy); + if (cp) + { + cp->setPos(this->pos()); + cp->setRect(this->rect()); + cp->setTransform(this->transform()); + } +} + void UBGraphicsRuler::paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget) { Q_UNUSED(styleOption); diff --git a/src/tools/UBGraphicsRuler.h b/src/tools/UBGraphicsRuler.h index 89584b70..f58e6348 100644 --- a/src/tools/UBGraphicsRuler.h +++ b/src/tools/UBGraphicsRuler.h @@ -41,6 +41,7 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu } virtual UBItem* deepCopy() const; + virtual void copyItemParameters(UBItem *copy) const; virtual void StartLine(const QPointF& position, qreal width); virtual void DrawLine(const QPointF& position, qreal width); diff --git a/src/tools/UBGraphicsTriangle.cpp b/src/tools/UBGraphicsTriangle.cpp index f62413fe..49880a01 100644 --- a/src/tools/UBGraphicsTriangle.cpp +++ b/src/tools/UBGraphicsTriangle.cpp @@ -94,9 +94,7 @@ UBItem* UBGraphicsTriangle::deepCopy(void) const { UBGraphicsTriangle* copy = new UBGraphicsTriangle(); - copy->setPos(this->pos()); - copy->setPolygon(this->polygon()); - copy->setTransform(this->transform()); + copyItemParameters(copy); // TODO UB 4.7 ... complete all members ? @@ -104,6 +102,17 @@ UBItem* UBGraphicsTriangle::deepCopy(void) const } +void UBGraphicsTriangle::copyItemParameters(UBItem *copy) const +{ + UBGraphicsTriangle* cp = dynamic_cast(copy); + if (cp) + { + cp->setPos(this->pos()); + cp->setPolygon(this->polygon()); + cp->setTransform(this->transform()); + } +} + void UBGraphicsTriangle::setRect(qreal x, qreal y, qreal w, qreal h, UBGraphicsTriangleOrientation orientation) { QPolygonF polygon; diff --git a/src/tools/UBGraphicsTriangle.h b/src/tools/UBGraphicsTriangle.h index 60f8d145..b945b6b6 100644 --- a/src/tools/UBGraphicsTriangle.h +++ b/src/tools/UBGraphicsTriangle.h @@ -45,6 +45,7 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt virtual UBItem* deepCopy(void) const; + virtual void copyItemParameters(UBItem *copy) const; virtual void StartLine(const QPointF& scenePos, qreal width); virtual void DrawLine(const QPointF& position, qreal width);