2
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Symbian Foundation.
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the "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 |
* Symbian Foundation - Initial contribution
|
|
11 |
*
|
|
12 |
* Description:
|
|
13 |
* Implementation of the MyWebWidget class.
|
|
14 |
*/
|
|
15 |
|
|
16 |
#include <QtGui/QLineEdit>
|
|
17 |
#include <QtWebKit/QWebView>
|
|
18 |
#include <QtGui/QVBoxLayout>
|
|
19 |
#include <QtGui/QLabel>
|
|
20 |
#include <QtCore/QUrl>
|
|
21 |
#include <QtGui/QAction>
|
|
22 |
#include <QtWebKit/QWebHistory>
|
|
23 |
|
|
24 |
#include "mytoolbar.h" //added
|
|
25 |
#include "mywebwidget.h"
|
|
26 |
|
|
27 |
MyWebWidget::MyWebWidget(QWidget *parent)
|
|
28 |
: QWidget(parent)
|
|
29 |
{
|
|
30 |
m_softkeyAction = new QAction( tr("Options"), this );
|
|
31 |
m_softkeyAction->setSoftKeyRole(QAction::PositiveSoftKey);
|
|
32 |
addAction(m_softkeyAction);
|
|
33 |
|
|
34 |
m_lineEdit = new QLineEdit(this);
|
|
35 |
m_lineEdit->setStyleSheet("background-color:white; padding: 6px ; color:blue");
|
|
36 |
m_lineEdit->setText("Enter url ...");
|
|
37 |
|
|
38 |
m_view = new QWebView(this);
|
|
39 |
m_view->load(QUrl("http://blog.symbian.org"));
|
|
40 |
|
|
41 |
m_layout = new QVBoxLayout();
|
|
42 |
|
|
43 |
m_layout->addWidget(m_lineEdit);
|
|
44 |
m_layout->addWidget(m_view);
|
|
45 |
m_layout->insertSpacing(1,10);
|
|
46 |
|
|
47 |
//add toolbar
|
|
48 |
m_toolbar = new MyToolBar(this);
|
|
49 |
m_layout->addWidget(m_toolbar);
|
|
50 |
|
|
51 |
setLayout(m_layout);
|
|
52 |
m_layout->addStretch();
|
|
53 |
|
|
54 |
connect(m_lineEdit,SIGNAL(editingFinished()),SLOT(openUrl()));
|
|
55 |
connect(m_view,SIGNAL(loadFinished(bool)),SLOT(onLoadFinished(bool)));
|
|
56 |
|
|
57 |
//connect the toolbar as well
|
|
58 |
connect(m_toolbar,SIGNAL(goBack()),SLOT(loadPreviousPage()));
|
|
59 |
}
|
|
60 |
|
|
61 |
MyWebWidget::~MyWebWidget()
|
|
62 |
{
|
|
63 |
|
|
64 |
}
|
|
65 |
|
|
66 |
//added
|
|
67 |
void MyWebWidget::loadPreviousPage()
|
|
68 |
{
|
|
69 |
if(m_view->history()->canGoBack())
|
|
70 |
{
|
|
71 |
m_view->history()->back();
|
|
72 |
}
|
|
73 |
}
|
|
74 |
|
|
75 |
void MyWebWidget::openUrl()
|
|
76 |
{
|
|
77 |
QString url(m_lineEdit->text());
|
|
78 |
if(!url.contains("http://",Qt::CaseInsensitive))
|
|
79 |
url.prepend("http://");
|
|
80 |
m_view->load(QUrl(url));
|
|
81 |
|
|
82 |
}
|
|
83 |
|
|
84 |
void MyWebWidget::onLoadFinished(bool finished)
|
|
85 |
{
|
|
86 |
if(finished){
|
|
87 |
m_lineEdit->clear();
|
|
88 |
m_lineEdit->setText(tr("Enter url ..."));
|
|
89 |
}
|
|
90 |
}
|