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