diff options
-rw-r--r-- | examples/webengine/quicknanobrowser/quickwindow.qml | 12 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview.cpp | 17 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview_p.h | 4 | ||||
-rw-r--r-- | tests/quicktestbrowser/ZoomController.qml | 102 | ||||
-rw-r--r-- | tests/quicktestbrowser/quickwindow.qml | 24 | ||||
-rw-r--r-- | tests/quicktestbrowser/resources.qrc | 1 |
6 files changed, 160 insertions, 0 deletions
diff --git a/examples/webengine/quicknanobrowser/quickwindow.qml b/examples/webengine/quicknanobrowser/quickwindow.qml index c6b03418c..c73951046 100644 --- a/examples/webengine/quicknanobrowser/quickwindow.qml +++ b/examples/webengine/quicknanobrowser/quickwindow.qml @@ -93,6 +93,18 @@ ApplicationWindow { tabs.removeTab(tabs.currentIndex) } } + Action { + shortcut: "Ctrl+0" + onTriggered: currentWebView.zoomFactor = 1.0; + } + Action { + shortcut: "Ctrl+-" + onTriggered: currentWebView.zoomFactor -= 0.1; + } + Action { + shortcut: "Ctrl+=" + onTriggered: currentWebView.zoomFactor += 0.1; + } toolBar: ToolBar { id: navigationBar diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index b466c8566..6f216fda9 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -554,6 +554,17 @@ void QQuickWebEngineView::stop() d->adapter->stop(); } +void QQuickWebEngineView::setZoomFactor(qreal arg) +{ + Q_D(QQuickWebEngineView); + qreal oldFactor = d->adapter->currentZoomFactor(); + d->adapter->setZoomFactor(arg); + if (qFuzzyCompare(oldFactor, d->adapter->currentZoomFactor())) + return; + + emit zoomFactorChanged(arg); +} + void QQuickWebEngineViewPrivate::didRunJavaScript(quint64 requestId, const QVariant &result) { Q_Q(QQuickWebEngineView); @@ -617,6 +628,12 @@ QQuickWebEngineViewExperimental *QQuickWebEngineView::experimental() const return d->e.data(); } +qreal QQuickWebEngineView::zoomFactor() const +{ + Q_D(const QQuickWebEngineView); + return d->adapter->currentZoomFactor(); +} + bool QQuickWebEngineViewExperimental::inspectable() const { Q_D(const QQuickWebEngineView); diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h index 402c2ce65..d2f262a9b 100644 --- a/src/webengine/api/qquickwebengineview_p.h +++ b/src/webengine/api/qquickwebengineview_p.h @@ -56,6 +56,7 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem { Q_PROPERTY(QString title READ title NOTIFY titleChanged) Q_PROPERTY(bool canGoBack READ canGoBack NOTIFY loadingChanged) Q_PROPERTY(bool canGoForward READ canGoForward NOTIFY loadingChanged) + Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged) Q_ENUMS(NavigationRequestAction); Q_ENUMS(NavigationType); Q_ENUMS(LoadStatus); @@ -75,6 +76,7 @@ public: QString title() const; bool canGoBack() const; bool canGoForward() const; + qreal zoomFactor() const; QQuickWebEngineViewExperimental *experimental() const; @@ -133,6 +135,7 @@ public Q_SLOTS: void goForward(); void reload(); void stop(); + void setZoomFactor(qreal arg); Q_SIGNALS: void titleChanged(); @@ -143,6 +146,7 @@ Q_SIGNALS: void linkHovered(const QUrl &hoveredUrl); void navigationRequested(QQuickWebEngineNavigationRequest *request); void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID); + void zoomFactorChanged(qreal arg); protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); diff --git a/tests/quicktestbrowser/ZoomController.qml b/tests/quicktestbrowser/ZoomController.qml new file mode 100644 index 000000000..a714ed2a9 --- /dev/null +++ b/tests/quicktestbrowser/ZoomController.qml @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 Digia Plc and its Subsidiary(-ies) 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.3 +import QtQuick.Controls 1.2 +import QtQuick.Layouts 1.1 + +Rectangle { + property alias zoomFactor: slider.value ; + function zoomIn() { + visible = true + visibilityTimer.restart() + zoomFactor = zoomFactor + 0.25; + } + function zoomOut() { + visible = true + visibilityTimer.restart() + zoomFactor = zoomFactor - 0.25; + } + function reset() { zoomFactor = 1.0 } + + width: 220 + height: 30 + color: palette.window + visible: false + radius: 4 + + SystemPalette { + id: palette + } + Timer { + id: visibilityTimer + interval: 3000 + repeat: false + onTriggered: zoomController.visible = false + } + + RowLayout { + anchors.margins: 4 + anchors.fill: parent + ToolButton { + id: plusButton + text: '+' + onClicked: zoomIn() + } + ToolButton { + text: '\u2014' + id: minusButton + onClicked: zoomOut() + } + Slider { + id: slider + maximumValue: 5.0 + minimumValue: 0.25 + Layout.fillWidth: true; + stepSize: 0.05 + value: 1 + onValueChanged: visibilityTimer.restart() + } + Button { + text: "Reset" + onClicked: reset() + } + } +} diff --git a/tests/quicktestbrowser/quickwindow.qml b/tests/quicktestbrowser/quickwindow.qml index f24717b01..ebde5b1ab 100644 --- a/tests/quicktestbrowser/quickwindow.qml +++ b/tests/quicktestbrowser/quickwindow.qml @@ -121,6 +121,18 @@ ApplicationWindow { browserWindow.showNormal() } } + Action { + shortcut: "Ctrl+0" + onTriggered: zoomController.reset() + } + Action { + shortcut: "Ctrl+-" + onTriggered: zoomController.zoomOut() + } + Action { + shortcut: "Ctrl+=" + onTriggered: zoomController.zoomIn() + } Menu { id: backHistoryMenu @@ -391,4 +403,16 @@ ApplicationWindow { } } } + ZoomController { + id: zoomController + y: parent.mapFromItem(currentWebView, 0 , 0).y - 4 + anchors.right: parent.right + width: (parent.width > 800) ? parent.width * 0.25 : 220 + anchors.rightMargin: (parent.width > 400) ? 100 : 0 + } + Binding { + target: currentWebView + property: "zoomFactor" + value: zoomController.zoomFactor + } } diff --git a/tests/quicktestbrowser/resources.qrc b/tests/quicktestbrowser/resources.qrc index cdc3d2304..4880b3d65 100644 --- a/tests/quicktestbrowser/resources.qrc +++ b/tests/quicktestbrowser/resources.qrc @@ -4,6 +4,7 @@ <file>ContextMenuExtras.qml</file> <file>FeaturePermissionBar.qml</file> <file>ButtonWithMenu.qml</file> + <file>ZoomController.qml</file> </qresource> <qresource prefix="icons"> <!-- To the risk of this breaking more often, do not duplicate the resources since this application won't be deployed --> |