Skip to content

Commit

Permalink
committing qtwebkit-examples files
Browse files Browse the repository at this point in the history
  • Loading branch information
RaymondMitchell-GG committed Jan 26, 2016
1 parent 49ebbe0 commit bcfc469
Show file tree
Hide file tree
Showing 65 changed files with 3,709 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
\example webkitqml/flickrview
\title Flickr View Example
\brief Demonstrates how to embed a web view in a Qt Quick application
\ingroup webkit-qmlexamples

The Flickr View Qt Quick example uses a \l{WebView} to browse the images
from the \l{http://flickr.com}{Flickr} public RSS feed.

\image flickrview-example.png

FlickrView is an example that retrieves the \l{http://www.flickr.com/services/feeds/docs/photos_public}{flickr.com RSS feed of public photos}
utilizing an \l{XmlListModel} and shows the thumbnails in a \l{ListView}.
When clicking on a thumbnail in the list at the bottom, the full size
image is loaded in a \l{WebView} using the corresponding Flickr link for it.
It is also possible to browse the profile of Flickr users in the WebView like in a
normal browser. This demonstrates how navigaton can be restricted to a specific
domain in the \c{onNavigationRequested} signal.
The feed can be updated using pull-to-refresh at the end of the thumbnail list.

This example uses the QtWebKit QML API that utilizes the WebKit2 split-process architecture.
*/
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
\example webkitqml/youtubeview
\title YouTube View Example
\brief Demonstrates how to embed a web view in a Qt Quick application
\ingroup webkit-qmlexamples

The YouTube View \l{Qt QML}{QML} example uses a \l{WebView} to play
\l{http://www.youtube.com/html5}{HTML5 video clips from YouTube}.

\image youtubeview-example.png

The application makes use of an \l{XmlListModel} to query the \l{https://developers.google.com/youtube}{YouTube API}
for HTML5 video clips and lists thumbnails of the clips in a \l{ListView} at the top. The \l{WebView} loads a local \c player.html file that
embeds a YouTube HTML5 video player using the \l{https://developers.google.com/youtube/iframe_api_reference}{IFrame player API},
which allows to control the YouTube player using JavaScript.

When clicking on a thumbnail, the corresponding clip is loaded in the WebView by passing the video ID as a query string to \c player.html.
When the video is started, the thumbnail list is hidden with an animated fade-out, when the video is stopped the list is showed again.
The specific states of the player change the title of the WebView using \e{document.title} in JavaScript. The application
is acting on these title changes in the \c{onTitleChanged} slot of the WebView item and thus switches between specific states.
By default the application loads a list of movie trailers.

When clicking on the button below the thumbnail list, the application switches to search mode, which allows to search for videos
using keywords. Additionally it is also possible to choose from a number of preset movie trailer streams.

\image youtubeview-example-preset.png

This example uses the QtWebKit QML API that utilizes the WebKit2 split-process architecture.
*/
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
\example webkitwidgets/browser
\title Tab Browser
\brief Demonstrates a complete web browsing experience
\ingroup webkit-widgetexamples

The Tab Browser example shows \l{Qt WebKit} module in action,
providing a little Web browser application with support for tabs.

\image browser-demo.png

This browser is the foundation for the \l{Arora Browser}, a simple cross-platform
Web browser.
*/
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
\example webkitwidgets/domtraversal
\title DOM Traversal Example
\brief Demonstrates how to traverse the DOM tree
\ingroup webkit-widgetexamples

\brief The DOM Traversal example shows how to use the QWebElement class to access
the structure of a Web page.

\image webkit-domtraversal.png

The QWebElement class provides an API that can be used to examine the structure
and content of a Web page via a Document Object Model (DOM) interface. It can be
used for basic traversal of the document structure, to search for particular
elements (see the \l{Simple Selector Example}), and to modify content in-place.

This example uses a QWebView widget to display the Web page, and a dock widget
holds the QTreeWidget that shows the document structure. These widgets are
placed in an instance of the \c Window class, which we describe below.

\section1 Window Class Definition

The \c Window class is derived from QMainWindow and its user interface is created
using \l{Qt Designer}. As a result, the class is also derived from the user
interface class created by \l uic:

\snippet webkitwidgets/domtraversal/window.h Window class definition

Two important functions to note are the \c on_webView_loadFinished() slot and
the \c examineChildElements() function. The former is automatically called
when the QWebView widget finishes loading a page. See the
\l{#Further Reading}{Further Reading} section for more information on this
mechanism.

The \c examineChildElements() function is used to traverse the document structure
and add items to the QTreeWidget.

\section1 Window Class Implementation

In the \c Window class constructor, we call the \l{QWidget::}{setupUi()} function
to set up the user interface described in the \c{window.ui} file:

\snippet webkitwidgets/domtraversal/window.cpp Window constructor

When the Web page is loaded, the \c on_webView_loadFinished() slot is called. Here,
we clear the tree widget and begin inspection of the document by obtaining the
document element from the page's main frame:

\snippet webkitwidgets/domtraversal/window.cpp begin document inspection

At this point, we call the \c examineChildElements() function to traverse the
document, starting with the child elements of the document element for which we
will create top level items in the tree widget.

The \c examineChildElements() function accepts a parent element and a parent item.
Starting with the first child element, which we obtain with the element's
\l{QWebElement::}{firstChild()} function, we examine each child element of the
parent item. For each valid (non-null) element, which we check by calling its
\l{QWebElement::}{isNull()} function, we create a new QTreeWidgetItem instance with
the element name and add it to the parent item.

\snippet webkitwidgets/domtraversal/window.cpp traverse document

We recursively examine the child elements for each element by calling
\c examineChildElements() with the current child element and the newly-created item.
To obtain the next element at the same level in the document, we call its
\l{QWebElement::}{nextSibling()} function.

This recursive approach to reading the document makes it easy to create a simple
representation of the document structure in a tree widget.

For completeness, we show the \c setUrl() function, which is provided to allow the
document URL to be set from the example's \c main() function.

\snippet webkitwidgets/domtraversal/window.cpp set URL

\section1 Starting the Example

We set up the application, create
a \c Window instance, set its URL, and show it:

\snippet webkitwidgets/domtraversal/main.cpp main program

When the application's event loop is run, the Qt home page will load, and the
tree widget will be updated to show the document structure. Navigating to another
page will cause the tree widget to be updated to show the document structure of
the new page.

\section1 Further Reading

The QWebElement documentation contains more information about DOM access for the
QtWebKit classes.

In this example, we take advantage of Qt's
\l{Using a Designer UI File in Your Application#Automatic Connections}{auto-connection}
feature to avoid explicitly connecting signals to slots. The user interface
contains a QWebView widget called \c webView whose \l{QWebView::}{loadFinished()}
signal is automatically connected to the \c on_webView_loadFinished() slot when
we call \l{QWidget::}{setupUi()} in the \c Window constructor.
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "AddressBar.h"

#include <QtCore>
#include <QtWidgets>

AddressBar::AddressBar(QWidget *parent)
: QWidget(parent)
{
m_lineEdit = new QLineEdit(parent);
m_lineEdit->setPlaceholderText("Enter address or search terms");
connect(m_lineEdit, SIGNAL(returnPressed()), SLOT(processAddress()));
m_toolButton = new QToolButton(parent);
m_toolButton->setText("Go");
connect(m_toolButton, SIGNAL(clicked()), SLOT(processAddress()));
}

QSize AddressBar::sizeHint() const
{
return m_lineEdit->sizeHint();
}

void AddressBar::processAddress()
{
if (!m_lineEdit->text().isEmpty())
emit addressEntered(m_lineEdit->text());
}

void AddressBar::resizeEvent(QResizeEvent *event)
{
int x, y, w, h;

m_toolButton->adjustSize();
x = width() - m_toolButton->width();
y = 0;
w = m_toolButton->width();
h = height() - 1;
m_toolButton->setGeometry(x, y, w, h);
m_toolButton->show();

x = 0;
y = 0;
w = width() - m_toolButton->width();
h = height() - 1;
m_lineEdit->setGeometry(x, y, w, h);
m_lineEdit->show();
}

void AddressBar::focusInEvent(QFocusEvent *event)
{
m_lineEdit->setFocus();
QWidget::focusInEvent(event);
}
Loading

0 comments on commit bcfc469

Please sign in to comment.