From 14e326effe1b5ecf37f97b93535438ed94a82862 Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Wed, 18 Apr 2012 12:51:03 +0300 Subject: [PATCH] Some bugs fixed and more DnD functionality implemented --- src/board/UBFeaturesController.cpp | 37 ++++++++++++++++++++-- src/board/UBFeaturesController.h | 5 +-- src/gui/UBFeaturesWidget.cpp | 50 ++++++++++++++++++++---------- src/gui/UBFeaturesWidget.h | 16 ++++++++-- 4 files changed, 84 insertions(+), 24 deletions(-) diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp index e7609d2a..2175d94f 100644 --- a/src/board/UBFeaturesController.cpp +++ b/src/board/UBFeaturesController.cpp @@ -27,7 +27,7 @@ UBFeature::UBFeature(const QString &url, const QPixmap &icon, const QString &nam UBFeature::UBFeature(const UBFeature &f) { virtualPath = f.getUrl(); - mPath = f.getPath(); + mPath = f.getFullPath(); mThumbnail = f.getThumbnail(); mName = f.getName(); elementType = f.getType(); @@ -110,7 +110,7 @@ void UBFeaturesController::fileSystemScan(const QString & currentPath, const QSt } QString itemName = (fileType != FEATURE_ITEM) ? fileName : fileInfo->completeBaseName(); QPixmap icon = QPixmap(":images/libpalette/soundIcon.svg"); - QString fullFileName = currentPath + "/" + fileName; + QString fullFileName = fileInfo->filePath(); if ( fileType == FEATURE_FOLDER ) { @@ -131,7 +131,7 @@ void UBFeaturesController::fileSystemScan(const QString & currentPath, const QSt icon = QPixmap( thumbnailPath ); else icon = createThumbnail( fullFileName );*/ } - featuresList->push_back( UBFeature( currVirtualPath, icon, fileName, currentPath, fileType ) ); + featuresList->push_back( UBFeature( currVirtualPath, icon, fileName, fullFileName, fileType ) ); if ( fileType == FEATURE_FOLDER ) { @@ -194,7 +194,16 @@ void UBFeaturesController::addItemToPage(const UBFeature &item) UBFeature UBFeaturesController::moveItemToFolder( const QUrl &url, const UBFeature &destination ) { + UBFeature newElement = copyItemToFolder( url, destination ); QString sourcePath = url.toLocalFile(); + QFile::remove( sourcePath ); + QString thumbnailPath = UBFileSystemUtils::thumbnailPath( sourcePath ); + if (thumbnailPath.length() && QFileInfo( thumbnailPath ).exists()) + { + QFile::remove(thumbnailPath); + } + return newElement; + /*QString sourcePath = url.toLocalFile(); Q_ASSERT( QFileInfo( sourcePath ).exists() ); @@ -217,8 +226,30 @@ UBFeature UBFeaturesController::moveItemToFolder( const QUrl &url, const UBFeatu if ( UBFileSystemUtils::mimeTypeFromFileName( newFullPath ).contains("application") ) type = UBFeatureElementType::FEATURE_INTERACTIVE; UBFeature newElement( destVirtualPath, thumb, name, destPath, type ); + return newElement;*/ +} + +UBFeature UBFeaturesController::copyItemToFolder( const QUrl &url, const UBFeature &destination ) +{ + QString sourcePath = url.toLocalFile(); + + Q_ASSERT( QFileInfo( sourcePath ).exists() ); + + QString name = QFileInfo( sourcePath ).fileName(); + QString destPath = destination.getFullPath(); + QString destVirtualPath = destination.getUrl() + "/" + destination.getName(); + QString newFullPath = destPath + "/" + name; + QFile( sourcePath ).copy( newFullPath ); + + QPixmap thumb = thumbnailForFile( newFullPath ); + + UBFeatureElementType type = UBFeatureElementType::FEATURE_ITEM; + if ( UBFileSystemUtils::mimeTypeFromFileName( newFullPath ).contains("application") ) + type = UBFeatureElementType::FEATURE_INTERACTIVE; + UBFeature newElement( destVirtualPath, thumb, name, newFullPath, type ); return newElement; } + /* void UBFeaturesController::addImageToCurrentPage( const QString &path ) { diff --git a/src/board/UBFeaturesController.h b/src/board/UBFeaturesController.h index cde23347..e08eff53 100644 --- a/src/board/UBFeaturesController.h +++ b/src/board/UBFeaturesController.h @@ -31,8 +31,8 @@ public: return mThumbnail; }; QString getUrl() const { return virtualPath; }; - QString getPath() const { return mPath; }; - QString getFullPath() const { return mPath + "/" + mName; }; + //QString getPath() const { return mPath; }; + QString getFullPath() const { return mPath; }; UBFeatureElementType getType() const { return elementType; } ; private: QString virtualPath; @@ -58,6 +58,7 @@ public: void addItemToPage(const UBFeature &item); static QPixmap thumbnailForFile( const QString &path ); static UBFeature moveItemToFolder( const QUrl &url, const UBFeature &destination ); + static UBFeature copyItemToFolder( const QUrl &url, const UBFeature &destination ); private: void initDirectoryTree(); void fileSystemScan(const QString &currPath, const QString & currVirtualPath); diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index e8f0722d..12215fcd 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -28,8 +28,8 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale featuresModel = new UBFeaturesModel(this); featuresModel->setFeaturesList( controller->getFeatures() ); featuresModel->setSupportedDragActions( Qt::CopyAction | Qt::MoveAction ); - featuresListView = new QListView(this); - pathListView = new QListView(this); + featuresListView = new UBFeaturesListView(this); + pathListView = new UBFeaturesListView(this); featuresProxyModel = new UBFeaturesProxyModel(this); @@ -69,7 +69,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale pathListView->setSelectionMode( QAbstractItemView::NoSelection ); pathListView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); pathListView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); - pathListView->setMovement( QListView::Static ); + //pathListView->setMovement( QListView::Static ); pathListView->setDragDropMode( QAbstractItemView::DragDrop ); pathScene = new QGraphicsScene(this); @@ -192,6 +192,21 @@ UBFeaturesWidget::~UBFeaturesWidget() { } +UBFeaturesListView::UBFeaturesListView( QWidget* parent, const char* name ) : QListView(parent) +{ + setObjectName(name); +} + +void UBFeaturesListView::dropEvent( QDropEvent *event ) +{ + if( event->source() || dynamic_cast( event->source() ) ) + { + event->setDropAction( Qt::MoveAction ); + } + QListView::dropEvent( event ); +} + + UBFeatureProperties::UBFeatureProperties( QWidget *parent, const char *name ) : QWidget(parent) , mpLayout(NULL) , mpButtonLayout(NULL) @@ -432,18 +447,6 @@ QMimeData* UBFeaturesModel::mimeData(const QModelIndexList &indexes) const } } mimeData->setUrls( urlList ); - /*QByteArray encodedData; - - QDataStream stream(&encodedData, QIODevice::WriteOnly); - - foreach (QModelIndex index, indexes) { - if (index.isValid()) { - QString str = qVariantValue(data(index)); - stream << str; - } - } - - mimeData->setData("text/uri-list", encodedData);*/ return mimeData; } @@ -476,7 +479,16 @@ bool UBFeaturesModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction act foreach ( QUrl url, urls ) { - UBFeature element = UBFeaturesController::moveItemToFolder( url, parentFeature ); + UBFeature element; + + if ( action == Qt::MoveAction ) + { + element = UBFeaturesController::moveItemToFolder( url, parentFeature ); + } + else + { + element = UBFeaturesController::copyItemToFolder( url, parentFeature ); + } beginInsertRows( QModelIndex(), featuresList->size(), featuresList->size() ); featuresList->push_back( element ); endInsertRows(); @@ -517,6 +529,10 @@ Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const if ( item.getType() == UBFeatureElementType::FEATURE_INTERACTIVE || item.getType() == UBFeatureElementType::FEATURE_ITEM ) return Qt::ItemIsDragEnabled | defaultFlags; + if ( item.getType() == UBFeatureElementType::FEATURE_FOLDER || + item.getType() == UBFeatureElementType::FEATURE_CATEGORY && item.getFullPath() != "") + return defaultFlags | Qt::ItemIsDropEnabled; + else return defaultFlags; } return defaultFlags | Qt::ItemIsDropEnabled; } @@ -605,7 +621,7 @@ void UBFeaturesPathItemDelegate::paint( QPainter *painter, const QStyleOptionVie { UBFeature feature = index.data( Qt::UserRole + 1 ).value(); QRect rect = option.rect; - if ( !feature.getPath().isEmpty() ) + if ( !feature.getFullPath().isEmpty() ) { painter->drawPixmap( rect.left() - 10, rect.center().y() - 5, *arrowPixmap ); } diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index 4e0c36df..d4e881c6 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -13,6 +13,7 @@ #include #include #include +#include #include "UBDockPaletteWidget.h" #include "UBLibActionBar.h" @@ -34,6 +35,7 @@ class UBFeaturesPathProxyModel; class UBFeaturesPathViewer; class UBFeatureProperties; class UBFeatureItemButton; +class UBFeaturesListView; class UBFeaturesWidget : public UBDockPaletteWidget { @@ -62,8 +64,8 @@ private: UBFeaturesSearchProxyModel *featuresSearchModel; UBFeaturesPathProxyModel *featuresPathModel; - QListView *featuresListView; - QListView *pathListView; + UBFeaturesListView *featuresListView; + UBFeaturesListView *pathListView; QVBoxLayout *layout; UBFeaturesPathViewer *pathViewer; QGraphicsScene *pathScene; @@ -79,6 +81,16 @@ private slots: void searchStarted(QString); }; +class UBFeaturesListView : public QListView +{ + Q_OBJECT +public: + UBFeaturesListView( QWidget* parent=0, const char* name="UBFeaturesListView" ); + virtual ~UBFeaturesListView() {}; +protected: + virtual void dropEvent( QDropEvent *event ); +}; + class UBFeaturesPathViewer : public QGraphicsView { Q_OBJECT