browsercore/appfw/ThumbnailEngine/TnEngineView.cpp
branchGCC_SURGE
changeset 8 2e16851ffecd
parent 2 bf4420e9fa4d
parent 6 1c3b8676e58c
equal deleted inserted replaced
2:bf4420e9fa4d 8:2e16851ffecd
     1 /*
       
     2 * Copyright (c) 2009 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 <QPainter>
       
    20 #include <QPaintEvent>
       
    21 #include "TnEngineView.h"
       
    22 #include "TnEngineHandler.h"
       
    23 
       
    24 const int ScrollingDelta = 60;
       
    25 
       
    26 namespace WRT {
       
    27 
       
    28 TnEngineView::TnEngineView(QWidget* parent, TnEngineHandler* handler)
       
    29 : QWidget(parent), m_TnEngineHandler(handler)
       
    30 {
       
    31     //connect(this, SIGNAL(closeViewRequested()), WebController::webController()->wrtController(), SLOT(closeViewRequested()));
       
    32     //connect(this, SIGNAL(cancelViewRequested()), WebController::webController()->wrtController(), SLOT(cancelViewRequested()));
       
    33 }
       
    34 
       
    35 void TnEngineView::initview()
       
    36 {
       
    37     setGeometry(parentWidget()->rect());
       
    38     m_TnEngineHandler->setFullScreenMode(true);
       
    39     m_TnEngineHandler->setContainerRect(QRect(QPoint(0, 0), rect().size()));
       
    40     m_TnEngineHandler->setVisible(true);
       
    41     // ensure that system cursor is an arrow, not a random icon.
       
    42     // This is not an issue if the platform does not have a system cursor
       
    43     
       
    44     // FIXME: Cursor undef for symbian?
       
    45 #if !defined(Q_OS_SYMBIAN)
       
    46     setCursor(Qt::ArrowCursor);
       
    47 #endif
       
    48     setFocusPolicy(Qt::WheelFocus);
       
    49     setFocus(Qt::OtherFocusReason);
       
    50 }
       
    51 
       
    52 
       
    53 TnEngineView* TnEngineView::initiWithParentAndTnEngineHandler(QWidget* parent, TnEngineHandler* handler)
       
    54 {
       
    55     TnEngineView* that = new TnEngineView(parent, handler);
       
    56     that->initview();
       
    57     return that;
       
    58 }
       
    59 
       
    60 TnEngineView::~TnEngineView()
       
    61 {
       
    62     //m_TnEngineHandler->setVisible(false);
       
    63     //m_TnEngineHandler->setFullScreenMode(false);
       
    64 }
       
    65 
       
    66 void TnEngineView::paintEvent(QPaintEvent* e)
       
    67 {
       
    68     TnEngineView* that = const_cast<TnEngineView*>(this);
       
    69     QPainter painter(that);
       
    70     m_TnEngineHandler->setVisible(true);
       
    71     m_TnEngineHandler->draw(painter, e->rect());
       
    72 }
       
    73 
       
    74 void TnEngineView::keyPressEvent(QKeyEvent* ev)
       
    75 {
       
    76     if (    ev->key() == Qt::Key_Enter
       
    77          || ev->key() == Qt::Key_Return
       
    78          || ev->key() == Qt::Key_Select ) {
       
    79         emit ok();
       
    80         return;
       
    81     }
       
    82     if (ev->key() == Qt::Key_Escape) {
       
    83         emit cancel();
       
    84         return;
       
    85     }
       
    86     if (ev->key() == Qt::Key_Up || ev->key() == Qt::Key_Down || ev->key() == Qt::Key_Left || ev->key() == Qt::Key_Right) {
       
    87         int x = ScrollingDelta / 2, y = ScrollingDelta;
       
    88         switch (ev->key()) {
       
    89             case Qt::Key_Down:
       
    90                 x = 0;
       
    91                 break;
       
    92             case Qt::Key_Up:
       
    93                 x = 0;
       
    94                 y *= -1;
       
    95                 break;
       
    96             case Qt::Key_Left:
       
    97                 x *= -1;
       
    98                 y = 0;
       
    99                 break;
       
   100             case Qt::Key_Right:
       
   101                 y = 0;
       
   102                 break;
       
   103             }
       
   104         emit scrollBy(x, y);
       
   105     }
       
   106 }
       
   107 
       
   108 void TnEngineView::resizeEvent(QResizeEvent* event)
       
   109 {
       
   110     m_TnEngineHandler->setContainerRect(QRect(QPoint(0, 0), rect().size()));
       
   111 }
       
   112 
       
   113 void TnEngineView::mouseMoveEvent(QMouseEvent* e)
       
   114 {
       
   115     QRect indicatorRect = m_TnEngineHandler->indicatorRect();
       
   116     int zoomLevel = m_TnEngineHandler->zoomOutLevel();
       
   117     int xDelta = ((e->x() - indicatorRect.x() - indicatorRect.width() / 2) * zoomLevel ) / 100;
       
   118     int yDelta = ((e->y() - indicatorRect.y() - indicatorRect.height() / 2) * zoomLevel ) / 100;
       
   119     emit scrollBy(xDelta, yDelta);
       
   120     m_currPoint.setX(e->x());
       
   121     m_currPoint.setY(e->y());
       
   122 }
       
   123 
       
   124 void TnEngineView::mousePressEvent(QMouseEvent* e)
       
   125 {
       
   126     m_currPoint.setX(e->x());
       
   127     m_currPoint.setY(e->y());
       
   128 }
       
   129 
       
   130 void TnEngineView::mouseReleaseEvent(QMouseEvent* e)
       
   131 {
       
   132     m_currPoint.setX(e->x());
       
   133     m_currPoint.setY(e->y());
       
   134     emit ok();
       
   135 }
       
   136 
       
   137 }
       
   138