1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Qt interface class to Thumbnail Manager |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef THUMBNAILMANAGER_QT_H |
|
19 #define THUMBNAILMANAGER_QT_H |
|
20 |
|
21 #include <QObject> |
|
22 #include <QPixmap> |
|
23 #include <QImage> |
|
24 |
|
25 #include <QtGlobal> |
|
26 |
|
27 class QString; |
|
28 class QSize; |
|
29 |
|
30 class ThumbnailManagerPrivate; |
|
31 class TestThumbnailManager; |
|
32 |
|
33 #ifdef TNMQT_DLL |
|
34 # define TNM_EXPORT Q_DECL_EXPORT |
|
35 #else |
|
36 # define TNM_EXPORT Q_DECL_IMPORT |
|
37 #endif |
|
38 |
|
39 |
|
40 /** default priority value */ |
|
41 const int tnmWrapperPriorityIdle = -100; |
|
42 |
|
43 class ThumbnailManager : public QObject |
|
44 { |
|
45 Q_OBJECT |
|
46 |
|
47 public: |
|
48 |
|
49 /** Thumbnail size. */ |
|
50 enum ThumbnailSize |
|
51 { |
|
52 /** |
|
53 * Small thumbnail |
|
54 */ |
|
55 ThumbnailSmall = 0, |
|
56 /** |
|
57 * Medium thumbnail |
|
58 */ |
|
59 ThumbnailMedium, |
|
60 /** |
|
61 * Large thumbnail |
|
62 */ |
|
63 ThumbnailLarge |
|
64 }; |
|
65 |
|
66 /** Mode of thumbnail creation. */ |
|
67 enum ThumbnailMode |
|
68 { |
|
69 /** |
|
70 * Default mode. This means that: |
|
71 * - Thumbnail must be as large as requested (unless the actual object is smaller). |
|
72 * - Smaller thumbnails may be up scaled to desired resolution. |
|
73 * - Aspect ratio is maintained and thumbnails are not cropped. The |
|
74 * resulting thumbnail may smaller in either width or height if |
|
75 * the aspect ratio of the object does not match the aspect ratio |
|
76 * of the requested size. |
|
77 */ |
|
78 Default = 0, |
|
79 |
|
80 /** |
|
81 * Allow thumbnails which are smaller than requested are. Thumbnail |
|
82 * bitmaps are never up scaled if this flag is set. |
|
83 */ |
|
84 AllowAnySize = 1, |
|
85 |
|
86 /** |
|
87 * New thumbnail images are not created if this flag is set. Only |
|
88 * existing thumbnails may be returned. If a requested thumbnail does |
|
89 * not exist null pixmap will be returned. |
|
90 */ |
|
91 DoNotCreate = 2, |
|
92 |
|
93 /** |
|
94 * Thumbnail images are cropped to match requested aspect ratio. If |
|
95 * this mode is set, the size of the resulting thumbnail always |
|
96 * matches the requested size. |
|
97 */ |
|
98 CropToAspectRatio = 4 |
|
99 }; |
|
100 |
|
101 /** Quality versus speed preference setting */ |
|
102 enum QualityPreference |
|
103 { |
|
104 /** |
|
105 * Prefer thumbnails in the highest quality possible disregarding |
|
106 * any negative impact on performance. |
|
107 */ |
|
108 OptimizeForQuality, |
|
109 |
|
110 /** |
|
111 * Get thumbnails as fast as possible, even if |
|
112 * it means lower quality. |
|
113 */ |
|
114 OptimizeForPerformance |
|
115 }; |
|
116 |
|
117 |
|
118 /** |
|
119 * Constructor |
|
120 * |
|
121 * @param parentPtr parent |
|
122 */ |
|
123 TNM_EXPORT ThumbnailManager( QObject* parentPtr = NULL ); |
|
124 |
|
125 /** |
|
126 * Destructor |
|
127 */ |
|
128 TNM_EXPORT ~ThumbnailManager(); |
|
129 |
|
130 /** |
|
131 * Get quality versus performance preference. |
|
132 * |
|
133 * @return quality versus performance preference |
|
134 */ |
|
135 TNM_EXPORT QualityPreference qualityPreference() const; |
|
136 |
|
137 /** |
|
138 * Set quality versus performance preference. |
|
139 * |
|
140 * @param qualityPreference New quality versus performance preference |
|
141 * value. |
|
142 * @return true on success |
|
143 */ |
|
144 TNM_EXPORT bool setQualityPreference( QualityPreference qualityPreference ); |
|
145 |
|
146 /** |
|
147 * Get the current desired size for thumbnail bitmaps. |
|
148 * |
|
149 * @return Current desired size for thumbnail bitmaps (in pixels). |
|
150 */ |
|
151 TNM_EXPORT QSize thumbnailSize() const; |
|
152 |
|
153 /** |
|
154 * Set desired size for thumbnail bitmaps. |
|
155 * |
|
156 * @param thumbnailSize New desired thumbnail size. |
|
157 * @return true on success |
|
158 */ |
|
159 TNM_EXPORT bool setThumbnailSize( const QSize& thumbnailSize ); |
|
160 |
|
161 /** |
|
162 * Set desired size for thumbnail bitmaps. |
|
163 * |
|
164 * @param thumbnailSize New desired thumbnail size. |
|
165 * @return true on success |
|
166 */ |
|
167 TNM_EXPORT bool setThumbnailSize( ThumbnailSize thumbnailSize ); |
|
168 |
|
169 /** |
|
170 * Get current mode for thumbnail generation. |
|
171 * |
|
172 * @return Current mode. |
|
173 */ |
|
174 TNM_EXPORT ThumbnailMode mode() const; |
|
175 |
|
176 /** |
|
177 * Set mode for thumbnail generation. |
|
178 * |
|
179 * @param mode New flags. |
|
180 * @return true on success |
|
181 */ |
|
182 TNM_EXPORT bool setMode( ThumbnailMode mode ); |
|
183 |
|
184 /** |
|
185 * Get a thumbnail for an object file. If a thumbnail already exists, it |
|
186 * is loaded and if a thumbnail does not exist, it is created |
|
187 * transparently. If thumbnail loadinf fails thumbnailReady signal is emited |
|
188 * with null pixmap and error code. |
|
189 * |
|
190 * @param fileName Source object or file |
|
191 * @param clientData Pointer to arbitrary client data. |
|
192 * This pointer is not used by the API for |
|
193 * anything other than returning it in the |
|
194 * ThumbnailReady signal. |
|
195 * @param priority Priority for this operation |
|
196 * @return Thumbnail request ID or -1 if request failed. This can be used to |
|
197 * cancel the request or change priority. |
|
198 * The ID is specific to this tnm |
|
199 * instance and may not be shared with other |
|
200 * instances. |
|
201 */ |
|
202 TNM_EXPORT int getThumbnail( const QString& fileName, void * clientData = NULL, |
|
203 int priority = tnmWrapperPriorityIdle ); |
|
204 |
|
205 /** |
|
206 * Get a persistent thumbnail for an object file. If a thumbnail already |
|
207 * exists, it is loaded and if a thumbnail does not exist, it is created |
|
208 * transparently. If thumbnail loading fails thumbnailReady signal is emited |
|
209 * with null pixmap and error code. |
|
210 * |
|
211 * @param thumbnailId Thumbnail ID |
|
212 * @param clientData Pointer to arbitrary client data. |
|
213 * This pointer is not used by the API for |
|
214 * anything other than returning it in the |
|
215 * ThumbnailReady signal. |
|
216 * @param priority Priority for this operation |
|
217 * @return Thumbnail request ID or -1 if request failed. This can be used to |
|
218 * cancel the request or change priority. |
|
219 * The ID is specific to this tnm |
|
220 * instance and may not be shared with other |
|
221 * instances. |
|
222 */ |
|
223 TNM_EXPORT int getThumbnail( unsigned long int thumbnailId, void * clientData = NULL, |
|
224 int priority = tnmWrapperPriorityIdle ); |
|
225 |
|
226 /** |
|
227 * Set a thumbnail for an object file generated from pixmap delivered. |
|
228 * thumbnailReady() signal will be emited when the operation is complete. |
|
229 * |
|
230 * @param source Pixmap from which the thumbnail will be created |
|
231 * @param fileName file name |
|
232 * @param clientData Pointer to arbitrary client data. |
|
233 * This pointer is not used by the API for |
|
234 * anything other than returning it in the |
|
235 * ThumbnailReady callback. |
|
236 * @param priority Priority for this operation |
|
237 * @return Thumbnail request ID or -1 if request failed. This can be used to |
|
238 * cancel the request or change priority. |
|
239 * |
|
240 */ |
|
241 TNM_EXPORT int setThumbnail( const QPixmap& source, const QString& fileName, |
|
242 void * clientData = NULL, int priority = tnmWrapperPriorityIdle ); |
|
243 |
|
244 /** |
|
245 * Set a thumbnail for an object file generated from pixmap delivered. |
|
246 * thumbnailReady() signal will be emited when the operation is complete. |
|
247 * |
|
248 * @param source QImage from which the thumbnail will be created |
|
249 * @param fileName file name |
|
250 * @param clientData Pointer to arbitrary client data. |
|
251 * This pointer is not used by the API for |
|
252 * anything other than returning it in the |
|
253 * ThumbnailReady callback. |
|
254 * @param priority Priority for this operation |
|
255 * @return Thumbnail request ID or -1 if request failed. This can be used to |
|
256 * cancel the request or change priority. |
|
257 * |
|
258 */ |
|
259 TNM_EXPORT int setThumbnail( const QImage& source, const QString& fileName, |
|
260 void * clientData = NULL, int priority = tnmWrapperPriorityIdle ); |
|
261 |
|
262 /** |
|
263 * Set a thumbnail for an object file generated from source file. |
|
264 * thumbnailReady() signal will be emited when the operation is complete. |
|
265 * |
|
266 * @param sourceFileName Source file name from which the thumbnail will be created |
|
267 * @param targetFileName Target file name |
|
268 * @param clientData Pointer to arbitrary client data. |
|
269 * This pointer is not used by the API for |
|
270 * anything other than returning it in the |
|
271 * ThumbnailReady callback. |
|
272 * @param priority Priority for this operation |
|
273 * @return Thumbnail request ID or -1 if request failed. This can be used to |
|
274 * cancel the request or change priority. |
|
275 * |
|
276 */ |
|
277 TNM_EXPORT int setThumbnail( const QString& sourceFileName, const QString& targetFileName, |
|
278 const QString& mimeType = QString(""), void * clientData = NULL, |
|
279 int priority = tnmWrapperPriorityIdle ); |
|
280 |
|
281 /** |
|
282 * Delete all thumbnails for a given object. This is an asynchronous |
|
283 * operation, which always returns immediately. |
|
284 * |
|
285 * @param fileName Source file |
|
286 */ |
|
287 TNM_EXPORT void deleteThumbnails( const QString& fileName ); |
|
288 |
|
289 /** |
|
290 * Delete all thumbnails for a given object. This is an asynchronous |
|
291 * operation, which always returns immediately. |
|
292 * |
|
293 * @param thumbnailId thumbnail id |
|
294 */ |
|
295 TNM_EXPORT void deleteThumbnails( unsigned long int thumbnailId ); |
|
296 |
|
297 /** |
|
298 * Cancel a thumbnail operation. |
|
299 * |
|
300 * @param id Request ID for the operation to be cancelled. |
|
301 * @return true if cancelling was successful. |
|
302 */ |
|
303 TNM_EXPORT bool cancelRequest( int id ); |
|
304 |
|
305 /** |
|
306 * Change the priority of a queued thumbnail operation. |
|
307 * |
|
308 * @param id Request ID for the request which to assign a new |
|
309 * priority. |
|
310 * @param newPriority New priority value |
|
311 * @return true if change was successful. |
|
312 */ |
|
313 TNM_EXPORT bool changePriority( int id, int newPriority ); |
|
314 |
|
315 signals: |
|
316 /** |
|
317 * Final thumbnail bitmap generation or loading is complete. |
|
318 * |
|
319 * @param pixmap An object representing the resulting thumbnail. |
|
320 * @param clientData Client data |
|
321 * @param id Request ID for the operation |
|
322 * @param errorCode error code |
|
323 */ |
|
324 TNM_EXPORT void thumbnailReady( QPixmap , void * , int , int ); |
|
325 |
|
326 /** |
|
327 * Final thumbnail bitmap generation or loading is complete. |
|
328 * |
|
329 * @param image An object representing the resulting thumbnail. |
|
330 * @param clientData Client data |
|
331 * @param id Request ID for the operation |
|
332 * @param errorCode error code |
|
333 */ |
|
334 TNM_EXPORT void thumbnailReady( QImage , void * , int , int ); |
|
335 |
|
336 protected: |
|
337 |
|
338 void connectNotify(const char *signal); |
|
339 |
|
340 void disconnectNotify(const char *signal); |
|
341 |
|
342 private: |
|
343 ThumbnailManagerPrivate* d; |
|
344 |
|
345 friend class ThumbnailManagerPrivate; |
|
346 friend class TestThumbnailManager; |
|
347 }; |
|
348 |
|
349 #endif // THUMBNAILMANAGER_QT |
|