messagingapp/msgui/unifiedviewer/src/univiewerpixmapwidget.cpp
author hgs
Tue, 05 Oct 2010 13:58:47 +0530
changeset 73 ecf6a73a9186
parent 63 eceabb8c7a12
permissions -rw-r--r--
201039_03
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
 * All rights reserved.
hgs
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
 *
hgs
parents:
diff changeset
     9
 * Initial Contributors:
hgs
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
 *
hgs
parents:
diff changeset
    12
 * Contributors:
hgs
parents:
diff changeset
    13
 *
hgs
parents:
diff changeset
    14
 * Description: This widget displays the pixmap content in viewer.
hgs
parents:
diff changeset
    15
 *
hgs
parents:
diff changeset
    16
 */
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include "univiewerpixmapwidget.h"
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
// SYSTEM INCLUDES
hgs
parents:
diff changeset
    21
#include <HbTapGesture>
hgs
parents:
diff changeset
    22
#include <HbWidget>
hgs
parents:
diff changeset
    23
#include <HbInstantFeedback>
hgs
parents:
diff changeset
    24
#include <HbMenu>
hgs
parents:
diff changeset
    25
#include <QPixmap>
hgs
parents:
diff changeset
    26
#include <QTimer>
hgs
parents:
diff changeset
    27
#include <thumbnailmanager_qt.h>
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
// USER INCLUDES
73
ecf6a73a9186 201039_03
hgs
parents: 63
diff changeset
    30
#include "msgservicelaunchutil.h"
37
hgs
parents:
diff changeset
    31
#include "unidatamodelplugininterface.h"
hgs
parents:
diff changeset
    32
hgs
parents:
diff changeset
    33
// LOCAL CONSTANTS
hgs
parents:
diff changeset
    34
#define LOC_OPEN    hbTrId("txt_common_menu_open")
62
fdbe8253b596 201035_03
hgs
parents: 51
diff changeset
    35
37
hgs
parents:
diff changeset
    36
51
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    37
static const char PIXMAP_ICON[] = "qtg_small_image";
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    38
static const char CORRUPTED_PIXMAP_ICON[] = "qtg_large_corrupted";
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    39
static const char VIDEO_MIMETYPE[] = "video";
41
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
    40
51
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    41
static const int WIDTH_RATIO = 4;
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    42
static const int HEIGHT_RATIO = 3;
37
hgs
parents:
diff changeset
    43
hgs
parents:
diff changeset
    44
//---------------------------------------------------------------
hgs
parents:
diff changeset
    45
// UniViewerPixmapWidget::UniViewerPixmapWidget
hgs
parents:
diff changeset
    46
// @see header file
hgs
parents:
diff changeset
    47
//---------------------------------------------------------------
hgs
parents:
diff changeset
    48
UniViewerPixmapWidget::UniViewerPixmapWidget(QGraphicsItem *parent) :
51
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    49
    HbIconItem(parent), mInfo(0), mViewerUtils(0), mThumbnailManager(0)
37
hgs
parents:
diff changeset
    50
{
hgs
parents:
diff changeset
    51
    this->grabGesture(Qt::TapGesture);
hgs
parents:
diff changeset
    52
    init();
hgs
parents:
diff changeset
    53
}
hgs
parents:
diff changeset
    54
hgs
parents:
diff changeset
    55
//---------------------------------------------------------------
hgs
parents:
diff changeset
    56
// UniViewerPixmapWidget::~UniViewerPixmapWidget
hgs
parents:
diff changeset
    57
// @see header file
hgs
parents:
diff changeset
    58
//---------------------------------------------------------------
hgs
parents:
diff changeset
    59
UniViewerPixmapWidget::~UniViewerPixmapWidget()
hgs
parents:
diff changeset
    60
{
51
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    61
    if (mInfo) {
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    62
        delete mInfo;
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    63
        mInfo = NULL;
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    64
    }
37
hgs
parents:
diff changeset
    65
}
hgs
parents:
diff changeset
    66
hgs
parents:
diff changeset
    67
//---------------------------------------------------------------
51
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    68
// UniViewerPixmapWidget::populate
37
hgs
parents:
diff changeset
    69
// @see header file
hgs
parents:
diff changeset
    70
//---------------------------------------------------------------
hgs
parents:
diff changeset
    71
void UniViewerPixmapWidget::populate(UniMessageInfo *info)
hgs
parents:
diff changeset
    72
{
hgs
parents:
diff changeset
    73
    mMimeType = info->mimetype();
hgs
parents:
diff changeset
    74
    mPixmapPath = info->path();
51
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    75
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    76
    /**
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    77
     * Create a copy of info for video content.
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    78
     * mInfo will be deleted in the destructor.
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    79
     */
37
hgs
parents:
diff changeset
    80
    if (mMimeType.contains(VIDEO_MIMETYPE)) {
51
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    81
        mInfo = new UniMessageInfo(*info);
37
hgs
parents:
diff changeset
    82
    }
51
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    83
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    84
    if (info->isProtected()) {
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    85
        if (mMimeType.contains(VIDEO_MIMETYPE)) {
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    86
            emit thumbnailFound(false, mInfo);
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    87
        }
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    88
        else {
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    89
            this->setIconName(PIXMAP_ICON);
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    90
        }
37
hgs
parents:
diff changeset
    91
    }
hgs
parents:
diff changeset
    92
    else if (info->isCorrupted()) {
51
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    93
        if (mMimeType.contains(VIDEO_MIMETYPE)) {
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    94
            emit thumbnailFound(false, mInfo);
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    95
        }
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    96
        else {
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    97
            this->setIconName(CORRUPTED_PIXMAP_ICON);
3507212d340e 201031_02
hgs
parents: 41
diff changeset
    98
        }
37
hgs
parents:
diff changeset
    99
    }
hgs
parents:
diff changeset
   100
    else {
51
3507212d340e 201031_02
hgs
parents: 41
diff changeset
   101
        if (mMimeType.contains(VIDEO_MIMETYPE)) {
3507212d340e 201031_02
hgs
parents: 41
diff changeset
   102
            mThumbnailManager->getThumbnail(mPixmapPath);
3507212d340e 201031_02
hgs
parents: 41
diff changeset
   103
            this->ungrabGesture(Qt::TapGesture);
3507212d340e 201031_02
hgs
parents: 41
diff changeset
   104
        }
3507212d340e 201031_02
hgs
parents: 41
diff changeset
   105
        else {
3507212d340e 201031_02
hgs
parents: 41
diff changeset
   106
            QPixmap pixmap(mPixmapPath);
3507212d340e 201031_02
hgs
parents: 41
diff changeset
   107
            this->setIcon(HbIcon(pixmap));
3507212d340e 201031_02
hgs
parents: 41
diff changeset
   108
        }
37
hgs
parents:
diff changeset
   109
    }
hgs
parents:
diff changeset
   110
}
hgs
parents:
diff changeset
   111
hgs
parents:
diff changeset
   112
//---------------------------------------------------------------
hgs
parents:
diff changeset
   113
// UniViewerPixmapWidget::gestureEvent
hgs
parents:
diff changeset
   114
// @see header file
hgs
parents:
diff changeset
   115
//---------------------------------------------------------------
hgs
parents:
diff changeset
   116
void UniViewerPixmapWidget::gestureEvent(QGestureEvent *event)
hgs
parents:
diff changeset
   117
{
hgs
parents:
diff changeset
   118
    HbTapGesture *tapGesture = qobject_cast<HbTapGesture*> (event->gesture(Qt::TapGesture));
hgs
parents:
diff changeset
   119
    if (tapGesture) {
hgs
parents:
diff changeset
   120
        switch (tapGesture->state()) {
hgs
parents:
diff changeset
   121
        case Qt::GestureStarted:
hgs
parents:
diff changeset
   122
        {
hgs
parents:
diff changeset
   123
            // Trigger haptic feedback.
hgs
parents:
diff changeset
   124
            HbInstantFeedback::play(HbFeedback::Basic);
hgs
parents:
diff changeset
   125
            break;
hgs
parents:
diff changeset
   126
        }
hgs
parents:
diff changeset
   127
        case Qt::GestureUpdated:
hgs
parents:
diff changeset
   128
        {
hgs
parents:
diff changeset
   129
            if (HbTapGesture::TapAndHold == tapGesture->tapStyleHint()) {
hgs
parents:
diff changeset
   130
                // Handle longtap.
hgs
parents:
diff changeset
   131
                handleLongTap(tapGesture->scenePosition());
hgs
parents:
diff changeset
   132
            }
hgs
parents:
diff changeset
   133
            break;
hgs
parents:
diff changeset
   134
        }
hgs
parents:
diff changeset
   135
        case Qt::GestureFinished:
hgs
parents:
diff changeset
   136
        {
hgs
parents:
diff changeset
   137
            HbInstantFeedback::play(HbFeedback::Basic);
hgs
parents:
diff changeset
   138
            if (HbTapGesture::Tap == tapGesture->tapStyleHint()) {
hgs
parents:
diff changeset
   139
                // Handle short tap
hgs
parents:
diff changeset
   140
                handleShortTap();
hgs
parents:
diff changeset
   141
            }
hgs
parents:
diff changeset
   142
            break;
hgs
parents:
diff changeset
   143
        }
hgs
parents:
diff changeset
   144
        case Qt::GestureCanceled:
hgs
parents:
diff changeset
   145
        {
hgs
parents:
diff changeset
   146
            HbInstantFeedback::play(HbFeedback::Basic);
hgs
parents:
diff changeset
   147
            break;
hgs
parents:
diff changeset
   148
        }
hgs
parents:
diff changeset
   149
        }
hgs
parents:
diff changeset
   150
    }
hgs
parents:
diff changeset
   151
    else {
hgs
parents:
diff changeset
   152
        HbIconItem::gestureEvent(event);
hgs
parents:
diff changeset
   153
    }
hgs
parents:
diff changeset
   154
}
hgs
parents:
diff changeset
   155
hgs
parents:
diff changeset
   156
//---------------------------------------------------------------
hgs
parents:
diff changeset
   157
// UniViewerPixmapWidget::handleOpen
hgs
parents:
diff changeset
   158
// @see header file
hgs
parents:
diff changeset
   159
//---------------------------------------------------------------
hgs
parents:
diff changeset
   160
void UniViewerPixmapWidget::handleOpen()
hgs
parents:
diff changeset
   161
{
hgs
parents:
diff changeset
   162
    this->ungrabGesture(Qt::TapGesture);
hgs
parents:
diff changeset
   163
hgs
parents:
diff changeset
   164
    if (!mViewerUtils) {
73
ecf6a73a9186 201039_03
hgs
parents: 63
diff changeset
   165
        mViewerUtils = new MsgServiceLaunchUtil(this);
37
hgs
parents:
diff changeset
   166
    }
hgs
parents:
diff changeset
   167
    mViewerUtils->launchContentViewer(mMimeType, mPixmapPath);
hgs
parents:
diff changeset
   168
hgs
parents:
diff changeset
   169
    //fire timer to regrab gesture after some delay.
hgs
parents:
diff changeset
   170
    QTimer::singleShot(300,this,SLOT(regrabGesture()));
hgs
parents:
diff changeset
   171
}
hgs
parents:
diff changeset
   172
73
ecf6a73a9186 201039_03
hgs
parents: 63
diff changeset
   173
ecf6a73a9186 201039_03
hgs
parents: 63
diff changeset
   174
41
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   175
//---------------------------------------------------------------
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   176
// UniViewerPixmapWidget::regrabGesture
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   177
// @see header file
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   178
//---------------------------------------------------------------
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   179
void UniViewerPixmapWidget::regrabGesture()
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   180
{
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   181
    this->grabGesture(Qt::TapGesture);
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   182
}
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   183
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   184
//---------------------------------------------------------------
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   185
// UniViewerPixmapWidget::thumbnailReady
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   186
// @see header
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   187
//---------------------------------------------------------------
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   188
void UniViewerPixmapWidget::thumbnailReady(const QPixmap& pixmap, void *data, int id, int error)
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   189
{
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   190
    Q_UNUSED(data)
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   191
    Q_UNUSED(id)
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   192
    this->grabGesture(Qt::TapGesture);
51
3507212d340e 201031_02
hgs
parents: 41
diff changeset
   193
    if (error) {
3507212d340e 201031_02
hgs
parents: 41
diff changeset
   194
        emit thumbnailFound(false, mInfo);
3507212d340e 201031_02
hgs
parents: 41
diff changeset
   195
    }
3507212d340e 201031_02
hgs
parents: 41
diff changeset
   196
    else {
41
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   197
        this->setIcon(HbIcon(pixmap));
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   198
        this->hide();
51
3507212d340e 201031_02
hgs
parents: 41
diff changeset
   199
        emit thumbnailFound(true, NULL);
41
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   200
    }
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   201
}
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   202
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   203
//---------------------------------------------------------------
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   204
// UniViewerPixmapWidget::init
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   205
// @see header file
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   206
//---------------------------------------------------------------
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   207
void UniViewerPixmapWidget::init()
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   208
{
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   209
    mThumbnailManager = new ThumbnailManager(this);
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   210
    mThumbnailManager->setMode(ThumbnailManager::CropToAspectRatio);
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   211
    mThumbnailManager->setQualityPreference(ThumbnailManager::OptimizeForQuality);
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   212
    mThumbnailManager->setThumbnailSize(getThumbnailSize());
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   213
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   214
    connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void*, int, int)), this,
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   215
        SLOT(thumbnailReady(QPixmap, void*, int, int)));
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   216
}
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   217
37
hgs
parents:
diff changeset
   218
//----------------------------------------------------------------------------
hgs
parents:
diff changeset
   219
// UniViewerPixmapWidget::handleShortTap
hgs
parents:
diff changeset
   220
// @see header file
hgs
parents:
diff changeset
   221
//----------------------------------------------------------------------------
hgs
parents:
diff changeset
   222
void UniViewerPixmapWidget::handleShortTap()
hgs
parents:
diff changeset
   223
{
hgs
parents:
diff changeset
   224
    emit shortTap(mPixmapPath);
hgs
parents:
diff changeset
   225
hgs
parents:
diff changeset
   226
    // Open the media.
hgs
parents:
diff changeset
   227
    handleOpen();
hgs
parents:
diff changeset
   228
}
hgs
parents:
diff changeset
   229
hgs
parents:
diff changeset
   230
//---------------------------------------------------------------
hgs
parents:
diff changeset
   231
// UniViewerPixmapWidget::handleLongTap
hgs
parents:
diff changeset
   232
// @see header file
hgs
parents:
diff changeset
   233
//---------------------------------------------------------------
hgs
parents:
diff changeset
   234
void UniViewerPixmapWidget::handleLongTap(const QPointF &position)
hgs
parents:
diff changeset
   235
{
hgs
parents:
diff changeset
   236
    emit longTap(position);
hgs
parents:
diff changeset
   237
hgs
parents:
diff changeset
   238
    HbMenu* menu = new HbMenu;
hgs
parents:
diff changeset
   239
    menu->setAttribute(Qt::WA_DeleteOnClose);
hgs
parents:
diff changeset
   240
    menu->addAction(LOC_OPEN, this, SLOT(handleOpen()));
62
fdbe8253b596 201035_03
hgs
parents: 51
diff changeset
   241
    
37
hgs
parents:
diff changeset
   242
    menu->setPreferredPos(position);
hgs
parents:
diff changeset
   243
    menu->show();
hgs
parents:
diff changeset
   244
}
hgs
parents:
diff changeset
   245
hgs
parents:
diff changeset
   246
//---------------------------------------------------------------
41
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   247
// UniViewerPixmapWidget::getThumbnailSize
37
hgs
parents:
diff changeset
   248
// @see header file
hgs
parents:
diff changeset
   249
//---------------------------------------------------------------
41
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   250
QSize UniViewerPixmapWidget::getThumbnailSize()
37
hgs
parents:
diff changeset
   251
{
41
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   252
    QSize thumbnailSize(1, 1);
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   253
    HbWidget *parent = qobject_cast<HbWidget *>(this->parentWidget());
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   254
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   255
    if (parent) {
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   256
        qreal thumbnailWidth = 0.0;
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   257
        qreal thumbnailHeight = 0.0;
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   258
        parent->style()->parameter("hb-param-screen-short-edge", thumbnailWidth);
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   259
        thumbnailHeight = (thumbnailWidth * HEIGHT_RATIO) / WIDTH_RATIO;
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   260
        thumbnailSize.setHeight(qRound(thumbnailHeight));
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   261
        thumbnailSize.setWidth(qRound(thumbnailWidth));
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   262
    }
25fe1fe642e3 201027_02
hgs
parents: 37
diff changeset
   263
    return thumbnailSize;
37
hgs
parents:
diff changeset
   264
}
hgs
parents:
diff changeset
   265
hgs
parents:
diff changeset
   266
// EOF