diff --git a/applets/webbrowser/contents/ui/main.qml b/applets/webbrowser/contents/ui/main.qml --- a/applets/webbrowser/contents/ui/main.qml +++ b/applets/webbrowser/contents/ui/main.qml @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright 2014, 2016 by Mikhail Ivchenko * + * Copyright 2018 by Kai Uwe Broulik * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -18,7 +19,7 @@ ***************************************************************************/ import QtQuick 2.0 -import QtWebKit 3.0 +import QtWebEngine 1.1 import QtQuick.Layouts 1.1 import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.extras 2.0 as PlasmaExtras @@ -45,23 +46,72 @@ } webview.url = url; } + onActiveFocusChanged: { + if (activeFocus) { + selectAll(); + } + } + text: webview.url } PlasmaComponents.Button{ - iconSource: "view-refresh" - onClicked: webview.reload() + iconSource: webview.loading ? "process-stop" : "view-refresh" + onClicked: webview.loading ? webview.stop() : webview.reload() } } - PlasmaExtras.ScrollArea { + + Item { Layout.fillWidth: true Layout.fillHeight: true - WebView { + + // TODO use contentsSize but that crashes, now mostly for some sane initial size + Layout.preferredWidth: units.gridUnit * 25 + Layout.preferredHeight: units.gridUnit * 12 + + // Binding it to e.g. width will be super slow on resizing + Timer { + id: updateZoomTimer + interval: 100 + onTriggered: { + // Try to fit contents for a smaller screen + webview.zoomFactor = Math.min(1, webview.width / 1000); + } + + } + + WebEngineView { id: webview anchors.fill: parent onUrlChanged: plasmoid.configuration.url = url; Component.onCompleted: url = plasmoid.configuration.url; + + onLinkHovered: { + if (hoveredUrl.toString() !== "") { + mouseArea.cursorShape = Qt.PointingHandCursor; + } else { + mouseArea.cursorShape = Qt.ArrowCursor; + } + } + + onWidthChanged: updateZoomTimer.start() + onLoadingChanged: { + if (loadRequest.status === WebEngineLoadRequest.LoadSucceededStatus) { + updateZoomTimer.start(); + } + } } - } - //There will be RowLayout with buttons for bookmarks and zooming. + MouseArea { + id: mouseArea + anchors.fill: parent + acceptedButtons: Qt.BackButton | Qt.ForwardButton + onPressed: { + if (mouse.button === Qt.BackButton) { + webview.goBack(); + } else if (mouse.button === Qt.ForwardButton) { + webview.goForward(); + } + } + } + } }