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>
cec3b5da Poul Sander 2026-02-19 19:17 7
cec3b5da Poul Sander 2026-02-19 19:17 8
class ThumbnailWorker;
032aa1e1 Poul Sander 2026-02-19 18:55 9
032aa1e1 Poul Sander 2026-02-19 18:55 10
class ImageModel : public QAbstractListModel
032aa1e1 Poul Sander 2026-02-19 18:55 11
{
032aa1e1 Poul Sander 2026-02-19 18:55 12
    Q_OBJECT
032aa1e1 Poul Sander 2026-02-19 18:55 13
032aa1e1 Poul Sander 2026-02-19 18:55 14
public:
032aa1e1 Poul Sander 2026-02-19 18:55 15
    explicit ImageModel(QObject *parent = nullptr);
cec3b5da Poul Sander 2026-02-19 19:17 16
    ~ImageModel();
032aa1e1 Poul Sander 2026-02-19 18:55 17
032aa1e1 Poul Sander 2026-02-19 18:55 18
    void setDirectory(const QString &path);
032aa1e1 Poul Sander 2026-02-19 18:55 19
    QString filePath(const QModelIndex &index) const;
032aa1e1 Poul Sander 2026-02-19 18:55 20
032aa1e1 Poul Sander 2026-02-19 18:55 21
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
032aa1e1 Poul Sander 2026-02-19 18:55 22
    QVariant data(const QModelIndex &index, int role) const override;
032aa1e1 Poul Sander 2026-02-19 18:55 23
cec3b5da Poul Sander 2026-02-19 19:17 24
    void thumbnailReady(int row, const QPixmap &pixmap);
cec3b5da Poul Sander 2026-02-19 19:17 25
032aa1e1 Poul Sander 2026-02-19 18:55 26
private:
032aa1e1 Poul Sander 2026-02-19 18:55 27
    struct Item
032aa1e1 Poul Sander 2026-02-19 18:55 28
    {
032aa1e1 Poul Sander 2026-02-19 18:55 29
        QString path;
032aa1e1 Poul Sander 2026-02-19 18:55 30
        QPixmap thumbnail;
cec3b5da Poul Sander 2026-02-19 19:17 31
        bool loaded = false;
032aa1e1 Poul Sander 2026-02-19 18:55 32
    };
032aa1e1 Poul Sander 2026-02-19 18:55 33
032aa1e1 Poul Sander 2026-02-19 18:55 34
    QVector<Item> m_items;
cec3b5da Poul Sander 2026-02-19 19:17 35
    QThreadPool m_threadPool;
cec3b5da Poul Sander 2026-02-19 19:17 36
    QPixmap m_placeholder;
032aa1e1 Poul Sander 2026-02-19 18:55 37
};
1970-01-01 00:00 38