some DnD bugs fixed

preferencesAboutTextFull
Anna Udovichenko 13 years ago
parent f2c608338b
commit e130379b3e
  1. 57
      src/board/UBFeaturesController.cpp
  2. 10
      src/board/UBFeaturesController.h
  3. 10
      src/gui/UBFeaturesActionBar.cpp
  4. 3
      src/gui/UBFeaturesActionBar.h
  5. 69
      src/gui/UBFeaturesWidget.cpp
  6. 7
      src/gui/UBFeaturesWidget.h

@ -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 bool UBFeature::isFolder() const
{ {
@ -72,12 +80,17 @@ void UBFeaturesController::initDirectoryTree()
trashPath = rootPath + "/Trash"; trashPath = rootPath + "/Trash";
favoritePath = rootPath + "/Favorites"; favoritePath = rootPath + "/Favorites";
featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/AudiosCategory.svg"), "Audios" , mUserAudioDirectoryPath ) ); audiosElement = UBFeature( rootPath, QPixmap(":images/libpalette/AudiosCategory.svg"), "Audios" , mUserAudioDirectoryPath );
featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/MoviesCategory.svg"), "Movies" , mUserVideoDirectoryPath ) ); featuresList->append( audiosElement );
featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/PicturesCategory.svg"), "Pictures" , mUserPicturesDirectoryPath ) ); 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/ApplicationsCategory.svg"), "Applications" , mUserInteractiveDirectoryPath ) );
featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/FlashCategory.svg"), "Animations" , mUserAnimationDirectoryPath ) ); flashElement = UBFeature( rootPath, QPixmap(":images/libpalette/FlashCategory.svg"), "Animations" , mUserAnimationDirectoryPath );
featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/InteractivesCategory.svg"), "Interactivities" , mLibInteractiveDirectoryPath ) ); 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 ) ); 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 );
@ -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 UBFeaturesController::moveItemToFolder( const QUrl &url, const UBFeature &destination )
{ {
UBFeature newElement = copyItemToFolder( url, destination ); UBFeature newElement = copyItemToFolder( url, destination );
@ -338,9 +371,19 @@ UBFeature UBFeaturesController::copyItemToFolder( const QUrl &url, const UBFeatu
Q_ASSERT( QFileInfo( sourcePath ).exists() ); 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 name = QFileInfo( sourcePath ).fileName();
QString destPath = destination.getFullPath(); QString destPath = dest.getFullPath();
QString destVirtualPath = destination.getUrl() + "/" + destination.getName(); QString destVirtualPath = dest.getVirtualPath();
QString newFullPath = destPath + "/" + name; QString newFullPath = destPath + "/" + name;
QFile( sourcePath ).copy( newFullPath ); QFile( sourcePath ).copy( newFullPath );

@ -34,8 +34,11 @@ public:
QString getUrl() const { return virtualPath; } QString getUrl() const { return virtualPath; }
//QString getPath() const { return mPath; }; //QString getPath() const { return mPath; };
QString getFullPath() const { return mPath; } QString getFullPath() const { return mPath; }
QString getVirtualPath() const { return virtualPath + "/" + mName; }
UBFeatureElementType getType() const { return elementType; } UBFeatureElementType getType() const { return elementType; }
bool isFolder() const; bool isFolder() const;
bool operator ==( const UBFeature &f )const;
bool operator !=( const UBFeature &f )const;
private: private:
QString virtualPath; QString virtualPath;
QPixmap mThumbnail; QPixmap mThumbnail;
@ -78,6 +81,7 @@ private:
//void addImageToCurrentPage( const QString &path ); //void addImageToCurrentPage( const QString &path );
void loadFavoriteList(); void loadFavoriteList();
void saveFavoriteList(); void saveFavoriteList();
UBFeature getDestinationForItem( const QUrl &url );
static UBFeatureElementType fileTypeFromUrl( const QString &path ); static UBFeatureElementType fileTypeFromUrl( const QString &path );
@ -115,6 +119,12 @@ private:
UBFeature currentElement; UBFeature currentElement;
UBFeature trashElement; UBFeature trashElement;
UBFeature favoriteElement; UBFeature favoriteElement;
UBFeature audiosElement;
UBFeature moviesElement;
UBFeature picturesElement;
UBFeature interactElement;
UBFeature flashElement;
UBFeature shapesElement;
QSet <QString> *favoriteSet; QSet <QString> *favoriteSet;
}; };

@ -143,6 +143,16 @@ void UBFeaturesActionBar::setButtons()
mpRemoveFavoriteBtn->show(); mpRemoveFavoriteBtn->show();
mpNewFolderBtn->hide(); mpNewFolderBtn->hide();
break; break;
case IN_TRASH:
mpFavoriteBtn->hide();
mpSocialBtn->hide();
mSearchBar->show();
//mpSearchBtn->show();
//mpDeleteBtn->hide();
mpCloseBtn->hide();
//mpRemoveFavoriteBtn->show();
mpNewFolderBtn->hide();
break;
default: default:
break; break;
} }

@ -12,7 +12,8 @@ enum UBFeaturesActionBarState
IN_ROOT, IN_ROOT,
IN_FOLDER, IN_FOLDER,
IN_PROPERTIES, IN_PROPERTIES,
IN_FAVORITE IN_FAVORITE,
IN_TRASH
}; };
class UBFeaturesActionBar : public QWidget class UBFeaturesActionBar : public QWidget

@ -56,6 +56,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale
featuresListView->setViewMode( QListView::IconMode ); featuresListView->setViewMode( QListView::IconMode );
itemDelegate = new UBFeaturesItemDelegate( this, featuresListView ); itemDelegate = new UBFeaturesItemDelegate( this, featuresListView );
featuresListView->setItemDelegate( itemDelegate ); featuresListView->setItemDelegate( itemDelegate );
//featuresListView->setSelectionRectVisible(false);
featuresListView->setIconSize( QSize(defaultThumbnailSize, defaultThumbnailSize) ); featuresListView->setIconSize( QSize(defaultThumbnailSize, defaultThumbnailSize) );
featuresListView->setGridSize( QSize(defaultThumbnailSize * 1.75, defaultThumbnailSize * 1.75) ); 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->setSelectionMode( QAbstractItemView::NoSelection );
pathListView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); pathListView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
pathListView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); pathListView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn );
pathListView->setFlow( QListView::LeftToRight );
pathListView->setWrapping(false);
//pathListView->setResizeMode( QListView::Adjust ); //pathListView->setResizeMode( QListView::Adjust );
//pathListView->setMovement( QListView::Static ); //pathListView->setMovement( QListView::Static );
pathListView->setDragDropMode( QAbstractItemView::DropOnly ); pathListView->setDragDropMode( QAbstractItemView::DropOnly );
@ -170,6 +174,10 @@ void UBFeaturesWidget::currentSelected(const QModelIndex &current)
{ {
mActionBar->setCurrentState( IN_FAVORITE ); mActionBar->setCurrentState( IN_FAVORITE );
} }
else if (feature.getType() == FEATURE_TRASH)
{
mActionBar->setCurrentState( IN_TRASH );
}
else else
{ {
mActionBar->setCurrentState( IN_FOLDER ); mActionBar->setCurrentState( IN_FOLDER );
@ -208,6 +216,10 @@ void UBFeaturesWidget::currentPathChanged(const QModelIndex &index)
{ {
mActionBar->setCurrentState( IN_FAVORITE ); mActionBar->setCurrentState( IN_FAVORITE );
} }
else if (feature.getType() == FEATURE_TRASH)
{
mActionBar->setCurrentState( IN_TRASH );
}
else else
{ {
mActionBar->setCurrentState( IN_FOLDER ); mActionBar->setCurrentState( IN_FOLDER );
@ -224,7 +236,6 @@ void UBFeaturesWidget::createNewFolder()
featuresModel->addItem( newFolder ); featuresModel->addItem( newFolder );
featuresProxyModel->invalidate(); featuresProxyModel->invalidate();
} }
} }
void UBFeaturesWidget::deleteElements( const QMimeData & mimeData ) 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); 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 ) void UBFeaturesListView::dragEnterEvent( QDragEnterEvent *event )
{ {
if ( event->mimeData()->hasUrls() ) if ( event->mimeData()->hasUrls() )
@ -537,19 +576,15 @@ bool UBFeaturesModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction act
int endRow = 0; int endRow = 0;
UBFeature parentFeature;
if ( !parent.isValid() ) if ( !parent.isValid() )
{ {
return false; parentFeature = dynamic_cast<UBFeaturesWidget *>(QObject::parent())->getFeaturesController()->getCurrentElement();
/*if (row < 0)
endRow = featuresList->size();
else
endRow = qMin( row, featuresList->size() );*/
} }
else else
endRow = parent.row(); {
Q_UNUSED(endRow) //why do we need this variable? parentFeature = parent.data( Qt::UserRole + 1).value<UBFeature>();
}
UBFeature parentFeature = parent.data( Qt::UserRole + 1).value<UBFeature>();
QList<QUrl> urls = mimeData->urls(); QList<QUrl> urls = mimeData->urls();
@ -628,7 +663,7 @@ Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const
return Qt::ItemIsDragEnabled | defaultFlags; return Qt::ItemIsDragEnabled | defaultFlags;
if ( item.isFolder() && !item.getFullPath().isNull() ) if ( item.isFolder() && !item.getFullPath().isNull() )
return defaultFlags | Qt::ItemIsDropEnabled; return defaultFlags | Qt::ItemIsDropEnabled;
else return defaultFlags; else return defaultFlags | Qt::ItemIsDropEnabled;
} }
/*if ( index.isValid() ) /*if ( index.isValid() )
{ {
@ -647,7 +682,7 @@ Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const
default:; 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 QFontMetrics fm = listView->fontMetrics();
const QSize iSize = listView->iconSize(); const QSize iSize = listView->iconSize();
return elidedText( fm, iSize.width(), Qt::ElideRight, text );
if ( iSize.width() > 0 && fm.width(text) > iSize.width() )
{
while (fm.width(text) > iSize.width())
text.resize(text.size()-1);
text += "...";
}
} }
return text; return text;
} }

@ -19,6 +19,7 @@
//#include "UBLibActionBar.h" //#include "UBLibActionBar.h"
#include "board/UBFeaturesController.h" #include "board/UBFeaturesController.h"
#include "UBFeaturesActionBar.h" #include "UBFeaturesActionBar.h"
#include "UBRubberBand.h"
#define THUMBNAIL_WIDTH 400 #define THUMBNAIL_WIDTH 400
@ -105,6 +106,12 @@ public:
protected: protected:
virtual void dragEnterEvent( QDragEnterEvent *event ); virtual void dragEnterEvent( QDragEnterEvent *event );
virtual void dropEvent( QDropEvent *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;
}; };

Loading…
Cancel
Save