Changeset View
Changeset View
Standalone View
Standalone View
applets/webbrowser/package/contents/ui/main.qml
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright 2014, 2016 by Mikhail Ivchenko <ematirov@gmail.com> * | ||||
3 | * Copyright 2018 by Kai Uwe Broulik <kde@privat.broulik.de> * | ||||
4 | * * | ||||
5 | * This program is free software; you can redistribute it and/or modify * | ||||
6 | * it under the terms of the GNU General Public License as published by * | ||||
7 | * the Free Software Foundation; either version 2 of the License, or * | ||||
8 | * (at your option) any later version. * | ||||
9 | * * | ||||
10 | * This program is distributed in the hope that it will be useful, * | ||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
13 | * GNU General Public License for more details. * | ||||
14 | * * | ||||
15 | * You should have received a copy of the GNU General Public License * | ||||
16 | * along with this program; if not, write to the * | ||||
17 | * Free Software Foundation, Inc., * | ||||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | ||||
19 | ***************************************************************************/ | ||||
20 | | ||||
21 | import QtQuick 2.0 | ||||
22 | import QtWebEngine 1.1 | ||||
23 | import QtQuick.Layouts 1.1 | ||||
24 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||||
25 | import org.kde.plasma.extras 2.0 as PlasmaExtras | ||||
26 | | ||||
27 | ColumnLayout { | ||||
28 | RowLayout{ | ||||
29 | Layout.fillWidth: true | ||||
30 | PlasmaComponents.Button{ | ||||
31 | iconSource: "go-previous" | ||||
32 | onClicked: webview.goBack() | ||||
33 | enabled: webview.canGoBack | ||||
34 | } | ||||
35 | PlasmaComponents.Button{ | ||||
36 | iconSource: "go-next" | ||||
37 | onClicked: webview.goForward() | ||||
38 | enabled: webview.canGoForward | ||||
39 | } | ||||
40 | PlasmaComponents.TextField{ | ||||
41 | Layout.fillWidth: true | ||||
42 | onAccepted: { | ||||
43 | var url = text; | ||||
44 | if (url.indexOf(":/") < 0) { | ||||
45 | url = "http://" + url; | ||||
46 | } | ||||
47 | webview.url = url; | ||||
48 | } | ||||
49 | onActiveFocusChanged: { | ||||
50 | if (activeFocus) { | ||||
51 | selectAll(); | ||||
52 | } | ||||
53 | } | ||||
54 | | ||||
55 | text: webview.url | ||||
56 | } | ||||
57 | PlasmaComponents.Button{ | ||||
58 | iconSource: webview.loading ? "process-stop" : "view-refresh" | ||||
59 | onClicked: webview.loading ? webview.stop() : webview.reload() | ||||
60 | } | ||||
61 | } | ||||
62 | | ||||
63 | Item { | ||||
64 | Layout.fillWidth: true | ||||
65 | Layout.fillHeight: true | ||||
66 | | ||||
67 | // TODO use contentsSize but that crashes, now mostly for some sane initial size | ||||
68 | Layout.preferredWidth: units.gridUnit * 25 | ||||
69 | Layout.preferredHeight: units.gridUnit * 12 | ||||
70 | | ||||
71 | // Binding it to e.g. width will be super slow on resizing | ||||
72 | Timer { | ||||
73 | id: updateZoomTimer | ||||
74 | interval: 100 | ||||
75 | onTriggered: { | ||||
76 | // Try to fit contents for a smaller screen | ||||
77 | webview.zoomFactor = Math.min(1, webview.width / 1000); | ||||
78 | } | ||||
79 | | ||||
80 | } | ||||
81 | | ||||
82 | WebEngineView { | ||||
83 | id: webview | ||||
84 | anchors.fill: parent | ||||
85 | onUrlChanged: plasmoid.configuration.url = url; | ||||
86 | Component.onCompleted: url = plasmoid.configuration.url; | ||||
87 | | ||||
88 | onLinkHovered: { | ||||
89 | if (hoveredUrl.toString() !== "") { | ||||
90 | mouseArea.cursorShape = Qt.PointingHandCursor; | ||||
91 | } else { | ||||
92 | mouseArea.cursorShape = Qt.ArrowCursor; | ||||
93 | } | ||||
94 | } | ||||
95 | | ||||
96 | onWidthChanged: updateZoomTimer.start() | ||||
97 | onLoadingChanged: { | ||||
98 | if (loadRequest.status === WebEngineLoadRequest.LoadSucceededStatus) { | ||||
99 | updateZoomTimer.start(); | ||||
100 | } | ||||
101 | } | ||||
102 | } | ||||
103 | | ||||
104 | MouseArea { | ||||
105 | id: mouseArea | ||||
106 | anchors.fill: parent | ||||
107 | acceptedButtons: Qt.BackButton | Qt.ForwardButton | ||||
108 | onPressed: { | ||||
109 | if (mouse.button === Qt.BackButton) { | ||||
110 | webview.goBack(); | ||||
111 | } else if (mouse.button === Qt.ForwardButton) { | ||||
112 | webview.goForward(); | ||||
113 | } | ||||
114 | } | ||||
115 | } | ||||
116 | } | ||||
117 | } |