1 | /* -*- C++ -*- |
2 | This file is part of ThreadWeaver. |
3 | |
4 | SPDX-FileCopyrightText: 2005-2014 Mirko Boehm <mirko@kde.org> |
5 | |
6 | SPDX-License-Identifier: LGPL-2.0-or-later |
7 | */ |
8 | |
9 | #ifndef IMAGE_H |
10 | #define IMAGE_H |
11 | |
12 | #include <QAtomicInt> |
13 | #include <QCoreApplication> |
14 | #include <QImage> |
15 | #include <QReadWriteLock> |
16 | |
17 | #include "Progress.h" |
18 | |
19 | class Model; |
20 | |
21 | /*! |
22 | * \class Image |
23 | * |
24 | * \inmodule ThreadWeaver |
25 | * |
26 | * \brief Image loads an image from a path, and then calculates and saves a thumbnail for it. |
27 | */ |
28 | class Image |
29 | { |
30 | Q_DECLARE_TR_FUNCTIONS(Image) |
31 | |
32 | public: |
33 | /*! |
34 | * \enum Steps |
35 | * |
36 | * \value Step_NotStarted |
37 | * \value Step_LoadFile |
38 | * \value Step_LoadImage |
39 | * \value Step_ComputeThumbNail |
40 | * \value Step_SaveThumbNail |
41 | * \value Step_NumberOfSteps |
42 | * \value Step_Complete |
43 | */ |
44 | enum Steps { |
45 | Step_NotStarted, |
46 | Step_LoadFile, |
47 | Step_LoadImage, |
48 | Step_ComputeThumbNail, |
49 | Step_SaveThumbNail, |
50 | Step_NumberOfSteps = Step_SaveThumbNail, |
51 | Step_Complete = Step_SaveThumbNail, |
52 | }; |
53 | |
54 | /*! |
55 | */ |
56 | Image(const QString inputFileName = QString(), const QString outputFileName = QString(), Model *model = nullptr, int id = 0); |
57 | /*! |
58 | */ |
59 | Progress progress() const; |
60 | /*! |
61 | */ |
62 | QString description() const; |
63 | /*! |
64 | */ |
65 | QString details() const; |
66 | /*! |
67 | */ |
68 | QString details2() const; |
69 | /*! |
70 | */ |
71 | int processingOrder() const; |
72 | |
73 | /*! |
74 | */ |
75 | const QString inputFileName() const; |
76 | /*! |
77 | */ |
78 | const QString outputFileName() const; |
79 | /*! |
80 | */ |
81 | QImage thumbNail() const; |
82 | |
83 | /*! |
84 | */ |
85 | void loadFile(); |
86 | /*! |
87 | */ |
88 | void loadImage(); |
89 | /*! |
90 | */ |
91 | void computeThumbNail(); |
92 | /*! |
93 | */ |
94 | void saveThumbNail(); |
95 | |
96 | static const int ThumbHeight; |
97 | static const int ThumbWidth; |
98 | |
99 | private: |
100 | /*! |
101 | */ |
102 | void announceProgress(Steps step); |
103 | /*! |
104 | */ |
105 | void error(Steps step, const QString &message); |
106 | |
107 | QString m_inputFileName; |
108 | QString m_outputFileName; |
109 | QString m_description; |
110 | QString m_details; |
111 | QString m_details2; |
112 | QAtomicInt m_progress; |
113 | QAtomicInt m_failedStep; |
114 | QAtomicInt m_processingOrder; |
115 | |
116 | QByteArray m_imageData; |
117 | QImage m_image; |
118 | QImage m_thumbnail; |
119 | Model *m_model; |
120 | int m_id; |
121 | |
122 | static QReadWriteLock Lock; |
123 | static int ProcessingOrder; |
124 | }; |
125 | |
126 | Q_DECLARE_METATYPE(Image) |
127 | Q_DECLARE_METATYPE(const Image *) |
128 | |
129 | #endif // IMAGE_H |
130 | |