15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "univiewerbodywidget.h" |
18 #include "univiewerbodywidget.h" |
19 |
19 |
|
20 // SYSTEM INCLUDES |
20 #include <QFile> |
21 #include <QFile> |
21 #include <QFileInfo> |
|
22 #include <QPixmap> |
|
23 #include <QGraphicsLayout> |
|
24 #include <QSignalMapper> |
|
25 |
|
26 #include <HbTextItem> |
22 #include <HbTextItem> |
27 #include <HbIconItem> |
|
28 #include <HbPushButton> |
|
29 #include <HbAction> |
|
30 #include <HbMenu> |
|
31 #include <HbMainWindow> |
23 #include <HbMainWindow> |
32 #include <HbInstance> |
24 |
33 #include <HbGesture> |
25 // USER INCLUDES |
34 #include <HbGestureSceneFilter> |
|
35 |
|
36 #include <xqaiwrequest.h> |
|
37 #include <xqrequestinfo.h> |
|
38 #include <xqappmgr.h> |
|
39 |
|
40 #include "univiewertextitem.h" |
26 #include "univiewertextitem.h" |
41 #include "msgmediautil.h" |
27 #include "univiewerpixmapwidget.h" |
|
28 #include "univieweraudiowidget.h" |
|
29 |
42 // LOCAL CONSTANTS |
30 // LOCAL CONSTANTS |
43 const QString AUDIO_ICON("qtg_mono_audio"); |
31 const QString IMAGE_MIMETYPE("image"); |
44 |
32 const QString AUDIO_MIMETYPE("audio"); |
45 // Localization |
33 const QString VIDEO_MIMETYPE("video"); |
46 #define LOC_TITLE hbTrId("txt_messaging_title_messaging") |
34 const QString TEXT_MIMETYPE("text"); |
47 |
35 |
48 //--------------------------------------------------------------- |
36 //--------------------------------------------------------------- |
49 //UniViewerBodyWidget::UniViewerBodyWidget |
37 //UniViewerBodyWidget::UniViewerBodyWidget |
50 // @see header file |
38 // @see header file |
51 //--------------------------------------------------------------- |
39 //--------------------------------------------------------------- |
52 UniViewerBodyWidget::UniViewerBodyWidget(QGraphicsItem *parent) : |
40 UniViewerBodyWidget::UniViewerBodyWidget(QGraphicsItem *parent) : |
53 HbWidget(parent), mHasText(false), mHasPixmap(false), mTextItem(0), mSlideCounter(0), |
41 HbWidget(parent), mHasText(false), mHasPixmap(false), mTextItem(0), mSlideCounter(0), |
54 mIconItem(0), mAudioItem(0) |
42 mPixmapItem(0), mAudioItem(0) |
55 { |
43 { |
56 //Gesture filter for the image |
44 this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
57 gestureFilter = new HbGestureSceneFilter(Qt::LeftButton, this); |
|
58 gestureFilter->setLongpressAnimation(true); |
|
59 HbGesture *gesture = new HbGesture(HbGesture::longpress, 20); |
|
60 gestureFilter->addGesture(gesture); |
|
61 connect(gesture, SIGNAL(longPress(QPointF)), this, SLOT(longPressed(QPointF))); |
|
62 // Signal mapper for opening media files |
|
63 mSignalMapper = new QSignalMapper(this); |
|
64 connect(mSignalMapper, SIGNAL(mapped(const QString &)), this, SLOT(openMedia(const QString &))); |
|
65 } |
45 } |
66 |
46 |
67 //--------------------------------------------------------------- |
47 //--------------------------------------------------------------- |
68 //UniViewerBodyWidget::~UniViewerBodyWidget |
48 //UniViewerBodyWidget::~UniViewerBodyWidget |
69 // @see header file |
49 // @see header file |
74 |
54 |
75 //--------------------------------------------------------------- |
55 //--------------------------------------------------------------- |
76 //UniViewerBodyWidget::setImage |
56 //UniViewerBodyWidget::setImage |
77 // @see header file |
57 // @see header file |
78 //--------------------------------------------------------------- |
58 //--------------------------------------------------------------- |
79 void UniViewerBodyWidget::setImage(QString imagefile) |
59 void UniViewerBodyWidget::setPixmap(UniMessageInfo *info) |
80 { |
60 { |
81 setHasPixmap(true); |
61 setHasPixmap(true); |
82 //create image item instance |
62 //create image item instance |
83 if (!mIconItem) { |
63 if (!mPixmapItem) { |
84 mIconItem = new HbIconItem(this); |
64 mPixmapItem = new UniViewerPixmapWidget(this); |
85 HbStyle::setItemName(mIconItem, "pixmap"); |
65 HbStyle::setItemName(mPixmapItem, "pixmap"); |
86 } |
66 } |
87 |
67 mPixmapItem->hide(); |
88 QPixmap pixmap(imagefile); |
68 mPixmapItem->populate(info); |
89 mIconItem->setIcon(HbIcon(pixmap)); |
|
90 |
|
91 // TODO |
|
92 // Implementation for short tap action is unclear |
|
93 // Connect to signal mapper |
|
94 |
69 |
95 this->repolish(); |
70 this->repolish(); |
96 } |
71 } |
97 |
72 |
98 //--------------------------------------------------------------- |
73 //--------------------------------------------------------------- |
99 //UniViewerBodyWidget::setAudio |
74 //UniViewerBodyWidget::setAudio |
100 // @see header file |
75 // @see header file |
101 //--------------------------------------------------------------- |
76 //--------------------------------------------------------------- |
102 void UniViewerBodyWidget::setAudio(QString audiofile) |
77 void UniViewerBodyWidget::setAudio(UniMessageInfo *info) |
103 { |
78 { |
104 if (!mAudioItem) { |
79 if (!mAudioItem) { |
105 mAudioItem = new HbPushButton(this); |
80 mAudioItem = new UniViewerAudioWidget(this); |
106 HbStyle::setItemName(mAudioItem, "audioItem"); |
81 HbStyle::setItemName(mAudioItem, "audioItem"); |
107 } |
82 } |
108 QFileInfo fileInfo(audiofile); |
83 mAudioItem->hide(); |
109 mAudioItem->setIcon(HbIcon(AUDIO_ICON)); |
84 mAudioItem->populate(info); |
110 mAudioItem->setText(fileInfo.baseName()); |
|
111 MsgMediaUtil mediaUtil; |
|
112 mAudioItem->setAdditionalText(mediaUtil.mediaDuration(audiofile)); |
|
113 mAudioItem->setTextAlignment(Qt::AlignLeft); |
|
114 |
|
115 // Connect to signal mapper with file name |
|
116 mSignalMapper->setMapping(mAudioItem, audiofile); |
|
117 connect(mAudioItem, SIGNAL(clicked()), mSignalMapper, SLOT(map())); |
|
118 |
85 |
119 this->repolish(); |
86 this->repolish(); |
120 } |
87 } |
121 |
88 |
122 //--------------------------------------------------------------- |
89 //--------------------------------------------------------------- |
123 //UniViewerBodyWidget::setVideo |
90 //UniViewerBodyWidget::setVideo |
124 // @see header file |
91 // @see header file |
125 //--------------------------------------------------------------- |
92 //--------------------------------------------------------------- |
126 void UniViewerBodyWidget::setVideo(QString videofile) |
93 void UniViewerBodyWidget::setVideo(UniMessageInfo *info) |
127 { |
94 { |
128 Q_UNUSED(videofile) |
95 setHasPixmap(true); |
129 } |
96 //create image item instance |
130 |
97 if (!mPixmapItem) { |
131 //--------------------------------------------------------------- |
98 mPixmapItem = new UniViewerPixmapWidget(this); |
132 //UniViewerBodyWidget::setTextContent |
99 HbStyle::setItemName(mPixmapItem, "pixmap"); |
133 // @see header file |
100 } |
134 //--------------------------------------------------------------- |
101 mPixmapItem->hide(); |
135 void UniViewerBodyWidget::setTextContent(QString text) |
102 mPixmapItem->populate(info); |
|
103 |
|
104 this->repolish(); |
|
105 } |
|
106 |
|
107 //--------------------------------------------------------------- |
|
108 //UniViewerBodyWidget::setText |
|
109 // @see header file |
|
110 //--------------------------------------------------------------- |
|
111 void UniViewerBodyWidget::setText(QString text) |
136 { |
112 { |
137 setHasText(true); |
113 setHasText(true); |
138 |
114 |
139 if (!mTextItem) { |
115 if (!mTextItem) { |
140 mTextItem = new UniViewerTextItem(this); |
116 mTextItem = new UniViewerTextItem(this); |
141 HbStyle::setItemName(mTextItem, "textItem"); |
117 HbStyle::setItemName(mTextItem, "textItem"); |
142 connect(mTextItem, SIGNAL(sendMessage(const QString&)), this, |
118 connect(mTextItem, SIGNAL(sendMessage(const QString&)), this, |
143 SIGNAL(sendMessage(const QString&))); |
119 SIGNAL(sendMessage(const QString&))); |
144 } |
120 } |
|
121 mTextItem->hide(); |
145 text.replace(QChar::ParagraphSeparator, QChar::LineSeparator); |
122 text.replace(QChar::ParagraphSeparator, QChar::LineSeparator); |
146 text.replace('\r', QChar::LineSeparator); |
123 text.replace('\r', QChar::LineSeparator); |
147 mTextItem->setText(text); |
124 mTextItem->setText(text); |
148 this->repolish(); |
125 this->repolish(); |
149 } |
126 } |
150 |
127 |
151 //--------------------------------------------------------------- |
128 //--------------------------------------------------------------- |
152 //UniViewerBodyWidget::setTextContent |
129 // UniViewerBodyWidget::setSlideCounter |
153 // @see header file |
130 // @see header file |
154 //--------------------------------------------------------------- |
131 //--------------------------------------------------------------- |
155 void UniViewerBodyWidget::setSlideCounter(QString &slideCounter) |
132 void UniViewerBodyWidget::setSlideCounter(QString &slideCounter) |
156 { |
133 { |
157 if (!mSlideCounter) { |
134 if (!mSlideCounter) { |
158 mSlideCounter = new HbTextItem(this); |
135 mSlideCounter = new HbTextItem(this); |
159 HbStyle::setItemName(mSlideCounter, "slideCounter"); |
136 HbStyle::setItemName(mSlideCounter, "slideCounter"); |
160 } |
137 } |
161 |
138 |
|
139 mSlideCounter->hide(); |
162 mSlideCounter->setText(slideCounter); |
140 mSlideCounter->setText(slideCounter); |
163 this->repolish(); |
141 this->repolish(); |
164 } |
142 } |
165 |
143 |
166 //--------------------------------------------------------------- |
144 //--------------------------------------------------------------- |
266 setHasPixmap(false); |
242 setHasPixmap(false); |
267 repolish(); |
243 repolish(); |
268 } |
244 } |
269 |
245 |
270 //--------------------------------------------------------------- |
246 //--------------------------------------------------------------- |
271 //UniViewerBodyWidget::resizeEvent |
247 //UniViewerBodyWidget::sizeHint |
272 // @see header file |
248 // @see header file |
273 //--------------------------------------------------------------- |
249 //--------------------------------------------------------------- |
274 void UniViewerBodyWidget::resizeEvent(QGraphicsSceneResizeEvent* event) |
250 QSizeF UniViewerBodyWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const |
275 { |
251 { |
276 Q_UNUSED(event) |
252 QSizeF szHint = HbWidget::sizeHint(which, constraint); |
277 |
253 |
278 HbMainWindow *mainWindow = this->mainWindow(); |
254 HbMainWindow *mainWindow = this->mainWindow(); |
279 if (mainWindow) { |
255 if (!mainWindow) { |
280 qreal screenWidth = 0.0; |
256 return szHint; |
281 qreal screenHeight = 0.0; |
257 } |
282 qreal leftMargin = 0.0; |
258 |
283 qreal rightMargin = 0.0; |
259 qreal screenWidth = 0.0; |
284 qreal chromeHeight = 0.0; |
260 qreal screenHeight = 0.0; |
285 qreal toolbarHeight = 0.0; |
261 qreal leftMargin = 0.0; |
286 qreal iconSize = 0.0; |
262 qreal rightMargin = 0.0; |
287 qreal unitSize = HbDeviceProfile::profile(mIconItem).unitValue(); |
263 qreal chromeHeight = 0.0; |
288 style()->parameter("hb-param-screen-width", screenWidth); |
264 qreal toolbarHeight = 0.0; |
289 style()->parameter("hb-param-screen-height", screenHeight); |
265 qreal iconSize = 0.0; |
290 style()->parameter("hb-param-margin-gene-left", leftMargin); |
266 qreal spacing = 0.0; |
291 style()->parameter("hb-param-margin-gene-right", rightMargin); |
267 qreal unitSize = HbDeviceProfile::profile(mPixmapItem).unitValue(); |
292 style()->parameter("hb-param-widget-chrome-height", chromeHeight); |
268 style()->parameter("hb-param-screen-width", screenWidth); |
293 style()->parameter("hb-param-widget-toolbar-height", toolbarHeight); |
269 style()->parameter("hb-param-screen-height", screenHeight); |
294 style()->parameter("hb-param-graphic-size-primary-large", iconSize); |
270 style()->parameter("hb-param-margin-gene-left", leftMargin); |
295 |
271 style()->parameter("hb-param-margin-gene-right", rightMargin); |
296 qreal maxWidth = 0.0; |
272 style()->parameter("hb-param-widget-chrome-height", chromeHeight); |
297 qreal maxHeight = 0.0; |
273 style()->parameter("hb-param-widget-toolbar-height", toolbarHeight); |
298 |
274 style()->parameter("hb-param-graphic-size-primary-large", iconSize); |
299 if (mainWindow->orientation() == Qt::Horizontal) { |
275 style()->parameter("hb-param-margin-gene-middle-vertical", spacing); |
300 qreal temp; |
276 |
301 temp = screenWidth; |
277 qreal maxWidth = 0.0; |
302 screenWidth = screenHeight; |
278 qreal maxHeight = 0.0; |
303 screenHeight = temp; |
279 |
304 if (mIconItem) { |
280 // Calculate max height & max width. |
305 if (mHasText) { |
281 if (mainWindow->orientation() == Qt::Horizontal) { |
306 maxWidth = (screenWidth / 2) - leftMargin - unitSize; |
282 qreal temp; |
307 } |
283 temp = screenWidth; |
308 else { |
284 screenWidth = screenHeight; |
309 maxWidth = screenWidth - leftMargin - rightMargin; |
285 screenHeight = temp; |
310 } |
286 |
311 maxHeight = screenHeight - chromeHeight - toolbarHeight; |
287 if (mPixmapItem && mHasText) { |
312 } |
288 maxWidth = (screenWidth / 2) - leftMargin - unitSize; |
313 if (mAudioItem) { |
289 } |
314 mAudioItem->setStretched(true); |
290 else { |
315 } |
291 maxWidth = screenWidth - leftMargin - rightMargin; |
316 } |
292 } |
317 else if (mainWindow->orientation() == Qt::Vertical) { |
293 maxHeight = screenHeight - chromeHeight - toolbarHeight; |
318 if (mIconItem) { |
294 |
319 maxWidth = screenWidth - leftMargin - rightMargin; |
295 if (mAudioItem) { |
320 maxHeight = screenHeight - chromeHeight - toolbarHeight; |
296 mAudioItem->setStretched(true); |
321 } |
297 } |
322 if (mAudioItem) { |
298 } |
323 mAudioItem->setStretched(false); |
299 else if (mainWindow->orientation() == Qt::Vertical) { |
324 } |
300 maxWidth = screenWidth - leftMargin - rightMargin; |
325 } |
301 maxHeight = screenHeight - chromeHeight - toolbarHeight; |
326 |
302 |
327 if (mIconItem) { |
303 if (mAudioItem) { |
328 qreal imageWidth = mIconItem->icon().defaultSize().width(); |
304 mAudioItem->setStretched(false); |
329 qreal imageHeight = mIconItem->icon().defaultSize().height(); |
305 } |
330 |
306 } |
331 qreal widthToSet = 0.0; |
307 |
332 qreal heightToSet = 0.0; |
308 // Slide Counter |
333 |
309 QSizeF slideCounterSize(0, 0); |
334 if (imageWidth < iconSize) { |
310 if (mSlideCounter) { |
335 widthToSet = iconSize; |
311 slideCounterSize = mSlideCounter->effectiveSizeHint(which, constraint); |
336 heightToSet = iconSize; |
312 mSlideCounter->show(); |
337 } |
313 } |
338 else if (imageWidth <= maxWidth) { |
314 // Audio Item |
339 // resize not needed |
315 QSizeF audioSize(0, 0); |
340 widthToSet = imageWidth; |
316 if (mAudioItem) { |
341 heightToSet = qMin(imageHeight, maxHeight); |
317 audioSize = mAudioItem->effectiveSizeHint(which, constraint); |
342 } |
318 mAudioItem->show(); |
343 else { |
319 } |
344 // resize needed, keep aspect-ratio and resize |
320 |
345 widthToSet = maxWidth; |
321 // Text Item |
346 heightToSet = maxWidth * (imageHeight / imageWidth); |
322 QSizeF textSize(0, 0); |
347 heightToSet = qMin(heightToSet, maxHeight); |
323 if (mTextItem) { |
348 |
324 textSize = mTextItem->effectiveSizeHint(which, constraint); |
349 } |
325 mTextItem->show(); |
350 if (heightToSet == maxHeight) { |
326 } |
351 widthToSet = heightToSet * (imageWidth / imageHeight); |
327 |
352 } |
328 // Pixmap Item |
353 |
329 QSizeF pixmapSize(0, 0); |
354 mIconItem->setPreferredWidth(widthToSet); |
330 if (mPixmapItem) { |
355 mIconItem->setPreferredHeight(heightToSet); |
331 qreal imageWidth = mPixmapItem->icon().defaultSize().width(); |
356 } |
332 qreal imageHeight = mPixmapItem->icon().defaultSize().height(); |
357 } |
333 |
358 } |
334 qreal widthToSet = 0.0; |
359 |
335 qreal heightToSet = 0.0; |
360 //--------------------------------------------------------------- |
336 |
361 //UniViewerBodyWidget::longPressed |
337 if (imageWidth < iconSize) { |
362 // @see header file |
338 widthToSet = iconSize; |
363 //--------------------------------------------------------------- |
339 heightToSet = iconSize; |
364 void UniViewerBodyWidget::longPressed(QPointF position) |
340 } |
365 { |
341 else if (imageWidth <= maxWidth) { |
366 |
342 // resize not needed |
367 HbMenu* menu = new HbMenu; |
343 widthToSet = imageWidth; |
368 menu->addAction(tr("Open"), this, SLOT(openMedia())); |
344 heightToSet = qMin(imageHeight, maxHeight); |
369 menu->addAction(tr("View details"), this, SLOT(viewDetails())); |
345 } |
370 menu->exec(position); |
346 else { |
371 delete menu; |
347 // resize needed, keep aspect-ratio and resize |
372 } |
348 widthToSet = maxWidth; |
373 |
349 heightToSet = maxWidth * (imageHeight / imageWidth); |
374 //--------------------------------------------------------------- |
350 heightToSet = qMin(heightToSet, maxHeight); |
375 //UniViewerBodyWidget::openMedia |
351 |
376 // @see header file |
352 } |
377 //--------------------------------------------------------------- |
353 if (heightToSet == maxHeight) { |
378 void UniViewerBodyWidget::openMedia() |
354 widthToSet = heightToSet * (imageWidth / imageHeight); |
379 { |
355 } |
380 } |
356 |
381 |
357 pixmapSize.setHeight(heightToSet); |
382 //--------------------------------------------------------------- |
358 pixmapSize.setWidth(widthToSet); |
383 //UniViewerBodyWidget::openMedia |
359 mPixmapItem->setPreferredSize(pixmapSize); |
384 // @see header file |
360 mPixmapItem->show(); |
385 //--------------------------------------------------------------- |
361 } |
386 void UniViewerBodyWidget::openMedia(const QString& fileName) |
362 |
387 { |
363 // Calculate the size hint to be returned. |
388 XQSharableFile sf; |
364 szHint.setHeight(0); |
389 XQAiwRequest* request = 0; |
365 |
390 |
366 if (!slideCounterSize.isNull()) { |
391 if (!sf.open(fileName)) { |
367 szHint.rheight() += (slideCounterSize.height() + spacing); |
392 return; |
368 } |
393 } |
369 if (!audioSize.isNull()) { |
394 |
370 szHint.rheight() += (audioSize.height() + spacing); |
395 // Get handlers |
371 } |
396 XQApplicationManager appManager; |
372 |
397 QList<XQAiwInterfaceDescriptor> fileHandlers = appManager.list(sf); |
373 if (mainWindow->orientation() == Qt::Horizontal) { |
398 if (fileHandlers.count() > 0) { |
374 qreal remainingHeight = qMax(pixmapSize.height(), textSize.height()); |
399 XQAiwInterfaceDescriptor d = fileHandlers.first(); |
375 if (remainingHeight > 0.0) { |
400 request = appManager.create(sf, d); |
376 szHint.rheight() += (remainingHeight + spacing); |
401 |
377 } |
402 if (!request) { |
378 } |
403 sf.close(); |
379 else if (mainWindow->orientation() == Qt::Vertical) { |
404 return; |
380 if (!pixmapSize.isNull()) { |
405 } |
381 szHint.rheight() += (pixmapSize.height() + spacing); |
406 } |
382 } |
407 else { |
383 if (!textSize.isNull()) { |
408 sf.close(); |
384 szHint.rheight() += (textSize.height() + spacing); |
409 return; |
385 } |
410 } |
386 } |
411 |
387 szHint.rheight() = qMax(maxHeight, szHint.height()); |
412 // Result handlers |
388 |
413 connect(request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&))); |
389 return szHint; |
414 connect(request, SIGNAL(requestError(const QVariant&)), this, |
390 } |
415 SLOT(handleError(const QVariant&))); |
391 |
416 |
|
417 request->setEmbedded(true); |
|
418 request->setSynchronous(true); |
|
419 |
|
420 // Fill args |
|
421 QList<QVariant> args; |
|
422 args << qVariantFromValue(sf); |
|
423 request->setArguments(args); |
|
424 |
|
425 // Fill headers |
|
426 QString key("WindowTitle"); |
|
427 QVariant value(QString(LOC_TITLE)); |
|
428 XQRequestInfo info; |
|
429 info.setInfo(key, value); |
|
430 request->setInfo(info); |
|
431 |
|
432 request->send(); |
|
433 |
|
434 // Cleanup |
|
435 sf.close(); |
|
436 delete request; |
|
437 } |
|
438 |
|
439 //--------------------------------------------------------------- |
|
440 //UniViewerBodyWidget::viewDetails |
|
441 // @see header file |
|
442 //--------------------------------------------------------------- |
|
443 void UniViewerBodyWidget::viewDetails() |
|
444 { |
|
445 //open details view. |
|
446 } |
|
447 |
|
448 //--------------------------------------------------------------- |
|
449 // UniViewerBodyWidget :: handleOk |
|
450 // @see header file |
|
451 //--------------------------------------------------------------- |
|
452 void UniViewerBodyWidget::handleOk(const QVariant& result) |
|
453 { |
|
454 Q_UNUSED(result) |
|
455 } |
|
456 |
|
457 //--------------------------------------------------------------- |
|
458 // UniViewerBodyWidget :: handleError |
|
459 // @see header file |
|
460 //--------------------------------------------------------------- |
|
461 void UniViewerBodyWidget::handleError(int errorCode, const QString& errorMessage) |
|
462 { |
|
463 Q_UNUSED(errorMessage) |
|
464 Q_UNUSED(errorCode) |
|
465 } |
|
466 // EOF |
392 // EOF |