diff -r 84d9eb65b26f -r 518b245aa84c messagingapp/msgui/unifiededitor/src/msgunieditorattachment.cpp --- a/messagingapp/msgui/unifiededitor/src/msgunieditorattachment.cpp Mon May 03 12:29:07 2010 +0300 +++ b/messagingapp/msgui/unifiededitor/src/msgunieditorattachment.cpp Fri Jun 25 15:47:40 2010 +0530 @@ -25,15 +25,19 @@ #include #include #include -#include -#include +#include +#include #include #include +#include +#include // USER INCLUDES +#include "msgcontactsutil.h" #include "msgunieditorattachment.h" -#include "unieditorgenutils.h" -#include "s60qconversions.h" +#include "UniEditorGenUtils.h" +#include +#include "msgunieditorutils.h" // Constants #define BYTES_TO_KBYTES_FACTOR 1024 @@ -49,82 +53,71 @@ const QString ATTACHMENT_ICON("qtg_small_attachment"); -MsgUnifiedEditorAttachment::MsgUnifiedEditorAttachment( const QString& pluginPath, - const QString& attachmentpath, +MsgUnifiedEditorAttachment::MsgUnifiedEditorAttachment( const QString& attachmentpath, const int filesize, QGraphicsItem *parent ) : HbWidget(parent), -mPluginPath(pluginPath), mPath(attachmentpath), mSize(filesize), -mMimeType(QString()), mAttachmentIcon(0), mAttachmentName(0), -mGestureFilter(0), -mMaxSmsSize(KFirstNormalSmsLength) +mMaxSmsSize(KFirstNormalSmsLength), +mEditorUtils(0) { -#ifdef _DEBUG_TRACES_ - qDebug() << "MsgUnifiedEditorAttachment calling HbStyle::registerPlugin"; -#endif + this->grabGesture(Qt::TapGesture); + setProperty("state", "normal"); - setPluginBaseId(style()->registerPlugin(mPluginPath)); - - //back ground - HbFrameItem* backGround = new HbFrameItem(this); - backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL); - backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); - this->setBackgroundItem(backGround); + //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() { - style()->unregisterPlugin(mPluginPath); - - if(mGestureFilter) - { - removeSceneEventFilter(mGestureFilter); - } } const QString& MsgUnifiedEditorAttachment::path() @@ -142,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); @@ -154,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() @@ -172,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) ) @@ -192,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 (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::NoOverride; - } - } +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