git repos / SagoImageBrowser

blame: imagemodel.h

normal view · raw

032aa1e1 Poul Sander 2026-02-19 18:55 1
#pragma once
032aa1e1 Poul Sander 2026-02-19 18:55 2
032aa1e1 Poul Sander 2026-02-19 18:55 3
#include <QAbstractListModel>
032aa1e1 Poul Sander 2026-02-19 18:55 4
#include <QPixmap>
032aa1e1 Poul Sander 2026-02-19 18:55 5
#include <QVector>
cec3b5da Poul Sander 2026-02-19 19:17 6
#include <QThreadPool>
6fcd6c90 Poul Sander 2026-02-19 21:12 7
#include <QSet>
6fcd6c90 Poul Sander 2026-02-19 21:12 8
#include <atomic>
09130ab9 Poul Sander 2026-02-22 22:19 9
#include <QIcon>
cec3b5da Poul Sander 2026-02-19 19:17 10
cec3b5da Poul Sander 2026-02-19 19:17 11
class ThumbnailWorker;
032aa1e1 Poul Sander 2026-02-19 18:55 12
032aa1e1 Poul Sander 2026-02-19 18:55 13
class ImageModel : public QAbstractListModel
032aa1e1 Poul Sander 2026-02-19 18:55 14
{
032aa1e1 Poul Sander 2026-02-19 18:55 15
    Q_OBJECT
032aa1e1 Poul Sander 2026-02-19 18:55 16
032aa1e1 Poul Sander 2026-02-19 18:55 17
public:
032aa1e1 Poul Sander 2026-02-19 18:55 18
    explicit ImageModel(QObject *parent = nullptr);
cec3b5da Poul Sander 2026-02-19 19:17 19
    ~ImageModel();
032aa1e1 Poul Sander 2026-02-19 18:55 20
032aa1e1 Poul Sander 2026-02-19 18:55 21
    void setDirectory(const QString &path);
032aa1e1 Poul Sander 2026-02-19 18:55 22
    QString filePath(const QModelIndex &index) const;
09130ab9 Poul Sander 2026-02-22 22:19 23
    bool isFolder(const QModelIndex &index) const;
09130ab9 Poul Sander 2026-02-22 22:19 24
    QString currentDirectory() const;
032aa1e1 Poul Sander 2026-02-19 18:55 25
6fcd6c90 Poul Sander 2026-02-19 21:12 26
    void requestThumbnails(int firstRow, int lastRow);
6fcd6c90 Poul Sander 2026-02-19 21:12 27
032aa1e1 Poul Sander 2026-02-19 18:55 28
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
032aa1e1 Poul Sander 2026-02-19 18:55 29
    QVariant data(const QModelIndex &index, int role) const override;
032aa1e1 Poul Sander 2026-02-19 18:55 30
6fcd6c90 Poul Sander 2026-02-19 21:12 31
    void thumbnailReady(int row, const QImage &image);
cec3b5da Poul Sander 2026-02-19 19:17 32
032aa1e1 Poul Sander 2026-02-19 18:55 33
private:
032aa1e1 Poul Sander 2026-02-19 18:55 34
    struct Item
032aa1e1 Poul Sander 2026-02-19 18:55 35
    {
032aa1e1 Poul Sander 2026-02-19 18:55 36
        QString path;
09130ab9 Poul Sander 2026-02-22 22:19 37
        QString displayName;
032aa1e1 Poul Sander 2026-02-19 18:55 38
        QPixmap thumbnail;
cec3b5da Poul Sander 2026-02-19 19:17 39
        bool loaded = false;
09130ab9 Poul Sander 2026-02-22 22:19 40
        bool isFolder = false;
032aa1e1 Poul Sander 2026-02-19 18:55 41
    };
032aa1e1 Poul Sander 2026-02-19 18:55 42
6fcd6c90 Poul Sander 2026-02-19 21:12 43
    void queueRow(int row);
6fcd6c90 Poul Sander 2026-02-19 21:12 44
032aa1e1 Poul Sander 2026-02-19 18:55 45
    QVector<Item> m_items;
cec3b5da Poul Sander 2026-02-19 19:17 46
    QThreadPool m_threadPool;
cec3b5da Poul Sander 2026-02-19 19:17 47
    QPixmap m_placeholder;
6fcd6c90 Poul Sander 2026-02-19 21:12 48
6fcd6c90 Poul Sander 2026-02-19 21:12 49
    QSet<int> m_pendingRows;
6fcd6c90 Poul Sander 2026-02-19 21:12 50
    std::atomic_bool m_cancelFlag{false};
09130ab9 Poul Sander 2026-02-22 22:19 51
    QIcon m_folderIcon;
09130ab9 Poul Sander 2026-02-22 22:19 52
    QString m_currentDir;
032aa1e1 Poul Sander 2026-02-19 18:55 53
};
1970-01-01 00:00 54