messagingapp/msgui/unifiedviewer/src/univiewerpixmapwidget.cpp
changeset 37 518b245aa84c
child 41 25fe1fe642e3
equal deleted inserted replaced
25:84d9eb65b26f 37:518b245aa84c
       
     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: This widget displays the pixmap content in viewer.
       
    15  *
       
    16  */
       
    17 
       
    18 #include "univiewerpixmapwidget.h"
       
    19 
       
    20 // SYSTEM INCLUDES
       
    21 #include <HbTapGesture>
       
    22 #include <HbWidget>
       
    23 #include <HbInstantFeedback>
       
    24 #include <HbMenu>
       
    25 #include <QPixmap>
       
    26 #include <QTimer>
       
    27 #include <thumbnailmanager_qt.h>
       
    28 
       
    29 // USER INCLUDES
       
    30 #include "univiewerutils.h"
       
    31 #include "unidatamodelplugininterface.h"
       
    32 
       
    33 // LOCAL CONSTANTS
       
    34 #define LOC_OPEN    hbTrId("txt_common_menu_open")
       
    35 #define LOC_SAVE    hbTrId("txt_common_menu_save")
       
    36 
       
    37 const QString PIXMAP_ICON("qtg_small_image");
       
    38 const QString CORRUPTED_PIXMAP_ICON("qtg_large_corrupted");
       
    39 const QString VIDEO_MIMETYPE("video");
       
    40 const QString MSG_VIDEO_ICON("qtg_small_video");
       
    41 
       
    42 //---------------------------------------------------------------
       
    43 // UniViewerPixmapWidget::UniViewerPixmapWidget
       
    44 // @see header file
       
    45 //---------------------------------------------------------------
       
    46 UniViewerPixmapWidget::UniViewerPixmapWidget(QGraphicsItem *parent) :
       
    47     HbIconItem(parent), mViewerUtils(0), mThumbnailManager(0)
       
    48 {
       
    49     this->grabGesture(Qt::TapGesture);
       
    50     init();
       
    51 }
       
    52 
       
    53 //---------------------------------------------------------------
       
    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
       
    71 // @see header file
       
    72 //---------------------------------------------------------------
       
    73 UniViewerPixmapWidget::~UniViewerPixmapWidget()
       
    74 {
       
    75 }
       
    76 
       
    77 //---------------------------------------------------------------
       
    78 // UniViewerPixmapWidget::setPixmap
       
    79 // @see header file
       
    80 //---------------------------------------------------------------
       
    81 void UniViewerPixmapWidget::populate(UniMessageInfo *info)
       
    82 {
       
    83     mMimeType = info->mimetype();
       
    84     mPixmapPath = info->path();
       
    85     if (mMimeType.contains(VIDEO_MIMETYPE)) {
       
    86         this->setIcon(MSG_VIDEO_ICON);
       
    87         mThumbnailManager->getThumbnail(mPixmapPath);
       
    88         this->ungrabGesture(Qt::TapGesture);
       
    89     }
       
    90     else if (info->isProtected()) {
       
    91         this->setIconName(PIXMAP_ICON);
       
    92     }
       
    93     else if (info->isCorrupted()) {
       
    94         this->setIconName(CORRUPTED_PIXMAP_ICON);
       
    95     }
       
    96     else {
       
    97         QPixmap pixmap(mPixmapPath);
       
    98         this->setIcon(HbIcon(pixmap));
       
    99     }
       
   100 }
       
   101 
       
   102 //---------------------------------------------------------------
       
   103 // UniViewerPixmapWidget::gestureEvent
       
   104 // @see header file
       
   105 //---------------------------------------------------------------
       
   106 void UniViewerPixmapWidget::gestureEvent(QGestureEvent *event)
       
   107 {
       
   108     HbTapGesture *tapGesture = qobject_cast<HbTapGesture*> (event->gesture(Qt::TapGesture));
       
   109     if (tapGesture) {
       
   110         switch (tapGesture->state()) {
       
   111         case Qt::GestureStarted:
       
   112         {
       
   113             // Trigger haptic feedback.
       
   114             HbInstantFeedback::play(HbFeedback::Basic);
       
   115             break;
       
   116         }
       
   117         case Qt::GestureUpdated:
       
   118         {
       
   119             if (HbTapGesture::TapAndHold == tapGesture->tapStyleHint()) {
       
   120                 // Handle longtap.
       
   121                 handleLongTap(tapGesture->scenePosition());
       
   122             }
       
   123             break;
       
   124         }
       
   125         case Qt::GestureFinished:
       
   126         {
       
   127             HbInstantFeedback::play(HbFeedback::Basic);
       
   128             if (HbTapGesture::Tap == tapGesture->tapStyleHint()) {
       
   129                 // Handle short tap
       
   130                 handleShortTap();
       
   131             }
       
   132             break;
       
   133         }
       
   134         case Qt::GestureCanceled:
       
   135         {
       
   136             HbInstantFeedback::play(HbFeedback::Basic);
       
   137             break;
       
   138         }
       
   139         }
       
   140     }
       
   141     else {
       
   142         HbIconItem::gestureEvent(event);
       
   143     }
       
   144 }
       
   145 
       
   146 //---------------------------------------------------------------
       
   147 // UniViewerPixmapWidget::handleOpen
       
   148 // @see header file
       
   149 //---------------------------------------------------------------
       
   150 void UniViewerPixmapWidget::handleOpen()
       
   151 {
       
   152     this->ungrabGesture(Qt::TapGesture);
       
   153 
       
   154     if (!mViewerUtils) {
       
   155         mViewerUtils = new UniViewerUtils(this);
       
   156     }
       
   157     mViewerUtils->launchContentViewer(mMimeType, mPixmapPath);
       
   158 
       
   159     //fire timer to regrab gesture after some delay.
       
   160     QTimer::singleShot(300,this,SLOT(regrabGesture()));
       
   161 }
       
   162 
       
   163 //---------------------------------------------------------------
       
   164 // UniViewerPixmapWidget::handleSave
       
   165 // @see header file
       
   166 //---------------------------------------------------------------
       
   167 void UniViewerPixmapWidget::handleSave()
       
   168 {
       
   169 }
       
   170 
       
   171 //----------------------------------------------------------------------------
       
   172 // UniViewerPixmapWidget::handleShortTap
       
   173 // @see header file
       
   174 //----------------------------------------------------------------------------
       
   175 void UniViewerPixmapWidget::handleShortTap()
       
   176 {
       
   177     emit shortTap(mPixmapPath);
       
   178 
       
   179     // Open the media.
       
   180     handleOpen();
       
   181 }
       
   182 
       
   183 //---------------------------------------------------------------
       
   184 // UniViewerPixmapWidget::handleLongTap
       
   185 // @see header file
       
   186 //---------------------------------------------------------------
       
   187 void UniViewerPixmapWidget::handleLongTap(const QPointF &position)
       
   188 {
       
   189     emit longTap(position);
       
   190 
       
   191     HbMenu* menu = new HbMenu;
       
   192     menu->setAttribute(Qt::WA_DeleteOnClose);
       
   193     menu->addAction(LOC_OPEN, this, SLOT(handleOpen()));
       
   194     menu->addAction(LOC_SAVE, this, SLOT(handleSave()));
       
   195     menu->setPreferredPos(position);
       
   196     menu->show();
       
   197 }
       
   198 
       
   199 //---------------------------------------------------------------
       
   200 // UniViewerPixmapWidget::regrabGesture
       
   201 // @see header file
       
   202 //---------------------------------------------------------------
       
   203 void UniViewerPixmapWidget::regrabGesture()
       
   204 {
       
   205     this->grabGesture(Qt::TapGesture);
       
   206 }
       
   207 
       
   208 //---------------------------------------------------------------
       
   209 // UniViewerPixmapWidget::thumbnailReady
       
   210 // @see header
       
   211 //---------------------------------------------------------------
       
   212 void UniViewerPixmapWidget::thumbnailReady(const QPixmap& pixmap, void *data, int id, int error)
       
   213 {
       
   214     Q_UNUSED(data)
       
   215     Q_UNUSED(id)
       
   216     this->grabGesture(Qt::TapGesture);
       
   217     if (!error) {
       
   218         this->setIcon(HbIcon(pixmap));
       
   219         this->hide();
       
   220         this->updateGeometry();
       
   221     }
       
   222 }
       
   223 // EOF