emailuis/nmailui/src/nmviewerwebview.cpp
author hgs
Tue, 29 Jun 2010 17:12:28 +0300
changeset 48 10eaf342f539
parent 47 f83bd4ae1fe3
child 57 ae34e1715e21
permissions -rw-r--r--
201025_1
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
 *
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    14
 * Description: NMailUI web viewer. Inherits from
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    15
 *              QGrapohicsWebView and handles gestures, etc.
44
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
  mSuppressRelease(false)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
{
47
hgs
parents: 44
diff changeset
    28
    // Subscribe this widget to tap and pinch gestures.
hgs
parents: 44
diff changeset
    29
    grabGesture(Qt::TapGesture);
44
hgs
parents: 43
diff changeset
    30
    grabGesture(Qt::PinchGesture);
47
hgs
parents: 44
diff changeset
    31
    // Prevent this widget from accepting focus.
hgs
parents: 44
diff changeset
    32
    setFocusPolicy(Qt::NoFocus);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    33
}
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
/*!
44
hgs
parents: 43
diff changeset
    36
    Destructor.
hgs
parents: 43
diff changeset
    37
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    38
NmMailViewerWK::~NmMailViewerWK()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
{
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    40
    mContent.clear();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    41
}
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
/*!
44
hgs
parents: 43
diff changeset
    44
    Adds content into web view.
hgs
parents: 43
diff changeset
    45
 */
43
hgs
parents: 18
diff changeset
    46
void NmMailViewerWK::addContent(QString key, QVariant val, NmId partId, bool isFetched) 
hgs
parents: 18
diff changeset
    47
{
hgs
parents: 18
diff changeset
    48
    mContent[key] = NmMailViewerWkContentItem(val, partId, isFetched);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    49
}
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
/*!
44
hgs
parents: 43
diff changeset
    52
    Returns resource from added content.
hgs
parents: 43
diff changeset
    53
 */
43
hgs
parents: 18
diff changeset
    54
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
    55
{
43
hgs
parents: 18
diff changeset
    56
    NM_FUNCTION;
hgs
parents: 18
diff changeset
    57
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    58
    if (type == QTextDocument::ImageResource) {
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    59
        QString key = '<' + name.path() + '>';
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    60
        if (!mContent.contains(key)) {
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    61
            key = name.path();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    62
        }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    63
        if (mContent.contains(key)) {
43
hgs
parents: 18
diff changeset
    64
            partId = mContent[key].mPartId;
hgs
parents: 18
diff changeset
    65
            isFetched = mContent[key].mIsFetched;
hgs
parents: 18
diff changeset
    66
            return mContent[key].mData;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    67
        }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    68
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    69
    return 0;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    70
}
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
/*!
47
hgs
parents: 44
diff changeset
    73
    This is the main event handler that processes all incoming events in an
hgs
parents: 44
diff changeset
    74
    appropriate manner.
44
hgs
parents: 43
diff changeset
    75
 */
47
hgs
parents: 44
diff changeset
    76
bool NmMailViewerWK::event(QEvent* event)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    77
{
44
hgs
parents: 43
diff changeset
    78
    bool consumed = false;
hgs
parents: 43
diff changeset
    79
    if (event) {
hgs
parents: 43
diff changeset
    80
        switch (event->type()) {
hgs
parents: 43
diff changeset
    81
        case QEvent::Gesture:
47
hgs
parents: 44
diff changeset
    82
            // Handle gesture events.
hgs
parents: 44
diff changeset
    83
            gestureEvent(static_cast<QGestureEvent*>(event));
hgs
parents: 44
diff changeset
    84
            consumed = event->isAccepted();
44
hgs
parents: 43
diff changeset
    85
            break;
hgs
parents: 43
diff changeset
    86
        case QEvent::GraphicsSceneContextMenu:
47
hgs
parents: 44
diff changeset
    87
            // Handle context-menu events.
hgs
parents: 44
diff changeset
    88
            // contextMenuEvent() is invoked directly in order to override
hgs
parents: 44
diff changeset
    89
            // text selection in QWebPage.
hgs
parents: 44
diff changeset
    90
            contextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent*>(event));
hgs
parents: 44
diff changeset
    91
            consumed = event->isAccepted();
44
hgs
parents: 43
diff changeset
    92
            break;
hgs
parents: 43
diff changeset
    93
        default:
47
hgs
parents: 44
diff changeset
    94
            // Invoke base class' event handler.
hgs
parents: 44
diff changeset
    95
            consumed = QGraphicsWebView::event(event);
44
hgs
parents: 43
diff changeset
    96
            break;
hgs
parents: 43
diff changeset
    97
        }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    98
    }
44
hgs
parents: 43
diff changeset
    99
    return consumed;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   100
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   101
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   102
/*!
47
hgs
parents: 44
diff changeset
   103
    Handles context-menu events.
hgs
parents: 44
diff changeset
   104
 */
hgs
parents: 44
diff changeset
   105
void NmMailViewerWK::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
hgs
parents: 44
diff changeset
   106
{
hgs
parents: 44
diff changeset
   107
    if (event) {
hgs
parents: 44
diff changeset
   108
        // Suppress context-menu invocations.
hgs
parents: 44
diff changeset
   109
        event->accept();
hgs
parents: 44
diff changeset
   110
    }
hgs
parents: 44
diff changeset
   111
}
hgs
parents: 44
diff changeset
   112
hgs
parents: 44
diff changeset
   113
/*!
hgs
parents: 44
diff changeset
   114
    Handles gesture events.
44
hgs
parents: 43
diff changeset
   115
 */
47
hgs
parents: 44
diff changeset
   116
void NmMailViewerWK::gestureEvent(QGestureEvent* event)
hgs
parents: 44
diff changeset
   117
{
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   118
    if (event) {
47
hgs
parents: 44
diff changeset
   119
        if (QTapGesture* tap = static_cast<QTapGesture*>(event->gesture(Qt::TapGesture))) {
hgs
parents: 44
diff changeset
   120
            switch (tap->state()) {
hgs
parents: 44
diff changeset
   121
            case Qt::GestureCanceled:
hgs
parents: 44
diff changeset
   122
                // Tap cancellation suppresses the following mouse release.
hgs
parents: 44
diff changeset
   123
                mSuppressRelease = true;
hgs
parents: 44
diff changeset
   124
                break;
hgs
parents: 44
diff changeset
   125
            default:
hgs
parents: 44
diff changeset
   126
                // Other states disclose the following mouse release.
hgs
parents: 44
diff changeset
   127
                mSuppressRelease = false;
hgs
parents: 44
diff changeset
   128
                break;
hgs
parents: 44
diff changeset
   129
            }
hgs
parents: 44
diff changeset
   130
            event->accept();
hgs
parents: 44
diff changeset
   131
        }
44
hgs
parents: 43
diff changeset
   132
        if (QPinchGesture* pinch = static_cast<QPinchGesture*>(event->gesture(Qt::PinchGesture))) {
hgs
parents: 43
diff changeset
   133
            // Handle pinch (zoom).
hgs
parents: 43
diff changeset
   134
            // At the moment we simply consume the event.
hgs
parents: 43
diff changeset
   135
            event->accept();
hgs
parents: 43
diff changeset
   136
        }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   137
    }
47
hgs
parents: 44
diff changeset
   138
}
hgs
parents: 44
diff changeset
   139
hgs
parents: 44
diff changeset
   140
/*!
hgs
parents: 44
diff changeset
   141
    Handles double-click events.
hgs
parents: 44
diff changeset
   142
 */
hgs
parents: 44
diff changeset
   143
void NmMailViewerWK::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
hgs
parents: 44
diff changeset
   144
{
hgs
parents: 44
diff changeset
   145
    if (event) {
hgs
parents: 44
diff changeset
   146
        // Handle double clicks (instant zoom).
hgs
parents: 44
diff changeset
   147
        // At the moment we simply consume the event.
hgs
parents: 44
diff changeset
   148
        event->accept();
hgs
parents: 44
diff changeset
   149
    }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   150
}
47
hgs
parents: 44
diff changeset
   151
hgs
parents: 44
diff changeset
   152
/*!
hgs
parents: 44
diff changeset
   153
    Handles mouse-move events.
hgs
parents: 44
diff changeset
   154
 */
hgs
parents: 44
diff changeset
   155
void NmMailViewerWK::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
hgs
parents: 44
diff changeset
   156
{
hgs
parents: 44
diff changeset
   157
    if (event) {
hgs
parents: 44
diff changeset
   158
        // Suppress drag selection.
hgs
parents: 44
diff changeset
   159
        event->accept();
hgs
parents: 44
diff changeset
   160
    }
hgs
parents: 44
diff changeset
   161
}
hgs
parents: 44
diff changeset
   162
hgs
parents: 44
diff changeset
   163
/*!
hgs
parents: 44
diff changeset
   164
    Handles mouse-release events.
hgs
parents: 44
diff changeset
   165
 */
hgs
parents: 44
diff changeset
   166
void NmMailViewerWK::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
hgs
parents: 44
diff changeset
   167
{
hgs
parents: 44
diff changeset
   168
    if (event) {
hgs
parents: 44
diff changeset
   169
        // Suppress mouse release if the previous tap was cancelled.
hgs
parents: 44
diff changeset
   170
        // Otherwise, invoke the base class' event handler.
hgs
parents: 44
diff changeset
   171
        if (mSuppressRelease) {
hgs
parents: 44
diff changeset
   172
            event->accept();
hgs
parents: 44
diff changeset
   173
        } else {
hgs
parents: 44
diff changeset
   174
            QGraphicsWebView::mouseReleaseEvent(event);
hgs
parents: 44
diff changeset
   175
        }
hgs
parents: 44
diff changeset
   176
    }
hgs
parents: 44
diff changeset
   177
}