Warning, /network/angelfish/src/contents/ui/Navigation.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2014-2015 Sebastian Kügler <sebas@kde.org> 0002 // SPDX-FileCopyrightText: 2021 Devin Lin <espidev@gmail.com> 0003 // 0004 // SPDX-License-Identifier: GPL-2.0-or-later 0005 0006 import QtQuick 2.15 0007 import QtQuick.Layouts 1.0 0008 import QtWebEngine 1.4 0009 import QtQuick.Controls 2.0 as Controls 0010 0011 import org.kde.kirigami 2.5 as Kirigami 0012 import org.kde.angelfish 1.0 0013 0014 Item { 0015 id: navigation 0016 0017 height: expandedHeight 0018 0019 property bool navigationShown: true 0020 0021 property int expandedHeight: Kirigami.Units.gridUnit * 3 0022 property int buttonSize: Kirigami.Units.gridUnit * 2 0023 property int gestureThreshold: height * 2 0024 0025 property var tabsSheet 0026 0027 signal activateUrlEntry; 0028 0029 Rectangle { anchors.fill: parent; color: Kirigami.Theme.backgroundColor; } 0030 0031 // left/right gesture icons 0032 Kirigami.Icon { 0033 id: leftGestureIcon 0034 anchors.margins: Kirigami.Units.gridUnit 0035 anchors.left: navigation.left 0036 anchors.top: navigation.top 0037 anchors.bottom: navigation.bottom 0038 implicitWidth: height 0039 0040 opacity: Math.abs(navContainer.x) / gestureThreshold 0041 source: "arrow-left" 0042 transform: Scale { 0043 origin.x: leftGestureIcon.implicitWidth / 2 0044 origin.y: leftGestureIcon.implicitWidth / 2 0045 xScale: Math.max(0, navContainer.x / gestureThreshold) 0046 yScale: Math.max(0, navContainer.x / gestureThreshold) 0047 } 0048 } 0049 Kirigami.Icon { 0050 id: rightGestureIcon 0051 anchors.margins: Kirigami.Units.gridUnit 0052 anchors.right: navigation.right 0053 anchors.top: navigation.top 0054 anchors.bottom: navigation.bottom 0055 implicitWidth: height 0056 0057 opacity: Math.abs(navContainer.x) / gestureThreshold 0058 source: "arrow-right" 0059 transform: Scale { 0060 origin.x: rightGestureIcon.implicitWidth / 2 0061 origin.y: rightGestureIcon.implicitWidth / 2 0062 xScale: Math.max(0, -navContainer.x / gestureThreshold) 0063 yScale: Math.max(0, -navContainer.x / gestureThreshold) 0064 } 0065 } 0066 0067 Item { 0068 id: navContainer 0069 width: navigation.width 0070 height: navigation.height 0071 anchors.bottom: parent.bottom 0072 0073 opacity: 1 - (Math.abs(navContainer.x) / (gestureThreshold * 2)) 0074 0075 // left/right gestures 0076 HapticsEffectLoader { 0077 id: vibrate 0078 } 0079 DragHandler { 0080 id: dragHandler 0081 target: parent 0082 yAxis.enabled: false 0083 xAxis.enabled: true 0084 xAxis.minimum: currentWebView.canGoForward ? -gestureThreshold : 0 0085 xAxis.maximum: currentWebView.canGoBack ? gestureThreshold : 0 0086 onActiveChanged: { 0087 xAnimator.restart(); // go back to center 0088 0089 if (parent.x >= gestureThreshold && currentWebView.canGoBack) { 0090 currentWebView.goBack() 0091 } else if (parent.x <= -gestureThreshold && currentWebView.canGoForward) { 0092 currentWebView.goForward() 0093 } 0094 } 0095 } 0096 NumberAnimation on x { 0097 id: xAnimator 0098 running: !dragHandler.active 0099 duration: Kirigami.Units.longDuration 0100 easing.type: Easing.InOutQuad 0101 to: 0 0102 } 0103 onXChanged: { 0104 if ((x >= gestureThreshold && currentWebView.canGoBack) || (x <= -gestureThreshold && currentWebView.canGoForward)) { 0105 vibrate.start(); 0106 } 0107 } 0108 0109 RowLayout { 0110 id: layout 0111 anchors.fill: parent 0112 anchors.leftMargin: Kirigami.Units.gridUnit / 2 0113 anchors.rightMargin: Kirigami.Units.gridUnit / 2 0114 0115 spacing: Kirigami.Units.smallSpacing 0116 Kirigami.Theme.inherit: true 0117 0118 Controls.ToolButton { 0119 id: mainMenuButton 0120 icon.name: rootPage.privateMode ? "view-private" : "application-menu" 0121 visible: webBrowser.landscape || Settings.navBarMainMenu 0122 0123 Layout.preferredWidth: buttonSize 0124 Layout.preferredHeight: buttonSize 0125 0126 Kirigami.Theme.inherit: true 0127 0128 onClicked: globalDrawer.open() 0129 } 0130 0131 Controls.ToolButton { 0132 visible: webBrowser.landscape || Settings.navBarTabs 0133 Layout.preferredWidth: buttonSize 0134 Layout.preferredHeight: buttonSize 0135 0136 Rectangle { 0137 anchors.centerIn: parent 0138 height: Kirigami.Units.gridUnit * 1.25 0139 width: Kirigami.Units.gridUnit * 1.25 0140 0141 color: "transparent" 0142 border.color: Kirigami.Theme.textColor 0143 border.width: Kirigami.Units.gridUnit / 10 0144 radius: Kirigami.Units.gridUnit / 5 0145 0146 Kirigami.Theme.inherit: true 0147 0148 Controls.Label { 0149 anchors.centerIn: parent 0150 height: Kirigami.Units.gridUnit 0151 width: Kirigami.Units.gridUnit 0152 fontSizeMode: Text.Fit 0153 minimumPixelSize: 0 0154 minimumPointSize: 0 0155 clip: true 0156 text: "%1".arg(tabs.count) 0157 horizontalAlignment: Text.AlignHCenter 0158 verticalAlignment: Text.AlignVCenter 0159 Kirigami.Theme.inherit: true 0160 } 0161 } 0162 0163 onClicked: tabsSheet.open() 0164 } 0165 0166 Controls.ToolButton { 0167 id: backButton 0168 0169 Layout.preferredWidth: buttonSize 0170 Layout.preferredHeight: buttonSize 0171 0172 visible: currentWebView.canGoBack && Settings.navBarBack 0173 icon.name: "go-previous" 0174 0175 Kirigami.Theme.inherit: true 0176 0177 onClicked: currentWebView.goBack() 0178 onPressAndHold: { 0179 historySheet.backHistory = true; 0180 historySheet.open(); 0181 } 0182 } 0183 0184 Controls.ToolButton { 0185 id: forwardButton 0186 0187 Layout.preferredWidth: buttonSize 0188 Layout.preferredHeight: buttonSize 0189 0190 visible: currentWebView.canGoForward && Settings.navBarForward 0191 icon.name: "go-next" 0192 0193 Kirigami.Theme.inherit: true 0194 0195 onClicked: currentWebView.goForward() 0196 onPressAndHold: { 0197 historySheet.backHistory = false; 0198 historySheet.open(); 0199 } 0200 } 0201 0202 Controls.ToolButton { 0203 id: labelItem 0204 Layout.fillWidth: true 0205 Layout.preferredHeight: buttonSize 0206 0207 property string scheme: UrlUtils.urlScheme(currentWebView.requestedUrl) 0208 0209 Controls.ToolButton { 0210 id: schemeIcon 0211 anchors.left: parent.left 0212 anchors.verticalCenter: parent.verticalCenter 0213 icon.name: { 0214 if (labelItem.scheme === "https") return "lock"; 0215 if (labelItem.scheme === "http") return "unlock"; 0216 return ""; 0217 } 0218 visible: icon.name 0219 height: buttonSize * 0.75 0220 width: visible ? buttonSize * 0.75 : 0 0221 Kirigami.Theme.inherit: true 0222 background: Rectangle { 0223 implicitWidth: schemeIcon.width 0224 implicitHeight: schemeIcon.height 0225 color: "transparent" 0226 } 0227 onClicked: activateUrlEntry() 0228 } 0229 0230 Controls.Label { 0231 anchors.left: schemeIcon.right 0232 anchors.right: parent.right 0233 anchors.top: parent.top 0234 height: parent.height 0235 0236 text: { 0237 if (labelItem.scheme === "http" || labelItem.scheme === "https") { 0238 return UrlUtils.htmlFormattedUrl(currentWebView.requestedUrl) 0239 } 0240 return currentWebView.requestedUrl; 0241 } 0242 textFormat: Text.StyledText 0243 elide: Text.ElideRight 0244 verticalAlignment: Text.AlignVCenter 0245 Kirigami.Theme.inherit: true 0246 } 0247 0248 onClicked: activateUrlEntry() 0249 } 0250 0251 Controls.ToolButton { 0252 id: reloadButton 0253 0254 Layout.preferredWidth: buttonSize 0255 Layout.preferredHeight: buttonSize 0256 0257 visible: Settings.navBarReload 0258 icon.name: currentWebView.loading ? "process-stop" : "view-refresh" 0259 0260 Kirigami.Theme.inherit: true 0261 0262 onClicked: currentWebView.loading ? currentWebView.stopLoading() : currentWebView.reload() 0263 0264 } 0265 0266 Controls.ToolButton { 0267 id: optionsButton 0268 0269 property string targetState: "overview" 0270 0271 Layout.fillWidth: false 0272 Layout.preferredWidth: buttonSize 0273 Layout.preferredHeight: buttonSize 0274 0275 visible: webBrowser.landscape || Settings.navBarContextMenu 0276 icon.name: "overflow-menu" 0277 0278 Kirigami.Theme.inherit: true 0279 0280 onClicked: contextDrawer.open() 0281 } 0282 } 0283 } 0284 0285 states: [ 0286 State { 0287 name: "shown" 0288 when: navigationShown 0289 AnchorChanges { 0290 target: navigation 0291 anchors.bottom: navigation.parent.bottom 0292 anchors.top: undefined 0293 } 0294 }, 0295 State { 0296 name: "hidden" 0297 when: !navigationShown 0298 AnchorChanges { 0299 target: navigation 0300 anchors.bottom: undefined 0301 anchors.top: navigation.parent.bottom 0302 } 0303 } 0304 ] 0305 transitions: Transition { 0306 AnchorAnimation { 0307 duration: navigation.visible ? Kirigami.Units.longDuration : 0 0308 } 0309 } 0310 }