From 6e01ff519e5f2dfeb605b4bb6408283dd1363ea8 Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Tue, 6 Jul 2021 16:34:12 +0200 Subject: Port example to qt6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use qqc2 instead of qqc1. Drop styles. Fix progress bar layout. Pick-to: 6.2 Fixes: QTBUG-88620 Change-Id: I893704cd9718de9f8b836b35bdbd8a5931fd65d9 Reviewed-by: Christian Strømme --- .../minibrowser/+android/LoadProgressStyle.qml | 62 ----------------- examples/webview/minibrowser/CMakeLists.txt | 4 +- examples/webview/minibrowser/LoadProgressStyle.qml | 67 ------------------- examples/webview/minibrowser/main.qml | 77 ++++++++-------------- examples/webview/minibrowser/qml.qrc | 10 ++- 5 files changed, 33 insertions(+), 187 deletions(-) delete mode 100644 examples/webview/minibrowser/+android/LoadProgressStyle.qml delete mode 100644 examples/webview/minibrowser/LoadProgressStyle.qml diff --git a/examples/webview/minibrowser/+android/LoadProgressStyle.qml b/examples/webview/minibrowser/+android/LoadProgressStyle.qml deleted file mode 100644 index 35eeb30..0000000 --- a/examples/webview/minibrowser/+android/LoadProgressStyle.qml +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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$ -** -****************************************************************************/ - -import QtQuick 2.2 -import QtQuick.Controls.Styles 1.2 - -ProgressBarStyle { - background: Rectangle { - radius: 2 - color: "transparent" - implicitHeight: Math.round(urlField.height / 1.3) - implicitWidth: urlField.width - 12 - } - -} diff --git a/examples/webview/minibrowser/CMakeLists.txt b/examples/webview/minibrowser/CMakeLists.txt index 5e6dc54..0d3d1cd 100644 --- a/examples/webview/minibrowser/CMakeLists.txt +++ b/examples/webview/minibrowser/CMakeLists.txt @@ -37,8 +37,6 @@ target_link_libraries(minibrowser PUBLIC # Resources: set(qml_resource_files - "+android/LoadProgressStyle.qml" - "LoadProgressStyle.qml" "images/left-32.png" "images/refresh-32.png" "images/right-32.png" @@ -49,6 +47,8 @@ set(qml_resource_files qt6_add_resources(minibrowser "qml" PREFIX "/" + BASE + "images" FILES ${qml_resource_files} ) diff --git a/examples/webview/minibrowser/LoadProgressStyle.qml b/examples/webview/minibrowser/LoadProgressStyle.qml deleted file mode 100644 index 88d047f..0000000 --- a/examples/webview/minibrowser/LoadProgressStyle.qml +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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$ -** -****************************************************************************/ - -import QtQuick 2.2 -import QtQuick.Controls.Styles 1.2 - -ProgressBarStyle { - background: Rectangle { - radius: 2 - color: "transparent" - implicitHeight: urlField.height - 2 - implicitWidth: urlField.width - } - progress: Rectangle { - anchors.fill: parent - color: "#80c342" - opacity: 0.5 - } - -} diff --git a/examples/webview/minibrowser/main.qml b/examples/webview/minibrowser/main.qml index 30d94a6..6f6bcfd 100644 --- a/examples/webview/minibrowser/main.qml +++ b/examples/webview/minibrowser/main.qml @@ -48,17 +48,13 @@ ** ****************************************************************************/ -import QtQuick 2.2 -import QtQuick.Controls 1.1 -import QtWebView 1.1 -import QtQuick.Layouts 1.1 -import QtQuick.Controls.Styles 1.2 +import QtQuick +import QtQuick.Controls +import QtWebView +import QtQuick.Layouts ApplicationWindow { - property bool showProgress: webView.loading - && Qt.platform.os !== "ios" - && Qt.platform.os !== "winrt" visible: true x: initialX y: initialY @@ -66,7 +62,7 @@ ApplicationWindow { height: initialHeight title: webView.title - toolBar: ToolBar { + menuBar: ToolBar { id: navigationBar RowLayout { anchors.fill: parent @@ -74,37 +70,25 @@ ApplicationWindow { ToolButton { id: backButton - tooltip: qsTr("Back") - iconSource: "images/left-32.png" + icon.source: "qrc:/left-32.png" onClicked: webView.goBack() enabled: webView.canGoBack Layout.preferredWidth: navigationBar.height - style: ButtonStyle { - background: Rectangle { color: "transparent" } - } } ToolButton { id: forwardButton - tooltip: qsTr("Forward") - iconSource: "images/right-32.png" + icon.source: "qrc:/right-32.png" onClicked: webView.goForward() enabled: webView.canGoForward Layout.preferredWidth: navigationBar.height - style: ButtonStyle { - background: Rectangle { color: "transparent" } - } } ToolButton { id: reloadButton - tooltip: webView.loading ? qsTr("Stop"): qsTr("Refresh") - iconSource: webView.loading ? "images/stop-32.png" : "images/refresh-32.png" + icon.source: webView.loading ? "qrc:/stop-32.png" : "qrc:/refresh-32.png" onClicked: webView.loading ? webView.stop() : webView.reload() Layout.preferredWidth: navigationBar.height - style: ButtonStyle { - background: Rectangle { color: "transparent" } - } } Item { Layout.preferredWidth: 5 } @@ -114,46 +98,39 @@ ApplicationWindow { id: urlField inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhPreferLowercase text: webView.url - onAccepted: webView.url = utils.fromUserInput(text) - - ProgressBar { - anchors.centerIn: parent - style: LoadProgressStyle { } - z: Qt.platform.os === "android" ? -1 : 1 - visible: showProgress - minimumValue: 0 - maximumValue: 100 - value: webView.loadProgress == 100 ? 0 : webView.loadProgress - } - } + } Item { Layout.preferredWidth: 5 } ToolButton { id: goButton text: qsTr("Go") - Layout.preferredWidth: navigationBar.height onClicked: { Qt.inputMethod.commit() Qt.inputMethod.hide() webView.url = utils.fromUserInput(urlField.text) } - style: ButtonStyle { - background: Rectangle { color: "transparent" } - } } Item { Layout.preferredWidth: 10 } - } - } - - statusBar: StatusBar { - id: statusBar - visible: showProgress - RowLayout { - anchors.fill: parent - Label { text: webView.loadProgress == 100 ? qsTr("Done") : qsTr("Loading: ") + webView.loadProgress + "%" } + } + ProgressBar { + id: progress + anchors { + left: parent.left + top: parent.bottom + right: parent.right + leftMargin: parent.leftMargin + rightMargin: parent.rightMargin + } + height:3 + z: Qt.platform.os === "android" ? -1 : -2 + background: Item {} + visible: Qt.platform.os !== "ios" && Qt.platform.os !== "winrt" + from: 0 + to: 100 + value: webView.loadProgress < 100 ? webView.loadProgress : 0 } } @@ -161,7 +138,7 @@ ApplicationWindow { id: webView anchors.fill: parent url: initialUrl - onLoadingChanged: { + onLoadingChanged: function(loadRequest) { if (loadRequest.errorString) console.error(loadRequest.errorString); } diff --git a/examples/webview/minibrowser/qml.qrc b/examples/webview/minibrowser/qml.qrc index 9791b21..f360471 100644 --- a/examples/webview/minibrowser/qml.qrc +++ b/examples/webview/minibrowser/qml.qrc @@ -1,11 +1,9 @@ main.qml - images/left-32.png - images/stop-32.png - images/refresh-32.png - LoadProgressStyle.qml - +android/LoadProgressStyle.qml - images/right-32.png + images/left-32.png + images/stop-32.png + images/refresh-32.png + images/right-32.png -- cgit v1.2.3