emailuis/nmailui/src/nmviewerwebview.cpp
author hgs
Thu, 24 Jun 2010 14:32:18 +0300
changeset 47 f83bd4ae1fe3
parent 44 c2d07d913565
child 48 10eaf342f539
permissions -rw-r--r--
201025
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
44
hgs
parents: 43
diff changeset
     2
 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents: 43
diff changeset
     3
 * All rights reserved.
hgs
parents: 43
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents: 43
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents: 43
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents: 43
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents: 43
diff changeset
     8
 *
hgs
parents: 43
diff changeset
     9
 * Initial Contributors:
hgs
parents: 43
diff changeset
    10
 * Nokia Corporation - initial contribution.
hgs
parents: 43
diff changeset
    11
 *
hgs
parents: 43
diff changeset
    12
 * Contributors:
hgs
parents: 43
diff changeset
    13
 *
hgs
parents: 43
diff changeset
    14
 * Description:
hgs
parents: 43
diff changeset
    15
 *
hgs
parents: 43
diff changeset
    16
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
#include "nmuiheaders.h"
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
/*!
44
hgs
parents: 43
diff changeset
    21
    Constructor.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    22
*/
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
NmMailViewerWK::NmMailViewerWK()
47
hgs
parents: 44
diff changeset
    24
: QGraphicsWebView(),
hgs
parents: 44
diff changeset
    25
  mContent(),
hgs
parents: 44
diff changeset
    26
  mParentView(NULL),
hgs
parents: 44
diff changeset
    27
  mSuppressRelease(false)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    28
{
47
hgs
parents: 44
diff changeset
    29
    // Subscribe this widget to tap and pinch gestures.
hgs
parents: 44
diff changeset
    30
    grabGesture(Qt::TapGesture);
44
hgs
parents: 43
diff changeset
    31
    grabGesture(Qt::PinchGesture);
47
hgs
parents: 44
diff changeset
    32
    // Prevent this widget from accepting focus.
hgs
parents: 44
diff changeset
    33
    setFocusPolicy(Qt::NoFocus);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    34
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    35
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    36
/*!
44
hgs
parents: 43
diff changeset
    37
    Destructor.
hgs
parents: 43
diff changeset
    38
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
NmMailViewerWK::~NmMailViewerWK()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    40
{
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    41
    mContent.clear();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    42
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    43
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    44
/*!
44
hgs
parents: 43
diff changeset
    45
    Sets the parent view.
hgs
parents: 43
diff changeset
    46
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    47
void NmMailViewerWK::setParentView(NmViewerView *parentView)
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    48
{
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    49
    mParentView = parentView;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    50
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    51
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    52
/*!
44
hgs
parents: 43
diff changeset
    53
    Adds content into web view.
hgs
parents: 43
diff changeset
    54
 */
43
hgs
parents: 18
diff changeset
    55
void NmMailViewerWK::addContent(QString key, QVariant val, NmId partId, bool isFetched) 
hgs
parents: 18
diff changeset
    56
{
hgs
parents: 18
diff changeset
    57
    mContent[key] = NmMailViewerWkContentItem(val, partId, isFetched);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    58
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    59
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    60
/*!
44
hgs
parents: 43
diff changeset
    61
    Returns resource from added content.
hgs
parents: 43
diff changeset
    62
 */
43
hgs
parents: 18
diff changeset
    63
QVariant NmMailViewerWK::loadResource(int type, const QUrl &name, NmId &partId, bool &isFetched)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    64
{
43
hgs
parents: 18
diff changeset
    65
    NM_FUNCTION;
hgs
parents: 18
diff changeset
    66
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    67
    if (type == QTextDocument::ImageResource) {
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    68
        QString key = '<' + name.path() + '>';
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    69
        if (!mContent.contains(key)) {
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    70
            key = name.path();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    71
        }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    72
        if (mContent.contains(key)) {
43
hgs
parents: 18
diff changeset
    73
            partId = mContent[key].mPartId;
hgs
parents: 18
diff changeset
    74
            isFetched = mContent[key].mIsFetched;
hgs
parents: 18
diff changeset
    75
            return mContent[key].mData;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    76
        }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    77
        return 0;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    78
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    79
    return 0;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    80
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    81
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    82
/*!
47
hgs
parents: 44
diff changeset
    83
    This is the main event handler that processes all incoming events in an
hgs
parents: 44
diff changeset
    84
    appropriate manner.
44
hgs
parents: 43
diff changeset
    85
 */
47
hgs
parents: 44
diff changeset
    86
bool NmMailViewerWK::event(QEvent* event)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    87
{
44
hgs
parents: 43
diff changeset
    88
    bool consumed = false;
hgs
parents: 43
diff changeset
    89
    if (event) {
hgs
parents: 43
diff changeset
    90
        switch (event->type()) {
hgs
parents: 43
diff changeset
    91
        case QEvent::Gesture:
47
hgs
parents: 44
diff changeset
    92
            // Handle gesture events.
hgs
parents: 44
diff changeset
    93
            gestureEvent(static_cast<QGestureEvent*>(event));
hgs
parents: 44
diff changeset
    94
            consumed = event->isAccepted();
44
hgs
parents: 43
diff changeset
    95
            break;
hgs
parents: 43
diff changeset
    96
        case QEvent::GraphicsSceneContextMenu:
47
hgs
parents: 44
diff changeset
    97
            // Handle context-menu events.
hgs
parents: 44
diff changeset
    98
            // contextMenuEvent() is invoked directly in order to override
hgs
parents: 44
diff changeset
    99
            // text selection in QWebPage.
hgs
parents: 44
diff changeset
   100
            contextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent*>(event));
hgs
parents: 44
diff changeset
   101
            consumed = event->isAccepted();
44
hgs
parents: 43
diff changeset
   102
            break;
hgs
parents: 43
diff changeset
   103
        default:
47
hgs
parents: 44
diff changeset
   104
            // Invoke base class' event handler.
hgs
parents: 44
diff changeset
   105
            consumed = QGraphicsWebView::event(event);
44
hgs
parents: 43
diff changeset
   106
            break;
hgs
parents: 43
diff changeset
   107
        }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   108
    }
44
hgs
parents: 43
diff changeset
   109
    return consumed;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   110
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   111
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   112
/*!
47
hgs
parents: 44
diff changeset
   113
    Handles context-menu events.
hgs
parents: 44
diff changeset
   114
 */
hgs
parents: 44
diff changeset
   115
void NmMailViewerWK::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
hgs
parents: 44
diff changeset
   116
{
hgs
parents: 44
diff changeset
   117
    if (event) {
hgs
parents: 44
diff changeset
   118
        // Suppress context-menu invocations.
hgs
parents: 44
diff changeset
   119
        event->accept();
hgs
parents: 44
diff changeset
   120
    }
hgs
parents: 44
diff changeset
   121
}
hgs
parents: 44
diff changeset
   122
hgs
parents: 44
diff changeset
   123
/*!
hgs
parents: 44
diff changeset
   124
    Handles gesture events.
44
hgs
parents: 43
diff changeset
   125
 */
47
hgs
parents: 44
diff changeset
   126
void NmMailViewerWK::gestureEvent(QGestureEvent* event)
hgs
parents: 44
diff changeset
   127
{
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   128
    if (event) {
47
hgs
parents: 44
diff changeset
   129
        if (QTapGesture* tap = static_cast<QTapGesture*>(event->gesture(Qt::TapGesture))) {
hgs
parents: 44
diff changeset
   130
            switch (tap->state()) {
hgs
parents: 44
diff changeset
   131
            case Qt::GestureCanceled:
hgs
parents: 44
diff changeset
   132
                // Tap cancellation suppresses the following mouse release.
hgs
parents: 44
diff changeset
   133
                mSuppressRelease = true;
hgs
parents: 44
diff changeset
   134
                break;
hgs
parents: 44
diff changeset
   135
            default:
hgs
parents: 44
diff changeset
   136
                // Other states disclose the following mouse release.
hgs
parents: 44
diff changeset
   137
                mSuppressRelease = false;
hgs
parents: 44
diff changeset
   138
                break;
hgs
parents: 44
diff changeset
   139
            }
hgs
parents: 44
diff changeset
   140
            event->accept();
hgs
parents: 44
diff changeset
   141
        }
44
hgs
parents: 43
diff changeset
   142
        if (QPinchGesture* pinch = static_cast<QPinchGesture*>(event->gesture(Qt::PinchGesture))) {
hgs
parents: 43
diff changeset
   143
            // Handle pinch (zoom).
hgs
parents: 43
diff changeset
   144
            // At the moment we simply consume the event.
hgs
parents: 43
diff changeset
   145
            event->accept();
hgs
parents: 43
diff changeset
   146
        }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   147
    }
47
hgs
parents: 44
diff changeset
   148
}
hgs
parents: 44
diff changeset
   149
hgs
parents: 44
diff changeset
   150
/*!
hgs
parents: 44
diff changeset
   151
    Handles double-click events.
hgs
parents: 44
diff changeset
   152
 */
hgs
parents: 44
diff changeset
   153
void NmMailViewerWK::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
hgs
parents: 44
diff changeset
   154
{
hgs
parents: 44
diff changeset
   155
    if (event) {
hgs
parents: 44
diff changeset
   156
        // Handle double clicks (instant zoom).
hgs
parents: 44
diff changeset
   157
        // At the moment we simply consume the event.
hgs
parents: 44
diff changeset
   158
        event->accept();
hgs
parents: 44
diff changeset
   159
    }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   160
}
47
hgs
parents: 44
diff changeset
   161
hgs
parents: 44
diff changeset
   162
/*!
hgs
parents: 44
diff changeset
   163
    Handles mouse-move events.
hgs
parents: 44
diff changeset
   164
 */
hgs
parents: 44
diff changeset
   165
void NmMailViewerWK::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
hgs
parents: 44
diff changeset
   166
{
hgs
parents: 44
diff changeset
   167
    if (event) {
hgs
parents: 44
diff changeset
   168
        // Suppress drag selection.
hgs
parents: 44
diff changeset
   169
        event->accept();
hgs
parents: 44
diff changeset
   170
    }
hgs
parents: 44
diff changeset
   171
}
hgs
parents: 44
diff changeset
   172
hgs
parents: 44
diff changeset
   173
/*!
hgs
parents: 44
diff changeset
   174
    Handles mouse-release events.
hgs
parents: 44
diff changeset
   175
 */
hgs
parents: 44
diff changeset
   176
void NmMailViewerWK::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
hgs
parents: 44
diff changeset
   177
{
hgs
parents: 44
diff changeset
   178
    if (event) {
hgs
parents: 44
diff changeset
   179
        // Suppress mouse release if the previous tap was cancelled.
hgs
parents: 44
diff changeset
   180
        // Otherwise, invoke the base class' event handler.
hgs
parents: 44
diff changeset
   181
        if (mSuppressRelease) {
hgs
parents: 44
diff changeset
   182
            event->accept();
hgs
parents: 44
diff changeset
   183
        } else {
hgs
parents: 44
diff changeset
   184
            QGraphicsWebView::mouseReleaseEvent(event);
hgs
parents: 44
diff changeset
   185
        }
hgs
parents: 44
diff changeset
   186
    }
hgs
parents: 44
diff changeset
   187
}