Warning, /plasma/aura-browser/app/qml/main.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2022 Aditya Mehra <aix.m@outlook.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 2.12 0008 import QtQuick.Window 2.12 0009 import QtQuick.Layouts 1.12 0010 import QtWebEngine 1.7 0011 import QtQuick.Controls 2.12 as Controls 0012 import QtQuick.LocalStorage 2.12 0013 import "views" as Views 0014 import "delegates" as Delegates 0015 import "code/RecentStorage.js" as RecentStorage 0016 import "code/BookmarkStorage.js" as BookmarkStorage 0017 import "code/Utils.js" as Utils 0018 import Aura 1.0 as Aura 0019 import QtQuick.VirtualKeyboard 0020 import QtQuick.VirtualKeyboard.Settings 0021 import Qt5Compat.GraphicalEffects 0022 import org.kde.kirigami as Kirigami 0023 0024 Kirigami.AbstractApplicationWindow { 0025 id: root 0026 visible: true 0027 width: Screen.desktopAvailableWidth 0028 height: Screen.desktopAvailableHeight 0029 title: i18n("Aura-Browser") 0030 property alias showStack: auraStack.currentIndex 0031 property int virtualMouseMoveSpeed: 10 0032 signal settingsTabRequested 0033 signal blurFieldRequested 0034 signal mouseActivationRequested 0035 signal mouseDeActivationRequested 0036 signal ignoreInputRequested 0037 visibility: "FullScreen" 0038 0039 onClosing: { 0040 auraStack.destroy() 0041 } 0042 0043 function switchToTab(index){ 0044 auraStack.currentIndex = index 0045 } 0046 0047 function removeFromTabView(index){ 0048 tabBarViewModel.remove(index); 0049 auraStack.currentIndex = 0; 0050 } 0051 0052 function removeTab(){ 0053 auraStack.itemAt(tabsListView.currentIndex).toRemove = true; 0054 } 0055 0056 function createTab(url){ 0057 var gencolor = Utils.genRandomColor() 0058 var tcolor = gencolor.toString() 0059 var cpm = Qt.createComponent("WebLoader.qml"); 0060 if (cpm.status == Component.Ready) { 0061 var tpm = cpm.createObject(auraStack, {pageUrl: url}); 0062 tpm.pageUrl = url 0063 tabBarViewModel.append({"pageName": url, "rand_color": tcolor, "removable": true}) 0064 showStack = auraStack.count - 1 0065 } 0066 } 0067 0068 function prependStartPage(){ 0069 var gencolor = Utils.genRandomColor() 0070 var tcolor = gencolor.toString() 0071 var spm = Qt.createComponent("StartPage.qml") 0072 if(spm.status == Component.Ready){ 0073 var spmi = spm.createObject(auraStack, {}); 0074 tabBarViewModel.append({"pageName": "Start Page", "rand_color": tcolor, "removable": false}) 0075 showStack = auraStack.count - 1 0076 } 0077 } 0078 0079 globalDrawer: Kirigami.GlobalDrawer { 0080 id: gDrawer 0081 handleVisible: false 0082 0083 onOpened: { 0084 quitButton.forceActiveFocus(); 0085 } 0086 0087 Controls.Label { 0088 id: bblabl 0089 text: i18n("Press 'esc' or the [←] Back button to close") 0090 color: Kirigami.Theme.textColor 0091 Layout.alignment: Qt.AlignRight 0092 } 0093 0094 Kirigami.Separator { 0095 Layout.fillWidth: true 0096 Layout.preferredHeight: 1 0097 } 0098 0099 Controls.Button { 0100 id: quitButton 0101 Layout.fillWidth: true 0102 Layout.preferredHeight: Kirigami.Units.gridUnit * 4 0103 KeyNavigation.down: closeMenuButton 0104 0105 background: Rectangle { 0106 color: quitButton.activeFocus ? Kirigami.Theme.highlightColor : Kirigami.Theme.backgroundColor 0107 border.color: Kirigami.Theme.disabledTextColor 0108 } 0109 0110 contentItem: RowLayout { 0111 Kirigami.Icon { 0112 source: "window-close" 0113 Layout.preferredWidth: Kirigami.Units.iconSizes.medium 0114 Layout.preferredHeight: Kirigami.Units.iconSizes.medium 0115 } 0116 0117 Controls.Label { 0118 Layout.fillWidth: true 0119 color: Kirigami.Theme.textColor 0120 text: "Quit" 0121 } 0122 } 0123 0124 onClicked: (mouse)=> { 0125 root.close(); 0126 } 0127 0128 Keys.onReturnPressed: (event)=> { 0129 root.close(); 0130 } 0131 } 0132 Controls.Button { 0133 id: closeMenuButton 0134 Layout.fillWidth: true 0135 Layout.preferredHeight: Kirigami.Units.gridUnit * 4 0136 KeyNavigation.up: quitButton 0137 0138 background: Rectangle { 0139 color: closeMenuButton.activeFocus ? Kirigami.Theme.highlightColor : Kirigami.Theme.backgroundColor 0140 border.color: Kirigami.Theme.disabledTextColor 0141 } 0142 0143 contentItem: RowLayout { 0144 Kirigami.Icon { 0145 source: "application-menu" 0146 Layout.preferredWidth: Kirigami.Units.iconSizes.medium 0147 Layout.preferredHeight: Kirigami.Units.iconSizes.medium 0148 } 0149 0150 Controls.Label { 0151 Layout.fillWidth: true 0152 color: Kirigami.Theme.textColor 0153 text: i18n("Close Menu") 0154 } 0155 } 0156 0157 onClicked: (mouse)=> { 0158 gDrawer.close(); 0159 } 0160 0161 Keys.onReturnPressed: (event)=> { 0162 gDrawer.close(); 0163 } 0164 } 0165 } 0166 0167 ListModel { 0168 id: tabBarViewModel 0169 } 0170 0171 ListModel { 0172 id: bookmarksModel 0173 } 0174 0175 StackLayout { 0176 id: auraStack 0177 anchors.fill: parent 0178 currentIndex: tabsListView.currentIndex 0179 } 0180 0181 Controls.Drawer { 0182 id: tabBarView 0183 width: parent.width 0184 height: parent.height / 3 0185 edge: Qt.TopEdge 0186 interactive: true 0187 dragMargin: 0 0188 0189 onOpened: { 0190 tabsListView.forceActiveFocus() 0191 auraStack.itemAt(auraStack.currentIndex).focus = false 0192 } 0193 0194 onClosed: { 0195 auraStack.itemAt(auraStack.currentIndex).focus = true 0196 } 0197 0198 background: Rectangle { 0199 color: Kirigami.Theme.backgroundColor 0200 layer.enabled: true 0201 layer.effect: DropShadow { 0202 horizontalOffset: 0 0203 verticalOffset: 2 0204 radius: 8.0 0205 samples: 17 0206 color: Qt.rgba(0,0,0,0.6) 0207 } 0208 } 0209 0210 Rectangle { 0211 anchors.fill: parent 0212 anchors.margins: Kirigami.Units.largeSpacing 0213 color: Kirigami.Theme.backgroundColor 0214 0215 RowLayout { 0216 id: tabLblView 0217 anchors.top: parent.top 0218 anchors.topMargin: Kirigami.Units.smallSpacing 0219 anchors.left: parent.left 0220 anchors.right: parent.right 0221 0222 Views.LabelView { 0223 title: i18n("Current Tabs") 0224 } 0225 0226 Controls.Label { 0227 id: backbtnlabelHeading 0228 text: i18n("Press 'esc' or the [←] Back button to close") 0229 color: Kirigami.Theme.textColor 0230 Layout.alignment: Qt.AlignRight 0231 } 0232 } 0233 0234 Kirigami.Separator { 0235 id: headrSeptTml 0236 anchors.top: tabLblView.bottom 0237 width: parent.width 0238 height: 1 0239 } 0240 0241 Views.TileViewTabs{ 0242 id: tabsListView 0243 model: tabBarViewModel 0244 anchors.top: headrSeptTml.bottom 0245 anchors.left: parent.left 0246 anchors.right: parent.right 0247 anchors.bottom: tabCtrlArea.top 0248 navigationDown: tabRemoveBtn 0249 currentIndex: auraStack.currentIndex 0250 0251 delegate: Delegates.TabDelegate {} 0252 0253 onCurrentItemChanged: { 0254 auraStack.currentIndex = tabsListView.currentIndex 0255 } 0256 } 0257 0258 RowLayout { 0259 id: tabCtrlArea 0260 anchors.bottom: parent.bottom 0261 anchors.left: parent.left 0262 anchors.right: parent.right 0263 height: Kirigami.Units.gridUnit * 3 0264 0265 Controls.Button { 0266 id: tabRemoveBtn 0267 Layout.fillWidth: true 0268 Layout.fillHeight: true 0269 text: i18n("Remove Tab") 0270 palette.buttonText: Kirigami.Theme.textColor 0271 KeyNavigation.up: tabsListView 0272 0273 background: Rectangle { 0274 color: tabRemoveBtn.activeFocus ? Kirigami.Theme.highlightColor : Qt.lighter(Kirigami.Theme.backgroundColor, 1.2) 0275 border.color: Kirigami.Theme.disabledTextColor 0276 radius: 20 0277 } 0278 0279 onClicked: (mouse)=> { 0280 Aura.NavigationSoundEffects.playClickedSound() 0281 if(tabsListView.currentItem.isRemovable){ 0282 removeTab() 0283 } else { 0284 console.log("Not Removable Item") 0285 } 0286 } 0287 0288 Keys.onReturnPressed: (event)=> { 0289 Aura.NavigationSoundEffects.playClickedSound() 0290 if(tabsListView.currentItem.isRemovable){ 0291 removeTab() 0292 } else { 0293 console.log("Not Removable Item") 0294 } 0295 } 0296 0297 Keys.onPressed: (event)=> { 0298 switch (event.key) { 0299 case Qt.Key_Down: 0300 case Qt.Key_Right: 0301 case Qt.Key_Left: 0302 case Qt.Key_Up: 0303 case Qt.Key_Tab: 0304 case Qt.Key_Backtab: 0305 Aura.NavigationSoundEffects.playMovingSound(); 0306 break; 0307 default: 0308 break; 0309 } 0310 } 0311 } 0312 } 0313 } 0314 } 0315 0316 Component.onCompleted: { 0317 Cursor.setStep(Aura.GlobalSettings.virtualMouseSpeed); 0318 if(Aura.GlobalSettings.firstRun){ 0319 RecentStorage.dbInit(); 0320 BookmarkStorage.dbInit(); 0321 BookmarkStorage.prePopulateBookmarks(); 0322 Aura.GlobalSettings.setFirstRun(false); 0323 } 0324 prependStartPage(); 0325 } 0326 0327 Connections { 0328 target: Aura.GlobalSettings 0329 function onFocusOnVKeyboard() { 0330 mouseDeActivationRequested(); 0331 } 0332 function onFocusOffVKeyboard() { 0333 ignoreInputRequested(); 0334 } 0335 } 0336 0337 UrlEntryBox { 0338 id: urlEntryBox 0339 } 0340 0341 InputPanel { 0342 id: inputPanel 0343 z: 99 0344 x: 0 0345 y: root.height 0346 width: urlEntryBox.opened ? urlEntryBox.contentItem.width : root.width 0347 parent: urlEntryBox.opened ? urlEntryBox.contentItem : root.contentItem 0348 0349 onActiveChanged: { 0350 if(!active){ 0351 keyFilter.startFilter(); 0352 mouseActivationRequested() 0353 blurFieldRequested(); 0354 } else { 0355 keyFilter.stopFilter(); 0356 } 0357 } 0358 0359 states: State { 0360 name: "visible" 0361 when: inputPanel.active 0362 PropertyChanges { 0363 target: inputPanel 0364 y: parent.height - inputPanel.height 0365 } 0366 } 0367 0368 transitions: Transition { 0369 from: "" 0370 to: "visible" 0371 reversible: true 0372 ParallelAnimation { 0373 NumberAnimation { 0374 properties: "y" 0375 duration: 250 0376 easing.type: Easing.InOutQuad 0377 } 0378 } 0379 } 0380 } 0381 }