implemented deleting from favorite folder

preferencesAboutTextFull
Anna Udovichenko 13 years ago
parent fe0c8ab2e4
commit 0cf7b075b3
  1. 24
      src/board/UBFeaturesController.cpp
  2. 20
      src/board/UBFeaturesController.h
  3. 9
      src/gui/UBFeaturesActionBar.cpp
  4. 1
      src/gui/UBFeaturesActionBar.h
  5. 49
      src/gui/UBFeaturesWidget.cpp
  6. 1
      src/gui/UBFeaturesWidget.h

@ -24,17 +24,15 @@ UBFeature::UBFeature(const QString &url, const QPixmap &icon, const QString &nam
}
UBFeature::UBFeature(const UBFeature &f)
bool UBFeature::isFolder() const
{
virtualPath = f.getUrl();
mPath = f.getFullPath();
mThumbnail = f.getThumbnail();
mName = f.getName();
elementType = f.getType();
return elementType == FEATURE_CATEGORY || elementType == FEATURE_TRASH || elementType == FEATURE_FAVORITE
|| elementType == FEATURE_FOLDER;
}
UBFeaturesController::UBFeaturesController(QWidget *pParentWidget) :
QObject(pParentWidget),
mLastItemOffsetIndex(0)
@ -83,7 +81,7 @@ void UBFeaturesController::initDirectoryTree()
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 );
favoriteElement = UBFeature( rootPath, QPixmap(":images/libpalette/FavoritesCategory.svg"), "Favorites", "favorites" );
favoriteElement = UBFeature( rootPath, QPixmap(":images/libpalette/FavoritesCategory.svg"), "Favorites", "favorites", FEATURE_FAVORITE );
featuresList->append( favoriteElement );
loadFavoriteList();
@ -215,6 +213,16 @@ UBFeature UBFeaturesController::addToFavorite( const QUrl &path )
return UBFeature();
}
void UBFeaturesController::removeFromFavorite( const QUrl &path )
{
QString filePath = fileNameFromUrl( path );
if ( favoriteSet->find( filePath ) != favoriteSet->end() )
{
favoriteSet->erase( favoriteSet->find( filePath ) );
saveFavoriteList();
}
}
QString UBFeaturesController::fileNameFromUrl( const QUrl &url )
{
QString fileName = url.toString();

@ -18,14 +18,15 @@ enum UBFeatureElementType
FEATURE_INTERACTIVE,
FEATURE_INTERNAL,
FEATURE_ITEM,
FEATURE_TRASH
FEATURE_TRASH,
FEATURE_FAVORITE
};
class UBFeature
{
public:
UBFeature() {;}
UBFeature(const UBFeature &f);
//UBFeature(const UBFeature &f);
UBFeature(const QString &url, const QPixmap &icon, const QString &name, const QString &realPath, UBFeatureElementType type = FEATURE_CATEGORY);
virtual ~UBFeature() {;}
QString getName() const { return mName; }
@ -34,6 +35,7 @@ public:
//QString getPath() const { return mPath; };
QString getFullPath() const { return mPath; }
UBFeatureElementType getType() const { return elementType; }
bool isFolder() const;
private:
QString virtualPath;
QPixmap mThumbnail;
@ -59,14 +61,16 @@ public:
const UBFeature& getCurrentElement()const { return currentElement; }
void setCurrentElement( const UBFeature &elem ) { currentElement = elem; }
const UBFeature & getTrashElement () const { return trashElement; }
static QPixmap thumbnailForFile( const QString &path );
static UBFeature moveItemToFolder( const QUrl &url, const UBFeature &destination );
static UBFeature copyItemToFolder( const QUrl &url, const UBFeature &destination );
static void deleteItem( const QUrl &url );
UBFeature moveItemToFolder( const QUrl &url, const UBFeature &destination );
UBFeature copyItemToFolder( const QUrl &url, const UBFeature &destination );
void deleteItem( const QUrl &url );
bool isTrash( const QUrl &url );
UBFeature newFolder( const QString &name );
UBFeature addToFavorite( const QUrl &path );
void removeFromFavorite( const QUrl &path );
static QString fileNameFromUrl( const QUrl &url );
static QPixmap thumbnailForFile( const QString &path );
private:
void initDirectoryTree();
void fileSystemScan(const QString &currPath, const QString & currVirtualPath);
@ -74,7 +78,7 @@ private:
//void addImageToCurrentPage( const QString &path );
void loadFavoriteList();
void saveFavoriteList();
static QString fileNameFromUrl( const QUrl &url );
static UBFeatureElementType fileTypeFromUrl( const QString &path );
QVector <UBFeature> *featuresList;

@ -180,13 +180,18 @@ void UBFeaturesActionBar::dropEvent( QDropEvent *event )
event->accept();
emit deleteElements( *event->mimeData() );
}
if ( dest == mpFavoriteBtn )
else if ( dest == mpFavoriteBtn )
{
event->setDropAction( Qt::CopyAction );
event->accept();
emit addToFavorite( *event->mimeData() );
}
else if ( dest == mpRemoveFavoriteBtn )
{
event->setDropAction( Qt::MoveAction );
event->accept();
emit removeFromFavorite( *event->mimeData() );
}
}
UBFeaturesActionBar::~UBFeaturesActionBar()

@ -28,6 +28,7 @@ signals:
void newFolderToCreate();
void deleteElements( const QMimeData &data );
void addToFavorite( const QMimeData &data );
void removeFromFavorite( const QMimeData &data );
private slots:
void onSearchTextChanged(QString txt);
void onActionNewFolder();

@ -99,6 +99,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale
connect( mActionBar, SIGNAL( newFolderToCreate() ), this, SLOT( createNewFolder() ) );
connect( mActionBar, SIGNAL( deleteElements(const QMimeData &) ), this, SLOT( deleteElements(const QMimeData &) ) );
connect( mActionBar, SIGNAL( addToFavorite(const QMimeData &) ), this, SLOT( addToFavorite(const QMimeData &) ) );
connect( mActionBar, SIGNAL( removeFromFavorite(const QMimeData &) ), this, SLOT( removeFromFavorite(const QMimeData &) ) );
connect( pathListView, SIGNAL(clicked( const QModelIndex & ) ),
this, SLOT( currentPathChanged( const QModelIndex & ) ) );
}
@ -127,8 +128,8 @@ void UBFeaturesWidget::currentSelected(const QModelIndex &current)
QString path = model->data(current, Qt::UserRole).toString();
eUBLibElementType type = (eUBLibElementType)model->data(current, Qt::UserRole + 1).toInt();*/
UBFeature feature = model->data(current, Qt::UserRole + 1).value<UBFeature>();
if ( feature.getType() == FEATURE_FOLDER || feature.getType() == FEATURE_CATEGORY ||
feature.getType() == FEATURE_TRASH )
if ( feature.isFolder() )
{
QString newPath = feature.getUrl() + "/" + feature.getName();
//pathViewer->addPathElement( feature.getThumbnail(), newPath );
@ -140,8 +141,15 @@ void UBFeaturesWidget::currentSelected(const QModelIndex &current)
featuresPathModel->setPath( newPath );
featuresPathModel->invalidate();
if ( feature.getType() == FEATURE_FAVORITE )
{
mActionBar->setCurrentState( IN_FAVORITE );
}
else
{
mActionBar->setCurrentState( IN_FOLDER );
}
}
else
{
featureProperties->showElement( feature );
@ -171,6 +179,10 @@ void UBFeaturesWidget::currentPathChanged(const QModelIndex &index)
{
mActionBar->setCurrentState( IN_ROOT );
}
else if (feature.getType() == FEATURE_FAVORITE)
{
mActionBar->setCurrentState( IN_FAVORITE );
}
else
{
mActionBar->setCurrentState( IN_FOLDER );
@ -198,14 +210,16 @@ void UBFeaturesWidget::deleteElements( const QMimeData & mimeData )
foreach ( QUrl url, urls )
{
if ( controller->isTrash( url) )
if ( controller->isTrash( url ) )
{
UBFeaturesController::deleteItem( url );
controller->deleteItem( url );
}
else
{
UBFeature elem = UBFeaturesController::moveItemToFolder( url, controller->getTrashElement() );
UBFeature elem = controller->moveItemToFolder( url, controller->getTrashElement() );
controller->removeFromFavorite( url );
featuresModel->addItem( elem );
featuresModel->deleteFavoriteItem( UBFeaturesController::fileNameFromUrl( url ) );
}
}
QSortFilterProxyModel *model = dynamic_cast<QSortFilterProxyModel *>( featuresListView->model() );
@ -228,6 +242,17 @@ void UBFeaturesWidget::addToFavorite( const QMimeData & mimeData )
model->invalidate();
}
void UBFeaturesWidget::removeFromFavorite( const QMimeData & mimeData )
{
if ( !mimeData.hasUrls() )
return;
QList<QUrl> urls = mimeData.urls();
foreach( QUrl url, urls )
{
controller->removeFromFavorite( url );
}
}
void UBFeaturesWidget::switchToListView()
{
stackedWidget->setCurrentIndex(ID_LISTVIEW);
@ -499,11 +524,11 @@ bool UBFeaturesModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction act
if ( action == Qt::MoveAction )
{
element = UBFeaturesController::moveItemToFolder( url, parentFeature );
element = dynamic_cast<UBFeaturesWidget *>(QObject::parent())->getFeaturesController()->moveItemToFolder( url, parentFeature );
}
else
{
element = UBFeaturesController::copyItemToFolder( url, parentFeature );
element = dynamic_cast<UBFeaturesWidget *>(QObject::parent())->getFeaturesController()->copyItemToFolder( url, parentFeature );
}
addItem( element );
}
@ -522,7 +547,7 @@ void UBFeaturesModel::deleteFavoriteItem( const QString &path )
for ( int i = 0; i < featuresList->size(); ++i )
{
if ( !QString::compare( featuresList->at(i).getFullPath(), path, Qt::CaseInsensitive ) &&
!QString::compare( featuresList->at(i).getUrl(), "root/favorite", Qt::CaseInsensitive ) )
!QString::compare( featuresList->at(i).getUrl(), "/root/favorites", Qt::CaseInsensitive ) )
{
removeRow( i, QModelIndex() );
return;
@ -564,9 +589,7 @@ Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const
item.getType() == FEATURE_ITEM ||
item.getType() == FEATURE_INTERNAL )
return Qt::ItemIsDragEnabled | defaultFlags;
if ( item.getType() == FEATURE_FOLDER ||
item.getType() == FEATURE_TRASH ||
(item.getType() == FEATURE_CATEGORY && !item.getFullPath().isNull()))
if ( item.isFolder() && !item.getFullPath().isNull() )
return defaultFlags | Qt::ItemIsDropEnabled;
else return defaultFlags;
}
@ -619,11 +642,9 @@ bool UBFeaturesPathProxyModel::filterAcceptsRow( int sourceRow, const QModelInde
eUBLibElementType type = (eUBLibElementType)sourceModel()->data(index, Qt::UserRole + 1).toInt();*/
UBFeature feature = sourceModel()->data(index, Qt::UserRole + 1).value<UBFeature>();
bool isFolder = feature.getType() == FEATURE_CATEGORY ||
feature.getType() == FEATURE_FOLDER || feature.getType() == FEATURE_TRASH;
QString virtualFullPath = feature.getUrl() + "/" + feature.getName();
return isFolder && path.startsWith( virtualFullPath );
return feature.isFolder() && path.startsWith( virtualFullPath );
}
QString UBFeaturesItemDelegate::displayText ( const QVariant & value, const QLocale & locale ) const

@ -84,6 +84,7 @@ private slots:
void createNewFolder();
void deleteElements( const QMimeData & );
void addToFavorite( const QMimeData & );
void removeFromFavorite( const QMimeData & );
};
class UBFeaturesListView : public QListView

Loading…
Cancel
Save