32 |
32 |
33 // LOCAL CONSTANTS |
33 // LOCAL CONSTANTS |
34 #define LOC_OPEN hbTrId("txt_common_menu_open") |
34 #define LOC_OPEN hbTrId("txt_common_menu_open") |
35 #define LOC_SAVE hbTrId("txt_common_menu_save") |
35 #define LOC_SAVE hbTrId("txt_common_menu_save") |
36 |
36 |
37 const QString PIXMAP_ICON("qtg_small_image"); |
37 static const char PIXMAP_ICON[] = "qtg_small_image"; |
38 const QString CORRUPTED_PIXMAP_ICON("qtg_large_corrupted"); |
38 static const char CORRUPTED_PIXMAP_ICON[] = "qtg_large_corrupted"; |
39 const QString VIDEO_MIMETYPE("video"); |
39 static const char VIDEO_MIMETYPE[] = "video"; |
40 const QString MSG_VIDEO_ICON("qtg_small_video"); |
40 |
|
41 static const int WIDTH_RATIO = 4; |
|
42 static const int HEIGHT_RATIO = 3; |
41 |
43 |
42 //--------------------------------------------------------------- |
44 //--------------------------------------------------------------- |
43 // UniViewerPixmapWidget::UniViewerPixmapWidget |
45 // UniViewerPixmapWidget::UniViewerPixmapWidget |
44 // @see header file |
46 // @see header file |
45 //--------------------------------------------------------------- |
47 //--------------------------------------------------------------- |
46 UniViewerPixmapWidget::UniViewerPixmapWidget(QGraphicsItem *parent) : |
48 UniViewerPixmapWidget::UniViewerPixmapWidget(QGraphicsItem *parent) : |
47 HbIconItem(parent), mViewerUtils(0), mThumbnailManager(0) |
49 HbIconItem(parent), mInfo(0), mViewerUtils(0), mThumbnailManager(0) |
48 { |
50 { |
49 this->grabGesture(Qt::TapGesture); |
51 this->grabGesture(Qt::TapGesture); |
50 init(); |
52 init(); |
51 } |
53 } |
52 |
54 |
53 //--------------------------------------------------------------- |
55 //--------------------------------------------------------------- |
54 // UniViewerPixmapWidget::init |
|
55 // @see header file |
|
56 //--------------------------------------------------------------- |
|
57 void UniViewerPixmapWidget::init() |
|
58 { |
|
59 mThumbnailManager = new ThumbnailManager(this); |
|
60 mThumbnailManager->setMode(ThumbnailManager::Default); |
|
61 mThumbnailManager->setQualityPreference(ThumbnailManager::OptimizeForQuality); |
|
62 mThumbnailManager->setThumbnailSize(ThumbnailManager::ThumbnailLarge); |
|
63 |
|
64 connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void*, int, int)), this, |
|
65 SLOT(thumbnailReady(QPixmap, void*, int, int))); |
|
66 |
|
67 } |
|
68 |
|
69 //--------------------------------------------------------------- |
|
70 // UniViewerPixmapWidget::~UniViewerPixmapWidget |
56 // UniViewerPixmapWidget::~UniViewerPixmapWidget |
71 // @see header file |
57 // @see header file |
72 //--------------------------------------------------------------- |
58 //--------------------------------------------------------------- |
73 UniViewerPixmapWidget::~UniViewerPixmapWidget() |
59 UniViewerPixmapWidget::~UniViewerPixmapWidget() |
74 { |
60 { |
75 } |
61 if (mInfo) { |
76 |
62 delete mInfo; |
77 //--------------------------------------------------------------- |
63 mInfo = NULL; |
78 // UniViewerPixmapWidget::setPixmap |
64 } |
|
65 } |
|
66 |
|
67 //--------------------------------------------------------------- |
|
68 // UniViewerPixmapWidget::populate |
79 // @see header file |
69 // @see header file |
80 //--------------------------------------------------------------- |
70 //--------------------------------------------------------------- |
81 void UniViewerPixmapWidget::populate(UniMessageInfo *info) |
71 void UniViewerPixmapWidget::populate(UniMessageInfo *info) |
82 { |
72 { |
83 mMimeType = info->mimetype(); |
73 mMimeType = info->mimetype(); |
84 mPixmapPath = info->path(); |
74 mPixmapPath = info->path(); |
|
75 |
|
76 /** |
|
77 * Create a copy of info for video content. |
|
78 * mInfo will be deleted in the destructor. |
|
79 */ |
85 if (mMimeType.contains(VIDEO_MIMETYPE)) { |
80 if (mMimeType.contains(VIDEO_MIMETYPE)) { |
86 this->setIcon(MSG_VIDEO_ICON); |
81 mInfo = new UniMessageInfo(*info); |
87 mThumbnailManager->getThumbnail(mPixmapPath); |
82 } |
88 this->ungrabGesture(Qt::TapGesture); |
83 |
89 } |
84 if (info->isProtected()) { |
90 else if (info->isProtected()) { |
85 if (mMimeType.contains(VIDEO_MIMETYPE)) { |
91 this->setIconName(PIXMAP_ICON); |
86 emit thumbnailFound(false, mInfo); |
|
87 } |
|
88 else { |
|
89 this->setIconName(PIXMAP_ICON); |
|
90 } |
92 } |
91 } |
93 else if (info->isCorrupted()) { |
92 else if (info->isCorrupted()) { |
94 this->setIconName(CORRUPTED_PIXMAP_ICON); |
93 if (mMimeType.contains(VIDEO_MIMETYPE)) { |
|
94 emit thumbnailFound(false, mInfo); |
|
95 } |
|
96 else { |
|
97 this->setIconName(CORRUPTED_PIXMAP_ICON); |
|
98 } |
95 } |
99 } |
96 else { |
100 else { |
97 QPixmap pixmap(mPixmapPath); |
101 if (mMimeType.contains(VIDEO_MIMETYPE)) { |
98 this->setIcon(HbIcon(pixmap)); |
102 mThumbnailManager->getThumbnail(mPixmapPath); |
|
103 this->ungrabGesture(Qt::TapGesture); |
|
104 } |
|
105 else { |
|
106 QPixmap pixmap(mPixmapPath); |
|
107 this->setIcon(HbIcon(pixmap)); |
|
108 } |
99 } |
109 } |
100 } |
110 } |
101 |
111 |
102 //--------------------------------------------------------------- |
112 //--------------------------------------------------------------- |
103 // UniViewerPixmapWidget::gestureEvent |
113 // UniViewerPixmapWidget::gestureEvent |
164 // UniViewerPixmapWidget::handleSave |
174 // UniViewerPixmapWidget::handleSave |
165 // @see header file |
175 // @see header file |
166 //--------------------------------------------------------------- |
176 //--------------------------------------------------------------- |
167 void UniViewerPixmapWidget::handleSave() |
177 void UniViewerPixmapWidget::handleSave() |
168 { |
178 { |
|
179 } |
|
180 |
|
181 //--------------------------------------------------------------- |
|
182 // UniViewerPixmapWidget::regrabGesture |
|
183 // @see header file |
|
184 //--------------------------------------------------------------- |
|
185 void UniViewerPixmapWidget::regrabGesture() |
|
186 { |
|
187 this->grabGesture(Qt::TapGesture); |
|
188 } |
|
189 |
|
190 //--------------------------------------------------------------- |
|
191 // UniViewerPixmapWidget::thumbnailReady |
|
192 // @see header |
|
193 //--------------------------------------------------------------- |
|
194 void UniViewerPixmapWidget::thumbnailReady(const QPixmap& pixmap, void *data, int id, int error) |
|
195 { |
|
196 Q_UNUSED(data) |
|
197 Q_UNUSED(id) |
|
198 this->grabGesture(Qt::TapGesture); |
|
199 if (error) { |
|
200 emit thumbnailFound(false, mInfo); |
|
201 } |
|
202 else { |
|
203 this->setIcon(HbIcon(pixmap)); |
|
204 this->hide(); |
|
205 emit thumbnailFound(true, NULL); |
|
206 } |
|
207 } |
|
208 |
|
209 //--------------------------------------------------------------- |
|
210 // UniViewerPixmapWidget::init |
|
211 // @see header file |
|
212 //--------------------------------------------------------------- |
|
213 void UniViewerPixmapWidget::init() |
|
214 { |
|
215 mThumbnailManager = new ThumbnailManager(this); |
|
216 mThumbnailManager->setMode(ThumbnailManager::CropToAspectRatio); |
|
217 mThumbnailManager->setQualityPreference(ThumbnailManager::OptimizeForQuality); |
|
218 mThumbnailManager->setThumbnailSize(getThumbnailSize()); |
|
219 |
|
220 connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void*, int, int)), this, |
|
221 SLOT(thumbnailReady(QPixmap, void*, int, int))); |
169 } |
222 } |
170 |
223 |
171 //---------------------------------------------------------------------------- |
224 //---------------------------------------------------------------------------- |
172 // UniViewerPixmapWidget::handleShortTap |
225 // UniViewerPixmapWidget::handleShortTap |
173 // @see header file |
226 // @see header file |
195 menu->setPreferredPos(position); |
248 menu->setPreferredPos(position); |
196 menu->show(); |
249 menu->show(); |
197 } |
250 } |
198 |
251 |
199 //--------------------------------------------------------------- |
252 //--------------------------------------------------------------- |
200 // UniViewerPixmapWidget::regrabGesture |
253 // UniViewerPixmapWidget::getThumbnailSize |
201 // @see header file |
254 // @see header file |
202 //--------------------------------------------------------------- |
255 //--------------------------------------------------------------- |
203 void UniViewerPixmapWidget::regrabGesture() |
256 QSize UniViewerPixmapWidget::getThumbnailSize() |
204 { |
257 { |
205 this->grabGesture(Qt::TapGesture); |
258 QSize thumbnailSize(1, 1); |
206 } |
259 HbWidget *parent = qobject_cast<HbWidget *>(this->parentWidget()); |
207 |
260 |
208 //--------------------------------------------------------------- |
261 if (parent) { |
209 // UniViewerPixmapWidget::thumbnailReady |
262 qreal thumbnailWidth = 0.0; |
210 // @see header |
263 qreal thumbnailHeight = 0.0; |
211 //--------------------------------------------------------------- |
264 parent->style()->parameter("hb-param-screen-short-edge", thumbnailWidth); |
212 void UniViewerPixmapWidget::thumbnailReady(const QPixmap& pixmap, void *data, int id, int error) |
265 thumbnailHeight = (thumbnailWidth * HEIGHT_RATIO) / WIDTH_RATIO; |
213 { |
266 thumbnailSize.setHeight(qRound(thumbnailHeight)); |
214 Q_UNUSED(data) |
267 thumbnailSize.setWidth(qRound(thumbnailWidth)); |
215 Q_UNUSED(id) |
268 } |
216 this->grabGesture(Qt::TapGesture); |
269 return thumbnailSize; |
217 if (!error) { |
270 } |
218 this->setIcon(HbIcon(pixmap)); |
271 |
219 this->hide(); |
|
220 this->updateGeometry(); |
|
221 } |
|
222 } |
|
223 // EOF |
272 // EOF |