34
|
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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#ifndef STUB_THUMBNAILMANAGER_QT_H
|
|
19 |
#define STUB_THUMBNAILMANAGER_QT_H
|
|
20 |
|
|
21 |
#include <QObject>
|
|
22 |
#include <QPixmap.h>
|
|
23 |
#include <QMap>
|
|
24 |
|
|
25 |
class QString;
|
|
26 |
class QSize;
|
|
27 |
|
|
28 |
/** default priority value */
|
|
29 |
const int tnmWrapperPriorityIdle = -100;
|
|
30 |
|
|
31 |
class ThumbnailManager : public QObject
|
|
32 |
{
|
|
33 |
Q_OBJECT
|
|
34 |
|
|
35 |
public:
|
|
36 |
/** Thumbnail size. */
|
|
37 |
enum ThumbnailSize
|
|
38 |
{
|
|
39 |
/**
|
|
40 |
* Small thumbnail
|
|
41 |
*/
|
|
42 |
ThumbnailSmall = 0,
|
|
43 |
/**
|
|
44 |
* Medium thumbnail
|
|
45 |
*/
|
|
46 |
ThumbnailMedium,
|
|
47 |
/**
|
|
48 |
* Large thumbnail
|
|
49 |
*/
|
|
50 |
ThumbnailLarge
|
|
51 |
};
|
|
52 |
|
|
53 |
/** Mode of thumbnail creation. */
|
|
54 |
enum ThumbnailMode
|
|
55 |
{
|
|
56 |
/**
|
|
57 |
* Default mode. This means that:
|
|
58 |
* - Thumbnail must be as large as requested (unless the actual object is smaller).
|
|
59 |
* - Smaller thumbnails may be up scaled to desired resolution.
|
|
60 |
* - Aspect ratio is maintained and thumbnails are not cropped. The
|
|
61 |
* resulting thumbnail may smaller in either width or height if
|
|
62 |
* the aspect ratio of the object does not match the aspect ratio
|
|
63 |
* of the requested size.
|
|
64 |
*/
|
|
65 |
Default = 0,
|
|
66 |
|
|
67 |
/**
|
|
68 |
* Allow thumbnails which are smaller than requested are. Thumbnail
|
|
69 |
* bitmaps are never up scaled if this flag is set.
|
|
70 |
*/
|
|
71 |
AllowAnySize = 1,
|
|
72 |
|
|
73 |
/**
|
|
74 |
* New thumbnail images are not created if this flag is set. Only
|
|
75 |
* existing thumbnails may be returned. If a requested thumbnail does
|
|
76 |
* not exist null pixmap will be returned.
|
|
77 |
*/
|
|
78 |
DoNotCreate = 2,
|
|
79 |
|
|
80 |
/**
|
|
81 |
* Thumbnail images are cropped to match requested aspect ratio. If
|
|
82 |
* this mode is set, the size of the resulting thumbnail always
|
|
83 |
* matches the requested size.
|
|
84 |
*/
|
|
85 |
CropToAspectRatio = 4
|
|
86 |
};
|
|
87 |
|
|
88 |
/** Quality versus speed preference setting */
|
|
89 |
enum QualityPreference
|
|
90 |
{
|
|
91 |
/**
|
|
92 |
* Prefer thumbnails in the highest quality possible disregarding
|
|
93 |
* any negative impact on performance.
|
|
94 |
*/
|
|
95 |
OptimizeForQuality,
|
|
96 |
|
|
97 |
/**
|
|
98 |
* Get thumbnails as fast as possible, even if
|
|
99 |
* it means lower quality.
|
|
100 |
*/
|
|
101 |
OptimizeForPerformance
|
|
102 |
};
|
|
103 |
|
|
104 |
/** Display modes. */
|
|
105 |
enum DisplayMode
|
|
106 |
{
|
|
107 |
/** No display mode */
|
|
108 |
None,
|
|
109 |
|
|
110 |
/** Monochrome display mode (1 bpp) */
|
|
111 |
Gray2,
|
|
112 |
|
|
113 |
/** Four grayscales display mode (2 bpp) */
|
|
114 |
Gray4,
|
|
115 |
|
|
116 |
/** 16 grayscales display mode (4 bpp) */
|
|
117 |
Gray16,
|
|
118 |
|
|
119 |
/** 256 grayscales display mode (8 bpp) */
|
|
120 |
Gray256,
|
|
121 |
|
|
122 |
/** Low colour GA 16 colour display mode (4 bpp) */
|
|
123 |
Color16,
|
|
124 |
|
|
125 |
/** 256 colour display mode (8 bpp) */
|
|
126 |
Color256,
|
|
127 |
|
|
128 |
/** 64,000 colour display mode (16 bpp) */
|
|
129 |
Color64K,
|
|
130 |
|
|
131 |
/** True colour display mode (24 bpp) */
|
|
132 |
Color16M,
|
|
133 |
|
|
134 |
/** (Not an actual display mode used for moving buffers containing bitmaps) */
|
|
135 |
Rgb,
|
|
136 |
|
|
137 |
/** 4096 colour display (12 bpp). */
|
|
138 |
Color4K,
|
|
139 |
|
|
140 |
/** True colour display mode (32 bpp, but top byte is unused and unspecified) */
|
|
141 |
Color16MU,
|
|
142 |
|
|
143 |
/** Display mode with alpha (24bpp colour plus 8bpp alpha) */
|
|
144 |
Color16MA,
|
|
145 |
|
|
146 |
/** Pre-multiplied Alpha display mode
|
|
147 |
* (24bpp color multiplied with the alpha channel value, plus 8bpp alpha) */
|
|
148 |
Color16MAP
|
|
149 |
};
|
|
150 |
|
|
151 |
public:
|
|
152 |
|
|
153 |
|
|
154 |
/**
|
|
155 |
* Constructor
|
|
156 |
*
|
|
157 |
* @param parentPtr parent
|
|
158 |
*/
|
|
159 |
ThumbnailManager( QObject* parentPtr = NULL );
|
|
160 |
|
|
161 |
/**
|
|
162 |
* Destructor
|
|
163 |
*/
|
|
164 |
virtual ~ThumbnailManager();
|
|
165 |
|
|
166 |
/**
|
|
167 |
* Get quality versus performance preference.
|
|
168 |
*
|
|
169 |
* @return quality versus performance preference
|
|
170 |
*/
|
|
171 |
QualityPreference qualityPreference() const;
|
|
172 |
|
|
173 |
/**
|
|
174 |
* Set quality versus performance preference.
|
|
175 |
*
|
|
176 |
* @param qualityPreference New quality versus performance preference
|
|
177 |
* value.
|
|
178 |
* @return true on success
|
|
179 |
*/
|
|
180 |
bool setQualityPreference( QualityPreference qualityPreference );
|
|
181 |
|
|
182 |
/**
|
|
183 |
* Get the current display mode for thumbnail bitmaps.
|
|
184 |
*
|
|
185 |
* @return current display mode for thumbnail bitmaps
|
|
186 |
*/
|
|
187 |
DisplayMode displayMode() const;
|
|
188 |
|
|
189 |
/**
|
|
190 |
* Set new display mode for thumbnail bitmaps.
|
|
191 |
*
|
|
192 |
* @param displayMode new display mode for thumbnail bitmaps.
|
|
193 |
* @return true on success
|
|
194 |
*/
|
|
195 |
bool setDisplayMode( DisplayMode displayMode );
|
|
196 |
|
|
197 |
/**
|
|
198 |
* Get the current desired size for thumbnail bitmaps.
|
|
199 |
*
|
|
200 |
* @return Current desired size for thumbnail bitmaps (in pixels).
|
|
201 |
*/
|
|
202 |
QSize thumbnailSize() const;
|
|
203 |
|
|
204 |
/**
|
|
205 |
* Set desired size for thumbnail bitmaps.
|
|
206 |
*
|
|
207 |
* @param thumbnailSize New desired thumbnail size.
|
|
208 |
* @return true on success
|
|
209 |
*/
|
|
210 |
bool setThumbnailSize( const QSize& thumbnailSize );
|
|
211 |
|
|
212 |
/**
|
|
213 |
* Set desired size for thumbnail bitmaps.
|
|
214 |
*
|
|
215 |
* @param thumbnailSize New desired thumbnail size.
|
|
216 |
* @return true on success
|
|
217 |
*/
|
|
218 |
bool setThumbnailSize( ThumbnailSize thumbnailSize );
|
|
219 |
|
|
220 |
/**
|
|
221 |
* Get current mode for thumbnail generation.
|
|
222 |
*
|
|
223 |
* @return Current mode.
|
|
224 |
*/
|
|
225 |
ThumbnailMode mode() const;
|
|
226 |
|
|
227 |
/**
|
|
228 |
* Set mode for thumbnail generation.
|
|
229 |
*
|
|
230 |
* @param mode New flags.
|
|
231 |
* @return true on success
|
|
232 |
*/
|
|
233 |
bool setMode( ThumbnailMode mode );
|
|
234 |
|
|
235 |
/**
|
|
236 |
* Get a thumbnail for an object file. If a thumbnail already exists, it
|
|
237 |
* is loaded and if a thumbnail does not exist, it is created
|
|
238 |
* transparently. If thumbnail loadinf fails thumbnailReady signal is emited
|
|
239 |
* with null pixmap and error code.
|
|
240 |
*
|
|
241 |
* @param fileName Source object or file
|
|
242 |
* @param clientData Pointer to arbitrary client data.
|
|
243 |
* This pointer is not used by the API for
|
|
244 |
* anything other than returning it in the
|
|
245 |
* ThumbnailReady signal.
|
|
246 |
* @param priority Priority for this operation
|
|
247 |
* @return Thumbnail request ID or -1 if request failed. This can be used to
|
|
248 |
* cancel the request or change priority.
|
|
249 |
* The ID is specific to this tnm
|
|
250 |
* instance and may not be shared with other
|
|
251 |
* instances.
|
|
252 |
*/
|
|
253 |
int getThumbnail( const QString& fileName, void * clientData = NULL,
|
|
254 |
int priority = tnmWrapperPriorityIdle );
|
|
255 |
|
|
256 |
/**
|
|
257 |
* Get a persistent thumbnail for an object file. If a thumbnail already
|
|
258 |
* exists, it is loaded and if a thumbnail does not exist, it is created
|
|
259 |
* transparently. If thumbnail loading fails thumbnailReady signal is emited
|
|
260 |
* with null pixmap and error code.
|
|
261 |
*
|
|
262 |
* @param thumbnailId Thumbnail ID
|
|
263 |
* @param clientData Pointer to arbitrary client data.
|
|
264 |
* This pointer is not used by the API for
|
|
265 |
* anything other than returning it in the
|
|
266 |
* ThumbnailReady signal.
|
|
267 |
* @param priority Priority for this operation
|
|
268 |
* @return Thumbnail request ID or -1 if request failed. This can be used to
|
|
269 |
* cancel the request or change priority.
|
|
270 |
* The ID is specific to this tnm
|
|
271 |
* instance and may not be shared with other
|
|
272 |
* instances.
|
|
273 |
*/
|
|
274 |
int getThumbnail( unsigned long int thumbnailId, void * clientData = NULL,
|
|
275 |
int priority = tnmWrapperPriorityIdle );
|
|
276 |
|
|
277 |
/**
|
|
278 |
* Set a thumbnail for an object file generated from pixmap delivered.
|
|
279 |
* thumbnailReady() signal will be emited when the operation is complete.
|
|
280 |
*
|
|
281 |
* @param source Pixmap from which the thumbnail will be created
|
|
282 |
* @param fileName file name
|
|
283 |
* @param clientData Pointer to arbitrary client data.
|
|
284 |
* This pointer is not used by the API for
|
|
285 |
* anything other than returning it in the
|
|
286 |
* ThumbnailReady callback.
|
|
287 |
* @param priority Priority for this operation
|
|
288 |
* @return Thumbnail request ID or -1 if request failed. This can be used to
|
|
289 |
* cancel the request or change priority.
|
|
290 |
*
|
|
291 |
*/
|
|
292 |
int setThumbnail( const QPixmap& source, const QString& fileName,
|
|
293 |
void * clientData = NULL, int priority = tnmWrapperPriorityIdle );
|
|
294 |
|
|
295 |
/**
|
|
296 |
* Delete all thumbnails for a given object. This is an asynchronous
|
|
297 |
* operation, which always returns immediately.
|
|
298 |
*
|
|
299 |
* @param fileName Source file
|
|
300 |
*/
|
|
301 |
void deleteThumbnails( const QString& fileName );
|
|
302 |
|
|
303 |
/**
|
|
304 |
* Delete all thumbnails for a given object. This is an asynchronous
|
|
305 |
* operation, which always returns immediately.
|
|
306 |
*
|
|
307 |
* @param thumbnailId thumbnail id
|
|
308 |
*/
|
|
309 |
void deleteThumbnails( unsigned long int thumbnailId );
|
|
310 |
|
|
311 |
/**
|
|
312 |
* Cancel a thumbnail operation.
|
|
313 |
*
|
|
314 |
* @param id Request ID for the operation to be cancelled.
|
|
315 |
* @return true if cancelling was successful.
|
|
316 |
*/
|
|
317 |
bool cancelRequest( int id );
|
|
318 |
|
|
319 |
/**
|
|
320 |
* Change the priority of a queued thumbnail operation.
|
|
321 |
*
|
|
322 |
* @param id Request ID for the request which to assign a new
|
|
323 |
* priority.
|
|
324 |
* @param newPriority New priority value
|
|
325 |
* @return true if change was successful.
|
|
326 |
*/
|
|
327 |
bool changePriority( int id, int newPriority );
|
|
328 |
|
|
329 |
signals:
|
|
330 |
/**
|
|
331 |
* Final thumbnail bitmap generation or loading is complete.
|
|
332 |
*
|
|
333 |
* @param pixmap An object representing the resulting thumbnail.
|
|
334 |
* @param clientData Client data
|
|
335 |
* @param id Request ID for the operation
|
|
336 |
* @param errorCode error code
|
|
337 |
*/
|
|
338 |
void thumbnailReady( QPixmap , void * , int , int );
|
|
339 |
|
|
340 |
public: // Test methods.
|
|
341 |
|
|
342 |
void emitThumbnailReady(int tnId, bool emitNullThumb = false);
|
|
343 |
|
|
344 |
/**
|
|
345 |
* Emits thumbnailReady signal.
|
|
346 |
*
|
|
347 |
* @param pixmap An object representing the resulting thumbnail.
|
|
348 |
* @param clientData Client data
|
|
349 |
* @param id Request ID for the operation
|
|
350 |
* @param errorCode error code
|
|
351 |
*/
|
|
352 |
void emitThumbnailReady(QPixmap pixmap, void *internal, int id, int errorCode);
|
|
353 |
|
|
354 |
public: // Test data.
|
|
355 |
|
|
356 |
ThumbnailSize mThumbSize;
|
|
357 |
QualityPreference mQuality;
|
|
358 |
ThumbnailMode mMode;
|
|
359 |
|
|
360 |
struct TnRequest
|
|
361 |
{
|
|
362 |
QString name;
|
|
363 |
void *id;
|
|
364 |
int priority;
|
|
365 |
bool cancelled;
|
|
366 |
|
|
367 |
TnRequest(QString name, void *id, int priority, bool cancelled) {
|
|
368 |
this->name = name;
|
|
369 |
this->id = id;
|
|
370 |
this->priority = priority;
|
|
371 |
this->cancelled = cancelled;
|
|
372 |
}
|
|
373 |
|
|
374 |
TnRequest() {
|
|
375 |
name = QString("");
|
|
376 |
id = 0;
|
|
377 |
priority = tnmWrapperPriorityIdle;
|
|
378 |
cancelled = false;
|
|
379 |
}
|
|
380 |
};
|
|
381 |
|
|
382 |
static QMap<int, TnRequest> mRequests;
|
|
383 |
|
|
384 |
static bool mGetThumbFails;
|
|
385 |
static int mThumbnailReadyError;
|
37
|
386 |
static int mCancelRequestCount;
|
34
|
387 |
};
|
|
388 |
|
|
389 |
#endif // STUB_THUMBNAILMANAGER_QT
|