diff --git a/client/ui/controllers/focusController.cpp b/client/ui/controllers/focusController.cpp index 58e33c7e..7e2f79d3 100644 --- a/client/ui/controllers/focusController.cpp +++ b/client/ui/controllers/focusController.cpp @@ -18,7 +18,6 @@ bool isVisible(QObject* item) bool isFocusable(QObject* item) { const auto res = item->property("isFocusable").toBool(); - // qDebug() << "==>> " << (res ? "FOCUSABLE" : "NOT focusable") << item; return res; } @@ -60,28 +59,23 @@ bool isOnTheScene(QObject* object) return false; } - QRectF itemRect{}; // TODO: ListView couln't get into list because it's children's rect is too large - // if (isListView(item)) { - // itemRect = QRectF(item->x(), item->y(), item->width(), item->height()); - // } else { - itemRect = item->mapRectToScene(item->childrenRect()); - // } + QRectF itemRect = item->mapRectToScene(item->childrenRect()); + QQuickWindow* window = item->window(); if (!window) { qWarning() << "Couldn't get the window on the Scene check"; return false; } - // const auto contentItem = window->contentItem(); - // if (!contentItem) { - // qWarning() << "Couldn't get the content item on the Scene check"; - // return false; - // } - // QRectF windowRect = contentItem->childrenRect(); - // const auto res = (windowRect.contains(itemRect) || isListView(item)); - // // qDebug() << (res ? "===>> item is inside the Scene" : "===>> ITEM IS OUTSIDE THE SCENE") << " itemRect: " << itemRect << "; windowRect: " << windowRect; - // return res; - return true; + const auto contentItem = window->contentItem(); + if (!contentItem) { + qWarning() << "Couldn't get the content item on the Scene check"; + return false; + } + QRectF windowRect = contentItem->childrenRect(); + const auto res = (windowRect.contains(itemRect) || isListView(item)); + // qDebug() << (res ? "===>> item is inside the Scene" : "===>> ITEM IS OUTSIDE THE SCENE") << " itemRect: " << itemRect << "; windowRect: " << windowRect; + return res; } bool isEnabled(QObject* obj) @@ -98,7 +92,6 @@ QQuickItem* getPageOfItem(QQuickItem* item) // TODO: remove? } const auto pagePattern = QString::fromLatin1("Page"); QString className{item->metaObject()->className()}; - qDebug() << "=====================>> Item: " << item << " with name: " << item->metaObject()->className(); const auto isPage = className.contains(pagePattern, Qt::CaseSensitive); if(isPage) { return item; @@ -122,9 +115,7 @@ QList getSubChain(QObject* item) && isEnabled(child) ) { res.append(child); - // qDebug() << "==>> [*** added ***] " << qobject_cast(child); } else { - // qDebug() << "==>> [** skipped **] " << qobject_cast(child); res.append(getSubChain(child)); } } @@ -134,14 +125,12 @@ QList getSubChain(QObject* item) template void printItems(const T& items, QObject* current_item) { - qDebug() << "**********************************************"; for(const auto& item : items) { QQuickItem* i = qobject_cast(item); QPointF coords {getItemCenterPointOnScene(i)}; QString prefix = current_item == i ? "==>" : " "; - qDebug() << prefix << " Item: " << i << " with coords: " << coords; + // qDebug() << prefix << " Item: " << i << " with coords: " << coords; // Uncomment to visualize tab transitions } - qDebug() << "**********************************************"; } /*! @@ -308,7 +297,7 @@ void FocusController::resetFocus() void FocusController::nextKeyTabItem() { if (m_lvfc) { - focusNextListViewItem(); // Need to go on first element by default? + focusNextListViewItem(); return; } @@ -335,7 +324,6 @@ void FocusController::nextKeyTabItem() } if(isListView(m_focusedItem)) { - qDebug() << "===>> Found ListView Item: " << m_focusedItem; // TODO: remove? m_lvfc = new ListViewFocusController(m_focusedItem, this); focusNextListViewItem(); return; @@ -387,22 +375,22 @@ void FocusController::previousKeyTabItem() void FocusController::nextKeyUpItem() { - qDebug() << "nextKeyUpItem" << "triggered"; + previousKeyTabItem(); } void FocusController::nextKeyDownItem() { - qDebug() << "nextKeyDownItem" << "triggered"; + nextKeyTabItem(); } void FocusController::nextKeyLeftItem() { - qDebug() << "nextKeyLeftItem" << "triggered"; + previousKeyTabItem(); } void FocusController::nextKeyRightItem() { - qDebug() << "nextKeyRightItem" << "triggered"; + nextKeyTabItem(); } void FocusController::reload() @@ -414,10 +402,8 @@ void FocusController::reload() const auto rootItem = m_rootItem; if (rootItem != nullptr) { - qDebug() << "*** root item: " << rootItem; rootObjects << qobject_cast(rootItem); } else { - qDebug() << "*** root item is null"; rootObjects = m_engine->rootObjects(); } @@ -453,14 +439,10 @@ void FocusController::reload() return; } - // qDebug() << "==> Active Focused Item: " << window->activeFocusItem(); - // qDebug() << "--> Active Focused Object: " << window->focusObject(); - // qDebug() << ">>> Current Focused Item: " << m_focused_item; - m_focusedItemIndex = m_focusChain.indexOf(window->activeFocusItem()); if(m_focusedItemIndex == -1) { - qDebug() << "===>> No focus item in chain. Moving focus to begin..."; + qInfo() << "No focus item in chain. Moving focus to begin..."; // m_focused_item_index = 0; // if not in focus chain current return; } diff --git a/client/ui/qml/Components/ConnectButton.qml b/client/ui/qml/Components/ConnectButton.qml index c3032eab..b90891a0 100644 --- a/client/ui/qml/Components/ConnectButton.qml +++ b/client/ui/qml/Components/ConnectButton.qml @@ -25,7 +25,23 @@ Button { Keys.onBacktabPressed: { FocusController.previousKeyTabItem() } + + Keys.onUpPressed: { + FocusController.nextKeyUpItem() + } + Keys.onDownPressed: { + FocusController.nextKeyDownItem() + } + + Keys.onLeftPressed: { + FocusController.nextKeyLeftItem() + } + + Keys.onRightPressed: { + FocusController.nextKeyRightItem() + } + implicitWidth: 190 implicitHeight: 190 diff --git a/client/ui/qml/Components/HomeContainersListView.qml b/client/ui/qml/Components/HomeContainersListView.qml index 9c3d3857..5d3569f5 100644 --- a/client/ui/qml/Components/HomeContainersListView.qml +++ b/client/ui/qml/Components/HomeContainersListView.qml @@ -46,6 +46,14 @@ ListView { FocusController.previousKeyTabItem() } + Keys.onRightPressed: { + FocusController.nextKeyTabItem() + } + + Keys.onLeftPressed: { + FocusController.previousKeyTabItem() + } + // activeFocusOnTab: true // onActiveFocusChanged: { // console.log("===========================") diff --git a/client/ui/qml/Components/HomeSplitTunnelingDrawer.qml b/client/ui/qml/Components/HomeSplitTunnelingDrawer.qml index b37b0b81..67696c33 100644 --- a/client/ui/qml/Components/HomeSplitTunnelingDrawer.qml +++ b/client/ui/qml/Components/HomeSplitTunnelingDrawer.qml @@ -46,11 +46,9 @@ DrawerType2 { descriptionText: qsTr("Enabled \nCan't be disabled for current server") rightImageSource: "qrc:/images/controls/chevron-right.svg" - // KeyNavigation.tab: siteBasedSplitTunnelingSwitch.visible ? siteBasedSplitTunnelingSwitch.rightButton : focusItem - clickedFunction: function() { -// PageController.goToPage(PageEnum.PageSettingsSplitTunneling) -// root.close() + PageController.goToPage(PageEnum.PageSettingsSplitTunneling) + root.close() } } @@ -67,10 +65,6 @@ DrawerType2 { descriptionText: enabled && SitesModel.isTunnelingEnabled ? qsTr("Enabled") : qsTr("Disabled") rightImageSource: "qrc:/images/controls/chevron-right.svg" - // KeyNavigation.tab: appSplitTunnelingSwitch.visible ? - // appSplitTunnelingSwitch.rightButton : - // focusItem - clickedFunction: function() { PageController.goToPage(PageEnum.PageSettingsSplitTunneling) root.closeTriggered() @@ -90,8 +84,6 @@ DrawerType2 { descriptionText: AppSplitTunnelingModel.isTunnelingEnabled ? qsTr("Enabled") : qsTr("Disabled") rightImageSource: "qrc:/images/controls/chevron-right.svg" - // KeyNavigation.tab: focusItem - clickedFunction: function() { PageController.goToPage(PageEnum.PageSettingsAppSplitTunneling) root.closeTriggered() diff --git a/client/ui/qml/Controls2/BasicButtonType.qml b/client/ui/qml/Controls2/BasicButtonType.qml index e925035b..2f1e3fbb 100644 --- a/client/ui/qml/Controls2/BasicButtonType.qml +++ b/client/ui/qml/Controls2/BasicButtonType.qml @@ -38,14 +38,28 @@ Button { property bool isFocusable: true Keys.onTabPressed: { - console.debug("--> Tab is pressed on BasicButtonType: ", objectName) FocusController.nextKeyTabItem() } - + Keys.onBacktabPressed: { - console.debug("--> Shift+Tab is pressed on ", objectName) FocusController.previousKeyTabItem() } + + Keys.onUpPressed: { + FocusController.nextKeyUpItem() + } + + Keys.onDownPressed: { + FocusController.nextKeyDownItem() + } + + Keys.onLeftPressed: { + FocusController.nextKeyLeftItem() + } + + Keys.onRightPressed: { + FocusController.nextKeyRightItem() + } implicitHeight: 56 diff --git a/client/ui/qml/Controls2/FlickableType.qml b/client/ui/qml/Controls2/FlickableType.qml index db857ea9..2151e520 100644 --- a/client/ui/qml/Controls2/FlickableType.qml +++ b/client/ui/qml/Controls2/FlickableType.qml @@ -11,6 +11,7 @@ Flickable { } else if (item.y + item.height > fl.contentY + fl.height) { fl.contentY = item.y + item.height - fl.height + 40 // 40 is a bottom margin } + fl.returnToBounds() } clip: true diff --git a/client/ui/qml/Controls2/HorizontalRadioButton.qml b/client/ui/qml/Controls2/HorizontalRadioButton.qml index b87d9b84..89cc1658 100644 --- a/client/ui/qml/Controls2/HorizontalRadioButton.qml +++ b/client/ui/qml/Controls2/HorizontalRadioButton.qml @@ -30,15 +30,29 @@ RadioButton { property bool isFocusable: true Keys.onTabPressed: { - console.debug("--> Tab is pressed on BasicButtonType: ", objectName) FocusController.nextKeyTabItem() } Keys.onBacktabPressed: { - console.debug("--> Shift+Tab is pressed on ", objectName) FocusController.previousKeyTabItem() } + Keys.onUpPressed: { + FocusController.nextKeyUpItem() + } + + Keys.onDownPressed: { + FocusController.nextKeyDownItem() + } + + Keys.onLeftPressed: { + FocusController.nextKeyLeftItem() + } + + Keys.onRightPressed: { + FocusController.nextKeyRightItem() + } + indicator: Rectangle { anchors.fill: parent radius: 16 diff --git a/client/ui/qml/Controls2/ImageButtonType.qml b/client/ui/qml/Controls2/ImageButtonType.qml index 8770f454..d5f646a7 100644 --- a/client/ui/qml/Controls2/ImageButtonType.qml +++ b/client/ui/qml/Controls2/ImageButtonType.qml @@ -38,6 +38,22 @@ Button { FocusController.previousKeyTabItem() } + Keys.onUpPressed: { + FocusController.nextKeyUpItem() + } + + Keys.onDownPressed: { + FocusController.nextKeyDownItem() + } + + Keys.onLeftPressed: { + FocusController.nextKeyLeftItem() + } + + Keys.onRightPressed: { + FocusController.nextKeyRightItem() + } + Keys.onEnterPressed: root.clicked() Keys.onReturnPressed: root.clicked() diff --git a/client/ui/qml/Controls2/LabelWithButtonType.qml b/client/ui/qml/Controls2/LabelWithButtonType.qml index 5e05c30e..087415f7 100644 --- a/client/ui/qml/Controls2/LabelWithButtonType.qml +++ b/client/ui/qml/Controls2/LabelWithButtonType.qml @@ -50,28 +50,44 @@ Item { Keys.onBacktabPressed: { FocusController.previousKeyTabItem() } + + Keys.onUpPressed: { + FocusController.nextKeyUpItem() + } + + Keys.onDownPressed: { + FocusController.nextKeyDownItem() + } + + Keys.onLeftPressed: { + FocusController.nextKeyLeftItem() + } + + Keys.onRightPressed: { + FocusController.nextKeyRightItem() + } implicitWidth: content.implicitWidth + content.anchors.topMargin + content.anchors.bottomMargin implicitHeight: content.implicitHeight + content.anchors.leftMargin + content.anchors.rightMargin - // onFocusChanged: { - // if (root.activeFocus) { - // if (root.parentFlickable) { - // root.parentFlickable.ensureVisible(root) - // } - // } - // } + onFocusChanged: { + if (root.activeFocus) { + if (root.parentFlickable) { + root.parentFlickable.ensureVisible(root) + } + } + } - // Connections { - // target: rightImage - // function onFocusChanged() { - // if (rightImage.activeFocus) { - // if (root.parentFlickable) { - // root.parentFlickable.ensureVisible(root) - // } - // } - // } - // } + Connections { + target: rightImage + function onFocusChanged() { + if (rightImage.activeFocus) { + if (root.parentFlickable) { + root.parentFlickable.ensureVisible(root) + } + } + } + } MouseArea { anchors.fill: parent diff --git a/client/ui/qml/Controls2/ListViewWithRadioButtonType.qml b/client/ui/qml/Controls2/ListViewWithRadioButtonType.qml index ed5fa6d9..9024af91 100644 --- a/client/ui/qml/Controls2/ListViewWithRadioButtonType.qml +++ b/client/ui/qml/Controls2/ListViewWithRadioButtonType.qml @@ -43,6 +43,22 @@ ListView { FocusController.previousKeyTabItem() } + Keys.onUpPressed: { + FocusController.nextKeyUpItem() + } + + Keys.onDownPressed: { + FocusController.nextKeyDownItem() + } + + Keys.onLeftPressed: { + FocusController.nextKeyLeftItem() + } + + Keys.onRightPressed: { + FocusController.nextKeyRightItem() + } + ButtonGroup { id: buttonGroup } diff --git a/client/ui/qml/Controls2/SwitcherType.qml b/client/ui/qml/Controls2/SwitcherType.qml index b96f40e4..3569a7d0 100644 --- a/client/ui/qml/Controls2/SwitcherType.qml +++ b/client/ui/qml/Controls2/SwitcherType.qml @@ -45,10 +45,27 @@ Switch { FocusController.previousKeyTabItem() } + Keys.onUpPressed: { + FocusController.nextKeyUpItem() + } + + Keys.onDownPressed: { + FocusController.nextKeyDownItem() + } + + Keys.onLeftPressed: { + FocusController.nextKeyLeftItem() + } + + Keys.onRightPressed: { + FocusController.nextKeyRightItem() + } + hoverEnabled: enabled ? true : false focusPolicy: Qt.TabFocus property FlickableType parentFlickable: null + onFocusChanged: { if (root.activeFocus) { if (root.parentFlickable) { diff --git a/client/ui/qml/Controls2/TabButtonType.qml b/client/ui/qml/Controls2/TabButtonType.qml index d3dc0d1b..0e48d975 100644 --- a/client/ui/qml/Controls2/TabButtonType.qml +++ b/client/ui/qml/Controls2/TabButtonType.qml @@ -26,6 +26,22 @@ TabButton { Keys.onBacktabPressed: { FocusController.previousKeyTabItem() } + + Keys.onUpPressed: { + FocusController.nextKeyUpItem() + } + + Keys.onDownPressed: { + FocusController.nextKeyDownItem() + } + + Keys.onLeftPressed: { + FocusController.nextKeyLeftItem() + } + + Keys.onRightPressed: { + FocusController.nextKeyRightItem() + } implicitHeight: 48 diff --git a/client/ui/qml/Controls2/TabImageButtonType.qml b/client/ui/qml/Controls2/TabImageButtonType.qml index 3e0b5aed..b49ad8eb 100644 --- a/client/ui/qml/Controls2/TabImageButtonType.qml +++ b/client/ui/qml/Controls2/TabImageButtonType.qml @@ -16,13 +16,29 @@ TabButton { property bool isFocusable: true - Keys.onTabPressed: { - FocusController.nextKeyTabItem() - } + Keys.onTabPressed: { + FocusController.nextKeyTabItem() + } - Keys.onBacktabPressed: { - FocusController.previousKeyTabItem() - } + Keys.onBacktabPressed: { + FocusController.previousKeyTabItem() + } + + Keys.onUpPressed: { + FocusController.nextKeyUpItem() + } + + Keys.onDownPressed: { + FocusController.nextKeyDownItem() + } + + Keys.onLeftPressed: { + FocusController.nextKeyLeftItem() + } + + Keys.onRightPressed: { + FocusController.nextKeyRightItem() + } property string borderFocusedColor: AmneziaStyle.color.paleGray property int borderFocusedWidth: 1 @@ -30,7 +46,6 @@ TabButton { property var clickedFunc hoverEnabled: true - // focusPolicy: Qt.TabFocus icon.source: image icon.color: isSelected ? selectedColor : defaultColor @@ -53,7 +68,6 @@ TabButton { } Keys.onEnterPressed: { - console.log("$$$$$$$$$ ENTER PRESSED INSIDE TABIMAGEBUTTONTYPE") if (root.clickedFunc && typeof root.clickedFunc === "function") { root.clickedFunc() } diff --git a/client/ui/qml/Controls2/VerticalRadioButton.qml b/client/ui/qml/Controls2/VerticalRadioButton.qml index 4320103b..dcf0f1d9 100644 --- a/client/ui/qml/Controls2/VerticalRadioButton.qml +++ b/client/ui/qml/Controls2/VerticalRadioButton.qml @@ -34,6 +34,26 @@ RadioButton { FocusController.nextKeyTabItem() } + Keys.onBacktabPressed: { + FocusController.previousKeyTabItem() + } + + Keys.onUpPressed: { + FocusController.nextKeyUpItem() + } + + Keys.onDownPressed: { + FocusController.nextKeyDownItem() + } + + Keys.onLeftPressed: { + FocusController.nextKeyLeftItem() + } + + Keys.onRightPressed: { + FocusController.nextKeyRightItem() + } + hoverEnabled: true // focusPolicy: Qt.TabFocus diff --git a/client/ui/qml/Pages2/PageHome.qml b/client/ui/qml/Pages2/PageHome.qml index aa2f0501..2d52b044 100644 --- a/client/ui/qml/Pages2/PageHome.qml +++ b/client/ui/qml/Pages2/PageHome.qml @@ -410,6 +410,16 @@ PageType { ServersListView { id: serversMenuContent objectName: "serversMenuContent" + + isFocusable: false + + Connections { + target: drawer + + function onIsOpenedChanged() { + serversMenuContent.isFocusable = drawer.isOpened + } + } } } }