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(); return elementType == FEATURE_CATEGORY || elementType == FEATURE_TRASH || elementType == FEATURE_FAVORITE
mPath = f.getFullPath(); || elementType == FEATURE_FOLDER;
mThumbnail = f.getThumbnail();
mName = f.getName();
elementType = f.getType();
} }
UBFeaturesController::UBFeaturesController(QWidget *pParentWidget) : UBFeaturesController::UBFeaturesController(QWidget *pParentWidget) :
QObject(pParentWidget), QObject(pParentWidget),
mLastItemOffsetIndex(0) mLastItemOffsetIndex(0)
@ -83,7 +81,7 @@ void UBFeaturesController::initDirectoryTree()
featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/ShapesCategory.svg"), "Shapes" , mLibShapesDirectoryPath ) ); featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/ShapesCategory.svg"), "Shapes" , mLibShapesDirectoryPath ) );
trashElement = UBFeature( rootPath, QPixmap(":images/libpalette/TrashCategory.svg"), "Trash", trashDirectoryPath, FEATURE_TRASH ); trashElement = UBFeature( rootPath, QPixmap(":images/libpalette/TrashCategory.svg"), "Trash", trashDirectoryPath, FEATURE_TRASH );
featuresList->append( trashElement ); 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 ); featuresList->append( favoriteElement );
loadFavoriteList(); loadFavoriteList();
@ -215,6 +213,16 @@ UBFeature UBFeaturesController::addToFavorite( const QUrl &path )
return UBFeature(); 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 UBFeaturesController::fileNameFromUrl( const QUrl &url )
{ {
QString fileName = url.toString(); QString fileName = url.toString();

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

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

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

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

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

Loading…
Cancel
Save