git repos / SagoImageBrowser

blame: src/imageviewwidget.h

normal view · raw

61136b77 Poul Sander 2026-02-20 22:45 1
#pragma once
61136b77 Poul Sander 2026-02-20 22:45 2
61136b77 Poul Sander 2026-02-20 22:45 3
#include <QWidget>
61136b77 Poul Sander 2026-02-20 22:45 4
#include <QImage>
61136b77 Poul Sander 2026-02-20 22:45 5
#include <QPixmap>
61136b77 Poul Sander 2026-02-20 22:45 6
#include <QString>
c8ae2669 Poul Sander 2026-02-22 17:52 7
#include <QPoint>
58103277 Poul Sander 2026-03-01 22:53 8
#include <QMap>
58103277 Poul Sander 2026-03-01 22:53 9
#include <QStringList>
58103277 Poul Sander 2026-03-01 22:53 10
#include <QThread>
53fdab93 Poul Sander 2026-05-18 18:45 11
#include "exifreader.h"
58103277 Poul Sander 2026-03-01 22:53 12
58103277 Poul Sander 2026-03-01 22:53 13
class ImageLoadWorker : public QThread
58103277 Poul Sander 2026-03-01 22:53 14
{
58103277 Poul Sander 2026-03-01 22:53 15
    Q_OBJECT
58103277 Poul Sander 2026-03-01 22:53 16
public:
58103277 Poul Sander 2026-03-01 22:53 17
    explicit ImageLoadWorker(const QString &path, QObject *parent = nullptr);
58103277 Poul Sander 2026-03-01 22:53 18
    void run() override;
58103277 Poul Sander 2026-03-01 22:53 19
signals:
58103277 Poul Sander 2026-03-01 22:53 20
    void imageLoaded(const QString &path, const QPixmap &pixmap);
58103277 Poul Sander 2026-03-01 22:53 21
private:
58103277 Poul Sander 2026-03-01 22:53 22
    QString m_path;
58103277 Poul Sander 2026-03-01 22:53 23
};
61136b77 Poul Sander 2026-02-20 22:45 24
61136b77 Poul Sander 2026-02-20 22:45 25
class ImageViewWidget : public QWidget
61136b77 Poul Sander 2026-02-20 22:45 26
{
61136b77 Poul Sander 2026-02-20 22:45 27
    Q_OBJECT
61136b77 Poul Sander 2026-02-20 22:45 28
61136b77 Poul Sander 2026-02-20 22:45 29
public:
58103277 Poul Sander 2026-03-01 22:53 30
    // Number of images to read ahead and keep behind the current image
58103277 Poul Sander 2026-03-01 22:53 31
    static constexpr int CacheReadAhead = 2;
58103277 Poul Sander 2026-03-01 22:53 32
    static constexpr int CacheKeepBehind = 2;
58103277 Poul Sander 2026-03-01 22:53 33
c58dbdb7 Poul Sander 2026-02-22 17:49 34
    enum ZoomMode { FitToScreen, OriginalSize, CustomZoom };
c58dbdb7 Poul Sander 2026-02-22 17:49 35
61136b77 Poul Sander 2026-02-20 22:45 36
    explicit ImageViewWidget(QWidget *parent = nullptr);
61136b77 Poul Sander 2026-02-20 22:45 37
61136b77 Poul Sander 2026-02-20 22:45 38
    void setImage(const QString &path);
f61bf886 Poul Sander 2026-02-23 19:27 39
    void setBackgroundColor(const QString &color);
c58dbdb7 Poul Sander 2026-02-22 17:49 40
    void zoomIn();
c58dbdb7 Poul Sander 2026-02-22 17:49 41
    void zoomOut();
c58dbdb7 Poul Sander 2026-02-22 17:49 42
    void zoomOriginal();
c58dbdb7 Poul Sander 2026-02-22 17:49 43
    void zoomFitToScreen();
61136b77 Poul Sander 2026-02-20 22:45 44
58103277 Poul Sander 2026-03-01 22:53 45
    void prefetchImage(const QString &path);
58103277 Poul Sander 2026-03-01 22:53 46
    void setNeighborPaths(const QStringList &paths);
58103277 Poul Sander 2026-03-01 22:53 47
    void clearCache();
58103277 Poul Sander 2026-03-01 22:53 48
53fdab93 Poul Sander 2026-05-18 18:45 49
    void setExifData(const ExifData &data);
53fdab93 Poul Sander 2026-05-18 18:45 50
    void toggleExifOverlay();
53fdab93 Poul Sander 2026-05-18 18:45 51
61136b77 Poul Sander 2026-02-20 22:45 52
signals:
61136b77 Poul Sander 2026-02-20 22:45 53
    void closeRequested();
1ffc1962 Poul Sander 2026-02-20 23:41 54
    void nextRequested();
1ffc1962 Poul Sander 2026-02-20 23:41 55
    void previousRequested();
61136b77 Poul Sander 2026-02-20 22:45 56
61136b77 Poul Sander 2026-02-20 22:45 57
protected:
61136b77 Poul Sander 2026-02-20 22:45 58
    void paintEvent(QPaintEvent *event) override;
61136b77 Poul Sander 2026-02-20 22:45 59
    void keyPressEvent(QKeyEvent *event) override;
c8ae2669 Poul Sander 2026-02-22 17:52 60
    void mousePressEvent(QMouseEvent *event) override;
c8ae2669 Poul Sander 2026-02-22 17:52 61
    void mouseMoveEvent(QMouseEvent *event) override;
c8ae2669 Poul Sander 2026-02-22 17:52 62
    void mouseReleaseEvent(QMouseEvent *event) override;
1035a476 Poul Sander 2026-02-23 19:30 63
    void mouseDoubleClickEvent(QMouseEvent *event) override;
61136b77 Poul Sander 2026-02-20 22:45 64
61136b77 Poul Sander 2026-02-20 22:45 65
private:
c8ae2669 Poul Sander 2026-02-22 17:52 66
    void clampOffset(int imgW, int imgH);
58103277 Poul Sander 2026-03-01 22:53 67
    QPixmap loadImageFromDisk(const QString &path);
58103277 Poul Sander 2026-03-01 22:53 68
    void onImageLoaded(const QString &path, const QPixmap &pixmap);
c8ae2669 Poul Sander 2026-02-22 17:52 69
61136b77 Poul Sander 2026-02-20 22:45 70
    QPixmap m_pixmap;
c58dbdb7 Poul Sander 2026-02-22 17:49 71
    ZoomMode m_zoomMode = FitToScreen;
c58dbdb7 Poul Sander 2026-02-22 17:49 72
    double m_zoomFactor = 1.0;
f61bf886 Poul Sander 2026-02-23 19:27 73
    QString m_backgroundColor = "black";
58103277 Poul Sander 2026-03-01 22:53 74
    QString m_currentPath;
58103277 Poul Sander 2026-03-01 22:53 75
58103277 Poul Sander 2026-03-01 22:53 76
    // Image cache: path -> pixmap
58103277 Poul Sander 2026-03-01 22:53 77
    QMap<QString, QPixmap> m_cache;
58103277 Poul Sander 2026-03-01 22:53 78
    QStringList m_neighborPaths;       // ordered list of paths around current image
58103277 Poul Sander 2026-03-01 22:53 79
    QSet<QString> m_pendingLoads;      // paths currently being loaded in background
c8ae2669 Poul Sander 2026-02-22 17:52 80
c8ae2669 Poul Sander 2026-02-22 17:52 81
    // Panning state
c8ae2669 Poul Sander 2026-02-22 17:52 82
    QPoint m_offset;        // current pan offset (pixels)
c8ae2669 Poul Sander 2026-02-22 17:52 83
    bool   m_dragging = false;
c8ae2669 Poul Sander 2026-02-22 17:52 84
    QPoint m_dragStart;
c8ae2669 Poul Sander 2026-02-22 17:52 85
    QPoint m_offsetAtDragStart;
53fdab93 Poul Sander 2026-05-18 18:45 86
53fdab93 Poul Sander 2026-05-18 18:45 87
    // EXIF overlay
53fdab93 Poul Sander 2026-05-18 18:45 88
    ExifData m_exifData;
53fdab93 Poul Sander 2026-05-18 18:45 89
    bool m_showExifOverlay = false;
61136b77 Poul Sander 2026-02-20 22:45 90
};
1970-01-01 00:00 91