From 62a82e1daa47b42e8a21e83b49c3caa23e6d4c58 Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Wed, 2 May 2012 18:43:59 +0300 Subject: [PATCH] fixed deleting default widget --- src/board/UBFeaturesController.cpp | 10 ++++++++++ src/board/UBFeaturesController.h | 2 ++ src/gui/UBFeaturesActionBar.cpp | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp index cf2c6204..5ab469a4 100644 --- a/src/board/UBFeaturesController.cpp +++ b/src/board/UBFeaturesController.cpp @@ -40,6 +40,10 @@ bool UBFeature::isFolder() const || elementType == FEATURE_FOLDER; } +bool UBFeature::isDeletable()const +{ + return elementType == FEATURE_ITEM; +} UBFeaturesController::UBFeaturesController(QWidget *pParentWidget) : QObject(pParentWidget), @@ -281,6 +285,12 @@ QPixmap UBFeaturesController::thumbnailForFile(const QString &path) return thumb; } +bool UBFeaturesController::isDeletable( const QUrl &url ) +{ + UBFeatureElementType type = fileTypeFromUrl( fileNameFromUrl(url) ); + return type == FEATURE_ITEM; +} + QPixmap UBFeaturesController::createThumbnail(const QString &path) { QString thumbnailPath = UBFileSystemUtils::thumbnailPath(path); diff --git a/src/board/UBFeaturesController.h b/src/board/UBFeaturesController.h index 0144be39..914b6a7d 100644 --- a/src/board/UBFeaturesController.h +++ b/src/board/UBFeaturesController.h @@ -37,6 +37,7 @@ public: QString getVirtualPath() const { return virtualPath + "/" + mName; } UBFeatureElementType getType() const { return elementType; } bool isFolder() const; + bool isDeletable() const; bool operator ==( const UBFeature &f )const; bool operator !=( const UBFeature &f )const; private: @@ -74,6 +75,7 @@ public: static QString fileNameFromUrl( const QUrl &url ); static QPixmap thumbnailForFile( const QString &path ); + static bool isDeletable( const QUrl &url ); private: void initDirectoryTree(); void fileSystemScan(const QString &currPath, const QString & currVirtualPath); diff --git a/src/gui/UBFeaturesActionBar.cpp b/src/gui/UBFeaturesActionBar.cpp index b3afc99a..09b7af82 100644 --- a/src/gui/UBFeaturesActionBar.cpp +++ b/src/gui/UBFeaturesActionBar.cpp @@ -179,7 +179,9 @@ void UBFeaturesActionBar::dragMoveEvent(QDragMoveEvent *event) void UBFeaturesActionBar::dragEnterEvent( QDragEnterEvent *event ) { if (event->mimeData()->hasFormat("text/uri-list")) + { event->acceptProposedAction(); + } } void UBFeaturesActionBar::dropEvent( QDropEvent *event ) @@ -187,6 +189,12 @@ void UBFeaturesActionBar::dropEvent( QDropEvent *event ) QWidget *dest = childAt( event->pos() ); if ( dest == mpDeleteBtn ) { + QList urls = event->mimeData()->urls(); + foreach ( QUrl url, urls ) + { + if ( !UBFeaturesController::isDeletable( url ) ) + return; + } event->setDropAction( Qt::MoveAction ); event->accept(); emit deleteElements( *event->mimeData() );