From ff9a74b1ea7d5b8d55e4e534c0f638ece4eb64c1 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Thu, 1 Sep 2011 17:39:15 +0200 Subject: [PATCH] fixed issue http://188.165.53.52/jira/browse/SANKORE-213 --- src/board/UBBoardController.cpp | 4 - src/board/UBBoardController.h | 7 - src/board/UBBoardPaletteManager.cpp | 27 +- src/board/UBLibraryController.cpp | 135 ++-- src/board/UBLibraryController.h | 11 +- src/core/UBApplication.cpp | 7 +- src/gui/UBLibActionBar.cpp | 5 +- src/gui/UBLibItemProperties.cpp | 11 +- src/gui/UBLibNavigatorWidget.cpp | 32 +- src/gui/UBLibNavigatorWidget.h | 2 + src/gui/UBLibPalette.cpp | 177 ----- src/gui/UBLibPalette.h | 79 -- src/gui/UBLibWidget.h | 1 + src/gui/UBLibraryWidget.cpp | 1136 +++++++++++++-------------- src/gui/UBLibraryWidget.h | 10 +- src/gui/gui.pri | 2 - 16 files changed, 687 insertions(+), 959 deletions(-) delete mode 100644 src/gui/UBLibPalette.cpp delete mode 100644 src/gui/UBLibPalette.h diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index c037db93..d132e933 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -54,7 +54,6 @@ #include "document/UBDocumentProxy.h" #include "document/UBDocumentController.h" -#include "board/UBLibraryController.h" #include "board/UBDrawingController.h" #include "board/UBBoardView.h" @@ -72,7 +71,6 @@ UBBoardController::UBBoardController(UBMainWindow* mainWindow) , mActiveDocument(0) , mActiveScene(0) , mActiveSceneIndex(-1) - , mLibraryController(0) , mPaletteManager(0) , mSoftwareUpdateDialog(0) , mMessageWindow(0) @@ -85,8 +83,6 @@ UBBoardController::UBBoardController(UBMainWindow* mainWindow) , mSystemScaleFactor(1.0) , mCleanupDone(false) { - mLibraryController = new UBLibraryController(mMainWindow->centralWidget(), this); - mZoomFactor = UBSettings::settings()->boardZoomFactor->get().toDouble(); int penColorIndex = UBSettings::settings()->penColorIndex(); diff --git a/src/board/UBBoardController.h b/src/board/UBBoardController.h index 5e1e0260..87cc8fb9 100644 --- a/src/board/UBBoardController.h +++ b/src/board/UBBoardController.h @@ -25,7 +25,6 @@ class UBApplication; class UBBoardView; class UBDocumentController; -class UBLibraryController; class UBMessageWindow; class UBGraphicsScene; class UBDocumentProxy; @@ -129,11 +128,6 @@ class UBBoardController : public QObject return mMarkerColorOnLightBackground; } - UBLibraryController* libraryController() - { - return mLibraryController; - } - qreal systemScaleFactor() { return mSystemScaleFactor; @@ -285,7 +279,6 @@ class UBBoardController : public QObject UBGraphicsScene* mActiveScene; int mActiveSceneIndex; - UBLibraryController* mLibraryController; UBBoardPaletteManager *mPaletteManager; UBSoftwareUpdateDialog *mSoftwareUpdateDialog; diff --git a/src/board/UBBoardPaletteManager.cpp b/src/board/UBBoardPaletteManager.cpp index 2e9efabb..86cb4736 100755 --- a/src/board/UBBoardPaletteManager.cpp +++ b/src/board/UBBoardPaletteManager.cpp @@ -49,7 +49,6 @@ #include "document/UBDocumentProxy.h" #include "podcast/UBPodcastController.h" -#include "board/UBLibraryController.h" #include "board/UBDrawingController.h" #include "tools/UBToolsManager.h" @@ -569,7 +568,8 @@ void UBBoardPaletteManager::addItemToLibrary() , Qt::KeepAspectRatio, Qt::SmoothTransformation); } QImage image = mPixmap.toImage(); - UBApplication::boardController->libraryController()->importImageOnLibrary(image); + //UBApplication::boardController->libraryController()->importImageOnLibrary(image); + } else { @@ -579,29 +579,6 @@ void UBBoardPaletteManager::addItemToLibrary() mAddItemPalette->hide(); } -//void UBBoardPaletteManager::shareItemOnWeb() -//{ -// QPixmap pixmap = mPixmap; - -// if(mPixmap.isNull()) -// { -// pixmap = QPixmap(mItemUrl.toLocalFile()); -// } - -// if(!pixmap.isNull()) -// { -// UBCapturePublisher* publisher = new UBCapturePublisher(pixmap, this); -// publisher->publish(); -// } -// else -// { -// UBApplication::showMessage(tr("Error Publishing Image to the Web")); -// } - -// mAddItemPalette->hide(); -//} - - void UBBoardPaletteManager::zoomButtonPressed() { mZoomButtonPressedTime = QTime::currentTime(); diff --git a/src/board/UBLibraryController.cpp b/src/board/UBLibraryController.cpp index 4aed8c49..e95f7767 100644 --- a/src/board/UBLibraryController.cpp +++ b/src/board/UBLibraryController.cpp @@ -45,10 +45,10 @@ static quint32 magicNumber = 0xACDCAFE0; static QString favoriteVirtualPath = "$favorite$"; -UBLibraryController::UBLibraryController(QWidget *pParentWidget, UBBoardController *pBoardController) : +UBLibraryController::UBLibraryController(QWidget *pParentWidget) : QObject(pParentWidget), mParentWidget(pParentWidget), - mBoardController(pBoardController), + mBoardController(UBApplication::boardController), mLastItemOffsetIndex(0) { readFavoriteList(); @@ -84,7 +84,7 @@ void UBLibraryController::createInternalWidgetItems() UBToolsManager::UBToolDescriptor tool = UBToolsManager::manager()->toolByID(toolUri); UBLibElement *newTool = new UBLibElement(eUBLibElementType_InteractiveItem, QUrl(tool.id), tool.label); QImage toolImage = tool.icon.toImage(); - newTool->setThumbnail(&toolImage); + newTool->setThumbnail(toolImage); newTool->setInformation(tool.label + " " + tool.version); mInternalLibElements << newTool; @@ -201,64 +201,54 @@ QList UBLibraryController::rootCategoriesList() QList categories; UBLibElement* element = new UBLibElement(eUBLibElementType_Folder, mAudioStandardDirectoryPath, tr("Audios", "Audio category element")); - QImage* categoryImage = new QImage(":images/libpalette/AudiosCategory.svg"); - element->setThumbnail(categoryImage); + element->setThumbnail(QImage(":images/libpalette/AudiosCategory.svg")); element->setMoveable(false); categories << element; element = new UBLibElement(eUBLibElementType_Folder, mVideoStandardDirectoryPath, tr("Movies", "Movies category element")); - categoryImage = new QImage(":images/libpalette/MoviesCategory.svg"); - element->setThumbnail(categoryImage); + element->setThumbnail(QImage(":images/libpalette/MoviesCategory.svg")); element->setMoveable(false); categories << element; element = new UBLibElement(eUBLibElementType_Folder, mPicturesStandardDirectoryPath, tr("Pictures", "Pictures category element")); - categoryImage = new QImage(":images/libpalette/PicturesCategory.svg"); - element->setThumbnail(categoryImage); + element->setThumbnail(QImage(":images/libpalette/PicturesCategory.svg")); element->setMoveable(false); categories << element; QString path = UBSettings::settings()->uniboardShapeLibraryDirectory(); - categoryImage = new QImage(":images/libpalette/ShapesCategory.svg"); element = new UBLibElement(eUBLibElementType_Folder, QUrl::fromLocalFile(path), tr("Shapes", "Shapes category element")); - element->setThumbnail(categoryImage); + element->setThumbnail(QImage(":images/libpalette/ShapesCategory.svg")); element->setMoveable(false); categories << element; - categoryImage = new QImage(":images/libpalette/ApplicationsCategory.svg"); element = new UBLibElement(eUBLibElementType_Folder, mInteractiveUserDirectoryPath, tr("Applications", "Applications category element")); - element->setThumbnail(categoryImage); + element->setThumbnail(QImage(":images/libpalette/ApplicationsCategory.svg")); element->setMoveable(false); categories << element; - categoryImage = new QImage(":images/libpalette/FavoritesCategory.svg"); element = new UBLibElement(eUBLibElementType_VirtualFolder, favoriteVirtualPath, tr("Favorite", "Favorite category element")); - element->setThumbnail(categoryImage); + element->setThumbnail(QImage(":images/libpalette/FavoritesCategory.svg")); element->setMoveable(false); categories << element; - categoryImage = new QImage(":images/libpalette/InteractivesCategory.svg"); mInteractiveCategoryPath = QUrl::fromLocalFile(UBSettings::settings()->uniboardGipLibraryDirectory()); element = new UBLibElement(eUBLibElementType_Folder, mInteractiveCategoryPath, tr("Interactivities", "Interactives category element")); - element->setThumbnail(categoryImage); + element->setThumbnail(QImage(":images/libpalette/InteractivesCategory.svg")); element->setMoveable(false); categories << element; - categoryImage = new QImage(":images/libpalette/FlashCategory.svg"); element = new UBLibElement(eUBLibElementType_Folder, mAnimationUserDirectoryPath, tr("Animations", "Animations category element")); - element->setThumbnail(categoryImage); + element->setThumbnail(QImage(":images/libpalette/FlashCategory.svg")); element->setMoveable(false); categories << element; - - categories << UBLibElement::trashElement(); return categories; } -QImage* UBLibraryController::createThumbnail(UBLibElement* pElement) +QImage UBLibraryController::createThumbnail(UBLibElement* pElement) { QString thumbnailPath = UBFileSystemUtils::thumbnailPath(pElement->path().toLocalFile()); QString mimetype = UBFileSystemUtils::mimeTypeFromFileName(pElement->path().toLocalFile()); @@ -287,17 +277,17 @@ QImage* UBLibraryController::createThumbnail(UBLibElement* pElement) } } - return new QImage(thumbnailPath); + return QImage(thumbnailPath); } -QImage* UBLibraryController::thumbnailForFile(UBLibElement* pElement) +QImage UBLibraryController::thumbnailForFile(UBLibElement* pElement) { if (pElement->path().toString().contains("uniboardTool://")){ - QImage* image = new QImage(UBToolsManager::manager()->iconFromToolId(pElement->path().toString())); + QImage image = QImage(UBToolsManager::manager()->iconFromToolId(pElement->path().toString())); return image; } if (pElement->type() == eUBLibElementType_InteractiveItem){ - QImage* image = new QImage(UBAbstractWidget::iconFilePath(pElement->path())); + QImage image = QImage(UBAbstractWidget::iconFilePath(pElement->path())); return image; } @@ -307,7 +297,7 @@ QImage* UBLibraryController::thumbnailForFile(UBLibElement* pElement) qWarning() << "thumbnailForFile impossible to create thumbnail path for the element " + pElement->path().toLocalFile(); if (QFileInfo(thumbnailPath).exists()) - return new QImage(thumbnailPath); + return QImage(thumbnailPath); else return createThumbnail(pElement); } @@ -318,7 +308,8 @@ QList UBLibraryController::addVirtualElementsForItemPath(const QS if (pPath == mInteractiveUserDirectoryPath.toLocalFile()){ content << listElementsInPath(UBSettings::settings()->uniboardInteractiveLibraryDirectory()); content << listElementsInPath(UBSettings::settings()->uniboardInteractiveFavoritesDirectory()); - content << mInternalLibElements; + foreach(UBLibElement* eachElement, mInternalLibElements) + content << new UBLibElement(eachElement); } else if (pPath == mPicturesStandardDirectoryPath.toLocalFile()){ QUrl path = QUrl::fromLocalFile(UBSettings::settings()->uniboardImageLibraryDirectory()); @@ -353,8 +344,8 @@ QList UBLibraryController::listElementsInPath(const QString& pPat UBLibElement *element = new UBLibElement(fileType, QUrl::fromLocalFile(fileInfo->absoluteFilePath()), itemName); if (fileType == eUBLibElementType_Folder) { - QImage* directoryImage = new QImage(":images/libpalette/folder.svg"); - element->setThumbnail(directoryImage); +// QImage* directoryImage = new QImage(":images/libpalette/folder.svg"); + element->setThumbnail(QImage(":images/libpalette/folder.svg")); } else if (fileType == eUBLibElementType_Item) { if (element->path().toLocalFile().contains(".thumbnail.")) @@ -373,7 +364,10 @@ QList UBLibraryController::listElementsInPath(const QString& pPat QList UBLibraryController::listElementsInVirtualForlder(UBLibElement* pElement) { Q_UNUSED(pElement); - return mFavoriteList; + QList copyOfTheFavoriteList; + foreach(UBLibElement* eachElement, mFavoriteList) + copyOfTheFavoriteList << new UBLibElement(eachElement); + return copyOfTheFavoriteList; } void UBLibraryController::moveContent(QList sourceList, UBLibElement *pDestination) @@ -416,21 +410,31 @@ void UBLibraryController::emptyElementsOnTrash( QList elementsLis } } +void UBLibraryController::cleanElementsList() +{ +// qDebug() << "cleanElementsList()"; +// qDebug() << this; +// foreach(UBLibElement*eachElement, mElementsList) +// qDebug() << eachElement; + qDeleteAll(mElementsList); + mElementsList.clear(); +} + QList UBLibraryController::getContent(UBLibElement *element) { - QList elementsList; + cleanElementsList(); switch (element->type()) { case eUBLibElementType_Category: { - elementsList = rootCategoriesList(); + mElementsList = rootCategoriesList(); break; } case eUBLibElementType_VirtualFolder: { - elementsList = listElementsInVirtualForlder(element); + mElementsList = listElementsInVirtualForlder(element); break; } case eUBLibElementType_Folder: { - elementsList = listElementsInPath(element->path().toLocalFile()); + mElementsList = listElementsInPath(element->path().toLocalFile()); break; } case eUBLibElementType_Item: { @@ -443,16 +447,20 @@ QList UBLibraryController::getContent(UBLibElement *element) break; } - return elementsList; +// qDebug() << "getContent()"; +// qDebug() << this; +// foreach(UBLibElement*eachElement, mElementsList) +// qDebug() << eachElement; + + return mElementsList; } UBLibraryController::~UBLibraryController() { + cleanElementsList(); //NOOP } - - void UBLibraryController::setItemAsBackground(UBLibElement* image) { if (!activeScene()){ @@ -501,9 +509,6 @@ void UBLibraryController::addItemToPage(UBLibElement* item) else{ UBApplication::showMessage(tr("Adding to page failed for item %1.").arg(item->name())); } - - - } void UBLibraryController::removeBackground() @@ -564,7 +569,8 @@ void UBLibraryController::readFavoriteList() eachElement->setInformation(info); eachElement->setExtension(extension); eachElement->setThumbnail(thumbnailForFile(eachElement)); - mFavoriteList << eachElement; + if(!isOnFavoriteList(eachElement)) + mFavoriteList << eachElement; } file.close(); @@ -582,10 +588,10 @@ UBLibElement* UBLibraryController::isOnFavoriteList(UBLibElement * element) void UBLibraryController::addToFavorite(QList elementList) { - foreach(UBLibElement* eachElement, elementList){ + foreach(UBLibElement* eachElement, elementList) if(!isOnFavoriteList(eachElement)) - mFavoriteList << eachElement; - } + mFavoriteList << new UBLibElement(eachElement); + persistFavoriteList(); } @@ -601,7 +607,8 @@ void UBLibraryController::removeFromFavorite(QList elementList) persistFavoriteList(); } -QRectF UBLibraryController::visibleSceneRect() { +QRectF UBLibraryController::visibleSceneRect() +{ QRectF visibleSceneRect(0, 0, 0, 0); if (activeScene() && mBoardController && mBoardController->controlView()) { @@ -621,7 +628,8 @@ QRectF UBLibraryController::visibleSceneRect() { return visibleSceneRect; } -void UBLibraryController::addImagesToCurrentPage(const QList& images) { +void UBLibraryController::addImagesToCurrentPage(const QList& images) +{ QPointF pos = visibleSceneRect().topLeft(); foreach(const QUrl url, images) @@ -652,7 +660,8 @@ void UBLibraryController::addImagesToCurrentPage(const QList& images) { } } -void UBLibraryController::addVideosToCurrentPage(const QList& videos) { +void UBLibraryController::addVideosToCurrentPage(const QList& videos) +{ QPointF pos = visibleSceneRect().topLeft(); foreach(const QUrl url, videos) @@ -665,7 +674,8 @@ void UBLibraryController::addVideosToCurrentPage(const QList& videos) { } } -void UBLibraryController::addAudiosToCurrentPage(const QList& sounds) { +void UBLibraryController::addAudiosToCurrentPage(const QList& sounds) +{ QPointF topLeftPos = visibleSceneRect().topLeft(); QPointF pos = topLeftPos; @@ -680,12 +690,10 @@ void UBLibraryController::addAudiosToCurrentPage(const QList& sounds) { } } -void UBLibraryController::addInteractivesToCurrentPage( - const QList& widgets) { +void UBLibraryController::addInteractivesToCurrentPage( const QList& widgets) +{ foreach(const QUrl url, widgets) - { mBoardController->downloadURL(url, QPointF(0, 0)); - } } QString UBLibraryController::favoritePath() @@ -699,6 +707,17 @@ UBLibElement::UBLibElement() { mbMoveable = false; } +UBLibElement::UBLibElement(UBLibElement* element) +{ + mType = element->type(); + mPath = element->path(); + mThumbnail = *element->thumbnail(); + mInfo = element->information(); + mName = element->name(); + mExtension = element->extension(); + mbMoveable = element->isMoveable(); +} + UBLibElement::UBLibElement(eUBLibElementType type, const QUrl &path, const QString &name) { @@ -728,7 +747,7 @@ UBLibElement::~UBLibElement() UBChainedLibElement::UBChainedLibElement(UBLibElement *pElem, UBChainedLibElement *pNextElem) { - mpElem = pElem; + mpElem = new UBLibElement(pElem); mpNextElem = pNextElem; } @@ -747,13 +766,9 @@ void UBChainedLibElement::setNextElement(UBChainedLibElement *nextElem) UBLibElement* UBLibElement::trashElement() { - static UBLibElement *trashElement; - if (trashElement) - return trashElement; - + UBLibElement *trashElement; trashElement = new UBLibElement(eUBLibElementType_Folder, QUrl::fromLocalFile(UBSettings::trashLibraryPaletteDirPath()), QObject::tr("Trash", "Pictures category element")); - QImage *categoryImage = new QImage(":images/libpalette/TrashCategory.svg"); - trashElement->setThumbnail(categoryImage); + trashElement->setThumbnail(QImage(":images/libpalette/TrashCategory.svg")); trashElement->setMoveable(false); return trashElement; diff --git a/src/board/UBLibraryController.h b/src/board/UBLibraryController.h index e0422199..26b6fe61 100644 --- a/src/board/UBLibraryController.h +++ b/src/board/UBLibraryController.h @@ -42,6 +42,7 @@ class UBLibElement public: UBLibElement(); UBLibElement(eUBLibElementType type, const QUrl& path, const QString& name); + UBLibElement(UBLibElement* element); ~UBLibElement(); static UBLibElement* trashElement(); @@ -51,7 +52,7 @@ public: QUrl path(){return mPath;} void setPath(QUrl path){mPath = path;} QImage* thumbnail(){return &mThumbnail;} - void setThumbnail(QImage* pThumb){mThumbnail = *pThumb;} + void setThumbnail(QImage pThumb){mThumbnail = pThumb;} QString information(){return mInfo;} void setInformation(QString info){mInfo = info;} QString name(){return mName;} @@ -91,7 +92,7 @@ class UBLibraryController : public QObject Q_OBJECT; public: - UBLibraryController(QWidget *parentWidget, UBBoardController *boardController); + UBLibraryController(QWidget *parentWidget); virtual ~UBLibraryController(); QList getContent(UBLibElement* pElement); @@ -134,14 +135,16 @@ class UBLibraryController : public QObject void persistFavoriteList(); void readFavoriteList(); QList mInternalLibElements; + QList mElementsList; + void cleanElementsList(); private: QList rootCategoriesList(); QList listElementsInPath(const QString& pPath); QList listElementsInVirtualForlder(UBLibElement* pElement); void userPath(QUrl &pPath); - QImage* thumbnailForFile(UBLibElement* pPath); - QImage* createThumbnail(UBLibElement* pPath); + QImage thumbnailForFile(UBLibElement* pPath); + QImage createThumbnail(UBLibElement* pPath); QList addVirtualElementsForItemPath(const QString& pPath); void createInternalWidgetItems(); diff --git a/src/core/UBApplication.cpp b/src/core/UBApplication.cpp index 0e431005..90e2dfd3 100644 --- a/src/core/UBApplication.cpp +++ b/src/core/UBApplication.cpp @@ -38,7 +38,6 @@ #include "board/UBBoardController.h" #include "board/UBDrawingController.h" -#include "board/UBLibraryController.h" #include "board/UBBoardView.h" #include "web/UBWebController.h" @@ -380,10 +379,10 @@ void UBApplication::toolBarDisplayTextChanged(QVariant display) } -void UBApplication::closeEvent(QCloseEvent *event) -{ +void UBApplication::closeEvent(QCloseEvent *event) +{ Q_UNUSED(event); - + closing(); } diff --git a/src/gui/UBLibActionBar.cpp b/src/gui/UBLibActionBar.cpp index 31901971..6b4093c0 100644 --- a/src/gui/UBLibActionBar.cpp +++ b/src/gui/UBLibActionBar.cpp @@ -16,9 +16,9 @@ #include #include +#include "UBLibWidget.h" #include "UBLibActionBar.h" #include "core/UBApplication.h" -#include "board/UBBoardController.h" #include "core/memcheck.h" @@ -361,7 +361,8 @@ void UBLibActionBar::onSelectionChanged(QList itemList, bool isI */ UBLibraryController* UBLibActionBar::libraryController() { - return UBApplication::boardController->libraryController(); + UBLibWidget* libWidget = dynamic_cast(parentWidget()); + return libWidget->libNavigator()->libraryWidget()->libraryController(); } /** diff --git a/src/gui/UBLibItemProperties.cpp b/src/gui/UBLibItemProperties.cpp index 92739aaf..1b47fbef 100644 --- a/src/gui/UBLibItemProperties.cpp +++ b/src/gui/UBLibItemProperties.cpp @@ -12,15 +12,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + +#include "UBLibWidget.h" #include "UBLibItemProperties.h" #include "core/UBApplication.h" -#include "board/UBBoardController.h" - #include "frameworks/UBFileSystemUtils.h" - #include "core/memcheck.h" /** @@ -223,7 +222,8 @@ void UBLibItemProperties::adaptSize() */ void UBLibItemProperties::onAddToPage() { - UBApplication::boardController->libraryController()->addItemToPage(mpElement); + UBLibWidget* libWidget = dynamic_cast(parentWidget()->parentWidget()); + libWidget->libNavigator()->libraryWidget()->libraryController()->addItemToPage(mpElement); } /** @@ -239,7 +239,8 @@ void UBLibItemProperties::onAddToLib() */ void UBLibItemProperties::onSetAsBackground() { - UBApplication::boardController->libraryController()->setItemAsBackground(mpElement); + UBLibWidget* libWidget = dynamic_cast(parentWidget()->parentWidget()); + libWidget->libNavigator()->libraryWidget()->libraryController()->setItemAsBackground(mpElement); } /** diff --git a/src/gui/UBLibNavigatorWidget.cpp b/src/gui/UBLibNavigatorWidget.cpp index 8edaf447..46908a29 100644 --- a/src/gui/UBLibNavigatorWidget.cpp +++ b/src/gui/UBLibNavigatorWidget.cpp @@ -13,7 +13,7 @@ * along with this program. If not, see . */ #include "UBLibNavigatorWidget.h" -#include "UBRightPalette.h" +#include "UBLibWidget.h" #include "core/memcheck.h" @@ -27,19 +27,18 @@ static int tickIntervalForSlider = 10; * @param name as the object name */ UBLibNavigatorWidget::UBLibNavigatorWidget(QWidget *parent, const char *name):QWidget(parent) - , mLayout(NULL) - , mLibWidget(NULL) - , mPathViewer(NULL) - , mSlider(NULL) - , mSliderWidthSetting(NULL) + , mLayout(NULL) + , mLibWidget(NULL) + , mPathViewer(NULL) + , mSlider(NULL) + , mSliderWidthSetting(NULL) { setObjectName(name); setAcceptDrops(true); - UBRightPalette* pRightPalette = dynamic_cast(parentWidget()); + UBLibWidget* libWidget = dynamic_cast(parentWidget()); mLayout = new QVBoxLayout(this); -// mLayout->setContentsMargins(20, 5, 5, 5); setLayout(mLayout); mPathViewer = new UBLibPathViewer(this); @@ -66,15 +65,13 @@ UBLibNavigatorWidget::UBLibNavigatorWidget(QWidget *parent, const char *name):QW connect(mSlider,SIGNAL(valueChanged(int)),this,SLOT(updateThumbnailsSize(int))); connect(mPathViewer, SIGNAL(elementsDropped(QList,UBLibElement*)), mLibWidget, SLOT(onElementsDropped(QList,UBLibElement*))); - if(NULL != pRightPalette) - { - connect(mLibWidget, SIGNAL(navigBarUpdate(UBLibElement*)), pRightPalette->libWidget()->actionBar(), SLOT(onNavigbarUpdate(UBLibElement*))); - connect(mLibWidget, SIGNAL(itemsSelected(QList, bool)), pRightPalette->libWidget()->actionBar(), SLOT(onSelectionChanged(QList, bool))); - connect(pRightPalette->libWidget()->actionBar(), SIGNAL(deleteDone()), mLibWidget, SLOT(onRefreshCurrentFolder())); - connect(mLibWidget, SIGNAL(favoritesEntered(bool)), pRightPalette->libWidget()->actionBar(), SLOT(onFavoritesEntered(bool))); - connect(pRightPalette->libWidget()->actionBar(), SIGNAL(searchElement(QString)), mLibWidget, SLOT(onSearchElement(QString))); - connect(pRightPalette->libWidget()->actionBar(), SIGNAL(newFolderToCreate()), mLibWidget, SLOT(onNewFolderToCreate())); - } + + connect(mLibWidget, SIGNAL(navigBarUpdate(UBLibElement*)), libWidget->actionBar(), SLOT(onNavigbarUpdate(UBLibElement*))); + connect(mLibWidget, SIGNAL(itemsSelected(QList, bool)), libWidget->actionBar(), SLOT(onSelectionChanged(QList, bool))); + connect(libWidget->actionBar(), SIGNAL(deleteDone()), mLibWidget, SLOT(onRefreshCurrentFolder())); + connect(mLibWidget, SIGNAL(favoritesEntered(bool)), libWidget->actionBar(), SLOT(onFavoritesEntered(bool))); + connect(libWidget->actionBar(), SIGNAL(searchElement(QString)), mLibWidget, SLOT(onSearchElement(QString))); + connect(libWidget->actionBar(), SIGNAL(newFolderToCreate()), mLibWidget, SLOT(onNewFolderToCreate())); mLibWidget->init(); } @@ -147,6 +144,7 @@ void UBLibNavigatorWidget::removeNextChainedElements(UBChainedLibElement *fromEl if(NULL != fromElem->nextElement()) { removeNextChainedElements(fromElem->nextElement()); + delete fromElem->nextElement()->element(); delete fromElem->nextElement(); fromElem->setNextElement(NULL); } diff --git a/src/gui/UBLibNavigatorWidget.h b/src/gui/UBLibNavigatorWidget.h index 0917b6e3..a8750b38 100644 --- a/src/gui/UBLibNavigatorWidget.h +++ b/src/gui/UBLibNavigatorWidget.h @@ -32,6 +32,8 @@ public: ~UBLibNavigatorWidget(); void dropMe(const QMimeData* _data); + UBLibraryWidget* libraryWidget(){return mLibWidget;}; + signals: void propertiesRequested(UBLibElement* elem); diff --git a/src/gui/UBLibPalette.cpp b/src/gui/UBLibPalette.cpp deleted file mode 100644 index 597a99a0..00000000 --- a/src/gui/UBLibPalette.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include -#include "UBLibPalette.h" - -#include "core/memcheck.h" - -/** - * \brief Constructor - * @param parent as the parent widget - * @param name as the object name - */ -UBLibPalette::UBLibPalette(QWidget *parent, const char *name):UBDockPalette(parent, name) - , mLayout(NULL) - , mStackedWidget(NULL) - , mNavigator(NULL) - , mProperties(NULL) - , mActionBar(NULL) -{ - setOrientation(eUBDockOrientation_Right); - - setAcceptDrops(true); - - resize(UBSettings::settings()->libPaletteWidth->get().toInt(), parentWidget()->height()); - setContentsMargins(border(), 0, 0, 0); - mCollapseWidth = 180; - mLastWidth = 300; - - mLayout = new QVBoxLayout(this); - mLayout->setContentsMargins(20, customMargin(), customMargin(), customMargin()); - setLayout(mLayout); - - // Build the GUI - mStackedWidget = new QStackedWidget(this); - mActionBar = new UBLibActionBar(this); - mNavigator = new UBLibNavigatorWidget(this); - mProperties = new UBLibItemProperties(this); - - mLayout->addWidget(mStackedWidget, 1); - mLayout->addWidget(mActionBar, 0); - - mStackedWidget->addWidget(mNavigator); - mStackedWidget->addWidget(mProperties); - - mStackedWidget->setCurrentIndex(ID_NAVIGATOR); - miCrntStackWidget = ID_NAVIGATOR; - - connect(mNavigator, SIGNAL(propertiesRequested(UBLibElement*)), this, SLOT(showProperties(UBLibElement*))); - connect(mProperties, SIGNAL(showFolderContent()), this, SLOT(showFolder())); -} - -/** - * \brief Destructor - */ -UBLibPalette::~UBLibPalette() -{ - if(NULL != mProperties) - { - delete mProperties; - mProperties = NULL; - } - if(NULL != mActionBar) - { - delete mActionBar; - mActionBar = NULL; - } -} - -/** - * \brief Update the maximum width - */ -void UBLibPalette::updateMaxWidth() -{ - setMaximumWidth((int)((parentWidget()->width() * 2)/3)); - setMaximumHeight(parentWidget()->height()); - setMinimumHeight(parentWidget()->height()); -} - -/** - * \brief Handles the drag enter event - * @param pEvent as the drag enter event - */ -void UBLibPalette::dragEnterEvent(QDragEnterEvent *pEvent) -{ - setBackgroundRole(QPalette::Highlight); - pEvent->acceptProposedAction(); -} - -void UBLibPalette::dragLeaveEvent(QDragLeaveEvent *pEvent) -{ - pEvent->accept(); -} - -/** - * \brief Handles the drop event - * @param pEvent as the drop event - */ -void UBLibPalette::dropEvent(QDropEvent *pEvent) -{ - processMimeData(pEvent->mimeData()); - setBackgroundRole(QPalette::Dark); - mStackedWidget->setCurrentIndex(miCrntStackWidget); - pEvent->acceptProposedAction(); -} - -/** - * \brief Handles the drag move event - * @param pEvent as the drag move event - */ -void UBLibPalette::dragMoveEvent(QDragMoveEvent *pEvent) -{ - pEvent->acceptProposedAction(); -} - -/** - * \brief Process the dropped MIME data - * @param pData as the mime dropped data - */ -void UBLibPalette::processMimeData(const QMimeData *pData) -{ - // Display the different mime types contained in the mime data - QStringList qslFormats = pData->formats(); - for(int i = 0; i < qslFormats.size(); i++) - { - qDebug() << "Dropped element format " << i << " = "<< qslFormats.at(i); - } -} - -void UBLibPalette::mouseMoveEvent(QMouseEvent *event) -{ - if(mCanResize) - { - UBDockPalette::mouseMoveEvent(event); - } - else - { - //qDebug() << "Mouse move event detected!" ; - } -} - -void UBLibPalette::showProperties(UBLibElement *elem) -{ - if(NULL != elem) - { - mActionBar->setButtons(eButtonSet_Properties); - // Show the properties of this object - mProperties->showElement(elem); - mStackedWidget->setCurrentIndex(ID_PROPERTIES); - miCrntStackWidget = ID_PROPERTIES; - } -} - -void UBLibPalette::showFolder() -{ - mActionBar->setButtons(mActionBar->previousButtonSet()); - mStackedWidget->setCurrentIndex(ID_NAVIGATOR); - miCrntStackWidget = ID_NAVIGATOR; -} - -void UBLibPalette::resizeEvent(QResizeEvent *event) -{ - UBDockPalette::resizeEvent(event); - UBSettings::settings()->libPaletteWidth->set(width()); - emit resized(); -} diff --git a/src/gui/UBLibPalette.h b/src/gui/UBLibPalette.h deleted file mode 100644 index ca6d6890..00000000 --- a/src/gui/UBLibPalette.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifndef UBLIBPALETTE_H -#define UBLIBPALETTE_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "UBDockPalette.h" -#include "UBLibNavigatorWidget.h" -#include "UBLibItemProperties.h" -#include "UBLibActionBar.h" - -#define ID_NAVIGATOR 0 -#define ID_PROPERTIES 1 - -class UBLibPalette : public UBDockPalette -{ - Q_OBJECT -public: - UBLibPalette(QWidget* parent=0, const char* name="libPalette"); - ~UBLibPalette(); - - UBLibActionBar* actionBar(){return mActionBar;} - -signals: - void resized(); - -protected: - void updateMaxWidth(); - void dragEnterEvent(QDragEnterEvent* pEvent); - void dropEvent(QDropEvent *pEvent); - void dragMoveEvent(QDragMoveEvent* pEvent); - void dragLeaveEvent(QDragLeaveEvent* pEvent); - void mouseMoveEvent(QMouseEvent *event); - void resizeEvent(QResizeEvent *event); - -private slots: - void showProperties(UBLibElement* elem); - void showFolder(); - -private: - void processMimeData(const QMimeData* pData); - - /** The layout */ - QVBoxLayout* mLayout; - /** The stacked layout */ - QStackedWidget* mStackedWidget; - /** The Navigator widget */ - UBLibNavigatorWidget* mNavigator; - /** The Properties widget */ - UBLibItemProperties* mProperties; - /** UBLibActionBar */ - UBLibActionBar* mActionBar; - /** The current stack widget index*/ - int miCrntStackWidget; -}; - -#endif // UBLIBPALETTE_H diff --git a/src/gui/UBLibWidget.h b/src/gui/UBLibWidget.h index 09896ae4..644bd93f 100644 --- a/src/gui/UBLibWidget.h +++ b/src/gui/UBLibWidget.h @@ -42,6 +42,7 @@ public: ~UBLibWidget(); UBLibActionBar* actionBar(){return mActionBar;} + UBLibNavigatorWidget* libNavigator() {return mNavigator;}; signals: void resized(); diff --git a/src/gui/UBLibraryWidget.cpp b/src/gui/UBLibraryWidget.cpp index f887568b..d66f0b2c 100644 --- a/src/gui/UBLibraryWidget.cpp +++ b/src/gui/UBLibraryWidget.cpp @@ -12,573 +12,569 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#include -#include - -#include "UBLibraryWidget.h" -#include "core/UBSettings.h" -#include "core/UBSetting.h" -#include "core/UBApplication.h" - -#include "board/UBBoardController.h" -#include "board/UBLibraryController.h" - -#include "core/memcheck.h" - -/** - * \brief Constructor - * @param parent as the parent widget - * @param name as the widget object name - */ -UBLibraryWidget::UBLibraryWidget(QWidget *parent, const char *name):UBThumbnailWidget(parent) - , chainedElements(NULL) - , mpCrntDir(NULL) - , mpCrntElem(NULL) - , mCrntPath("/") -{ - setObjectName(name); - setSpacing(5); - setStyleSheet(QString("background: #EEEEEE; border-radius : 10px; border : 2px solid #999999;")); -} - -/** - * \brief Destructor - */ -UBLibraryWidget::~UBLibraryWidget() -{ -// if(NULL != chainedElements) -// { -// delete chainedElements; -// chainedElements = NULL; -// } -// if(NULL != mpCrntDir) -// { -// delete mpCrntDir; -// mpCrntDir = NULL; -// } -// if(NULL != mpCrntElem) -// { -// delete mpCrntElem; -// mpCrntElem = NULL; -// } -} - -/** - * \brief Initialize the widget content - */ -void UBLibraryWidget::init() -{ - setAcceptDrops(true); - mpCrntElem = new UBLibElement(); - mpCrntElem->setThumbnail(new QImage(":images/libpalette/home.png")); - chainedElements = new UBChainedLibElement(mpCrntElem); - QList qlElems = libraryController()->getContent(mpCrntElem); - mCurrentElems = qlElems; - - setCurrentElemsAndRefresh(chainedElements); - - connect(this, SIGNAL(mouseClick(QGraphicsItem*,int)), this, SLOT(onItemClicked(QGraphicsItem*,int))); - connect(this, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); -} - -/** - * \brief Refresh the view - */ -void UBLibraryWidget::refreshView() -{ - // Clear the view - mItems.clear(); - mLabels.clear(); - mItemsPaths.clear(); - mGraphicItems.clear(); - - // Generate the graphics items - generateItems(); - - // Set the new items - setGraphicsItems(mGraphicItems, mItemsPaths, mLabels); - - // Refresh the view - refreshScene(); - - emit navigBarUpdate(mpCrntElem); - - bool bFavorite = false; - if(NULL != mpCrntDir && libraryController()->favoritePath() == mpCrntDir->path().toLocalFile()) - { - bFavorite = true; - } - emit favoritesEntered(bFavorite); -} - -/** - * \brief Generate the graphic items related to the current directory - */ -void UBLibraryWidget::generateItems() -{ - for(int i = 0; i < mCurrentElems.size(); i++) - { - UBLibElement* pElem = mCurrentElems.at(i); - mLabels << pElem->name(); - mItemsPaths << pElem->path(); - QGraphicsPixmapItem *pixmapItem = new UBThumbnailPixmap(QPixmap::fromImage(*pElem->thumbnail())); - mGraphicItems << pixmapItem; - } -} - -/** - * \brief Handles the click on an item - * @param item as the clicked item - * @param index as the given index - */ -void UBLibraryWidget::onItemClicked(QGraphicsItem *item, int index) -{ - Q_UNUSED(index); - if(NULL != item) - { - int iItem = mGraphicItems.indexOf(item); - if(0 <= iItem) - { - UBLibElement* pElem = mCurrentElems.at(iItem); - if(NULL != pElem) - { - mpCrntElem = pElem; - if(eUBLibElementType_Folder == pElem->type() || - eUBLibElementType_VirtualFolder == pElem->type()) - { - // Add the clicked element to the end of the elements list - // (at this level, the user can only go down in the path) - UBChainedLibElement* pNextElem = new UBChainedLibElement(pElem); - appendChainedElement(pNextElem, chainedElements); - - mpCrntDir = pElem; - // Display the content of the folder - QList qlElems = libraryController()->getContent(pElem); - mCurrentElems = qlElems; - refreshView(); - } - else - { - // Display the properties view - emit propertiesRequested(pElem); - } - } - } - } -} - -/** - * \brief Append the given element to the given chain - * @param element as the element to append - * @param toElem as the given chain - */ -void UBLibraryWidget::appendChainedElement(UBChainedLibElement *element, UBChainedLibElement *toElem) -{ - if(NULL != toElem) - { - if(NULL != toElem->nextElement()) - { - appendChainedElement(element, toElem->nextElement()); - } - else - { - toElem->setNextElement(element); - } - } -} - -/** - * \brief Set the current element and refresh the scene - * @param elem as the current element - */ -void UBLibraryWidget::setCurrentElemsAndRefresh(UBChainedLibElement *elem) -{ - if(NULL != elem) - { - UBLibElement* pLibElem = elem->element(); - if(NULL != pLibElem) - { - if(eUBLibElementType_Item != pLibElem->type()) - { - QList qlElements = libraryController()->getContent(pLibElem); - mCurrentElems = qlElements; - mpCrntElem = pLibElem; - refreshView(); - mpCrntDir = pLibElem; - bool bFavorite = false; - if(NULL != mpCrntDir && libraryController()->favoritePath() == mpCrntDir->path().toLocalFile()) - { - bFavorite = true; - } - emit favoritesEntered(bFavorite); - } - } - } -} - -/** - * \brief Handles the selection changed event - */ -void UBLibraryWidget::onSelectionChanged() -{ - // Get the selected items - QList qlSelectedItems; - QList qlGI = selectedItems(); - - bCanDrag = true; - foreach(QGraphicsItem* it, qlGI) - { - int itIndex = mGraphicItems.indexOf(it); - if(0 <= itIndex) - { - UBLibElement* pElem = mCurrentElems.at(itIndex); - if(NULL != pElem) - { - if(eUBLibElementType_Category != pElem->type() && - eUBLibElementType_VirtualFolder != pElem->type()) - { - qlSelectedItems << pElem; - } - - if(!pElem->isMoveable()) - { - bCanDrag = false; - } - } - } - } - - // Check if we are in the trash folder - bool bInTrash = false; - if(NULL != mpCrntDir) - { - if("Trash" == mpCrntDir->name()) - { - bInTrash = true; - } - } - - // Send the signal with these items - emit itemsSelected(qlSelectedItems, bInTrash); -} - -/** - * \brief Handle the delete done event - */ -void UBLibraryWidget::onRefreshCurrentFolder() -{ - // Refresh the current view - mCurrentElems = libraryController()->getContent(mpCrntDir); - refreshView(); -} - -/** - * \brief Handles the drag enter event - * @param event as the drag enter event - */ -void UBLibraryWidget::dragEnterEvent(QDragEnterEvent *event) -{ - event->acceptProposedAction(); -} - -/** - * \brief Handles the drag move event - * @param event as the drag move event - */ -void UBLibraryWidget::dragMoveEvent(QDragMoveEvent *event) -{ - UBLibElement* pElem = elementAt(event->pos()); - if(NULL != pElem) - { - // We can only drop an item into a folder - if(eUBLibElementType_Folder == pElem->type() || - eUBLibElementType_VirtualFolder == pElem->type()) - { - event->acceptProposedAction(); - } - } -} - -void UBLibraryWidget::onDropMe(const QMimeData *_data) -{ - Q_UNUSED(_data); -} - -/** - * \brief Handles the drop event - * @param event as the drop event - */ -void UBLibraryWidget::dropEvent(QDropEvent *event) -{ - const QMimeData* pMimeData = event->mimeData(); - if(event->source() == this) - { - event->accept(); - - // Get the destination item - UBLibElement* pElem = elementAt(event->pos()); - if(NULL != pElem) - { - if(eUBLibElementType_Folder == pElem->type()) - { - // The drag comes from this application, we have now to get the list of UBLibElements* - QList qlDroppedElems; - - foreach(QUrl url, pMimeData->urls()) - { - qlDroppedElems << url.toString(); - } - - if(!qlDroppedElems.empty()) - onElementsDropped(qlDroppedElems, pElem); - } - } - } - else - { - bool bDropAccepted = false; - if (pMimeData->hasImage()) - { - qDebug() << "hasImage"; - QImage image = qvariant_cast(pMimeData->imageData()); - libraryController()->importImageOnLibrary(image); - bDropAccepted = true; - } - else if (pMimeData->hasHtml()) - { - qDebug() << "hasHtml Unsupported yet"; - } - else if (pMimeData->hasText()) - { - // On linux external dragged element are considered as text; - qDebug() << "hasText: " << pMimeData->text(); - QString filePath = QUrl(pMimeData->text()).toLocalFile(); - libraryController()->importItemOnLibrary(filePath); - bDropAccepted = true; - } - else if (pMimeData->hasUrls()) - { - qDebug() << "hasUrls"; - QList urlList = pMimeData->urls(); - for (int i = 0; i < urlList.size() && i < 32; ++i) - { - QString filePath = QUrl(urlList.at(i).path()).toLocalFile(); - libraryController()->importItemOnLibrary(filePath); - bDropAccepted = true; - } - } - else - { - qWarning() << "Cannot import data"; - } - - if(bDropAccepted) - { - onRefreshCurrentFolder(); - event->accept(); - } - else - { - event->ignore(); - } - } -} - -/** - * \brief Get the element at the given position - * @param p as the given position - * @return a pointer on the related element - */ -UBLibElement* UBLibraryWidget::elementAt(QPoint p) -{ - QGraphicsItem* pItem = itemAt(p); - if(NULL != pItem) - { - int iItem = mGraphicItems.indexOf(pItem); - if(-1 != iItem) - { - return mCurrentElems.at(iItem); - } - } - - // If no element is found, return NULL - return NULL; -} - - -/** - * \brief Get the element from the given name - * @param name as the given element name - * @return the UBLibElement related to the given name - */ -UBLibElement* UBLibraryWidget::elementFromFilePath(const QString &filePath) -{ - UBLibElement* pElem = NULL; - - foreach(UBLibElement* elem, mCurrentElems) - { - if(elem->path().toLocalFile() == QUrl(filePath).toLocalFile()) - { - return elem; - } - - } - - return pElem; -} - -/** - * \brief Get a pointer on the library controller - * @return a pointer on the library controller - */ -UBLibraryController* UBLibraryWidget::libraryController() -{ - return UBApplication::boardController->libraryController(); -} - -/** - * \brief Update the thumbnails size - * @param newSize as the thumbnail size - */ -void UBLibraryWidget::updateThumbnailsSize(int newSize) -{ - setThumbnailWidth(newSize); - refreshView(); -} - -/** - * \brief Handles the element dropped event - * @param elements as the list of dropped elements - * @param target as the drop target - */ -void UBLibraryWidget::onElementsDropped(QList elements, UBLibElement *target) -{ - if(target != mpCrntDir) - { - QList qlElements; - - foreach(QString qsElem, elements) - qlElements << elementFromFilePath(qsElem); - - libraryController()->moveContent(qlElements, target); - mCurrentElems = libraryController()->getContent(mpCrntDir); - refreshView(); - } -} - -/** - * \brief Search the element related to the given text - * @param elem as the searched element name - */ -void UBLibraryWidget::onSearchElement(QString elem) -{ - // Store the original list of items - mOrigCurrentElems = libraryController()->getContent(mpCrntDir); - - // Build the filtered list - mCurrentElems.clear(); - if(elem.isEmpty()) - { - mCurrentElems = mOrigCurrentElems; - } - else - { - foreach(UBLibElement* ubLibElem, mOrigCurrentElems) - { - if(ubLibElem->name().toLower().contains(elem.toLower())) - { - mCurrentElems << ubLibElem; - } - } - } - refreshView(); -} - -/** - * \brief Create a new folder - */ -void UBLibraryWidget::onNewFolderToCreate() -{ - // Create here a dialog asking the name of the new folder - UBNewFolderDlg dlg; - if(QDialog::Accepted == dlg.exec()) - { - libraryController()->createNewFolder(dlg.folderName(), mpCrntElem); - onRefreshCurrentFolder(); - } -} - -/** - * \brief Constructor - * @param parent as the parent widget - * @param name as the object name - */ -UBNewFolderDlg::UBNewFolderDlg(QWidget *parent, const char *name):QDialog(parent) - , mpLabel(NULL) - , mpLineEdit(NULL) - , mpButtons(NULL) - , mpLayout(NULL) - , mpHLayout(NULL) -{ - setObjectName(name); - setWindowTitle(tr("Add new folder")); - - mpLabel = new QLabel(tr("New Folder name:"),this); - mpLineEdit = new QLineEdit(this); - mpButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); - mpLayout = new QVBoxLayout(this); - mpHLayout = new QHBoxLayout(this); - - setLayout(mpLayout); - mpLayout->addLayout(mpHLayout, 0); - mpHLayout->addWidget(mpLabel, 0); - mpHLayout->addWidget(mpLineEdit, 1); - mpLayout->addWidget(mpButtons); - - connect(mpButtons->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(accept())); - connect(mpButtons->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject())); - - setMaximumHeight(100); - setMinimumHeight(100); -} - -/** - * \brief Destructor - */ -UBNewFolderDlg::~UBNewFolderDlg() -{ - if(NULL != mpButtons) - { - delete mpButtons; - mpButtons = NULL; - } - if(NULL != mpLineEdit) - { - delete mpLineEdit; - mpLineEdit = NULL; - } - if(NULL != mpLabel) - { - delete mpLabel; - mpLabel = NULL; - } - if(NULL != mpHLayout) - { - delete mpHLayout; - mpHLayout = NULL; - } - if(NULL != mpLayout) - { - delete mpLayout; - mpLayout = NULL; - } -} - -/** - * \brief Get the folder name - * @return the entered folder name - */ -QString UBNewFolderDlg::folderName() -{ - return mpLineEdit->text(); -} +#include +#include + +#include "UBLibraryWidget.h" +#include "core/UBSettings.h" +#include "core/UBSetting.h" +#include "core/UBApplication.h" + +#include "board/UBBoardController.h" +#include "board/UBLibraryController.h" + +#include "core/memcheck.h" + +/** + * \brief Constructor + * @param parent as the parent widget + * @param name as the widget object name + */ +UBLibraryWidget::UBLibraryWidget(QWidget *parent, const char *name):UBThumbnailWidget(parent) + , chainedElements(NULL) + , mpCrntDir(NULL) + , mpCrntElem(NULL) +{ + setObjectName(name); + setSpacing(5); + setStyleSheet(QString("background: #EEEEEE; border-radius : 10px; border : 2px solid #999999;")); + mLibraryController = new UBLibraryController(parentWidget()); +} + +/** + * \brief Destructor + */ +UBLibraryWidget::~UBLibraryWidget() +{ + if(mLibraryController){ + delete mLibraryController; + mLibraryController = NULL; + } + +// if(NULL != chainedElements) +// { +// delete chainedElements; +// chainedElements = NULL; +// } + if(NULL != mpCrntDir) + { + delete mpCrntDir; + mpCrntDir = NULL; + } + if(NULL != mpCrntElem) + { + delete mpCrntElem; + mpCrntElem = NULL; + } +} + +/** + * \brief Initialize the widget content + */ +void UBLibraryWidget::init() +{ + setAcceptDrops(true); + mpCrntElem = new UBLibElement(); + mpCrntElem->setThumbnail(QImage(":images/libpalette/home.png")); + chainedElements = new UBChainedLibElement(mpCrntElem); + QList qlElems = mLibraryController->getContent(mpCrntElem); + mCurrentElems = qlElems; + + setCurrentElemsAndRefresh(chainedElements); + + connect(this, SIGNAL(mouseClick(QGraphicsItem*,int)), this, SLOT(onItemClicked(QGraphicsItem*,int))); + connect(this, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); +} + +/** + * \brief Refresh the view + */ +void UBLibraryWidget::refreshView() +{ + // Clear the view + mItems.clear(); + mLabels.clear(); + mItemsPaths.clear(); + mGraphicItems.clear(); + + // Generate the graphics items + generateItems(); + + // Set the new items + setGraphicsItems(mGraphicItems, mItemsPaths, mLabels); + + // Refresh the view + refreshScene(); + + emit navigBarUpdate(mpCrntElem); + + bool bFavorite = false; + if(NULL != mpCrntDir && mLibraryController->favoritePath() == mpCrntDir->path().toLocalFile()) + { + bFavorite = true; + } + emit favoritesEntered(bFavorite); +} + +/** + * \brief Generate the graphic items related to the current directory + */ +void UBLibraryWidget::generateItems() +{ + for(int i = 0; i < mCurrentElems.size(); i++) + { + UBLibElement* pElem = mCurrentElems.at(i); + mLabels << pElem->name(); + mItemsPaths << pElem->path(); + QGraphicsPixmapItem *pixmapItem = new UBThumbnailPixmap(QPixmap::fromImage(*pElem->thumbnail())); + mGraphicItems << pixmapItem; + } +} + +/** + * \brief Handles the click on an item + * @param item as the clicked item + * @param index as the given index + */ +void UBLibraryWidget::onItemClicked(QGraphicsItem *item, int index) +{ + Q_UNUSED(index); + if(NULL != item) + { + int iItem = mGraphicItems.indexOf(item); + if(0 <= iItem) + { + UBLibElement* pElem = mCurrentElems.at(iItem); + if(NULL != pElem) + { + delete mpCrntElem; + mpCrntElem = new UBLibElement(pElem); + if(eUBLibElementType_Folder == pElem->type() || eUBLibElementType_VirtualFolder == pElem->type()) { + // Add the clicked element to the end of the elements list + // (at this level, the user can only go down in the path) + UBChainedLibElement* pNextElem = new UBChainedLibElement(pElem); + appendChainedElement(pNextElem, chainedElements); + delete mpCrntDir; + mpCrntDir = new UBLibElement(pElem); + // Display the content of the folder + QList qlElems = mLibraryController->getContent(mpCrntDir); + mCurrentElems = qlElems; + refreshView(); + } + else + { + // Display the properties view + emit propertiesRequested(pElem); + } + } + } + } +} + +/** + * \brief Append the given element to the given chain + * @param element as the element to append + * @param toElem as the given chain + */ +void UBLibraryWidget::appendChainedElement(UBChainedLibElement *element, UBChainedLibElement *toElem) +{ + if(NULL != toElem) + { + if(NULL != toElem->nextElement()) + { + appendChainedElement(element, toElem->nextElement()); + } + else + { + toElem->setNextElement(element); + } + } +} + +/** + * \brief Set the current element and refresh the scene + * @param elem as the current element + */ +void UBLibraryWidget::setCurrentElemsAndRefresh(UBChainedLibElement *elem) +{ + if(NULL != elem) + { + UBLibElement* pLibElem = elem->element(); + if(NULL != pLibElem) + { + if(eUBLibElementType_Item != pLibElem->type()) + { + QList qlElements = mLibraryController->getContent(pLibElem); + mCurrentElems = qlElements; + delete mpCrntElem; + mpCrntElem = new UBLibElement(pLibElem); + refreshView(); + delete mpCrntDir; + mpCrntDir = new UBLibElement(pLibElem); + bool bFavorite = false; + if(NULL != mpCrntDir && mLibraryController->favoritePath() == mpCrntDir->path().toLocalFile()) + { + bFavorite = true; + } + emit favoritesEntered(bFavorite); + } + } + } +} + +/** + * \brief Handles the selection changed event + */ +void UBLibraryWidget::onSelectionChanged() +{ + // Get the selected items + QList qlSelectedItems; + QList qlGI = selectedItems(); + + bCanDrag = true; + foreach(QGraphicsItem* it, qlGI) + { + int itIndex = mGraphicItems.indexOf(it); + if(0 <= itIndex) + { + UBLibElement* pElem = mCurrentElems.at(itIndex); + if(NULL != pElem) + { + if(eUBLibElementType_Category != pElem->type() && eUBLibElementType_VirtualFolder != pElem->type()) { + qlSelectedItems << pElem; + } + + if(!pElem->isMoveable()) + { + bCanDrag = false; + } + } + } + } + + // Check if we are in the trash folder + bool bInTrash = false; + if(NULL != mpCrntDir) + { + if("Trash" == mpCrntDir->name()) + { + bInTrash = true; + } + } + + // Send the signal with these items + emit itemsSelected(qlSelectedItems, bInTrash); +} + +/** + * \brief Handle the delete done event + */ +void UBLibraryWidget::onRefreshCurrentFolder() +{ + // Refresh the current view + mCurrentElems = mLibraryController->getContent(mpCrntDir); + refreshView(); +} + +/** + * \brief Handles the drag enter event + * @param event as the drag enter event + */ +void UBLibraryWidget::dragEnterEvent(QDragEnterEvent *event) +{ + event->acceptProposedAction(); +} + +/** + * \brief Handles the drag move event + * @param event as the drag move event + */ +void UBLibraryWidget::dragMoveEvent(QDragMoveEvent *event) +{ + UBLibElement* pElem = elementAt(event->pos()); + if(NULL != pElem) + { + // We can only drop an item into a folder + if(eUBLibElementType_Folder == pElem->type() || + eUBLibElementType_VirtualFolder == pElem->type()) + { + event->acceptProposedAction(); + } + } +} + +void UBLibraryWidget::onDropMe(const QMimeData *_data) +{ + Q_UNUSED(_data); +} + +/** + * \brief Handles the drop event + * @param event as the drop event + */ +void UBLibraryWidget::dropEvent(QDropEvent *event) +{ + const QMimeData* pMimeData = event->mimeData(); + if(event->source() == this) + { + event->accept(); + + // Get the destination item + UBLibElement* pElem = elementAt(event->pos()); + if(NULL != pElem) + { + if(eUBLibElementType_Folder == pElem->type()) + { + // The drag comes from this application, we have now to get the list of UBLibElements* + QList qlDroppedElems; + + foreach(QUrl url, pMimeData->urls()) + { + qlDroppedElems << url.toString(); + } + + if(!qlDroppedElems.empty()) + onElementsDropped(qlDroppedElems, pElem); + } + } + } + else + { + bool bDropAccepted = false; + if (pMimeData->hasImage()) + { + qDebug() << "hasImage"; + QImage image = qvariant_cast(pMimeData->imageData()); + mLibraryController->importImageOnLibrary(image); + bDropAccepted = true; + } + else if (pMimeData->hasHtml()) + { + qDebug() << "hasHtml Unsupported yet"; + } + else if (pMimeData->hasText()) + { + // On linux external dragged element are considered as text; + qDebug() << "hasText: " << pMimeData->text(); + QString filePath = QUrl(pMimeData->text()).toLocalFile(); + mLibraryController->importItemOnLibrary(filePath); + bDropAccepted = true; + } + else if (pMimeData->hasUrls()) + { + qDebug() << "hasUrls"; + QList urlList = pMimeData->urls(); + for (int i = 0; i < urlList.size() && i < 32; ++i) + { + QString filePath = QUrl(urlList.at(i).path()).toLocalFile(); + mLibraryController->importItemOnLibrary(filePath); + bDropAccepted = true; + } + } + else + { + qWarning() << "Cannot import data"; + } + + if(bDropAccepted) + { + onRefreshCurrentFolder(); + event->accept(); + } + else + { + event->ignore(); + } + } +} + +/** + * \brief Get the element at the given position + * @param p as the given position + * @return a pointer on the related element + */ +UBLibElement* UBLibraryWidget::elementAt(QPoint p) +{ + QGraphicsItem* pItem = itemAt(p); + if(NULL != pItem) + { + int iItem = mGraphicItems.indexOf(pItem); + if(-1 != iItem) + { + return mCurrentElems.at(iItem); + } + } + + // If no element is found, return NULL + return NULL; +} + + +/** + * \brief Get the element from the given name + * @param name as the given element name + * @return the UBLibElement related to the given name + */ +UBLibElement* UBLibraryWidget::elementFromFilePath(const QString &filePath) +{ + UBLibElement* pElem = NULL; + + foreach(UBLibElement* elem, mCurrentElems) + { + if(elem->path().toLocalFile() == QUrl(filePath).toLocalFile()) + { + return elem; + } + + } + + return pElem; +} + + +/** + * \brief Update the thumbnails size + * @param newSize as the thumbnail size + */ +void UBLibraryWidget::updateThumbnailsSize(int newSize) +{ + setThumbnailWidth(newSize); + refreshView(); +} + +/** + * \brief Handles the element dropped event + * @param elements as the list of dropped elements + * @param target as the drop target + */ +void UBLibraryWidget::onElementsDropped(QList elements, UBLibElement *target) +{ + if(target != mpCrntDir) + { + QList qlElements; + + foreach(QString qsElem, elements) + qlElements << elementFromFilePath(qsElem); + + mLibraryController->moveContent(qlElements, target); + mCurrentElems = mLibraryController->getContent(mpCrntDir); + refreshView(); + } +} + +/** + * \brief Search the element related to the given text + * @param elem as the searched element name + */ +void UBLibraryWidget::onSearchElement(QString elem) +{ + // Store the original list of items + mOrigCurrentElems = mLibraryController->getContent(mpCrntDir); + + // Build the filtered list + mCurrentElems.clear(); + if(elem.isEmpty()) + { + mCurrentElems = mOrigCurrentElems; + } + else + { + foreach(UBLibElement* ubLibElem, mOrigCurrentElems) + { + if(ubLibElem->name().toLower().contains(elem.toLower())) + { + mCurrentElems << ubLibElem; + } + } + } + refreshView(); +} + +/** + * \brief Create a new folder + */ +void UBLibraryWidget::onNewFolderToCreate() +{ + // Create here a dialog asking the name of the new folder + UBNewFolderDlg dlg; + if(QDialog::Accepted == dlg.exec()) + { + mLibraryController->createNewFolder(dlg.folderName(), mpCrntElem); + onRefreshCurrentFolder(); + } +} + +/** + * \brief Constructor + * @param parent as the parent widget + * @param name as the object name + */ +UBNewFolderDlg::UBNewFolderDlg(QWidget *parent, const char *name):QDialog(parent) + , mpLabel(NULL) + , mpLineEdit(NULL) + , mpButtons(NULL) + , mpLayout(NULL) + , mpHLayout(NULL) +{ + setObjectName(name); + setWindowTitle(tr("Add new folder")); + + mpLabel = new QLabel(tr("New Folder name:"),this); + mpLineEdit = new QLineEdit(this); + mpButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); + mpLayout = new QVBoxLayout(this); + mpHLayout = new QHBoxLayout(this); + + setLayout(mpLayout); + mpLayout->addLayout(mpHLayout, 0); + mpHLayout->addWidget(mpLabel, 0); + mpHLayout->addWidget(mpLineEdit, 1); + mpLayout->addWidget(mpButtons); + + connect(mpButtons->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(accept())); + connect(mpButtons->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject())); + + setMaximumHeight(100); + setMinimumHeight(100); +} + +/** + * \brief Destructor + */ +UBNewFolderDlg::~UBNewFolderDlg() +{ + if(NULL != mpButtons) + { + delete mpButtons; + mpButtons = NULL; + } + if(NULL != mpLineEdit) + { + delete mpLineEdit; + mpLineEdit = NULL; + } + if(NULL != mpLabel) + { + delete mpLabel; + mpLabel = NULL; + } + if(NULL != mpHLayout) + { + delete mpHLayout; + mpHLayout = NULL; + } + if(NULL != mpLayout) + { + delete mpLayout; + mpLayout = NULL; + } +} + +/** + * \brief Get the folder name + * @return the entered folder name + */ +QString UBNewFolderDlg::folderName() +{ + return mpLineEdit->text(); +} diff --git a/src/gui/UBLibraryWidget.h b/src/gui/UBLibraryWidget.h index 42f9aa32..e6fd0fc7 100644 --- a/src/gui/UBLibraryWidget.h +++ b/src/gui/UBLibraryWidget.h @@ -29,7 +29,10 @@ #include #include "UBThumbnailWidget.h" -#include "board/UBLibraryController.h" + +class UBLibraryController; +class UBChainedLibElement; +class UBLibElement; class UBLibraryWidget : public UBThumbnailWidget { @@ -44,6 +47,8 @@ public: void updateThumbnailsSize(int newSize); void init(); + UBLibraryController* libraryController() {return mLibraryController;}; + public slots: void onRefreshCurrentFolder(); void onElementsDropped(QList elements, UBLibElement* target); @@ -71,14 +76,13 @@ private: void appendChainedElement(UBChainedLibElement* element, UBChainedLibElement* toElem); UBLibElement* elementAt(QPoint p); UBLibElement* elementFromFilePath(const QString& filePath); - UBLibraryController* libraryController(); + UBLibraryController* mLibraryController; UBLibElement* mpCrntDir; UBLibElement* mpCrntElem; QList mCurrentElems; QList mOrigCurrentElems; QList mItems; - QString mCrntPath; }; diff --git a/src/gui/gui.pri b/src/gui/gui.pri index 0c17c86c..6d933785 100644 --- a/src/gui/gui.pri +++ b/src/gui/gui.pri @@ -29,7 +29,6 @@ HEADERS += src/gui/UBThumbnailView.h \ src/gui/UBFavoriteToolPalette.h \ src/gui/UBKeyboardPalette.h \ src/gui/UBNavigatorPalette.h \ - src/gui/UBLibPalette.h \ src/gui/UBDocumentNavigator.h \ src/gui/UBDockPalette.h \ src/gui/UBPropertyPalette.h \ @@ -76,7 +75,6 @@ SOURCES += src/gui/UBThumbnailView.cpp \ src/gui/UBFavoriteToolPalette.cpp \ src/gui/UBKeyboardPalette.cpp \ src/gui/UBNavigatorPalette.cpp \ - src/gui/UBLibPalette.cpp \ src/gui/UBDocumentNavigator.cpp \ src/gui/UBDockPalette.cpp \ src/gui/UBPropertyPalette.cpp \