summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2019-05-09 15:22:24 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-05-09 15:22:24 +0200
commit0eac492b5c66b1774118c387dd527ad419e51be7 (patch)
tree37324fdefd615e433dd65073390d7b9996d660d3 /examples
parent5d6086d1b97461b35c143839a8a6ba1b990bb87c (diff)
parent99d46a8a918dee7323bc3d4f1624c47c097f9a3a (diff)
Merge remote-tracking branch 'origin/5.13' into dev
Diffstat (limited to 'examples')
-rw-r--r--examples/webengine/customdialogs/doc/src/customdialogs.qdoc2
-rw-r--r--examples/webengine/customdialogs/main.cpp1
-rw-r--r--examples/webengine/minimal/doc/src/minimal.qdoc4
-rw-r--r--examples/webengine/quicknanobrowser/BrowserDialog.qml2
-rw-r--r--examples/webengine/quicknanobrowser/DownloadView.qml2
-rw-r--r--examples/webengine/quicknanobrowser/main.cpp5
-rw-r--r--examples/webengine/recipebrowser/doc/src/recipebrowser.qdoc20
-rw-r--r--examples/webenginewidgets/cookiebrowser/doc/src/cookiebrowser.qdoc2
-rw-r--r--examples/webenginewidgets/html2pdf/doc/src/html2pdf.qdoc6
-rw-r--r--examples/webenginewidgets/maps/doc/src/maps.qdoc2
-rw-r--r--examples/webenginewidgets/minimal/doc/src/minimal.qdoc4
-rw-r--r--examples/webenginewidgets/printme/data/data.qrc7
-rw-r--r--examples/webenginewidgets/printme/data/icon.svg24
-rw-r--r--examples/webenginewidgets/printme/data/index.html24
-rw-r--r--examples/webenginewidgets/printme/data/style.css72
-rw-r--r--examples/webenginewidgets/printme/doc/images/printme-example.pngbin0 -> 42074 bytes
-rw-r--r--examples/webenginewidgets/printme/doc/src/printme.qdoc98
-rw-r--r--examples/webenginewidgets/printme/main.cpp76
-rw-r--r--examples/webenginewidgets/printme/printhandler.cpp115
-rw-r--r--examples/webenginewidgets/printme/printhandler.h79
-rw-r--r--examples/webenginewidgets/printme/printme.pro9
-rw-r--r--examples/webenginewidgets/simplebrowser/browser.cpp13
-rw-r--r--examples/webenginewidgets/simplebrowser/browser.h2
-rw-r--r--examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc27
-rw-r--r--examples/webenginewidgets/spellchecker/doc/src/spellchecker.qdoc4
-rw-r--r--examples/webenginewidgets/spellchecker/main.cpp1
-rw-r--r--examples/webenginewidgets/videoplayer/doc/src/videoplayer.qdoc6
-rw-r--r--examples/webenginewidgets/webenginewidgets.pro7
-rw-r--r--examples/webenginewidgets/webui/doc/src/webui.qdoc6
29 files changed, 574 insertions, 46 deletions
diff --git a/examples/webengine/customdialogs/doc/src/customdialogs.qdoc b/examples/webengine/customdialogs/doc/src/customdialogs.qdoc
index 3fc888a77..5c550ed5e 100644
--- a/examples/webengine/customdialogs/doc/src/customdialogs.qdoc
+++ b/examples/webengine/customdialogs/doc/src/customdialogs.qdoc
@@ -29,7 +29,7 @@
\example webengine/customdialogs
\title WebEngine Qt Quick Custom Dialogs Example
\ingroup webengine-examples
- \brief Customizes UI elements of Qt WebEngine's dialogs.
+ \brief Customizes UI elements of \QWE's dialogs.
\image customdialogs.png
diff --git a/examples/webengine/customdialogs/main.cpp b/examples/webengine/customdialogs/main.cpp
index 35f39211d..82a3eca63 100644
--- a/examples/webengine/customdialogs/main.cpp
+++ b/examples/webengine/customdialogs/main.cpp
@@ -66,6 +66,7 @@ typedef QGuiApplication Application;
int main(int argc, char *argv[])
{
QCoreApplication::setOrganizationName("QtExamples");
+ QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
Application app(argc, argv);
QtWebEngine::initialize();
diff --git a/examples/webengine/minimal/doc/src/minimal.qdoc b/examples/webengine/minimal/doc/src/minimal.qdoc
index 8d12afc7c..4fc62bddb 100644
--- a/examples/webengine/minimal/doc/src/minimal.qdoc
+++ b/examples/webengine/minimal/doc/src/minimal.qdoc
@@ -29,7 +29,7 @@
\example webengine/minimal
\title WebEngine Qt Quick Minimal Example
\ingroup webengine-examples
- \brief Displays a web page using the Qt Quick integration of Qt WebEngine.
+ \brief Displays a web page using the Qt Quick integration of \QWE.
\image minimal-example.png
@@ -52,7 +52,7 @@
In the \c main function we first set the
\l{QCoreApplication::organizationName} property. This affects the locations
- where Qt WebEngine stores persistent and cached data (see also
+ where \QWE stores persistent and cached data (see also
\l{WebEngineProfile::cachePath} and
\l{WebEngineProfile::persistentStoragePath}).
diff --git a/examples/webengine/quicknanobrowser/BrowserDialog.qml b/examples/webengine/quicknanobrowser/BrowserDialog.qml
index 6b0b3acd6..a7ff9a55b 100644
--- a/examples/webengine/quicknanobrowser/BrowserDialog.qml
+++ b/examples/webengine/quicknanobrowser/BrowserDialog.qml
@@ -50,7 +50,7 @@
import QtQuick 2.1
import QtQuick.Window 2.2
-import QtWebEngine 1.7
+import QtWebEngine 1.9
Window {
id: window
diff --git a/examples/webengine/quicknanobrowser/DownloadView.qml b/examples/webengine/quicknanobrowser/DownloadView.qml
index ed28c761c..f6ebeab4a 100644
--- a/examples/webengine/quicknanobrowser/DownloadView.qml
+++ b/examples/webengine/quicknanobrowser/DownloadView.qml
@@ -51,7 +51,7 @@
import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Controls.Styles 1.0
-import QtWebEngine 1.2
+import QtWebEngine 1.9
import QtQuick.Layouts 1.0
Rectangle {
diff --git a/examples/webengine/quicknanobrowser/main.cpp b/examples/webengine/quicknanobrowser/main.cpp
index 18ba7b3e2..8d032f5d8 100644
--- a/examples/webengine/quicknanobrowser/main.cpp
+++ b/examples/webengine/quicknanobrowser/main.cpp
@@ -89,7 +89,10 @@ int main(int argc, char **argv)
Utils utils;
appEngine.rootContext()->setContextProperty("utils", &utils);
appEngine.load(QUrl("qrc:/ApplicationRoot.qml"));
- QMetaObject::invokeMethod(appEngine.rootObjects().first(), "load", Q_ARG(QVariant, startupUrl()));
+ if (!appEngine.rootObjects().isEmpty())
+ QMetaObject::invokeMethod(appEngine.rootObjects().first(), "load", Q_ARG(QVariant, startupUrl()));
+ else
+ qFatal("Failed to load sources");
return app.exec();
}
diff --git a/examples/webengine/recipebrowser/doc/src/recipebrowser.qdoc b/examples/webengine/recipebrowser/doc/src/recipebrowser.qdoc
index 0321c22e4..63a0af361 100644
--- a/examples/webengine/recipebrowser/doc/src/recipebrowser.qdoc
+++ b/examples/webengine/recipebrowser/doc/src/recipebrowser.qdoc
@@ -101,7 +101,7 @@
width.
\skipto WebEngineView
- \printuntil KeyNavigation.priority
+ \printuntil Layout.fillHeight
We then disable the \l{WebEngineSettings::focusOnNavigationEnabled}{focusOnNavigationEnabled}
setting to make sure that the \l{WebEngineView} does not steal focus from the \c RecipeList
@@ -110,19 +110,25 @@
ContextMenuRequest.
\skipto focusOnNavigationEnabled
- \printto firstLoadComplete
+ \printuntil }
When the application starts, instead of directly showing the \l{WebEngineView}, we show a
placeholder \l{Rectangle} with a \l{BusyIndicator} to provide a nicer user experience while the
- application is loading. Once the first page in the view is loaded, we start a \l{Timer} that
+ application is loading.
+
+ \printuntil }
+ \dots 12
+ \skipto Rectangle
+ \printuntil }
+
+ Once the first page in the view is loaded, we start a \l{Timer} that
will hide the placeholder and show the actual page. The delay provides more time for the recipe
images to load, so that when the view is shown, the page is completely rendered. The timer also
shows a help \l{ToolTip} that informs the user on how to navigate the recipes.
- \printuntil busy.running = true
- \printline }
- \printline }
- \printline }
+ \quotefromfile webengine/recipebrowser/resources/qml/main.qml
+ \skipto Timer {
+ \printuntil }
Let's see what the \c RecipeList item looks like from the inside. The root item is a
FocusScope to allow transferring focus to the child ListView whenever the root item receives
diff --git a/examples/webenginewidgets/cookiebrowser/doc/src/cookiebrowser.qdoc b/examples/webenginewidgets/cookiebrowser/doc/src/cookiebrowser.qdoc
index a1b4eeb18..316e11a9b 100644
--- a/examples/webenginewidgets/cookiebrowser/doc/src/cookiebrowser.qdoc
+++ b/examples/webenginewidgets/cookiebrowser/doc/src/cookiebrowser.qdoc
@@ -29,7 +29,7 @@
\example webenginewidgets/cookiebrowser
\title WebEngine Cookie Browser Example
\ingroup webengine-widgetexamples
- \brief A cookie browser based on Qt WebEngine Widgets.
+ \brief A cookie browser based on \QWE Widgets.
\image cookiebrowser.png
diff --git a/examples/webenginewidgets/html2pdf/doc/src/html2pdf.qdoc b/examples/webenginewidgets/html2pdf/doc/src/html2pdf.qdoc
index eea7f7c09..37fe3eb50 100644
--- a/examples/webenginewidgets/html2pdf/doc/src/html2pdf.qdoc
+++ b/examples/webenginewidgets/html2pdf/doc/src/html2pdf.qdoc
@@ -29,11 +29,11 @@
\example webenginewidgets/html2pdf
\title WebEngine Widgets Html2Pdf Example
\ingroup webengine-widgetexamples
- \brief Converts web pages to PDF documents using Qt WebEngine.
+ \brief Converts web pages to PDF documents using \QWE.
\image html2pdf-example.png
- \e {Html2Pdf} demonstrates how to use Qt WebEngine to implement a
+ \e {Html2Pdf} demonstrates how to use \QWE to implement a
command-line application for converting web pages into PDF documents.
\include examples-run.qdocinc
@@ -90,7 +90,7 @@
\skipto int main
\printuntil /^\}/
- Note that to use Qt WebEngine Widgets we need to create a \l QApplication
+ Note that to use \QWE Widgets we need to create a \l QApplication
and not a \l QCoreApplication, even though this is a command line
application.
*/
diff --git a/examples/webenginewidgets/maps/doc/src/maps.qdoc b/examples/webenginewidgets/maps/doc/src/maps.qdoc
index 5e4a5cd83..489a5a780 100644
--- a/examples/webenginewidgets/maps/doc/src/maps.qdoc
+++ b/examples/webenginewidgets/maps/doc/src/maps.qdoc
@@ -38,7 +38,7 @@
The \l {https://www.w3.org/TR/geolocation-API/}{Geolocation API} is a
JavaScript API that web applications can use to determine the user's
- physical location to show on a map, for example. As Qt WebEngine relies on
+ physical location to show on a map, for example. As \QWE relies on
\l {Qt Location} to power this API a viable location backend is needed for
the target platform.
diff --git a/examples/webenginewidgets/minimal/doc/src/minimal.qdoc b/examples/webenginewidgets/minimal/doc/src/minimal.qdoc
index d0b25c4b8..b04390d23 100644
--- a/examples/webenginewidgets/minimal/doc/src/minimal.qdoc
+++ b/examples/webenginewidgets/minimal/doc/src/minimal.qdoc
@@ -29,7 +29,7 @@
\example webenginewidgets/minimal
\title WebEngine Widgets Minimal Example
\ingroup webengine-widgetexamples
- \brief Displays a web page using Qt WebEngine Widgets.
+ \brief Displays a web page using \QWE Widgets.
\image minimal-example.png
@@ -53,7 +53,7 @@
In the \c main function we first set the
\l{QCoreApplication::organizationName} property. This affects the locations
- where Qt WebEngine stores persistent and cached data (see also
+ where \QWE stores persistent and cached data (see also
\l{QWebEngineProfile::cachePath} and
\l{QWebEngineProfile::persistentStoragePath}).
diff --git a/examples/webenginewidgets/printme/data/data.qrc b/examples/webenginewidgets/printme/data/data.qrc
new file mode 100644
index 000000000..a9c76cc7e
--- /dev/null
+++ b/examples/webenginewidgets/printme/data/data.qrc
@@ -0,0 +1,7 @@
+<RCC>
+ <qresource prefix="/">
+ <file>index.html</file>
+ <file>style.css</file>
+ <file>icon.svg</file>
+ </qresource>
+</RCC>
diff --git a/examples/webenginewidgets/printme/data/icon.svg b/examples/webenginewidgets/printme/data/icon.svg
new file mode 100644
index 000000000..b90ff26dd
--- /dev/null
+++ b/examples/webenginewidgets/printme/data/icon.svg
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 19.2.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
+<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+ width="94px" height="94px" viewBox="0 0 94 94" enable-background="new 0 0 94 94" xml:space="preserve">
+<g>
+ <circle fill="none" cx="47" cy="47" r="47"/>
+ <g>
+ <path fill="#46A2DA" d="M47,92.979c-11.779,0-23.559-4.484-32.526-13.451C-3.461,61.591-3.461,32.409,14.472,14.474
+ C32.41-3.463,61.592-3.461,79.526,14.473c17.935,17.936,17.935,47.119,0.002,65.054l-0.002,0.001
+ C70.559,88.495,58.779,92.979,47,92.979z"/>
+ </g>
+ <path fill="#80C342" d="M93,47C93,21.595,72.405,1,47,1C34.297,1,22.797,6.149,14.473,14.473l65.054,65.054
+ C87.851,71.203,93,59.703,93,47z"/>
+ <g>
+ <path fill="#46A2DA" d="M47,65c-4.808,0-9.328-1.873-12.728-5.272c-7.018-7.019-7.018-18.438,0-25.456
+ C37.672,30.873,42.192,29,47,29s9.328,1.873,12.728,5.272c7.018,7.019,7.018,18.438,0,25.456C56.328,63.127,51.808,65,47,65z"/>
+ <path fill="#FFFFFF" d="M62.248,59.919c6.671-7.858,6.312-19.644-1.105-27.061C57.237,28.953,52.118,27,47,27
+ c-5.118,0-10.237,1.953-14.142,5.858c-7.81,7.81-7.81,20.474,0,28.284C36.763,65.047,41.882,67,47,67
+ c4.379,0,8.752-1.441,12.372-4.3L77.88,81.209c0.989-0.895,1.935-1.837,2.843-2.814L62.248,59.919z M35.686,58.314
+ c-6.238-6.238-6.238-16.389,0-22.627C38.708,32.664,42.726,31,47,31c4.274,0,8.292,1.664,11.314,4.686
+ c6.238,6.238,6.238,16.389,0,22.627C55.292,61.336,51.274,63,47,63C42.726,63,38.708,61.336,35.686,58.314z"/>
+ </g>
+</g>
+</svg>
diff --git a/examples/webenginewidgets/printme/data/index.html b/examples/webenginewidgets/printme/data/index.html
new file mode 100644
index 000000000..cf286e85a
--- /dev/null
+++ b/examples/webenginewidgets/printme/data/index.html
@@ -0,0 +1,24 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <title>PrintMe</title>
+ <link rel="stylesheet" type="text/css" href="style.css">
+ <script>
+ function printNow() {
+ window.print();
+ }
+ </script>
+ </head>
+ <body>
+ <form class="form">
+ <img class="logo" src="icon.svg" alt="qtwebengine">
+ <div class="header">
+ <h1>Hello Paper World!</h1>
+ <h2>Press Ctrl+p to print with print preview</h2>
+ <h2>Press Ctrl+Shift+p to print without print preview</h2>
+ <h2>Click the button to print using JavaScript</h2>
+ <p class="button" onclick="printNow()">Print Now</p>
+ </form>
+ </body>
+</html>
diff --git a/examples/webenginewidgets/printme/data/style.css b/examples/webenginewidgets/printme/data/style.css
new file mode 100644
index 000000000..cf6a2b7bf
--- /dev/null
+++ b/examples/webenginewidgets/printme/data/style.css
@@ -0,0 +1,72 @@
+html,body {
+ height:100%;
+ width:100%;
+ margin:0;
+}
+ body {
+ display:flex;
+}
+ .logo {
+ width: 75px;
+ height: 75px;
+ float: left;
+ margin: 20px 20px 0px 20px;
+ -webkit-animation:spin 8s linear infinite;
+}
+ @-webkit-keyframes spin {
+ 100% {
+ -webkit-transform: rotate(360deg);
+ }
+}
+ .header {
+ display: inline
+}
+ .form {
+ width: 480px;
+ height: 170px;
+ background: -webkit-linear-gradient(bottom, #ddd, #fff);
+ border: 1px solid #999;
+ border-radius: 12px;
+ color: #46a;
+ font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif;
+ font-size: 14px;
+ font-style: italic;
+ font-weight: bold;
+ margin: auto;
+ padding: 10px;
+ position: relative;
+ line-height: 26px;
+ text-decoration: none;
+ -webkit-box-shadow: 0px 0px 5px #444;
+}
+ h1 {
+ padding-left:40px;
+ color: #46a2da;
+}
+ h2 {
+ color: #80c342;
+ font-size: 13px;
+ margin-top: -20px;
+}
+ span {
+ margin-left: 20px;
+}
+ .button{
+ display: inline-block;
+ background: #46a2da;
+ width: 100px;
+ height: 30px;
+ padding: 0px;
+ text-align: center;
+ font-weight: bold;
+ color: #ffffff;
+ text-decoration: none;
+ border: 1px solid #999;
+ margin-left: 190px;
+}
+ .button:hover {
+ background-color: #46a200
+}
+ .button:active {
+ background-color: #3e8e41;
+}
diff --git a/examples/webenginewidgets/printme/doc/images/printme-example.png b/examples/webenginewidgets/printme/doc/images/printme-example.png
new file mode 100644
index 000000000..a636972fd
--- /dev/null
+++ b/examples/webenginewidgets/printme/doc/images/printme-example.png
Binary files differ
diff --git a/examples/webenginewidgets/printme/doc/src/printme.qdoc b/examples/webenginewidgets/printme/doc/src/printme.qdoc
new file mode 100644
index 000000000..d05d5147b
--- /dev/null
+++ b/examples/webenginewidgets/printme/doc/src/printme.qdoc
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://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: https://www.gnu.org/licenses/fdl-1.3.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example webenginewidgets/printme
+ \title WebEngine Widgets PrintMe Example
+ \ingroup webengine-widgetexamples
+ \brief Demonstrates how to print web pages using Qt WebEngine Widgets.
+
+ \image printme-example.png
+
+ \e PrintMe demonstrates how to use the \l{QWebEnginePage} and
+ \l{QPrintDialog} classes to print a web page. Further, it shows how
+ to implement print preview by using the \l{QPrintPreviewDialog} class.
+ For completeness, it also illustrates how to trigger a printing request
+ within JavaScript.
+
+ \include examples-run.qdocinc
+
+ \section1 Simple HTML Page
+
+ In this example, we create an internal HTML page that is added as a resource
+ collection file (.qrc). The page shows only a small HTML message box that
+ explains how to trigger printing by using keyboard shortcuts or clicking a
+ button. The button has the JavaScript \c{onclick} event attribute that calls
+ the JavaScript \c{window.print()} function.
+
+ \quotefromfile webenginewidgets/printme/data/index.html
+ \skipto <html
+ \printuntil html>
+
+ \section1 Main Function
+
+ In the \c main function, we first instantiate a QWebEngineView and set the
+ URL to our internal HTML page. Next, we create a \c PrintHandler instance
+ and pass the requested page. For convenience, we also create keyboard
+ shortcuts that can be used to call a print dialog or print preview dialog.
+
+ \quotefromfile webenginewidgets/printme/main.cpp
+ \skipto QWebEngineView view
+ \printto return
+
+ \section1 Print Handler
+
+ In the \c{PrintHandler} function, we first implement \c{printPreview()},
+ where we instantiate \l{QPrinter} together with \l{QPrintPreviewDialog}.
+ We need the \l{QPrintPreviewDialog::paintRequested} handle to generate a
+ set of preview pages.
+
+ \quotefromfile webenginewidgets/printme/printhandler.cpp
+ \skipto PrintHandler::printPreview(
+ \printuntil /^\}/
+
+ Now we can implement the \c{PrintHandler::printDocument()} slot, which is
+ called in response to the \l{QPrintPreviewDialog::paintRequested} signal.
+
+ \quotefromfile webenginewidgets/printme/printhandler.cpp
+ \skipto PrintHandler::printDocument(
+ \printuntil /^\}/
+
+ To do actual painting on a printer, we call the \l{QWebEnginePage::print()}
+ function. Because this call blocks the main event loop, we need to create
+ a local one. We begin the local event loop by calling
+ \l{QEventLoop::exec()}. When the local event loop terminates,
+ we check for \c{result} and report any errors that occurred.
+
+ The last function we implement, \c{PrintHandler::print()}, is trivial,
+ because it simply opens \l{QPrintDialog} and calls the previously
+ implemented \c{PrintHandler::printDocument()}.
+
+ \quotefromfile webenginewidgets/printme/printhandler.cpp
+ \skipto PrintHandler::print(
+ \printuntil /^\}/
+*/
diff --git a/examples/webenginewidgets/printme/main.cpp b/examples/webenginewidgets/printme/main.cpp
new file mode 100644
index 000000000..e4d6d9dc8
--- /dev/null
+++ b/examples/webenginewidgets/printme/main.cpp
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "printhandler.h"
+#include <QApplication>
+#include <QShortcut>
+#include <QWebEngineView>
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+ QApplication app(argc, argv);
+
+ QWebEngineView view;
+ view.setUrl(QUrl(QStringLiteral("qrc:/index.html")));
+ view.resize(1024, 750);
+ view.show();
+
+ PrintHandler handler;
+ handler.setPage(view.page());
+
+ auto printPreviewShortCut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_P), &view);
+ auto printShortCut = new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_P), &view);
+
+ QObject::connect(printPreviewShortCut, &QShortcut::activated, &handler, &PrintHandler::printPreview);
+ QObject::connect(printShortCut, &QShortcut::activated, &handler, &PrintHandler::print);
+
+ return app.exec();
+}
diff --git a/examples/webenginewidgets/printme/printhandler.cpp b/examples/webenginewidgets/printme/printhandler.cpp
new file mode 100644
index 000000000..d8c4fc177
--- /dev/null
+++ b/examples/webenginewidgets/printme/printhandler.cpp
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "printhandler.h"
+#include <QEventLoop>
+#include <QPrintDialog>
+#include <QPrinter>
+#include <QPainter>
+#include <QPrintPreviewDialog>
+#include <QWebEnginePage>
+
+PrintHandler::PrintHandler(QObject *parent)
+ : QObject(parent)
+{
+
+}
+
+void PrintHandler::setPage(QWebEnginePage *page)
+{
+ Q_ASSERT(!m_page);
+ m_page = page;
+ connect(m_page, &QWebEnginePage::printRequested, this, &PrintHandler::printPreview);
+}
+
+void PrintHandler::print()
+{
+ QPrinter printer(QPrinter::HighResolution);
+ QPrintDialog dialog(&printer, m_page->view());
+ if (dialog.exec() != QDialog::Accepted)
+ return;
+ printDocument(&printer);
+}
+
+void PrintHandler::printDocument(QPrinter *printer)
+{
+ QEventLoop loop;
+ bool result;
+ auto printPreview = [&](bool success) { result = success; loop.quit(); };
+ m_page->print(printer, std::move(printPreview));
+ loop.exec();
+ if (!result) {
+ QPainter painter;
+ if (painter.begin(printer)) {
+ QFont font = painter.font();
+ font.setPixelSize(20);
+ painter.setFont(font);
+ painter.drawText(QPointF(10,25),
+ QStringLiteral("Could not generate print preview."));
+
+ painter.end();
+ }
+ }
+}
+
+void PrintHandler::printPreview()
+{
+ if (!m_page)
+ return;
+ if (m_inPrintPreview)
+ return;
+ m_inPrintPreview = true;
+ QPrinter printer;
+ QPrintPreviewDialog preview(&printer, m_page->view());
+ connect(&preview, &QPrintPreviewDialog::paintRequested,
+ this, &PrintHandler::printDocument);
+ preview.exec();
+ m_inPrintPreview = false;
+}
diff --git a/examples/webenginewidgets/printme/printhandler.h b/examples/webenginewidgets/printme/printhandler.h
new file mode 100644
index 000000000..69b71f4a8
--- /dev/null
+++ b/examples/webenginewidgets/printme/printhandler.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PRINTHANDLER_H
+#define PRINTHANDLER_H
+
+#include <QObject>
+
+QT_BEGIN_NAMESPACE
+class QPainter;
+class QPrinter;
+class QWebEnginePage;
+QT_END_NAMESPACE
+
+class PrintHandler : public QObject
+{
+ Q_OBJECT
+public:
+ PrintHandler(QObject *parent = nullptr);
+ void setPage(QWebEnginePage *page);
+
+public slots:
+ void print();
+ void printPreview();
+ void printDocument(QPrinter *printer);
+
+private:
+ QWebEnginePage *m_page = nullptr;
+ bool m_inPrintPreview = false;
+};
+
+#endif // PRINTHANDLER_H
diff --git a/examples/webenginewidgets/printme/printme.pro b/examples/webenginewidgets/printme/printme.pro
new file mode 100644
index 000000000..15b3959d5
--- /dev/null
+++ b/examples/webenginewidgets/printme/printme.pro
@@ -0,0 +1,9 @@
+QT += webenginewidgets printsupport
+
+HEADERS = printhandler.h
+SOURCES = main.cpp \
+ printhandler.cpp
+RESOURCES = data/data.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/webenginewidgets/printme
+INSTALLS += target
diff --git a/examples/webenginewidgets/simplebrowser/browser.cpp b/examples/webenginewidgets/simplebrowser/browser.cpp
index 5c6dbd35e..68458b2a4 100644
--- a/examples/webenginewidgets/simplebrowser/browser.cpp
+++ b/examples/webenginewidgets/simplebrowser/browser.cpp
@@ -51,8 +51,6 @@
#include "browser.h"
#include "browserwindow.h"
-#include <QWebEngineProfile>
-
Browser::Browser()
{
// Quit application if the download manager window is the only remaining window
@@ -61,14 +59,17 @@ Browser::Browser()
QObject::connect(
QWebEngineProfile::defaultProfile(), &QWebEngineProfile::downloadRequested,
&m_downloadManagerWidget, &DownloadManagerWidget::downloadRequested);
- QObject::connect(
- &m_otrProfile, &QWebEngineProfile::downloadRequested,
- &m_downloadManagerWidget, &DownloadManagerWidget::downloadRequested);
}
BrowserWindow *Browser::createWindow(bool offTheRecord)
{
- auto profile = offTheRecord ? &m_otrProfile : QWebEngineProfile::defaultProfile();
+ if (offTheRecord && !m_otrProfile) {
+ m_otrProfile.reset(new QWebEngineProfile);
+ QObject::connect(
+ m_otrProfile.get(), &QWebEngineProfile::downloadRequested,
+ &m_downloadManagerWidget, &DownloadManagerWidget::downloadRequested);
+ }
+ auto profile = offTheRecord ? m_otrProfile.get() : QWebEngineProfile::defaultProfile();
auto mainWindow = new BrowserWindow(this, profile, false);
m_windows.append(mainWindow);
QObject::connect(mainWindow, &QObject::destroyed, [this, mainWindow]() {
diff --git a/examples/webenginewidgets/simplebrowser/browser.h b/examples/webenginewidgets/simplebrowser/browser.h
index fbc8465d2..4c17121df 100644
--- a/examples/webenginewidgets/simplebrowser/browser.h
+++ b/examples/webenginewidgets/simplebrowser/browser.h
@@ -73,6 +73,6 @@ public:
private:
QVector<BrowserWindow*> m_windows;
DownloadManagerWidget m_downloadManagerWidget;
- QWebEngineProfile m_otrProfile;
+ QScopedPointer<QWebEngineProfile> m_otrProfile;
};
#endif // BROWSER_H
diff --git a/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc b/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc
index b0c426232..251ca5ad8 100644
--- a/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc
+++ b/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc
@@ -29,7 +29,7 @@
\example webenginewidgets/simplebrowser
\title WebEngine Widgets Simple Browser Example
\ingroup webengine-widgetexamples
- \brief A simple browser based on Qt WebEngine Widgets.
+ \brief A simple browser based on \QWE Widgets.
\image simplebrowser.png
@@ -267,10 +267,10 @@
Alternatively we could implement private browsing on the tab-level, with
some tabs in a window in normal mode, others in private mode.
- Implementing private browsing is quite easy using Qt WebEngine. All one has
+ Implementing private browsing is quite easy using \QWE. All one has
to do is to create a new \l{QWebEngineProfile} and use it in the
\l{QWebEnginePage} instead of the default profile. In the example this new
- profile is created and owned by the \c Browser object:
+ profile is owned by the \c Browser object:
\quotefromfile webenginewidgets/simplebrowser/browser.h
\skipto /^class Browser$/
@@ -285,15 +285,24 @@
\printline m_otrProfile
\printline /^\};$/
- The default constructor for \l{QWebEngineProfile} already puts it in
- \e{off-the-record} mode. All that is left to do is to pass the appropriate
- profile down to the appropriate \l QWebEnginePage objects. The \c Browser
- object will hand to each new \c BrowserWindow either the global default
- profile (see \l{QWebEngineProfile::defaultProfile}) or its own
- off-the-record profile:
+ Required profile for \e{private browsing} is created together with its
+ first window. The default constructor for \l{QWebEngineProfile} already
+ puts it in \e{off-the-record} mode.
\quotefromfile webenginewidgets/simplebrowser/browser.cpp
+
\skipto Browser::createWindow
+ \printuntil m_otrProfile.reset
+ \dots
+
+ All that is left to do is to pass the appropriate profile down to the
+ appropriate \l QWebEnginePage objects. The \c Browser object will hand to
+ each new \c BrowserWindow either the global default profile
+ (see \l{QWebEngineProfile::defaultProfile}) or one shared
+ \e{off-the-record} profile instance:
+
+ \dots
+ \skipto m_otrProfile.get
\printuntil mainWindow = new BrowserWindow
\skipto return mainWindow
\printuntil /^\}/
diff --git a/examples/webenginewidgets/spellchecker/doc/src/spellchecker.qdoc b/examples/webenginewidgets/spellchecker/doc/src/spellchecker.qdoc
index ff7b43a1b..ecdb1c818 100644
--- a/examples/webenginewidgets/spellchecker/doc/src/spellchecker.qdoc
+++ b/examples/webenginewidgets/spellchecker/doc/src/spellchecker.qdoc
@@ -41,7 +41,7 @@
\section1 Dictionaries
To be able to check the spelling, we need to provide the spellchecker with
- dictionaries. The Qt WebEngine spellchecker supports dictionaries provided by the
+ dictionaries. The \QWE spellchecker supports dictionaries provided by the
\l {Hunspell project} on all platforms and native dictionaries provided by macOS.
In this example, we want to support the English and German languages.
@@ -102,7 +102,7 @@
the actual language display name. We will use that mapping to display names
of dictionaries in the context menu. Spellchecking is disabled by default.
Therefore we also enable spellchecker and set the \e English dictionary.
- When Qt WebEngine's spellcheck service initializes, it will try to load the
+ When \QWE's spellcheck service initializes, it will try to load the
\c bdict dictionaries and to check them for consistency.
Any errors are logged by using the qWarning() function.
diff --git a/examples/webenginewidgets/spellchecker/main.cpp b/examples/webenginewidgets/spellchecker/main.cpp
index c2951fe00..bf056ea9e 100644
--- a/examples/webenginewidgets/spellchecker/main.cpp
+++ b/examples/webenginewidgets/spellchecker/main.cpp
@@ -54,6 +54,7 @@
int main(int argc, char *argv[])
{
QCoreApplication::setOrganizationName("QtExamples");
+ QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
WebView view;
diff --git a/examples/webenginewidgets/videoplayer/doc/src/videoplayer.qdoc b/examples/webenginewidgets/videoplayer/doc/src/videoplayer.qdoc
index 9f6add6ae..5c455345b 100644
--- a/examples/webenginewidgets/videoplayer/doc/src/videoplayer.qdoc
+++ b/examples/webenginewidgets/videoplayer/doc/src/videoplayer.qdoc
@@ -40,8 +40,8 @@
cross-browser Javascript API that enables a web page to request that one of
its HTML elements be made to occupy the user's entire screen. It is
commonly used for full screen video playback via the \c <video> element, but
- can in principle be used to display any HTML content in full screen mode. Qt
- WebEngine supports this API, however it is disabled by default. This example
+ can in principle be used to display any HTML content in full screen mode.
+ \QWE supports this API, however it is disabled by default. This example
shows the steps needed to switch it on, including:
\list
@@ -94,7 +94,7 @@
\skipto MainWindow::MainWindow
\printuntil setCentralWidget
- We then configure Qt WebEngine to advertise support for the Fullscreen API:
+ We then configure \QWE to advertise support for the Fullscreen API:
\printline QWebEngineSettings
diff --git a/examples/webenginewidgets/webenginewidgets.pro b/examples/webenginewidgets/webenginewidgets.pro
index 20c7ead50..0d47aac80 100644
--- a/examples/webenginewidgets/webenginewidgets.pro
+++ b/examples/webenginewidgets/webenginewidgets.pro
@@ -1,5 +1,5 @@
include($$QTWEBENGINE_OUT_ROOT/src/core/qtwebenginecore-config.pri) # workaround for QTBUG-68093
-QT_FOR_CONFIG += webenginecore
+QT_FOR_CONFIG += webenginecore webenginecore-private
TEMPLATE=subdirs
@@ -7,7 +7,6 @@ SUBDIRS += \
minimal \
contentmanipulation \
cookiebrowser \
- html2pdf \
simplebrowser \
stylesheetbrowser \
videoplayer \
@@ -16,6 +15,10 @@ SUBDIRS += \
qtConfig(webengine-geolocation): SUBDIRS += maps
qtConfig(webengine-webchannel): SUBDIRS += markdowneditor
+qtConfig(webengine-printing-and-pdf) {
+ SUBDIRS += printme html2pdf
+}
+
qtConfig(webengine-spellchecker):!qtConfig(webengine-native-spellchecker):!cross_compile {
SUBDIRS += spellchecker
} else {
diff --git a/examples/webenginewidgets/webui/doc/src/webui.qdoc b/examples/webenginewidgets/webui/doc/src/webui.qdoc
index 47d9fbad1..949b358a7 100644
--- a/examples/webenginewidgets/webui/doc/src/webui.qdoc
+++ b/examples/webenginewidgets/webui/doc/src/webui.qdoc
@@ -35,8 +35,8 @@
\e {WebUI} demonstrates how to implement a custom scheme in a secure way.
- Aside from the built-in URL schemes, such as \c {http} and \c {qrc}, Qt
- WebEngine may be extended with \e {custom schemes} by creating \e {custom
+ Aside from the built-in URL schemes, such as \c {http} and \c {qrc},
+ \QWE may be extended with \e {custom schemes} by creating \e {custom
scheme handlers}. This example shows:
\list
@@ -111,7 +111,7 @@
made already at the top of the \c {main} function. This is so because custom
schemes need to be registered as early as possible so that that they can be
passed to all subprocesses. Specifically, custom schemes need to be registered
- before any other Qt WebEngine classes are instantiated by the application.
+ before any other \QWE classes are instantiated by the application.
\section1 Handling Requests