From 71ca20fe227dcfbc79923fe1bd6221f40741581f Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Fri, 13 Apr 2012 20:14:28 +0300 Subject: [PATCH 01/12] Unstable branch init --- src/board/UBBoardPaletteManager.cpp | 4 + src/board/UBBoardPaletteManager.h | 3 + src/board/UBBoardView.cpp | 10 +- src/board/UBFeaturesController.cpp | 256 ++++++++++++ src/board/UBFeaturesController.h | 99 +++++ src/board/board.pri | 6 +- src/gui/UBFeaturesWidget.cpp | 618 ++++++++++++++++++++++++++++ src/gui/UBFeaturesWidget.h | 247 +++++++++++ src/gui/UBLibraryWidget.h | 1 + src/gui/gui.pri | 2 + 10 files changed, 1239 insertions(+), 7 deletions(-) create mode 100644 src/board/UBFeaturesController.cpp create mode 100644 src/board/UBFeaturesController.h create mode 100644 src/gui/UBFeaturesWidget.cpp create mode 100644 src/gui/UBFeaturesWidget.h diff --git a/src/board/UBBoardPaletteManager.cpp b/src/board/UBBoardPaletteManager.cpp index f21c089b..e8f6aaa4 100644 --- a/src/board/UBBoardPaletteManager.cpp +++ b/src/board/UBBoardPaletteManager.cpp @@ -153,6 +153,10 @@ void UBBoardPaletteManager::setupDockPaletteWidgets() mRightPalette = new UBRightPalette(mContainer); // RIGHT palette widgets + + mRightPalette->registerWidget(mpFeaturesWidget); + mRightPalette->addTab(mpFeaturesWidget); + mRightPalette->registerWidget(mpLibWidget); mRightPalette->addTab(mpLibWidget); // The cache widget will be visible only if a cache is put on the page diff --git a/src/board/UBBoardPaletteManager.h b/src/board/UBBoardPaletteManager.h index 4e5e5d99..6a1c60a1 100644 --- a/src/board/UBBoardPaletteManager.h +++ b/src/board/UBBoardPaletteManager.h @@ -27,6 +27,7 @@ #include "gui/UBCachePropertiesWidget.h" #include "gui/UBDockDownloadWidget.h" #include "core/UBApplicationController.h" +#include "gui/UBFeaturesWidget.h" class UBStylusPalette; @@ -129,6 +130,8 @@ class UBBoardPaletteManager : public QObject /** The cache properties widget */ UBCachePropertiesWidget* mpCachePropWidget; + UBFeaturesWidget *mpFeaturesWidget; + /** The download widget */ UBDockDownloadWidget* mpDownloadWidget; // HACK: here we duplicate the lib widget for the desktop mode diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 1e493cc2..c655ac3c 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -800,17 +800,17 @@ void UBBoardView::dropEvent (QDropEvent *event) QGraphicsItem* graphicsItemAtPos = itemAt(event->pos().x(),event->pos().y()); UBGraphicsWidgetItem* graphicsWidget = dynamic_cast(graphicsItemAtPos); - qDebug() << event->source(); - if (graphicsWidget && graphicsWidget->acceptDrops()) { + graphicsWidget->processDropEvent(event); event->acceptProposedAction(); - } - else if (!event->source() + } else if (!event->source() || dynamic_cast(event->source()) || dynamic_cast(event->source()) - || dynamic_cast(event->source())) { + || dynamic_cast(event->source())) + || dynamic_cast(event->source()) ) { + mController->processMimeData (event->mimeData (), mapToScene (event->pos ())); event->acceptProposedAction(); } diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp new file mode 100644 index 00000000..e7609d2a --- /dev/null +++ b/src/board/UBFeaturesController.cpp @@ -0,0 +1,256 @@ +#include +#include + +#include "core/UBApplication.h" +#include "board/UBBoardController.h" +#include "UBFeaturesController.h" +#include "core/UBSettings.h" +#include "tools/UBToolsManager.h" +#include "frameworks/UBFileSystemUtils.h" +#include "frameworks/UBPlatformUtils.h" + + +#include "core/UBDownloadManager.h" +#include "domain/UBAbstractWidget.h" +#include "domain/UBGraphicsScene.h" +#include "domain/UBGraphicsSvgItem.h" +#include "domain/UBGraphicsPixmapItem.h" +#include "domain/UBGraphicsVideoItem.h" +#include "domain/UBGraphicsWidgetItem.h" + +UBFeature::UBFeature(const QString &url, const QPixmap &icon, const QString &name, const QString &realPath, UBFeatureElementType type) +: virtualPath(url), mThumbnail(icon), mName(name), mPath(realPath), elementType(type) +{ + +} + +UBFeature::UBFeature(const UBFeature &f) +{ + virtualPath = f.getUrl(); + mPath = f.getPath(); + mThumbnail = f.getThumbnail(); + mName = f.getName(); + elementType = f.getType(); +} + + + +UBFeaturesController::UBFeaturesController(QWidget *pParentWidget) : + QObject(pParentWidget), + mLastItemOffsetIndex(0) +{ + rootPath = "/root"; + initDirectoryTree(); +} + +void UBFeaturesController::initDirectoryTree() +{ + mUserAudioDirectoryPath = UBSettings::settings()->userAudioDirectory(); + mUserVideoDirectoryPath = UBSettings::settings()->userVideoDirectory(); + mUserPicturesDirectoryPath = UBSettings::settings()->userImageDirectory(); + mUserInteractiveDirectoryPath = UBSettings::settings()->userInteractiveDirectory(); + mUserAnimationDirectoryPath = UBSettings::settings()->userAnimationDirectory(); + + mLibPicturesDirectoryPath = UBSettings::settings()->applicationImageLibraryDirectory(); + mLibInteractiveDirectoryPath = UBSettings::settings()->applicationInteractivesDirectory(); + mLibApplicationsDirectoryPath = UBSettings::settings()->applicationApplicationsLibraryDirectory(); + mLibShapesDirectoryPath = UBSettings::settings()->applicationShapeLibraryDirectory() ; + + featuresList = new QVector (); + + QList tools = UBToolsManager::manager()->allTools(); + + featuresList->push_back( UBFeature( "", QPixmap( ":images/libpalette/home.png" ), "root", "" ) ); + + appPath = rootPath + "/Applications"; + audiosPath = rootPath + "/Audios"; + moviesPath = rootPath + "/Movies"; + picturesPath = rootPath + "/Pictures"; + flashPath = rootPath + "/Animations"; + interactPath = rootPath + "/Interactivities"; + shapesPath = rootPath + "/Shapes"; + + featuresList->push_back( UBFeature( rootPath, QPixmap(":images/libpalette/AudiosCategory.svg"), "Audios" , mUserAudioDirectoryPath ) ); + featuresList->push_back( UBFeature( rootPath, QPixmap(":images/libpalette/MoviesCategory.svg"), "Movies" , mUserVideoDirectoryPath ) ); + featuresList->push_back( UBFeature( rootPath, QPixmap(":images/libpalette/PicturesCategory.svg"), "Pictures" , mUserPicturesDirectoryPath ) ); + featuresList->push_back( UBFeature( rootPath, QPixmap(":images/libpalette/ApplicationsCategory.svg"), "Applications" , mUserInteractiveDirectoryPath ) ); + featuresList->push_back( UBFeature( rootPath, QPixmap(":images/libpalette/FlashCategory.svg"), "Animations" , mUserAnimationDirectoryPath ) ); + featuresList->push_back( UBFeature( rootPath, QPixmap(":images/libpalette/InteractivesCategory.svg"), "Interactivities" , mLibInteractiveDirectoryPath ) ); + featuresList->push_back( UBFeature( rootPath, QPixmap(":images/libpalette/ShapesCategory.svg"), "Shapes" , mLibShapesDirectoryPath ) ); + + foreach (UBToolsManager::UBToolDescriptor tool, tools) + { + featuresList->push_back( UBFeature( appPath, tool.icon, tool.label, mUserInteractiveDirectoryPath, FEATURE_INTERACTIVE ) ); + } + fileSystemScan( mUserInteractiveDirectoryPath, appPath ); + fileSystemScan( mUserAudioDirectoryPath, audiosPath ); + fileSystemScan( mUserPicturesDirectoryPath, picturesPath ); + fileSystemScan( mUserVideoDirectoryPath, moviesPath ); + fileSystemScan( mUserAnimationDirectoryPath, flashPath ); + + fileSystemScan( mLibApplicationsDirectoryPath, appPath ); + fileSystemScan( mLibPicturesDirectoryPath, picturesPath ); + fileSystemScan( mLibShapesDirectoryPath, shapesPath ); + fileSystemScan( mLibInteractiveDirectoryPath, interactPath ); + +} + +void UBFeaturesController::fileSystemScan(const QString & currentPath, const QString & currVirtualPath) +{ + QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(currentPath); + + QFileInfoList::iterator fileInfo; + for ( fileInfo = fileInfoList.begin(); fileInfo != fileInfoList.end(); fileInfo += 1) + { + UBFeatureElementType fileType = fileInfo->isDir() ? FEATURE_FOLDER : FEATURE_ITEM; + + QString fileName = fileInfo->fileName(); + if ( UBFileSystemUtils::mimeTypeFromFileName(fileName).contains("application") ) { + fileType = FEATURE_INTERACTIVE; + } + QString itemName = (fileType != FEATURE_ITEM) ? fileName : fileInfo->completeBaseName(); + QPixmap icon = QPixmap(":images/libpalette/soundIcon.svg"); + QString fullFileName = currentPath + "/" + fileName; + + if ( fileType == FEATURE_FOLDER ) + { + icon = QPixmap(":images/libpalette/folder.svg"); + } + else if ( fileType == FEATURE_INTERACTIVE ) + { + icon = QPixmap( UBAbstractWidget::iconFilePath( QUrl::fromLocalFile(fullFileName) ) ); + } + else + { + if ( fullFileName.contains(".thumbnail.") ) + continue; + icon = thumbnailForFile( fullFileName ); + /*QString thumbnailPath = UBFileSystemUtils::thumbnailPath( fullFileName ); + + if (QFileInfo( thumbnailPath).exists() ) + icon = QPixmap( thumbnailPath ); + else icon = createThumbnail( fullFileName );*/ + } + featuresList->push_back( UBFeature( currVirtualPath, icon, fileName, currentPath, fileType ) ); + + if ( fileType == FEATURE_FOLDER ) + { + fileSystemScan( fullFileName, currVirtualPath + "/" + fileName ); + } + + } +} + +QPixmap UBFeaturesController::thumbnailForFile(const QString &path) +{ + QPixmap thumb; + QString thumbnailPath = UBFileSystemUtils::thumbnailPath( path ); + + if ( QFileInfo( thumbnailPath ).exists() ) + thumb = QPixmap( thumbnailPath ); + else thumb = createThumbnail( path ); + return thumb; +} + +QPixmap 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"; + else if ( mimetype.contains("video") ) + thumbnailPath = ":images/libpalette/movieIcon.svg"; + else + { + if ( extension.startsWith("svg", Qt::CaseInsensitive) || extension.startsWith("svgz", Qt::CaseInsensitive) ) + { + thumbnailPath = path; + } + else + { + QPixmap pix(path); + if (!pix.isNull()) + { + pix = pix.scaledToWidth(qMin(UBSettings::maxThumbnailWidth, pix.width()), Qt::SmoothTransformation); + pix.save(thumbnailPath); + UBPlatformUtils::hideFile(thumbnailPath); + } + else{ + thumbnailPath = ":images/libpalette/notFound.png"; + } + } + } + + return QPixmap(thumbnailPath); +} + +void UBFeaturesController::addItemToPage(const UBFeature &item) +{ + UBApplication::boardController->downloadURL( QUrl::fromLocalFile( item.getFullPath() ) ); +} + +UBFeature UBFeaturesController::moveItemToFolder( 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 ); + QFile::remove( sourcePath ); + + QString thumbnailPath = UBFileSystemUtils::thumbnailPath( sourcePath ); + if (thumbnailPath.length() && QFileInfo( thumbnailPath ).exists()) + { + QFile::remove(thumbnailPath); + } + + QPixmap thumb = thumbnailForFile( newFullPath ); + + UBFeatureElementType type = UBFeatureElementType::FEATURE_ITEM; + if ( UBFileSystemUtils::mimeTypeFromFileName( newFullPath ).contains("application") ) + type = UBFeatureElementType::FEATURE_INTERACTIVE; + UBFeature newElement( destVirtualPath, thumb, name, destPath, type ); + return newElement; +} +/* +void UBFeaturesController::addImageToCurrentPage( const QString &path ) +{ + QPointF pos = UBApplication::boardController->activeScene()->normalizedSceneRect().center(); + mLastItemOffsetIndex = qMin(mLastItemOffsetIndex, 5); + + QGraphicsItem* itemInScene = 0; + + if ( UBApplication::boardController->activeScene() ) + { + QString mimeType = UBFileSystemUtils::mimeTypeFromFileName( path ); + + pos = QPointF( pos.x() + 50 * mLastItemOffsetIndex, pos.y() + 50 * mLastItemOffsetIndex ); + mLastItemOffsetIndex++; + //TODO UB 4.x move this logic to the scene .. + if (mimeType == "image/svg+xml") + { + itemInScene = UBApplication::boardController->activeScene()->addSvg( QUrl::fromLocalFile(path), pos ); + } + else + { + itemInScene = UBApplication::boardController->activeScene()->addPixmap( QPixmap(path), pos ); + } + } + + if (itemInScene) + { + itemInScene = UBApplication::boardController->activeScene()->scaleToFitDocumentSize(itemInScene, false, UBSettings::objectInControlViewMargin); + } +} +*/ + +UBFeaturesController::~UBFeaturesController() +{ +} diff --git a/src/board/UBFeaturesController.h b/src/board/UBFeaturesController.h new file mode 100644 index 00000000..cde23347 --- /dev/null +++ b/src/board/UBFeaturesController.h @@ -0,0 +1,99 @@ +#ifndef UBFEATURESCONTROLLER_H +#define UBFEATURESCONTROLLER_H + +#include +#include +#include +#include +#include +#include + +//#include "UBDockPaletteWidget.h" + +enum UBFeatureElementType +{ + FEATURE_CATEGORY, + FEATURE_VIRTUALFOLDER, + FEATURE_FOLDER, + FEATURE_INTERACTIVE, + FEATURE_ITEM +}; + +class UBFeature +{ +public: + UBFeature(){}; + UBFeature(const UBFeature &f); + UBFeature(const QString &url, const QPixmap &icon, const QString &name, const QString &realPath, UBFeatureElementType type = FEATURE_CATEGORY); + virtual ~UBFeature(){}; + QString getName() const { return mName; }; + QPixmap getThumbnail() const { + return mThumbnail; + }; + QString getUrl() const { return virtualPath; }; + QString getPath() const { return mPath; }; + QString getFullPath() const { return mPath + "/" + mName; }; + UBFeatureElementType getType() const { return elementType; } ; +private: + QString virtualPath; + QString mPath; + QPixmap mThumbnail; + QString mName; + UBFeatureElementType elementType; +}; +Q_DECLARE_METATYPE( UBFeature ) + + +class UBFeaturesController : public QObject +{ +Q_OBJECT +public: + UBFeaturesController(QWidget *parentWidget); + virtual ~UBFeaturesController(); + + QVector * getFeatures()const { return featuresList; }; + + QString getRootPath()const { return rootPath; }; + + void addItemToPage(const UBFeature &item); + static QPixmap thumbnailForFile( const QString &path ); + static UBFeature moveItemToFolder( const QUrl &url, const UBFeature &destination ); +private: + void initDirectoryTree(); + void fileSystemScan(const QString &currPath, const QString & currVirtualPath); + static QPixmap createThumbnail(const QString &path); + //void addImageToCurrentPage( const QString &path ); + + QVector *featuresList; + UBFeature *rootElement; + + QString mUserAudioDirectoryPath; + QString mUserVideoDirectoryPath; + QString mUserPicturesDirectoryPath; + QString mUserInteractiveDirectoryPath; + QString mUserAnimationDirectoryPath; + + QString libraryPath; + QString mLibAudioDirectoryPath; + QString mLibVideoDirectoryPath; + QString mLibPicturesDirectoryPath; + QString mLibInteractiveDirectoryPath; + QString mLibAnimationDirectoryPath; + QString mLibApplicationsDirectoryPath; + QString mLibShapesDirectoryPath; + + QString rootPath; + QString audiosPath; + QString moviesPath; + QString picturesPath; + QString appPath; + QString flashPath; + QString shapesPath; + QString interactPath; + + int mLastItemOffsetIndex; +}; + + + +#endif \ No newline at end of file diff --git a/src/board/board.pri b/src/board/board.pri index bf934a62..1208db87 100644 --- a/src/board/board.pri +++ b/src/board/board.pri @@ -3,13 +3,15 @@ HEADERS += src/board/UBBoardController.h \ src/board/UBBoardPaletteManager.h \ src/board/UBBoardView.h \ src/board/UBLibraryController.h \ - src/board/UBDrawingController.h + src/board/UBDrawingController.h \ + src/board/UBFeaturesController.h SOURCES += src/board/UBBoardController.cpp \ src/board/UBBoardPaletteManager.cpp \ src/board/UBBoardView.cpp \ src/board/UBLibraryController.cpp \ - src/board/UBDrawingController.cpp + src/board/UBDrawingController.cpp \ + src/board/UBFeaturesController.cpp diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp new file mode 100644 index 00000000..dbdaa99b --- /dev/null +++ b/src/gui/UBFeaturesWidget.cpp @@ -0,0 +1,618 @@ +#include "UBFeaturesWidget.h" +#include "domain/UBAbstractWidget.h" +#include "gui/UBThumbnailWidget.h" +#include "frameworks/UBFileSystemUtils.h" +#include "core/UBApplication.h" +#include "core/UBDownloadManager.h" + +UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPaletteWidget(parent) +{ + setObjectName(name); + mName = "FeaturesWidget"; + mVisibleState = true; + + setAttribute(Qt::WA_StyledBackground, true); + setStyleSheet(UBApplication::globalStyleSheet()); + + mIconToLeft = QPixmap(":images/library_open.png"); + mIconToRight = QPixmap(":images/library_close.png"); + setAcceptDrops(true); + + stackedWidget = new QStackedWidget(this); + layout = new QVBoxLayout(this); + + controller = new UBFeaturesController(this); + + featuresModel = new UBFeaturesModel(this); + featuresModel->setFeaturesList( controller->getFeatures() ); + featuresModel->setSupportedDragActions( Qt::CopyAction | Qt::MoveAction ); + featuresListView = new QListView(this); + pathListView = new QListView(this); + + + featuresProxyModel = new UBFeaturesProxyModel(this); + featuresProxyModel->setFilterFixedString( controller->getRootPath() ); + featuresProxyModel->setSourceModel( featuresModel ); + featuresProxyModel->setFilterCaseSensitivity( Qt::CaseInsensitive ); + + featuresSearchModel = new UBFeaturesSearchProxyModel(this); + featuresSearchModel->setSourceModel( featuresModel ); + featuresSearchModel->setFilterCaseSensitivity( Qt::CaseInsensitive ); + + featuresPathModel = new UBFeaturesPathProxyModel(this); + featuresPathModel->setPath( controller->getRootPath() ); + featuresPathModel->setSourceModel( featuresModel ); + + + featuresListView->setDragDropMode( QAbstractItemView::InternalMove ); + featuresListView->setModel( featuresProxyModel ); + + featuresListView->setResizeMode( QListView::Adjust ); + featuresListView->setViewMode( QListView::IconMode ); + itemDelegate = new UBFeaturesItemDelegate( this, featuresListView ); + featuresListView->setItemDelegate( itemDelegate ); + + featuresListView->setIconSize( QSize(40, 40) ); + featuresListView->setGridSize( QSize(70, 70) ); + + pathListView->setModel( featuresPathModel ); + pathListView->setViewMode( QListView::IconMode ); + pathListView->setIconSize( QSize(30, 30) ); + pathListView->setGridSize( QSize(50, 30) ); + pathListView->setFixedHeight( 60 ); + pathItemDelegate = new UBFeaturesPathItemDelegate( this ); + pathListView->setItemDelegate( pathItemDelegate ); + pathListView->setSelectionMode( QAbstractItemView::NoSelection ); + pathListView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + pathListView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); + pathListView->setMovement( QListView::Static ); + pathListView->setDragDropMode( QAbstractItemView::DragDrop ); + + pathScene = new QGraphicsScene(this); + //pathViewer = new UBFeaturesPathViewer( QPixmap(":images/libpalette/home.png"), controller->getRootPath(), pathScene, this ); + featureProperties = new UBFeatureProperties(this); + + //layout->addWidget( pathViewer ); + //pathViewer->show(); + //layout->addWidget( featuresListView ); + layout->addWidget( pathListView ); + layout->addWidget( stackedWidget ); + + stackedWidget->addWidget( featuresListView ); + stackedWidget->addWidget( featureProperties ); + stackedWidget->setCurrentIndex(ID_LISTVIEW); + currentStackedWidget = ID_LISTVIEW; + + mActionBar = new UBLibActionBar(this); + layout->addWidget(mActionBar); + + /*connect(featuresListView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex &, const QModelIndex & )), + this, SLOT(currentSelected(const QModelIndex &)));*/ + connect( featuresListView, SIGNAL(clicked ( const QModelIndex & ) ), + this, SLOT( currentSelected(const QModelIndex &) ) ); + connect( mActionBar, SIGNAL( searchElement(QString) ), this, SLOT( searchStarted(QString) ) ); + connect( pathListView, SIGNAL(clicked( const QModelIndex & ) ), + this, SLOT( currentPathChanged( const QModelIndex & ) ) ); +} + +void UBFeaturesWidget::searchStarted( QString pattern ) +{ + if ( pattern.isEmpty() ) + { + featuresListView->setModel( featuresProxyModel ); + featuresProxyModel->invalidate(); + } + else + { + featuresSearchModel->setFilterWildcard( "*" + pattern + "*" ); + featuresListView->setModel( featuresSearchModel ); + featuresSearchModel->invalidate(); + } +} + +void UBFeaturesWidget::currentSelected(const QModelIndex ¤t) +{ + if (current.isValid()) + { + QSortFilterProxyModel *model = dynamic_cast( featuresListView->model() ); + /*QString name = model->data(current).toString(); + QString path = model->data(current, Qt::UserRole).toString(); + eUBLibElementType type = (eUBLibElementType)model->data(current, Qt::UserRole + 1).toInt();*/ + UBFeature feature = model->data(current, Qt::UserRole + 1).value(); + if ( feature.getType() == UBFeatureElementType::FEATURE_FOLDER || feature.getType() == UBFeatureElementType::FEATURE_CATEGORY) + { + QString newPath = feature.getUrl() + "/" + feature.getName(); + //pathViewer->addPathElement( feature.getThumbnail(), newPath ); + + model->setFilterFixedString( newPath ); + model->invalidate(); + switchToListView(); + + featuresPathModel->setPath( newPath ); + featuresPathModel->invalidate(); + } + else + { + featureProperties->showElement( feature ); + switchToProperties(); + } + + } +} + +void UBFeaturesWidget::currentPathChanged(const QModelIndex &index) +{ + if ( index.isValid() ) + { + UBFeature feature = featuresPathModel->data(index, Qt::UserRole + 1).value(); + QString newPath = feature.getUrl() + "/" + feature.getName(); + + featuresPathModel->setPath( newPath ); + featuresPathModel->invalidate(); + + featuresListView->setModel( featuresProxyModel ); + featuresProxyModel->setFilterFixedString(newPath); + featuresProxyModel->invalidate(); + switchToListView(); + } +} + + +void UBFeaturesWidget::switchToListView() +{ + stackedWidget->setCurrentIndex(ID_LISTVIEW); + currentStackedWidget = ID_LISTVIEW; +} + +void UBFeaturesWidget::switchToProperties() +{ + stackedWidget->setCurrentIndex(ID_PROPERTIES); + currentStackedWidget = ID_PROPERTIES; +} + + + +void UBFeaturesWidget::currentPathChanged(const QString &path) +{ + int newDepth = path.count("/"); + pathViewer->truncatePath(newDepth); + featuresListView->setModel( featuresProxyModel ); + featuresProxyModel->setFilterFixedString(path); + featuresProxyModel->invalidate(); + switchToListView(); +} + + + +UBFeaturesWidget::~UBFeaturesWidget() +{ +} + +UBFeatureProperties::UBFeatureProperties( QWidget *parent, const char *name ) : QWidget(parent) + , mpLayout(NULL) + , mpButtonLayout(NULL) + , mpAddPageButton(NULL) + , mpAddToLibButton(NULL) + , mpSetAsBackgroundButton(NULL) + , mpObjInfoLabel(NULL) + , mpThumbnail(NULL) + , mpOrigPixmap(NULL) + , mpElement(NULL) +{ + setObjectName(name); + + setAttribute(Qt::WA_StyledBackground, true); + setStyleSheet(UBApplication::globalStyleSheet()); + + // Create the GUI + mpLayout = new QVBoxLayout(this); + setLayout(mpLayout); + + maxThumbHeight = height() / 4; + + mpThumbnail = new QLabel(); + QPixmap icon(":images/libpalette/notFound.png"); + icon.scaledToWidth(THUMBNAIL_WIDTH); + + mpThumbnail->setPixmap(icon); + mpThumbnail->setObjectName("DockPaletteWidgetBox"); + mpThumbnail->setStyleSheet("background:white;"); + mpThumbnail->setAlignment(Qt::AlignHCenter); + mpLayout->addWidget(mpThumbnail, 0); + + mpButtonLayout = new QHBoxLayout(); + mpLayout->addLayout(mpButtonLayout, 0); + + mpAddPageButton = new UBFeatureItemButton(); + mpAddPageButton->setText(tr("Add to page")); + mpButtonLayout->addWidget(mpAddPageButton); + + mpSetAsBackgroundButton = new UBFeatureItemButton(); + mpSetAsBackgroundButton->setText(tr("Set as background")); + mpButtonLayout->addWidget(mpSetAsBackgroundButton); + + mpAddToLibButton = new UBFeatureItemButton(); + mpAddToLibButton->setText(tr("Add to library")); + mpButtonLayout->addWidget(mpAddToLibButton); + + mpButtonLayout->addStretch(1); + + mpObjInfoLabel = new QLabel(tr("Object informations")); + mpObjInfoLabel->setStyleSheet(QString("color: #888888; font-size : 18px; font-weight:bold;")); + mpLayout->addWidget(mpObjInfoLabel, 0); + + connect(mpAddPageButton, SIGNAL(clicked()), this, SLOT(onAddToPage())); + +} + +void UBFeatureProperties::showElement( const UBFeature &elem ) +{ + if ( mpOrigPixmap ) + { + delete mpOrigPixmap; + mpOrigPixmap = NULL; + } + if ( mpElement ) + { + delete mpElement; + mpElement = NULL; + } + mpElement = new UBFeature( elem ); + mpOrigPixmap = new QPixmap( elem.getThumbnail() ); + mpThumbnail->setPixmap(elem.getThumbnail().scaledToWidth(THUMBNAIL_WIDTH)); + //populateMetadata(); + + if ( UBApplication::isFromWeb( elem.getUrl() ) ) + { + mpAddToLibButton->show(); + /*if(elem->metadatas()["Type"].toLower().contains("image")) + { + mpSetAsBackgroundButton->show(); + } + else + { + mpSetAsBackgroundButton->hide(); + }*/ + } + else + { + mpAddToLibButton->hide(); + if (UBFileSystemUtils::mimeTypeFromFileName( elem.getUrl() ).contains("image")) + { + mpSetAsBackgroundButton->show(); + } + else + { + mpSetAsBackgroundButton->hide(); + } + } +} + +void UBFeatureProperties::onAddToPage() +{ + if ( UBApplication::isFromWeb( mpElement->getUrl() ) ) + { + sDownloadFileDesc desc; + desc.isBackground = false; + desc.modal = true; + desc.name = QFileInfo( mpElement->getName() ).fileName(); + desc.url = mpElement->getUrl(); + UBDownloadManager::downloadManager()->addFileToDownload(desc); + + } + else + { + QWidget *w = parentWidget()->parentWidget(); + UBFeaturesWidget* featuresWidget = dynamic_cast( w ); + featuresWidget->getFeaturesController()->addItemToPage( *mpElement ); + } +} + +UBFeatureProperties::~UBFeatureProperties() +{ +} + +UBFeaturesPathViewer::UBFeaturesPathViewer(const QPixmap &root, const QString &rootPath, QGraphicsScene *sc, QWidget* parent, const char* name) : QGraphicsView(sc, parent) +{ + setObjectName(name); + + setAttribute(Qt::WA_StyledBackground, true); + setStyleSheet(UBApplication::globalStyleSheet()); + + layout = new QGraphicsLinearLayout(); + + container = new QGraphicsWidget(); + container->setMaximumWidth( width() - 20 ); + container->setLayout( layout ); + scene()->addItem( container ); + + UBFolderWidget* pIconLabel = new UBFolderWidget(); + pIconLabel->setStyleSheet(QString("background-color: transparent;")); + pIconLabel->setPixmap( root ); + pIconLabel->setPath(rootPath); + connect( pIconLabel, SIGNAL( clicked(const QString &) ), parent, SLOT( currentPathChanged(const QString &) ) ); + + QGraphicsProxyWidget *iconWidget = scene()->addWidget( pIconLabel ) ;; + layout->addItem( iconWidget ); + setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); + setAlignment( Qt::AlignLeft ); + setFixedHeight( 70 ); + arrowPixmap = new QPixmap(":images/navig_arrow.png"); +} + +void UBFeaturesPathViewer::addPathElement(const QPixmap &p, const QString &s) +{ + UBFolderWidget* pIconLabel = new UBFolderWidget(); + pIconLabel->setStyleSheet(QString("background-color: transparent;")); + pIconLabel->setPixmap( *arrowPixmap ); + + QGraphicsProxyWidget *iconWidget = scene()->addWidget( pIconLabel ); + layout->addItem( iconWidget ); + + + pIconLabel = new UBFolderWidget(); + + pIconLabel->setStyleSheet(QString("background-color: transparent;")); + pIconLabel->setPixmap( p.scaledToHeight( height() - 30, Qt::SmoothTransformation) ); + pIconLabel->setPath(s); + connect( pIconLabel, SIGNAL( clicked(const QString &) ), parent(), SLOT( currentPathChanged(const QString &) ) ); + + iconWidget = scene()->addWidget( pIconLabel ); + layout->addItem( iconWidget ); + scene()->invalidate(); +} + +void UBFeaturesPathViewer::truncatePath(int number) +{ + QList items = scene()->items(); + int itemsToDel = items.size() - number * 2; + for ( QList ::iterator it = items.begin() ; it != items.begin() + itemsToDel; ++it ) + { + scene()->removeItem( (*it) ); + QGraphicsLayoutItem *layoutItem = dynamic_cast(*it); + Q_ASSERT(layout); + layout->removeItem(layoutItem); + delete layoutItem; + } + scene()->invalidate(); +} + +UBFeatureItemButton::UBFeatureItemButton(QWidget *parent, const char *name):QPushButton(parent) +{ + setObjectName(name); + setStyleSheet(QString("background-color : #DDDDDD; color : #555555; border-radius : 6px; padding : 5px; font-weight : bold; font-size : 12px;")); +} + +UBFeatureItemButton::~UBFeatureItemButton() +{ + +} + +QVariant UBFeaturesModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (role == Qt::DisplayRole) + return featuresList->at(index.row()).getName(); + else if (role == Qt::DecorationRole) + { + return QIcon( featuresList->at(index.row()).getThumbnail() ); + } + else if (role == Qt::UserRole) + { + return featuresList->at(index.row()).getUrl(); + } + else if (role == Qt::UserRole + 1) + { + //return featuresList->at(index.row()).getType(); + UBFeature f = featuresList->at(index.row()); + return QVariant::fromValue( f ); + } + + return QVariant(); +} + +QMimeData* UBFeaturesModel::mimeData(const QModelIndexList &indexes) const +{ + QMimeData *mimeData = new QMimeData(); + QList urlList; + + foreach (QModelIndex index, indexes) + { + if ( index.isValid() ) + { + UBFeature element = data( index, Qt::UserRole + 1 ).value(); + urlList.push_back( QUrl::fromLocalFile( element.getFullPath() ) ); + } + } + mimeData->setUrls( urlList ); + /*QByteArray encodedData; + + QDataStream stream(&encodedData, QIODevice::WriteOnly); + + foreach (QModelIndex index, indexes) { + if (index.isValid()) { + QString str = qVariantValue(data(index)); + stream << str; + } + } + + mimeData->setData("text/uri-list", encodedData);*/ + + return mimeData; +} + +bool UBFeaturesModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent) +{ + if ( !mimeData->hasUrls() ) + return false; + if ( action == Qt::IgnoreAction ) + return true; + if ( column > 0 ) + return false; + + int endRow; + + if ( !parent.isValid() ) + { + return false; + /*if (row < 0) + endRow = featuresList->size(); + else + endRow = qMin( row, featuresList->size() );*/ + } + else + endRow = parent.row(); + + UBFeature parentFeature = parent.data( Qt::UserRole + 1).value(); + + QList urls = mimeData->urls(); + + foreach ( QUrl url, urls ) + { + UBFeature element = UBFeaturesController::moveItemToFolder( url, parentFeature ); + beginInsertRows( QModelIndex(), featuresList->size(), featuresList->size() ); + featuresList->push_back( element ); + endInsertRows(); + } + return true; +} + +bool UBFeaturesModel::removeRows( int row, int count, const QModelIndex & parent ) +{ + if ( row < 0 ) + return false; + if ( row + count >= featuresList->size() ) + return false; + beginRemoveRows( parent, row, row + count - 1 ); + featuresList->remove( row, count ); + endRemoveRows(); + return true; +} + +bool UBFeaturesModel::removeRow( int row, const QModelIndex & parent ) +{ + if ( row < 0 ) + return false; + if ( row >= featuresList->size() ) + return false; + beginRemoveRows( parent, row, row ); + featuresList->remove( row ); + endRemoveRows(); + return true; +} + +Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const +{ + Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index); + if ( index.isValid() ) + { + UBFeature item = index.data( Qt::UserRole + 1 ).value(); + if ( item.getType() == UBFeatureElementType::FEATURE_INTERACTIVE || + item.getType() == UBFeatureElementType::FEATURE_ITEM ) + return Qt::ItemIsDragEnabled | defaultFlags; + } + return defaultFlags | Qt::ItemIsDropEnabled; +} + + +QStringList UBFeaturesModel::mimeTypes() const +{ + QStringList types; + types << "text/uri-list"; + return types; +} + +int UBFeaturesModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + else + return featuresList->size(); +} + + +bool UBFeaturesProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex & sourceParent )const +{ + QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); + QString path = index.data( Qt::UserRole ).toString(); + + return filterRegExp().exactMatch(path); +} + +bool UBFeaturesSearchProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex & sourceParent )const +{ + QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); + /*QString name = sourceModel()->data(index, Qt::DisplayRole).toString(); + eUBLibElementType type = (eUBLibElementType)sourceModel()->data(index, Qt::UserRole + 1).toInt();*/ + + UBFeature feature = sourceModel()->data(index, Qt::UserRole + 1).value(); + bool isFile = feature.getType() == UBFeatureElementType::FEATURE_INTERACTIVE || + feature.getType() == UBFeatureElementType::FEATURE_ITEM; + + return isFile && filterRegExp().exactMatch( feature.getName() ); +} + +bool UBFeaturesPathProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex & sourceParent )const +{ + QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); + /*QString name = sourceModel()->data(index, Qt::DisplayRole).toString(); + eUBLibElementType type = (eUBLibElementType)sourceModel()->data(index, Qt::UserRole + 1).toInt();*/ + + UBFeature feature = sourceModel()->data(index, Qt::UserRole + 1).value(); + bool isFolder = feature.getType() == UBFeatureElementType::FEATURE_CATEGORY || + feature.getType() == UBFeatureElementType::FEATURE_FOLDER; + QString virtualFullPath = feature.getUrl() + "/" + feature.getName(); + + return isFolder && path.startsWith( virtualFullPath ); +} + +QString UBFeaturesItemDelegate::displayText ( const QVariant & value, const QLocale & locale ) const +{ + QString text = value.toString(); + if (listView) + { + const QFontMetrics fm = listView->fontMetrics(); + const QSize iSize = listView->iconSize(); + + if ( iSize.width() > 0 && fm.width(text) > iSize.width() ) + { + while (fm.width(text) > iSize.width()) + text.resize(text.size()-1); + text += "..."; + } + } + return text; +} + +UBFeaturesPathItemDelegate::UBFeaturesPathItemDelegate(QWidget *parent) : QStyledItemDelegate(parent) +{ + arrowPixmap = new QPixmap(":images/navig_arrow.png"); +} + +QString UBFeaturesPathItemDelegate::displayText ( const QVariant & value, const QLocale & locale ) const +{ + return ""; +} + +void UBFeaturesPathItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + UBFeature feature = index.data( Qt::UserRole + 1 ).value(); + QRect rect = option.rect; + if ( !feature.getPath().isEmpty() ) + { + 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 ) ); +} + +UBFeaturesPathItemDelegate::~UBFeaturesPathItemDelegate() +{ + if ( arrowPixmap ) + { + delete arrowPixmap; + arrowPixmap = NULL; + } +} \ No newline at end of file diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h new file mode 100644 index 00000000..4e0c36df --- /dev/null +++ b/src/gui/UBFeaturesWidget.h @@ -0,0 +1,247 @@ +#ifndef UBFEATURESWIDGET_H +#define UBFEATURESWIDGET_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "UBDockPaletteWidget.h" +#include "UBLibActionBar.h" +#include "board/UBFeaturesController.h" + + +#define THUMBNAIL_WIDTH 400 +#define ID_LISTVIEW 0 +#define ID_PROPERTIES 1 + +class UBListModel; + +class UBFeaturesModel; +class UBFeaturesItemDelegate; +class UBFeaturesPathItemDelegate; +class UBFeaturesProxyModel; +class UBFeaturesSearchProxyModel; +class UBFeaturesPathProxyModel; +class UBFeaturesPathViewer; +class UBFeatureProperties; +class UBFeatureItemButton; + +class UBFeaturesWidget : public UBDockPaletteWidget +{ + Q_OBJECT +public: + UBFeaturesWidget(QWidget* parent=0, const char* name="UBFeaturesWidget"); + virtual ~UBFeaturesWidget(); + + bool visibleInMode(eUBDockPaletteWidgetMode mode) + { + return mode == eUBDockPaletteWidget_BOARD + || mode == eUBDockPaletteWidget_DESKTOP; + } + UBFeaturesController * getFeaturesController()const { return controller; }; +private: + void switchToListView(); + void switchToProperties(); + + UBFeaturesController *controller; + + UBFeaturesItemDelegate *itemDelegate; + UBFeaturesPathItemDelegate *pathItemDelegate; + + UBFeaturesModel *featuresModel; + UBFeaturesProxyModel *featuresProxyModel; + UBFeaturesSearchProxyModel *featuresSearchModel; + UBFeaturesPathProxyModel *featuresPathModel; + + QListView *featuresListView; + QListView *pathListView; + QVBoxLayout *layout; + UBFeaturesPathViewer *pathViewer; + QGraphicsScene *pathScene; + UBLibActionBar *mActionBar; + UBFeatureProperties *featureProperties; + QStackedWidget *stackedWidget; + + int currentStackedWidget; +private slots: + void currentSelected(const QModelIndex &); + void currentPathChanged(const QString &); + void currentPathChanged( const QModelIndex & ); + void searchStarted(QString); +}; + +class UBFeaturesPathViewer : public QGraphicsView +{ + Q_OBJECT +public: + UBFeaturesPathViewer(const QPixmap &root, const QString &rootPath, QGraphicsScene *sc, QWidget* parent=0, const char* name="UBFeaturesPathViewer"); + virtual ~UBFeaturesPathViewer() {} ; + void addPathElement(const QPixmap &p, const QString &s); + void truncatePath(int number); +private: + QGraphicsLinearLayout *layout; + QGraphicsWidget *container; + QPixmap *arrowPixmap; +}; + + +class UBFolderWidget : public QLabel +{ + Q_OBJECT +public: + UBFolderWidget( QWidget * parent = 0, Qt::WindowFlags f = 0 ) : QLabel( parent, f ) {}; + virtual ~UBFolderWidget() {}; + virtual QString getPath()const { return path; }; + virtual void setPath( const QString &p ) { path = p; }; +signals: + void clicked(const QString &); +protected: + virtual void mouseReleaseEvent ( QMouseEvent * ev ) + { + emit clicked(path); + }; + virtual void mousePressEvent ( QMouseEvent * ev ) + { + ev->accept(); + }; +private: + QString path; +}; + + +class UBFeatureProperties : public QWidget +{ + Q_OBJECT +public: + UBFeatureProperties(QWidget* parent=0, const char* name="UBFeatureProperties"); + ~UBFeatureProperties(); + + void showElement(const UBFeature &elem); + + +protected: + //void resizeEvent(QResizeEvent *event); + //void showEvent(QShowEvent *event); + +private slots: + void onAddToPage(); + //void onAddToLib(); + //void onSetAsBackground(); + //void onBack(); + +private: + QVBoxLayout* mpLayout; + QHBoxLayout* mpButtonLayout; + UBFeatureItemButton* mpAddPageButton; + UBFeatureItemButton* mpAddToLibButton; + UBFeatureItemButton* mpSetAsBackgroundButton; + QLabel* mpObjInfoLabel; + //QTreeWidget* mpObjInfos; + QLabel* mpThumbnail; + QPixmap* mpOrigPixmap; + int maxThumbHeight; + UBFeature *mpElement; + //QTreeWidgetItem* mpItem; +}; + + + + +class UBFeatureItemButton : public QPushButton +{ +public: + UBFeatureItemButton(QWidget* parent=0, const char* name="UBFeatureItemButton"); + ~UBFeatureItemButton(); +}; + +class UBFeaturesModel : public QAbstractListModel +{ + Q_OBJECT +public: + UBFeaturesModel( QObject *parent = 0 ) { }; + virtual ~UBFeaturesModel(){}; + + QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; + QMimeData *mimeData( const QModelIndexList &indexes ) const; + QStringList mimeTypes() const; + int rowCount( const QModelIndex &parent ) const; + Qt::ItemFlags flags( const QModelIndex &index ) const; + bool dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent); + bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); + bool removeRow(int row, const QModelIndex &parent = QModelIndex()); + Qt::DropActions supportedDropActions() const { return Qt::MoveAction | Qt::CopyAction; }; + + void setFeaturesList( QVector *flist ) { featuresList = flist; }; +private: + QVector *featuresList; +}; + +class UBFeaturesProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT +public: + UBFeaturesProxyModel(QObject *parent = 0) { QSortFilterProxyModel::QSortFilterProxyModel(parent); }; + virtual ~UBFeaturesProxyModel() {}; +protected: + virtual bool filterAcceptsRow ( int sourceRow, const QModelIndex & sourceParent ) const; +}; + +class UBFeaturesSearchProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT +public: + UBFeaturesSearchProxyModel(QObject *parent = 0) { QSortFilterProxyModel::QSortFilterProxyModel(parent); }; + virtual ~UBFeaturesSearchProxyModel() {}; +protected: + virtual bool filterAcceptsRow ( int sourceRow, const QModelIndex & sourceParent ) const; +}; + +class UBFeaturesPathProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT +public: + UBFeaturesPathProxyModel(QObject *parent = 0) { QSortFilterProxyModel::QSortFilterProxyModel(parent); }; + virtual ~UBFeaturesPathProxyModel() {}; + void setPath( const QString &p ) { path = p; }; +protected: + virtual bool filterAcceptsRow ( int sourceRow, const QModelIndex & sourceParent ) const; +private: + QString path; +}; + +class UBFeaturesItemDelegate : public QStyledItemDelegate +{ + Q_OBJECT +public: + UBFeaturesItemDelegate(QWidget *parent = 0, const QListView *lw = 0) : QStyledItemDelegate(parent) { listView = lw; }; + ~UBFeaturesItemDelegate() {}; + //UBFeaturesItemDelegate(const QListView *lw = 0) { listView = lw; }; + //void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + //QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; + virtual QString displayText ( const QVariant & value, const QLocale & locale ) const; +private: + const QListView *listView; +}; + +class UBFeaturesPathItemDelegate : public QStyledItemDelegate +{ + Q_OBJECT +public: + UBFeaturesPathItemDelegate(QWidget *parent = 0); + ~UBFeaturesPathItemDelegate(); + virtual QString displayText ( const QVariant & value, const QLocale & locale ) const; + void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; +private: + QPixmap *arrowPixmap; +}; + +#endif // UBFEATURESWIDGET_H \ No newline at end of file diff --git a/src/gui/UBLibraryWidget.h b/src/gui/UBLibraryWidget.h index e4eb8d02..7f3bbeb4 100644 --- a/src/gui/UBLibraryWidget.h +++ b/src/gui/UBLibraryWidget.h @@ -29,6 +29,7 @@ #include #include "UBThumbnailWidget.h" +#include "board/UBLibraryController.h" class UBLibraryController; class UBChainedLibElement; diff --git a/src/gui/gui.pri b/src/gui/gui.pri index a901409f..2a033a4f 100644 --- a/src/gui/gui.pri +++ b/src/gui/gui.pri @@ -46,6 +46,7 @@ HEADERS += src/gui/UBThumbnailView.h \ src/gui/UBLibWebView.h \ src/gui/UBDownloadWidget.h \ src/gui/UBDockDownloadWidget.h \ + src/gui/UBFeaturesWidget.h\ src/gui/UBDockTeacherGuideWidget.h \ src/gui/UBTeacherGuideWidget.h \ src/gui/UBTeacherGuideWidgetsTools.h \ @@ -99,6 +100,7 @@ SOURCES += src/gui/UBThumbnailView.cpp \ src/gui/UBLibWebView.cpp \ src/gui/UBDownloadWidget.cpp \ src/gui/UBDockDownloadWidget.cpp \ + src/gui/UBFeaturesWidget.cpp\ src/gui/UBDockTeacherGuideWidget.cpp \ src/gui/UBTeacherGuideWidget.cpp \ src/gui/UBTeacherGuideWidgetsTools.cpp \ From 2e04977035baf713dcb8887ab73a43f2e3353fba Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Mon, 16 Apr 2012 16:41:26 +0300 Subject: [PATCH 02/12] UBFeaturesTab added basic functionality partialy implemented --- resources/style.qss | 10 +++++++++- src/board/UBBoardPaletteManager.cpp | 1 + src/board/UBBoardView.cpp | 3 ++- src/gui/UBFeaturesWidget.cpp | 16 ++++++++++------ 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/resources/style.qss b/resources/style.qss index 38eeecbc..8bc816cd 100644 --- a/resources/style.qss +++ b/resources/style.qss @@ -4,7 +4,8 @@ QWidget#UBLibPathViewer, QWidget#UBLibNavigatorWidget, QWidget#UBLibItemProperties, QWidget#UBDownloadWidget, -QWidget#UBTeacherGuideWidget +QWidget#UBTeacherGuideWidget, +QWidget#UBFeatureProperties { background: #EEEEEE; border-radius: 10px; @@ -25,6 +26,13 @@ QWidget#UBLibWebView border: 2px solid #999999; } +QListView +{ + background: #EEEEEE; + border-radius : 10px; + border: 2px solid #999999; +} + QWebView#SearchEngineView { background:white; diff --git a/src/board/UBBoardPaletteManager.cpp b/src/board/UBBoardPaletteManager.cpp index e8f6aaa4..25f9d1d8 100644 --- a/src/board/UBBoardPaletteManager.cpp +++ b/src/board/UBBoardPaletteManager.cpp @@ -138,6 +138,7 @@ void UBBoardPaletteManager::setupDockPaletteWidgets() mpDownloadWidget = new UBDockDownloadWidget(); mpTeacherGuideWidget = new UBDockTeacherGuideWidget(); + mpFeaturesWidget = new UBFeaturesWidget(); // Add the dock palettes mLeftPalette = new UBLeftPalette(mContainer); diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index c655ac3c..0d8e7c39 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -16,6 +16,7 @@ #include #include +#include #include "UBDrawingController.h" @@ -808,7 +809,7 @@ void UBBoardView::dropEvent (QDropEvent *event) } else if (!event->source() || dynamic_cast(event->source()) || dynamic_cast(event->source()) - || dynamic_cast(event->source())) + || dynamic_cast(event->source()) || dynamic_cast(event->source()) ) { mController->processMimeData (event->mimeData (), mapToScene (event->pos ())); diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index dbdaa99b..e8f0722d 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -4,6 +4,7 @@ #include "frameworks/UBFileSystemUtils.h" #include "core/UBApplication.h" #include "core/UBDownloadManager.h" +#include "globals/UBGlobals.h" UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPaletteWidget(parent) { @@ -11,8 +12,9 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale mName = "FeaturesWidget"; mVisibleState = true; - setAttribute(Qt::WA_StyledBackground, true); - setStyleSheet(UBApplication::globalStyleSheet()); + SET_STYLE_SHEET(); + //setAttribute(Qt::WA_StyledBackground, true); + //setStyleSheet(UBApplication::globalStyleSheet()); mIconToLeft = QPixmap(":images/library_open.png"); mIconToRight = QPixmap(":images/library_close.png"); @@ -44,6 +46,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale featuresPathModel->setSourceModel( featuresModel ); + //featuresListView->setStyleSheet( QString("background: #EEEEEE;border-radius: 10px;border: 2px solid #999999;") ); featuresListView->setDragDropMode( QAbstractItemView::InternalMove ); featuresListView->setModel( featuresProxyModel ); @@ -55,6 +58,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale featuresListView->setIconSize( QSize(40, 40) ); featuresListView->setGridSize( QSize(70, 70) ); + //pathListView->setStyleSheet( QString("background: #EEEEEE; border-radius : 10px; border : 2px solid #999999;") ); pathListView->setModel( featuresPathModel ); pathListView->setViewMode( QListView::IconMode ); pathListView->setIconSize( QSize(30, 30) ); @@ -201,8 +205,8 @@ UBFeatureProperties::UBFeatureProperties( QWidget *parent, const char *name ) : { setObjectName(name); - setAttribute(Qt::WA_StyledBackground, true); - setStyleSheet(UBApplication::globalStyleSheet()); + SET_STYLE_SHEET(); + //setStyleSheet(UBApplication::globalStyleSheet()); // Create the GUI mpLayout = new QVBoxLayout(this); @@ -316,9 +320,9 @@ UBFeaturesPathViewer::UBFeaturesPathViewer(const QPixmap &root, const QString &r { setObjectName(name); - setAttribute(Qt::WA_StyledBackground, true); + /*setAttribute(Qt::WA_StyledBackground, true); setStyleSheet(UBApplication::globalStyleSheet()); - +*/ layout = new QGraphicsLinearLayout(); container = new QGraphicsWidget(); From 14e326effe1b5ecf37f97b93535438ed94a82862 Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Wed, 18 Apr 2012 12:51:03 +0300 Subject: [PATCH 03/12] Some bugs fixed and more DnD functionality implemented --- src/board/UBFeaturesController.cpp | 37 ++++++++++++++++++++-- src/board/UBFeaturesController.h | 5 +-- src/gui/UBFeaturesWidget.cpp | 50 ++++++++++++++++++++---------- src/gui/UBFeaturesWidget.h | 16 ++++++++-- 4 files changed, 84 insertions(+), 24 deletions(-) diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp index e7609d2a..2175d94f 100644 --- a/src/board/UBFeaturesController.cpp +++ b/src/board/UBFeaturesController.cpp @@ -27,7 +27,7 @@ UBFeature::UBFeature(const QString &url, const QPixmap &icon, const QString &nam UBFeature::UBFeature(const UBFeature &f) { virtualPath = f.getUrl(); - mPath = f.getPath(); + mPath = f.getFullPath(); mThumbnail = f.getThumbnail(); mName = f.getName(); elementType = f.getType(); @@ -110,7 +110,7 @@ void UBFeaturesController::fileSystemScan(const QString & currentPath, const QSt } QString itemName = (fileType != FEATURE_ITEM) ? fileName : fileInfo->completeBaseName(); QPixmap icon = QPixmap(":images/libpalette/soundIcon.svg"); - QString fullFileName = currentPath + "/" + fileName; + QString fullFileName = fileInfo->filePath(); if ( fileType == FEATURE_FOLDER ) { @@ -131,7 +131,7 @@ void UBFeaturesController::fileSystemScan(const QString & currentPath, const QSt icon = QPixmap( thumbnailPath ); 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 ) { @@ -194,7 +194,16 @@ void UBFeaturesController::addItemToPage(const UBFeature &item) UBFeature UBFeaturesController::moveItemToFolder( const QUrl &url, const UBFeature &destination ) { + UBFeature newElement = copyItemToFolder( url, destination ); 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() ); @@ -217,8 +226,30 @@ UBFeature UBFeaturesController::moveItemToFolder( const QUrl &url, const UBFeatu if ( UBFileSystemUtils::mimeTypeFromFileName( newFullPath ).contains("application") ) type = UBFeatureElementType::FEATURE_INTERACTIVE; 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; } + /* void UBFeaturesController::addImageToCurrentPage( const QString &path ) { diff --git a/src/board/UBFeaturesController.h b/src/board/UBFeaturesController.h index cde23347..e08eff53 100644 --- a/src/board/UBFeaturesController.h +++ b/src/board/UBFeaturesController.h @@ -31,8 +31,8 @@ public: return mThumbnail; }; QString getUrl() const { return virtualPath; }; - QString getPath() const { return mPath; }; - QString getFullPath() const { return mPath + "/" + mName; }; + //QString getPath() const { return mPath; }; + QString getFullPath() const { return mPath; }; UBFeatureElementType getType() const { return elementType; } ; private: QString virtualPath; @@ -58,6 +58,7 @@ public: void addItemToPage(const UBFeature &item); static QPixmap thumbnailForFile( const QString &path ); static UBFeature moveItemToFolder( const QUrl &url, const UBFeature &destination ); + static UBFeature copyItemToFolder( const QUrl &url, const UBFeature &destination ); private: void initDirectoryTree(); void fileSystemScan(const QString &currPath, const QString & currVirtualPath); diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index e8f0722d..12215fcd 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -28,8 +28,8 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale featuresModel = new UBFeaturesModel(this); featuresModel->setFeaturesList( controller->getFeatures() ); featuresModel->setSupportedDragActions( Qt::CopyAction | Qt::MoveAction ); - featuresListView = new QListView(this); - pathListView = new QListView(this); + featuresListView = new UBFeaturesListView(this); + pathListView = new UBFeaturesListView(this); featuresProxyModel = new UBFeaturesProxyModel(this); @@ -69,7 +69,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale pathListView->setSelectionMode( QAbstractItemView::NoSelection ); pathListView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); pathListView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); - pathListView->setMovement( QListView::Static ); + //pathListView->setMovement( QListView::Static ); pathListView->setDragDropMode( QAbstractItemView::DragDrop ); 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( event->source() ) ) + { + event->setDropAction( Qt::MoveAction ); + } + QListView::dropEvent( event ); +} + + UBFeatureProperties::UBFeatureProperties( QWidget *parent, const char *name ) : QWidget(parent) , mpLayout(NULL) , mpButtonLayout(NULL) @@ -432,18 +447,6 @@ QMimeData* UBFeaturesModel::mimeData(const QModelIndexList &indexes) const } } mimeData->setUrls( urlList ); - /*QByteArray encodedData; - - QDataStream stream(&encodedData, QIODevice::WriteOnly); - - foreach (QModelIndex index, indexes) { - if (index.isValid()) { - QString str = qVariantValue(data(index)); - stream << str; - } - } - - mimeData->setData("text/uri-list", encodedData);*/ return mimeData; } @@ -476,7 +479,16 @@ bool UBFeaturesModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction act 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() ); featuresList->push_back( element ); endInsertRows(); @@ -517,6 +529,10 @@ Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const if ( item.getType() == UBFeatureElementType::FEATURE_INTERACTIVE || item.getType() == UBFeatureElementType::FEATURE_ITEM ) 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; } @@ -605,7 +621,7 @@ void UBFeaturesPathItemDelegate::paint( QPainter *painter, const QStyleOptionVie { UBFeature feature = index.data( Qt::UserRole + 1 ).value(); QRect rect = option.rect; - if ( !feature.getPath().isEmpty() ) + if ( !feature.getFullPath().isEmpty() ) { painter->drawPixmap( rect.left() - 10, rect.center().y() - 5, *arrowPixmap ); } diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index 4e0c36df..d4e881c6 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -13,6 +13,7 @@ #include #include #include +#include #include "UBDockPaletteWidget.h" #include "UBLibActionBar.h" @@ -34,6 +35,7 @@ class UBFeaturesPathProxyModel; class UBFeaturesPathViewer; class UBFeatureProperties; class UBFeatureItemButton; +class UBFeaturesListView; class UBFeaturesWidget : public UBDockPaletteWidget { @@ -62,8 +64,8 @@ private: UBFeaturesSearchProxyModel *featuresSearchModel; UBFeaturesPathProxyModel *featuresPathModel; - QListView *featuresListView; - QListView *pathListView; + UBFeaturesListView *featuresListView; + UBFeaturesListView *pathListView; QVBoxLayout *layout; UBFeaturesPathViewer *pathViewer; QGraphicsScene *pathScene; @@ -79,6 +81,16 @@ private slots: 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 { Q_OBJECT From 4b182e733fd3235d8599945c5d332491c0a06e56 Mon Sep 17 00:00:00 2001 From: Ivan Ilin Date: Wed, 18 Apr 2012 14:14:47 +0300 Subject: [PATCH 04/12] linux gcc fixes --- src/board/UBFeaturesController.cpp | 4 +-- src/board/UBFeaturesController.h | 28 ++++++++--------- src/gui/UBFeaturesWidget.cpp | 37 +++++++++++++--------- src/gui/UBFeaturesWidget.h | 49 +++++++++++++++--------------- 4 files changed, 62 insertions(+), 56 deletions(-) diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp index 2175d94f..a2346abb 100644 --- a/src/board/UBFeaturesController.cpp +++ b/src/board/UBFeaturesController.cpp @@ -243,9 +243,9 @@ UBFeature UBFeaturesController::copyItemToFolder( const QUrl &url, const UBFeatu QPixmap thumb = thumbnailForFile( newFullPath ); - UBFeatureElementType type = UBFeatureElementType::FEATURE_ITEM; + UBFeatureElementType type = FEATURE_ITEM; if ( UBFileSystemUtils::mimeTypeFromFileName( newFullPath ).contains("application") ) - type = UBFeatureElementType::FEATURE_INTERACTIVE; + type = FEATURE_INTERACTIVE; UBFeature newElement( destVirtualPath, thumb, name, newFullPath, type ); return newElement; } diff --git a/src/board/UBFeaturesController.h b/src/board/UBFeaturesController.h index e08eff53..5d6544d9 100644 --- a/src/board/UBFeaturesController.h +++ b/src/board/UBFeaturesController.h @@ -22,24 +22,22 @@ enum UBFeatureElementType class UBFeature { public: - UBFeature(){}; + UBFeature() {;} UBFeature(const UBFeature &f); - UBFeature(const QString &url, const QPixmap &icon, const QString &name, const QString &realPath, UBFeatureElementType type = FEATURE_CATEGORY); - virtual ~UBFeature(){}; - QString getName() const { return mName; }; - QPixmap getThumbnail() const { - return mThumbnail; - }; - QString getUrl() const { return virtualPath; }; + UBFeature(const QString &url, const QPixmap &icon, const QString &name, const QString &realPath, UBFeatureElementType type = FEATURE_CATEGORY); + virtual ~UBFeature() {;} + QString getName() const { return mName; } + QPixmap getThumbnail() const {return mThumbnail;} + QString getUrl() const { return virtualPath; } //QString getPath() const { return mPath; }; - QString getFullPath() const { return mPath; }; - UBFeatureElementType getType() const { return elementType; } ; + QString getFullPath() const { return mPath; } + UBFeatureElementType getType() const { return elementType; } private: QString virtualPath; - QString mPath; QPixmap mThumbnail; QString mName; - UBFeatureElementType elementType; + QString mPath; + UBFeatureElementType elementType; }; Q_DECLARE_METATYPE( UBFeature ) @@ -51,9 +49,9 @@ public: UBFeaturesController(QWidget *parentWidget); virtual ~UBFeaturesController(); - QVector * getFeatures()const { return featuresList; }; + QVector * getFeatures()const { return featuresList; } - QString getRootPath()const { return rootPath; }; + QString getRootPath()const { return rootPath; } void addItemToPage(const UBFeature &item); static QPixmap thumbnailForFile( const QString &path ); @@ -97,4 +95,4 @@ private: -#endif \ No newline at end of file +#endif diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index 12215fcd..b2848cce 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -123,7 +123,7 @@ void UBFeaturesWidget::currentSelected(const QModelIndex ¤t) QString path = model->data(current, Qt::UserRole).toString(); eUBLibElementType type = (eUBLibElementType)model->data(current, Qt::UserRole + 1).toInt();*/ UBFeature feature = model->data(current, Qt::UserRole + 1).value(); - if ( feature.getType() == UBFeatureElementType::FEATURE_FOLDER || feature.getType() == UBFeatureElementType::FEATURE_CATEGORY) + if ( feature.getType() == FEATURE_FOLDER || feature.getType() == FEATURE_CATEGORY) { QString newPath = feature.getUrl() + "/" + feature.getName(); //pathViewer->addPathElement( feature.getThumbnail(), newPath ); @@ -453,16 +453,18 @@ QMimeData* UBFeaturesModel::mimeData(const QModelIndexList &indexes) const bool UBFeaturesModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent) { - if ( !mimeData->hasUrls() ) + Q_UNUSED(row) + + if ( !mimeData->hasUrls() ) return false; if ( action == Qt::IgnoreAction ) return true; if ( column > 0 ) return false; - int endRow; + int endRow = 0; - if ( !parent.isValid() ) + if ( !parent.isValid() ) { return false; /*if (row < 0) @@ -526,11 +528,11 @@ Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const if ( index.isValid() ) { UBFeature item = index.data( Qt::UserRole + 1 ).value(); - if ( item.getType() == UBFeatureElementType::FEATURE_INTERACTIVE || - item.getType() == UBFeatureElementType::FEATURE_ITEM ) + if ( item.getType() == FEATURE_INTERACTIVE || + item.getType() == FEATURE_ITEM ) return Qt::ItemIsDragEnabled | defaultFlags; - if ( item.getType() == UBFeatureElementType::FEATURE_FOLDER || - item.getType() == UBFeatureElementType::FEATURE_CATEGORY && item.getFullPath() != "") + if ( item.getType() == FEATURE_FOLDER || + (item.getType() == FEATURE_CATEGORY && item.getFullPath() != "")) return defaultFlags | Qt::ItemIsDropEnabled; else return defaultFlags; } @@ -569,8 +571,8 @@ bool UBFeaturesSearchProxyModel::filterAcceptsRow( int sourceRow, const QModelIn eUBLibElementType type = (eUBLibElementType)sourceModel()->data(index, Qt::UserRole + 1).toInt();*/ UBFeature feature = sourceModel()->data(index, Qt::UserRole + 1).value(); - bool isFile = feature.getType() == UBFeatureElementType::FEATURE_INTERACTIVE || - feature.getType() == UBFeatureElementType::FEATURE_ITEM; + bool isFile = feature.getType() == FEATURE_INTERACTIVE || + feature.getType() == FEATURE_ITEM; return isFile && filterRegExp().exactMatch( feature.getName() ); } @@ -582,8 +584,8 @@ bool UBFeaturesPathProxyModel::filterAcceptsRow( int sourceRow, const QModelInde eUBLibElementType type = (eUBLibElementType)sourceModel()->data(index, Qt::UserRole + 1).toInt();*/ UBFeature feature = sourceModel()->data(index, Qt::UserRole + 1).value(); - bool isFolder = feature.getType() == UBFeatureElementType::FEATURE_CATEGORY || - feature.getType() == UBFeatureElementType::FEATURE_FOLDER; + bool isFolder = feature.getType() == FEATURE_CATEGORY || + feature.getType() == FEATURE_FOLDER; QString virtualFullPath = feature.getUrl() + "/" + feature.getName(); return isFolder && path.startsWith( virtualFullPath ); @@ -591,7 +593,9 @@ bool UBFeaturesPathProxyModel::filterAcceptsRow( int sourceRow, const QModelInde QString UBFeaturesItemDelegate::displayText ( const QVariant & value, const QLocale & locale ) const { - QString text = value.toString(); + Q_UNUSED(locale) + + QString text = value.toString(); if (listView) { const QFontMetrics fm = listView->fontMetrics(); @@ -614,7 +618,10 @@ UBFeaturesPathItemDelegate::UBFeaturesPathItemDelegate(QWidget *parent) : QStyle QString UBFeaturesPathItemDelegate::displayText ( const QVariant & value, const QLocale & locale ) const { - return ""; + Q_UNUSED(value) + Q_UNUSED(locale) + + return QString(); } void UBFeaturesPathItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const @@ -635,4 +642,4 @@ UBFeaturesPathItemDelegate::~UBFeaturesPathItemDelegate() delete arrowPixmap; arrowPixmap = NULL; } -} \ No newline at end of file +} diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index d4e881c6..c4cca921 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -86,7 +86,7 @@ class UBFeaturesListView : public QListView Q_OBJECT public: UBFeaturesListView( QWidget* parent=0, const char* name="UBFeaturesListView" ); - virtual ~UBFeaturesListView() {}; + virtual ~UBFeaturesListView() {;} protected: virtual void dropEvent( QDropEvent *event ); }; @@ -96,7 +96,7 @@ class UBFeaturesPathViewer : public QGraphicsView Q_OBJECT public: UBFeaturesPathViewer(const QPixmap &root, const QString &rootPath, QGraphicsScene *sc, QWidget* parent=0, const char* name="UBFeaturesPathViewer"); - virtual ~UBFeaturesPathViewer() {} ; + virtual ~UBFeaturesPathViewer() {;} void addPathElement(const QPixmap &p, const QString &s); void truncatePath(int number); private: @@ -110,21 +110,22 @@ class UBFolderWidget : public QLabel { Q_OBJECT public: - UBFolderWidget( QWidget * parent = 0, Qt::WindowFlags f = 0 ) : QLabel( parent, f ) {}; - virtual ~UBFolderWidget() {}; - virtual QString getPath()const { return path; }; - virtual void setPath( const QString &p ) { path = p; }; + UBFolderWidget( QWidget * parent = 0, Qt::WindowFlags f = 0 ) : QLabel( parent, f ) {;} + virtual ~UBFolderWidget() {;} + virtual QString getPath()const { return path;} + virtual void setPath( const QString &p ) { path = p;} signals: void clicked(const QString &); protected: - virtual void mouseReleaseEvent ( QMouseEvent * ev ) + virtual void mouseReleaseEvent ( QMouseEvent * ev ) { - emit clicked(path); - }; + Q_UNUSED(ev) + emit clicked(path); + } virtual void mousePressEvent ( QMouseEvent * ev ) { ev->accept(); - }; + } private: QString path; }; @@ -179,8 +180,8 @@ class UBFeaturesModel : public QAbstractListModel { Q_OBJECT public: - UBFeaturesModel( QObject *parent = 0 ) { }; - virtual ~UBFeaturesModel(){}; + UBFeaturesModel( QObject *parent = 0 ) : QAbstractListModel(parent) {;} + virtual ~UBFeaturesModel(){;} QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; QMimeData *mimeData( const QModelIndexList &indexes ) const; @@ -190,9 +191,9 @@ public: bool dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent); bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); bool removeRow(int row, const QModelIndex &parent = QModelIndex()); - Qt::DropActions supportedDropActions() const { return Qt::MoveAction | Qt::CopyAction; }; + Qt::DropActions supportedDropActions() const { return Qt::MoveAction | Qt::CopyAction; } - void setFeaturesList( QVector *flist ) { featuresList = flist; }; + void setFeaturesList( QVector *flist ) { featuresList = flist; } private: QVector *featuresList; }; @@ -201,8 +202,8 @@ class UBFeaturesProxyModel : public QSortFilterProxyModel { Q_OBJECT public: - UBFeaturesProxyModel(QObject *parent = 0) { QSortFilterProxyModel::QSortFilterProxyModel(parent); }; - virtual ~UBFeaturesProxyModel() {}; + UBFeaturesProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent) {;} + virtual ~UBFeaturesProxyModel() {} protected: virtual bool filterAcceptsRow ( int sourceRow, const QModelIndex & sourceParent ) const; }; @@ -211,8 +212,8 @@ class UBFeaturesSearchProxyModel : public QSortFilterProxyModel { Q_OBJECT public: - UBFeaturesSearchProxyModel(QObject *parent = 0) { QSortFilterProxyModel::QSortFilterProxyModel(parent); }; - virtual ~UBFeaturesSearchProxyModel() {}; + UBFeaturesSearchProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent) {;} + virtual ~UBFeaturesSearchProxyModel() {} protected: virtual bool filterAcceptsRow ( int sourceRow, const QModelIndex & sourceParent ) const; }; @@ -221,9 +222,9 @@ class UBFeaturesPathProxyModel : public QSortFilterProxyModel { Q_OBJECT public: - UBFeaturesPathProxyModel(QObject *parent = 0) { QSortFilterProxyModel::QSortFilterProxyModel(parent); }; - virtual ~UBFeaturesPathProxyModel() {}; - void setPath( const QString &p ) { path = p; }; + UBFeaturesPathProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent) {;} + virtual ~UBFeaturesPathProxyModel() {} + void setPath( const QString &p ) { path = p; } protected: virtual bool filterAcceptsRow ( int sourceRow, const QModelIndex & sourceParent ) const; private: @@ -234,8 +235,8 @@ class UBFeaturesItemDelegate : public QStyledItemDelegate { Q_OBJECT public: - UBFeaturesItemDelegate(QWidget *parent = 0, const QListView *lw = 0) : QStyledItemDelegate(parent) { listView = lw; }; - ~UBFeaturesItemDelegate() {}; + UBFeaturesItemDelegate(QWidget *parent = 0, const QListView *lw = 0) : QStyledItemDelegate(parent) { listView = lw; } + ~UBFeaturesItemDelegate() {} //UBFeaturesItemDelegate(const QListView *lw = 0) { listView = lw; }; //void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; //QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; @@ -256,4 +257,4 @@ private: QPixmap *arrowPixmap; }; -#endif // UBFEATURESWIDGET_H \ No newline at end of file +#endif // UBFEATURESWIDGET_H From b7ceb4d3d59d6543314dac8e5811e5746a482d5b Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Wed, 18 Apr 2012 19:42:05 +0300 Subject: [PATCH 05/12] Fixed some DnD bugs, added action bar class --- src/board/UBFeaturesController.cpp | 4 ++-- src/board/UBFeaturesController.h | 1 + src/gui/UBFeaturesActionBar.cpp | 9 +++++++++ src/gui/UBFeaturesActionBar.h | 17 +++++++++++++++++ src/gui/UBFeaturesWidget.cpp | 17 +++++++++++++---- src/gui/gui.pri | 6 ++++-- 6 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 src/gui/UBFeaturesActionBar.cpp create mode 100644 src/gui/UBFeaturesActionBar.h diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp index a2346abb..8768811f 100644 --- a/src/board/UBFeaturesController.cpp +++ b/src/board/UBFeaturesController.cpp @@ -60,7 +60,7 @@ void UBFeaturesController::initDirectoryTree() QList tools = UBToolsManager::manager()->allTools(); - featuresList->push_back( UBFeature( "", QPixmap( ":images/libpalette/home.png" ), "root", "" ) ); + featuresList->push_back( UBFeature( QString(), QPixmap( ":images/libpalette/home.png" ), "root", QString() ) ); appPath = rootPath + "/Applications"; audiosPath = rootPath + "/Audios"; @@ -80,7 +80,7 @@ void UBFeaturesController::initDirectoryTree() foreach (UBToolsManager::UBToolDescriptor tool, tools) { - featuresList->push_back( UBFeature( appPath, tool.icon, tool.label, mUserInteractiveDirectoryPath, FEATURE_INTERACTIVE ) ); + featuresList->push_back( UBFeature( appPath, tool.icon, tool.label, tool.id, FEATURE_INTERNAL ) ); } fileSystemScan( mUserInteractiveDirectoryPath, appPath ); fileSystemScan( mUserAudioDirectoryPath, audiosPath ); diff --git a/src/board/UBFeaturesController.h b/src/board/UBFeaturesController.h index 5d6544d9..4da21c1d 100644 --- a/src/board/UBFeaturesController.h +++ b/src/board/UBFeaturesController.h @@ -16,6 +16,7 @@ enum UBFeatureElementType FEATURE_VIRTUALFOLDER, FEATURE_FOLDER, FEATURE_INTERACTIVE, + FEATURE_INTERNAL, FEATURE_ITEM }; diff --git a/src/gui/UBFeaturesActionBar.cpp b/src/gui/UBFeaturesActionBar.cpp new file mode 100644 index 00000000..0f5000a4 --- /dev/null +++ b/src/gui/UBFeaturesActionBar.cpp @@ -0,0 +1,9 @@ +#include "UBFeaturesActionBar.h" + +UBFeaturesActionBar::UBFeaturesActionBar( QWidget* parent, const char* name ) : QWidget (parent) +{ +} + +UBFeaturesActionBar::~UBFeaturesActionBar() +{ +} \ No newline at end of file diff --git a/src/gui/UBFeaturesActionBar.h b/src/gui/UBFeaturesActionBar.h new file mode 100644 index 00000000..a939a826 --- /dev/null +++ b/src/gui/UBFeaturesActionBar.h @@ -0,0 +1,17 @@ +#ifndef UBFEATURESACTIONBAR_H +#define UBFEATURESACTIONBAR_H + +#include +#include +#include "UBLibActionBar.h" + +class UBFeaturesActionBar : public QWidget +{ + Q_OBJECT +public: + UBFeaturesActionBar(QWidget* parent=0, const char* name="UBFeaturesActionBar"); + ~UBFeaturesActionBar(); +}; + + +#endif \ No newline at end of file diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index b2848cce..0f115f48 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -106,7 +106,7 @@ void UBFeaturesWidget::searchStarted( QString pattern ) featuresListView->setModel( featuresProxyModel ); featuresProxyModel->invalidate(); } - else + else if ( pattern.size() > 2 ) { featuresSearchModel->setFilterWildcard( "*" + pattern + "*" ); featuresListView->setModel( featuresSearchModel ); @@ -443,7 +443,14 @@ QMimeData* UBFeaturesModel::mimeData(const QModelIndexList &indexes) const if ( index.isValid() ) { UBFeature element = data( index, Qt::UserRole + 1 ).value(); - urlList.push_back( QUrl::fromLocalFile( element.getFullPath() ) ); + if ( element.getType() == FEATURE_INTERNAL ) + { + urlList.push_back( QUrl( element.getFullPath() ) ); + } + else if ( element.getType() == FEATURE_INTERACTIVE || element.getType() == FEATURE_ITEM ) + { + urlList.push_back( QUrl::fromLocalFile(element.getFullPath()) ); + } } } mimeData->setUrls( urlList ); @@ -529,10 +536,11 @@ Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const { UBFeature item = index.data( Qt::UserRole + 1 ).value(); if ( item.getType() == FEATURE_INTERACTIVE || - item.getType() == FEATURE_ITEM ) + item.getType() == FEATURE_ITEM || + item.getType() == FEATURE_INTERNAL ) return Qt::ItemIsDragEnabled | defaultFlags; if ( item.getType() == FEATURE_FOLDER || - (item.getType() == FEATURE_CATEGORY && item.getFullPath() != "")) + (item.getType() == FEATURE_CATEGORY && !item.getFullPath().isNull())) return defaultFlags | Qt::ItemIsDropEnabled; else return defaultFlags; } @@ -572,6 +580,7 @@ bool UBFeaturesSearchProxyModel::filterAcceptsRow( int sourceRow, const QModelIn UBFeature feature = sourceModel()->data(index, Qt::UserRole + 1).value(); bool isFile = feature.getType() == FEATURE_INTERACTIVE || + feature.getType() == FEATURE_INTERNAL || feature.getType() == FEATURE_ITEM; return isFile && filterRegExp().exactMatch( feature.getName() ); diff --git a/src/gui/gui.pri b/src/gui/gui.pri index 2a033a4f..a1dd1218 100644 --- a/src/gui/gui.pri +++ b/src/gui/gui.pri @@ -46,7 +46,8 @@ HEADERS += src/gui/UBThumbnailView.h \ src/gui/UBLibWebView.h \ src/gui/UBDownloadWidget.h \ src/gui/UBDockDownloadWidget.h \ - src/gui/UBFeaturesWidget.h\ + src/gui/UBFeaturesWidget.h \ + src/gui/UBFeaturesActionBar.h \ src/gui/UBDockTeacherGuideWidget.h \ src/gui/UBTeacherGuideWidget.h \ src/gui/UBTeacherGuideWidgetsTools.h \ @@ -100,7 +101,8 @@ SOURCES += src/gui/UBThumbnailView.cpp \ src/gui/UBLibWebView.cpp \ src/gui/UBDownloadWidget.cpp \ src/gui/UBDockDownloadWidget.cpp \ - src/gui/UBFeaturesWidget.cpp\ + src/gui/UBFeaturesWidget.cpp \ + src/gui/UBFeaturesActionBar.cpp \ src/gui/UBDockTeacherGuideWidget.cpp \ src/gui/UBTeacherGuideWidget.cpp \ src/gui/UBTeacherGuideWidgetsTools.cpp \ From addc1fe130a508f5a61353d7c6c4caf3344137e8 Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Fri, 20 Apr 2012 17:30:53 +0300 Subject: [PATCH 06/12] Implemented new folder creating --- src/board/UBFeaturesController.cpp | 31 +++++-- src/board/UBFeaturesController.h | 5 + src/gui/UBFeaturesActionBar.cpp | 143 ++++++++++++++++++++++++++++- src/gui/UBFeaturesActionBar.h | 45 ++++++++- src/gui/UBFeaturesWidget.cpp | 51 ++++++++-- src/gui/UBFeaturesWidget.h | 18 ++-- 6 files changed, 264 insertions(+), 29 deletions(-) diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp index 8768811f..cd260d5a 100644 --- a/src/board/UBFeaturesController.cpp +++ b/src/board/UBFeaturesController.cpp @@ -60,7 +60,8 @@ void UBFeaturesController::initDirectoryTree() QList tools = UBToolsManager::manager()->allTools(); - featuresList->push_back( UBFeature( QString(), QPixmap( ":images/libpalette/home.png" ), "root", QString() ) ); + featuresList->append( UBFeature( QString(), QPixmap( ":images/libpalette/home.png" ), "root", QString() ) ); + currentElement = featuresList->at(0); appPath = rootPath + "/Applications"; audiosPath = rootPath + "/Audios"; @@ -70,17 +71,17 @@ void UBFeaturesController::initDirectoryTree() interactPath = rootPath + "/Interactivities"; shapesPath = rootPath + "/Shapes"; - featuresList->push_back( UBFeature( rootPath, QPixmap(":images/libpalette/AudiosCategory.svg"), "Audios" , mUserAudioDirectoryPath ) ); - featuresList->push_back( UBFeature( rootPath, QPixmap(":images/libpalette/MoviesCategory.svg"), "Movies" , mUserVideoDirectoryPath ) ); - featuresList->push_back( UBFeature( rootPath, QPixmap(":images/libpalette/PicturesCategory.svg"), "Pictures" , mUserPicturesDirectoryPath ) ); - featuresList->push_back( UBFeature( rootPath, QPixmap(":images/libpalette/ApplicationsCategory.svg"), "Applications" , mUserInteractiveDirectoryPath ) ); - featuresList->push_back( UBFeature( rootPath, QPixmap(":images/libpalette/FlashCategory.svg"), "Animations" , mUserAnimationDirectoryPath ) ); - featuresList->push_back( UBFeature( rootPath, QPixmap(":images/libpalette/InteractivesCategory.svg"), "Interactivities" , mLibInteractiveDirectoryPath ) ); - featuresList->push_back( UBFeature( rootPath, QPixmap(":images/libpalette/ShapesCategory.svg"), "Shapes" , mLibShapesDirectoryPath ) ); + featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/AudiosCategory.svg"), "Audios" , mUserAudioDirectoryPath ) ); + featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/MoviesCategory.svg"), "Movies" , mUserVideoDirectoryPath ) ); + featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/PicturesCategory.svg"), "Pictures" , mUserPicturesDirectoryPath ) ); + featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/ApplicationsCategory.svg"), "Applications" , mUserInteractiveDirectoryPath ) ); + featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/FlashCategory.svg"), "Animations" , mUserAnimationDirectoryPath ) ); + featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/InteractivesCategory.svg"), "Interactivities" , mLibInteractiveDirectoryPath ) ); + featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/ShapesCategory.svg"), "Shapes" , mLibShapesDirectoryPath ) ); foreach (UBToolsManager::UBToolDescriptor tool, tools) { - featuresList->push_back( UBFeature( appPath, tool.icon, tool.label, tool.id, FEATURE_INTERNAL ) ); + featuresList->append( UBFeature( appPath, tool.icon, tool.label, tool.id, FEATURE_INTERNAL ) ); } fileSystemScan( mUserInteractiveDirectoryPath, appPath ); fileSystemScan( mUserAudioDirectoryPath, audiosPath ); @@ -131,7 +132,7 @@ void UBFeaturesController::fileSystemScan(const QString & currentPath, const QSt icon = QPixmap( thumbnailPath ); else icon = createThumbnail( fullFileName );*/ } - featuresList->push_back( UBFeature( currVirtualPath, icon, fileName, fullFileName, fileType ) ); + featuresList->append( UBFeature( currVirtualPath, icon, fileName, fullFileName, fileType ) ); if ( fileType == FEATURE_FOLDER ) { @@ -187,6 +188,16 @@ QPixmap UBFeaturesController::createThumbnail(const QString &path) return QPixmap(thumbnailPath); } +UBFeature UBFeaturesController::newFolder( const QString &name ) +{ + QString path = currentElement.getFullPath() + "/" + name; + if(!QFileInfo(path).exists()) + { + QDir().mkpath(path); + } + return UBFeature( currentElement.getUrl() + "/" + currentElement.getName(), QPixmap(":images/libpalette/folder.svg"), name, path, FEATURE_FOLDER ); +} + void UBFeaturesController::addItemToPage(const UBFeature &item) { UBApplication::boardController->downloadURL( QUrl::fromLocalFile( item.getFullPath() ) ); diff --git a/src/board/UBFeaturesController.h b/src/board/UBFeaturesController.h index 4da21c1d..8a36cd44 100644 --- a/src/board/UBFeaturesController.h +++ b/src/board/UBFeaturesController.h @@ -55,9 +55,13 @@ public: QString getRootPath()const { return rootPath; } void addItemToPage(const UBFeature &item); + UBFeature getCurrentElement()const { return currentElement; } + void setCurrentElement( const UBFeature &elem ) { currentElement = elem; } + static QPixmap thumbnailForFile( const QString &path ); static UBFeature moveItemToFolder( const QUrl &url, const UBFeature &destination ); static UBFeature copyItemToFolder( const QUrl &url, const UBFeature &destination ); + UBFeature newFolder( const QString &name ); private: void initDirectoryTree(); void fileSystemScan(const QString &currPath, const QString & currVirtualPath); @@ -92,6 +96,7 @@ private: QString interactPath; int mLastItemOffsetIndex; + UBFeature currentElement; }; diff --git a/src/gui/UBFeaturesActionBar.cpp b/src/gui/UBFeaturesActionBar.cpp index 0f5000a4..b1bc9cfe 100644 --- a/src/gui/UBFeaturesActionBar.cpp +++ b/src/gui/UBFeaturesActionBar.cpp @@ -1,9 +1,150 @@ #include "UBFeaturesActionBar.h" -UBFeaturesActionBar::UBFeaturesActionBar( QWidget* parent, const char* name ) : QWidget (parent) +UBFeaturesActionBar::UBFeaturesActionBar( UBFeaturesController *controller, QWidget* parent, const char* name ) : QWidget (parent) + , featuresController(controller) + , mButtonGroup(NULL) + , mSearchBar(NULL) + , mLayout(NULL) + , mpFavoriteAction(NULL) + , mpSocialAction(NULL) + , mpDeleteAction(NULL) + , mpSearchAction(NULL) + , mpCloseAction(NULL) + , mpRemoveFavorite(NULL) + , mpNewFolderAction(NULL) + , mpFavoriteBtn(NULL) + , mpSocialBtn(NULL) + , mpDeleteBtn(NULL) + , mpCloseBtn(NULL) + , mpRemoveFavoriteBtn(NULL) + , mpNewFolderBtn(NULL) { + setObjectName(name); + setStyleSheet(QString("background: #EEEEEE; border-radius : 10px; border : 2px solid #999999;")); + + setAcceptDrops(true); + + mButtonGroup = new QButtonGroup(this); + mSearchBar = new QLineEdit(this); + mSearchBar->setStyleSheet(QString("background-color:white; border-radius : 10px; padding : 2px;")); + //connect(mSearchBar, SIGNAL(returnPressed()), this, SLOT(onActionSearch())); + + mLayout = new QHBoxLayout(); + setLayout(mLayout); + + setMaximumHeight(ACTIONBAR_HEIGHT); + + // Create the actions + mpFavoriteAction = new QAction(QIcon(":/images/libpalette/miniFavorite.png"), tr("Add to favorites"), this); + mpSocialAction = new QAction(QIcon(":/images/libpalette/social.png"), tr("Share"), this); + mpSearchAction = new QAction(QIcon(":/images/libpalette/miniSearch.png"), tr("Search"), this); + mpDeleteAction = new QAction(QIcon(":/images/libpalette/miniTrash.png"), tr("Delete"), this); + mpCloseAction = new QAction(QIcon(":/images/close.svg"), tr("Back to folder"), this); + mpRemoveFavorite = new QAction(QIcon(":/images/libpalette/trash_favorite.svg"), tr("Remove from favorites"), this); + mpNewFolderAction = new QAction(QIcon(":/images/libpalette/miniNewFolder.png"), tr("Create new folder"), this); + + // Create the buttons + mpFavoriteBtn = new UBActionButton(this, mpFavoriteAction); + mpSocialBtn = new UBActionButton(this, mpSocialAction); + //mpSearchBtn = new UBActionButton(this, mpSearchAction); + mpDeleteBtn = new UBActionButton(this, mpDeleteAction); + mpCloseBtn = new UBActionButton(this, mpCloseAction); + mpRemoveFavoriteBtn = new UBActionButton(this, mpRemoveFavorite); + mpNewFolderBtn = new UBActionButton(this, mpNewFolderAction); + + // Initialize the buttons + //mpSearchBtn->setEnabled(false); + mpNewFolderBtn->setEnabled(false); + + // Add the buttons to the button group + mButtonGroup->addButton(mpFavoriteBtn); + mButtonGroup->addButton(mpSocialBtn); + //mButtonGroup->addButton(mpSearchBtn); + mButtonGroup->addButton(mpDeleteBtn); + mButtonGroup->addButton(mpCloseBtn); + mButtonGroup->addButton(mpRemoveFavoriteBtn); + mButtonGroup->addButton(mpNewFolderBtn); + // Connect signals & slots + /*connect(mpFavoriteAction,SIGNAL(triggered()), this, SLOT(onActionFavorite())); + connect(mpSocialAction,SIGNAL(triggered()), this, SLOT(onActionSocial())); + connect(mpSearchAction,SIGNAL(triggered()), this, SLOT(onActionSearch())); + connect(mpDeleteAction,SIGNAL(triggered()), this, SLOT(onActionTrash())); + connect(mpCloseAction, SIGNAL(triggered()), this, SLOT(onActionClose())); + connect(mpRemoveFavorite, SIGNAL(triggered()), this, SLOT(onActionRemoveFavorite())); + connect(mSearchBar, SIGNAL(textChanged(QString)), this, SLOT(onSearchTextChanged(QString))); + connect(mpNewFolderAction, SIGNAL(triggered()), this, SLOT(onActionNewFolder()));*/ + + connect(mSearchBar, SIGNAL(textChanged(QString)), this, SLOT(onSearchTextChanged(QString))); + connect(mpNewFolderAction, SIGNAL(triggered()), this, SLOT(onActionNewFolder())); + + // Build the default toolbar + mLayout->addWidget(mpFavoriteBtn); + mLayout->addWidget(mpSocialBtn); + mLayout->addWidget(mpNewFolderBtn); + mLayout->addWidget(mSearchBar); + //mLayout->addWidget(mpSearchBtn); + mLayout->addWidget(mpDeleteBtn); + mLayout->addWidget(mpCloseBtn); + mLayout->addWidget(mpRemoveFavoriteBtn); + setCurrentState( IN_ROOT ); +} + +void UBFeaturesActionBar::setCurrentState( UBFeaturesActionBarState state ) +{ + currentState = state; + setButtons(); +} + +void UBFeaturesActionBar::setButtons() +{ + switch( currentState ) + { + case IN_FOLDER: + mpNewFolderBtn->setEnabled(true); + case IN_ROOT: + mpFavoriteBtn->show(); + mpSocialBtn->hide(); + mSearchBar->show(); + mpDeleteBtn->show(); + mpCloseBtn->hide(); + mpRemoveFavoriteBtn->hide(); + mpNewFolderBtn->show(); + break; + case IN_PROPERTIES: + mpFavoriteBtn->show(); + mpSocialBtn->hide(); + mSearchBar->show(); + //mpSearchBtn->show(); + mpDeleteBtn->hide(); + mpCloseBtn->hide(); + mpRemoveFavoriteBtn->hide(); + mpNewFolderBtn->hide(); + break; + case IN_FAVORITE: + mpFavoriteBtn->hide(); + mpSocialBtn->hide(); + mSearchBar->show(); + //mpSearchBtn->show(); + mpDeleteBtn->hide(); + mpCloseBtn->hide(); + mpRemoveFavoriteBtn->show(); + mpNewFolderBtn->hide(); + break; + default: + break; + } +} + +void UBFeaturesActionBar::onSearchTextChanged(QString txt) +{ + emit searchElement(mSearchBar->text()); } +void UBFeaturesActionBar::onActionNewFolder() +{ + emit newFolderToCreate(); +} + UBFeaturesActionBar::~UBFeaturesActionBar() { } \ No newline at end of file diff --git a/src/gui/UBFeaturesActionBar.h b/src/gui/UBFeaturesActionBar.h index a939a826..0eae4fe8 100644 --- a/src/gui/UBFeaturesActionBar.h +++ b/src/gui/UBFeaturesActionBar.h @@ -4,13 +4,56 @@ #include #include #include "UBLibActionBar.h" +#include "board/UBFeaturesController.h" + +enum UBFeaturesActionBarState +{ + IN_ROOT, + IN_FOLDER, + IN_PROPERTIES, + IN_FAVORITE +}; class UBFeaturesActionBar : public QWidget { Q_OBJECT public: - UBFeaturesActionBar(QWidget* parent=0, const char* name="UBFeaturesActionBar"); + UBFeaturesActionBar(UBFeaturesController *controller, QWidget* parent=0, const char* name="UBFeaturesActionBar"); ~UBFeaturesActionBar(); + + void setCurrentState( UBFeaturesActionBarState state ); +signals: + void searchElement(QString text); + void newFolderToCreate(); +private slots: + void onSearchTextChanged(QString txt); + void onActionNewFolder(); +private: + void setButtons(); + UBFeaturesController *featuresController; + UBFeaturesActionBarState currentState; + + eButtonSet mCrntButtonSet; + eButtonSet mPreviousButtonSet; + + QButtonGroup* mButtonGroup; + QLineEdit* mSearchBar; + QHBoxLayout* mLayout; + QAction* mpFavoriteAction; + QAction* mpSocialAction; + QAction* mpDeleteAction; + QAction* mpSearchAction; + QAction* mpCloseAction; + QAction* mpRemoveFavorite; + QAction* mpNewFolderAction; + UBActionButton* mpFavoriteBtn; + UBActionButton* mpSocialBtn; + UBActionButton* mpDeleteBtn; + //UBActionButton* mpSearchBtn; + UBActionButton* mpCloseBtn; + UBActionButton* mpRemoveFavoriteBtn; + UBActionButton* mpNewFolderBtn; + }; diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index 0f115f48..0e6f36b8 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -1,6 +1,7 @@ #include "UBFeaturesWidget.h" #include "domain/UBAbstractWidget.h" #include "gui/UBThumbnailWidget.h" +#include "gui/UBLibraryWidget.h" #include "frameworks/UBFileSystemUtils.h" #include "core/UBApplication.h" #include "core/UBDownloadManager.h" @@ -87,7 +88,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale stackedWidget->setCurrentIndex(ID_LISTVIEW); currentStackedWidget = ID_LISTVIEW; - mActionBar = new UBLibActionBar(this); + mActionBar = new UBFeaturesActionBar(controller, this); layout->addWidget(mActionBar); /*connect(featuresListView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex &, const QModelIndex & )), @@ -95,6 +96,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale connect( featuresListView, SIGNAL(clicked ( const QModelIndex & ) ), this, SLOT( currentSelected(const QModelIndex &) ) ); connect( mActionBar, SIGNAL( searchElement(QString) ), this, SLOT( searchStarted(QString) ) ); + connect( mActionBar, SIGNAL( newFolderToCreate() ), this, SLOT( createNewFolder() ) ); connect( pathListView, SIGNAL(clicked( const QModelIndex & ) ), this, SLOT( currentPathChanged( const QModelIndex & ) ) ); } @@ -127,6 +129,7 @@ void UBFeaturesWidget::currentSelected(const QModelIndex ¤t) { QString newPath = feature.getUrl() + "/" + feature.getName(); //pathViewer->addPathElement( feature.getThumbnail(), newPath ); + controller->setCurrentElement( feature ); model->setFilterFixedString( newPath ); model->invalidate(); @@ -134,11 +137,13 @@ void UBFeaturesWidget::currentSelected(const QModelIndex ¤t) featuresPathModel->setPath( newPath ); featuresPathModel->invalidate(); + mActionBar->setCurrentState( IN_FOLDER ); } else { featureProperties->showElement( feature ); switchToProperties(); + mActionBar->setCurrentState( IN_PROPERTIES ); } } @@ -158,9 +163,29 @@ void UBFeaturesWidget::currentPathChanged(const QModelIndex &index) featuresProxyModel->setFilterFixedString(newPath); featuresProxyModel->invalidate(); switchToListView(); + controller->setCurrentElement( feature ); + if ( feature.getType() == FEATURE_CATEGORY && feature.getName() == "root" ) + { + mActionBar->setCurrentState( IN_ROOT ); + } + else + { + mActionBar->setCurrentState( IN_FOLDER ); + } } } +void UBFeaturesWidget::createNewFolder() +{ + UBNewFolderDlg dlg; + if(QDialog::Accepted == dlg.exec()) + { + UBFeature newFolder = controller->newFolder( dlg.folderName() ); + featuresModel->addItem( newFolder ); + featuresProxyModel->invalidate(); + } + +} void UBFeaturesWidget::switchToListView() { @@ -175,6 +200,7 @@ void UBFeaturesWidget::switchToProperties() } +/* void UBFeaturesWidget::currentPathChanged(const QString &path) { @@ -185,7 +211,7 @@ void UBFeaturesWidget::currentPathChanged(const QString &path) featuresProxyModel->invalidate(); switchToListView(); } - +*/ UBFeaturesWidget::~UBFeaturesWidget() @@ -330,14 +356,14 @@ void UBFeatureProperties::onAddToPage() UBFeatureProperties::~UBFeatureProperties() { } - +/* UBFeaturesPathViewer::UBFeaturesPathViewer(const QPixmap &root, const QString &rootPath, QGraphicsScene *sc, QWidget* parent, const char* name) : QGraphicsView(sc, parent) { setObjectName(name); - /*setAttribute(Qt::WA_StyledBackground, true); - setStyleSheet(UBApplication::globalStyleSheet()); -*/ + //setAttribute(Qt::WA_StyledBackground, true); + //setStyleSheet(UBApplication::globalStyleSheet()); + layout = new QGraphicsLinearLayout(); container = new QGraphicsWidget(); @@ -396,7 +422,7 @@ void UBFeaturesPathViewer::truncatePath(int number) } scene()->invalidate(); } - +*/ UBFeatureItemButton::UBFeatureItemButton(QWidget *parent, const char *name):QPushButton(parent) { setObjectName(name); @@ -498,13 +524,18 @@ bool UBFeaturesModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction act { element = UBFeaturesController::copyItemToFolder( url, parentFeature ); } - beginInsertRows( QModelIndex(), featuresList->size(), featuresList->size() ); - featuresList->push_back( element ); - endInsertRows(); + addItem( element ); } return true; } +void UBFeaturesModel::addItem( const UBFeature &item ) +{ + beginInsertRows( QModelIndex(), featuresList->size(), featuresList->size() ); + featuresList->push_back( item ); + endInsertRows(); +} + bool UBFeaturesModel::removeRows( int row, int count, const QModelIndex & parent ) { if ( row < 0 ) diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index c4cca921..4902d111 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -16,8 +16,9 @@ #include #include "UBDockPaletteWidget.h" -#include "UBLibActionBar.h" +//#include "UBLibActionBar.h" #include "board/UBFeaturesController.h" +#include "UBFeaturesActionBar.h" #define THUMBNAIL_WIDTH 400 @@ -67,18 +68,19 @@ private: UBFeaturesListView *featuresListView; UBFeaturesListView *pathListView; QVBoxLayout *layout; - UBFeaturesPathViewer *pathViewer; + //UBFeaturesPathViewer *pathViewer; QGraphicsScene *pathScene; - UBLibActionBar *mActionBar; + UBFeaturesActionBar *mActionBar; UBFeatureProperties *featureProperties; QStackedWidget *stackedWidget; int currentStackedWidget; private slots: - void currentSelected(const QModelIndex &); - void currentPathChanged(const QString &); + void currentSelected( const QModelIndex & ); + //void currentPathChanged(const QString &); void currentPathChanged( const QModelIndex & ); - void searchStarted(QString); + void searchStarted( QString ); + void createNewFolder(); }; class UBFeaturesListView : public QListView @@ -91,6 +93,7 @@ protected: virtual void dropEvent( QDropEvent *event ); }; +/* class UBFeaturesPathViewer : public QGraphicsView { Q_OBJECT @@ -129,7 +132,7 @@ protected: private: QString path; }; - +*/ class UBFeatureProperties : public QWidget { @@ -183,6 +186,7 @@ public: UBFeaturesModel( QObject *parent = 0 ) : QAbstractListModel(parent) {;} virtual ~UBFeaturesModel(){;} + void addItem( const UBFeature &item ); QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; QMimeData *mimeData( const QModelIndexList &indexes ) const; QStringList mimeTypes() const; From 512fd4155489870ab667ca36cba76366b5d120bd Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Mon, 23 Apr 2012 18:10:27 +0300 Subject: [PATCH 07/12] Implemented deleting items --- src/board/UBFeaturesController.cpp | 70 +++++-------------- src/board/UBFeaturesController.h | 13 +++- src/gui/UBFeaturesActionBar.cpp | 38 ++++++++++ src/gui/UBFeaturesActionBar.h | 8 ++- src/gui/UBFeaturesWidget.cpp | 107 ++++++++++------------------- src/gui/UBFeaturesWidget.h | 5 +- 6 files changed, 114 insertions(+), 127 deletions(-) diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp index cd260d5a..b6180dbe 100644 --- a/src/board/UBFeaturesController.cpp +++ b/src/board/UBFeaturesController.cpp @@ -55,6 +55,7 @@ void UBFeaturesController::initDirectoryTree() mLibInteractiveDirectoryPath = UBSettings::settings()->applicationInteractivesDirectory(); mLibApplicationsDirectoryPath = UBSettings::settings()->applicationApplicationsLibraryDirectory(); mLibShapesDirectoryPath = UBSettings::settings()->applicationShapeLibraryDirectory() ; + trashDirectoryPath = UBSettings::userTrashDirPath(); featuresList = new QVector (); @@ -70,6 +71,7 @@ void UBFeaturesController::initDirectoryTree() flashPath = rootPath + "/Animations"; interactPath = rootPath + "/Interactivities"; shapesPath = rootPath + "/Shapes"; + trashPath = rootPath + "/Trash"; featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/AudiosCategory.svg"), "Audios" , mUserAudioDirectoryPath ) ); featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/MoviesCategory.svg"), "Movies" , mUserVideoDirectoryPath ) ); @@ -78,6 +80,8 @@ void UBFeaturesController::initDirectoryTree() featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/FlashCategory.svg"), "Animations" , mUserAnimationDirectoryPath ) ); featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/InteractivesCategory.svg"), "Interactivities" , mLibInteractiveDirectoryPath ) ); featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/ShapesCategory.svg"), "Shapes" , mLibShapesDirectoryPath ) ); + trashElement = UBFeature( rootPath, QPixmap(":images/libpalette/TrashCategory.svg"), "Trash", trashDirectoryPath, FEATURE_TRASH ); + featuresList->append( trashElement ); foreach (UBToolsManager::UBToolDescriptor tool, tools) { @@ -93,6 +97,7 @@ void UBFeaturesController::initDirectoryTree() fileSystemScan( mLibPicturesDirectoryPath, picturesPath ); fileSystemScan( mLibShapesDirectoryPath, shapesPath ); fileSystemScan( mLibInteractiveDirectoryPath, interactPath ); + fileSystemScan( trashDirectoryPath, trashPath ); } @@ -206,38 +211,15 @@ void UBFeaturesController::addItemToPage(const UBFeature &item) UBFeature UBFeaturesController::moveItemToFolder( const QUrl &url, const UBFeature &destination ) { UBFeature newElement = copyItemToFolder( url, destination ); - QString sourcePath = url.toLocalFile(); - QFile::remove( sourcePath ); - QString thumbnailPath = UBFileSystemUtils::thumbnailPath( sourcePath ); - if (thumbnailPath.length() && QFileInfo( thumbnailPath ).exists()) - { - QFile::remove(thumbnailPath); - } - return newElement; + deleteItem( url ); /*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 ); QFile::remove( sourcePath ); - QString thumbnailPath = UBFileSystemUtils::thumbnailPath( sourcePath ); if (thumbnailPath.length() && QFileInfo( thumbnailPath ).exists()) { QFile::remove(thumbnailPath); - } - - QPixmap thumb = thumbnailForFile( newFullPath ); - - UBFeatureElementType type = UBFeatureElementType::FEATURE_ITEM; - if ( UBFileSystemUtils::mimeTypeFromFileName( newFullPath ).contains("application") ) - type = UBFeatureElementType::FEATURE_INTERACTIVE; - UBFeature newElement( destVirtualPath, thumb, name, destPath, type ); - return newElement;*/ + }*/ + return newElement; } UBFeature UBFeaturesController::copyItemToFolder( const QUrl &url, const UBFeature &destination ) @@ -261,37 +243,23 @@ UBFeature UBFeaturesController::copyItemToFolder( const QUrl &url, const UBFeatu return newElement; } -/* -void UBFeaturesController::addImageToCurrentPage( const QString &path ) +void UBFeaturesController::deleteItem( const QUrl &url ) { - QPointF pos = UBApplication::boardController->activeScene()->normalizedSceneRect().center(); - mLastItemOffsetIndex = qMin(mLastItemOffsetIndex, 5); + QString path = url.toLocalFile(); + Q_ASSERT( QFileInfo( path ).exists() ); - QGraphicsItem* itemInScene = 0; - - if ( UBApplication::boardController->activeScene() ) + QString thumbnailPath = UBFileSystemUtils::thumbnailPath( path ); + if (thumbnailPath.length() && QFileInfo( thumbnailPath ).exists()) { - QString mimeType = UBFileSystemUtils::mimeTypeFromFileName( path ); - - pos = QPointF( pos.x() + 50 * mLastItemOffsetIndex, pos.y() + 50 * mLastItemOffsetIndex ); - mLastItemOffsetIndex++; - //TODO UB 4.x move this logic to the scene .. - if (mimeType == "image/svg+xml") - { - itemInScene = UBApplication::boardController->activeScene()->addSvg( QUrl::fromLocalFile(path), pos ); - } - else - { - itemInScene = UBApplication::boardController->activeScene()->addPixmap( QPixmap(path), pos ); - } + QFile::remove(thumbnailPath); } + QFile::remove( path ); +} - if (itemInScene) - { - itemInScene = UBApplication::boardController->activeScene()->scaleToFitDocumentSize(itemInScene, false, UBSettings::objectInControlViewMargin); - } +bool UBFeaturesController::isTrash( const QUrl &url ) +{ + return url.toLocalFile().startsWith( trashDirectoryPath ); } -*/ UBFeaturesController::~UBFeaturesController() { diff --git a/src/board/UBFeaturesController.h b/src/board/UBFeaturesController.h index 8a36cd44..f1c0e485 100644 --- a/src/board/UBFeaturesController.h +++ b/src/board/UBFeaturesController.h @@ -17,7 +17,8 @@ enum UBFeatureElementType FEATURE_FOLDER, FEATURE_INTERACTIVE, FEATURE_INTERNAL, - FEATURE_ITEM + FEATURE_ITEM, + FEATURE_TRASH }; class UBFeature @@ -52,15 +53,18 @@ public: QVector * getFeatures()const { return featuresList; } - QString getRootPath()const { return rootPath; } + const QString& getRootPath()const { return rootPath; } void addItemToPage(const UBFeature &item); - UBFeature getCurrentElement()const { return currentElement; } + const UBFeature& getCurrentElement()const { return currentElement; } void setCurrentElement( const UBFeature &elem ) { currentElement = elem; } + const UBFeature & getTrashElement () const { return trashElement; } static QPixmap thumbnailForFile( const QString &path ); static UBFeature moveItemToFolder( const QUrl &url, const UBFeature &destination ); static UBFeature copyItemToFolder( const QUrl &url, const UBFeature &destination ); + static void deleteItem( const QUrl &url ); + bool isTrash( const QUrl &url ); UBFeature newFolder( const QString &name ); private: void initDirectoryTree(); @@ -85,6 +89,7 @@ private: QString mLibAnimationDirectoryPath; QString mLibApplicationsDirectoryPath; QString mLibShapesDirectoryPath; + QString trashDirectoryPath; QString rootPath; QString audiosPath; @@ -94,9 +99,11 @@ private: QString flashPath; QString shapesPath; QString interactPath; + QString trashPath; int mLastItemOffsetIndex; UBFeature currentElement; + UBFeature trashElement; }; diff --git a/src/gui/UBFeaturesActionBar.cpp b/src/gui/UBFeaturesActionBar.cpp index b1bc9cfe..ead9b859 100644 --- a/src/gui/UBFeaturesActionBar.cpp +++ b/src/gui/UBFeaturesActionBar.cpp @@ -87,6 +87,8 @@ UBFeaturesActionBar::UBFeaturesActionBar( UBFeaturesController *controller, QWid mLayout->addWidget(mpCloseBtn); mLayout->addWidget(mpRemoveFavoriteBtn); setCurrentState( IN_ROOT ); + mpDeleteBtn->setAcceptDrops(true); + setAcceptDrops( true ); } void UBFeaturesActionBar::setCurrentState( UBFeaturesActionBarState state ) @@ -100,7 +102,16 @@ void UBFeaturesActionBar::setButtons() switch( currentState ) { case IN_FOLDER: + mpFavoriteBtn->show(); + mpSocialBtn->hide(); + mSearchBar->show(); + mpDeleteBtn->show(); + mpCloseBtn->hide(); + mpRemoveFavoriteBtn->hide(); + mpNewFolderBtn->show(); mpNewFolderBtn->setEnabled(true); + mpDeleteBtn->setEnabled(true); + break; case IN_ROOT: mpFavoriteBtn->show(); mpSocialBtn->hide(); @@ -109,6 +120,8 @@ void UBFeaturesActionBar::setButtons() mpCloseBtn->hide(); mpRemoveFavoriteBtn->hide(); mpNewFolderBtn->show(); + mpNewFolderBtn->setEnabled(false); + mpDeleteBtn->setEnabled(false); break; case IN_PROPERTIES: mpFavoriteBtn->show(); @@ -145,6 +158,31 @@ void UBFeaturesActionBar::onActionNewFolder() emit newFolderToCreate(); } +/* +void UBFeaturesActionBar::dragMoveEvent(QDragMoveEvent *event) +{ + event->acceptProposedAction(); +} +*/ + +void UBFeaturesActionBar::dragEnterEvent( QDragEnterEvent *event ) +{ + if (event->mimeData()->hasFormat("text/uri-list")) + event->acceptProposedAction(); +} + +void UBFeaturesActionBar::dropEvent( QDropEvent *event ) +{ + QWidget *dest = childAt( event->pos() ); + if ( dest == mpDeleteBtn ) + { + event->setDropAction( Qt::MoveAction ); + event->accept(); + emit deleteElements( *event->mimeData() ); + } + +} + UBFeaturesActionBar::~UBFeaturesActionBar() { } \ No newline at end of file diff --git a/src/gui/UBFeaturesActionBar.h b/src/gui/UBFeaturesActionBar.h index 0eae4fe8..c41ec13d 100644 --- a/src/gui/UBFeaturesActionBar.h +++ b/src/gui/UBFeaturesActionBar.h @@ -3,6 +3,7 @@ #include #include +#include #include "UBLibActionBar.h" #include "board/UBFeaturesController.h" @@ -23,11 +24,16 @@ public: void setCurrentState( UBFeaturesActionBarState state ); signals: - void searchElement(QString text); + void searchElement(const QString &text); void newFolderToCreate(); + void deleteElements( const QMimeData &data ); private slots: void onSearchTextChanged(QString txt); void onActionNewFolder(); +protected: + //void dragMoveEvent(QDragMoveEvent *event); + void dragEnterEvent( QDragEnterEvent *event ); + void dropEvent( QDropEvent *event ); private: void setButtons(); UBFeaturesController *featuresController; diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index 0e6f36b8..956e0130 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -48,7 +48,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale //featuresListView->setStyleSheet( QString("background: #EEEEEE;border-radius: 10px;border: 2px solid #999999;") ); - featuresListView->setDragDropMode( QAbstractItemView::InternalMove ); + featuresListView->setDragDropMode( QAbstractItemView::DragDrop ); featuresListView->setModel( featuresProxyModel ); featuresListView->setResizeMode( QListView::Adjust ); @@ -95,13 +95,14 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale this, SLOT(currentSelected(const QModelIndex &)));*/ connect( featuresListView, SIGNAL(clicked ( const QModelIndex & ) ), this, SLOT( currentSelected(const QModelIndex &) ) ); - connect( mActionBar, SIGNAL( searchElement(QString) ), this, SLOT( searchStarted(QString) ) ); + connect( mActionBar, SIGNAL( searchElement(const QString &) ), this, SLOT( const searchStarted(QString &) ) ); connect( mActionBar, SIGNAL( newFolderToCreate() ), this, SLOT( createNewFolder() ) ); + connect( mActionBar, SIGNAL( deleteElements(const QMimeData &)), this, SLOT( deleteElements(const QMimeData &) ) ); connect( pathListView, SIGNAL(clicked( const QModelIndex & ) ), this, SLOT( currentPathChanged( const QModelIndex & ) ) ); } -void UBFeaturesWidget::searchStarted( QString pattern ) +void UBFeaturesWidget::searchStarted( const QString &pattern ) { if ( pattern.isEmpty() ) { @@ -125,7 +126,8 @@ void UBFeaturesWidget::currentSelected(const QModelIndex ¤t) QString path = model->data(current, Qt::UserRole).toString(); eUBLibElementType type = (eUBLibElementType)model->data(current, Qt::UserRole + 1).toInt();*/ UBFeature feature = model->data(current, Qt::UserRole + 1).value(); - if ( feature.getType() == FEATURE_FOLDER || feature.getType() == FEATURE_CATEGORY) + if ( feature.getType() == FEATURE_FOLDER || feature.getType() == FEATURE_CATEGORY || + feature.getType() == FEATURE_TRASH ) { QString newPath = feature.getUrl() + "/" + feature.getName(); //pathViewer->addPathElement( feature.getThumbnail(), newPath ); @@ -187,6 +189,28 @@ void UBFeaturesWidget::createNewFolder() } +void UBFeaturesWidget::deleteElements( const QMimeData & mimeData ) +{ + if ( !mimeData.hasUrls() ) + return; + QList urls = mimeData.urls(); + + foreach ( QUrl url, urls ) + { + if ( controller->isTrash( url) ) + { + UBFeaturesController::deleteItem( url ); + } + else + { + UBFeature elem = UBFeaturesController::moveItemToFolder( url, controller->getTrashElement() ); + featuresModel->addItem( elem ); + } + } + QSortFilterProxyModel *model = dynamic_cast( featuresListView->model() ); + model->invalidate(); +} + void UBFeaturesWidget::switchToListView() { stackedWidget->setCurrentIndex(ID_LISTVIEW); @@ -223,6 +247,12 @@ UBFeaturesListView::UBFeaturesListView( QWidget* parent, const char* name ) : QL setObjectName(name); } +void UBFeaturesListView::dragEnterEvent( QDragEnterEvent *event ) +{ + if ( event->mimeData()->hasUrls() ) + event->acceptProposedAction(); +} + void UBFeaturesListView::dropEvent( QDropEvent *event ) { if( event->source() || dynamic_cast( event->source() ) ) @@ -356,73 +386,7 @@ void UBFeatureProperties::onAddToPage() UBFeatureProperties::~UBFeatureProperties() { } -/* -UBFeaturesPathViewer::UBFeaturesPathViewer(const QPixmap &root, const QString &rootPath, QGraphicsScene *sc, QWidget* parent, const char* name) : QGraphicsView(sc, parent) -{ - setObjectName(name); - - //setAttribute(Qt::WA_StyledBackground, true); - //setStyleSheet(UBApplication::globalStyleSheet()); - - layout = new QGraphicsLinearLayout(); - - container = new QGraphicsWidget(); - container->setMaximumWidth( width() - 20 ); - container->setLayout( layout ); - scene()->addItem( container ); - - UBFolderWidget* pIconLabel = new UBFolderWidget(); - pIconLabel->setStyleSheet(QString("background-color: transparent;")); - pIconLabel->setPixmap( root ); - pIconLabel->setPath(rootPath); - connect( pIconLabel, SIGNAL( clicked(const QString &) ), parent, SLOT( currentPathChanged(const QString &) ) ); - - QGraphicsProxyWidget *iconWidget = scene()->addWidget( pIconLabel ) ;; - layout->addItem( iconWidget ); - setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); - setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); - setAlignment( Qt::AlignLeft ); - setFixedHeight( 70 ); - arrowPixmap = new QPixmap(":images/navig_arrow.png"); -} - -void UBFeaturesPathViewer::addPathElement(const QPixmap &p, const QString &s) -{ - UBFolderWidget* pIconLabel = new UBFolderWidget(); - pIconLabel->setStyleSheet(QString("background-color: transparent;")); - pIconLabel->setPixmap( *arrowPixmap ); - - QGraphicsProxyWidget *iconWidget = scene()->addWidget( pIconLabel ); - layout->addItem( iconWidget ); - - - pIconLabel = new UBFolderWidget(); - - pIconLabel->setStyleSheet(QString("background-color: transparent;")); - pIconLabel->setPixmap( p.scaledToHeight( height() - 30, Qt::SmoothTransformation) ); - pIconLabel->setPath(s); - connect( pIconLabel, SIGNAL( clicked(const QString &) ), parent(), SLOT( currentPathChanged(const QString &) ) ); - - iconWidget = scene()->addWidget( pIconLabel ); - layout->addItem( iconWidget ); - scene()->invalidate(); -} -void UBFeaturesPathViewer::truncatePath(int number) -{ - QList items = scene()->items(); - int itemsToDel = items.size() - number * 2; - for ( QList ::iterator it = items.begin() ; it != items.begin() + itemsToDel; ++it ) - { - scene()->removeItem( (*it) ); - QGraphicsLayoutItem *layoutItem = dynamic_cast(*it); - Q_ASSERT(layout); - layout->removeItem(layoutItem); - delete layoutItem; - } - scene()->invalidate(); -} -*/ UBFeatureItemButton::UBFeatureItemButton(QWidget *parent, const char *name):QPushButton(parent) { setObjectName(name); @@ -540,7 +504,7 @@ bool UBFeaturesModel::removeRows( int row, int count, const QModelIndex & parent { if ( row < 0 ) return false; - if ( row + count >= featuresList->size() ) + if ( row + count > featuresList->size() ) return false; beginRemoveRows( parent, row, row + count - 1 ); featuresList->remove( row, count ); @@ -571,6 +535,7 @@ Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const item.getType() == FEATURE_INTERNAL ) return Qt::ItemIsDragEnabled | defaultFlags; if ( item.getType() == FEATURE_FOLDER || + item.getType() == FEATURE_TRASH || (item.getType() == FEATURE_CATEGORY && !item.getFullPath().isNull())) return defaultFlags | Qt::ItemIsDropEnabled; else return defaultFlags; diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index 4902d111..8f7b4337 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -75,12 +75,14 @@ private: QStackedWidget *stackedWidget; int currentStackedWidget; + QModelIndex trashIndex; private slots: void currentSelected( const QModelIndex & ); //void currentPathChanged(const QString &); void currentPathChanged( const QModelIndex & ); - void searchStarted( QString ); + void searchStarted( const QString & ); void createNewFolder(); + void deleteElements( const QMimeData & ); }; class UBFeaturesListView : public QListView @@ -90,6 +92,7 @@ public: UBFeaturesListView( QWidget* parent=0, const char* name="UBFeaturesListView" ); virtual ~UBFeaturesListView() {;} protected: + virtual void dragEnterEvent( QDragEnterEvent *event ); virtual void dropEvent( QDropEvent *event ); }; From fe0c8ab2e4b2c54b9f97d17abd9c4dd581db1c34 Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Thu, 26 Apr 2012 11:27:55 +0300 Subject: [PATCH 08/12] Favorite functionality partially implemented --- src/board/UBFeaturesController.cpp | 102 +++++++++++++++++++++++++++++ src/board/UBFeaturesController.h | 9 +++ src/gui/UBFeaturesActionBar.cpp | 6 ++ src/gui/UBFeaturesActionBar.h | 1 + src/gui/UBFeaturesWidget.cpp | 34 +++++++++- src/gui/UBFeaturesWidget.h | 44 ++----------- 6 files changed, 154 insertions(+), 42 deletions(-) diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp index b6180dbe..9d65120b 100644 --- a/src/board/UBFeaturesController.cpp +++ b/src/board/UBFeaturesController.cpp @@ -72,6 +72,7 @@ void UBFeaturesController::initDirectoryTree() interactPath = rootPath + "/Interactivities"; shapesPath = rootPath + "/Shapes"; trashPath = rootPath + "/Trash"; + favoritePath = rootPath + "/Favorites"; featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/AudiosCategory.svg"), "Audios" , mUserAudioDirectoryPath ) ); featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/MoviesCategory.svg"), "Movies" , mUserVideoDirectoryPath ) ); @@ -82,10 +83,18 @@ void UBFeaturesController::initDirectoryTree() featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/ShapesCategory.svg"), "Shapes" , mLibShapesDirectoryPath ) ); trashElement = UBFeature( rootPath, QPixmap(":images/libpalette/TrashCategory.svg"), "Trash", trashDirectoryPath, FEATURE_TRASH ); featuresList->append( trashElement ); + favoriteElement = UBFeature( rootPath, QPixmap(":images/libpalette/FavoritesCategory.svg"), "Favorites", "favorites" ); + featuresList->append( favoriteElement ); + + loadFavoriteList(); foreach (UBToolsManager::UBToolDescriptor tool, tools) { featuresList->append( UBFeature( appPath, tool.icon, tool.label, tool.id, FEATURE_INTERNAL ) ); + if ( favoriteSet->find( tool.id ) != favoriteSet->end() ) + { + featuresList->append( UBFeature( favoritePath, tool.icon, tool.label, tool.id, FEATURE_INTERNAL ) ); + } } fileSystemScan( mUserInteractiveDirectoryPath, appPath ); fileSystemScan( mUserAudioDirectoryPath, audiosPath ); @@ -99,6 +108,8 @@ void UBFeaturesController::initDirectoryTree() fileSystemScan( mLibInteractiveDirectoryPath, interactPath ); fileSystemScan( trashDirectoryPath, trashPath ); + + } void UBFeaturesController::fileSystemScan(const QString & currentPath, const QString & currVirtualPath) @@ -138,6 +149,10 @@ void UBFeaturesController::fileSystemScan(const QString & currentPath, const QSt else icon = createThumbnail( fullFileName );*/ } featuresList->append( UBFeature( currVirtualPath, icon, fileName, fullFileName, fileType ) ); + if ( favoriteSet->find( fullFileName ) != favoriteSet->end() ) + { + featuresList->append( UBFeature( favoritePath, icon, fileName, fullFileName, fileType ) ); + } if ( fileType == FEATURE_FOLDER ) { @@ -147,8 +162,95 @@ void UBFeaturesController::fileSystemScan(const QString & currentPath, const QSt } } +void UBFeaturesController::loadFavoriteList() +{ + favoriteSet = new QSet(); + QFile file( UBSettings::userDataDirectory() + "/favorites.dat" ); + if ( file.exists() ) + { + file.open(QIODevice::ReadOnly); + QDataStream in(&file); + int elementsNumber; + in >> elementsNumber; + for ( int i = 0; i < elementsNumber; ++i) + { + QString path; + in >> path; + /*QFileInfo fileInfo( path ); + QString fileName = fileInfo.fileName(); + + UBFeature elem( favoritePath, thumbnailForFile( path ), fileName, path, fileTypeFromUrl(path) ); + featuresList->append( elem );*/ + favoriteSet->insert( path ); + } + } +} + +void UBFeaturesController::saveFavoriteList() +{ + QFile file( UBSettings::userDataDirectory() + "/favorites.dat" ); + file.resize(0); + file.open(QIODevice::WriteOnly); + QDataStream out(&file); + out << favoriteSet->size(); + for ( QSet::iterator it = favoriteSet->begin(); it != favoriteSet->end(); ++it ) + { + out << (*it); + } + file.close(); +} + +UBFeature UBFeaturesController::addToFavorite( const QUrl &path ) +{ + QString filePath = fileNameFromUrl( path ); + if ( favoriteSet->find( filePath ) == favoriteSet->end() ) + { + QFileInfo fileInfo( filePath ); + QString fileName = fileInfo.fileName(); + UBFeature elem( favoritePath, thumbnailForFile( filePath ), fileName, filePath, fileTypeFromUrl(filePath) ); + favoriteSet->insert( filePath ); + saveFavoriteList(); + return elem; + } + return UBFeature(); +} + +QString UBFeaturesController::fileNameFromUrl( const QUrl &url ) +{ + QString fileName = url.toString(); + if ( fileName.contains( "uniboardTool://" ) ) + return fileName; + return url.toLocalFile(); +} + +UBFeatureElementType UBFeaturesController::fileTypeFromUrl( const QString &path ) +{ + QFileInfo fileInfo( path ); + QString fileName = fileInfo.fileName(); + + UBFeatureElementType fileType = fileInfo.isDir() ? FEATURE_FOLDER : FEATURE_ITEM; + if ( UBFileSystemUtils::mimeTypeFromFileName(fileName).contains("application") ) + { + fileType = FEATURE_INTERACTIVE; + } + else if ( path.contains("uniboardTool://") ) + { + fileType = FEATURE_INTERNAL; + } + return fileType; +} + QPixmap UBFeaturesController::thumbnailForFile(const QString &path) { + if ( path.contains("uniboardTool://") ) + { + return QPixmap( UBToolsManager::manager()->iconFromToolId(path) ); + } + if ( UBFileSystemUtils::mimeTypeFromFileName(path).contains("application") ) + { + return QPixmap( UBAbstractWidget::iconFilePath( QUrl::fromLocalFile(path) ) ); + } + QPixmap thumb; QString thumbnailPath = UBFileSystemUtils::thumbnailPath( path ); diff --git a/src/board/UBFeaturesController.h b/src/board/UBFeaturesController.h index f1c0e485..194b31bb 100644 --- a/src/board/UBFeaturesController.h +++ b/src/board/UBFeaturesController.h @@ -66,11 +66,16 @@ public: static void deleteItem( const QUrl &url ); bool isTrash( const QUrl &url ); UBFeature newFolder( const QString &name ); + UBFeature addToFavorite( const QUrl &path ); private: void initDirectoryTree(); void fileSystemScan(const QString &currPath, const QString & currVirtualPath); static QPixmap createThumbnail(const QString &path); //void addImageToCurrentPage( const QString &path ); + void loadFavoriteList(); + void saveFavoriteList(); + static QString fileNameFromUrl( const QUrl &url ); + static UBFeatureElementType fileTypeFromUrl( const QString &path ); QVector *featuresList; UBFeature *rootElement; @@ -100,10 +105,14 @@ private: QString shapesPath; QString interactPath; QString trashPath; + QString favoritePath; int mLastItemOffsetIndex; UBFeature currentElement; UBFeature trashElement; + UBFeature favoriteElement; + + QSet *favoriteSet; }; diff --git a/src/gui/UBFeaturesActionBar.cpp b/src/gui/UBFeaturesActionBar.cpp index ead9b859..3ccf7c66 100644 --- a/src/gui/UBFeaturesActionBar.cpp +++ b/src/gui/UBFeaturesActionBar.cpp @@ -180,6 +180,12 @@ void UBFeaturesActionBar::dropEvent( QDropEvent *event ) event->accept(); emit deleteElements( *event->mimeData() ); } + if ( dest == mpFavoriteBtn ) + { + event->setDropAction( Qt::CopyAction ); + event->accept(); + emit addToFavorite( *event->mimeData() ); + } } diff --git a/src/gui/UBFeaturesActionBar.h b/src/gui/UBFeaturesActionBar.h index c41ec13d..488f713e 100644 --- a/src/gui/UBFeaturesActionBar.h +++ b/src/gui/UBFeaturesActionBar.h @@ -27,6 +27,7 @@ signals: void searchElement(const QString &text); void newFolderToCreate(); void deleteElements( const QMimeData &data ); + void addToFavorite( const QMimeData &data ); private slots: void onSearchTextChanged(QString txt); void onActionNewFolder(); diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index 956e0130..95b2955c 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -97,7 +97,8 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale this, SLOT( currentSelected(const QModelIndex &) ) ); connect( mActionBar, SIGNAL( searchElement(const QString &) ), this, SLOT( const searchStarted(QString &) ) ); 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( pathListView, SIGNAL(clicked( const QModelIndex & ) ), this, SLOT( currentPathChanged( const QModelIndex & ) ) ); } @@ -211,6 +212,22 @@ void UBFeaturesWidget::deleteElements( const QMimeData & mimeData ) model->invalidate(); } +void UBFeaturesWidget::addToFavorite( const QMimeData & mimeData ) +{ + if ( !mimeData.hasUrls() ) + return; + QList urls = mimeData.urls(); + + foreach ( QUrl url, urls ) + { + UBFeature elem = controller->addToFavorite( url ); + if ( !elem.getUrl().isEmpty() && !elem.getUrl().isNull() ) + featuresModel->addItem( elem ); + } + QSortFilterProxyModel *model = dynamic_cast( featuresListView->model() ); + model->invalidate(); +} + void UBFeaturesWidget::switchToListView() { stackedWidget->setCurrentIndex(ID_LISTVIEW); @@ -500,6 +517,19 @@ void UBFeaturesModel::addItem( const UBFeature &item ) endInsertRows(); } +void UBFeaturesModel::deleteFavoriteItem( const QString &path ) +{ + for ( int i = 0; i < featuresList->size(); ++i ) + { + if ( !QString::compare( featuresList->at(i).getFullPath(), path, Qt::CaseInsensitive ) && + !QString::compare( featuresList->at(i).getUrl(), "root/favorite", Qt::CaseInsensitive ) ) + { + removeRow( i, QModelIndex() ); + return; + } + } +} + bool UBFeaturesModel::removeRows( int row, int count, const QModelIndex & parent ) { if ( row < 0 ) @@ -590,7 +620,7 @@ bool UBFeaturesPathProxyModel::filterAcceptsRow( int sourceRow, const QModelInde UBFeature feature = sourceModel()->data(index, Qt::UserRole + 1).value(); bool isFolder = feature.getType() == FEATURE_CATEGORY || - feature.getType() == FEATURE_FOLDER; + feature.getType() == FEATURE_FOLDER || feature.getType() == FEATURE_TRASH; QString virtualFullPath = feature.getUrl() + "/" + feature.getName(); return isFolder && path.startsWith( virtualFullPath ); diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index 8f7b4337..f1b9ae7e 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -83,6 +83,7 @@ private slots: void searchStarted( const QString & ); void createNewFolder(); void deleteElements( const QMimeData & ); + void addToFavorite( const QMimeData & ); }; class UBFeaturesListView : public QListView @@ -96,46 +97,6 @@ protected: virtual void dropEvent( QDropEvent *event ); }; -/* -class UBFeaturesPathViewer : public QGraphicsView -{ - Q_OBJECT -public: - UBFeaturesPathViewer(const QPixmap &root, const QString &rootPath, QGraphicsScene *sc, QWidget* parent=0, const char* name="UBFeaturesPathViewer"); - virtual ~UBFeaturesPathViewer() {;} - void addPathElement(const QPixmap &p, const QString &s); - void truncatePath(int number); -private: - QGraphicsLinearLayout *layout; - QGraphicsWidget *container; - QPixmap *arrowPixmap; -}; - - -class UBFolderWidget : public QLabel -{ - Q_OBJECT -public: - UBFolderWidget( QWidget * parent = 0, Qt::WindowFlags f = 0 ) : QLabel( parent, f ) {;} - virtual ~UBFolderWidget() {;} - virtual QString getPath()const { return path;} - virtual void setPath( const QString &p ) { path = p;} -signals: - void clicked(const QString &); -protected: - virtual void mouseReleaseEvent ( QMouseEvent * ev ) - { - Q_UNUSED(ev) - emit clicked(path); - } - virtual void mousePressEvent ( QMouseEvent * ev ) - { - ev->accept(); - } -private: - QString path; -}; -*/ class UBFeatureProperties : public QWidget { @@ -190,6 +151,8 @@ public: virtual ~UBFeaturesModel(){;} void addItem( const UBFeature &item ); + void deleteFavoriteItem( const QString &path ); + QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; QMimeData *mimeData( const QModelIndexList &indexes ) const; QStringList mimeTypes() const; @@ -198,6 +161,7 @@ public: bool dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent); bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); bool removeRow(int row, const QModelIndex &parent = QModelIndex()); + Qt::DropActions supportedDropActions() const { return Qt::MoveAction | Qt::CopyAction; } void setFeaturesList( QVector *flist ) { featuresList = flist; } From 0cf7b075b368af94d153466da761e9355c99765c Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Thu, 26 Apr 2012 17:17:07 +0300 Subject: [PATCH 09/12] implemented deleting from favorite folder --- src/board/UBFeaturesController.cpp | 24 +++++++++----- src/board/UBFeaturesController.h | 20 +++++++----- src/gui/UBFeaturesActionBar.cpp | 9 ++++-- src/gui/UBFeaturesActionBar.h | 1 + src/gui/UBFeaturesWidget.cpp | 51 +++++++++++++++++++++--------- src/gui/UBFeaturesWidget.h | 1 + 6 files changed, 73 insertions(+), 33 deletions(-) diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp index 9d65120b..9f7de4b9 100644 --- a/src/board/UBFeaturesController.cpp +++ b/src/board/UBFeaturesController.cpp @@ -24,17 +24,15 @@ UBFeature::UBFeature(const QString &url, const QPixmap &icon, const QString &nam } -UBFeature::UBFeature(const UBFeature &f) + + +bool UBFeature::isFolder() const { - virtualPath = f.getUrl(); - mPath = f.getFullPath(); - mThumbnail = f.getThumbnail(); - mName = f.getName(); - elementType = f.getType(); + return elementType == FEATURE_CATEGORY || elementType == FEATURE_TRASH || elementType == FEATURE_FAVORITE + || elementType == FEATURE_FOLDER; } - UBFeaturesController::UBFeaturesController(QWidget *pParentWidget) : QObject(pParentWidget), mLastItemOffsetIndex(0) @@ -83,7 +81,7 @@ void UBFeaturesController::initDirectoryTree() featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/ShapesCategory.svg"), "Shapes" , mLibShapesDirectoryPath ) ); trashElement = UBFeature( rootPath, QPixmap(":images/libpalette/TrashCategory.svg"), "Trash", trashDirectoryPath, FEATURE_TRASH ); featuresList->append( trashElement ); - favoriteElement = UBFeature( rootPath, QPixmap(":images/libpalette/FavoritesCategory.svg"), "Favorites", "favorites" ); + favoriteElement = UBFeature( rootPath, QPixmap(":images/libpalette/FavoritesCategory.svg"), "Favorites", "favorites", FEATURE_FAVORITE ); featuresList->append( favoriteElement ); loadFavoriteList(); @@ -215,6 +213,16 @@ UBFeature UBFeaturesController::addToFavorite( const QUrl &path ) return UBFeature(); } +void UBFeaturesController::removeFromFavorite( const QUrl &path ) +{ + QString filePath = fileNameFromUrl( path ); + if ( favoriteSet->find( filePath ) != favoriteSet->end() ) + { + favoriteSet->erase( favoriteSet->find( filePath ) ); + saveFavoriteList(); + } +} + QString UBFeaturesController::fileNameFromUrl( const QUrl &url ) { QString fileName = url.toString(); diff --git a/src/board/UBFeaturesController.h b/src/board/UBFeaturesController.h index 194b31bb..b3a9aadb 100644 --- a/src/board/UBFeaturesController.h +++ b/src/board/UBFeaturesController.h @@ -18,14 +18,15 @@ enum UBFeatureElementType FEATURE_INTERACTIVE, FEATURE_INTERNAL, FEATURE_ITEM, - FEATURE_TRASH + FEATURE_TRASH, + FEATURE_FAVORITE }; class UBFeature { public: UBFeature() {;} - UBFeature(const UBFeature &f); + //UBFeature(const UBFeature &f); UBFeature(const QString &url, const QPixmap &icon, const QString &name, const QString &realPath, UBFeatureElementType type = FEATURE_CATEGORY); virtual ~UBFeature() {;} QString getName() const { return mName; } @@ -34,6 +35,7 @@ public: //QString getPath() const { return mPath; }; QString getFullPath() const { return mPath; } UBFeatureElementType getType() const { return elementType; } + bool isFolder() const; private: QString virtualPath; QPixmap mThumbnail; @@ -59,14 +61,16 @@ public: const UBFeature& getCurrentElement()const { return currentElement; } void setCurrentElement( const UBFeature &elem ) { currentElement = elem; } const UBFeature & getTrashElement () const { return trashElement; } - - static QPixmap thumbnailForFile( const QString &path ); - static UBFeature moveItemToFolder( const QUrl &url, const UBFeature &destination ); - static UBFeature copyItemToFolder( const QUrl &url, const UBFeature &destination ); - static void deleteItem( const QUrl &url ); + UBFeature moveItemToFolder( const QUrl &url, const UBFeature &destination ); + UBFeature copyItemToFolder( const QUrl &url, const UBFeature &destination ); + void deleteItem( const QUrl &url ); bool isTrash( const QUrl &url ); UBFeature newFolder( const QString &name ); UBFeature addToFavorite( const QUrl &path ); + void removeFromFavorite( const QUrl &path ); + + static QString fileNameFromUrl( const QUrl &url ); + static QPixmap thumbnailForFile( const QString &path ); private: void initDirectoryTree(); void fileSystemScan(const QString &currPath, const QString & currVirtualPath); @@ -74,7 +78,7 @@ private: //void addImageToCurrentPage( const QString &path ); void loadFavoriteList(); void saveFavoriteList(); - static QString fileNameFromUrl( const QUrl &url ); + static UBFeatureElementType fileTypeFromUrl( const QString &path ); QVector *featuresList; diff --git a/src/gui/UBFeaturesActionBar.cpp b/src/gui/UBFeaturesActionBar.cpp index 3ccf7c66..508136c0 100644 --- a/src/gui/UBFeaturesActionBar.cpp +++ b/src/gui/UBFeaturesActionBar.cpp @@ -180,13 +180,18 @@ void UBFeaturesActionBar::dropEvent( QDropEvent *event ) event->accept(); emit deleteElements( *event->mimeData() ); } - if ( dest == mpFavoriteBtn ) + else if ( dest == mpFavoriteBtn ) { event->setDropAction( Qt::CopyAction ); event->accept(); emit addToFavorite( *event->mimeData() ); } - + else if ( dest == mpRemoveFavoriteBtn ) + { + event->setDropAction( Qt::MoveAction ); + event->accept(); + emit removeFromFavorite( *event->mimeData() ); + } } UBFeaturesActionBar::~UBFeaturesActionBar() diff --git a/src/gui/UBFeaturesActionBar.h b/src/gui/UBFeaturesActionBar.h index 488f713e..653fbbac 100644 --- a/src/gui/UBFeaturesActionBar.h +++ b/src/gui/UBFeaturesActionBar.h @@ -28,6 +28,7 @@ signals: void newFolderToCreate(); void deleteElements( const QMimeData &data ); void addToFavorite( const QMimeData &data ); + void removeFromFavorite( const QMimeData &data ); private slots: void onSearchTextChanged(QString txt); void onActionNewFolder(); diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index 95b2955c..9da04a0a 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -99,6 +99,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale connect( mActionBar, SIGNAL( newFolderToCreate() ), this, SLOT( createNewFolder() ) ); connect( mActionBar, SIGNAL( deleteElements(const QMimeData &) ), this, SLOT( deleteElements(const QMimeData &) ) ); connect( mActionBar, SIGNAL( addToFavorite(const QMimeData &) ), this, SLOT( addToFavorite(const QMimeData &) ) ); + connect( mActionBar, SIGNAL( removeFromFavorite(const QMimeData &) ), this, SLOT( removeFromFavorite(const QMimeData &) ) ); connect( pathListView, SIGNAL(clicked( const QModelIndex & ) ), this, SLOT( currentPathChanged( const QModelIndex & ) ) ); } @@ -127,8 +128,8 @@ void UBFeaturesWidget::currentSelected(const QModelIndex ¤t) QString path = model->data(current, Qt::UserRole).toString(); eUBLibElementType type = (eUBLibElementType)model->data(current, Qt::UserRole + 1).toInt();*/ UBFeature feature = model->data(current, Qt::UserRole + 1).value(); - if ( feature.getType() == FEATURE_FOLDER || feature.getType() == FEATURE_CATEGORY || - feature.getType() == FEATURE_TRASH ) + + if ( feature.isFolder() ) { QString newPath = feature.getUrl() + "/" + feature.getName(); //pathViewer->addPathElement( feature.getThumbnail(), newPath ); @@ -140,7 +141,14 @@ void UBFeaturesWidget::currentSelected(const QModelIndex ¤t) featuresPathModel->setPath( newPath ); featuresPathModel->invalidate(); - mActionBar->setCurrentState( IN_FOLDER ); + if ( feature.getType() == FEATURE_FAVORITE ) + { + mActionBar->setCurrentState( IN_FAVORITE ); + } + else + { + mActionBar->setCurrentState( IN_FOLDER ); + } } else { @@ -171,6 +179,10 @@ void UBFeaturesWidget::currentPathChanged(const QModelIndex &index) { mActionBar->setCurrentState( IN_ROOT ); } + else if (feature.getType() == FEATURE_FAVORITE) + { + mActionBar->setCurrentState( IN_FAVORITE ); + } else { mActionBar->setCurrentState( IN_FOLDER ); @@ -198,14 +210,16 @@ void UBFeaturesWidget::deleteElements( const QMimeData & mimeData ) foreach ( QUrl url, urls ) { - if ( controller->isTrash( url) ) + if ( controller->isTrash( url ) ) { - UBFeaturesController::deleteItem( url ); + controller->deleteItem( url ); } else { - UBFeature elem = UBFeaturesController::moveItemToFolder( url, controller->getTrashElement() ); + UBFeature elem = controller->moveItemToFolder( url, controller->getTrashElement() ); + controller->removeFromFavorite( url ); featuresModel->addItem( elem ); + featuresModel->deleteFavoriteItem( UBFeaturesController::fileNameFromUrl( url ) ); } } QSortFilterProxyModel *model = dynamic_cast( featuresListView->model() ); @@ -228,6 +242,17 @@ void UBFeaturesWidget::addToFavorite( const QMimeData & mimeData ) model->invalidate(); } +void UBFeaturesWidget::removeFromFavorite( const QMimeData & mimeData ) +{ + if ( !mimeData.hasUrls() ) + return; + QList urls = mimeData.urls(); + foreach( QUrl url, urls ) + { + controller->removeFromFavorite( url ); + } +} + void UBFeaturesWidget::switchToListView() { stackedWidget->setCurrentIndex(ID_LISTVIEW); @@ -499,11 +524,11 @@ bool UBFeaturesModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction act if ( action == Qt::MoveAction ) { - element = UBFeaturesController::moveItemToFolder( url, parentFeature ); + element = dynamic_cast(QObject::parent())->getFeaturesController()->moveItemToFolder( url, parentFeature ); } else { - element = UBFeaturesController::copyItemToFolder( url, parentFeature ); + element = dynamic_cast(QObject::parent())->getFeaturesController()->copyItemToFolder( url, parentFeature ); } addItem( element ); } @@ -522,7 +547,7 @@ void UBFeaturesModel::deleteFavoriteItem( const QString &path ) for ( int i = 0; i < featuresList->size(); ++i ) { if ( !QString::compare( featuresList->at(i).getFullPath(), path, Qt::CaseInsensitive ) && - !QString::compare( featuresList->at(i).getUrl(), "root/favorite", Qt::CaseInsensitive ) ) + !QString::compare( featuresList->at(i).getUrl(), "/root/favorites", Qt::CaseInsensitive ) ) { removeRow( i, QModelIndex() ); return; @@ -564,9 +589,7 @@ Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const item.getType() == FEATURE_ITEM || item.getType() == FEATURE_INTERNAL ) return Qt::ItemIsDragEnabled | defaultFlags; - if ( item.getType() == FEATURE_FOLDER || - item.getType() == FEATURE_TRASH || - (item.getType() == FEATURE_CATEGORY && !item.getFullPath().isNull())) + if ( item.isFolder() && !item.getFullPath().isNull() ) return defaultFlags | Qt::ItemIsDropEnabled; else return defaultFlags; } @@ -619,11 +642,9 @@ bool UBFeaturesPathProxyModel::filterAcceptsRow( int sourceRow, const QModelInde eUBLibElementType type = (eUBLibElementType)sourceModel()->data(index, Qt::UserRole + 1).toInt();*/ UBFeature feature = sourceModel()->data(index, Qt::UserRole + 1).value(); - bool isFolder = feature.getType() == FEATURE_CATEGORY || - feature.getType() == FEATURE_FOLDER || feature.getType() == FEATURE_TRASH; QString virtualFullPath = feature.getUrl() + "/" + feature.getName(); - return isFolder && path.startsWith( virtualFullPath ); + return feature.isFolder() && path.startsWith( virtualFullPath ); } QString UBFeaturesItemDelegate::displayText ( const QVariant & value, const QLocale & locale ) const diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index f1b9ae7e..322fa4dc 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -84,6 +84,7 @@ private slots: void createNewFolder(); void deleteElements( const QMimeData & ); void addToFavorite( const QMimeData & ); + void removeFromFavorite( const QMimeData & ); }; class UBFeaturesListView : public QListView From 254d1acc9dc968da7383dfad6f9afd27f5d8c562 Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Fri, 27 Apr 2012 15:04:30 +0300 Subject: [PATCH 10/12] slider for thumbnail size added --- src/board/UBFeaturesController.cpp | 9 +------- src/board/UBFeaturesController.h | 4 ++-- src/gui/UBFeaturesWidget.cpp | 35 ++++++++++++++++++++++-------- src/gui/UBFeaturesWidget.h | 11 ++++++++-- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp index 9f7de4b9..863606da 100644 --- a/src/board/UBFeaturesController.cpp +++ b/src/board/UBFeaturesController.cpp @@ -55,7 +55,7 @@ void UBFeaturesController::initDirectoryTree() mLibShapesDirectoryPath = UBSettings::settings()->applicationShapeLibraryDirectory() ; trashDirectoryPath = UBSettings::userTrashDirPath(); - featuresList = new QVector (); + featuresList = new QList (); QList tools = UBToolsManager::manager()->allTools(); @@ -322,13 +322,6 @@ UBFeature UBFeaturesController::moveItemToFolder( const QUrl &url, const UBFeatu { UBFeature newElement = copyItemToFolder( url, destination ); deleteItem( url ); - /*QString sourcePath = url.toLocalFile(); - QFile::remove( sourcePath ); - QString thumbnailPath = UBFileSystemUtils::thumbnailPath( sourcePath ); - if (thumbnailPath.length() && QFileInfo( thumbnailPath ).exists()) - { - QFile::remove(thumbnailPath); - }*/ return newElement; } diff --git a/src/board/UBFeaturesController.h b/src/board/UBFeaturesController.h index b3a9aadb..a46c6e63 100644 --- a/src/board/UBFeaturesController.h +++ b/src/board/UBFeaturesController.h @@ -53,7 +53,7 @@ public: UBFeaturesController(QWidget *parentWidget); virtual ~UBFeaturesController(); - QVector * getFeatures()const { return featuresList; } + QList * getFeatures()const { return featuresList; } const QString& getRootPath()const { return rootPath; } @@ -81,7 +81,7 @@ private: static UBFeatureElementType fileTypeFromUrl( const QString &path ); - QVector *featuresList; + QList *featuresList; UBFeature *rootElement; QString mUserAudioDirectoryPath; diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index 9da04a0a..b29b2c30 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -56,14 +56,14 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale itemDelegate = new UBFeaturesItemDelegate( this, featuresListView ); featuresListView->setItemDelegate( itemDelegate ); - featuresListView->setIconSize( QSize(40, 40) ); - featuresListView->setGridSize( QSize(70, 70) ); + featuresListView->setIconSize( QSize(defaultThumbnailSize, defaultThumbnailSize) ); + featuresListView->setGridSize( QSize(defaultThumbnailSize * 1.75, defaultThumbnailSize * 1.75) ); //pathListView->setStyleSheet( QString("background: #EEEEEE; border-radius : 10px; border : 2px solid #999999;") ); pathListView->setModel( featuresPathModel ); pathListView->setViewMode( QListView::IconMode ); - pathListView->setIconSize( QSize(30, 30) ); - pathListView->setGridSize( QSize(50, 30) ); + pathListView->setIconSize( QSize(defaultThumbnailSize - 10, defaultThumbnailSize - 10) ); + pathListView->setGridSize( QSize(defaultThumbnailSize + 10, defaultThumbnailSize - 10) ); pathListView->setFixedHeight( 60 ); pathItemDelegate = new UBFeaturesPathItemDelegate( this ); pathListView->setItemDelegate( pathItemDelegate ); @@ -89,7 +89,12 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale currentStackedWidget = ID_LISTVIEW; mActionBar = new UBFeaturesActionBar(controller, this); - layout->addWidget(mActionBar); + thumbSlider = new QSlider( Qt::Horizontal, this ); + thumbSlider->setMinimum( minThumbnailSize ); + thumbSlider->setMaximum( maxThumbnailSize ); + thumbSlider->setValue( defaultThumbnailSize ); + layout->addWidget( thumbSlider ); + layout->addWidget( mActionBar ); /*connect(featuresListView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex &, const QModelIndex & )), this, SLOT(currentSelected(const QModelIndex &)));*/ @@ -102,6 +107,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale connect( mActionBar, SIGNAL( removeFromFavorite(const QMimeData &) ), this, SLOT( removeFromFavorite(const QMimeData &) ) ); connect( pathListView, SIGNAL(clicked( const QModelIndex & ) ), this, SLOT( currentPathChanged( const QModelIndex & ) ) ); + connect( thumbSlider, SIGNAL( sliderMoved(int) ), this, SLOT(thumbnailSizeChanged( int ) ) ); } void UBFeaturesWidget::searchStarted( const QString &pattern ) @@ -253,6 +259,12 @@ void UBFeaturesWidget::removeFromFavorite( const QMimeData & mimeData ) } } +void UBFeaturesWidget::thumbnailSizeChanged( int value ) +{ + featuresListView->setIconSize( QSize( value, value ) ); + featuresListView->setGridSize( QSize( value * 1.75, value * 1.75 ) ); +} + void UBFeaturesWidget::switchToListView() { stackedWidget->setCurrentIndex(ID_LISTVIEW); @@ -407,7 +419,10 @@ void UBFeatureProperties::showElement( const UBFeature &elem ) void UBFeatureProperties::onAddToPage() { - if ( UBApplication::isFromWeb( mpElement->getUrl() ) ) + QWidget *w = parentWidget()->parentWidget(); + UBFeaturesWidget* featuresWidget = dynamic_cast( w ); + featuresWidget->getFeaturesController()->addItemToPage( *mpElement ); + /*if ( UBApplication::isFromWeb( mpElement->getUrl() ) ) { sDownloadFileDesc desc; desc.isBackground = false; @@ -422,7 +437,7 @@ void UBFeatureProperties::onAddToPage() QWidget *w = parentWidget()->parentWidget(); UBFeaturesWidget* featuresWidget = dynamic_cast( w ); featuresWidget->getFeaturesController()->addItemToPage( *mpElement ); - } + }*/ } UBFeatureProperties::~UBFeatureProperties() @@ -562,7 +577,8 @@ bool UBFeaturesModel::removeRows( int row, int count, const QModelIndex & parent if ( row + count > featuresList->size() ) return false; beginRemoveRows( parent, row, row + count - 1 ); - featuresList->remove( row, count ); + //featuresList->remove( row, count ); + featuresList->erase( featuresList->begin() + row, featuresList->begin() + row + count ); endRemoveRows(); return true; } @@ -574,7 +590,8 @@ bool UBFeaturesModel::removeRow( int row, const QModelIndex & parent ) if ( row >= featuresList->size() ) return false; beginRemoveRows( parent, row, row ); - featuresList->remove( row ); + //featuresList->remove( row ); + featuresList->erase( featuresList->begin() + row ); endRemoveRows(); return true; } diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index 322fa4dc..22a0f26d 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -51,6 +51,10 @@ public: || mode == eUBDockPaletteWidget_DESKTOP; } UBFeaturesController * getFeaturesController()const { return controller; }; + + static const int minThumbnailSize = 20; + static const int maxThumbnailSize = 100; + static const int defaultThumbnailSize = 40; private: void switchToListView(); void switchToProperties(); @@ -67,6 +71,8 @@ private: UBFeaturesListView *featuresListView; UBFeaturesListView *pathListView; + + QSlider *thumbSlider; QVBoxLayout *layout; //UBFeaturesPathViewer *pathViewer; QGraphicsScene *pathScene; @@ -85,6 +91,7 @@ private slots: void deleteElements( const QMimeData & ); void addToFavorite( const QMimeData & ); void removeFromFavorite( const QMimeData & ); + void thumbnailSizeChanged( int ); }; class UBFeaturesListView : public QListView @@ -165,9 +172,9 @@ public: Qt::DropActions supportedDropActions() const { return Qt::MoveAction | Qt::CopyAction; } - void setFeaturesList( QVector *flist ) { featuresList = flist; } + void setFeaturesList( QList *flist ) { featuresList = flist; } private: - QVector *featuresList; + QList *featuresList; }; class UBFeaturesProxyModel : public QSortFilterProxyModel From 0bed9fad8eebfb481112113061e1cdbe6aa37b29 Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Fri, 27 Apr 2012 18:39:33 +0300 Subject: [PATCH 11/12] added slider size and position updating --- src/gui/UBFeaturesWidget.cpp | 22 ++++++++++++++++++++-- src/gui/UBFeaturesWidget.h | 2 ++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index b29b2c30..384194b2 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -70,6 +70,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale pathListView->setSelectionMode( QAbstractItemView::NoSelection ); pathListView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); pathListView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); + //pathListView->setResizeMode( QListView::Adjust ); //pathListView->setMovement( QListView::Static ); pathListView->setDragDropMode( QAbstractItemView::DragDrop ); @@ -89,11 +90,16 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale currentStackedWidget = ID_LISTVIEW; mActionBar = new UBFeaturesActionBar(controller, this); - thumbSlider = new QSlider( Qt::Horizontal, this ); + thumbSlider = new QSlider( Qt::Horizontal, featuresListView ); thumbSlider->setMinimum( minThumbnailSize ); thumbSlider->setMaximum( maxThumbnailSize ); thumbSlider->setValue( defaultThumbnailSize ); - layout->addWidget( thumbSlider ); + //qDebug() << "init" << featuresListView->height(); + thumbSlider->move( 0, featuresListView->height() ); + thumbSlider->resize( thumbSlider->width(), thumbSlider->height() + 4 ); + thumbSlider->show(); + featuresListView->installEventFilter(this); + //layout->addWidget( thumbSlider ); layout->addWidget( mActionBar ); /*connect(featuresListView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex &, const QModelIndex & )), @@ -110,6 +116,18 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale connect( thumbSlider, SIGNAL( sliderMoved(int) ), this, SLOT(thumbnailSizeChanged( int ) ) ); } +bool UBFeaturesWidget::eventFilter( QObject *target, QEvent *event ) +{ + if ( target == featuresListView && event->type() == QEvent::Resize ) + { + thumbSlider->move( 10, featuresListView->height() - thumbSlider->height() - 10 ); + thumbSlider->resize( featuresListView->width() - 20, thumbSlider->height() ); + //qDebug() << featuresListView->height(); + //return true; + } + return UBDockPaletteWidget::eventFilter(target, event); +} + void UBFeaturesWidget::searchStarted( const QString &pattern ) { if ( pattern.isEmpty() ) diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index 22a0f26d..ea718f22 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -92,6 +92,8 @@ private slots: void addToFavorite( const QMimeData & ); void removeFromFavorite( const QMimeData & ); void thumbnailSizeChanged( int ); +protected: + bool eventFilter(QObject *target, QEvent *event); }; class UBFeaturesListView : public QListView From c6e8b92d36d82cce48118f4614469c1d3614ae8a Mon Sep 17 00:00:00 2001 From: Ivan Ilyin Date: Sat, 28 Apr 2012 23:45:23 +0300 Subject: [PATCH 12/12] Some warnings disabled --- src/gui/UBFeaturesActionBar.cpp | 3 ++- src/gui/UBFeaturesWidget.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/UBFeaturesActionBar.cpp b/src/gui/UBFeaturesActionBar.cpp index 508136c0..e9a560e1 100644 --- a/src/gui/UBFeaturesActionBar.cpp +++ b/src/gui/UBFeaturesActionBar.cpp @@ -150,6 +150,7 @@ void UBFeaturesActionBar::setButtons() void UBFeaturesActionBar::onSearchTextChanged(QString txt) { + Q_UNUSED(txt) emit searchElement(mSearchBar->text()); } @@ -196,4 +197,4 @@ void UBFeaturesActionBar::dropEvent( QDropEvent *event ) UBFeaturesActionBar::~UBFeaturesActionBar() { -} \ No newline at end of file +} diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index 384194b2..e3affd5c 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -546,6 +546,7 @@ bool UBFeaturesModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction act } else endRow = parent.row(); + Q_UNUSED(endRow) //why do we need this variable? UBFeature parentFeature = parent.data( Qt::UserRole + 1).value();