diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp index 0e34c595..cf2c6204 100644 --- a/src/board/UBFeaturesController.cpp +++ b/src/board/UBFeaturesController.cpp @@ -24,7 +24,15 @@ UBFeature::UBFeature(const QString &url, const QPixmap &icon, const QString &nam } +bool UBFeature::operator ==( const UBFeature &f )const +{ + return virtualPath == f.getUrl() && mName == f.getName() && mPath == f.getFullPath() && elementType == f.getType(); +} +bool UBFeature::operator !=( const UBFeature &f )const +{ + return !(*this == f); +} bool UBFeature::isFolder() const { @@ -72,12 +80,17 @@ void UBFeaturesController::initDirectoryTree() trashPath = rootPath + "/Trash"; favoritePath = rootPath + "/Favorites"; - featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/AudiosCategory.svg"), "Audios" , mUserAudioDirectoryPath ) ); - featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/MoviesCategory.svg"), "Movies" , mUserVideoDirectoryPath ) ); - featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/PicturesCategory.svg"), "Pictures" , mUserPicturesDirectoryPath ) ); + audiosElement = UBFeature( rootPath, QPixmap(":images/libpalette/AudiosCategory.svg"), "Audios" , mUserAudioDirectoryPath ); + featuresList->append( audiosElement ); + moviesElement = UBFeature( rootPath, QPixmap(":images/libpalette/MoviesCategory.svg"), "Movies" , mUserVideoDirectoryPath ); + featuresList->append( moviesElement ); + picturesElement = UBFeature( rootPath, QPixmap(":images/libpalette/PicturesCategory.svg"), "Pictures" , mUserPicturesDirectoryPath ); + featuresList->append( picturesElement ); featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/ApplicationsCategory.svg"), "Applications" , mUserInteractiveDirectoryPath ) ); - featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/FlashCategory.svg"), "Animations" , mUserAnimationDirectoryPath ) ); - featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/InteractivesCategory.svg"), "Interactivities" , mLibInteractiveDirectoryPath ) ); + flashElement = UBFeature( rootPath, QPixmap(":images/libpalette/FlashCategory.svg"), "Animations" , mUserAnimationDirectoryPath ); + featuresList->append( flashElement ); + interactElement = UBFeature( rootPath, QPixmap(":images/libpalette/InteractivesCategory.svg"), "Interactivities" , mLibInteractiveDirectoryPath ); + featuresList->append( interactElement ); featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/ShapesCategory.svg"), "Shapes" , mLibShapesDirectoryPath ) ); trashElement = UBFeature( rootPath, QPixmap(":images/libpalette/TrashCategory.svg"), "Trash", trashDirectoryPath, FEATURE_TRASH ); featuresList->append( trashElement ); @@ -325,6 +338,26 @@ void UBFeaturesController::addItemToPage(const UBFeature &item) } } +UBFeature UBFeaturesController::getDestinationForItem( const QUrl &url ) +{ + QString mimetype = UBFileSystemUtils::mimeTypeFromFileName( fileNameFromUrl(url) ); + + if ( mimetype.contains("audio") ) + return audiosElement; + if ( mimetype.contains("video") ) + return moviesElement; + else if ( mimetype.contains("image") ) + return picturesElement; + else if ( mimetype.contains("application") ) + { + if ( mimetype.contains( "x-shockwave-flash") ) + return flashElement; + else + return interactElement; + } + return UBFeature(); +} + UBFeature UBFeaturesController::moveItemToFolder( const QUrl &url, const UBFeature &destination ) { UBFeature newElement = copyItemToFolder( url, destination ); @@ -338,9 +371,19 @@ UBFeature UBFeaturesController::copyItemToFolder( const QUrl &url, const UBFeatu Q_ASSERT( QFileInfo( sourcePath ).exists() ); + UBFeature possibleDest = getDestinationForItem( url ); + + UBFeature dest = destination; + + if ( destination != trashElement && + !destination.getVirtualPath().startsWith( possibleDest.getVirtualPath(), Qt::CaseInsensitive ) ) + { + dest = possibleDest; + } + QString name = QFileInfo( sourcePath ).fileName(); - QString destPath = destination.getFullPath(); - QString destVirtualPath = destination.getUrl() + "/" + destination.getName(); + QString destPath = dest.getFullPath(); + QString destVirtualPath = dest.getVirtualPath(); QString newFullPath = destPath + "/" + name; QFile( sourcePath ).copy( newFullPath ); diff --git a/src/board/UBFeaturesController.h b/src/board/UBFeaturesController.h index a46c6e63..0144be39 100644 --- a/src/board/UBFeaturesController.h +++ b/src/board/UBFeaturesController.h @@ -34,8 +34,11 @@ public: QString getUrl() const { return virtualPath; } //QString getPath() const { return mPath; }; QString getFullPath() const { return mPath; } + QString getVirtualPath() const { return virtualPath + "/" + mName; } UBFeatureElementType getType() const { return elementType; } bool isFolder() const; + bool operator ==( const UBFeature &f )const; + bool operator !=( const UBFeature &f )const; private: QString virtualPath; QPixmap mThumbnail; @@ -78,6 +81,7 @@ private: //void addImageToCurrentPage( const QString &path ); void loadFavoriteList(); void saveFavoriteList(); + UBFeature getDestinationForItem( const QUrl &url ); static UBFeatureElementType fileTypeFromUrl( const QString &path ); @@ -115,6 +119,12 @@ private: UBFeature currentElement; UBFeature trashElement; UBFeature favoriteElement; + UBFeature audiosElement; + UBFeature moviesElement; + UBFeature picturesElement; + UBFeature interactElement; + UBFeature flashElement; + UBFeature shapesElement; QSet *favoriteSet; }; diff --git a/src/gui/UBFeaturesActionBar.cpp b/src/gui/UBFeaturesActionBar.cpp index e9a560e1..b3afc99a 100644 --- a/src/gui/UBFeaturesActionBar.cpp +++ b/src/gui/UBFeaturesActionBar.cpp @@ -143,6 +143,16 @@ void UBFeaturesActionBar::setButtons() mpRemoveFavoriteBtn->show(); mpNewFolderBtn->hide(); break; + case IN_TRASH: + mpFavoriteBtn->hide(); + mpSocialBtn->hide(); + mSearchBar->show(); + //mpSearchBtn->show(); + //mpDeleteBtn->hide(); + mpCloseBtn->hide(); + //mpRemoveFavoriteBtn->show(); + mpNewFolderBtn->hide(); + break; default: break; } diff --git a/src/gui/UBFeaturesActionBar.h b/src/gui/UBFeaturesActionBar.h index 653fbbac..a45371d8 100644 --- a/src/gui/UBFeaturesActionBar.h +++ b/src/gui/UBFeaturesActionBar.h @@ -12,7 +12,8 @@ enum UBFeaturesActionBarState IN_ROOT, IN_FOLDER, IN_PROPERTIES, - IN_FAVORITE + IN_FAVORITE, + IN_TRASH }; class UBFeaturesActionBar : public QWidget diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index e7f1520a..58a691ae 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -56,6 +56,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale featuresListView->setViewMode( QListView::IconMode ); itemDelegate = new UBFeaturesItemDelegate( this, featuresListView ); featuresListView->setItemDelegate( itemDelegate ); + //featuresListView->setSelectionRectVisible(false); featuresListView->setIconSize( QSize(defaultThumbnailSize, defaultThumbnailSize) ); featuresListView->setGridSize( QSize(defaultThumbnailSize * 1.75, defaultThumbnailSize * 1.75) ); @@ -71,6 +72,9 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale pathListView->setSelectionMode( QAbstractItemView::NoSelection ); pathListView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); pathListView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); + pathListView->setFlow( QListView::LeftToRight ); + pathListView->setWrapping(false); + //pathListView->setResizeMode( QListView::Adjust ); //pathListView->setMovement( QListView::Static ); pathListView->setDragDropMode( QAbstractItemView::DropOnly ); @@ -170,6 +174,10 @@ void UBFeaturesWidget::currentSelected(const QModelIndex ¤t) { mActionBar->setCurrentState( IN_FAVORITE ); } + else if (feature.getType() == FEATURE_TRASH) + { + mActionBar->setCurrentState( IN_TRASH ); + } else { mActionBar->setCurrentState( IN_FOLDER ); @@ -208,6 +216,10 @@ void UBFeaturesWidget::currentPathChanged(const QModelIndex &index) { mActionBar->setCurrentState( IN_FAVORITE ); } + else if (feature.getType() == FEATURE_TRASH) + { + mActionBar->setCurrentState( IN_TRASH ); + } else { mActionBar->setCurrentState( IN_FOLDER ); @@ -224,7 +236,6 @@ void UBFeaturesWidget::createNewFolder() featuresModel->addItem( newFolder ); featuresProxyModel->invalidate(); } - } void UBFeaturesWidget::deleteElements( const QMimeData & mimeData ) @@ -315,11 +326,39 @@ UBFeaturesWidget::~UBFeaturesWidget() { } -UBFeaturesListView::UBFeaturesListView( QWidget* parent, const char* name ) : QListView(parent) +UBFeaturesListView::UBFeaturesListView( QWidget* parent, const char* name ) +: QListView(parent) { setObjectName(name); + //rubberBand = new UBRubberBand( QRubberBand::Rectangle, this ); } +/* +void UBFeaturesListView::mousePressEvent( QMouseEvent *event ) +{ + rubberOrigin = event->pos(); + rubberBand->setGeometry( QRect( rubberOrigin, QSize() ) ); + //qDebug() << rubberOrigin.x() << rubberOrigin.y(); + rubberBand->show(); + QListView::mousePressEvent(event); +} + +void UBFeaturesListView::mouseMoveEvent( QMouseEvent *event ) +{ + QPoint current = event->pos(); + rubberBand->setGeometry( QRect( rubberOrigin, current ).normalized() ); + + //setSelection( rubberBand->rect(), QItemSelectionModel::Select ); + QListView::mouseMoveEvent(event); +} + +void UBFeaturesListView::mouseReleaseEvent( QMouseEvent *event ) +{ + rubberBand->hide(); + QListView::mouseReleaseEvent(event); +} + +*/ void UBFeaturesListView::dragEnterEvent( QDragEnterEvent *event ) { if ( event->mimeData()->hasUrls() ) @@ -537,19 +576,15 @@ bool UBFeaturesModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction act int endRow = 0; + UBFeature parentFeature; if ( !parent.isValid() ) { - return false; - /*if (row < 0) - endRow = featuresList->size(); - else - endRow = qMin( row, featuresList->size() );*/ + parentFeature = dynamic_cast(QObject::parent())->getFeaturesController()->getCurrentElement(); } else - endRow = parent.row(); - Q_UNUSED(endRow) //why do we need this variable? - - UBFeature parentFeature = parent.data( Qt::UserRole + 1).value(); + { + parentFeature = parent.data( Qt::UserRole + 1).value(); + } QList urls = mimeData->urls(); @@ -628,7 +663,7 @@ Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const return Qt::ItemIsDragEnabled | defaultFlags; if ( item.isFolder() && !item.getFullPath().isNull() ) return defaultFlags | Qt::ItemIsDropEnabled; - else return defaultFlags; + else return defaultFlags | Qt::ItemIsDropEnabled; } /*if ( index.isValid() ) { @@ -647,7 +682,7 @@ Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const default:; } }*/ - return defaultFlags; + return defaultFlags | Qt::ItemIsDropEnabled; } @@ -710,13 +745,7 @@ QString UBFeaturesItemDelegate::displayText ( const QVariant & value, const QLoc { const QFontMetrics fm = listView->fontMetrics(); const QSize iSize = listView->iconSize(); - - if ( iSize.width() > 0 && fm.width(text) > iSize.width() ) - { - while (fm.width(text) > iSize.width()) - text.resize(text.size()-1); - text += "..."; - } + return elidedText( fm, iSize.width(), Qt::ElideRight, text ); } return text; } diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index ea718f22..5c9762c6 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -19,6 +19,7 @@ //#include "UBLibActionBar.h" #include "board/UBFeaturesController.h" #include "UBFeaturesActionBar.h" +#include "UBRubberBand.h" #define THUMBNAIL_WIDTH 400 @@ -105,6 +106,12 @@ public: protected: virtual void dragEnterEvent( QDragEnterEvent *event ); virtual void dropEvent( QDropEvent *event ); + /*virtual void mousePressEvent( QMouseEvent *event ); + virtual void mouseMoveEvent( QMouseEvent *event ); + virtual void mouseReleaseEvent( QMouseEvent *event );*/ +private: + //UBRubberBand *rubberBand; + //QPoint rubberOrigin; };