ginebra2/ChromeView.cpp
changeset 3 0954f5dd2cd0
parent 0 1450b09d0cfd
child 9 b39122337a00
--- a/ginebra2/ChromeView.cpp	Fri May 14 15:40:36 2010 +0300
+++ b/ginebra2/ChromeView.cpp	Tue Jun 29 00:46:29 2010 -0400
@@ -1,26 +1,30 @@
 /*
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation, version 2.1 of the License.
 *
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU Lesser General Public License for more details.
 *
-* Contributors:
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program.  If not,
+* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
 *
-* Description: 
+* Description:
 *
 */
 
-
 #include <QtGui>
 #include <QWebPage>
 
 #include "ChromeView.h"
-#include "ChromeWidget.h"
+#include "ChromeWidget.h" //TODO: get rid of this, refer directly to layout
+#include "ChromeLayout.h" 
 #ifndef NO_QSTM_GESTURE
 #include "qstmgestureevent.h"
 #endif
@@ -31,12 +35,28 @@
 #endif //SET_DEFAULT_IAP
 #endif //Q_OS_SYMBIAN
 
+#ifdef ENABLE_PERF_TRACE
+#include "wrtperftracer.h"
+#endif
+
 namespace GVA {
 
-ChromeView::ChromeView(ChromeWidget * chrome, QWidget * parent)
-  : QGraphicsView(chrome->scene(), parent),
-    m_topWidget(chrome)
+ChromeView::ChromeView(QGraphicsScene *graphicsScene, ChromeWidget * chrome, QWidget * parent)
+#ifdef ORBIT_UI
+  : HbMainWindow(parent),
+#else
+  : QGraphicsView(graphicsScene, parent),
+#endif // ORBIT_UI
+    m_chrome(chrome),
+    m_topWidget(chrome->layout())
 {
+#ifdef ORBIT_UI
+  addView(chrome->layout());
+#endif // ORRBIT_UI
+
+  // Initialize the ChromeWidget with the scene created in the ChromeView
+  chrome->layout()->setScene(scene());
+
   //setGeometry(chrome->geometry().toRect());
   setObjectName("ChromeView");
   //When content view is external widget, make the background transparent
@@ -44,6 +64,13 @@
   setStyleSheet("QGraphicsView#ChromeView {margin:0; border: 0; padding:0; background:#fff}");
   setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
   setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+#ifdef BEDROCK_TILED_BACKING_STORE
+  setFrameShape(QFrame::NoFrame);
+  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+  scene()->setItemIndexMethod(QGraphicsScene::NoIndex);
+#endif  
+	
   //NB: maybe not needed?
   setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
   //installEventFilter(this);
@@ -63,19 +90,33 @@
 #endif //SET_DEFAULT_IAP
 #endif //Q_OS_SYMBIAN
 }
-  
+
 ChromeView::~ChromeView()
 {
-
 }
 
 void ChromeView::resizeEvent(QResizeEvent * ev)
 {
-  //Resize the chrome to match the view and scene rectangle size
+    //Resize the chrome to match the view and scene rectangle size
+    if (m_topWidget) {
 
-  if(m_topWidget)
-     m_topWidget->setGeometry(0,0, ev->size().width(), ev->size().height());
-  QGraphicsView::resizeEvent(ev);
+      // On calling setGeometry on QGraphicsWidget, the layout resizes if
+      // first called before resize on children happens. In order to avoid painting
+      // the children in their old positions, first let children change size
+      // ChromeWidget * w = static_cast<ChromeWidget*>(m_topWidget);
+      // w->sizeChange(ev->size());
+      //TODO: move sizeChange to ChromeLayout, remove m_chrome member !!!!!
+      m_chrome->sizeChange(ev->size());
+      m_topWidget->setGeometry(0,0, ev->size().width(), ev->size().height());
+    }
+    QGraphicsView::resizeEvent(ev);
+	
+#ifdef BEDROCK_TILED_BACKING_STORE
+    if (scene()) {
+        QRectF rect(QPointF(0, 0), size());
+        scene()->setSceneRect(rect);
+    }
+#endif	
 }
 
 //Never scroll the chrome
@@ -85,6 +126,8 @@
 
 void ChromeView::scrollContentsBy(int dx, int dy)
 {
+    Q_UNUSED(dx)
+    Q_UNUSED(dy)
   // qDebug() << "View scroll";
   //  QGraphicsView::scrollContentsBy(dx, dy);
 }
@@ -92,34 +135,34 @@
   //Eat key events not otherwise consumed.
   /*  bool ChromeView::eventFilter(QObject * obj, QEvent * ev)
   {
-   if(ev->type() == QEvent::KeyPress){
-   		int key = static_cast<QKeyEvent*>(ev)->key();
-   		if(key == Qt::Key_Down || key == Qt::Key_Up || key ==Qt::Key_Left){
+   if (ev->type() == QEvent::KeyPress){
+        int key = static_cast<QKeyEvent*>(ev)->key();
+        if (key == Qt::Key_Down || key == Qt::Key_Up || key ==Qt::Key_Left){
          return true;
        }
     }
     return QObject::eventFilter(obj,ev);
- 
+
     }*/
-  
+
 bool ChromeView::event(QEvent* event)
 {
 #ifndef NO_QSTM_GESTURE
-	  if (event->type() == QEvent::Gesture) {
-	      QStm_Gesture* gesture = getQStmGesture(event);
-	      if (gesture) {
-			  QPoint pos = mapFromGlobal(gesture->position());
-	    	  QGraphicsScene* gs = scene();
-			  QGraphicsItem* gi = gs->itemAt(QPointF(pos));
+      if (event->type() == QEvent::Gesture) {
+          QStm_Gesture* gesture = getQStmGesture(event);
+          if (gesture) {
+              QPoint pos = mapFromGlobal(gesture->position());
+              QGraphicsScene* gs = scene();
+              QGraphicsItem* gi = gs->itemAt(QPointF(pos));
 
-			  if (gi) {
-			      gs->sendEvent(gi, event);
-			  }
-			  return true;
-	      }
-	  }	  
+              if (gi) {
+                  gs->sendEvent(gi, event);
+              }
+              return true;
+          }
+      }
 #endif
-	return QGraphicsView::event(event);
+    return QGraphicsView::event(event);
 }
 
 #ifdef Q_OS_SYMBIAN
@@ -135,4 +178,4 @@
 #endif // SET_DEFAULT_IAP
 #endif // Q_OS_SYMBIAN
 
-} // namespace GVA
\ No newline at end of file
+} // namespace GVA