add focusController class

This commit is contained in:
Cyril Anisimov 2024-09-14 19:42:55 +02:00
parent 8547de82ea
commit 02bbcd3a31
76 changed files with 1906 additions and 1576 deletions

View file

@ -18,8 +18,6 @@ import "../Config"
PageType {
id: root
defaultActiveFocusItem: clientNameTextField.textField
enum ConfigType {
AmneziaConnection,
OpenVpn,
@ -47,7 +45,7 @@ PageType {
shareConnectionDrawer.headerText = qsTr("Connection to ") + serverSelector.text
shareConnectionDrawer.configContentHeaderText = qsTr("File with connection settings to ") + serverSelector.text
shareConnectionDrawer.open()
shareConnectionDrawer.
shareConnectionDrawer.contentVisible = false
PageController.showBusyIndicator(true)
@ -104,7 +102,7 @@ PageType {
}
function onExportErrorOccurred(error) {
shareConnectionDrawer.close()
shareConnectionDrawer.closeTriggered()
PageController.showErrorMessage(error)
}
@ -172,16 +170,6 @@ PageType {
spacing: 0
Item {
id: focusItem
KeyNavigation.tab: header.actionButton
onFocusChanged: {
if (focusItem.activeFocus) {
a.contentY = 0
}
}
}
HeaderType {
id: header
Layout.fillWidth: true
@ -191,10 +179,18 @@ PageType {
actionButtonImage: "qrc:/images/controls/more-vertical.svg"
actionButtonFunction: function() {
shareFullAccessDrawer.open()
shareFullAccessDrawer.openTriggered()
}
KeyNavigation.tab: connectionRadioButton
// KeyNavigation.tab: connectionRadioButton
actionButton.onFocusChanged: {
console.debug("MOVE THIS LOGIC TO CPP!")
if (actionButton.activeFocus) {
if (fl) {
fl.ensureVisible(moreButton)
}
}
}
DrawerType2 {
id: shareFullAccessDrawer
@ -205,11 +201,11 @@ PageType {
expandedHeight: root.height
onClosed: {
if (!GC.isMobile()) {
clientNameTextField.textField.forceActiveFocus()
// clientNameTextField.textField.forceActiveFocus()
}
}
expandedContent: ColumnLayout {
expandedStateContent: ColumnLayout {
id: shareFullAccessDrawerContent
anchors.top: parent.top
anchors.left: parent.left
@ -226,7 +222,7 @@ PageType {
target: shareFullAccessDrawer
enabled: !GC.isMobile()
function onOpened() {
focusItem.forceActiveFocus()
// focusItem.forceActiveFocus()
}
}
@ -240,10 +236,10 @@ PageType {
descriptionText: qsTr("Use for your own devices, or share with those you trust to manage the server.")
}
Item {
id: focusItem
KeyNavigation.tab: shareFullAccessButton.rightButton
}
// Item {
// id: focusItem
// // KeyNavigation.tab: shareFullAccessButton.rightButton
// }
LabelWithButtonType {
id: shareFullAccessButton
@ -251,11 +247,11 @@ PageType {
text: qsTr("Share")
rightImageSource: "qrc:/images/controls/chevron-right.svg"
KeyNavigation.tab: focusItem
// KeyNavigation.tab: focusItem
clickedFunction: function() {
PageController.goToPage(PageEnum.PageShareFullAccess)
shareFullAccessDrawer.close()
shareFullAccessDrawer.closeTriggered()
}
}
@ -288,12 +284,12 @@ PageType {
implicitWidth: (root.width - 32) / 2
text: qsTr("Connection")
KeyNavigation.tab: usersRadioButton
// KeyNavigation.tab: usersRadioButton
onClicked: {
accessTypeSelector.currentIndex = 0
if (!GC.isMobile()) {
clientNameTextField.textField.forceActiveFocus()
// clientNameTextField.textField.forceActiveFocus()
}
}
}
@ -305,7 +301,7 @@ PageType {
implicitWidth: (root.width - 32) / 2
text: qsTr("Users")
KeyNavigation.tab: accessTypeSelector.currentIndex === 0 ? clientNameTextField.textField : serverSelector
// KeyNavigation.tab: accessTypeSelector.currentIndex === 0 ? clientNameTextField.textField : serverSelector
onClicked: {
accessTypeSelector.currentIndex = 1
@ -313,7 +309,7 @@ PageType {
ExportController.updateClientManagementModel(ContainersModel.getProcessedContainerIndex(),
ServersModel.getProcessedServerCredentials())
PageController.showBusyIndicator(false)
focusItem.forceActiveFocus()
// focusItem.forceActiveFocus()
}
}
}
@ -343,7 +339,7 @@ PageType {
checkEmptyText: true
KeyNavigation.tab: serverSelector
// KeyNavigation.tab: serverSelector
}
@ -390,7 +386,7 @@ PageType {
serverSelector.severSelectorIndexChanged()
}
serverSelector.close()
serverSelector.closeTriggered()
}
Component.onCompleted: {
@ -409,7 +405,7 @@ PageType {
}
}
KeyNavigation.tab: protocolSelector
// KeyNavigation.tab: protocolSelector
}
DropDownType {
@ -450,7 +446,7 @@ PageType {
clickedFunction: function() {
handler()
protocolSelector.close()
protocolSelector.closeTriggered()
}
Connections {
@ -509,11 +505,11 @@ PageType {
}
}
KeyNavigation.tab: accessTypeSelector.currentIndex === 0 ?
exportTypeSelector :
isSearchBarVisible ?
searchTextField.textField :
usersHeader.actionButton
// KeyNavigation.tab: accessTypeSelector.currentIndex === 0 ?
// exportTypeSelector : searchTextField.textField
// isSearchBarVisible ?
// searchTextField.textField :
// usersHeader.actionButton
}
DropDownType {
@ -549,7 +545,7 @@ PageType {
clickedFunction: function() {
exportTypeSelector.text = selectedText
exportTypeSelector.currentIndex = currentIndex
exportTypeSelector.close()
exportTypeSelector.closeTriggered()
}
Component.onCompleted: {
@ -558,7 +554,7 @@ PageType {
}
}
KeyNavigation.tab: shareButton
// KeyNavigation.tab: shareButton
}
@ -622,11 +618,11 @@ PageType {
target: root
function onIsSearchBarVisibleChanged() {
if (root.isSearchBarVisible) {
searchTextField.textField.forceActiveFocus()
// searchTextField.textField.forceActiveFocus()
} else {
searchTextField.textFieldText = ""
if (!GC.isMobile()) {
usersHeader.actionButton.forceActiveFocus()
// usersHeader.actionButton.forceActiveFocus()
}
}
}
@ -638,15 +634,15 @@ PageType {
function navigateTo() {
if (GC.isMobile()) {
focusItem.forceActiveFocus()
// focusItem.forceActiveFocus()
return;
}
if (searchTextField.textFieldText === "") {
root.isSearchBarVisible = false
usersHeader.actionButton.forceActiveFocus()
// usersHeader.actionButton.forceActiveFocus()
} else {
closeSearchButton.forceActiveFocus()
// closeSearchButton.forceActiveFocus()
}
}
@ -663,9 +659,9 @@ PageType {
Keys.onTabPressed: {
if (!GC.isMobile()) {
if (clientsListView.model.count > 0) {
clientsListView.forceActiveFocus()
// clientsListView.forceActiveFocus()
} else {
lastItemTabClicked(focusItem)
// lastItemTabClicked(focusItem)
}
}
}
@ -706,10 +702,10 @@ PageType {
if (!GC.isMobile()) {
if (currentIndex < this.count - 1) {
this.incrementCurrentIndex()
currentItem.focusItem.forceActiveFocus()
// currentItem.focusItem.forceActiveFocus()
} else {
this.currentIndex = 0
lastItemTabClicked(focusItem)
// lastItemTabClicked(focusItem)
}
}
}
@ -717,7 +713,7 @@ PageType {
onActiveFocusChanged: {
if (focus && !GC.isMobile()) {
currentIndex = 0
currentItem.focusItem.forceActiveFocus()
// currentItem.focusItem.forceActiveFocus()
}
}
@ -735,7 +731,7 @@ PageType {
implicitWidth: clientsListView.width
implicitHeight: delegateContent.implicitHeight
property alias focusItem: clientFocusItem.rightButton
// property alias focusItem: clientFocusItem.rightButton
ColumnLayout {
id: delegateContent
@ -755,7 +751,7 @@ PageType {
rightImageSource: "qrc:/images/controls/chevron-right.svg"
clickedFunction: function() {
clientInfoDrawer.open()
clientInfoDrawer.openTriggered()
}
}
@ -768,15 +764,15 @@ PageType {
onClosed: {
if (!GC.isMobile()) {
focusItem.forceActiveFocus()
// focusItem.forceActiveFocus()
}
}
width: root.width
height: root.height
expandedContent: ColumnLayout {
id: expandedContent
expandedStateContent: ColumnLayout {
id: expandedStateContent
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
@ -785,14 +781,14 @@ PageType {
anchors.rightMargin: 16
onImplicitHeightChanged: {
clientInfoDrawer.expandedHeight = expandedContent.implicitHeight + 32
clientInfoDrawer.expandedHeight = expandedStateContent.implicitHeight + 32
}
Connections {
target: clientInfoDrawer
enabled: !GC.isMobile()
function onOpened() {
focusItem1.forceActiveFocus()
// focusItem1.forceActiveFocus()
}
}
@ -846,11 +842,6 @@ PageType {
text: qsTr("Allowed IPs: %1").arg(allowedIps)
}
Item {
id: focusItem1
KeyNavigation.tab: renameButton
}
BasicButtonType {
id: renameButton
Layout.fillWidth: true
@ -865,10 +856,10 @@ PageType {
text: qsTr("Rename")
KeyNavigation.tab: revokeButton
// KeyNavigation.tab: revokeButton
clickedFunc: function() {
clientNameEditDrawer.open()
clientNameEditDrawer.openTriggered()
}
DrawerType2 {
@ -881,11 +872,11 @@ PageType {
onClosed: {
if (!GC.isMobile()) {
focusItem1.forceActiveFocus()
// focusItem1.forceActiveFocus()
}
}
expandedContent: ColumnLayout {
expandedStateContent: ColumnLayout {
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
@ -897,15 +888,10 @@ PageType {
target: clientNameEditDrawer
enabled: !GC.isMobile()
function onOpened() {
clientNameEditor.textField.forceActiveFocus()
// clientNameEditor.textField.forceActiveFocus()
}
}
Item {
id: focusItem2
KeyNavigation.tab: clientNameEditor.textField
}
TextFieldWithHeaderType {
id: clientNameEditor
Layout.fillWidth: true
@ -914,7 +900,7 @@ PageType {
textField.maximumLength: 20
checkEmptyText: true
KeyNavigation.tab: saveButton
// KeyNavigation.tab: saveButton
}
BasicButtonType {
@ -923,7 +909,7 @@ PageType {
Layout.fillWidth: true
text: qsTr("Save")
KeyNavigation.tab: focusItem2
// KeyNavigation.tab: focusItem2
clickedFunc: function() {
if (clientNameEditor.textFieldText === "") {
@ -937,7 +923,7 @@ PageType {
ContainersModel.getProcessedContainerIndex(),
ServersModel.getProcessedServerCredentials())
PageController.showBusyIndicator(false)
clientNameEditDrawer.close()
clientNameEditDrawer.closeTriggered()
}
}
}
@ -958,7 +944,7 @@ PageType {
borderWidth: 1
text: qsTr("Revoke")
KeyNavigation.tab: focusItem1
// KeyNavigation.tab: focusItem1
clickedFunc: function() {
var headerText = qsTr("Revoke the config for a user - %1?").arg(clientName)
@ -967,12 +953,12 @@ PageType {
var noButtonText = qsTr("Cancel")
var yesButtonFunction = function() {
clientInfoDrawer.close()
clientInfoDrawer.closeTriggered()
root.revokeConfig(index)
}
var noButtonFunction = function() {
if (!GC.isMobile()) {
focusItem1.forceActiveFocus()
// focusItem1.forceActiveFocus()
}
}
@ -993,7 +979,7 @@ PageType {
anchors.fill: parent
onClosed: {
if (!GC.isMobile()) {
clientNameTextField.textField.forceActiveFocus()
// clientNameTextField.textField.forceActiveFocus()
}
}
}
@ -1001,7 +987,7 @@ PageType {
MouseArea {
anchors.fill: parent
onPressed: function(mouse) {
forceActiveFocus()
// forceActiveFocus()
mouse.accepted = false
}
}