diff --git a/applets/CMakeLists.txt b/applets/CMakeLists.txt --- a/applets/CMakeLists.txt +++ b/applets/CMakeLists.txt @@ -1,7 +1,6 @@ plasma_install_package(activitypager org.kde.plasma.activitypager) plasma_install_package(kickerdash org.kde.plasma.kickerdash) plasma_install_package(konsoleprofiles/package org.kde.plasma.konsoleprofiles) -plasma_install_package(webbrowser org.kde.plasma.webbrowser) add_subdirectory(binary-clock) add_subdirectory(calculator) @@ -27,3 +26,4 @@ add_subdirectory(timer) add_subdirectory(userswitcher) add_subdirectory(weather) +add_subdirectory(webbrowser) diff --git a/applets/webbrowser/CMakeLists.txt b/applets/webbrowser/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/applets/webbrowser/CMakeLists.txt @@ -0,0 +1,13 @@ +find_package(Qt5WebEngine ${REQUIRED_QT_VERSION} CONFIG) + +set_package_properties(Qt5WebEngine PROPERTIES + PURPOSE "Needed by the web browser applet" + URL "https://doc.qt.io/qt-5/qtwebengine-index.html" + TYPE OPTIONAL +) + +if (Qt5WebEngine_FOUND) + +plasma_install_package(package org.kde.plasma.webbrowser) + +endif() diff --git a/applets/webbrowser/contents/config/main.xml b/applets/webbrowser/package/contents/config/main.xml rename from applets/webbrowser/contents/config/main.xml rename to applets/webbrowser/package/contents/config/main.xml diff --git a/applets/webbrowser/contents/ui/main.qml b/applets/webbrowser/package/contents/ui/main.qml rename from applets/webbrowser/contents/ui/main.qml rename to applets/webbrowser/package/contents/ui/main.qml --- a/applets/webbrowser/contents/ui/main.qml +++ b/applets/webbrowser/package/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(); + } + } + } + } } diff --git a/applets/webbrowser/metadata.desktop b/applets/webbrowser/package/metadata.desktop rename from applets/webbrowser/metadata.desktop rename to applets/webbrowser/package/metadata.desktop