Some bugs fixed and more DnD functionality implemented

preferencesAboutTextFull
Anna Udovichenko 13 years ago
parent 2e04977035
commit 14e326effe
  1. 37
      src/board/UBFeaturesController.cpp
  2. 5
      src/board/UBFeaturesController.h
  3. 50
      src/gui/UBFeaturesWidget.cpp
  4. 16
      src/gui/UBFeaturesWidget.h

@ -27,7 +27,7 @@ UBFeature::UBFeature(const QString &url, const QPixmap &icon, const QString &nam
UBFeature::UBFeature(const UBFeature &f) UBFeature::UBFeature(const UBFeature &f)
{ {
virtualPath = f.getUrl(); virtualPath = f.getUrl();
mPath = f.getPath(); mPath = f.getFullPath();
mThumbnail = f.getThumbnail(); mThumbnail = f.getThumbnail();
mName = f.getName(); mName = f.getName();
elementType = f.getType(); elementType = f.getType();
@ -110,7 +110,7 @@ void UBFeaturesController::fileSystemScan(const QString & currentPath, const QSt
} }
QString itemName = (fileType != FEATURE_ITEM) ? fileName : fileInfo->completeBaseName(); QString itemName = (fileType != FEATURE_ITEM) ? fileName : fileInfo->completeBaseName();
QPixmap icon = QPixmap(":images/libpalette/soundIcon.svg"); QPixmap icon = QPixmap(":images/libpalette/soundIcon.svg");
QString fullFileName = currentPath + "/" + fileName; QString fullFileName = fileInfo->filePath();
if ( fileType == FEATURE_FOLDER ) if ( fileType == FEATURE_FOLDER )
{ {
@ -131,7 +131,7 @@ void UBFeaturesController::fileSystemScan(const QString & currentPath, const QSt
icon = QPixmap( thumbnailPath ); icon = QPixmap( thumbnailPath );
else icon = createThumbnail( fullFileName );*/ 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 ) if ( fileType == FEATURE_FOLDER )
{ {
@ -194,7 +194,16 @@ void UBFeaturesController::addItemToPage(const UBFeature &item)
UBFeature UBFeaturesController::moveItemToFolder( const QUrl &url, const UBFeature &destination ) UBFeature UBFeaturesController::moveItemToFolder( const QUrl &url, const UBFeature &destination )
{ {
UBFeature newElement = copyItemToFolder( url, destination );
QString sourcePath = url.toLocalFile(); 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() ); Q_ASSERT( QFileInfo( sourcePath ).exists() );
@ -217,8 +226,30 @@ UBFeature UBFeaturesController::moveItemToFolder( const QUrl &url, const UBFeatu
if ( UBFileSystemUtils::mimeTypeFromFileName( newFullPath ).contains("application") ) if ( UBFileSystemUtils::mimeTypeFromFileName( newFullPath ).contains("application") )
type = UBFeatureElementType::FEATURE_INTERACTIVE; type = UBFeatureElementType::FEATURE_INTERACTIVE;
UBFeature newElement( destVirtualPath, thumb, name, destPath, type ); 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; return newElement;
} }
/* /*
void UBFeaturesController::addImageToCurrentPage( const QString &path ) void UBFeaturesController::addImageToCurrentPage( const QString &path )
{ {

@ -31,8 +31,8 @@ public:
return mThumbnail; return mThumbnail;
}; };
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 + "/" + mName; }; QString getFullPath() const { return mPath; };
UBFeatureElementType getType() const { return elementType; } ; UBFeatureElementType getType() const { return elementType; } ;
private: private:
QString virtualPath; QString virtualPath;
@ -58,6 +58,7 @@ public:
void addItemToPage(const UBFeature &item); void addItemToPage(const UBFeature &item);
static QPixmap thumbnailForFile( const QString &path ); static QPixmap thumbnailForFile( const QString &path );
static UBFeature moveItemToFolder( const QUrl &url, const UBFeature &destination ); static UBFeature moveItemToFolder( const QUrl &url, const UBFeature &destination );
static UBFeature copyItemToFolder( const QUrl &url, const UBFeature &destination );
private: private:
void initDirectoryTree(); void initDirectoryTree();
void fileSystemScan(const QString &currPath, const QString & currVirtualPath); void fileSystemScan(const QString &currPath, const QString & currVirtualPath);

@ -28,8 +28,8 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale
featuresModel = new UBFeaturesModel(this); featuresModel = new UBFeaturesModel(this);
featuresModel->setFeaturesList( controller->getFeatures() ); featuresModel->setFeaturesList( controller->getFeatures() );
featuresModel->setSupportedDragActions( Qt::CopyAction | Qt::MoveAction ); featuresModel->setSupportedDragActions( Qt::CopyAction | Qt::MoveAction );
featuresListView = new QListView(this); featuresListView = new UBFeaturesListView(this);
pathListView = new QListView(this); pathListView = new UBFeaturesListView(this);
featuresProxyModel = new UBFeaturesProxyModel(this); featuresProxyModel = new UBFeaturesProxyModel(this);
@ -69,7 +69,7 @@ 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->setMovement( QListView::Static ); //pathListView->setMovement( QListView::Static );
pathListView->setDragDropMode( QAbstractItemView::DragDrop ); pathListView->setDragDropMode( QAbstractItemView::DragDrop );
pathScene = new QGraphicsScene(this); 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<UBFeaturesListView *>( event->source() ) )
{
event->setDropAction( Qt::MoveAction );
}
QListView::dropEvent( event );
}
UBFeatureProperties::UBFeatureProperties( QWidget *parent, const char *name ) : QWidget(parent) UBFeatureProperties::UBFeatureProperties( QWidget *parent, const char *name ) : QWidget(parent)
, mpLayout(NULL) , mpLayout(NULL)
, mpButtonLayout(NULL) , mpButtonLayout(NULL)
@ -432,18 +447,6 @@ QMimeData* UBFeaturesModel::mimeData(const QModelIndexList &indexes) const
} }
} }
mimeData->setUrls( urlList ); mimeData->setUrls( urlList );
/*QByteArray encodedData;
QDataStream stream(&encodedData, QIODevice::WriteOnly);
foreach (QModelIndex index, indexes) {
if (index.isValid()) {
QString str = qVariantValue<QString>(data(index));
stream << str;
}
}
mimeData->setData("text/uri-list", encodedData);*/
return mimeData; return mimeData;
} }
@ -476,7 +479,16 @@ bool UBFeaturesModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction act
foreach ( QUrl url, urls ) 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() ); beginInsertRows( QModelIndex(), featuresList->size(), featuresList->size() );
featuresList->push_back( element ); featuresList->push_back( element );
endInsertRows(); endInsertRows();
@ -517,6 +529,10 @@ Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const
if ( item.getType() == UBFeatureElementType::FEATURE_INTERACTIVE || if ( item.getType() == UBFeatureElementType::FEATURE_INTERACTIVE ||
item.getType() == UBFeatureElementType::FEATURE_ITEM ) item.getType() == UBFeatureElementType::FEATURE_ITEM )
return Qt::ItemIsDragEnabled | defaultFlags; 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; return defaultFlags | Qt::ItemIsDropEnabled;
} }
@ -605,7 +621,7 @@ void UBFeaturesPathItemDelegate::paint( QPainter *painter, const QStyleOptionVie
{ {
UBFeature feature = index.data( Qt::UserRole + 1 ).value<UBFeature>(); UBFeature feature = index.data( Qt::UserRole + 1 ).value<UBFeature>();
QRect rect = option.rect; QRect rect = option.rect;
if ( !feature.getPath().isEmpty() ) if ( !feature.getFullPath().isEmpty() )
{ {
painter->drawPixmap( rect.left() - 10, rect.center().y() - 5, *arrowPixmap ); painter->drawPixmap( rect.left() - 10, rect.center().y() - 5, *arrowPixmap );
} }

@ -13,6 +13,7 @@
#include <QLocale> #include <QLocale>
#include <QGraphicsLinearLayout> #include <QGraphicsLinearLayout>
#include <QStackedWidget> #include <QStackedWidget>
#include <QDropEvent>
#include "UBDockPaletteWidget.h" #include "UBDockPaletteWidget.h"
#include "UBLibActionBar.h" #include "UBLibActionBar.h"
@ -34,6 +35,7 @@ class UBFeaturesPathProxyModel;
class UBFeaturesPathViewer; class UBFeaturesPathViewer;
class UBFeatureProperties; class UBFeatureProperties;
class UBFeatureItemButton; class UBFeatureItemButton;
class UBFeaturesListView;
class UBFeaturesWidget : public UBDockPaletteWidget class UBFeaturesWidget : public UBDockPaletteWidget
{ {
@ -62,8 +64,8 @@ private:
UBFeaturesSearchProxyModel *featuresSearchModel; UBFeaturesSearchProxyModel *featuresSearchModel;
UBFeaturesPathProxyModel *featuresPathModel; UBFeaturesPathProxyModel *featuresPathModel;
QListView *featuresListView; UBFeaturesListView *featuresListView;
QListView *pathListView; UBFeaturesListView *pathListView;
QVBoxLayout *layout; QVBoxLayout *layout;
UBFeaturesPathViewer *pathViewer; UBFeaturesPathViewer *pathViewer;
QGraphicsScene *pathScene; QGraphicsScene *pathScene;
@ -79,6 +81,16 @@ private slots:
void searchStarted(QString); 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 class UBFeaturesPathViewer : public QGraphicsView
{ {
Q_OBJECT Q_OBJECT

Loading…
Cancel
Save