Warning, /network/angelfish/src/contents/ui/NavigationEntrySheet.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2019 Simon Schmeisser <s.schmeisser@gmx.net>
0002 // SPDX-FileCopyrightText: 2019 Jonah BrĂ¼chert <jbb@kaidan.im>
0003 //
0004 // SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006 import QtQuick 2.7
0007 import QtQuick.Controls 2.2 as Controls
0008 import QtQuick.Layouts 1.2
0009 
0010 import org.kde.kirigami 2.5 as Kirigami
0011 import org.kde.angelfish 1.0
0012 
0013 import "regex-weburl.js" as RegexWebUrl
0014 
0015 Controls.Drawer {
0016     id: overlay
0017     dragMargin: 0
0018     edge: Qt.BottomEdge
0019     width: parent.width
0020 
0021     bottomPadding: 0
0022     topPadding: 0
0023     rightPadding: 0
0024     leftPadding: 0
0025 
0026     property int buttonSize: Kirigami.Units.gridUnit * 2
0027     property int fullHeight: 0.9 * rootPage.height
0028     property bool openedState: false
0029 
0030     contentHeight: fullHeight - topPadding - bottomPadding
0031     contentWidth: parent.width - rightPadding - leftPadding
0032     contentItem: Item {
0033         width: parent.width
0034         height: parent.height
0035 
0036         RowLayout {
0037             id: editRow
0038             anchors.top: parent.top
0039             anchors.horizontalCenter: parent.horizontalCenter
0040             height: Kirigami.Units.gridUnit * 3
0041             width: parent.width - Kirigami.Units.gridUnit
0042 
0043             Controls.ToolButton {
0044                 Layout.preferredWidth: buttonSize
0045                 Layout.preferredHeight: buttonSize
0046 
0047                 icon.name: "window-minimize"
0048 
0049                 Kirigami.Theme.inherit: true
0050 
0051                 onClicked: overlay.close()
0052             }
0053 
0054             Controls.TextField {
0055                 id: urlInput
0056 
0057                 Layout.fillWidth: true
0058                 clip: true
0059                 focus: false
0060                 inputMethodHints: Qt.ImhUrlCharactersOnly | (rootPage.privateMode ? Qt.ImhNoPredictiveText : Qt.ImhNone)
0061                 Kirigami.Theme.inherit: true
0062 
0063                 onActiveFocusChanged: if (activeFocus) selectAll()
0064                 onAccepted: applyUrl()
0065                 onDisplayTextChanged: {
0066                     if (!openedState) return; // avoid filtering
0067                     if (displayText === "" || displayText.length > 2) {
0068                         urlFilter.filter = displayText;
0069                         timer.running = false;
0070                     }
0071                     else timer.running = true;
0072                 }
0073                 Keys.onEscapePressed: if (overlay.sheetOpen) overlay.close()
0074 
0075                 Timer {
0076                     id: timer
0077                     repeat: false
0078                     interval: Math.max(1000, 3000 - urlInput.displayText.length * 1000)
0079                     onTriggered: urlFilter.filter = urlInput.displayText
0080                 }
0081 
0082                 function applyUrl() {
0083                     if (text.match(RegexWebUrl.re_weburl) || text.startsWith("chrome://")) {
0084                         currentWebView.url = UrlUtils.urlFromUserInput(text);
0085                     } else {
0086                         currentWebView.url = UrlUtils.urlFromUserInput(Settings.searchBaseUrl + text);
0087                     }
0088                     overlay.close();
0089                 }
0090             }
0091 
0092             Controls.ToolButton {
0093                 Layout.preferredWidth: buttonSize
0094                 Layout.preferredHeight: buttonSize
0095 
0096                 icon.name: "go-next"
0097 
0098                 Kirigami.Theme.inherit: true
0099 
0100                 onClicked: urlInput.applyUrl();
0101             }
0102         }
0103 
0104         ListView {
0105             id: listView
0106 
0107             anchors {
0108                 bottom: parent.bottom
0109                 left: parent.left
0110                 right: parent.right
0111                 top: editRow.bottom
0112             }
0113 
0114             boundsBehavior: Flickable.StopAtBounds
0115             clip: true
0116 
0117             delegate: UrlDelegate {
0118                 showRemove: false
0119                 onClicked: {
0120                     currentWebView.url = url;
0121                     overlay.close();
0122                 }
0123                 highlightText: urlFilter.filter
0124                 width: parent && parent.width
0125             }
0126 
0127             model: BookmarksHistoryModel {
0128                 id: urlFilter
0129                 active: openedState
0130                 history: true
0131             }
0132         }
0133     }
0134 
0135     onOpened: {
0136         // check if the drawer was just slightly slided
0137         if (openedState) return;
0138         urlInput.text = currentWebView.requestedUrl;
0139         urlInput.forceActiveFocus();
0140         urlInput.selectAll();
0141         urlFilter.filter = "";
0142         openedState = true;
0143         listView.positionViewAtBeginning();
0144     }
0145 
0146     onClosed: {
0147         openedState = false;
0148         currentWebView.forceActiveFocus();
0149     }
0150 }