ginebra2/ChromeView.cpp
changeset 0 1450b09d0cfd
child 3 0954f5dd2cd0
child 5 0f2326c2a325
equal deleted inserted replaced
-1:000000000000 0:1450b09d0cfd
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <QtGui>
       
    20 #include <QWebPage>
       
    21 
       
    22 #include "ChromeView.h"
       
    23 #include "ChromeWidget.h"
       
    24 #ifndef NO_QSTM_GESTURE
       
    25 #include "qstmgestureevent.h"
       
    26 #endif
       
    27 
       
    28 #ifdef Q_OS_SYMBIAN
       
    29 #ifdef SET_DEFAULT_IAP
       
    30 #include "sym_iap_util.h"
       
    31 #endif //SET_DEFAULT_IAP
       
    32 #endif //Q_OS_SYMBIAN
       
    33 
       
    34 namespace GVA {
       
    35 
       
    36 ChromeView::ChromeView(ChromeWidget * chrome, QWidget * parent)
       
    37   : QGraphicsView(chrome->scene(), parent),
       
    38     m_topWidget(chrome)
       
    39 {
       
    40   //setGeometry(chrome->geometry().toRect());
       
    41   setObjectName("ChromeView");
       
    42   //When content view is external widget, make the background transparent
       
    43   //setStyleSheet("QGraphicsView#ChromeView {margin:0; border: 0; padding:0; background:transparent}");
       
    44   setStyleSheet("QGraphicsView#ChromeView {margin:0; border: 0; padding:0; background:#fff}");
       
    45   setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
       
    46   setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
       
    47   //NB: maybe not needed?
       
    48   setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
       
    49   //installEventFilter(this);
       
    50   //chrome->page()->setView(this);
       
    51 #ifndef NO_QSTM_GESTURE
       
    52   ungrabGesture(Qt::PanGesture);
       
    53   ungrabGesture(Qt::TapGesture);
       
    54   ungrabGesture(Qt::TapAndHoldGesture);
       
    55   ungrabGesture(Qt::PinchGesture);
       
    56   ungrabGesture(Qt::SwipeGesture);
       
    57 #endif
       
    58 
       
    59 #ifdef Q_OS_SYMBIAN
       
    60 #ifdef SET_DEFAULT_IAP
       
    61     QTimer::singleShot(0, this, SLOT(setDefaultIap()));
       
    62   //setDefaultIap();
       
    63 #endif //SET_DEFAULT_IAP
       
    64 #endif //Q_OS_SYMBIAN
       
    65 }
       
    66   
       
    67 ChromeView::~ChromeView()
       
    68 {
       
    69 
       
    70 }
       
    71 
       
    72 void ChromeView::resizeEvent(QResizeEvent * ev)
       
    73 {
       
    74   //Resize the chrome to match the view and scene rectangle size
       
    75 
       
    76   if(m_topWidget)
       
    77      m_topWidget->setGeometry(0,0, ev->size().width(), ev->size().height());
       
    78   QGraphicsView::resizeEvent(ev);
       
    79 }
       
    80 
       
    81 //Never scroll the chrome
       
    82 //NB: this shouldn't be needed, but some events from
       
    83 //the chrome are causing scrolling. Need to track this
       
    84 //down further.
       
    85 
       
    86 void ChromeView::scrollContentsBy(int dx, int dy)
       
    87 {
       
    88   // qDebug() << "View scroll";
       
    89   //  QGraphicsView::scrollContentsBy(dx, dy);
       
    90 }
       
    91 
       
    92   //Eat key events not otherwise consumed.
       
    93   /*  bool ChromeView::eventFilter(QObject * obj, QEvent * ev)
       
    94   {
       
    95    if(ev->type() == QEvent::KeyPress){
       
    96    		int key = static_cast<QKeyEvent*>(ev)->key();
       
    97    		if(key == Qt::Key_Down || key == Qt::Key_Up || key ==Qt::Key_Left){
       
    98          return true;
       
    99        }
       
   100     }
       
   101     return QObject::eventFilter(obj,ev);
       
   102  
       
   103     }*/
       
   104   
       
   105 bool ChromeView::event(QEvent* event)
       
   106 {
       
   107 #ifndef NO_QSTM_GESTURE
       
   108 	  if (event->type() == QEvent::Gesture) {
       
   109 	      QStm_Gesture* gesture = getQStmGesture(event);
       
   110 	      if (gesture) {
       
   111 			  QPoint pos = mapFromGlobal(gesture->position());
       
   112 	    	  QGraphicsScene* gs = scene();
       
   113 			  QGraphicsItem* gi = gs->itemAt(QPointF(pos));
       
   114 
       
   115 			  if (gi) {
       
   116 			      gs->sendEvent(gi, event);
       
   117 			  }
       
   118 			  return true;
       
   119 	      }
       
   120 	  }	  
       
   121 #endif
       
   122 	return QGraphicsView::event(event);
       
   123 }
       
   124 
       
   125 #ifdef Q_OS_SYMBIAN
       
   126 #ifdef SET_DEFAULT_IAP
       
   127 void ChromeView::setDefaultIap()
       
   128 {
       
   129 #ifdef ENABLE_PERF_TRACE
       
   130     PERF_DEBUG() << "Setting up default IAP.\n";
       
   131 #endif
       
   132 
       
   133     qt_SetDefaultIap();
       
   134 }
       
   135 #endif // SET_DEFAULT_IAP
       
   136 #endif // Q_OS_SYMBIAN
       
   137 
       
   138 } // namespace GVA