userguide/src/BrowserWrapper.cpp
branchRCL_3
changeset 44 12f60d9a73b3
equal deleted inserted replaced
40:0d1adf67ec1b 44:12f60d9a73b3
       
     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 #include <QGraphicsScene>
       
    19 #include <QGraphicsProxyWidget>
       
    20 #include <QGraphicsLinearLayout>
       
    21 #include <QWebFrame>
       
    22 
       
    23 #include "HelpDocumentLoader.h"
       
    24 #include "HelpCommon.h"
       
    25 #include "BrowserWrapper.h"
       
    26 
       
    27 #ifdef Q_OS_SYMBIAN
       
    28 #include <wrtcontroller.h>
       
    29 #endif
       
    30 
       
    31 BrowserWrapper::BrowserWrapper()
       
    32 {
       
    33 }
       
    34 
       
    35 BrowserWrapper::~BrowserWrapper()
       
    36 {
       
    37 }
       
    38 
       
    39 void BrowserWrapper::init()
       
    40 {
       
    41 #ifdef Q_OS_SYMBIAN
       
    42     WRT::WrtController* wrtController = new WRT::WrtController(this, WRT::GraphicsWebView);
       
    43     mWebView = wrtController->graphicsWebView();
       
    44 #else
       
    45 	mWebView = new QGraphicsWebView();
       
    46 #endif
       
    47     mWebView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
       
    48     mWebView->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
       
    49     mWebView->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
       
    50 	mWebView->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
       
    51 	mWebView->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
       
    52     mWebView->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
       
    53     mWebView->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
       
    54     connect(mWebView, SIGNAL(linkClicked(const QUrl&)), this, SIGNAL(linkClicked(const QUrl&)));
       
    55     
       
    56     QGraphicsLinearLayout* vLayout = new QGraphicsLinearLayout(this);
       
    57     vLayout->setOrientation(Qt::Vertical);
       
    58     vLayout->addItem(mWebView);
       
    59     vLayout->setContentsMargins(0,0,0,0);
       
    60     setLayout(vLayout);
       
    61 }
       
    62 
       
    63 void BrowserWrapper::setHtml(const QString& html, const QUrl& url)
       
    64 {
       
    65     mWebView->setHtml(html, url);
       
    66 
       
    67     if(!mHistory.count() || mHistory.top()!=url)
       
    68     {
       
    69         mHistory.append(url);
       
    70     }
       
    71 }
       
    72 
       
    73 void BrowserWrapper::clearHistory()
       
    74 {
       
    75     mHistory.clear();
       
    76 }
       
    77 
       
    78 bool BrowserWrapper::canGoBack()
       
    79 {
       
    80     return (mHistory.count() > 1);
       
    81 }
       
    82 
       
    83 void BrowserWrapper::back()
       
    84 {
       
    85     if(canGoBack())
       
    86     {
       
    87         mHistory.pop();
       
    88         QUrl url = mHistory.top();
       
    89         emit urlChanged(url);
       
    90     }
       
    91 }
       
    92 
       
    93 
       
    94 // end of file
       
    95