From 9265be9445ebd3bcd404dcca9186a1abc5c454cd Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 2 May 2017 16:10:55 +0200 Subject: QuickNanoBrowser: Code cleanup Fixes following warnings: error: Unknown component. (M300) warning: == and != may perform type coercion, use === or !== to avoid it. (M126) error: "autoLoadIconsForPage" is not a member of "WebEngineSettings". (M18) error: "touchIconsEnabled" is not a member of "WebEngineSettings". (M18) warning: "tab" is declared more than once. (M107) Also sort import list. Change-Id: I859ee341a7a84494975aea8ec5fb0d988a90d2b9 Reviewed-by: Allan Sandfeld Jensen --- examples/webengine/quicknanobrowser/BrowserWindow.qml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'examples') diff --git a/examples/webengine/quicknanobrowser/BrowserWindow.qml b/examples/webengine/quicknanobrowser/BrowserWindow.qml index c008425d9..b53db9bdb 100644 --- a/examples/webengine/quicknanobrowser/BrowserWindow.qml +++ b/examples/webengine/quicknanobrowser/BrowserWindow.qml @@ -48,15 +48,16 @@ ** ****************************************************************************/ +import Qt.labs.settings 1.0 +import QtQml 2.2 import QtQuick 2.2 -import QtWebEngine 1.2 import QtQuick.Controls 1.0 +import QtQuick.Controls.Private 1.0 import QtQuick.Controls.Styles 1.0 +import QtQuick.Dialogs 1.2 import QtQuick.Layouts 1.0 import QtQuick.Window 2.1 -import QtQuick.Controls.Private 1.0 -import QtQuick.Dialogs 1.2 -import Qt.labs.settings 1.0 +import QtWebEngine 1.3 ApplicationWindow { id: browserWindow @@ -294,7 +295,7 @@ ApplicationWindow { id: httpDiskCacheEnabled text: "HTTP Disk Cache" checkable: !currentWebView.profile.offTheRecord - checked: (currentWebView.profile.httpCacheType == WebEngineProfile.DiskHttpCache) + checked: (currentWebView.profile.httpCacheType === WebEngineProfile.DiskHttpCache) onToggled: currentWebView.profile.httpCacheType = checked ? WebEngineProfile.DiskHttpCache : WebEngineProfile.MemoryHttpCache } MenuItem { @@ -397,8 +398,8 @@ ApplicationWindow { tabs.currentIndex = tabs.count - 1 request.openIn(tab.item) } else if (request.destination == WebEngineView.NewViewInBackgroundTab) { - var tab = tabs.createEmptyTab(currentWebView.profile) - request.openIn(tab.item) + var backgroundTab = tabs.createEmptyTab(currentWebView.profile) + request.openIn(backgroundTab.item) } else if (request.destination == WebEngineView.NewViewInDialog) { var dialog = applicationRoot.createDialog(currentWebView.profile) request.openIn(dialog.currentWebView) -- cgit v1.2.3 From fa0aa60a9a7da656dad351e89e0a4612e889c7db Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 2 May 2017 16:25:23 +0200 Subject: QuickNanoBrowser: Unify use of semicolons in JS See also http://lists.qt-project.org/pipermail/development/2016-October/027441.html Change-Id: Id0f3e5e994e2160f7f199c02d5e79d0ad86a0d70 Reviewed-by: Allan Sandfeld Jensen --- .../webengine/quicknanobrowser/ApplicationRoot.qml | 18 +-- .../webengine/quicknanobrowser/BrowserWindow.qml | 126 ++++++++++----------- .../webengine/quicknanobrowser/DownloadView.qml | 12 +- .../quicknanobrowser/FullScreenNotification.qml | 12 +- 4 files changed, 84 insertions(+), 84 deletions(-) (limited to 'examples') diff --git a/examples/webengine/quicknanobrowser/ApplicationRoot.qml b/examples/webengine/quicknanobrowser/ApplicationRoot.qml index 6735be932..78defab80 100644 --- a/examples/webengine/quicknanobrowser/ApplicationRoot.qml +++ b/examples/webengine/quicknanobrowser/ApplicationRoot.qml @@ -70,18 +70,18 @@ QtObject { onClosing: destroy() } function createWindow(profile) { - var newWindow = browserWindowComponent.createObject(root) - newWindow.currentWebView.profile = profile - profile.downloadRequested.connect(newWindow.onDownloadRequested) - return newWindow + var newWindow = browserWindowComponent.createObject(root); + newWindow.currentWebView.profile = profile; + profile.downloadRequested.connect(newWindow.onDownloadRequested); + return newWindow; } function createDialog(profile) { - var newDialog = browserDialogComponent.createObject(root) - newDialog.currentWebView.profile = profile - return newDialog + var newDialog = browserDialogComponent.createObject(root); + newDialog.currentWebView.profile = profile; + return newDialog; } function load(url) { - var browserWindow = createWindow(defaultProfile) - browserWindow.currentWebView.url = url + var browserWindow = createWindow(defaultProfile); + browserWindow.currentWebView.url = url; } } diff --git a/examples/webengine/quicknanobrowser/BrowserWindow.qml b/examples/webengine/quicknanobrowser/BrowserWindow.qml index b53db9bdb..596e4a76e 100644 --- a/examples/webengine/quicknanobrowser/BrowserWindow.qml +++ b/examples/webengine/quicknanobrowser/BrowserWindow.qml @@ -80,19 +80,19 @@ ApplicationWindow { Settings { id : appSettings - property alias autoLoadImages: loadImages.checked; - property alias javaScriptEnabled: javaScriptEnabled.checked; - property alias errorPageEnabled: errorPageEnabled.checked; - property alias pluginsEnabled: pluginsEnabled.checked; - property alias fullScreenSupportEnabled: fullScreenSupportEnabled.checked; - property alias autoLoadIconsForPage: autoLoadIconsForPage.checked; - property alias touchIconsEnabled: touchIconsEnabled.checked; + property alias autoLoadImages: loadImages.checked + property alias javaScriptEnabled: javaScriptEnabled.checked + property alias errorPageEnabled: errorPageEnabled.checked + property alias pluginsEnabled: pluginsEnabled.checked + property alias fullScreenSupportEnabled: fullScreenSupportEnabled.checked + property alias autoLoadIconsForPage: autoLoadIconsForPage.checked + property alias touchIconsEnabled: touchIconsEnabled.checked } Action { shortcut: "Ctrl+D" onTriggered: { - downloadView.visible = !downloadView.visible + downloadView.visible = !downloadView.visible; } } Action { @@ -107,14 +107,14 @@ ApplicationWindow { shortcut: StandardKey.Refresh onTriggered: { if (currentWebView) - currentWebView.reload() + currentWebView.reload(); } } Action { shortcut: StandardKey.AddTab onTriggered: { - tabs.createEmptyTab(currentWebView.profile) - tabs.currentIndex = tabs.count - 1 + tabs.createEmptyTab(currentWebView.profile); + tabs.currentIndex = tabs.count - 1; addressBar.forceActiveFocus(); addressBar.selectAll(); } @@ -129,23 +129,23 @@ ApplicationWindow { shortcut: "Escape" onTriggered: { if (currentWebView.state == "FullScreen") { - browserWindow.visibility = browserWindow.previousVisibility - fullScreenNotification.hide() + browserWindow.visibility = browserWindow.previousVisibility; + fullScreenNotification.hide(); currentWebView.triggerWebAction(WebEngineView.ExitFullScreen); } } } Action { shortcut: "Ctrl+0" - onTriggered: currentWebView.zoomFactor = 1.0; + onTriggered: currentWebView.zoomFactor = 1.0 } Action { shortcut: StandardKey.ZoomOut - onTriggered: currentWebView.zoomFactor -= 0.1; + onTriggered: currentWebView.zoomFactor -= 0.1 } Action { shortcut: StandardKey.ZoomIn - onTriggered: currentWebView.zoomFactor += 0.1; + onTriggered: currentWebView.zoomFactor += 0.1 } Action { @@ -188,7 +188,7 @@ ApplicationWindow { toolBar: ToolBar { id: navigationBar RowLayout { - anchors.fill: parent; + anchors.fill: parent ToolButton { enabled: currentWebView && (currentWebView.canGoBack || currentWebView.canGoForward) menu:Menu { @@ -337,12 +337,12 @@ ApplicationWindow { TabView { id: tabs function createEmptyTab(profile) { - var tab = addTab("", tabComponent) + var tab = addTab("", tabComponent); // We must do this first to make sure that tab.active gets set so that tab.item gets instantiated immediately. - tab.active = true - tab.title = Qt.binding(function() { return tab.item.title }) - tab.item.profile = profile - return tab + tab.active = true; + tab.title = Qt.binding(function() { return tab.item.title }); + tab.item.profile = profile; + return tab; } anchors.fill: parent @@ -356,10 +356,10 @@ ApplicationWindow { onLinkHovered: { if (hoveredUrl == "") - resetStatusText.start() + resetStatusText.start(); else { - resetStatusText.stop() - statusText.text = hoveredUrl + resetStatusText.stop(); + statusText.text = hoveredUrl; } } @@ -386,69 +386,69 @@ ApplicationWindow { settings.touchIconsEnabled: appSettings.touchIconsEnabled onCertificateError: { - error.defer() - sslDialog.enqueue(error) + error.defer(); + sslDialog.enqueue(error); } onNewViewRequested: { if (!request.userInitiated) - print("Warning: Blocked a popup window.") + print("Warning: Blocked a popup window."); else if (request.destination == WebEngineView.NewViewInTab) { - var tab = tabs.createEmptyTab(currentWebView.profile) - tabs.currentIndex = tabs.count - 1 - request.openIn(tab.item) + var tab = tabs.createEmptyTab(currentWebView.profile); + tabs.currentIndex = tabs.count - 1; + request.openIn(tab.item); } else if (request.destination == WebEngineView.NewViewInBackgroundTab) { - var backgroundTab = tabs.createEmptyTab(currentWebView.profile) - request.openIn(backgroundTab.item) + var backgroundTab = tabs.createEmptyTab(currentWebView.profile); + request.openIn(backgroundTab.item); } else if (request.destination == WebEngineView.NewViewInDialog) { - var dialog = applicationRoot.createDialog(currentWebView.profile) - request.openIn(dialog.currentWebView) + var dialog = applicationRoot.createDialog(currentWebView.profile); + request.openIn(dialog.currentWebView); } else { - var window = applicationRoot.createWindow(currentWebView.profile) - request.openIn(window.currentWebView) + var window = applicationRoot.createWindow(currentWebView.profile); + request.openIn(window.currentWebView); } } onFullScreenRequested: { if (request.toggleOn) { - webEngineView.state = "FullScreen" - browserWindow.previousVisibility = browserWindow.visibility - browserWindow.showFullScreen() - fullScreenNotification.show() + webEngineView.state = "FullScreen"; + browserWindow.previousVisibility = browserWindow.visibility; + browserWindow.showFullScreen(); + fullScreenNotification.show(); } else { - webEngineView.state = "" - browserWindow.visibility = browserWindow.previousVisibility - fullScreenNotification.hide() + webEngineView.state = ""; + browserWindow.visibility = browserWindow.previousVisibility; + fullScreenNotification.hide(); } - request.accept() + request.accept(); } onRenderProcessTerminated: { - var status = "" + var status = ""; switch (terminationStatus) { case WebEngineView.NormalTerminationStatus: - status = "(normal exit)" + status = "(normal exit)"; break; case WebEngineView.AbnormalTerminationStatus: - status = "(abnormal exit)" + status = "(abnormal exit)"; break; case WebEngineView.CrashedTerminationStatus: - status = "(crashed)" + status = "(crashed)"; break; case WebEngineView.KilledTerminationStatus: - status = "(killed)" + status = "(killed)"; break; } - print("Render process exited with code " + exitCode + " " + status) - reloadTimer.running = true + print("Render process exited with code " + exitCode + " " + status); + reloadTimer.running = true; } onWindowCloseRequested: { if (tabs.count == 1) - browserWindow.close() + browserWindow.close(); else - tabs.removeTab(tabs.currentIndex) + tabs.removeTab(tabs.currentIndex); } Timer { @@ -474,19 +474,19 @@ ApplicationWindow { "you may not be connected with the host you tried to connect to.\n" + "Do you wish to override the security check and continue?" onYes: { - certErrors.shift().ignoreCertificateError() - presentError() + certErrors.shift().ignoreCertificateError(); + presentError(); } onNo: reject() onRejected: reject() function reject(){ - certErrors.shift().rejectCertificate() - presentError() + certErrors.shift().rejectCertificate(); + presentError(); } function enqueue(error){ - certErrors.push(error) - presentError() + certErrors.push(error); + presentError(); } function presentError(){ visible = certErrors.length > 0 @@ -504,9 +504,9 @@ ApplicationWindow { } function onDownloadRequested(download) { - downloadView.visible = true - downloadView.append(download) - download.accept() + downloadView.visible = true; + downloadView.append(download); + download.accept(); } Rectangle { diff --git a/examples/webengine/quicknanobrowser/DownloadView.qml b/examples/webengine/quicknanobrowser/DownloadView.qml index 13be4bd78..ed28c761c 100644 --- a/examples/webengine/quicknanobrowser/DownloadView.qml +++ b/examples/webengine/quicknanobrowser/DownloadView.qml @@ -64,8 +64,8 @@ Rectangle { } function append(download) { - downloadModel.append(download) - downloadModel.downloads.push(download) + downloadModel.append(download); + downloadModel.downloads.push(download); } Component { @@ -113,14 +113,14 @@ Rectangle { anchors.right: parent.right iconSource: "icons/process-stop.png" onClicked: { - var download = downloadModel.downloads[index] + var download = downloadModel.downloads[index]; - download.cancel() + download.cancel(); downloadModel.downloads = downloadModel.downloads.filter(function (el) { return el.id !== download.id; }); - downloadModel.remove(index) + downloadModel.remove(index); } } } @@ -167,7 +167,7 @@ Rectangle { text: "OK" anchors.centerIn: parent onClicked: { - downloadView.visible = false + downloadView.visible = false; } } } diff --git a/examples/webengine/quicknanobrowser/FullScreenNotification.qml b/examples/webengine/quicknanobrowser/FullScreenNotification.qml index 80a63d479..f0487e868 100644 --- a/examples/webengine/quicknanobrowser/FullScreenNotification.qml +++ b/examples/webengine/quicknanobrowser/FullScreenNotification.qml @@ -51,14 +51,14 @@ Rectangle { opacity: 0 function show() { - visible = true - opacity = 1 - reset.start() + visible = true; + opacity = 1; + reset.start(); } function hide() { - reset.stop() - opacity = 0 + reset.stop(); + opacity = 0; } Behavior on opacity { @@ -66,7 +66,7 @@ Rectangle { duration: 750 onStopped: { if (opacity == 0) - visible = false + visible = false; } } } -- cgit v1.2.3 From 2156011b0a6047cd2b49dd03f6f3145cfc0f64b0 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 2 May 2017 15:46:56 +0200 Subject: markdown: Code beautification Change-Id: I74d30578a9725f10a8d4e86ff8740d5f467d0fbc Reviewed-by: Allan Sandfeld Jensen --- examples/webenginewidgets/markdowneditor/document.h | 2 +- examples/webenginewidgets/markdowneditor/mainwindow.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/webenginewidgets/markdowneditor/document.h b/examples/webenginewidgets/markdowneditor/document.h index 3c16c251d..bc6552731 100644 --- a/examples/webenginewidgets/markdowneditor/document.h +++ b/examples/webenginewidgets/markdowneditor/document.h @@ -57,7 +57,7 @@ class Document : public QObject { Q_OBJECT - Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged) + Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged FINAL) public: explicit Document(QObject *parent = nullptr) : QObject(parent) {} diff --git a/examples/webenginewidgets/markdowneditor/mainwindow.h b/examples/webenginewidgets/markdowneditor/mainwindow.h index ad0320373..817f626d8 100644 --- a/examples/webenginewidgets/markdowneditor/mainwindow.h +++ b/examples/webenginewidgets/markdowneditor/mainwindow.h @@ -67,7 +67,7 @@ class MainWindow : public QMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); void openFile(const QString &path); -- cgit v1.2.3 From 8ed45ab8997757ddd98ea8132f0a9bb3ad26e52a Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 4 May 2017 12:03:47 +0200 Subject: SimpleBrowser: Press Ctrl-L to focus the location bar This commonly used short cut is a must-have for every browser, even simple ones. Change-Id: I2a0bde05bceeb5a4334e3a7168bd45a9335311ee Reviewed-by: Kai Koehne --- examples/webenginewidgets/simplebrowser/browserwindow.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'examples') diff --git a/examples/webenginewidgets/simplebrowser/browserwindow.cpp b/examples/webenginewidgets/simplebrowser/browserwindow.cpp index c01f912d3..762d56c85 100644 --- a/examples/webenginewidgets/simplebrowser/browserwindow.cpp +++ b/examples/webenginewidgets/simplebrowser/browserwindow.cpp @@ -105,6 +105,13 @@ BrowserWindow::BrowserWindow(QWidget *parent, Qt::WindowFlags flags) m_urlLineEdit->setFavIcon(QIcon(QStringLiteral(":defaulticon.png"))); + QAction *focusUrlLineEditAction = new QAction(this); + addAction(focusUrlLineEditAction); + focusUrlLineEditAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_L)); + connect(focusUrlLineEditAction, &QAction::triggered, this, [this] () { + m_urlLineEdit->setFocus(Qt::ShortcutFocusReason); + }); + handleWebViewTitleChanged(tr("Qt Simple Browser")); m_tabWidget->createTab(); } -- cgit v1.2.3 From b24a6419869c14e32e87cb97e529cc25c246b5e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Wed, 5 Apr 2017 17:14:16 +0200 Subject: Create example for full screen feature in WebEngine Adds an example ('videoplayer') showing how to enable the Fullscreen API[1] in QWebEngineView. This is one of the missing examples blocking the removal of demobrowser. [1]: https://fullscreen.spec.whatwg.org Task-number: QTBUG-59820 Change-Id: Ib02a1556515d87e595ca54c2bce18c9144030fbc Reviewed-by: Kai Koehne Reviewed-by: Leena Miettinen Reviewed-by: Michal Klocek --- .../webenginewidgets/videoplayer/data/index.html | 23 +++ .../videoplayer/data/videoplayer.qrc | 5 + .../videoplayer/doc/images/videoplayer-example.png | Bin 0 -> 34140 bytes .../videoplayer/doc/src/videoplayer.qdoc | 186 +++++++++++++++++++++ .../videoplayer/fullscreennotification.cpp | 87 ++++++++++ .../videoplayer/fullscreennotification.h | 61 +++++++ .../videoplayer/fullscreenwindow.cpp | 88 ++++++++++ .../videoplayer/fullscreenwindow.h | 68 ++++++++ examples/webenginewidgets/videoplayer/main.cpp | 53 ++++++ .../webenginewidgets/videoplayer/mainwindow.cpp | 72 ++++++++ examples/webenginewidgets/videoplayer/mainwindow.h | 64 +++++++ .../webenginewidgets/videoplayer/videoplayer.pro | 19 +++ examples/webenginewidgets/webenginewidgets.pro | 3 +- 13 files changed, 728 insertions(+), 1 deletion(-) create mode 100644 examples/webenginewidgets/videoplayer/data/index.html create mode 100644 examples/webenginewidgets/videoplayer/data/videoplayer.qrc create mode 100644 examples/webenginewidgets/videoplayer/doc/images/videoplayer-example.png create mode 100644 examples/webenginewidgets/videoplayer/doc/src/videoplayer.qdoc create mode 100644 examples/webenginewidgets/videoplayer/fullscreennotification.cpp create mode 100644 examples/webenginewidgets/videoplayer/fullscreennotification.h create mode 100644 examples/webenginewidgets/videoplayer/fullscreenwindow.cpp create mode 100644 examples/webenginewidgets/videoplayer/fullscreenwindow.h create mode 100644 examples/webenginewidgets/videoplayer/main.cpp create mode 100644 examples/webenginewidgets/videoplayer/mainwindow.cpp create mode 100644 examples/webenginewidgets/videoplayer/mainwindow.h create mode 100644 examples/webenginewidgets/videoplayer/videoplayer.pro (limited to 'examples') diff --git a/examples/webenginewidgets/videoplayer/data/index.html b/examples/webenginewidgets/videoplayer/data/index.html new file mode 100644 index 000000000..4a1bdc33e --- /dev/null +++ b/examples/webenginewidgets/videoplayer/data/index.html @@ -0,0 +1,23 @@ + + + + + + + + + + diff --git a/examples/webenginewidgets/videoplayer/data/videoplayer.qrc b/examples/webenginewidgets/videoplayer/data/videoplayer.qrc new file mode 100644 index 000000000..c3322b454 --- /dev/null +++ b/examples/webenginewidgets/videoplayer/data/videoplayer.qrc @@ -0,0 +1,5 @@ + + + index.html + + diff --git a/examples/webenginewidgets/videoplayer/doc/images/videoplayer-example.png b/examples/webenginewidgets/videoplayer/doc/images/videoplayer-example.png new file mode 100644 index 000000000..9cf51d84a Binary files /dev/null and b/examples/webenginewidgets/videoplayer/doc/images/videoplayer-example.png differ diff --git a/examples/webenginewidgets/videoplayer/doc/src/videoplayer.qdoc b/examples/webenginewidgets/videoplayer/doc/src/videoplayer.qdoc new file mode 100644 index 000000000..599e13e6c --- /dev/null +++ b/examples/webenginewidgets/videoplayer/doc/src/videoplayer.qdoc @@ -0,0 +1,186 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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 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 webenginewidgets/videoplayer + \title WebEngine Widgets Video Player Example + \ingroup webengine-widgetexamples + \brief Displays full screen video using \l QWebEngineView + + \image videoplayer-example.png + + \e {Video Player} demonstrates how to support full screen playback of HTML5 + video using \l QWebEngineView. + + \l {https://fullscreen.spec.whatwg.org/}{The Fullscreen API} is a + 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