Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 13669 → Rev 13668

/trunk/Scribus/scribus/plugins/picbrowser/picturebrowser.cpp
8,10 → 8,6
#include <QMessageBox>
#include <iostream>
#include "picturebrowser.h"
#include "collection.h"
#include "findimage.h"
#include "previewimage.h"
#include "loadimage.h"
 
#include "prefsfile.h"
#include "prefsmanager.h"
118,7 → 114,7
imageViewArea->setUniformItemSizes ( true );
imageViewArea->setContextMenuPolicy ( Qt::CustomContextMenu );
imageViewArea->setSelectionMode ( QAbstractItemView::ExtendedSelection );
imageViewArea->setMovement ( QListView::Static);
imageViewArea->setMovement ( QListView::Snap );
imageViewArea->setResizeMode ( QListView::Adjust );
imageViewArea->setModel ( pModel );
 
2039,6 → 2035,1192
}
 
 
ImageInformation::ImageInformation()
{
}
 
 
previewImage::previewImage ( QString imageFile )
{
filtered = false;
previewIconCreated = false;
previewImageLoading = false;
 
fileInformation.setFile ( imageFile );
//enable caching
fileInformation.setCaching ( true );
}
 
 
//nothing to do yet
previewImage::~previewImage()
{
}
 
 
bool previewImage::createPreviewIcon ( const QImage &image, int size )
{
QPainter p;
//width/height of our icon (exclusive 1px border)
 
previewIcon = QPixmap ( size, size );
 
QBrush b ( QColor ( 205,205,205 ), loadIcon ( "testfill.png" ) );
 
p.begin ( &previewIcon );
 
p.setPen ( QPen ( Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin ) );
p.setBrush ( b );
p.drawRect ( 0, 0, size-1, size-1 );
 
p.drawImage ( ( ( size - image.width() ) / 2 ), ( ( size - image.height() ) / 2 ), image );
 
p.end();
 
previewIconCreated = true;
currentSize = size;
 
return true;
}
 
 
bool previewImage::insertIntoDocument ( ScribusDoc *doc, InsertAFrameData &iafData )
{
//adding imageframe
doc->itemAddUserFrame ( iafData );
 
return true;
}
 
 
bool previewImage::insertIntoImageFrame ( ScribusDoc *doc, PageItem *imageFrame )
{
//inserting image
if ( !imageFrame->loadImage ( fileInformation.absoluteFilePath(), false, -1, true ) )
{
return false;
}
 
return true;
}
 
 
previewImages::previewImages ( const QStringList& imageFiles )
{
createPreviewImagesList ( imageFiles );
}
 
 
void previewImages::createPreviewImagesList ( const QStringList& imageFiles )
{
//if there are already previewimages allocated, remove them
if ( previewImagesList.size() > 0 )
{
clearPreviewImagesList();
}
 
if ( imageFiles.isEmpty() )
{
return;
}
 
 
int s = imageFiles.size();
previewImage *tmpPreviewImage;
 
for ( int i = 0 ; i < s ; ++i )
{
tmpPreviewImage = new previewImage ( imageFiles.at ( i ) );
previewImagesList.append ( tmpPreviewImage );
}
}
 
 
void previewImages::createPreviewImagesList ( const imageCollection *collection )
{
//if there are already previewimages allocated, remove them
if ( previewImagesList.size() > 0 )
{
clearPreviewImagesList();
}
 
if ( collection->imageFiles.isEmpty() )
{
return;
}
 
 
int s = collection->imageFiles.size();
previewImage *tmpPreviewImage;
 
for ( int i = 0 ; i < s ; ++i )
{
tmpPreviewImage = new previewImage ( collection->imageFiles.at ( i ) );
tmpPreviewImage->tags = collection->tags.at ( i );
previewImagesList.append ( tmpPreviewImage );
}
}
 
 
void previewImages::clearPreviewImagesList()
{
int s = previewImagesList.size();
 
for ( int i = 0 ; i < s ; ++i )
{
delete previewImagesList.at ( i );
}
 
previewImagesList.clear();
}
 
 
bool previewImages::toRemove ( bool a, bool b )
{
if ( a )
{
if ( !b )
{
return true;
}
}
else if ( b )
{
return true;
}
 
return false;
}
 
 
void previewImages::filterFileName ( const QString &fileName, bool invert )
{
previewImage *tmpPreviewImage;
QRegExp rx ( fileName );
//wildcardmode should be sufficient
rx.setPatternSyntax ( QRegExp::Wildcard );
 
for ( int i = 0 ; i < previewImagesList.size() ; ++i )
{
tmpPreviewImage = previewImagesList.at ( i );
 
if ( toRemove ( rx.exactMatch ( tmpPreviewImage->fileInformation.fileName() ), invert ) )
{
tmpPreviewImage->filtered = true;
}
}
}
 
 
void previewImages::filterFileSize ( qint64 fileSize, bool smallerThan )
{
previewImage *tmpPreviewImage;
 
for ( int i = 0 ; i < previewImagesList.size() ; ++i )
{
tmpPreviewImage = previewImagesList.at ( i );
 
if ( toRemove ( ( tmpPreviewImage->fileInformation.size() < fileSize ), smallerThan ) )
{
tmpPreviewImage->filtered = true;
}
}
}
 
 
void previewImages::filterFileType ( const QStringList &types, bool invert )
{
previewImage *tmpPreviewImage;
 
for ( int i = 0 ; i < previewImagesList.size() ; ++i )
{
tmpPreviewImage = previewImagesList.at ( i );
QString type = QString ( "*." ) + tmpPreviewImage->fileInformation.suffix();
 
if ( toRemove ( ( types.contains ( type ) ), invert ) )
{
tmpPreviewImage->filtered = true;
}
}
}
 
 
void previewImages::filterFileModified ( const QDateTime &modified, bool smallerThan )
{
previewImage *tmpPreviewImage;
 
for ( int i = 0 ; i < previewImagesList.size() ; ++i )
{
tmpPreviewImage = previewImagesList.at ( i );
 
if ( toRemove ( ( tmpPreviewImage->fileInformation.lastModified() < modified ), smallerThan ) )
{
tmpPreviewImage->filtered = true;
}
}
}
 
 
//real image needs to be loaded for this info
void previewImages::filterResolution ( qint64 resolution, bool smallerThan )
{
previewImage *tmpPreviewImage;
 
for ( int i = 0 ; i < previewImagesList.size() ; ++i )
{
tmpPreviewImage = previewImagesList.at ( i );
 
if ( toRemove ( ( resolution < resolution ), smallerThan ) )
{
tmpPreviewImage->filtered = true;
}
}
}
 
 
void previewImages::filterTag ( const QStringList &tags, bool invert )
{
previewImage *tmpPreviewImage;
 
for ( int i = 0 ; i < previewImagesList.size() ; ++i )
{
tmpPreviewImage = previewImagesList.at ( i );
 
for ( int j = 0 ; j < tags.size() ; ++j )
{
if ( toRemove ( tmpPreviewImage->tags.contains ( tags.at ( j ) ), invert ) )
{
tmpPreviewImage->filtered = true;
break;
}
}
}
}
 
 
void previewImages::clearFilters()
{
previewImage *tmpPreviewImage;
 
for ( int i = 0 ; i < previewImagesList.size() ; ++i )
{
tmpPreviewImage = previewImagesList.at ( i );
tmpPreviewImage->filtered = false;
}
}
 
 
void previewImages::sortPreviewImages ( const int sort )
{
switch ( sort )
{
//sort by filename
case 0:
qSort ( previewImagesList.begin(), previewImagesList.end(), comparePreviewImageFileName );
break;
 
case 1:
//sort by filedate
qSort ( previewImagesList.begin(), previewImagesList.end(), comparePreviewImageFileType );
break;
 
case 2:
//sort by filetype
qSort ( previewImagesList.begin(), previewImagesList.end(), comparePreviewImageFileDate );
break;
 
case 3:
//sort by filesize
qSort ( previewImagesList.begin(), previewImagesList.end(), comparePreviewImageFileSize );
break;
 
case 4:
//sort by imageresolution
qSort ( previewImagesList.begin(), previewImagesList.end(), comparePreviewImageResolution );
break;
 
default:
break;
//if a wrong argument was specified, sort by name
qSort ( previewImagesList.begin(), previewImagesList.end(), comparePreviewImageFileName );
}
}
 
 
bool comparePreviewImageFileName ( const previewImage *i1, const previewImage *i2 )
{
return i1->fileInformation.fileName() < i2->fileInformation.fileName();
}
 
 
bool comparePreviewImageFileType ( const previewImage *i1, const previewImage *i2 )
{
return i1->fileInformation.suffix() < i2->fileInformation.suffix();
}
 
 
bool comparePreviewImageFileDate ( const previewImage *i1, const previewImage *i2 )
{
return i1->fileInformation.lastModified() < i2->fileInformation.lastModified();
}
 
 
bool comparePreviewImageFileSize ( const previewImage *i1, const previewImage *i2 )
{
return i1->fileInformation.size() < i2->fileInformation.size();
}
 
//real image needs to be loaded for this information!
bool comparePreviewImageResolution ( const previewImage *i1, const previewImage *i2 )
{
//return (resolution) < (resolution);
return true;
}
 
 
PreviewImagesModel::PreviewImagesModel ( QObject *parent ) : QAbstractListModel ( parent )
{
}
 
 
PreviewImagesModel::PreviewImagesModel ( PictureBrowser *parent ) : QAbstractListModel ( parent )
{
pictureBrowser = parent;
pId = 0;
 
createDefaultIcon ( pictureBrowser->pbSettings.previewIconSize );
}
 
 
void PreviewImagesModel::createDefaultIcon ( int size )
{
QPainter p;
 
defaultIcon = QPixmap ( size, size );
 
QBrush b ( QColor ( 205,205,205 ), loadIcon ( "testfill.png" ) );
 
p.begin ( &defaultIcon );
 
p.setPen ( QPen ( Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin ) );
p.setBrush ( b );
p.drawRect ( 0, 0, size-1, size-1 );
 
p.end();
 
defaultIconSize = size;
}
 
 
void PreviewImagesModel::setModelItemsList ( const QList<previewImage *> &previewImagesList )
{
//create new id
pId++;
 
//if there are already items stored, remove them
if ( modelItemsList.size() > 0 )
{
clearModelItemsList();
}
 
pictureBrowser->imagesDisplayed = 0;
pictureBrowser->imagesFiltered = 0;
 
beginInsertRows ( QModelIndex(), 0, previewImagesList.size() );
 
previewImage *tmpPreviewImage;
 
for ( int i = 0 ; i < previewImagesList.size() ; ++i )
{
if ( ! ( pictureBrowser->pbSettings.sortOrder ) )
{
tmpPreviewImage = previewImagesList.at ( i );
}
else
{
tmpPreviewImage = previewImagesList.at ( previewImagesList.size() - i - 1 );
}
 
if ( ! ( tmpPreviewImage->filtered ) )
{
modelItemsList.append ( tmpPreviewImage );
pictureBrowser->imagesDisplayed++;
}
else
{
pictureBrowser->imagesFiltered++;
}
}
 
endInsertRows();
}
 
 
void PreviewImagesModel::clearModelItemsList()
{
beginRemoveRows ( QModelIndex(), 0, ( modelItemsList.size() - 1 ) );
 
modelItemsList.clear();
 
endRemoveRows();
}
 
 
QVariant PreviewImagesModel::data ( const QModelIndex &index, int role ) const
{
if ( !index.isValid() )
{
return QVariant();
}
 
int row = index.row();
previewImage *tmpImage = modelItemsList.at ( row );
 
if ( role == Qt::DecorationRole )
{
pictureBrowser->currentRow = row;
 
//preload icons before and after current icon
if ( ( row - pictureBrowser->previewIconsVisible ) >= 0 )
{
previewImage *tmpImage2 = modelItemsList.at ( row - pictureBrowser->previewIconsVisible );
 
if ( ( !tmpImage2->previewIconCreated ) && ( !tmpImage2->previewImageLoading ) )
{
tmpImage2->previewImageLoading = true;
pictureBrowser->callLoadImageThread ( row - pictureBrowser->previewIconsVisible, pId );
}
}
 
if ( ( row + pictureBrowser->previewIconsVisible ) < modelItemsList.size() )
{
previewImage *tmpImage3 = modelItemsList.at ( row + pictureBrowser->previewIconsVisible );
 
if ( ( !tmpImage3->previewIconCreated ) && ( !tmpImage3->previewImageLoading ) )
{
tmpImage3->previewImageLoading = true;
pictureBrowser->callLoadImageThread ( row + pictureBrowser->previewIconsVisible, pId );
}
}
 
if ( !tmpImage->previewIconCreated )
{
if ( !tmpImage->previewImageLoading )
{
tmpImage->previewImageLoading = true;
pictureBrowser->callLoadImageThread ( row, pId );
}
 
return QIcon ( defaultIcon );
}
else
{
return QIcon ( tmpImage->previewIcon );
}
 
return QVariant();
}
else if ( role == Qt::DisplayRole )
{
if ( pictureBrowser->pbSettings.previewMode == 1 )
{
return tmpImage->fileInformation.fileName();
}
else
{
return QVariant();
}
}
 
return QVariant();
}
 
 
Qt::ItemFlags PreviewImagesModel::flags ( const QModelIndex &index ) const
{
if ( index.isValid() )
{
return ( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled );
}
 
//Qt modeltest requests 0 here
return 0;
}
 
 
int PreviewImagesModel::rowCount ( const QModelIndex &parent ) const
{
if ( parent.isValid() )
{
return 0;
}
else
{
return modelItemsList.size();
}
}
 
 
QStringList PreviewImagesModel::mimeTypes() const
{
QStringList types;
types << "text/uri-list";
return types;
}
 
 
QMimeData *PreviewImagesModel::mimeData ( const QModelIndexList &indexes ) const
{
QMimeData *mimeData = new QMimeData();
int row;
QList<QUrl> urls;
QString imageFile;
 
foreach ( QModelIndex index, indexes )
{
if ( index.isValid() )
{
row = index.row();
 
if ( ( row >= 0 ) && ( row < modelItemsList.size() ) )
{
imageFile = modelItemsList.at ( row )->fileInformation.absoluteFilePath();
urls.append ( QUrl ( imageFile ) );
}
}
}
 
mimeData->setUrls ( urls );
return mimeData;
}
 
 
void PreviewImagesModel::processLoadedImage ( int row, const QImage image, ImageInformation* imgInfo, int tpId )
{
//check if list of files has changed and this job is obsolete
if ( tpId != pId )
{
return;
}
 
//emit layoutAboutToBeChanged();
 
previewImage *loadedImage = modelItemsList.at ( row );
loadedImage->previewImageLoading = false;
loadedImage->createPreviewIcon ( image, pictureBrowser->pbSettings.previewIconSize );
 
loadedImage->imgInfo = imgInfo;
 
//emit layoutChanged();
 
QModelIndex changedIndex = index ( row );
dataChanged ( changedIndex, changedIndex );
}
 
 
void PreviewImagesModel::processImageLoadError ( int row, int tpId, int errorcode )
{
//check if list of files has changed and this job is obsolete
if ( tpId != pId )
{
return;
}
 
//emit layoutAboutToBeChanged();
 
previewImage *loadedImage = modelItemsList.at ( row );
loadedImage->previewImageLoading = false;
 
//emit layoutChanged();
}
 
 
imageCollection::imageCollection()
{
}
 
 
collections::collections ( QString collectionsName )
{
name = collectionsName;
}
 
 
collectionReaderThread::collectionReaderThread ( QString &xmlFile2, bool importCollection )
{
categoriesCount = 0;
type = 0;
restartThread = false;
 
xmlFile = xmlFile2;
import = importCollection;
}
 
 
void collectionReaderThread::readFile()
{
QFile inputFile ( xmlFile );
 
if ( !inputFile.open ( QFile::ReadOnly | QFile::Text ) )
{
return;
}
 
setDevice ( &inputFile );
 
while ( !atEnd() )
{
readNext();
 
if ( isStartElement() )
{
if ( name() == "picturebrowser" )
{
//we have a collectionsdbfile
if ( attributes().value ( "type" ) == "collectionsset" )
{
readCollectionsDb();
type = 1;
}
//we have a collectionfile
else if ( attributes().value ( "type" ) == "collection" )
{
collection = new imageCollection;
collection->file = xmlFile;
 
QString name = attributes().value ( "name" ).toString();
 
if ( !name.isEmpty() )
{
collection->name = name;
}
else
{
collection->name = xmlFile;
}
 
readCollectionFile();
type = 2;
}
}
}
}
}
 
 
void collectionReaderThread::readCollectionsDb()
{
while ( !atEnd() )
{
readNext();
 
if ( isEndElement() )
{
break;
}
 
if ( isStartElement() )
{
if ( name() == "category" )
{
QString name = attributes().value ( "name" ).toString();
collections *tmpCollections = new collections ( name );
collectionsSet.append ( tmpCollections );
 
readCategory();
 
categoriesCount++;
}
else
{
readUnknownElement();
}
}
}
}
 
 
void collectionReaderThread::readCollectionFile()
{
while ( !atEnd() && !restartThread )
{
readNext();
 
if ( isEndElement() )
{
break;
}
 
if ( isStartElement() )
{
if ( name() == "image" )
{
QString tmpImageFile = attributes().value ( "file" ).toString();
collection->imageFiles.append ( tmpImageFile );
 
readImage();
}
else
{
readUnknownElement();
}
}
}
}
 
 
void collectionReaderThread::readCategory()
{
while ( !atEnd() )
{
readNext();
 
if ( isEndElement() )
{
break;
}
 
if ( isStartElement() )
{
if ( name() == "collection" )
{
readCollection();
}
else
{
readUnknownElement();
}
}
}
}
 
 
void collectionReaderThread::readCollection()
{
collections *tmpCollections = collectionsSet.at ( categoriesCount );
 
tmpCollections->collectionFiles.append ( attributes().value ( "file" ).toString() );
tmpCollections->collectionNames.append ( readElementText() );
}
 
 
void collectionReaderThread::readImage()
{
QStringList tmpTags;
 
while ( !atEnd() && !restartThread )
{
readNext();
 
if ( isEndElement() )
{
break;
}
 
if ( isStartElement() )
{
if ( name() == "tag" )
{
//read tag here
tmpTags.append ( readElementText() );
}
else
{
readUnknownElement();
}
}
}
 
collection->tags.append ( tmpTags );
}
 
 
void collectionReaderThread::readUnknownElement()
{
while ( !atEnd() )
{
readNext();
 
if ( isEndElement() )
{
break;
}
 
if ( isStartElement() )
{
readUnknownElement();
}
}
}
 
 
void collectionReaderThread::run()
{
readFile();
}
 
 
void collectionReaderThread::restart()
{
restartThread = true;
}
 
 
collectionListReaderThread::collectionListReaderThread ( QStringList &xmlFiles2 )
{
restartThread = false;
 
xmlFiles = xmlFiles2;
}
 
 
void collectionListReaderThread::run()
{
if ( xmlFiles.isEmpty() )
{
return;
}
 
xmlFile = xmlFiles.takeAt ( 0 );
clrt = new collectionReaderThread ( xmlFile, false );
connect ( clrt, SIGNAL ( finished() ), this, SLOT ( collectionReaderThreadFinished() ) );
clrt->start();
 
exec();
}
 
 
void collectionListReaderThread::restart()
{
restartThread = true;
}
 
 
void collectionListReaderThread::collectionReaderThreadFinished()
{
readCollections.append ( clrt->collection );
delete clrt;
 
if ( xmlFiles.isEmpty() || restartThread )
{
quit();
}
else
{
xmlFile = xmlFiles.takeAt ( 0 );
clrt = new collectionReaderThread ( xmlFile, false );
connect ( clrt, SIGNAL ( finished() ), this, SLOT ( collectionReaderThreadFinished() ) );
clrt->start();
}
}
 
 
collectionsWriterThread::collectionsWriterThread ( QString &xmlFile2, QList<collections *> saveCollections2 )
{
xmlFile = xmlFile2;
saveCollections = saveCollections2;
restartThread = false;
}
 
 
void collectionsWriterThread::writeFile()
{
QFile outputFile ( xmlFile );
 
if ( !outputFile.open ( QFile::WriteOnly | QFile::Text ) )
{
return;
}
 
setDevice ( &outputFile );
 
writeStartDocument();
writeCharacters ( "\n" );
//writeDTD("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
writeStartElement ( "picturebrowser" );
 
writeAttribute ( "type", "collectionsset" );
 
writeCharacters ( "\n" );
 
for ( int i = 0 ; i < saveCollections.size() && !restartThread ; ++i )
{
writeCategory ( saveCollections.at ( i ) );
}
 
writeEndDocument();
}
 
 
void collectionsWriterThread::writeCategory ( const collections *category )
{
writeStartElement ( "category" );
writeAttribute ( "name", category->name );
writeCharacters ( "\n" );
 
for ( int i = 0 ; i < category->collectionNames.size() && !restartThread ; ++i )
{
writeCollection ( category->collectionNames.at ( i ), category->collectionFiles.at ( i ) );
}
 
writeEndElement();
writeCharacters ( "\n" );
}
 
 
void collectionsWriterThread::writeCollection ( const QString &collectionName, const QString &collectionFile )
{
writeStartElement ( "collection" );
writeAttribute ( "file", collectionFile );
 
writeCharacters ( collectionName );
 
writeEndElement();
writeCharacters ( "\n" );
}
 
 
void collectionsWriterThread::run()
{
writeFile();
}
 
 
void collectionsWriterThread::restart()
{
restartThread = true;
}
 
 
 
collectionWriterThread::collectionWriterThread ( QString &xmlFile2, imageCollection &saveCollection2 )
{
xmlFile = xmlFile2;
saveCollection = saveCollection2;
}
 
 
void collectionWriterThread::writeFile()
{
QFile outputFile ( xmlFile );
 
if ( !outputFile.open ( QFile::WriteOnly | QFile::Text ) )
{
return;
}
 
setDevice ( &outputFile );
 
writeStartDocument();
writeCharacters ( "\n" );
//writeDTD("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
writeStartElement ( "picturebrowser" );
 
writeAttribute ( "type", "collection" );
 
if ( !saveCollection.name.isEmpty() )
{
writeAttribute ( "name", saveCollection.name );
}
 
writeCharacters ( "\n" );
 
for ( int i = 0 ; i < saveCollection.imageFiles.size() ; ++i )
{
writeImage ( saveCollection.imageFiles.at ( i ), saveCollection.tags.at ( i ) );
}
 
writeEndDocument();
}
 
 
void collectionWriterThread::writeImage ( const QString &imageFile, const QStringList &tags )
{
writeStartElement ( "image" );
writeAttribute ( "file", imageFile );
writeCharacters ( "\n" );
 
writeTags ( tags );
 
writeEndElement();
writeCharacters ( "\n" );
}
 
 
void collectionWriterThread::writeTags ( const QStringList &tags )
{
for ( int i = 0 ; i < tags.size() ; ++i )
{
writeStartElement ( "tag" );
 
writeCharacters ( tags.at ( i ) );
 
writeEndElement();
writeCharacters ( "\n" );
}
}
 
 
void collectionWriterThread::run()
{
writeFile();
}
 
 
loadImagesThread::loadImagesThread ( PictureBrowser *parent, PreviewImagesModel *parentModel )
{
pictureBrowser = parent;
pModel = parentModel;
}
 
 
void loadImagesThread::run()
{
loadImagesThreadInstance help;
 
help.pictureBrowser = pictureBrowser;
help.pModel = pModel;
 
//register types for slots and signals
qRegisterMetaType<previewImage *> ( "previewImage*" );
qRegisterMetaType<ImageInformation *> ( "ImageInformation*" );
qRegisterMetaType<QImage> ( "QImage" );
 
connect ( &help, SIGNAL ( imageLoaded ( int, const QImage, ImageInformation*, int ) ), pModel, SLOT ( processLoadedImage ( int, const QImage, ImageInformation*, int ) ) );
connect ( &help, SIGNAL ( imageLoadError ( int, int, int ) ), pModel, SLOT ( processImageLoadError ( int, int, int ) ) );
connect ( pictureBrowser, SIGNAL ( loadImageJob ( int, QString, int, int ) ), &help, SLOT ( processLoadImageJob ( int, QString, int, int ) ) );
 
exec();
}
 
 
loadImagesThreadInstance::loadImagesThreadInstance()
{
}
 
void loadImagesThreadInstance::processLoadImageJob ( int row, QString path, int size, int tpId )
{
//check if list of files has changed and this job is obsolete
if ( pModel->pId != tpId )
{
return;
}
 
if ( qAbs ( row - pictureBrowser->currentRow ) > 2* ( pictureBrowser->previewIconsVisible ) )
{
emit imageLoadError ( row, tpId, 0 );
return;
}
 
ScImage image;
//no realCMYK
bool mode=false;
//no document needs to be assigned to this
CMSettings cms ( 0, "", 0 );
 
ImageInformation *imgInfo = new ImageInformation;
 
//load previewimage
if ( image.LoadPicture ( path, 1, cms, true, false, ScImage::Thumbnail, 72, &mode ) )
{
int ix,iy;
if ( ( image.imgInfo.exifDataValid ) && ( !image.imgInfo.exifInfo.thumbnail.isNull() ) )
{
ix = image.imgInfo.exifInfo.width;
iy = image.imgInfo.exifInfo.height;
}
else
{
ix = image.width();
iy = image.height();
}
( *imgInfo ).width = ix;
( *imgInfo ).height = iy;
( *imgInfo ).type = image.imgInfo.type;
( *imgInfo ).colorspace = image.imgInfo.colorspace;
( *imgInfo ).xdpi = qRound ( image.imgInfo.xres );
( *imgInfo ).ydpi = qRound ( image.imgInfo.yres );
( *imgInfo ).layers = image.imgInfo.layerInfo.size();
( *imgInfo ).embedded = image.imgInfo.isEmbedded;
( *imgInfo ).profileName = image.imgInfo.profileName;
( *imgInfo ).valid = true;
 
//image is bigger than our icon -> resize
if ( ( image.width() > ( size-2 ) ) || ( image.height() > ( size-2 ) ) )
{
emit imageLoaded ( row, image.scaled ( ( size-2 ), ( size-2 ), Qt::KeepAspectRatio, Qt::SmoothTransformation ), imgInfo, tpId );
}
//image is <= our icon -> put it in as it is
else
{
emit imageLoaded ( row, image.qImage().copy(), imgInfo, tpId );
}
}
else
{
//emit some errorsignal here
( *imgInfo ).valid = false;
emit imageLoaded ( row, QImage(), imgInfo, tpId );
}
}
 
 
findImagesThread::findImagesThread ( const QString& path2, const QStringList& nameFilters2, QDir::SortFlags sort2, bool searchSubfolders2 )
{
restartThread = false;
 
startPath = path2;
nameFilters = nameFilters2;
sort = sort2;
searchSubfolders = searchSubfolders2;
}
 
 
void findImagesThread::run()
{
findFiles ( startPath );
}
 
 
void findImagesThread::restart()
{
restartThread = true;
}
 
 
void findImagesThread::findFiles ( const QString& path )
{
QDir dir ( path );
 
if ( dir.exists() )
{
QFileInfoList list;
dir.setFilter ( QDir::AllDirs|QDir::Drives|QDir::Files|QDir::NoDotAndDotDot|QDir::NoSymLinks|QDir::Hidden );
dir.setNameFilters ( nameFilters );
dir.setSorting ( sort );
 
list = dir.entryInfoList();
 
for ( int i = 0 ; ( i < list.size() ) && ( !restartThread ) ; ++i )
{
QFileInfo fileInfo = list.at ( i );
 
if ( fileInfo.isDir() )
{
if ( searchSubfolders )
{
findFiles ( fileInfo.canonicalFilePath() );
}
}
else
{
imageFiles.append ( fileInfo.canonicalFilePath() );
}
}
}
}
 
 
imageFilters::imageFilters()
{
}