added importing images from board to library

preferencesAboutTextFull
Anna Udovichenko 13 years ago
parent 17dd85640b
commit b5fd37a9dd
  1. 21
      src/board/UBFeaturesController.cpp
  2. 1
      src/board/UBFeaturesController.h
  3. 55
      src/gui/UBFeaturesWidget.cpp
  4. 1
      src/gui/UBFeaturesWidget.h

@ -345,6 +345,27 @@ QPixmap UBFeaturesController::createThumbnail(const QString &path)
return QPixmap(thumbnailPath); return QPixmap(thumbnailPath);
} }
UBFeature UBFeaturesController::importImage( const QImage &image, const UBFeature &destination )
{
QDateTime now = QDateTime::currentDateTime();
QString fileName = tr("ImportedImage") + "-" + now.toString("dd-MM-yyyy hh-mm-ss") + ".png";
UBFeature dest = destination;
if ( !destination.getFullVirtualPath().startsWith( picturesElement.getFullVirtualPath(), Qt::CaseInsensitive ) )
{
dest = picturesElement;
}
QString filePath = dest.getFullPath().toLocalFile() + "/" + fileName;
image.save(filePath);
QPixmap thumb = createThumbnail( filePath );
return UBFeature( dest.getFullVirtualPath(), thumb, fileName,
QUrl::fromLocalFile( filePath ), FEATURE_ITEM );
}
UBFeature UBFeaturesController::newFolder( const QString &name ) UBFeature UBFeaturesController::newFolder( const QString &name )
{ {
QString path = currentElement.getFullPath().toLocalFile() + "/" + name; QString path = currentElement.getFullPath().toLocalFile() + "/" + name;

@ -86,6 +86,7 @@ public:
UBFeature newFolder( const QString &name ); UBFeature newFolder( const QString &name );
UBFeature addToFavorite( const QUrl &path ); UBFeature addToFavorite( const QUrl &path );
void removeFromFavorite( const QUrl &path ); void removeFromFavorite( const QUrl &path );
UBFeature importImage( const QImage &image, const UBFeature &destination );
static QString fileNameFromUrl( const QUrl &url ); static QString fileNameFromUrl( const QUrl &url );
static QPixmap thumbnailForFile( const QString &path ); static QPixmap thumbnailForFile( const QString &path );

@ -404,13 +404,19 @@ void UBFeaturesListView::mouseReleaseEvent( QMouseEvent *event )
*/ */
void UBFeaturesListView::dragEnterEvent( QDragEnterEvent *event ) void UBFeaturesListView::dragEnterEvent( QDragEnterEvent *event )
{ {
if ( event->mimeData()->hasUrls() ) if ( event->mimeData()->hasUrls() || event->mimeData()->hasImage() )
event->acceptProposedAction(); event->acceptProposedAction();
} }
void UBFeaturesListView::dragMoveEvent( QDragMoveEvent *event )
{
if ( event->mimeData()->hasUrls() || event->mimeData()->hasImage() )
event->acceptProposedAction();
}
void UBFeaturesListView::dropEvent( QDropEvent *event ) void UBFeaturesListView::dropEvent( QDropEvent *event )
{ {
if( event->source() || dynamic_cast<UBFeaturesListView *>( event->source() ) ) if( event->source() && dynamic_cast<UBFeaturesListView *>( event->source() ) )
{ {
event->setDropAction( Qt::MoveAction ); event->setDropAction( Qt::MoveAction );
} }
@ -775,7 +781,7 @@ bool UBFeaturesModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction act
{ {
Q_UNUSED(row) Q_UNUSED(row)
if ( !mimeData->hasUrls() ) if ( !mimeData->hasUrls() && !mimeData->hasImage() )
return false; return false;
if ( action == Qt::IgnoreAction ) if ( action == Qt::IgnoreAction )
return true; return true;
@ -794,22 +800,31 @@ bool UBFeaturesModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction act
parentFeature = parent.data( Qt::UserRole + 1).value<UBFeature>(); parentFeature = parent.data( Qt::UserRole + 1).value<UBFeature>();
} }
QList<QUrl> urls = mimeData->urls(); if ( mimeData->hasUrls() )
{
foreach ( QUrl url, urls ) QList<QUrl> urls = mimeData->urls();
{
UBFeature element; foreach ( QUrl url, urls )
{
if ( action == Qt::MoveAction ) UBFeature element;
{
element = dynamic_cast<UBFeaturesWidget *>(QObject::parent())->getFeaturesController()->moveItemToFolder( url, parentFeature ); if ( action == Qt::MoveAction )
} {
else element = dynamic_cast<UBFeaturesWidget *>(QObject::parent())->getFeaturesController()->moveItemToFolder( url, parentFeature );
{ }
element = dynamic_cast<UBFeaturesWidget *>(QObject::parent())->getFeaturesController()->copyItemToFolder( url, parentFeature ); else
} {
addItem( element ); element = dynamic_cast<UBFeaturesWidget *>(QObject::parent())->getFeaturesController()->copyItemToFolder( url, parentFeature );
} }
addItem( element );
}
}
else if ( mimeData->hasImage() )
{
QImage image = qvariant_cast<QImage>( mimeData->imageData() );
UBFeature element = dynamic_cast<UBFeaturesWidget *>(QObject::parent())->getFeaturesController()->importImage( image, parentFeature );
addItem( element );
}
return true; return true;
} }
@ -897,7 +912,7 @@ Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const
QStringList UBFeaturesModel::mimeTypes() const QStringList UBFeaturesModel::mimeTypes() const
{ {
QStringList types; QStringList types;
types << "text/uri-list"; types << "text/uri-list" << "image/png" << "image/tiff" << "image/gif" << "image/jpeg";
return types; return types;
} }

@ -114,6 +114,7 @@ public:
protected: protected:
virtual void dragEnterEvent( QDragEnterEvent *event ); virtual void dragEnterEvent( QDragEnterEvent *event );
virtual void dropEvent( QDropEvent *event ); virtual void dropEvent( QDropEvent *event );
virtual void dragMoveEvent( QDragMoveEvent *event );
/*virtual void mousePressEvent( QMouseEvent *event ); /*virtual void mousePressEvent( QMouseEvent *event );
virtual void mouseMoveEvent( QMouseEvent *event ); virtual void mouseMoveEvent( QMouseEvent *event );
virtual void mouseReleaseEvent( QMouseEvent *event );*/ virtual void mouseReleaseEvent( QMouseEvent *event );*/

Loading…
Cancel
Save