From 704eb9264581324227a5c47d76b31837cc32ce38 Mon Sep 17 00:00:00 2001 From: shibakaneki Date: Tue, 26 Apr 2011 10:45:59 +0200 Subject: [PATCH] Deactivated the drag ability on non-dragable items --- src/board/UBLibraryController.cpp | 15 ++++++++++++- src/board/UBLibraryController.h | 3 +++ src/gui/UBLibraryWidget.cpp | 6 +++++ src/gui/UBThumbnailWidget.cpp | 37 ++++++++++++++++++------------- src/gui/UBThumbnailWidget.h | 1 + 5 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/board/UBLibraryController.cpp b/src/board/UBLibraryController.cpp index e8d5e0eb..1eec04f6 100644 --- a/src/board/UBLibraryController.cpp +++ b/src/board/UBLibraryController.cpp @@ -221,40 +221,47 @@ QList UBLibraryController::rootCategoriesList() UBLibElement* element = new UBLibElement(eUBLibElementType_Folder, mAudioStandardDirectoryPath, tr("Audios", "Audio category element")); QImage* categoryImage = new QImage(":images/libpalette/AudiosCategory.svg"); element->setThumbnail(categoryImage); + 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->setMoveable(false); categories << element; element = new UBLibElement(eUBLibElementType_VirtualFolder, picturesVirtualPath, tr("Pictures", "Pictures category element")); categoryImage = new QImage(":images/libpalette/PicturesCategory.svg"); element->setThumbnail(categoryImage); + 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->setMoveable(false); categories << element; categoryImage = new QImage(":images/libpalette/ApplicationsCategory.svg"); element = new UBLibElement(eUBLibElementType_VirtualFolder, applicationsVirtualPath, tr("Applications", "Applications category element")); element->setThumbnail(categoryImage); + 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->setMoveable(false); categories << element; categoryImage = new QImage(":images/libpalette/InteractivesCategory.svg"); interactivesCategoryPath = UBSettings::settings()->uniboardGipLibraryDirectory(); element = new UBLibElement(eUBLibElementType_Folder, QUrl::fromLocalFile(interactivesCategoryPath), tr("Interactives", "Interactives category element")); element->setThumbnail(categoryImage); + element->setMoveable(false); categories << element; @@ -2429,7 +2436,8 @@ QString UBLibraryController::favoritePath() UBLibElement::UBLibElement() { mType = eUBLibElementType_Category; - mName = QObject::tr("/Home", "Category list label on nagigation tool bar"); + mName = QObject::tr("/Home", "Category list label on navigation tool bar"); + mbMoveable = false; } @@ -2439,6 +2447,7 @@ UBLibElement::UBLibElement(eUBLibElementType type, const QUrl &path, const QStri mPath = path; mName = name; mInfo = ""; + mbMoveable = true; if (type == eUBLibElementType_Folder) mThumbnail = QImage(":images/libpalette/folder.svg"); @@ -2448,6 +2457,9 @@ UBLibElement::UBLibElement(eUBLibElementType type, const QUrl &path, const QStri if (type == eUBLibElementType_Item) mExtension = QFileInfo(path.toLocalFile()).completeSuffix(); + + if(type == eUBLibElementType_VirtualFolder || type == eUBLibElementType_Category) + mbMoveable = false; } UBLibElement::~UBLibElement() @@ -2483,6 +2495,7 @@ UBLibElement* UBLibElement::trashElement() trashElement = new UBLibElement(eUBLibElementType_Folder, UBSettings::trashLibraryPaletteDirPath(), QObject::tr("Trash", "Pictures category element")); QImage *categoryImage = new QImage(":images/libpalette/TrashCategory.svg"); trashElement->setThumbnail(categoryImage); + trashElement->setMoveable(false); return trashElement; } diff --git a/src/board/UBLibraryController.h b/src/board/UBLibraryController.h index fcff4495..2061d689 100644 --- a/src/board/UBLibraryController.h +++ b/src/board/UBLibraryController.h @@ -46,6 +46,8 @@ public: void setName(QString name){mName = name;} QString extension(){return mExtension;} void setExtension(QString &extension){ mExtension = extension;} + bool isMoveable(){return mbMoveable;} + void setMoveable(bool bState){mbMoveable = bState;} private: eUBLibElementType mType; @@ -54,6 +56,7 @@ private: QString mInfo; QString mName; QString mExtension; + bool mbMoveable; }; class UBChainedLibElement diff --git a/src/gui/UBLibraryWidget.cpp b/src/gui/UBLibraryWidget.cpp index 3b6c5d62..f28239e2 100644 --- a/src/gui/UBLibraryWidget.cpp +++ b/src/gui/UBLibraryWidget.cpp @@ -209,6 +209,7 @@ void UBLibraryWidget::onSelectionChanged() QList qlSelectedItems; QList qlGI = selectedItems(); + bCanDrag = true; foreach(QGraphicsItem* it, qlGI) { int itIndex = mGraphicItems.indexOf(it); @@ -222,6 +223,11 @@ void UBLibraryWidget::onSelectionChanged() { qlSelectedItems << pElem; } + + if(!pElem->isMoveable()) + { + bCanDrag = false; + } } } } diff --git a/src/gui/UBThumbnailWidget.cpp b/src/gui/UBThumbnailWidget.cpp index 4d994f7b..765e99a0 100644 --- a/src/gui/UBThumbnailWidget.cpp +++ b/src/gui/UBThumbnailWidget.cpp @@ -19,6 +19,8 @@ UBThumbnailWidget::UBThumbnailWidget(QWidget* parent) , mSelectionSpan(0) , mLassoRectItem(0) { + // By default, the drag is possible + bCanDrag = true; setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing); setFrameShape(QFrame::NoFrame); @@ -326,30 +328,33 @@ void UBThumbnailWidget::mouseMoveEvent(QMouseEvent *event) if (0 == selectedItems().size()) return; - QDrag *drag = new QDrag(this); - QMimeData *mime = new QMimeData(); + if(bCanDrag) + { + QDrag *drag = new QDrag(this); + QMimeData *mime = new QMimeData(); - if (mMimeType.length() > 0) - mime->setData(mMimeType, QByteArray()); // trick the d&d system to register our own mime type + if (mMimeType.length() > 0) + mime->setData(mMimeType, QByteArray()); // trick the d&d system to register our own mime type - drag->setMimeData(mime); + drag->setMimeData(mime); - QList qlElements; + QList qlElements; - foreach (QGraphicsItem* item, selectedItems()) - { - if (mGraphicItems.contains(item)) + foreach (QGraphicsItem* item, selectedItems()) { - if (mGraphicItems.indexOf(item) <= mItemsPaths.size()){ - qlElements << mItemsPaths.at(mGraphicItems.indexOf(item)); + if (mGraphicItems.contains(item)) + { + if (mGraphicItems.indexOf(item) <= mItemsPaths.size()){ + qlElements << mItemsPaths.at(mGraphicItems.indexOf(item)); + } } } - } - if (qlElements.size() > 0){ - mime->setUrls(qlElements); - drag->setMimeData(mime); - drag->exec(); + if (qlElements.size() > 0){ + mime->setUrls(qlElements); + drag->setMimeData(mime); + drag->exec(); + } } } diff --git a/src/gui/UBThumbnailWidget.h b/src/gui/UBThumbnailWidget.h index 47cf47a3..a5660fc2 100644 --- a/src/gui/UBThumbnailWidget.h +++ b/src/gui/UBThumbnailWidget.h @@ -77,6 +77,7 @@ class UBThumbnailWidget : public QGraphicsView QList mItemsPaths; QStringList mLabels; bool bSelectionInProgress; + bool bCanDrag; private: void selectAll();