diff --git a/imageringlist.cpp b/imageringlist.cpp index 14a7ad6..642a9f7 100644 --- a/imageringlist.cpp +++ b/imageringlist.cpp @@ -70,6 +70,7 @@ void Image::imageLoaded(QImage img) ImageRingList::ImageRingList(QObject *parent) : QObject(parent) { + connect(&m_fileSystemWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(dirChanged(QString))); } bool ImageRingList::setDir(const QString path, const QString ¤tFile) @@ -88,39 +89,14 @@ bool ImageRingList::setDir(const QString path, const QString ¤tFile) absolutePaths.append(dir.absoluteFilePath(file)); } setFiles(absolutePaths, currentFile); + + m_fileSystemWatcher.removePaths(m_fileSystemWatcher.directories()); + m_fileSystemWatcher.addPath(path); return true; } return false; } -void ImageRingList::setFiles(const QStringList files, const QString ¤tFile) -{ - m_images.clear(); - foreach(const QString &file, files) - { - ImagePtr ptr = make_shared(file); - connect(ptr.get(), SIGNAL(pixmapLoaded(Image*)), this, SLOT(imageLoaded(Image*))); - m_images.append(ptr); - } - - int index = files.indexOf(currentFile); - if(index < 0) - index = 0; - - m_firstImage = m_currImage = m_lastImage = m_images.begin()+index; - (*m_currImage)->load(); - - m_width = DEFAULT_WIDTHload(); - m_lastImage = increment(m_lastImage); - (*m_lastImage)->load(); - } -} - void ImageRingList::setFile(const QString &file) { QFileInfo info(file); @@ -161,6 +137,34 @@ void ImageRingList::decrement() } } +void ImageRingList::setFiles(const QStringList files, const QString ¤tFile) +{ + m_images.clear(); + foreach(const QString &file, files) + { + ImagePtr ptr = make_shared(file); + connect(ptr.get(), SIGNAL(pixmapLoaded(Image*)), this, SLOT(imageLoaded(Image*))); + m_images.append(ptr); + } + + int index = files.indexOf(currentFile); + if(index < 0) + index = 0; + + m_firstImage = m_currImage = m_lastImage = m_images.begin()+index; + (*m_currImage)->load(); + + m_width = DEFAULT_WIDTHload(); + m_lastImage = increment(m_lastImage); + (*m_lastImage)->load(); + } +} + QList::iterator ImageRingList::increment(QList::iterator iter) { iter++; @@ -184,3 +188,14 @@ void ImageRingList::imageLoaded(Image *image) emit pixmapLoaded(image->pixmap()); } } + +void ImageRingList::dirChanged(QString dir) +{ + QString currentFile; + + if(m_images.size()) + currentFile = (*m_currImage)->name(); + + setDir(dir, currentFile); + emit currentImageChanged(); +} diff --git a/imageringlist.h b/imageringlist.h index 3577827..6c516e1 100644 --- a/imageringlist.h +++ b/imageringlist.h @@ -36,21 +36,24 @@ class ImageRingList : public QObject QList::iterator m_firstImage; QList::iterator m_currImage; QList::iterator m_lastImage; + QFileSystemWatcher m_fileSystemWatcher; public: explicit ImageRingList(QObject *parent = 0); bool setDir(const QString path, const QString ¤tFile = QString()); - void setFiles(const QStringList files, const QString ¤tFile = QString()); void setFile(const QString &file); ImagePtr currentImage(); void increment(); void decrement(); protected: + void setFiles(const QStringList files, const QString ¤tFile = QString()); QList::iterator increment(QList::iterator iter); QList::iterator decrement(QList::iterator iter); signals: void pixmapLoaded(QPixmap pix); + void currentImageChanged(); protected slots: void imageLoaded(Image *image); + void dirChanged(QString dir); }; #endif // IMAGERINGLIST_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 28c2f3e..7344f30 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -20,6 +20,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_ringList = new ImageRingList(this); connect(m_ringList, SIGNAL(pixmapLoaded(QPixmap)), this, SLOT(pixmapLoaded(QPixmap))); + connect(m_ringList, SIGNAL(currentImageChanged()), this, SLOT(updateWindowTitle())); QMenu *fileMenu = new QMenu(tr("File"), this); fileMenu->addAction(tr("Open"), this, SLOT(openFile()), QKeySequence("Ctrl+O")); @@ -90,7 +91,7 @@ void MainWindow::openFile() if(standardLocations.size()) path = standardLocations.first(); - QString file = QFileDialog::getOpenFileName(this, tr("Open file"), path, tr("Images (*.jpg *.png)")); + QString file = QFileDialog::getOpenFileName(this, tr("Open file"), path, tr("Images (*.jpg *.png *.JPG *.PNG)")); if(!file.isEmpty()) { QFileInfo info(file); diff --git a/mainwindow.h b/mainwindow.h index 7d2e2b4..1661c59 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -20,8 +20,8 @@ public: protected: void keyPressEvent(QKeyEvent *event); void keyReleaseEvent(QKeyEvent *event); - void updateWindowTitle(); protected slots: + void updateWindowTitle(); void pixmapLoaded(QPixmap pix); void openFile(); void markImage();