UBFeaturesComputingThread UBFeaturesNewFolderDialog

preferencesAboutTextFull
Ilia Ryabokon 12 years ago
parent f6585ab884
commit fd289bc6d9
  1. 17
      resources/style.qss
  2. 384
      src/board/UBFeaturesController.cpp
  3. 81
      src/board/UBFeaturesController.h
  4. 11
      src/gui/UBFeaturesActionBar.cpp
  5. 375
      src/gui/UBFeaturesWidget.cpp
  6. 110
      src/gui/UBFeaturesWidget.h

@ -5,15 +5,21 @@ QWidget#UBLibNavigatorWidget,
QWidget#UBLibItemProperties,
QWidget#UBDownloadWidget,
QWidget#UBTeacherGuideWidget,
QWidget#UBFeatureProperties,
QWidget#UBFeaturesNavigatorWidget,
QWidget#PathList
QWidget#PathList,
QWidget#UBFeaturesCentralWidget
{
background: #EEEEEE;
border-radius: 10px;
border: 2px solid #999999;
}
QWidget#mAdditionalDataContainer
{
border-radius: 10px;
border: 2px solid #999999;
}
QWidget#UBMediaVideoContainer
{
background: #000000;
@ -33,12 +39,9 @@ QListView
border: 0px;
}
QWidget#UBFeaturesWebView
QWidget#UBFeatureProperties
{
background: #EEEEEE;
border-radius : 10px;
border: 2px solid #999999;
border: 2px;
}
QWebView#SearchEngineView

@ -1,5 +1,6 @@
#include <QGraphicsItem>
#include <QPointF>
#include <QtGui>
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
@ -9,7 +10,6 @@
#include "frameworks/UBFileSystemUtils.h"
#include "frameworks/UBPlatformUtils.h"
#include "core/UBDownloadManager.h"
#include "domain/UBAbstractWidget.h"
#include "domain/UBGraphicsScene.h"
@ -22,22 +22,172 @@
const QString UBFeaturesController::virtualRootName = "root";
UBFeature::UBFeature(const QString &url, const QPixmap &icon, const QString &name, const QUrl &realPath, UBFeatureElementType type)
: virtualDir(url), mThumbnail(icon), mName(name), mPath(realPath), elementType(type)
void UBFeaturesComputingThread::scanFS(const QUrl & currentPath, const QString & currVirtualPath)
{
Q_ASSERT(QFileInfo(currentPath.toLocalFile()).exists());
QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(currentPath.toLocalFile());
QFileInfoList::iterator fileInfo;
for ( fileInfo = fileInfoList.begin(); fileInfo != fileInfoList.end(); fileInfo += 1) {
if (abort) {
return;
}
QString fullFileName = fileInfo->absoluteFilePath();
UBFeatureElementType featureType = UBFeaturesController::fileTypeFromUrl(fullFileName);
QString fileName = fileInfo->fileName();
QImage icon = UBFeaturesController::getIcon(fullFileName, featureType);
if ( fullFileName.contains(".thumbnail."))
continue;
UBFeature testFeature(currVirtualPath, icon, fileName, QUrl::fromLocalFile(fullFileName), featureType);
emit sendFeature(testFeature);
emit featureSent();
// featuresList->append(testFeature);
// if ( favoriteSet->find( QUrl::fromLocalFile( fullFileName ) ) != favoriteSet->end() ) {
// featuresList->append( UBFeature( favoritePath, icon, fileName, QUrl::fromLocalFile( fullFileName ), featureType ) );
// }
if (featureType == FEATURE_FOLDER) {
scanFS(QUrl::fromLocalFile(fullFileName), currVirtualPath + "/" + fileName);
}
}
}
UBFeature::~UBFeature()
void UBFeaturesComputingThread::scanAll(QList<QPair<QUrl, QString> > pScanningData)
{
for (int i = 0; i < mChildren.count(); i++) {
delete mChildren[i];
for (int i = 0; i < pScanningData.count(); i++) {
if (abort) {
return;
}
QPair<QUrl, QString> curPair = pScanningData.at(i);
scanFS(curPair.first, curPair.second);
}
}
for (int i = 0; i < mParents.count(); i++) {
mParents[i]->mChildren.removeAll(this);
int UBFeaturesComputingThread::featuresCount(const QUrl &pPath)
{
int noItems = 0;
QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(pPath.toLocalFile());
QFileInfoList::iterator fileInfo;
for ( fileInfo = fileInfoList.begin(); fileInfo != fileInfoList.end(); fileInfo += 1) {
QString fullFileName = fileInfo->absoluteFilePath();
UBFeatureElementType featureType = UBFeaturesController::fileTypeFromUrl(fullFileName);
if (featureType != FEATURE_INVALID && !fullFileName.contains(".thumbnail.")) {
noItems++;
} else {
continue;
}
if (featureType == FEATURE_FOLDER) {
noItems += featuresCount(QUrl::fromLocalFile(fullFileName));
}
}
return noItems;
}
int UBFeaturesComputingThread::featuresCountAll(QList<QPair<QUrl, QString> > pScanningData)
{
int noItems = 0;
for (int i = 0; i < pScanningData.count(); i++) {
QPair<QUrl, QString> curPair = pScanningData.at(i);
noItems += featuresCount(curPair.first);
}
return noItems;
}
UBFeaturesComputingThread::UBFeaturesComputingThread(QObject *parent) :
QThread(parent)
{
restart = false;
abort = false;
}
void UBFeaturesComputingThread::compute(const QList<QPair<QUrl, QString> > &pScanningData)
{
QMutexLocker curLocker(&mMutex);
mScanningData = pScanningData;
if (!isRunning()) {
start(LowPriority);
} else {
restart = true;
mWaitCondition.wakeOne();
}
}
void UBFeaturesComputingThread::run()
{
forever {
qDebug() << "Custom thread started execution";
mMutex.lock();
QList<QPair<QUrl, QString> > searchData = mScanningData;
mMutex.unlock();
if (abort) {
return;
}
if (restart) {
break;
}
QTime curTime = QTime::currentTime();
int fsCnt = featuresCountAll(searchData);
int msecsto = curTime.msecsTo(QTime::currentTime());
qDebug() << "time on evaluation" << msecsto;
emit maxFilesCountEvaluated(fsCnt);
emit scanStarted();
scanAll(searchData);
emit scanFinished();
mMutex.lock();
if (!restart) {
mWaitCondition.wait(&mMutex);
}
restart = false;
mMutex.unlock();
}
}
UBFeaturesComputingThread::~UBFeaturesComputingThread()
{
qDebug() << "thread destructor catched";
mMutex.lock();
abort = true;
mWaitCondition.wakeOne();
mMutex.unlock();
quit();
}
UBFeature::UBFeature(const QString &url, const QImage &icon, const QString &name, const QUrl &realPath, UBFeatureElementType type)
: virtualDir(url), mThumbnail(icon), mName(name), mPath(realPath), elementType(type)
{
}
UBFeature::~UBFeature()
{
}
QString UBFeature::getUrl() const
{
if ( elementType == FEATURE_INTERNAL )
@ -108,18 +258,18 @@ UBFeaturesController::UBFeaturesController(QWidget *pParentWidget) :
mLibSearchDirectoryPath =QUrl::fromLocalFile(UBSettings::settings()->userSearchDirectory());
trashDirectoryPath = QUrl::fromLocalFile(UBSettings::userTrashDirPath());
rootElement = UBFeature(QString(), QPixmap( ":images/libpalette/home.png" ), "root", QUrl());
audiosElement = UBFeature( rootPath, QPixmap(":images/libpalette/AudiosCategory.svg"), "Audios" , mUserAudioDirectoryPath, FEATURE_CATEGORY);
moviesElement = UBFeature( rootPath, QPixmap(":images/libpalette/MoviesCategory.svg"), "Movies" , mUserVideoDirectoryPath, FEATURE_CATEGORY);
picturesElement = UBFeature( rootPath, QPixmap(":images/libpalette/PicturesCategory.svg"), "Pictures" , mUserPicturesDirectoryPath, FEATURE_CATEGORY);
flashElement = UBFeature( rootPath, QPixmap(":images/libpalette/FlashCategory.svg"), "Animations" , mUserAnimationDirectoryPath, FEATURE_CATEGORY);
interactElement = UBFeature( rootPath, QPixmap(":images/libpalette/InteractivesCategory.svg"), "Interactivities" , mLibInteractiveDirectoryPath, FEATURE_CATEGORY);
applicationsElement = UBFeature( rootPath, QPixmap(":images/libpalette/ApplicationsCategory.svg"), "Applications" , mUserInteractiveDirectoryPath, FEATURE_CATEGORY);
shapesElement = UBFeature( rootPath, QPixmap(":images/libpalette/ShapesCategory.svg"), "Shapes" , mLibShapesDirectoryPath, FEATURE_CATEGORY );
favoriteElement = UBFeature( rootPath, QPixmap(":images/libpalette/FavoritesCategory.svg"), "Favorites", QUrl("favorites"), FEATURE_FAVORITE );
webSearchElement = UBFeature( rootPath, QPixmap(":images/libpalette/WebSearchCategory.svg"), "Web search", mLibSearchDirectoryPath, FEATURE_CATEGORY);
rootElement = UBFeature(QString(), QImage( ":images/libpalette/home.png" ), "root", QUrl());
audiosElement = UBFeature( rootPath, QImage(":images/libpalette/AudiosCategory.svg"), "Audios" , mUserAudioDirectoryPath, FEATURE_CATEGORY);
moviesElement = UBFeature( rootPath, QImage(":images/libpalette/MoviesCategory.svg"), "Movies" , mUserVideoDirectoryPath, FEATURE_CATEGORY);
picturesElement = UBFeature( rootPath, QImage(":images/libpalette/PicturesCategory.svg"), "Pictures" , mUserPicturesDirectoryPath, FEATURE_CATEGORY);
flashElement = UBFeature( rootPath, QImage(":images/libpalette/FlashCategory.svg"), "Animations" , mUserAnimationDirectoryPath, FEATURE_CATEGORY);
interactElement = UBFeature( rootPath, QImage(":images/libpalette/InteractivesCategory.svg"), "Interactivities" , mLibInteractiveDirectoryPath, FEATURE_CATEGORY);
applicationsElement = UBFeature( rootPath, QImage(":images/libpalette/ApplicationsCategory.svg"), "Applications" , mUserInteractiveDirectoryPath, FEATURE_CATEGORY);
shapesElement = UBFeature( rootPath, QImage(":images/libpalette/ShapesCategory.svg"), "Shapes" , mLibShapesDirectoryPath, FEATURE_CATEGORY );
favoriteElement = UBFeature( rootPath, QImage(":images/libpalette/FavoritesCategory.svg"), "Favorites", QUrl("favorites"), FEATURE_FAVORITE );
webSearchElement = UBFeature( rootPath, QImage(":images/libpalette/WebSearchCategory.svg"), "Web search", mLibSearchDirectoryPath, FEATURE_CATEGORY);
trashElement = UBFeature( rootPath, QPixmap(":images/libpalette/TrashCategory.svg"), "Trash", trashDirectoryPath, FEATURE_TRASH );
trashElement = UBFeature( rootPath, QImage(":images/libpalette/TrashCategory.svg"), "Trash", trashDirectoryPath, FEATURE_TRASH );
featuresList = new QList <UBFeature>();
@ -142,7 +292,40 @@ UBFeaturesController::UBFeaturesController(QWidget *pParentWidget) :
featuresPathModel->setSourceModel(featuresModel);
connect(featuresModel, SIGNAL(dataRestructured()), featuresProxyModel, SLOT(invalidate()));
connect(&mCThread, SIGNAL(sendFeature(UBFeature)), featuresModel, SLOT(addItem(UBFeature)));
connect(&mCThread, SIGNAL(featureSent()), this, SIGNAL(featureAddedFromThread()));
connect(&mCThread, SIGNAL(scanStarted()), this, SIGNAL(scanStarted()));
connect(&mCThread, SIGNAL(scanFinished()), this, SIGNAL(scanFinished()));
connect(&mCThread, SIGNAL(maxFilesCountEvaluated(int)), this, SIGNAL(maxFilesCountEvaluated(int)));
//Very unsafe function. Considering using deleteLater() instead
// connect(qApp, SIGNAL(aboutToQuit()), &mCThread, SLOT(terminate()));
QTimer::singleShot(0, this, SLOT(startThread()));
// startThread();
}
void UBFeaturesController::startThread()
{
QList<QPair<QUrl, QString> > computingData;
computingData << QPair<QUrl, QString>(mLibAudiosDirectoryPath, audiosPath)
<< QPair<QUrl, QString>(mLibVideosDirectoryPath, moviesPath)
<< QPair<QUrl, QString>(mLibAnimationsDirectoryPath, flashPath)
<< QPair<QUrl, QString>(mLibPicturesDirectoryPath, picturesPath)
<< QPair<QUrl, QString>(mUserInteractiveDirectoryPath, appPath)
<< QPair<QUrl, QString>(mUserAudioDirectoryPath, audiosPath)
<< QPair<QUrl, QString>(mUserPicturesDirectoryPath, picturesPath)
<< QPair<QUrl, QString>(mUserVideoDirectoryPath, moviesPath)
<< QPair<QUrl, QString>(mUserAnimationDirectoryPath, flashPath)
<< QPair<QUrl, QString>(mLibApplicationsDirectoryPath, appPath)
<< QPair<QUrl, QString>(mLibShapesDirectoryPath, shapesPath)
<< QPair<QUrl, QString>(mLibInteractiveDirectoryPath, interactPath)
<< QPair<QUrl, QString>(trashDirectoryPath, trashPath)
<< QPair<QUrl, QString>(mLibSearchDirectoryPath, rootPath + "/" + "Web search" );
mCThread.compute(computingData);
}
void UBFeaturesController::scanFS()
@ -166,29 +349,55 @@ void UBFeaturesController::scanFS()
QList <UBToolsManager::UBToolDescriptor> tools = UBToolsManager::manager()->allTools();
foreach (UBToolsManager::UBToolDescriptor tool, tools) {
featuresList->append(UBFeature(appPath, tool.icon, tool.label, QUrl(tool.id), FEATURE_INTERNAL));
featuresList->append(UBFeature(appPath, tool.icon.toImage(), tool.label, QUrl(tool.id), FEATURE_INTERNAL));
if (favoriteSet->find(QUrl(tool.id)) != favoriteSet->end()) {
featuresList->append(UBFeature(favoritePath, tool.icon, tool.label, QUrl(tool.id), FEATURE_INTERNAL));
featuresList->append(UBFeature(favoritePath, tool.icon.toImage(), tool.label, QUrl(tool.id), FEATURE_INTERNAL));
}
}
QTime time = QTime::currentTime();
//Claudio:
// don't change the order of the scans
fileSystemScan( mLibAudiosDirectoryPath, audiosPath);
fileSystemScan( mLibVideosDirectoryPath, moviesPath);
fileSystemScan( mLibAnimationsDirectoryPath, flashPath);
fileSystemScan( mLibPicturesDirectoryPath, picturesPath );
// fileSystemScan( mLibAudiosDirectoryPath, audiosPath);
// fileSystemScan( mLibVideosDirectoryPath, moviesPath);
// fileSystemScan( mLibAnimationsDirectoryPath, flashPath);
// fileSystemScan( mLibPicturesDirectoryPath, picturesPath );
fileSystemScan( mUserInteractiveDirectoryPath, appPath );
fileSystemScan( mUserAudioDirectoryPath, audiosPath );
fileSystemScan( mUserPicturesDirectoryPath, picturesPath );
fileSystemScan( mUserVideoDirectoryPath, moviesPath );
fileSystemScan( mUserAnimationDirectoryPath, flashPath );
// fileSystemScan( mUserInteractiveDirectoryPath, appPath );
// fileSystemScan( mUserAudioDirectoryPath, audiosPath );
// fileSystemScan( mUserPicturesDirectoryPath, picturesPath );
// fileSystemScan( mUserVideoDirectoryPath, moviesPath );
// fileSystemScan( mUserAnimationDirectoryPath, flashPath );
fileSystemScan( mLibApplicationsDirectoryPath, appPath );
fileSystemScan( mLibShapesDirectoryPath, shapesPath );
fileSystemScan( mLibInteractiveDirectoryPath, interactPath );
fileSystemScan( trashDirectoryPath, trashPath );
fileSystemScan( mLibSearchDirectoryPath, rootPath + "/" + "Web search" );
// fileSystemScan( mLibApplicationsDirectoryPath, appPath );
// fileSystemScan( mLibShapesDirectoryPath, shapesPath );
// fileSystemScan( mLibInteractiveDirectoryPath, interactPath );
// fileSystemScan( trashDirectoryPath, trashPath );
// fileSystemScan( mLibSearchDirectoryPath, rootPath + "/" + "Web search" );
int i =0;
i += featuresCount(mLibAudiosDirectoryPath);
i += featuresCount(mLibVideosDirectoryPath);
i += featuresCount(mLibAnimationsDirectoryPath);
i += featuresCount(mLibPicturesDirectoryPath);
i += featuresCount(mUserInteractiveDirectoryPath);
i += featuresCount(mUserAudioDirectoryPath);
i += featuresCount(mUserPicturesDirectoryPath);
i += featuresCount(mUserVideoDirectoryPath);
i += featuresCount(mUserAnimationDirectoryPath);
i += featuresCount(mLibApplicationsDirectoryPath);
i += featuresCount(mLibShapesDirectoryPath);
i += featuresCount(mLibInteractiveDirectoryPath);
i += featuresCount(trashDirectoryPath);
i += featuresCount(mLibSearchDirectoryPath);
int msecs = QTime(time).msecsTo(QTime::currentTime());
qDebug() << "Loading library" << msecs << "msecs\nNumber of elements" << i;
// emit TopIndexingLimitSet(i);
// emit indexingProgressValueChanged(i / 4);
}
void UBFeaturesController::fileSystemScan(const QUrl & currentPath, const QString & currVirtualPath)
@ -201,7 +410,7 @@ void UBFeaturesController::fileSystemScan(const QUrl & currentPath, const QStrin
UBFeatureElementType featureType = fileTypeFromUrl(fullFileName);
QString fileName = fileInfo->fileName();
QPixmap icon(getIcon(fullFileName, featureType));
QImage icon = getIcon(fullFileName, featureType);
if ( fullFileName.contains(".thumbnail."))
continue;
@ -220,6 +429,31 @@ void UBFeaturesController::fileSystemScan(const QUrl & currentPath, const QStrin
}
}
int UBFeaturesController::featuresCount(const QUrl &currPath)
{
int noItems = 0;
QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(currPath.toLocalFile());
QFileInfoList::iterator fileInfo;
for ( fileInfo = fileInfoList.begin(); fileInfo != fileInfoList.end(); fileInfo += 1) {
QString fullFileName = fileInfo->absoluteFilePath();
UBFeatureElementType featureType = fileTypeFromUrl(fullFileName);
if (featureType != FEATURE_INVALID && !fullFileName.contains(".thumbnail.")) {
noItems++;
} else {
continue;
}
if (featureType == FEATURE_FOLDER) {
noItems += featuresCount(QUrl::fromLocalFile(fullFileName));
}
}
return noItems;
}
void UBFeaturesController::loadFavoriteList()
{
favoriteSet = new QSet<QUrl>();
@ -260,7 +494,7 @@ void UBFeaturesController::addToFavorite( const QUrl &path )
{
QFileInfo fileInfo( filePath );
QString fileName = fileInfo.fileName();
UBFeature elem( favoritePath, getIcon( filePath, FEATURE_CATEGORY ), fileName, path, fileTypeFromUrl(filePath) );
UBFeature elem(favoritePath, getIcon( filePath, FEATURE_CATEGORY ), fileName, path, fileTypeFromUrl(filePath) );
favoriteSet->insert( path );
saveFavoriteList();
@ -318,33 +552,30 @@ UBFeatureElementType UBFeaturesController::fileTypeFromUrl( const QString &path
return fileType;
}
QPixmap UBFeaturesController::getIcon(const QString &path, UBFeatureElementType pFType = FEATURE_INVALID)
QImage UBFeaturesController::getIcon(const QString &path, UBFeatureElementType pFType = FEATURE_INVALID)
{
if ( pFType == FEATURE_FOLDER )
{
return QPixmap(":images/libpalette/folder.svg");
}
else if ( pFType == FEATURE_INTERACTIVE )
{
return QPixmap( UBAbstractWidget::iconFilePath( QUrl::fromLocalFile(path) ) );
if (pFType == FEATURE_FOLDER) {
return QImage(":images/libpalette/folder.svg");
} else if (pFType == FEATURE_INTERACTIVE) {
return QImage(UBAbstractWidget::iconFilePath(QUrl::fromLocalFile(path)));
}
if ( path.contains("uniboardTool://") )
{
return QPixmap( UBToolsManager::manager()->iconFromToolId(path) );
}
if ( UBFileSystemUtils::mimeTypeFromFileName(path).contains("application") )
{
return QPixmap( UBAbstractWidget::iconFilePath( QUrl::fromLocalFile(path) ) );
if ( path.contains("uniboardTool://") ) {
return QImage( UBToolsManager::manager()->iconFromToolId(path) );
} if ( UBFileSystemUtils::mimeTypeFromFileName(path).contains("application")) {
return QImage( UBAbstractWidget::iconFilePath( QUrl::fromLocalFile(path) ) );
}
QPixmap thumb;
QString thumbnailPath = UBFileSystemUtils::thumbnailPath( path );
QImage thumb;
QString thumbnailPath = UBFileSystemUtils::thumbnailPath(path);
if ( QFileInfo( thumbnailPath ).exists() )
thumb = QPixmap( thumbnailPath );
thumb = QImage( thumbnailPath );
else thumb = createThumbnail( path );
return thumb;
}
@ -354,12 +585,11 @@ bool UBFeaturesController::isDeletable( const QUrl &url )
return type == FEATURE_ITEM;
}
QPixmap UBFeaturesController::createThumbnail(const QString &path)
QImage UBFeaturesController::createThumbnail(const QString &path)
{
QString thumbnailPath = UBFileSystemUtils::thumbnailPath(path);
QString mimetype = UBFileSystemUtils::mimeTypeFromFileName(path);
QString extension = QFileInfo(path).completeSuffix();
//UBApplication::showMessage(tr("Creating image thumbnail for %1.").arg(pElement->name()));
if ( mimetype.contains("audio" ))
thumbnailPath = ":images/libpalette/soundIcon.svg";
@ -373,7 +603,7 @@ QPixmap UBFeaturesController::createThumbnail(const QString &path)
}
else
{
QPixmap pix(path);
QImage pix(path);
if (!pix.isNull())
{
pix = pix.scaledToWidth(qMin(UBSettings::maxThumbnailWidth, pix.width()), Qt::SmoothTransformation);
@ -386,7 +616,7 @@ QPixmap UBFeaturesController::createThumbnail(const QString &path)
}
}
return QPixmap(thumbnailPath);
return QImage(thumbnailPath);
}
void UBFeaturesController::importImage(const QImage &image, const QString &fileName)
@ -412,7 +642,7 @@ void UBFeaturesController::importImage( const QImage &image, const UBFeature &de
QString filePath = dest.getFullPath().toLocalFile() + "/" + mFileName;
image.save(filePath);
QPixmap thumb = createThumbnail( filePath );
QImage thumb = createThumbnail( filePath );
UBFeature resultItem = UBFeature( dest.getFullVirtualPath(), thumb, mFileName,
QUrl::fromLocalFile( filePath ), FEATURE_ITEM );
@ -420,7 +650,7 @@ void UBFeaturesController::importImage( const QImage &image, const UBFeature &de
}
void UBFeaturesController::addNewFolder(const QString &name)
void UBFeaturesController::addNewFolder(QString name)
{
QString path = currentElement.getFullPath().toLocalFile() + "/" + name;
@ -432,7 +662,7 @@ void UBFeaturesController::addNewFolder(const QString &name)
if(!QFileInfo(path).exists()) {
QDir().mkpath(path);
}
UBFeature newFeatureFolder = UBFeature( currentElement.getFullVirtualPath(), QPixmap(":images/libpalette/folder.svg"),
UBFeature newFeatureFolder = UBFeature( currentElement.getFullVirtualPath(), QImage(":images/libpalette/folder.svg"),
name, QUrl::fromLocalFile( path ), FEATURE_FOLDER );
featuresModel->addItem( newFeatureFolder );
@ -523,7 +753,7 @@ UBFeature UBFeaturesController::moveItemToFolder( const QUrl &url, const UBFeatu
deleteItem( url );
}
QPixmap thumb = getIcon( newFullPath );
QImage thumb = getIcon( newFullPath );
UBFeatureElementType type = FEATURE_ITEM;
if ( UBFileSystemUtils::mimeTypeFromFileName( newFullPath ).contains("application") )
@ -550,9 +780,24 @@ void UBFeaturesController::siftElements(const QString &pSiftValue)
featuresPathModel->invalidate();
}
UBFeature UBFeaturesController::getFeature(const QModelIndex &index, QListView *pOnView)
UBFeature UBFeaturesController::getFeature(const QModelIndex &index, const QString &listName)
{
return qobject_cast<QSortFilterProxyModel *>(pOnView->model())->data(index, Qt::UserRole + 1).value<UBFeature>();
// QSortFilterProxyModel *model = qobject_cast<QSortFilterProxyModel *>(pOnView->model());
QAbstractItemModel *model = 0;
if (listName == UBFeaturesWidget::objNamePathList) {
model = featuresPathModel;
} else if (listName == UBFeaturesWidget::objNameFeatureList) {
model = curListModel;
}
if (model) {
return model->data(index, Qt::UserRole + 1).value<UBFeature>();
}
return UBFeature();
// return pOnView->model()->data(index, Qt::UserRole + 1).value<UBFeature>(); /*featuresSearchModel->data(index, Qt::UserRole + 1).value<UBFeature>()*/;
}
void UBFeaturesController::searchStarted(const QString &pattern, QListView *pOnView)
@ -561,11 +806,13 @@ void UBFeaturesController::searchStarted(const QString &pattern, QListView *pOnV
pOnView->setModel(featuresProxyModel);
featuresProxyModel->invalidate();
} else if ( pattern.size() > 2 ) {
curListModel = featuresProxyModel;
} else if ( pattern.size() > 1 ) {
featuresSearchModel->setFilterWildcard( "*" + pattern + "*" );
pOnView->setModel(featuresSearchModel );
featuresSearchModel->invalidate();
curListModel = featuresSearchModel;
}
}
@ -599,7 +846,7 @@ UBFeature UBFeaturesController::copyItemToFolder( const QUrl &url, const UBFeatu
if (!sourcePath.compare(newFullPath, Qt::CaseInsensitive))
QFile(sourcePath).copy(newFullPath);
QPixmap thumb = getIcon(newFullPath);
QImage thumb = getIcon(newFullPath);
UBFeatureElementType type = FEATURE_ITEM;
if (UBFileSystemUtils::mimeTypeFromFileName(newFullPath).contains("application"))
@ -641,7 +888,7 @@ void UBFeaturesController::moveExternalData(const QUrl &url, const UBFeature &de
Q_ASSERT(QFileInfo(newFullPath).exists());
QPixmap thumb = getIcon(newFullPath, type);
QImage thumb = getIcon(newFullPath, type);
UBFeature newElement(destVirtualPath, thumb, name, QUrl::fromLocalFile(newFullPath), type);
featuresModel->addItem(newElement);
@ -710,6 +957,7 @@ void UBFeaturesController::assignFeaturesListVeiw(UBFeaturesListView *pList)
pList->setItemDelegate(itemDelegate);
pList->setModel(featuresProxyModel);
curListModel = featuresProxyModel;
}
void UBFeaturesController::assignPathListView(UBFeaturesListView *pList)

@ -12,6 +12,10 @@
#include <QUrl>
#include <QByteArray>
#include <QtGui>
#include <QImage>
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
class UBFeaturesModel;
class UBFeaturesItemDelegate;
@ -20,8 +24,45 @@ class UBFeaturesProxyModel;
class UBFeaturesSearchProxyModel;
class UBFeaturesPathProxyModel;
class UBFeaturesListView;
class UBFeature;
class UBFeaturesComputingThread : public QThread
{
Q_OBJECT
public:
explicit UBFeaturesComputingThread(QObject *parent = 0);
virtual ~UBFeaturesComputingThread();
void compute(const QList<QPair<QUrl, QString> > &pScanningData);
protected:
void run();
signals:
void sendFeature(UBFeature pFeature);
void featureSent();
void scanStarted();
void scanFinished();
void maxFilesCountEvaluated(int max);
public slots:
private:
void scanFS(const QUrl & currentPath, const QString & currVirtualPath);
void scanAll(QList<QPair<QUrl, QString> > pScanningData);
int featuresCount(const QUrl &pPath);
int featuresCountAll(QList<QPair<QUrl, QString> > pScanningData);
private:
QMutex mMutex;
QWaitCondition mWaitCondition;
QUrl mScanningPath;
QString mScanningVirtualPath;
QList<QPair<QUrl, QString> > mScanningData;
bool restart;
bool abort;
};
//#include "UBDockPaletteWidget.h"
enum UBFeatureElementType
{
@ -41,12 +82,12 @@ class UBFeature
{
public:
UBFeature() {;}
//UBFeature(const UBFeature &f);
UBFeature(const QString &url, const QPixmap &icon, const QString &name, const QUrl &realPath, UBFeatureElementType type = FEATURE_CATEGORY);
// UBFeature(const UBFeature &f);
UBFeature(const QString &url, const QImage &icon, const QString &name, const QUrl &realPath, UBFeatureElementType type = FEATURE_CATEGORY);
// UBFeature();
virtual ~UBFeature();
QString getName() const { return mName; }
QPixmap getThumbnail() const {return mThumbnail;}
QImage getThumbnail() const {return mThumbnail;}
QString getVirtualPath() const { return virtualDir; }
//QString getPath() const { return mPath; };
QUrl getFullPath() const { return mPath; }
@ -64,20 +105,13 @@ public:
const QMap<QString,QString> & getMetadata() const { return metadata; }
void setMetadata( const QMap<QString,QString> &data ) { metadata = data; }
bool hasChildren() const {return mChildren.count();}
bool hasParents() const {return mParents.count();}
bool hasRelationships() const {return mChildren.count() && mParents.count();}
private:
QString virtualDir;
QPixmap mThumbnail;
QImage mThumbnail;
QString mName;
QUrl mPath;
UBFeatureElementType elementType;
QMap<QString,QString> metadata;
QList<UBFeature*> mChildren;
QList<UBFeature*> mParents;
};
Q_DECLARE_METATYPE( UBFeature )
@ -111,7 +145,7 @@ public:
void rescanModel();
void siftElements(const QString &pSiftValue);
//TODO make less complicated for betteer maintainence
UBFeature getFeature(const QModelIndex &index, QListView *pOnView);
UBFeature getFeature(const QModelIndex &index, const QString &listName);
void searchStarted(const QString &pattern, QListView *pOnView);
void refreshModels();
@ -119,18 +153,17 @@ public:
void deleteItem(const UBFeature &pFeature);
bool isTrash( const QUrl &url );
void moveToTrash(UBFeature feature, bool deleteManualy = false);
void addNewFolder(const QString &name);
void addToFavorite( const QUrl &path );
void removeFromFavorite(const QUrl &path, bool deleteManualy = false);
void importImage(const QImage &image, const QString &fileName = QString());
void importImage( const QImage &image, const UBFeature &destination, const QString &fileName = QString() );
void fileSystemScan(const QUrl &currPath, const QString & currVirtualPath);
int featuresCount(const QUrl &currPath);
static UBFeatureElementType fileTypeFromUrl( const QString &path );
static QString fileNameFromUrl( const QUrl &url );
static QPixmap getIcon( const QString &path, UBFeatureElementType pFType );
static QImage getIcon( const QString &path, UBFeatureElementType pFType );
static bool isDeletable( const QUrl &url );
static char featureTypeSplitter() {return ':';}
@ -139,6 +172,16 @@ public:
void assignFeaturesListVeiw(UBFeaturesListView *pList);
void assignPathListView(UBFeaturesListView *pList);
signals:
void maxFilesCountEvaluated(int pLimit);
void scanStarted();
void scanFinished();
void featureAddedFromThread();
private slots:
void addNewFolder(QString name);
void startThread();
private:
UBFeaturesItemDelegate *itemDelegate;
@ -149,16 +192,16 @@ private:
UBFeaturesSearchProxyModel *featuresSearchModel;
UBFeaturesPathProxyModel *featuresPathModel;
QAbstractItemModel *curListModel;
UBFeaturesComputingThread mCThread;
private:
static QPixmap createThumbnail(const QString &path);
static QImage createThumbnail(const QString &path);
//void addImageToCurrentPage( const QString &path );
void loadFavoriteList();
void saveFavoriteList();
QList <UBFeature> *featuresList;
QUrl mUserAudioDirectoryPath;

@ -53,6 +53,7 @@ UBFeaturesActionBar::UBFeaturesActionBar( UBFeaturesController *controller, QWid
//mpSearchBtn = new UBActionButton(this, mpSearchAction);
mpRescanModelBtn = new UBActionButton(this, mpRescanModelAction);
mpRescanModelBtn->hide();
mpDeleteBtn = new UBActionButton(this, mpDeleteAction);
mpCloseBtn = new UBActionButton(this, mpCloseAction);
@ -124,7 +125,7 @@ void UBFeaturesActionBar::setButtons()
mpNewFolderBtn->show();
mpNewFolderBtn->setEnabled(true);
mpDeleteBtn->setEnabled(true);
mpRescanModelBtn->show();
// mpRescanModelBtn->show();
break;
case IN_ROOT:
mpFavoriteBtn->show();
@ -136,7 +137,7 @@ void UBFeaturesActionBar::setButtons()
mpNewFolderBtn->show();
mpNewFolderBtn->setEnabled(false);
mpDeleteBtn->setEnabled(false);
mpRescanModelBtn->show();
// mpRescanModelBtn->show();
break;
case IN_PROPERTIES:
mpFavoriteBtn->show();
@ -147,7 +148,7 @@ void UBFeaturesActionBar::setButtons()
mpCloseBtn->hide();
mpRemoveFavoriteBtn->hide();
mpNewFolderBtn->hide();
mpRescanModelBtn->hide();
// mpRescanModelBtn->hide();
break;
case IN_FAVORITE:
mpFavoriteBtn->hide();
@ -158,7 +159,7 @@ void UBFeaturesActionBar::setButtons()
mpCloseBtn->hide();
mpRemoveFavoriteBtn->show();
mpNewFolderBtn->hide();
mpRescanModelBtn->hide();
// mpRescanModelBtn->hide();
break;
case IN_TRASH:
mpFavoriteBtn->hide();
@ -171,7 +172,7 @@ void UBFeaturesActionBar::setButtons()
mpCloseBtn->hide();
//mpRemoveFavoriteBtn->show();
mpNewFolderBtn->hide();
mpRescanModelBtn->hide();
// mpRescanModelBtn->hide();
break;
default:
break;

@ -8,9 +8,14 @@
#include "core/UBDownloadManager.h"
#include "globals/UBGlobals.h"
#include "board/UBBoardController.h"
#include "globals/UBGlobals.h"
const char *UBFeaturesWidget::objNamePathList = "PathList";
const char *UBFeaturesWidget::objNameFeatureList = "FeatureList";
const char *objNamePathList = "PathList";
const char *objNameFeatureList = "FeatureList";
const QString UBFeaturesNewFolderDialog::acceptText = tr("Accept");
const QString UBFeaturesNewFolderDialog::cancelText = tr("Cancel");
const QString UBFeaturesNewFolderDialog::labelText = tr("Enter a new folder name");
const QMargins FeatureListMargins(0, 0, 0, 30);
const int FeatureListBorderOffset = 10;
@ -43,39 +48,19 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name)
pathListView = new UBFeaturesListView(this, objNamePathList);
controller->assignPathListView(pathListView);
//Maintains the view of the main part of the palette. Consists of
//mNavigator
//featureProperties
//webVeiw
stackedWidget = new QStackedWidget(this);
//Main features icon view with QSlider on the bottom
mNavigator = new UBFeaturesNavigatorWidget(this);
controller->assignFeaturesListVeiw(mNavigator->listView());
mNavigator->setSliderPosition(UBSettings::settings()->featureSliderPosition->get().toInt());
//Specifies the properties of a standalone element
featureProperties = new UBFeatureProperties(this);
//Used to show search bar on the search widget
webView = new UBFeaturesWebView(this);
//filling stackwidget
stackedWidget->addWidget(mNavigator);
stackedWidget->addWidget(featureProperties);
stackedWidget->addWidget(webView);
stackedWidget->setCurrentIndex(ID_LISTVIEW);
currentStackedWidget = ID_LISTVIEW;
centralWidget = new UBFeaturesCentralWidget(this);
controller->assignFeaturesListVeiw(centralWidget->listView());
centralWidget->setSliderPosition(UBSettings::settings()->featureSliderPosition->get().toInt());
//Bottom actionbar for DnD, quick search etc
mActionBar = new UBFeaturesActionBar(controller, this);
//Filling main layout
layout->addWidget(pathListView);
layout->addWidget(stackedWidget);
layout->addWidget(centralWidget);
layout->addWidget(mActionBar);
connect(mNavigator->listView(), SIGNAL(clicked(const QModelIndex &)), this, SLOT(currentSelected(const QModelIndex &)));
connect(centralWidget->listView(), SIGNAL(clicked(const QModelIndex &)), this, SLOT(currentSelected(const QModelIndex &)));
connect(mActionBar, SIGNAL(searchElement(const QString &)), this, SLOT( searchStarted(const QString &)));
connect(mActionBar, SIGNAL(newFolderToCreate()), this, SLOT(createNewFolder()));
connect(mActionBar, SIGNAL(deleteElements(const UBFeaturesMimeData *)), this, SLOT(deleteElements(const UBFeaturesMimeData *)));
@ -90,6 +75,12 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name)
connect(UBApplication::boardController, SIGNAL(displayMetadata(QMap<QString,QString>)), this, SLOT(onDisplayMetadata( QMap<QString,QString>)));
connect(UBDownloadManager::downloadManager(), SIGNAL( addDownloadedFileToLibrary( bool, QUrl, QString, QByteArray))
, this, SLOT(onAddDownloadedFileToLibrary(bool, QUrl, QString,QByteArray)));
connect(centralWidget, SIGNAL(lockMainWidget(bool)), this, SLOT(lockIt(bool)));
connect(centralWidget, SIGNAL(createNewFolderSignal(QString)), controller, SLOT(addNewFolder(QString)));
connect(controller, SIGNAL(scanStarted()), centralWidget, SLOT(scanStarted()));
connect(controller, SIGNAL(scanFinished()), centralWidget, SLOT(scanFinished()));
connect(controller, SIGNAL(maxFilesCountEvaluated(int)), centralWidget, SIGNAL(maxFilesCountEvaluated(int)));
connect(controller, SIGNAL(featureAddedFromThread()), centralWidget, SLOT(increaseStatusBarValue()));
}
UBFeaturesWidget::~UBFeaturesWidget()
@ -100,7 +91,7 @@ UBFeaturesWidget::~UBFeaturesWidget()
void UBFeaturesWidget::searchStarted(const QString &pattern)
{
controller->searchStarted(pattern, mNavigator->listView());
controller->searchStarted(pattern, centralWidget->listView());
}
void UBFeaturesWidget::currentSelected(const QModelIndex &current)
@ -110,25 +101,16 @@ void UBFeaturesWidget::currentSelected(const QModelIndex &current)
return;
}
//Calling to reset the model for listView. Maybe separate function needed
controller->searchStarted("", mNavigator->listView());
QString objName = sender()->objectName();
if (objName.isEmpty()) {
qWarning() << "incorrrect sender";
} else if (objName == objNamePathList) {
//Calling to reset the model for listView. Maybe separate function needed
controller->searchStarted("", centralWidget->listView());
}
QListView *calledList = 0;
if (objName == objNamePathList) {
calledList = pathListView;
} else if (objName == objNameFeatureList) {
calledList = mNavigator->listView();
}
UBFeature feature = controller->getFeature(current, calledList);
// QSortFilterProxyModel *model = dynamic_cast<QSortFilterProxyModel *>( mNavigator->listView()->model() );
// UBFeature feature = model->data(current, Qt::UserRole + 1).value<UBFeature>();
UBFeature feature = controller->getFeature(current, objName);
if ( feature.isFolder() ) {
QString newPath = feature.getFullVirtualPath();
@ -136,7 +118,7 @@ void UBFeaturesWidget::currentSelected(const QModelIndex &current)
controller->setCurrentElement(feature);
controller->siftElements(newPath);
switchToListView();
centralWidget->switchTo(UBFeaturesCentralWidget::MainList);
if ( feature.getType() == FEATURE_FAVORITE ) {
mActionBar->setCurrentState( IN_FAVORITE );
@ -145,35 +127,24 @@ void UBFeaturesWidget::currentSelected(const QModelIndex &current)
mActionBar->setCurrentState( IN_ROOT );
} else if (feature.getType() == FEATURE_TRASH) {
mActionBar->setCurrentState( IN_TRASH );
mActionBar->setCurrentState(IN_TRASH);
} else {
mActionBar->setCurrentState( IN_FOLDER );
mActionBar->setCurrentState(IN_FOLDER);
}
} else if ( feature.getType() == FEATURE_SEARCH ) {
webView->showElement( feature );
switchToWebView();
} else if (feature.getType() == FEATURE_SEARCH) {
centralWidget->showElement(feature, UBFeaturesCentralWidget::FeaturesWebView);
} else {
featureProperties->showElement( feature );
switchToProperties();
centralWidget->showElement(feature, UBFeaturesCentralWidget::FeaturePropertiesList);
mActionBar->setCurrentState( IN_PROPERTIES );
}
}
void UBFeaturesWidget::createNewFolder()
{
if (!mkFolderDlg)
{
mkFolderDlg = new UBNewFolderDlg(this);
connect (mkFolderDlg, SIGNAL(accepted()), this, SLOT(addFolder()));
}
mkFolderDlg->setWindowFlags(Qt::WindowStaysOnTopHint);
mkFolderDlg->resize(this->size().width()-20 ,80);
mkFolderDlg->move(5,this->size().height()-200);
mkFolderDlg->show();
centralWidget->showAdditionalData(UBFeaturesCentralWidget::NewFolderDialog, UBFeaturesCentralWidget::Modal);
}
void UBFeaturesWidget::addFolder()
@ -203,7 +174,7 @@ void UBFeaturesWidget::deleteElements( const UBFeaturesMimeData * mimeData )
void UBFeaturesWidget::deleteSelectedElements()
{
QModelIndexList selected = mNavigator->listView()->selectionModel()->selectedIndexes();
QModelIndexList selected = centralWidget->listView()->selectionModel()->selectedIndexes();
foreach ( QModelIndex sel, selected )
{
@ -224,6 +195,14 @@ void UBFeaturesWidget::rescanModel()
controller->rescanModel();
}
void UBFeaturesWidget::lockIt(bool pLock)
{
mActionBar->setEnabled(!pLock);
pathListView->setEnabled(!pLock);
centralWidget->setLockedExcludingAdditional(pLock);
// pathListView->setLocked(true);
}
void UBFeaturesWidget::addToFavorite( const UBFeaturesMimeData * mimeData )
{
if ( !mimeData->hasUrls() )
@ -253,7 +232,7 @@ void UBFeaturesWidget::onDisplayMetadata( QMap<QString,QString> metadata )
{
QString previewImageUrl;
switch (UBFileSystemUtils::mimeTypeFromUrl(QUrl(metadata["Url"])))
switch (static_cast<int>(UBFileSystemUtils::mimeTypeFromUrl(QUrl(metadata["Url"]))))
{
case UBMimeType::RasterImage:
case UBMimeType::VectorImage:
@ -282,11 +261,10 @@ void UBFeaturesWidget::onDisplayMetadata( QMap<QString,QString> metadata )
}break;
}
UBFeature feature( QString(), QPixmap(previewImageUrl), QString(), metadata["Url"], FEATURE_ITEM );
UBFeature feature( QString(), QImage(previewImageUrl), QString(), metadata["Url"], FEATURE_ITEM );
feature.setMetadata( metadata );
featureProperties->showElement( feature );
switchToProperties();
centralWidget->showElement(feature, UBFeaturesCentralWidget::FeaturePropertiesList);
mActionBar->setCurrentState( IN_PROPERTIES );
}
@ -298,12 +276,14 @@ void UBFeaturesWidget::onPreviewLoaded(int id, bool pSuccess, QUrl sourceUrl, QS
Q_UNUSED(isBackground);
Q_UNUSED(pSize);
Q_UNUSED(pPos);
Q_UNUSED(sourceUrl);
Q_UNUSED(pContentTypeHeader)
QImage img;
img.loadFromData(pData);
QPixmap pix = QPixmap::fromImage(img);
featureProperties->setOrigPixmap(pix);
featureProperties->setThumbnail(pix);
centralWidget->setPropertiesPixmap(pix);
centralWidget->setPropertiesThumbnail(pix);
}
void UBFeaturesWidget::onAddDownloadedFileToLibrary(bool pSuccess, QUrl sourceUrl, QString pContentHeader, QByteArray pData)
@ -318,14 +298,14 @@ void UBFeaturesWidget::onAddDownloadedFileToLibrary(bool pSuccess, QUrl sourceUr
void UBFeaturesWidget::addElementsToFavorite()
{
if ( currentStackedWidget == ID_PROPERTIES ) {
UBFeature feature = featureProperties->getCurrentElement();
if ( centralWidget->currentView() == UBFeaturesCentralWidget::FeaturePropertiesList ) {
UBFeature feature = centralWidget->getCurElementFromProperties();
if ( feature != UBFeature() && !UBApplication::isFromWeb(feature.getFullPath().toString())) {
controller->addToFavorite( feature.getFullPath() );
}
} else if ( currentStackedWidget == ID_LISTVIEW ) {
QModelIndexList selected = mNavigator->listView()->selectionModel()->selectedIndexes();
} else if ( centralWidget->currentView() == UBFeaturesCentralWidget::MainList ) {
QModelIndexList selected = centralWidget->listView()->selectionModel()->selectedIndexes();
for ( int i = 0; i < selected.size(); ++i ) {
UBFeature feature = selected.at(i).data( Qt::UserRole + 1 ).value<UBFeature>();
controller->addToFavorite(feature.getFullPath());
@ -337,7 +317,7 @@ void UBFeaturesWidget::addElementsToFavorite()
void UBFeaturesWidget::removeElementsFromFavorite()
{
QModelIndexList selected = mNavigator->listView()->selectionModel()->selectedIndexes();
QModelIndexList selected = centralWidget->listView()->selectionModel()->selectedIndexes();
QList <QUrl> items;
for ( int i = 0; i < selected.size(); ++i ) {
UBFeature feature = selected.at(i).data( Qt::UserRole + 1 ).value<UBFeature>();
@ -363,20 +343,20 @@ void UBFeaturesWidget::resizeEvent(QResizeEvent *event)
void UBFeaturesWidget::switchToListView()
{
stackedWidget->setCurrentIndex(ID_LISTVIEW);
currentStackedWidget = ID_LISTVIEW;
// stackedWidget->setCurrentIndex(ID_LISTVIEW);
// currentStackedWidget = ID_LISTVIEW;
}
void UBFeaturesWidget::switchToProperties()
{
stackedWidget->setCurrentIndex(ID_PROPERTIES);
currentStackedWidget = ID_PROPERTIES;
// stackedWidget->setCurrentIndex(ID_PROPERTIES);
// currentStackedWidget = ID_PROPERTIES;
}
void UBFeaturesWidget::switchToWebView()
{
stackedWidget->setCurrentIndex(ID_WEBVIEW);
currentStackedWidget = ID_WEBVIEW;
// stackedWidget->setCurrentIndex(ID_WEBVIEW);
// currentStackedWidget = ID_WEBVIEW;
}
QStringList UBFeaturesMimeData::formats() const
@ -390,7 +370,7 @@ void UBFeaturesWidget::importImage(const QImage &image, const QString &fileName)
}
UBFeaturesListView::UBFeaturesListView( QWidget* parent, const char* name )
: QListView(parent)
: QListView(parent)
{
setObjectName(name);
}
@ -423,7 +403,7 @@ void UBFeaturesListView::dragMoveEvent( QDragMoveEvent *event )
void UBFeaturesListView::dropEvent( QDropEvent *event )
{
QWidget *eventSource = event->source();
if (eventSource && eventSource->objectName() == objNameFeatureList) {
if (eventSource && eventSource->objectName() == UBFeaturesWidget::objNameFeatureList) {
event->setDropAction( Qt::MoveAction );
}
@ -445,9 +425,9 @@ UBFeaturesNavigatorWidget::UBFeaturesNavigatorWidget(QWidget *parent, const char
name = "UBFeaturesNavigatorWidget";
setObjectName(name);
SET_STYLE_SHEET()
// SET_STYLE_SHEET()
mListView = new UBFeaturesListView(this, objNameFeatureList);
mListView = new UBFeaturesListView(this, UBFeaturesWidget::objNameFeatureList);
mListSlder = new QSlider(Qt::Horizontal, this);
@ -461,7 +441,7 @@ UBFeaturesNavigatorWidget::UBFeaturesNavigatorWidget(QWidget *parent, const char
mainLayer->addWidget(mListView, 1);
mainLayer->addWidget(mListSlder, 0);
mainLayer->setMargin(0);
connect(mListSlder, SIGNAL(valueChanged(int)), mListView, SLOT(thumbnailSizeChanged(int)));
}
@ -471,6 +451,207 @@ void UBFeaturesNavigatorWidget::setSliderPosition(int pValue)
mListSlder->setValue(pValue);
}
UBFeaturesCentralWidget::UBFeaturesCentralWidget(QWidget *parent) : QWidget(parent)
{
setObjectName("UBFeaturesCentralWidget");
SET_STYLE_SHEET();
QVBoxLayout *mLayout = new QVBoxLayout(this);
setLayout(mLayout);
//Maintains the view of the main part of the palette. Consists of
//mNavigator
//featureProperties
//webVeiw
mStackedWidget = new QStackedWidget(this);
//Main features icon view with QSlider on the bottom
mNavigator = new UBFeaturesNavigatorWidget(this);
//Specifies the properties of a standalone element
mFeatureProperties = new UBFeatureProperties(this);
//Used to show search bar on the search widget
webView = new UBFeaturesWebView(this);
//filling stackwidget
mStackedWidget->addWidget(mNavigator);
mStackedWidget->addWidget(mFeatureProperties);
mStackedWidget->addWidget(webView);
mStackedWidget->setCurrentIndex(MainList);
mStackedWidget->setContentsMargins(0, 0, 0, 0);
mAdditionalDataContainer = new QStackedWidget(this);
mAdditionalDataContainer->setObjectName("mAdditionalDataContainer");
//New folder dialog
UBFeaturesNewFolderDialog *dlg = new UBFeaturesNewFolderDialog(mAdditionalDataContainer);
mAdditionalDataContainer->addWidget(dlg);
mAdditionalDataContainer->setCurrentIndex(NewFolderDialog);
connect(dlg, SIGNAL(createNewFolder(QString)), this, SLOT(createNewFolderSlot(QString)));
connect(dlg, SIGNAL(closeDialog()), this, SLOT(hideAdditionalData()));
//Progress bar to show scanning progress
QProgressBar *progressBar = new QProgressBar();
mAdditionalDataContainer->addWidget(progressBar);
mAdditionalDataContainer->setCurrentIndex(ProgressBarWidget);
progressBar->setMinimum(0);
progressBar->setValue(0);
progressBar->setMaximum(10000);
connect(this, SIGNAL(maxFilesCountEvaluated(int)), progressBar, SLOT(setMaximum(int)));
mLayout->addWidget(mStackedWidget, 1);
mLayout->addWidget(mAdditionalDataContainer, 0);
mAdditionalDataContainer->hide();
}
void UBFeaturesCentralWidget::showElement(const UBFeature &feature, StackElement pView)
{
if (pView == FeaturesWebView) {
webView->showElement(feature);
mStackedWidget->setCurrentIndex(FeaturesWebView);
} else if (pView == FeaturePropertiesList) {
mFeatureProperties->showElement(feature);
mStackedWidget->setCurrentIndex(FeaturePropertiesList);
}
}
void UBFeaturesCentralWidget::switchTo(StackElement pView)
{
mStackedWidget->setCurrentIndex(pView);
}
void UBFeaturesCentralWidget::setPropertiesPixmap(const QPixmap &pix)
{
mFeatureProperties->setOrigPixmap(pix);
}
void UBFeaturesCentralWidget::setPropertiesThumbnail(const QPixmap &pix)
{
mFeatureProperties->setThumbnail(pix);
}
UBFeature UBFeaturesCentralWidget::getCurElementFromProperties()
{
return mFeatureProperties->getCurrentElement();
}
void UBFeaturesCentralWidget::showAdditionalData(AddWidget pWidgetType, AddWidgetState pState)
{
mAdditionalDataContainer->setMaximumHeight(mAdditionalDataContainer->widget(pWidgetType)->sizeHint().height());
mAdditionalDataContainer->setCurrentIndex(pWidgetType);
mAdditionalDataContainer->show();
emit lockMainWidget(pState == Modal ? true : false);
}
void UBFeaturesCentralWidget::setLockedExcludingAdditional(bool pLock)
{
// Lock all the members excluding mAdditionalDataContainer
mStackedWidget->setEnabled(!pLock);
}
void UBFeaturesCentralWidget::createNewFolderSlot(QString pStr)
{
emit createNewFolderSignal(pStr);
hideAdditionalData();
}
void UBFeaturesCentralWidget::hideAdditionalData()
{
emit lockMainWidget(false);
mAdditionalDataContainer->hide();
}
void UBFeaturesCentralWidget::scanStarted()
{
if (!mAdditionalDataContainer->widget(ProgressBarWidget)) {
return;
}
QProgressBar *progressBar = qobject_cast<QProgressBar*>(mAdditionalDataContainer->widget(ProgressBarWidget));
if (progressBar && !progressBar->isVisible()) {
showAdditionalData((AddWidget)1);
}
}
void UBFeaturesCentralWidget::scanFinished()
{
if (!mAdditionalDataContainer->widget(ProgressBarWidget)) {
return;
}
QProgressBar *progressBar = qobject_cast<QProgressBar*>(mAdditionalDataContainer->widget(ProgressBarWidget));
if (progressBar && progressBar->isVisible()) {
hideAdditionalData();
qDebug() << "progressBar max value is " << progressBar->maximum();
}
}
void UBFeaturesCentralWidget::increaseStatusBarValue()
{
if (!mAdditionalDataContainer->widget(ProgressBarWidget)) {
return;
}
QProgressBar *progressBar = qobject_cast<QProgressBar*>(mAdditionalDataContainer->widget(ProgressBarWidget));
if (progressBar) {
progressBar->setValue(progressBar->value() + 1);
}
}
UBFeaturesNewFolderDialog::UBFeaturesNewFolderDialog(QWidget *parent) : QWidget(parent)
{
// SET_STYLE_SHEET()
this->setStyleSheet("background:white;");
QVBoxLayout *mainLayout = new QVBoxLayout();
setLayout(mainLayout);
QVBoxLayout *labelLayout = new QVBoxLayout(this);
QLabel *mLabel = new QLabel(labelText, this);
mLineEdit = new QLineEdit(this);
mValidator = new QRegExpValidator(QRegExp("[\^\/\:\?\*\|\<\>\"]{2,}"));
mLineEdit->setValidator(mValidator);
labelLayout->addWidget(mLabel);
labelLayout->addWidget(mLineEdit);
QHBoxLayout *buttonLayout = new QHBoxLayout(this);
QPushButton *acceptButton = new QPushButton(acceptText, this);
QPushButton *cancelButton = new QPushButton(cancelText, this);
buttonLayout->addWidget(acceptButton);
buttonLayout->addWidget(cancelButton);
mainLayout->addLayout(labelLayout);
mainLayout->addLayout(buttonLayout);
connect(acceptButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
}
void UBFeaturesNewFolderDialog::setRegexp(const QRegExp pRegExp)
{
mValidator->setRegExp(pRegExp);
}
void UBFeaturesNewFolderDialog::accept()
{
// Setting all the constraints we need
emit createNewFolder(mLineEdit->text());
mLineEdit->clear();
}
void UBFeaturesNewFolderDialog::reject()
{
mLineEdit->clear();
emit closeDialog();
}
UBFeaturesWebView::UBFeaturesWebView(QWidget* parent, const char* name):QWidget(parent)
, mpView(NULL)
, mpWebSettings(NULL)
@ -499,6 +680,7 @@ UBFeaturesWebView::UBFeaturesWebView(QWidget* parent, const char* name):QWidget(
mpWebSettings->setAttribute(QWebSettings::DnsPrefetchEnabled, true);
mpLayout->addWidget(mpView);
mpLayout->setMargin(0);
connect(mpView, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool)));
}
@ -578,8 +760,6 @@ UBFeatureProperties::UBFeatureProperties( QWidget *parent, const char *name ) :
{
setObjectName(name);
SET_STYLE_SHEET();
// Create the GUI
mpLayout = new QVBoxLayout(this);
setLayout(mpLayout);
@ -625,6 +805,7 @@ UBFeatureProperties::UBFeatureProperties( QWidget *parent, const char *name ) :
mpObjInfos->setObjectName("DockPaletteWidgetBox");
mpObjInfos->setStyleSheet("background:white;");
mpLayout->addWidget(mpObjInfos, 1);
mpLayout->setMargin(0);
connect( mpAddPageButton, SIGNAL(clicked()), this, SLOT(onAddToPage()) );
connect( mpSetAsBackgroundButton, SIGNAL( clicked() ), this, SLOT( onSetAsBackground() ) );
@ -700,7 +881,7 @@ UBFeature UBFeatureProperties::getCurrentElement() const
return UBFeature();
}
void UBFeatureProperties::setOrigPixmap(QPixmap &pix)
void UBFeatureProperties::setOrigPixmap(const QPixmap &pix)
{
if (mpOrigPixmap)
@ -709,7 +890,7 @@ void UBFeatureProperties::setOrigPixmap(QPixmap &pix)
mpOrigPixmap = new QPixmap(pix);
}
void UBFeatureProperties::setThumbnail(QPixmap &pix)
void UBFeatureProperties::setThumbnail(const QPixmap &pix)
{
mpThumbnail->setPixmap(pix.scaledToWidth(THUMBNAIL_WIDTH));
adaptSize();
@ -730,7 +911,7 @@ void UBFeatureProperties::adaptSize()
}
}
void UBFeatureProperties::showElement( const UBFeature &elem )
void UBFeatureProperties::showElement(const UBFeature &elem)
{
if ( mpOrigPixmap )
{
@ -742,9 +923,9 @@ void UBFeatureProperties::showElement( const UBFeature &elem )
delete mpElement;
mpElement = NULL;
}
mpElement = new UBFeature( elem );
mpOrigPixmap = new QPixmap( elem.getThumbnail() );
mpThumbnail->setPixmap(elem.getThumbnail().scaledToWidth(THUMBNAIL_WIDTH));
mpElement = new UBFeature(elem);
mpOrigPixmap = new QPixmap(QPixmap::fromImage(elem.getThumbnail()));
mpThumbnail->setPixmap(QPixmap::fromImage(elem.getThumbnail()).scaledToWidth(THUMBNAIL_WIDTH));
populateMetadata();
if ( UBApplication::isFromWeb( elem.getFullPath().toString() ) )
@ -794,8 +975,8 @@ void UBFeatureProperties::populateMetadata()
void UBFeatureProperties::onAddToPage()
{
QWidget *w = parentWidget()->parentWidget();
UBFeaturesWidget* featuresWidget = dynamic_cast<UBFeaturesWidget*>( w );
QWidget *w = parentWidget()->parentWidget()->parentWidget();
UBFeaturesWidget* featuresWidget = qobject_cast<UBFeaturesWidget*>( w );
if (featuresWidget)
featuresWidget->getFeaturesController()->addItemToPage( *mpElement );
}
@ -818,8 +999,8 @@ void UBFeatureProperties::onAddToLib()
void UBFeatureProperties::onSetAsBackground()
{
QWidget *w = parentWidget()->parentWidget();
UBFeaturesWidget* featuresWidget = dynamic_cast<UBFeaturesWidget*>( w );
QWidget *w = parentWidget()->parentWidget()->parentWidget();
UBFeaturesWidget* featuresWidget = qobject_cast<UBFeaturesWidget*>( w );
featuresWidget->getFeaturesController()->addItemAsBackground( *mpElement );
}
@ -845,7 +1026,7 @@ QVariant UBFeaturesModel::data(const QModelIndex &index, int role) const
}
else if (role == Qt::DecorationRole) {
return QIcon( featuresList->at(index.row()).getThumbnail() );
return QIcon( QPixmap::fromImage(featuresList->at(index.row()).getThumbnail()));
} else if (role == Qt::UserRole) {
return featuresList->at(index.row()).getVirtualPath();
@ -1017,7 +1198,7 @@ void UBFeaturesModel::moveData(const UBFeature &source, const UBFeature &destina
QString sourceVirtualPath = source.getVirtualPath();
UBFeatureElementType sourceType = source.getType();
QPixmap sourceIcon = source.getThumbnail();
QImage sourceIcon = source.getThumbnail();
Q_ASSERT( QFileInfo( sourcePath ).exists() );
@ -1183,7 +1364,7 @@ void UBFeaturesPathItemDelegate::paint( QPainter *painter, const QStyleOptionVie
{
painter->drawPixmap( rect.left() - 10, rect.center().y() - 5, *arrowPixmap );
}
painter->drawPixmap( rect.left() + 5, rect.center().y() - 5, feature.getThumbnail().scaledToHeight( 30, Qt::SmoothTransformation ) );
painter->drawImage( rect.left() + 5, rect.center().y() - 5, feature.getThumbnail().scaledToHeight( 30, Qt::SmoothTransformation ) );
}
UBFeaturesPathItemDelegate::~UBFeaturesPathItemDelegate()

@ -43,6 +43,8 @@ class UBFeaturesListView;
class UBFeaturesWebView;
class UBFeaturesNavigatorWidget;
class UBFeaturesMimeData;
class UBFeaturesCentralWidget;
class UBFeaturesNewFolderDialog;
class UBFeaturesWidget : public UBDockPaletteWidget
{
@ -63,6 +65,9 @@ public:
static const int maxThumbnailSize = 100;
static const int defaultThumbnailSize = 40;
static const char *objNamePathList;
static const char *objNameFeatureList;
public:
int scrollbarHorisontalPadding() const { return 10;}
int scrollbarVerticalIndent() const { return 0;}
@ -82,6 +87,7 @@ private slots:
void removeElementsFromFavorite();
void deleteSelectedElements();
void rescanModel();
void lockIt(bool pLock);
private:
void resizeEvent(QResizeEvent *event);
@ -91,17 +97,12 @@ private:
private:
UBFeaturesController *controller;
UBFeaturesNavigatorWidget *mNavigator;
UBFeaturesListView *pathListView;
QVBoxLayout *layout;
UBFeaturesActionBar *mActionBar;
UBFeatureProperties *featureProperties;
UBFeaturesWebView *webView;
QStackedWidget *stackedWidget;
int currentStackedWidget;
UBDownloadHttpFile* imageGatherer;
UBNewFolderDlg *mkFolderDlg;
UBFeaturesCentralWidget *centralWidget;
};
@ -134,6 +135,7 @@ protected:
private slots:
void thumbnailSizeChanged(int);
};
@ -153,6 +155,93 @@ private:
};
class UBFeaturesCentralWidget : public QWidget
{
Q_OBJECT
public:
enum StackElement{
MainList = 0,
FeaturePropertiesList,
FeaturesWebView
};
enum AddWidget {
NewFolderDialog = 0,
ProgressBarWidget
};
enum AddWidgetState {
NonModal = 0,
Modal
};
UBFeaturesCentralWidget(QWidget *parent = 0);
void setSliderPosition(int pValue) {mNavigator->setSliderPosition(pValue);}
UBFeaturesListView *listView() {return mNavigator->listView();}
void showElement(const UBFeature &feature, StackElement pView);
void switchTo(StackElement pView);
void setPropertiesPixmap(const QPixmap &pix);
void setPropertiesThumbnail(const QPixmap &pix);
StackElement currentView() const {return static_cast<StackElement>(mStackedWidget->currentIndex());}
UBFeature getCurElementFromProperties();
void showAdditionalData(AddWidget pWidgetType, AddWidgetState pState = NonModal);
void setLockedExcludingAdditional(bool pLock);
QStackedWidget *mStackedWidget;
UBFeaturesNavigatorWidget *mNavigator;
UBFeatureProperties *mFeatureProperties;
UBFeaturesWebView *webView;
QStackedWidget *mAdditionalDataContainer;
signals:
void lockMainWidget(bool pLock);
void createNewFolderSignal(QString pStr);
// progressbar widget related signals
void maxFilesCountEvaluated(int pValue);
private slots:
void createNewFolderSlot(QString pStr);
void hideAdditionalData();
void scanStarted();
void scanFinished();
void increaseStatusBarValue();
private:
};
class UBFeaturesNewFolderDialog : public QWidget
{
Q_OBJECT
public:
static const QString acceptText;
static const QString cancelText;
static const QString labelText;
UBFeaturesNewFolderDialog(QWidget *parent = 0);
void setRegexp(const QRegExp pRegExp);
signals:
void createNewFolder(QString str);
void closeDialog();
private slots:
void accept();
void reject();
private:
QLineEdit *mLineEdit;
QRegExpValidator *mValidator;
};
class UBFeaturesWebView : public QWidget
{
@ -182,8 +271,8 @@ public:
void showElement(const UBFeature &elem);
UBFeature getCurrentElement() const;
void setOrigPixmap(QPixmap &pix);
void setThumbnail(QPixmap &pix);
void setOrigPixmap(const QPixmap &pix);
void setThumbnail(const QPixmap &pix);
protected:
void resizeEvent(QResizeEvent *event);
@ -231,7 +320,6 @@ public:
UBFeaturesModel(QList<UBFeature> *pFeaturesList, QObject *parent = 0) : QAbstractListModel(parent), featuresList(pFeaturesList) {;}
virtual ~UBFeaturesModel(){;}
void addItem( const UBFeature &item );
void deleteFavoriteItem( const QString &path );
void deleteItem( const QString &path );
void deleteItem(const UBFeature &feature);
@ -251,6 +339,9 @@ public:
Qt::DropActions supportedDropActions() const { return Qt::MoveAction | Qt::CopyAction; }
// void setFeaturesList(QList <UBFeature> *flist ) { featuresList = flist; }
public slots:
void addItem( const UBFeature &item );
private:
QList <UBFeature> *featuresList;
};
@ -314,4 +405,5 @@ private:
QPixmap *arrowPixmap;
};
#endif // UBFEATURESWIDGET_H

Loading…
Cancel
Save