diff --git a/imageringlist.cpp b/imageringlist.cpp index f13f143..b8e175c 100644 --- a/imageringlist.cpp +++ b/imageringlist.cpp @@ -3,6 +3,7 @@ #include #include "loadrunable.h" #include "rawimage.h" +#include "database.h" using namespace std; @@ -97,9 +98,10 @@ void Image::thumbnailLoadFinish(void *rawImage) emit thumbnailLoaded(this); } -ImageRingList::ImageRingList(QObject *parent) : QAbstractItemModel(parent) +ImageRingList::ImageRingList(Database *database, QObject *parent) : QAbstractItemModel(parent) , m_liveMode(false) , m_analyzeLevel(None) + , m_database(database) { connect(&m_fileSystemWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(dirChanged(QString))); m_thumbPool = new QThreadPool(this); @@ -273,6 +275,15 @@ QStringList ImageRingList::imageNames() const return ret; } +void ImageRingList::updateMark() +{ + if(m_images.size()) + { + QModelIndex idx = index(m_currImage - m_images.begin(), 0); + emit dataChanged(idx, idx, {Qt::FontRole}); + } +} + QModelIndex ImageRingList::index(int row, int column, const QModelIndex &parent) const { return createIndex(row, column, m_images.at(row).get()); @@ -305,6 +316,13 @@ QVariant ImageRingList::data(const QModelIndex &index, int role) const QFileInfo info(m_images.at(index.row())->name()); return info.fileName(); } + case Qt::FontRole: + { + bool marked = m_database->isMarked(m_images.at(index.row())->name()); + QFont font; + font.setBold(marked); + return font; + } default: return QVariant(); } diff --git a/imageringlist.h b/imageringlist.h index 7e4d239..b526189 100644 --- a/imageringlist.h +++ b/imageringlist.h @@ -45,6 +45,8 @@ protected slots: typedef std::shared_ptr ImagePtr; +class Database; + class ImageRingList : public QAbstractItemModel { Q_OBJECT @@ -57,8 +59,9 @@ class ImageRingList : public QAbstractItemModel bool m_liveMode; AnalyzeLevel m_analyzeLevel; QThreadPool *m_thumbPool; + Database *m_database; public: - explicit ImageRingList(QObject *parent = 0); + explicit ImageRingList(Database *database, QObject *parent = 0); ~ImageRingList() override; bool setDir(const QString path, const QString ¤tFile = QString()); void setFile(const QString &file); @@ -75,6 +78,7 @@ public: void stopLoading(); int imageCount() const; QStringList imageNames() const; + void updateMark(); QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; QModelIndex parent(const QModelIndex &child) const override; diff --git a/mainwindow.cpp b/mainwindow.cpp index 9bb744c..c319e0f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -55,7 +55,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) connect(m_stretchPanel, &StretchToolbar::invert, m_imageGL->imageWidget(), &ImageWidget::invert); connect(m_stretchPanel, &StretchToolbar::superPixel, m_imageGL->imageWidget(), &ImageWidget::superPixel); - m_ringList = new ImageRingList(this); + m_ringList = new ImageRingList(m_database, this); m_filesystem = new FilesystemWidget(m_ringList, this); connect(m_filesystem, SIGNAL(fileSelected(int)), this, SLOT(loadFile(int))); @@ -437,7 +437,10 @@ void MainWindow::markImage() { QString file = ptr->name(); if(!file.isEmpty()) + { m_database->mark(file); + m_ringList->updateMark(); + } updateWindowTitle(); } @@ -450,7 +453,10 @@ void MainWindow::unmarkImage() { QString file = ptr->name(); if(!file.isEmpty()) + { m_database->unmark(file); + m_ringList->updateMark(); + } updateWindowTitle(); }