-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.h
More file actions
75 lines (66 loc) · 2.5 KB
/
worker.h
File metadata and controls
75 lines (66 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <QObject>
#include <QDebug>
#include <QPdfDocument>
#include <QUrl>
#include <QFileInfo>
#include <QDir>
#include <QTimer>
#include <QCoreApplication>
class Worker : public QObject {
Q_OBJECT
public:
explicit Worker(QObject* parent = nullptr): QObject(parent){
timer.setInterval(100);
connect(&timer, &QTimer::timeout, [=]() {
QCoreApplication::processEvents();
});
}
~Worker(){}
Q_INVOKABLE void doSomeWork() { // modify this to accommodate your params
//do something here
timer.setSingleShot(true);
timer.start();
}
Q_INVOKABLE void create_thumbnail(const QUrl& file_path_temp, const QUrl& thumb_image_path_temp, float thumb_max_size_temp){
file_path = file_path_temp;
thumb_image_path = thumb_image_path_temp;
thumb_max_size = thumb_max_size_temp;
timer.start();
QFileInfo file_info(thumb_image_path.toLocalFile());
if (!file_info.exists()){
qDebug() << "Creating Thumbnail: " << thumb_image_path.toLocalFile();
QFileInfo file_info(file_path.toLocalFile());
QDir thumb_dir = file_info.absoluteDir();
thumb_dir.mkpath(file_info.absolutePath());
// qDebug() << create_thumbnail_dir(thumb_image_path);
// QFile file(file_path.toLocalFile());
// if (!file.open(QFile::WriteOnly | QFile::Truncate)){
// qDebug() << "Problem Opening!";
// return false;
// }
QPdfDocument pdf_document;
//updateUI();
pdf_document.load(file_path.toLocalFile());
//updateUI();
float bigger_size = std::max(pdf_document.pagePointSize(0).width(), pdf_document.pagePointSize(0).height());
float pdf_image_divider = bigger_size / thumb_max_size;
QSize pdf_size(pdf_document.pagePointSize(0).width() / pdf_image_divider,
pdf_document.pagePointSize(0).height() / pdf_image_divider);
//updateUI();
QImage page(pdf_document.render(0, pdf_size));
//updateUI();
page = page.scaledToHeight(thumb_max_size, Qt::TransformationMode::SmoothTransformation);
//updateUI();
page.save(thumb_image_path.toLocalFile());
}
else{
qDebug() << "File already Exists!";
}
//return true;
}
private:
QTimer timer;
QUrl file_path;
QUrl thumb_image_path;
float thumb_max_size;
};