ginebra2/ContentViews/WebContentViewWidget.cpp
changeset 6 1c3b8676e58c
child 9 b39122337a00
equal deleted inserted replaced
5:0f2326c2a325 6:1c3b8676e58c
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * This program is free software: you can redistribute it and/or modify
       
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
       
     8 *
       
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
       
    13 *
       
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not,
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
       
    19 *
       
    20 */
       
    21 
       
    22 #include "WebContentViewWidget.h"
       
    23 
       
    24 #include "ScrollableWebContentView.h"
       
    25 #include "WebContentAnimationItem.h"
       
    26 #include "webpagecontroller.h"
       
    27 #include "WebView.h"
       
    28 #include "wrtbrowsercontainer.h"
       
    29 #include "ZoomMetaData.h"
       
    30 
       
    31 #include <QGraphicsLinearLayout>
       
    32 #include <QStyleOptionGraphicsItem>
       
    33 #include <QWebFrame>
       
    34 
       
    35 namespace GVA {
       
    36 
       
    37 WebContentViewWidget::WebContentViewWidget(QObject* parent, QWebPage* page)
       
    38     : m_webViewportProxy(new WebContentAnimationItem())
       
    39 {
       
    40     setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true);
       
    41     setParent(parent);
       
    42 
       
    43     m_webViewport = new ScrollableWebContentView(m_webViewportProxy, this);
       
    44 
       
    45     m_webView = new WebView();
       
    46 
       
    47     if (page)
       
    48         setPage(page);
       
    49 
       
    50     m_webViewportProxy->setWebView(m_webView);
       
    51     updatePreferredContentSize();
       
    52     m_webViewportProxy->setPos(QPointF(0,0));
       
    53 
       
    54     //FIX ME : Should we have to delete layout??
       
    55     QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical, this);
       
    56     layout->setContentsMargins(0,0,0,0);
       
    57     layout->setSpacing(0.);
       
    58     layout->addItem(m_webViewport);
       
    59 
       
    60     connect(m_webViewportProxy
       
    61             , SIGNAL(updateZoomActions(bool,bool))
       
    62             , this
       
    63             , SIGNAL(updateZoomActions(bool,bool)));
       
    64     connect(m_webViewport
       
    65             , SIGNAL(contextEventObject(QWebHitTestResult*))
       
    66             , this
       
    67             , SIGNAL(contextEventObject(QWebHitTestResult*)));
       
    68 
       
    69     connect(m_webViewport
       
    70             , SIGNAL(viewScrolled(QPoint&, QPoint&))
       
    71             , this
       
    72             , SIGNAL(viewScrolled(QPoint&, QPoint&)));
       
    73 }
       
    74 
       
    75 WebContentViewWidget::~WebContentViewWidget()
       
    76 {
       
    77     delete m_webView;
       
    78     delete m_webViewportProxy;
       
    79     delete m_webViewport;
       
    80 }
       
    81 
       
    82 void WebContentViewWidget::resizeEvent(QGraphicsSceneResizeEvent* event)
       
    83 {
       
    84     QGraphicsWidget::resizeEvent(event);
       
    85 
       
    86     setGeometry(QRectF(pos(), size()));
       
    87     setPreferredSize(size());
       
    88 }
       
    89 
       
    90 QWebPage* WebContentViewWidget::page()
       
    91 {
       
    92     return m_webView->page();
       
    93 }
       
    94 
       
    95 void WebContentViewWidget::setPage(QWebPage* page)
       
    96 {
       
    97     m_webView->setPage(page);
       
    98 
       
    99     connect(this->page()->mainFrame(), SIGNAL(initialLayoutCompleted()), m_webViewport, SLOT(reset()));
       
   100     connect(this->page()->mainFrame(), SIGNAL(contentsSizeChanged(const QSize &)), m_webViewport, SLOT(contentsSizeChanged(const QSize&)));
       
   101     connect(this->page()->mainFrame(), SIGNAL(loadFinished(bool)), m_webViewport, SLOT(pageLoadFinished(bool)));
       
   102 }
       
   103 
       
   104 QGraphicsWebView* WebContentViewWidget::webView()
       
   105 {
       
   106     return m_webView;
       
   107 }
       
   108 
       
   109 ZoomMetaData WebContentViewWidget::currentPageInfo()
       
   110 {
       
   111     return m_webViewport->currentPageInfo();
       
   112 }
       
   113 
       
   114 void WebContentViewWidget::setCurrentPageInfo(ZoomMetaData data)
       
   115 {
       
   116     m_webViewport->setCurrentPageInfo(data);
       
   117 }
       
   118 
       
   119 ZoomMetaData WebContentViewWidget::defaultZoomData()
       
   120 {
       
   121     return m_webViewport->defaultZoomData();
       
   122 }
       
   123 
       
   124 void WebContentViewWidget::setPageZoom(bool zoomIn)
       
   125 {
       
   126     Q_ASSERT(m_webViewport);
       
   127     m_webViewport->zoomToScreenCenter(zoomIn);
       
   128 }
       
   129 
       
   130 void WebContentViewWidget::showPage(bool isSuperPage)
       
   131 {
       
   132     if (!isSuperPage) {
       
   133         WRT::WrtBrowserContainer* wbc = WebPageController::getSingleton()->currentPage();
       
   134         setPage((QWebPage*)wbc);  // static_cast here gives compiler error
       
   135     } else { 
       
   136         //Its a super page
       
   137         m_webViewport->setSuperPage();
       
   138     }
       
   139 }
       
   140 
       
   141 void WebContentViewWidget::updatePreferredContentSize()
       
   142 {
       
   143    m_webViewport->updatePreferredContentSize();
       
   144 }
       
   145 
       
   146 } // namespace GVA