18 #include "univiewerbodywidget.h" |
18 #include "univiewerbodywidget.h" |
19 |
19 |
20 #include <QFile> |
20 #include <QFile> |
21 #include <QFileInfo> |
21 #include <QFileInfo> |
22 #include <QPixmap> |
22 #include <QPixmap> |
23 #include <QGraphicsLayout> |
|
24 #include <QSignalMapper> |
23 #include <QSignalMapper> |
25 |
24 |
26 #include <HbTextItem> |
25 #include <HbTextItem> |
27 #include <HbIconItem> |
|
28 #include <HbPushButton> |
26 #include <HbPushButton> |
29 #include <HbAction> |
|
30 #include <HbMenu> |
27 #include <HbMenu> |
31 #include <HbMainWindow> |
28 #include <HbMainWindow> |
32 #include <HbInstance> |
|
33 #include <HbGesture> |
|
34 #include <HbGestureSceneFilter> |
|
35 |
29 |
36 #include <xqaiwrequest.h> |
30 #include <xqaiwrequest.h> |
37 #include <xqrequestinfo.h> |
31 #include <xqrequestinfo.h> |
38 #include <xqappmgr.h> |
32 #include <xqappmgr.h> |
39 |
33 |
40 #include "univiewertextitem.h" |
34 #include "univiewertextitem.h" |
|
35 #include "univiewerpixmapwidget.h" |
41 #include "msgmediautil.h" |
36 #include "msgmediautil.h" |
42 // LOCAL CONSTANTS |
37 // LOCAL CONSTANTS |
43 const QString AUDIO_ICON("qtg_mono_audio"); |
38 const QString AUDIO_ICON("qtg_mono_audio"); |
44 |
39 |
45 // Localization |
40 // Localization |
46 #define LOC_TITLE hbTrId("txt_messaging_title_messaging") |
41 #define LOC_TITLE hbTrId("txt_messaging_title_messaging") |
|
42 #define LOC_OPEN hbTrId("txt_common_menu_open") |
|
43 #define LOC_SAVE hbTrId("txt_common_menu_save") |
47 |
44 |
48 //--------------------------------------------------------------- |
45 //--------------------------------------------------------------- |
49 //UniViewerBodyWidget::UniViewerBodyWidget |
46 //UniViewerBodyWidget::UniViewerBodyWidget |
50 // @see header file |
47 // @see header file |
51 //--------------------------------------------------------------- |
48 //--------------------------------------------------------------- |
52 UniViewerBodyWidget::UniViewerBodyWidget(QGraphicsItem *parent) : |
49 UniViewerBodyWidget::UniViewerBodyWidget(QGraphicsItem *parent) : |
53 HbWidget(parent), mHasText(false), mHasPixmap(false), mTextItem(0), mSlideCounter(0), |
50 HbWidget(parent), mHasText(false), mHasPixmap(false), mTextItem(0), mSlideCounter(0), |
54 mIconItem(0), mAudioItem(0) |
51 mPixmapItem(0), mAudioItem(0) |
55 { |
52 { |
56 //Gesture filter for the image |
53 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 |
54 // Signal mapper for opening media files |
63 mSignalMapper = new QSignalMapper(this); |
55 mSignalMapper = new QSignalMapper(this); |
64 connect(mSignalMapper, SIGNAL(mapped(const QString &)), this, SLOT(openMedia(const QString &))); |
56 connect(mSignalMapper, SIGNAL(mapped(const QString &)), this, SLOT(openMedia(const QString &))); |
65 } |
57 } |
66 |
58 |
266 setHasPixmap(false); |
256 setHasPixmap(false); |
267 repolish(); |
257 repolish(); |
268 } |
258 } |
269 |
259 |
270 //--------------------------------------------------------------- |
260 //--------------------------------------------------------------- |
271 //UniViewerBodyWidget::resizeEvent |
261 //UniViewerBodyWidget::sizeHint |
272 // @see header file |
262 // @see header file |
273 //--------------------------------------------------------------- |
263 //--------------------------------------------------------------- |
274 void UniViewerBodyWidget::resizeEvent(QGraphicsSceneResizeEvent* event) |
264 QSizeF UniViewerBodyWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const |
275 { |
265 { |
276 Q_UNUSED(event) |
266 QSizeF szHint = HbWidget::sizeHint(which, constraint); |
277 |
267 |
278 HbMainWindow *mainWindow = this->mainWindow(); |
268 HbMainWindow *mainWindow = this->mainWindow(); |
279 if (mainWindow) { |
269 if (!mainWindow) { |
280 qreal screenWidth = 0.0; |
270 return szHint; |
281 qreal screenHeight = 0.0; |
271 } |
282 qreal leftMargin = 0.0; |
272 |
283 qreal rightMargin = 0.0; |
273 qreal screenWidth = 0.0; |
284 qreal chromeHeight = 0.0; |
274 qreal screenHeight = 0.0; |
285 qreal toolbarHeight = 0.0; |
275 qreal leftMargin = 0.0; |
286 qreal iconSize = 0.0; |
276 qreal rightMargin = 0.0; |
287 qreal unitSize = HbDeviceProfile::profile(mIconItem).unitValue(); |
277 qreal chromeHeight = 0.0; |
288 style()->parameter("hb-param-screen-width", screenWidth); |
278 qreal toolbarHeight = 0.0; |
289 style()->parameter("hb-param-screen-height", screenHeight); |
279 qreal iconSize = 0.0; |
290 style()->parameter("hb-param-margin-gene-left", leftMargin); |
280 qreal spacing = 0.0; |
291 style()->parameter("hb-param-margin-gene-right", rightMargin); |
281 qreal unitSize = HbDeviceProfile::profile(mPixmapItem).unitValue(); |
292 style()->parameter("hb-param-widget-chrome-height", chromeHeight); |
282 style()->parameter("hb-param-screen-width", screenWidth); |
293 style()->parameter("hb-param-widget-toolbar-height", toolbarHeight); |
283 style()->parameter("hb-param-screen-height", screenHeight); |
294 style()->parameter("hb-param-graphic-size-primary-large", iconSize); |
284 style()->parameter("hb-param-margin-gene-left", leftMargin); |
295 |
285 style()->parameter("hb-param-margin-gene-right", rightMargin); |
296 qreal maxWidth = 0.0; |
286 style()->parameter("hb-param-widget-chrome-height", chromeHeight); |
297 qreal maxHeight = 0.0; |
287 style()->parameter("hb-param-widget-toolbar-height", toolbarHeight); |
298 |
288 style()->parameter("hb-param-graphic-size-primary-large", iconSize); |
299 if (mainWindow->orientation() == Qt::Horizontal) { |
289 style()->parameter("hb-param-margin-gene-middle-vertical", spacing); |
300 qreal temp; |
290 |
301 temp = screenWidth; |
291 qreal maxWidth = 0.0; |
302 screenWidth = screenHeight; |
292 qreal maxHeight = 0.0; |
303 screenHeight = temp; |
293 |
304 if (mIconItem) { |
294 // Calculate max height & max width. |
305 if (mHasText) { |
295 if (mainWindow->orientation() == Qt::Horizontal) { |
306 maxWidth = (screenWidth / 2) - leftMargin - unitSize; |
296 qreal temp; |
307 } |
297 temp = screenWidth; |
308 else { |
298 screenWidth = screenHeight; |
309 maxWidth = screenWidth - leftMargin - rightMargin; |
299 screenHeight = temp; |
310 } |
300 |
311 maxHeight = screenHeight - chromeHeight - toolbarHeight; |
301 if (mPixmapItem && mHasText) { |
312 } |
302 maxWidth = (screenWidth / 2) - leftMargin - unitSize; |
313 if (mAudioItem) { |
303 } |
314 mAudioItem->setStretched(true); |
304 else { |
315 } |
305 maxWidth = screenWidth - leftMargin - rightMargin; |
316 } |
306 } |
317 else if (mainWindow->orientation() == Qt::Vertical) { |
307 maxHeight = screenHeight - chromeHeight - toolbarHeight; |
318 if (mIconItem) { |
308 |
319 maxWidth = screenWidth - leftMargin - rightMargin; |
309 if (mAudioItem) { |
320 maxHeight = screenHeight - chromeHeight - toolbarHeight; |
310 mAudioItem->setStretched(true); |
321 } |
311 } |
322 if (mAudioItem) { |
312 } |
323 mAudioItem->setStretched(false); |
313 else if (mainWindow->orientation() == Qt::Vertical) { |
324 } |
314 maxWidth = screenWidth - leftMargin - rightMargin; |
325 } |
315 maxHeight = screenHeight - chromeHeight - toolbarHeight; |
326 |
316 |
327 if (mIconItem) { |
317 if (mAudioItem) { |
328 qreal imageWidth = mIconItem->icon().defaultSize().width(); |
318 mAudioItem->setStretched(false); |
329 qreal imageHeight = mIconItem->icon().defaultSize().height(); |
319 } |
330 |
320 } |
331 qreal widthToSet = 0.0; |
321 |
332 qreal heightToSet = 0.0; |
322 // Slide Counter |
333 |
323 QSizeF slideCounterSize(0, 0); |
334 if (imageWidth < iconSize) { |
324 if (mSlideCounter) { |
335 widthToSet = iconSize; |
325 slideCounterSize = mSlideCounter->effectiveSizeHint(which, constraint); |
336 heightToSet = iconSize; |
326 mSlideCounter->show(); |
337 } |
327 } |
338 else if (imageWidth <= maxWidth) { |
328 // Audio Item |
339 // resize not needed |
329 QSizeF audioSize(0, 0); |
340 widthToSet = imageWidth; |
330 if (mAudioItem) { |
341 heightToSet = qMin(imageHeight, maxHeight); |
331 audioSize = mAudioItem->effectiveSizeHint(which, constraint); |
342 } |
332 mAudioItem->show(); |
343 else { |
333 } |
344 // resize needed, keep aspect-ratio and resize |
334 |
345 widthToSet = maxWidth; |
335 // Text Item |
346 heightToSet = maxWidth * (imageHeight / imageWidth); |
336 QSizeF textSize(0, 0); |
347 heightToSet = qMin(heightToSet, maxHeight); |
337 if (mTextItem) { |
348 |
338 textSize = mTextItem->effectiveSizeHint(which, constraint); |
349 } |
339 mTextItem->show(); |
350 if (heightToSet == maxHeight) { |
340 } |
351 widthToSet = heightToSet * (imageWidth / imageHeight); |
341 |
352 } |
342 // Pixmap Item |
353 |
343 QSizeF pixmapSize(0, 0); |
354 mIconItem->setPreferredWidth(widthToSet); |
344 if (mPixmapItem) { |
355 mIconItem->setPreferredHeight(heightToSet); |
345 qreal imageWidth = mPixmapItem->icon().defaultSize().width(); |
356 } |
346 qreal imageHeight = mPixmapItem->icon().defaultSize().height(); |
357 } |
347 |
|
348 qreal widthToSet = 0.0; |
|
349 qreal heightToSet = 0.0; |
|
350 |
|
351 if (imageWidth < iconSize) { |
|
352 widthToSet = iconSize; |
|
353 heightToSet = iconSize; |
|
354 } |
|
355 else if (imageWidth <= maxWidth) { |
|
356 // resize not needed |
|
357 widthToSet = imageWidth; |
|
358 heightToSet = qMin(imageHeight, maxHeight); |
|
359 } |
|
360 else { |
|
361 // resize needed, keep aspect-ratio and resize |
|
362 widthToSet = maxWidth; |
|
363 heightToSet = maxWidth * (imageHeight / imageWidth); |
|
364 heightToSet = qMin(heightToSet, maxHeight); |
|
365 |
|
366 } |
|
367 if (heightToSet == maxHeight) { |
|
368 widthToSet = heightToSet * (imageWidth / imageHeight); |
|
369 } |
|
370 |
|
371 pixmapSize.setHeight(heightToSet); |
|
372 pixmapSize.setWidth(widthToSet); |
|
373 mPixmapItem->setPreferredSize(pixmapSize); |
|
374 mPixmapItem->show(); |
|
375 } |
|
376 |
|
377 // Calculate the size hint to be returned. |
|
378 szHint.setHeight(0); |
|
379 |
|
380 if (!slideCounterSize.isNull()) { |
|
381 szHint.rheight() += (slideCounterSize.height() + spacing); |
|
382 } |
|
383 if (!audioSize.isNull()) { |
|
384 szHint.rheight() += (audioSize.height() + spacing); |
|
385 } |
|
386 |
|
387 if (mainWindow->orientation() == Qt::Horizontal) { |
|
388 qreal remainingHeight = qMax(pixmapSize.height(), textSize.height()); |
|
389 if (remainingHeight > 0.0) { |
|
390 szHint.rheight() += (remainingHeight + spacing); |
|
391 } |
|
392 } |
|
393 else if (mainWindow->orientation() == Qt::Vertical) { |
|
394 if (!pixmapSize.isNull()) { |
|
395 szHint.rheight() += (pixmapSize.height() + spacing); |
|
396 } |
|
397 if (!textSize.isNull()) { |
|
398 szHint.rheight() += (textSize.height() + spacing); |
|
399 } |
|
400 } |
|
401 szHint.rheight() = qMax(maxHeight, szHint.height()); |
|
402 |
|
403 return szHint; |
358 } |
404 } |
359 |
405 |
360 //--------------------------------------------------------------- |
406 //--------------------------------------------------------------- |
361 //UniViewerBodyWidget::longPressed |
407 //UniViewerBodyWidget::longPressed |
362 // @see header file |
408 // @see header file |
363 //--------------------------------------------------------------- |
409 //--------------------------------------------------------------- |
364 void UniViewerBodyWidget::longPressed(QPointF position) |
410 void UniViewerBodyWidget::longPressed(QPointF position) |
365 { |
411 { |
366 |
412 |
367 HbMenu* menu = new HbMenu; |
413 HbMenu* menu = new HbMenu; |
368 menu->addAction(tr("Open"), this, SLOT(openMedia())); |
414 menu->setAttribute(Qt::WA_DeleteOnClose); |
369 menu->addAction(tr("View details"), this, SLOT(viewDetails())); |
415 menu->addAction(LOC_OPEN, this, SLOT(openMedia())); |
370 menu->exec(position); |
416 menu->addAction(LOC_SAVE, this, SLOT(saveMedia())); |
371 delete menu; |
417 menu->setPreferredPos(position); |
|
418 menu->show(); |
372 } |
419 } |
373 |
420 |
374 //--------------------------------------------------------------- |
421 //--------------------------------------------------------------- |
375 //UniViewerBodyWidget::openMedia |
422 //UniViewerBodyWidget::openMedia |
376 // @see header file |
423 // @see header file |