| cec3b5da |
Poul Sander |
2026-02-19 19:17 |
1 |
#include "thumbnailworker.h" |
| cec3b5da |
Poul Sander |
2026-02-19 19:17 |
2 |
#include <QImageReader> |
| cfe4a67b |
Poul Sander |
2026-02-19 23:06 |
3 |
#include <QPainter> |
| cec3b5da |
Poul Sander |
2026-02-19 19:17 |
4 |
|
| 6fcd6c90 |
Poul Sander |
2026-02-19 21:12 |
5 |
ThumbnailWorker::ThumbnailWorker(const QString &path, |
| 6fcd6c90 |
Poul Sander |
2026-02-19 21:12 |
6 |
int row, |
| 6fcd6c90 |
Poul Sander |
2026-02-19 21:12 |
7 |
std::atomic_bool *cancelFlag) |
| 6fcd6c90 |
Poul Sander |
2026-02-19 21:12 |
8 |
: m_path(path), |
| 6fcd6c90 |
Poul Sander |
2026-02-19 21:12 |
9 |
m_row(row), |
| 6fcd6c90 |
Poul Sander |
2026-02-19 21:12 |
10 |
m_cancelFlag(cancelFlag) |
| cec3b5da |
Poul Sander |
2026-02-19 19:17 |
11 |
{ |
| cec3b5da |
Poul Sander |
2026-02-19 19:17 |
12 |
setAutoDelete(true); |
| cec3b5da |
Poul Sander |
2026-02-19 19:17 |
13 |
} |
| cec3b5da |
Poul Sander |
2026-02-19 19:17 |
14 |
|
| cec3b5da |
Poul Sander |
2026-02-19 19:17 |
15 |
void ThumbnailWorker::run() |
| cec3b5da |
Poul Sander |
2026-02-19 19:17 |
16 |
{ |
| 6fcd6c90 |
Poul Sander |
2026-02-19 21:12 |
17 |
if (*m_cancelFlag) |
| 6fcd6c90 |
Poul Sander |
2026-02-19 21:12 |
18 |
return; |
| 6fcd6c90 |
Poul Sander |
2026-02-19 21:12 |
19 |
|
| cec3b5da |
Poul Sander |
2026-02-19 19:17 |
20 |
QImageReader reader(m_path); |
| cec3b5da |
Poul Sander |
2026-02-19 19:17 |
21 |
reader.setAutoTransform(true); |
| cec3b5da |
Poul Sander |
2026-02-19 19:17 |
22 |
|
| cec3b5da |
Poul Sander |
2026-02-19 19:17 |
23 |
QImage image = reader.read(); |
| 6fcd6c90 |
Poul Sander |
2026-02-19 21:12 |
24 |
|
| 6fcd6c90 |
Poul Sander |
2026-02-19 21:12 |
25 |
if (*m_cancelFlag) |
| 6fcd6c90 |
Poul Sander |
2026-02-19 21:12 |
26 |
return; |
| cec3b5da |
Poul Sander |
2026-02-19 19:17 |
27 |
|
| cec3b5da |
Poul Sander |
2026-02-19 19:17 |
28 |
if (!image.isNull()) |
| cec3b5da |
Poul Sander |
2026-02-19 19:17 |
29 |
{ |
| cfe4a67b |
Poul Sander |
2026-02-19 23:06 |
30 |
// Scale to fit within 128x128 keeping aspect ratio |
| b614a581 |
Poul Sander |
2026-02-19 21:18 |
31 |
QImage scaled = image.scaled(128, 128, |
| cfe4a67b |
Poul Sander |
2026-02-19 23:06 |
32 |
Qt::KeepAspectRatio, |
| b614a581 |
Poul Sander |
2026-02-19 21:18 |
33 |
Qt::SmoothTransformation); |
| cfe4a67b |
Poul Sander |
2026-02-19 23:06 |
34 |
// Center on a 128x128 canvas with transparent/white fill |
| cfe4a67b |
Poul Sander |
2026-02-19 23:06 |
35 |
QImage thumb(128, 128, QImage::Format_ARGB32_Premultiplied); |
| cfe4a67b |
Poul Sander |
2026-02-19 23:06 |
36 |
thumb.fill(Qt::transparent); |
| cfe4a67b |
Poul Sander |
2026-02-19 23:06 |
37 |
int x = (128 - scaled.width()) / 2; |
| cfe4a67b |
Poul Sander |
2026-02-19 23:06 |
38 |
int y = (128 - scaled.height()) / 2; |
| cfe4a67b |
Poul Sander |
2026-02-19 23:06 |
39 |
QPainter painter(&thumb); |
| cfe4a67b |
Poul Sander |
2026-02-19 23:06 |
40 |
painter.drawImage(x, y, scaled); |
| cfe4a67b |
Poul Sander |
2026-02-19 23:06 |
41 |
painter.end(); |
| 6fcd6c90 |
Poul Sander |
2026-02-19 21:12 |
42 |
emit finished(m_row, thumb); |
| cec3b5da |
Poul Sander |
2026-02-19 19:17 |
43 |
} |
| cec3b5da |
Poul Sander |
2026-02-19 19:17 |
44 |
} |
|
|
1970-01-01 00:00 |
45 |
|