emailuis/nmailui/src/nmviewerwebview.cpp
changeset 53 bf7eb7911fc5
parent 30 759dc5235cdb
child 47 f83bd4ae1fe3
child 54 997a02608b3a
equal deleted inserted replaced
30:759dc5235cdb 53:bf7eb7911fc5
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8  *
     9 * Initial Contributors:
     9  * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11 *
    11  *
    12 * Contributors:
    12  * Contributors:
    13 *
    13  *
    14 * Description:
    14  * Description:
    15 *
    15  *
    16 */
    16  */
    17 
    17 
    18 #include "nmuiheaders.h"
    18 #include "nmuiheaders.h"
    19 
    19 
    20 /*!
    20 /*!
    21     Constructor
    21     Constructor.
    22 */
    22 */
    23 NmMailViewerWK::NmMailViewerWK()
    23 NmMailViewerWK::NmMailViewerWK()
    24 	:QGraphicsWebView()
    24 : QGraphicsWebView()
    25 {
    25 {
    26     NM_FUNCTION;
    26     grabGesture(Qt::PinchGesture);
       
    27     installEventFilter(new NmEventFilterWK(this));
       
    28     setFlag(QGraphicsItem::ItemIsFocusable,false);
    27 }
    29 }
    28 
    30 
    29 /*!
    31 /*!
    30     Destructor
    32     Destructor.
    31 */
    33  */
    32 NmMailViewerWK::~NmMailViewerWK()
    34 NmMailViewerWK::~NmMailViewerWK()
    33 {
    35 {
    34     NM_FUNCTION;
       
    35     
       
    36     mContent.clear();
    36     mContent.clear();
    37 }
    37 }
    38 
    38 
    39 /*!
    39 /*!
    40 
    40     Sets the parent view.
    41 */
    41  */
    42 void NmMailViewerWK::setParentView(NmViewerView *parentView)
    42 void NmMailViewerWK::setParentView(NmViewerView *parentView)
    43 {
    43 {
    44     NM_FUNCTION;
       
    45     
       
    46     mParentView = parentView;
    44     mParentView = parentView;
    47 }
    45 }
    48 
    46 
    49 /*!
    47 /*!
    50     addContent. Function adds content into web view.
    48     Adds content into web view.
    51 */
    49  */
    52 void NmMailViewerWK::addContent(QString key, QVariant val, NmId partId, bool isFetched) 
    50 void NmMailViewerWK::addContent(QString key, QVariant val, NmId partId, bool isFetched) 
    53 {
    51 {
    54     NM_FUNCTION;
       
    55     
       
    56     mContent[key] = NmMailViewerWkContentItem(val, partId, isFetched);
    52     mContent[key] = NmMailViewerWkContentItem(val, partId, isFetched);
    57 }
    53 }
    58 
    54 
    59 /*!
    55 /*!
    60     loadResource. Function returns resource from added content (added with addContent)
    56     Returns resource from added content.
    61 */
    57  */
    62 QVariant NmMailViewerWK::loadResource(int type, const QUrl &name, NmId &partId, bool &isFetched)
    58 QVariant NmMailViewerWK::loadResource(int type, const QUrl &name, NmId &partId, bool &isFetched)
    63 {
    59 {
    64     NM_FUNCTION;
    60     NM_FUNCTION;
    65     
    61     
    66     if (type == QTextDocument::ImageResource) {
    62     if (type == QTextDocument::ImageResource) {
    77     }
    73     }
    78     return 0;
    74     return 0;
    79 }
    75 }
    80 
    76 
    81 /*!
    77 /*!
    82     sendMousePressEvent. Function is used to relay mouse event to base class
    78     Filter class' constructor.
    83 */
    79  */
    84 void NmMailViewerWK::sendMousePressEvent(QGraphicsSceneMouseEvent *event)
    80 NmEventFilterWK::NmEventFilterWK(QObject* parent)
       
    81 : QObject(parent)
    85 {
    82 {
    86     NM_FUNCTION;
    83 }
    87     
    84 
    88     if (event){
    85 /*
    89         QGraphicsWebView::mousePressEvent(event);
    86     Filters events if this object has been installed as an event filter.
       
    87  */
       
    88 bool NmEventFilterWK::eventFilter(QObject* object, QEvent* event) {
       
    89     Q_UNUSED(object);
       
    90     bool consumed = false;
       
    91     if (event) {
       
    92         switch (event->type()) {
       
    93         case QEvent::Gesture:
       
    94             consumed = gestureEvent(static_cast<QGestureEvent*>(event));
       
    95             break;
       
    96         case QEvent::GraphicsSceneMouseDoubleClick:
       
    97             // Handle double click (instant zoom).
       
    98             // At the moment we simply consume the event.
       
    99             event->accept();
       
   100             consumed = true;
       
   101             break;
       
   102         case QEvent::GraphicsSceneContextMenu:
       
   103         case QEvent::GraphicsSceneMouseMove:
       
   104             event->accept();
       
   105             consumed = true;
       
   106             break;
       
   107         default:
       
   108             break;
       
   109         }
    90     }
   110     }
       
   111     return consumed;
    91 }
   112 }
    92 
   113 
    93 /*!
   114 /*!
    94     sendMouseReleaseEvent. Function is used to relay mouse event to base class
   115     Handles gesture events. This function is invoked by the eventFilter()
    95 */
   116     function in case of gesture events.
    96 void NmMailViewerWK::sendMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   117  */
    97 {
   118 bool NmEventFilterWK::gestureEvent(QGestureEvent* event) {
    98     NM_FUNCTION;
   119     bool consumed = false;
    99     
       
   100     if (event) {
   120     if (event) {
   101         QGraphicsWebView::mouseReleaseEvent(event);
   121         if (QPinchGesture* pinch = static_cast<QPinchGesture*>(event->gesture(Qt::PinchGesture))) {
       
   122             // Handle pinch (zoom).
       
   123             // At the moment we simply consume the event.
       
   124             event->accept();
       
   125             consumed = true;
       
   126         }
   102     }
   127     }
       
   128     return consumed;
   103 }
   129 }
   104 
       
   105 
       
   106