Add filesystem widget
This commit is contained in:
+89
-20
@@ -78,7 +78,7 @@ void Image::imageLoaded(QImage img, void *rawImage, ImageInfoData info)
|
||||
}
|
||||
}
|
||||
|
||||
ImageRingList::ImageRingList(QObject *parent) : QObject(parent)
|
||||
ImageRingList::ImageRingList(QObject *parent) : QAbstractItemModel(parent)
|
||||
, m_liveMode(false)
|
||||
, m_analyzeLevel(None)
|
||||
{
|
||||
@@ -118,7 +118,10 @@ bool ImageRingList::setDir(const QString path, const QString ¤tFile)
|
||||
void ImageRingList::setFile(const QString &file)
|
||||
{
|
||||
QFileInfo info(file);
|
||||
setDir(info.absolutePath(), file);
|
||||
if(info.isDir())
|
||||
setDir(file);
|
||||
else
|
||||
setDir(info.absolutePath(), file);
|
||||
}
|
||||
|
||||
ImagePtr ImageRingList::currentImage()
|
||||
@@ -180,10 +183,90 @@ AnalyzeLevel ImageRingList::analyzeLevel() const
|
||||
return m_analyzeLevel;
|
||||
}
|
||||
|
||||
void ImageRingList::loadFile(int row)
|
||||
{
|
||||
if(row < m_images.size())
|
||||
{
|
||||
m_firstImage = m_currImage = m_lastImage = m_images.begin()+row;
|
||||
if(m_images.empty())
|
||||
return;
|
||||
|
||||
(*m_currImage)->load();
|
||||
|
||||
m_width = DEFAULT_WIDTH<m_images.size()/2 ? DEFAULT_WIDTH : m_images.size()/2;
|
||||
if(m_liveMode)
|
||||
m_width = 0;
|
||||
|
||||
for(int i=0; i<m_width; i++)
|
||||
{
|
||||
m_firstImage = decrement(m_firstImage);
|
||||
(*m_firstImage)->load();
|
||||
m_lastImage = increment(m_lastImage);
|
||||
(*m_lastImage)->load();
|
||||
}
|
||||
if(m_lastImage != m_firstImage)
|
||||
{
|
||||
QList<ImagePtr>::iterator iter = increment(m_lastImage);
|
||||
while(m_firstImage != iter)
|
||||
{
|
||||
(*iter)->release();
|
||||
iter = increment(iter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex ImageRingList::index(int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
return createIndex(row, column, m_images.at(row).get());
|
||||
}
|
||||
|
||||
QModelIndex ImageRingList::parent(const QModelIndex &child) const
|
||||
{
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
int ImageRingList::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if(parent == QModelIndex())
|
||||
return m_images.size();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ImageRingList::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
QVariant ImageRingList::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
switch(role)
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
{
|
||||
QFileInfo info(m_images.at(index.row())->name());
|
||||
return info.fileName();
|
||||
}
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant ImageRingList::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if(section==0 && orientation==Qt::Horizontal && role==Qt::DisplayRole)
|
||||
{
|
||||
return tr("Name");
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void ImageRingList::setFiles(const QStringList files, const QString ¤tFile)
|
||||
{
|
||||
QThreadPool::globalInstance()->clear();
|
||||
QThreadPool::globalInstance()->waitForDone();
|
||||
beginResetModel();
|
||||
m_images.clear();
|
||||
foreach(const QString &file, files)
|
||||
{
|
||||
@@ -196,23 +279,8 @@ void ImageRingList::setFiles(const QStringList files, const QString ¤tFile
|
||||
if(index < 0)
|
||||
index = 0;
|
||||
|
||||
m_firstImage = m_currImage = m_lastImage = m_images.begin()+index;
|
||||
if(m_images.empty())
|
||||
return;
|
||||
|
||||
(*m_currImage)->load();
|
||||
|
||||
m_width = DEFAULT_WIDTH<m_images.size()/2 ? DEFAULT_WIDTH : m_images.size()/2;
|
||||
if(m_liveMode)
|
||||
m_width = 0;
|
||||
|
||||
for(int i=0; i<m_width; i++)
|
||||
{
|
||||
m_firstImage = decrement(m_firstImage);
|
||||
(*m_firstImage)->load();
|
||||
m_lastImage = increment(m_lastImage);
|
||||
(*m_lastImage)->load();
|
||||
}
|
||||
endResetModel();
|
||||
loadFile(index);
|
||||
}
|
||||
|
||||
QList<ImagePtr>::iterator ImageRingList::increment(QList<ImagePtr>::iterator iter)
|
||||
@@ -237,6 +305,7 @@ void ImageRingList::imageLoaded(Image *image)
|
||||
{
|
||||
emit pixmapLoaded(image);
|
||||
emit infoLoaded(image->info());
|
||||
emit currentImageChanged(m_currImage-m_images.begin());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,5 +317,5 @@ void ImageRingList::dirChanged(QString dir)
|
||||
currentFile = (*m_currImage)->name();
|
||||
|
||||
setDir(dir, currentFile);
|
||||
emit currentImageChanged();
|
||||
emit currentImageChanged(m_currImage-m_images.begin());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user