messagingapp/msgui/unifiededitor/src/msgunieditorattachment.cpp
branchGCC_SURGE
changeset 47 5b14749788d7
parent 27 e4592d119491
parent 43 35b64624a9e7
--- a/messagingapp/msgui/unifiededitor/src/msgunieditorattachment.cpp	Thu Jun 17 09:57:06 2010 +0100
+++ b/messagingapp/msgui/unifiededitor/src/msgunieditorattachment.cpp	Thu Jul 22 16:32:06 2010 +0100
@@ -25,15 +25,19 @@
 #include <HbMenu>
 #include <MsgMimeTypes.h>
 #include <HbFrameItem>
-//#include <HbGestureSceneFilter>
-//#include <HbGesture>
+#include <HbInstantFeedback>
+#include <HbTapGesture>
 #include <QGraphicsSceneMouseEvent>
 #include <HbWidgetFeedback>
+#include <HbEffect>
+#include <QTimer>
 
 // USER INCLUDES
+#include "msgcontactsutil.h"
 #include "msgunieditorattachment.h"
-#include "unieditorgenutils.h"
-#include "s60qconversions.h"
+#include "UniEditorGenUtils.h"
+#include <xqconversions.h>
+#include "msgunieditorutils.h"
 
 // Constants
 #define BYTES_TO_KBYTES_FACTOR 1024
@@ -57,63 +61,63 @@
 mSize(filesize),
 mAttachmentIcon(0),
 mAttachmentName(0),
-//mGestureFilter(0),
-mMaxSmsSize(KFirstNormalSmsLength)
+mMaxSmsSize(KFirstNormalSmsLength),
+mEditorUtils(0)
 {
-        //back ground
-        HbFrameItem* backGround = new HbFrameItem(this);
-        backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL);
-        backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
-        this->setBackgroundItem(backGround);        
+    this->grabGesture(Qt::TapGesture);
+    setProperty("state", "normal");
+    
+    //back ground
+    mBackGround = new HbFrameItem(this);
+    mBackGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL);
+    mBackGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
+    this->setBackgroundItem(mBackGround);        
 
-        mAttachmentIcon = new HbIconItem(ATTACHMENT_ICON, this);
-        HbStyle::setItemName(mAttachmentIcon,"attachmentIcon");
+    mAttachmentIcon = new HbIconItem(ATTACHMENT_ICON, this);
+    HbStyle::setItemName(mAttachmentIcon,"attachmentIcon");
 
-        int at_size = 0;
-        TMsgMediaType mediaType = EMsgMediaUnknown;
-        UniEditorGenUtils* genUtils = new UniEditorGenUtils;
-        TRAP_IGNORE(genUtils->getFileInfoL(mPath,at_size,
-                                           mMimeType,mediaType));
-        TRAP_IGNORE(mMaxSmsSize = genUtils->MaxSmsMsgSizeL()); 
-        delete genUtils;
-        QFileInfo fileinfo(attachmentpath);
-        QString filename = fileinfo.fileName();
-        mAttachmentName = new HbTextItem(filename,this);
-        HbStyle::setItemName(mAttachmentName,"attachmentName");
-        mAttachmentName->setElideMode(Qt::ElideRight);
-        
-        // for sms, pure size should be shown
-        // for mms, additional mimeheader size must be included
-        qreal displaySize = mSize;
-        if(!isMultimediaContent())
-        {
-            displaySize = fileinfo.size();
-        }
-        int sizeInKb = displaySize/BYTES_TO_KBYTES_FACTOR;
-        QString fileDetails;
-        // if size exceeds 1kb, then show kb or else only bytes
-        if(sizeInKb >= 1)
-        {
-            fileDetails = QString().append(QString("(%1 Kb)").arg(sizeInKb));
-        }
-        else
-        {
-            fileDetails = QString().append(QString("(%1 B)").arg(displaySize));
-        }
+    int at_size = 0;
+    TMsgMediaType mediaType = EMsgMediaUnknown;
+    UniEditorGenUtils* genUtils = new UniEditorGenUtils;
+    TRAP_IGNORE(genUtils->getFileInfoL(mPath,at_size,
+        mMimeType,mediaType));
+    TRAP_IGNORE(mMaxSmsSize = genUtils->MaxSmsMsgSizeL()); 
+    delete genUtils;
+    QFileInfo fileinfo(attachmentpath);
+    QString filename = fileinfo.fileName();
+    mAttachmentName = new HbTextItem(filename,this);
+    HbStyle::setItemName(mAttachmentName,"attachmentName");
+    mAttachmentName->setElideMode(Qt::ElideRight);
 
-        mAttachmentDetails = new HbTextItem(fileDetails, this);
-        HbStyle::setItemName(mAttachmentDetails,"attachmentDetails");
-        mAttachmentDetails->setElideMode(Qt::ElideNone);
-        
-        initGesture();
+    // for sms, pure size should be shown
+    // for mms, additional mimeheader size must be included
+    qreal displaySize = mSize;
+    if(!isMultimediaContent())
+    {
+        displaySize = fileinfo.size();
+    }
+    int sizeInKb = displaySize/BYTES_TO_KBYTES_FACTOR;
+    QString fileDetails;
+    // if size exceeds 1kb, then show kb or else only bytes
+    if(sizeInKb >= 1)
+    {
+        fileDetails = QString().append(QString("(%1 Kb)").arg(sizeInKb));
+    }
+    else
+    {
+        fileDetails = QString().append(QString("(%1 B)").arg(displaySize));
+    }
+
+    mAttachmentDetails = new HbTextItem(fileDetails, this);
+    HbStyle::setItemName(mAttachmentDetails,"attachmentDetails");
+    mAttachmentDetails->setElideMode(Qt::ElideNone);
+    
+    HbEffect::add("attachmentWidget", "listviewitem_press", "pressed");
+    HbEffect::add("attachmentWidget", "listviewitem_release", "released");
 }
 
 MsgUnifiedEditorAttachment::~MsgUnifiedEditorAttachment()
 {
-  /*  if(mGestureFilter)
-        {
-        removeSceneEventFilter(mGestureFilter);
-        }*/
 }
 
 const QString& MsgUnifiedEditorAttachment::path()
@@ -131,11 +135,11 @@
     return mMimeType;
 }
 
-void MsgUnifiedEditorAttachment::longPressed(QPointF position)
+void MsgUnifiedEditorAttachment::handleLongTap(QPointF position)
 {
     HbMenu* menu = new HbMenu;
-    menu->addAction(LOC_OPEN, this, SLOT(openAttachment()));
-    menu->addAction(LOC_REMOVE, this, SLOT(removeAttachment()));
+    menu->addAction(LOC_OPEN, this, SLOT(handleOpen()));
+    menu->addAction(LOC_REMOVE, this, SLOT(handleRemove()));
     menu->addAction(LOC_DETAILS, this, SLOT(viewDetails()));
     menu->setDismissPolicy(HbPopup::TapAnywhere);
     menu->setAttribute(Qt::WA_DeleteOnClose, true);
@@ -143,14 +147,25 @@
     menu->show();
 }
 
-void MsgUnifiedEditorAttachment::removeAttachment()
+void MsgUnifiedEditorAttachment::handleRemove()
 {
     emit deleteMe(this);
 }
 
-void MsgUnifiedEditorAttachment::openAttachment()
+void MsgUnifiedEditorAttachment::handleOpen()
 {
-    //open corresponding viewer app.
+    this->ungrabGesture(Qt::TapGesture);
+    
+    //open corresponding viewer app
+
+    if (!mEditorUtils) 
+    {
+        mEditorUtils = new MsgUnifiedEditorUtils(this);
+    }
+    mEditorUtils->launchContentViewer(mMimeType, mPath);
+    
+    //fire timer to regrab gesture after some delay.
+    QTimer::singleShot(300,this,SLOT(regrabGesture()));
 }
 
 void MsgUnifiedEditorAttachment::viewDetails()
@@ -161,9 +176,9 @@
 bool MsgUnifiedEditorAttachment::isMultimediaContent()
 {
     bool ret = true;
-    QString vcard = S60QConversions::s60Desc8ToQString(KMsgMimeVCard());
-    QString vcal = S60QConversions::s60Desc8ToQString(KMsgMimeVCal());
-    QString ical = S60QConversions::s60Desc8ToQString(KMsgMimeICal());
+    QString vcard = XQConversions::s60Desc8ToQString(KMsgMimeVCard());
+    QString vcal = XQConversions::s60Desc8ToQString(KMsgMimeVCal());
+    QString ical = XQConversions::s60Desc8ToQString(KMsgMimeICal());
     if( !QString::compare(mMimeType, vcard, Qt::CaseInsensitive) ||
         !QString::compare(mMimeType, vcal, Qt::CaseInsensitive) ||
         !QString::compare(mMimeType, ical, Qt::CaseInsensitive) )
@@ -181,61 +196,76 @@
     return ret;
 }
 
-void MsgUnifiedEditorAttachment::mousePressEvent(QGraphicsSceneMouseEvent *event)
-{    
-    HbWidgetFeedback::triggered(this, Hb::InstantPressed);
-    
-    HbFrameItem* backGround = new HbFrameItem(this);
-    backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_PRESSED);
-    backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
-    this->setBackgroundItem(backGround); 
-    
-    event->accept();
-}
-
-void MsgUnifiedEditorAttachment::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+void MsgUnifiedEditorAttachment::gestureEvent(QGestureEvent *event)
 {
-    HbFrameItem* backGround = new HbFrameItem(this);
-    backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL);
-    backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
-    this->setBackgroundItem(backGround);
-    
-    if(this->rect().contains(event->pos()))
+    HbTapGesture *tapGesture = qobject_cast<HbTapGesture*> (event->gesture(Qt::TapGesture));
+    if (tapGesture) {
+        switch (tapGesture->state()) {
+        case Qt::GestureStarted:
+        {
+            // Trigger haptic feedback.
+            HbInstantFeedback::play(HbFeedback::Basic);
+            setPressed(true);
+            break;
+        }
+        case Qt::GestureUpdated:
         {
-        HbWidgetFeedback::triggered(this, Hb::InstantClicked);
-        emit clicked();
+            if (HbTapGesture::TapAndHold == tapGesture->tapStyleHint()) {
+                // Handle longtap.
+                setPressed(false);
+                handleLongTap(tapGesture->scenePosition());
+            }
+            break;
         }
-    
-    event->accept();    
+        case Qt::GestureFinished:
+        {
+            HbInstantFeedback::play(HbFeedback::Basic);
+            if (HbTapGesture::Tap == tapGesture->tapStyleHint()) {
+                // Handle short tap.
+                setPressed(false);
+                handleShortTap();
+            }
+            break;
+        }
+        case Qt::GestureCanceled:
+        {
+            HbInstantFeedback::play(HbFeedback::Basic);
+            setPressed(false);
+            break;
+        }
+        }
+    }
+    else {
+        HbWidget::gestureEvent(event);
+    }
 }
 
-void MsgUnifiedEditorAttachment::initGesture()
+void MsgUnifiedEditorAttachment::handleShortTap()
 {
-    // Create gesture filter
- /*   mGestureFilter = new HbGestureSceneFilter( Qt::LeftButton, this );
-    
-    // Add gestures for longpress
-    HbGesture* gestureLongpressed = new HbGesture( HbGesture::longpress,5 );
-    
-    mGestureFilter->addGesture( gestureLongpressed );
-    
-    connect( gestureLongpressed, SIGNAL(longPress(QPointF)),
-             this, SLOT(longPressed(QPointF)) );
-
-    //install gesture filter.
-    this->installSceneEventFilter(mGestureFilter);*/
+    handleOpen();
 }
 
-/*HbFeedback::InstantEffect MsgUnifiedEditorAttachment::overrideFeedback(Hb::InstantInteraction interaction) const
-        {
-        switch(interaction)
-            {
-            case Hb::InstantPressed:
-            case Hb::InstantClicked:
-                return HbFeedback::Basic;
-            default:
-                return HbFeedback::None;
-            }
-        }*/
+void MsgUnifiedEditorAttachment::setPressed(bool pressed)
+{
+    if (pressed) 
+    {
+        setProperty("state", "pressed");
+        mBackGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_PRESSED);
+        HbEffect::cancel(mBackGround, "released");
+        HbEffect::start(mBackGround, "attachmentWidget", "pressed");
 
+    }
+    else 
+    {
+        setProperty("state", "normal");
+        mBackGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL);
+        HbEffect::cancel(mBackGround, "pressed");
+        HbEffect::start(mBackGround, "attachmentWidget", "released");
+    }    
+}
+
+void MsgUnifiedEditorAttachment::regrabGesture()
+{
+    this->grabGesture(Qt::TapGesture);
+}
 // EOF