Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
CyAn84 committed Sep 20, 2024
1 parent 4814f69 commit 6d31502
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 202 deletions.
9 changes: 8 additions & 1 deletion client/ui/controllers/focusController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ void ListViewFocusController::focusNextItem()
qDebug() << "Empty focusChain with current delegate: " << currentDelegate();
m_focusChain = getSubChain(currentDelegate());
}
if (m_focusChain.empty()) {
qWarning() << "Empty ListView";
return;
}
m_focusedItemIndex++;
m_focusedItem = qobject_cast<QQuickItem*>(m_focusChain.at(m_focusedItemIndex));
m_focusedItem->forceActiveFocus();
Expand Down Expand Up @@ -288,6 +292,7 @@ FocusController::FocusController(QQmlApplicationEngine* engine, QObject *parent)
void FocusController::resetFocus()
{
reload();

if (m_focusChain.empty()) {
qWarning() << "There is no focusable elements";
return;
Expand Down Expand Up @@ -401,11 +406,12 @@ void FocusController::nextKeyRightItem()

void FocusController::reload()
{
m_focusChain.clear();
m_focusChain.clear();

QObjectList rootObjects;

const auto rootItem = m_rootItem;
qDebug() << "===>> root item: " << m_rootItem;

if (rootItem != nullptr) {
rootObjects << qobject_cast<QObject*>(rootItem);
Expand Down Expand Up @@ -462,4 +468,5 @@ void FocusController::reload()
void FocusController::setRootItem(QQuickItem* item)
{
m_rootItem = item;
qDebug() << "===>> root item has changed to " << item;
}
20 changes: 1 addition & 19 deletions client/ui/qml/Components/HomeContainersListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,12 @@ ListView {

// property int currentFocusIndex: 0

snapMode: ListView.SnapToItem
// snapMode: ListView.SnapToItem

// ScrollBar.vertical: ScrollBar {}

property bool isFocusable: true

Keys.onTabPressed: {
console.debug("--> Tab is pressed on HomeContainersListView: ", objectName)
FocusController.nextKeyTabItem()
}

Keys.onBacktabPressed: {
console.debug("--> Shift+Tab is pressed on HomeContainersListView: ", objectName)
FocusController.previousKeyTabItem()
}

Keys.onRightPressed: {
FocusController.nextKeyTabItem()
}

Keys.onLeftPressed: {
FocusController.previousKeyTabItem()
}

// activeFocusOnTab: true
// onActiveFocusChanged: {
// console.log("===========================")
Expand Down
2 changes: 2 additions & 0 deletions client/ui/qml/Components/InstalledAppsDrawer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ DrawerType2 {
clip: true
interactive: true

property bool isFocusable: true

model: SortFilterProxyModel {
id: proxyInstalledAppsModel
sourceModel: installedAppsModel
Expand Down
74 changes: 1 addition & 73 deletions client/ui/qml/Components/ServersListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,7 @@ ListView {
policy: root.height >= root.contentHeight ? ScrollBar.AlwaysOff : ScrollBar.AlwaysOn
}

readonly property bool isFocusable: true

// Keys.onTabPressed: {
// FocusController.nextKeyTabItem()
// }

// activeFocusOnTab: true
// focus: true

property int focusItemIndex: 0

// onFocusItemIndexChanged: {
// console.debug("===>> root onFocusItemIndexChanged")

// // const focusedElement = root.itemAtIndex(focusItemIndex)
// // if (focusedElement) {
// // if (focusedElement.y + focusedElement.height > root.height) {
// // root.contentY = focusedElement.y + focusedElement.height - root.height
// // } else {
// // root.contentY = 0
// // }
// // }
// }

Keys.onUpPressed: scrollBar.decrease()
Keys.onDownPressed: scrollBar.increase()

// Connections {
// target: drawer
// enabled: !GC.isMobile()
// function onIsCollapsedChanged() {
// if (drawer.isCollapsedStateActive) {
// const item = root.itemAtIndex(root.focusItemIndex)
// if (item) { item.serverRadioButtonProperty.focus = false }
// }
// }
// }
property bool isFocusable: true

Connections {
target: ServersModel
Expand Down Expand Up @@ -135,7 +99,6 @@ ListView {
enabled: false
}

// Keys.onTabPressed: serverInfoButton.forceActiveFocus()
Keys.onEnterPressed: serverRadioButton.clicked()
Keys.onReturnPressed: serverRadioButton.clicked()
}
Expand All @@ -144,10 +107,6 @@ ListView {
id: serverInfoButton
objectName: "serverInfoButton"

// signal keyTabOnLastElement

// isFocusable: false

image: "qrc:/images/controls/settings.svg"
imageColor: AmneziaStyle.color.paleGray

Expand All @@ -156,41 +115,10 @@ ListView {

z: 1

// onActiveFocusChanged: {
// console.debug("===>> serverInfoButton::activeFocusChanged")

// if (activeFocus) {
// if (currentIndex === root.count - 1) {
// console.log("---> Latest element")
// keyTabOnLastElement()
// }

// console.log("--->>", currentIndex)
// // serverRadioButton.forceActiveFocus()
// }
// }

// onKeyTabOnLastElement: {
// console.log("*** Signal emmited! ***")
// FocusController.nextKeyTabItem()
// }

// Keys.onTabPressed: {
// console.log("===>> serverInfoButton::Keys.onTabPressed")
// if (root.focusItemIndex < root.count - 1) {
// root.focusItemIndex++
// root.itemAtIndex(root.focusItemIndex).forceActiveFocus()
// } else {
// FocusController.nextKeyTabItem()
// root.contentY = 0
// }
// }
Keys.onEnterPressed: serverInfoButton.clicked()
Keys.onReturnPressed: serverInfoButton.clicked()

onClicked: function() {
console.debug("===>> onClicked serverInfoButton")

ServersModel.processedIndex = index
PageController.goToPage(PageEnum.PageSettingsServerInfo)
drawer.closeTriggered()
Expand Down
38 changes: 20 additions & 18 deletions client/ui/qml/Components/SettingsContainersListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ ListView {
clip: true
interactive: false

activeFocusOnTab: true
property bool isFocusable: false

// activeFocusOnTab: true
// Keys.onTabPressed: {
// if (currentIndex < this.count - 1) {
// this.incrementCurrentIndex()
Expand All @@ -32,18 +34,18 @@ ListView {
// }
// }

onCurrentIndexChanged: {
if (visible) {
if (fl.contentHeight > fl.height) {
var item = this.currentItem
if (item.y < fl.height) {
fl.contentY = item.y
} else if (item.y + item.height > fl.contentY + fl.height) {
fl.contentY = item.y + item.height - fl.height
}
}
}
}
// onCurrentIndexChanged: {
// if (visible) {
// if (fl.contentHeight > fl.height) {
// var item = this.currentItem
// if (item.y < fl.height) {
// fl.contentY = item.y
// } else if (item.y + item.height > fl.contentY + fl.height) {
// fl.contentY = item.y + item.height - fl.height
// }
// }
// }
// }

onVisibleChanged: {
if (visible) {
Expand All @@ -55,11 +57,11 @@ ListView {
implicitWidth: root.width
implicitHeight: delegateContent.implicitHeight

onActiveFocusChanged: {
if (activeFocus) {
containerRadioButton.rightButton.forceActiveFocus()
}
}
// onActiveFocusChanged: {
// if (activeFocus) {
// containerRadioButton.rightButton.forceActiveFocus()
// }
// }

ColumnLayout {
id: delegateContent
Expand Down
48 changes: 19 additions & 29 deletions client/ui/qml/Controls2/DropDownType.qml
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,25 @@ Item {
FocusController.nextKeyTabItem()
}

// function popupClosedFunc() {
// if (!GC.isMobile()) {
// this.forceActiveFocus()
// }
// }

// property var parentFlickable
// onFocusChanged: {
// if (root.activeFocus) {
// if (root.parentFlickable) {
// root.parentFlickable.ensureVisible(root)
// }
// }
// }
Keys.onBacktabPressed: {
FocusController.previousKeyTabItem()
}

Keys.onUpPressed: {
FocusController.nextKeyUpItem()
}

Keys.onDownPressed: {
FocusController.nextKeyDownItem()
}

Keys.onLeftPressed: {
FocusController.nextKeyLeftItem()
}

Keys.onRightPressed: {
FocusController.nextKeyRightItem()
}

implicitWidth: rootButtonContent.implicitWidth
implicitHeight: rootButtonContent.implicitHeight
Expand Down Expand Up @@ -171,8 +176,6 @@ Item {
}

ImageButtonType {
// isFocusable: false

Layout.rightMargin: 16

implicitWidth: 40
Expand Down Expand Up @@ -206,10 +209,6 @@ Item {
anchors.fill: parent
expandedHeight: drawerParent.height * drawerHeight

// onClosed: {
// root.popupClosedFunc()
// }

expandedStateContent: Item {
id: container
implicitHeight: menu.expandedHeight
Expand All @@ -226,7 +225,6 @@ Item {
id: backButton
backButtonImage: root.headerBackButtonImage
backButtonFunction: function() { menu.closeTriggered() }
// KeyNavigation.tab: listViewLoader.item
}
}

Expand All @@ -252,14 +250,6 @@ Item {
Loader {
id: listViewLoader
sourceComponent: root.listView

onLoaded: {
// listViewLoader.item.parentFlickable = flickable
// FocusController.reload()
// listViewLoader.item.lastItemTabClicked = function() {
// focusItem.forceActiveFocus()
// }
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions client/ui/qml/Controls2/PageType.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Item {
interval: 500 // Milliseconds
onTriggered: {
FocusController.resetFocus()
// FocusController.setRootItem(null)
}
repeat: false // Stop the timer after one trigger
running: !GC.isMobile() // Start the timer
Expand Down
2 changes: 0 additions & 2 deletions client/ui/qml/Pages2/PageHome.qml
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,6 @@ PageType {
rootWidth: root.width
height: 500 // TODO: make calculated

// isFocusable: false // TODO: this is a workaround. Need to remove it

Connections {
objectName: "rowLayoutConnections"

Expand Down
Loading

0 comments on commit 6d31502

Please sign in to comment.